author | dholmes |
Thu, 04 Oct 2012 19:52:09 -0400 | |
changeset 13956 | 1a25205d266e |
parent 12047 | 320a714614e9 |
child 14342 | 8435a30053c1 |
permissions | -rw-r--r-- |
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 |
||
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
51 |
#ifdef __APPLE__ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
52 |
#define LIB_SUFFIX "dylib" |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
53 |
#else |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
54 |
#define LIB_SUFFIX "so" |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
55 |
#endif |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
56 |
|
2 | 57 |
/* |
58 |
* create a string for the JNI native function name by adding the |
|
59 |
* appropriate decorations. |
|
60 |
*/ |
|
61 |
int |
|
62 |
dbgsysBuildFunName(char *name, int nameLen, int args_size, int encodingIndex) |
|
63 |
{ |
|
64 |
/* On Solaris, there is only one encoding method. */ |
|
65 |
if (encodingIndex == 0) |
|
66 |
return 1; |
|
67 |
return 0; |
|
68 |
} |
|
69 |
||
70 |
/* |
|
71 |
* create a string for the dynamic lib open call by adding the |
|
72 |
* appropriate pre and extensions to a filename and the path |
|
73 |
*/ |
|
74 |
void |
|
75 |
dbgsysBuildLibName(char *holder, int holderlen, char *pname, char *fname) |
|
76 |
{ |
|
77 |
const int pnamelen = pname ? strlen(pname) : 0; |
|
78 |
||
79 |
/* Quietly truncate on buffer overflow. Should be an error. */ |
|
80 |
if (pnamelen + (int)strlen(fname) + 10 > holderlen) { |
|
81 |
*holder = '\0'; |
|
82 |
return; |
|
83 |
} |
|
84 |
||
85 |
if (pnamelen == 0) { |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
86 |
(void)snprintf(holder, holderlen, "lib%s." LIB_SUFFIX, fname); |
2 | 87 |
} else { |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
88 |
(void)snprintf(holder, holderlen, "%s/lib%s." LIB_SUFFIX, pname, fname); |
2 | 89 |
} |
90 |
} |
|
91 |
||
92 |
#ifndef NATIVE |
|
93 |
extern int thr_main(void); |
|
94 |
#endif |
|
95 |
||
96 |
void * |
|
97 |
dbgsysLoadLibrary(const char *name, char *err_buf, int err_buflen) |
|
98 |
{ |
|
99 |
void * result; |
|
100 |
#ifdef NATIVE |
|
101 |
result = dlopen(name, RTLD_LAZY); |
|
102 |
#else |
|
103 |
sysMonitorEnter(greenThreadSelf(), &_dl_lock); |
|
104 |
result = dlopen(name, RTLD_NOW); |
|
105 |
sysMonitorExit(greenThreadSelf(), &_dl_lock); |
|
106 |
/* |
|
107 |
* This is a bit of bulletproofing to catch the commonly occurring |
|
108 |
* problem of people loading a library which depends on libthread into |
|
109 |
* the VM. thr_main() should always return -1 which means that libthread |
|
110 |
* isn't loaded. |
|
111 |
*/ |
|
112 |
if (thr_main() != -1) { |
|
113 |
VM_CALL(panic)("libthread loaded into green threads"); |
|
114 |
} |
|
115 |
#endif |
|
116 |
if (result == NULL) { |
|
117 |
(void)strncpy(err_buf, dlerror(), err_buflen-2); |
|
118 |
err_buf[err_buflen-1] = '\0'; |
|
119 |
} |
|
120 |
return result; |
|
121 |
} |
|
122 |
||
123 |
void dbgsysUnloadLibrary(void *handle) |
|
124 |
{ |
|
125 |
#ifndef NATIVE |
|
126 |
sysMonitorEnter(greenThreadSelf(), &_dl_lock); |
|
127 |
#endif |
|
128 |
(void)dlclose(handle); |
|
129 |
#ifndef NATIVE |
|
130 |
sysMonitorExit(greenThreadSelf(), &_dl_lock); |
|
131 |
#endif |
|
132 |
} |
|
133 |
||
134 |
void * dbgsysFindLibraryEntry(void *handle, const char *name) |
|
135 |
{ |
|
136 |
void * sym; |
|
137 |
#ifndef NATIVE |
|
138 |
sysMonitorEnter(greenThreadSelf(), &_dl_lock); |
|
139 |
#endif |
|
140 |
sym = dlsym(handle, name); |
|
141 |
#ifndef NATIVE |
|
142 |
sysMonitorExit(greenThreadSelf(), &_dl_lock); |
|
143 |
#endif |
|
144 |
return sym; |
|
145 |
} |