2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved.
|
2
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
5506
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
2
|
24 |
*/
|
|
25 |
|
|
26 |
/*
|
|
27 |
* Adapted from JDK 1.2 linker_md.c v1.37. Note that we #define
|
|
28 |
* NATIVE here, whether or not we're running solaris native threads.
|
|
29 |
* Outside the VM, it's unclear how we can do the locking that is
|
|
30 |
* done in the green threads version of the code below.
|
|
31 |
*/
|
|
32 |
#define NATIVE
|
|
33 |
|
|
34 |
/*
|
|
35 |
* Machine Dependent implementation of the dynamic linking support
|
|
36 |
* for java. This routine is Solaris specific.
|
|
37 |
*/
|
|
38 |
|
|
39 |
#include <stdio.h>
|
|
40 |
#include <dlfcn.h>
|
|
41 |
#include <unistd.h>
|
|
42 |
#include <stdlib.h>
|
|
43 |
#include <string.h>
|
|
44 |
|
|
45 |
#include "path_md.h"
|
|
46 |
#ifndef NATIVE
|
|
47 |
#include "iomgr.h"
|
|
48 |
#include "threads_md.h"
|
|
49 |
#endif
|
|
50 |
|
|
51 |
/*
|
|
52 |
* create a string for the JNI native function name by adding the
|
|
53 |
* appropriate decorations.
|
|
54 |
*/
|
|
55 |
int
|
|
56 |
dbgsysBuildFunName(char *name, int nameLen, int args_size, int encodingIndex)
|
|
57 |
{
|
|
58 |
/* On Solaris, there is only one encoding method. */
|
|
59 |
if (encodingIndex == 0)
|
|
60 |
return 1;
|
|
61 |
return 0;
|
|
62 |
}
|
|
63 |
|
|
64 |
/*
|
|
65 |
* create a string for the dynamic lib open call by adding the
|
|
66 |
* appropriate pre and extensions to a filename and the path
|
|
67 |
*/
|
|
68 |
void
|
|
69 |
dbgsysBuildLibName(char *holder, int holderlen, char *pname, char *fname)
|
|
70 |
{
|
|
71 |
const int pnamelen = pname ? strlen(pname) : 0;
|
|
72 |
|
|
73 |
/* Quietly truncate on buffer overflow. Should be an error. */
|
|
74 |
if (pnamelen + (int)strlen(fname) + 10 > holderlen) {
|
|
75 |
*holder = '\0';
|
|
76 |
return;
|
|
77 |
}
|
|
78 |
|
|
79 |
if (pnamelen == 0) {
|
|
80 |
(void)snprintf(holder, holderlen, "lib%s.so", fname);
|
|
81 |
} else {
|
|
82 |
(void)snprintf(holder, holderlen, "%s/lib%s.so", pname, fname);
|
|
83 |
}
|
|
84 |
}
|
|
85 |
|
|
86 |
#ifndef NATIVE
|
|
87 |
extern int thr_main(void);
|
|
88 |
#endif
|
|
89 |
|
|
90 |
void *
|
|
91 |
dbgsysLoadLibrary(const char *name, char *err_buf, int err_buflen)
|
|
92 |
{
|
|
93 |
void * result;
|
|
94 |
#ifdef NATIVE
|
|
95 |
result = dlopen(name, RTLD_LAZY);
|
|
96 |
#else
|
|
97 |
sysMonitorEnter(greenThreadSelf(), &_dl_lock);
|
|
98 |
result = dlopen(name, RTLD_NOW);
|
|
99 |
sysMonitorExit(greenThreadSelf(), &_dl_lock);
|
|
100 |
/*
|
|
101 |
* This is a bit of bulletproofing to catch the commonly occurring
|
|
102 |
* problem of people loading a library which depends on libthread into
|
|
103 |
* the VM. thr_main() should always return -1 which means that libthread
|
|
104 |
* isn't loaded.
|
|
105 |
*/
|
|
106 |
if (thr_main() != -1) {
|
|
107 |
VM_CALL(panic)("libthread loaded into green threads");
|
|
108 |
}
|
|
109 |
#endif
|
|
110 |
if (result == NULL) {
|
|
111 |
(void)strncpy(err_buf, dlerror(), err_buflen-2);
|
|
112 |
err_buf[err_buflen-1] = '\0';
|
|
113 |
}
|
|
114 |
return result;
|
|
115 |
}
|
|
116 |
|
|
117 |
void dbgsysUnloadLibrary(void *handle)
|
|
118 |
{
|
|
119 |
#ifndef NATIVE
|
|
120 |
sysMonitorEnter(greenThreadSelf(), &_dl_lock);
|
|
121 |
#endif
|
|
122 |
(void)dlclose(handle);
|
|
123 |
#ifndef NATIVE
|
|
124 |
sysMonitorExit(greenThreadSelf(), &_dl_lock);
|
|
125 |
#endif
|
|
126 |
}
|
|
127 |
|
|
128 |
void * dbgsysFindLibraryEntry(void *handle, const char *name)
|
|
129 |
{
|
|
130 |
void * sym;
|
|
131 |
#ifndef NATIVE
|
|
132 |
sysMonitorEnter(greenThreadSelf(), &_dl_lock);
|
|
133 |
#endif
|
|
134 |
sym = dlsym(handle, name);
|
|
135 |
#ifndef NATIVE
|
|
136 |
sysMonitorExit(greenThreadSelf(), &_dl_lock);
|
|
137 |
#endif
|
|
138 |
return sym;
|
|
139 |
}
|