author | duke |
Wed, 05 Jul 2017 19:57:26 +0200 | |
changeset 26050 | 5d268650760d |
parent 25859 | 3317bb8137f4 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
16726
diff
changeset
|
2 |
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
|
5 |
* modification, are permitted provided that the following conditions |
|
6 |
* are met: |
|
7 |
* |
|
8 |
* - Redistributions of source code must retain the above copyright |
|
9 |
* notice, this list of conditions and the following disclaimer. |
|
10 |
* |
|
11 |
* - Redistributions in binary form must reproduce the above copyright |
|
12 |
* notice, this list of conditions and the following disclaimer in the |
|
13 |
* documentation and/or other materials provided with the distribution. |
|
14 |
* |
|
5506 | 15 |
* - Neither the name of Oracle nor the names of its |
2 | 16 |
* contributors may be used to endorse or promote products derived |
17 |
* from this software without specific prior written permission. |
|
18 |
* |
|
19 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
|
20 |
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
|
21 |
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
22 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
23 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
24 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
25 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
26 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|
27 |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
28 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
29 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
30 |
*/ |
|
31 |
||
10292
ed7db6a12c2a
7067811: Update demo/sample code to state it should not be used for production
nloodin
parents:
5506
diff
changeset
|
32 |
/* |
ed7db6a12c2a
7067811: Update demo/sample code to state it should not be used for production
nloodin
parents:
5506
diff
changeset
|
33 |
* This source code is provided to illustrate the usage of a given feature |
ed7db6a12c2a
7067811: Update demo/sample code to state it should not be used for production
nloodin
parents:
5506
diff
changeset
|
34 |
* or technique and has been deliberately simplified. Additional steps |
ed7db6a12c2a
7067811: Update demo/sample code to state it should not be used for production
nloodin
parents:
5506
diff
changeset
|
35 |
* required for a production-quality application, such as security checks, |
ed7db6a12c2a
7067811: Update demo/sample code to state it should not be used for production
nloodin
parents:
5506
diff
changeset
|
36 |
* input validation and proper error handling, might not be present in |
ed7db6a12c2a
7067811: Update demo/sample code to state it should not be used for production
nloodin
parents:
5506
diff
changeset
|
37 |
* this sample code. |
ed7db6a12c2a
7067811: Update demo/sample code to state it should not be used for production
nloodin
parents:
5506
diff
changeset
|
38 |
*/ |
ed7db6a12c2a
7067811: Update demo/sample code to state it should not be used for production
nloodin
parents:
5506
diff
changeset
|
39 |
|
ed7db6a12c2a
7067811: Update demo/sample code to state it should not be used for production
nloodin
parents:
5506
diff
changeset
|
40 |
|
2 | 41 |
#include <sys/types.h> |
42 |
#include <sys/stat.h> |
|
43 |
#include <fcntl.h> |
|
44 |
||
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
16726
diff
changeset
|
45 |
#if !defined(LINUX) && !defined(_ALLBSD_SOURCE) && !defined(AIX) |
2 | 46 |
#include <procfs.h> |
47 |
#endif |
|
48 |
||
49 |
#include <stdio.h> |
|
50 |
#include <stdlib.h> |
|
51 |
#include <string.h> |
|
52 |
#include <sys/socket.h> |
|
53 |
#include <sys/errno.h> |
|
54 |
#include <unistd.h> |
|
55 |
#include <errno.h> |
|
56 |
#include <dlfcn.h> |
|
57 |
#include <sys/time.h> |
|
58 |
||
59 |
#include <netdb.h> |
|
60 |
#include <netinet/in.h> |
|
61 |
#include <sys/param.h> |
|
62 |
#include <time.h> |
|
63 |
||
64 |
#include "jni.h" |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
10292
diff
changeset
|
65 |
#include "jvm_md.h" |
2 | 66 |
#include "hprof.h" |
67 |
||
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
16726
diff
changeset
|
68 |
#ifdef AIX |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
16726
diff
changeset
|
69 |
#include "porting_aix.h" /* For the 'dladdr' function. */ |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
16726
diff
changeset
|
70 |
#endif |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
16726
diff
changeset
|
71 |
|
2 | 72 |
int |
73 |
md_getpid(void) |
|
74 |
{ |
|
75 |
static int pid = -1; |
|
76 |
||
77 |
if ( pid >= 0 ) { |
|
78 |
return pid; |
|
79 |
} |
|
80 |
pid = getpid(); |
|
81 |
return pid; |
|
82 |
} |
|
83 |
||
84 |
void |
|
85 |
md_sleep(unsigned seconds) |
|
86 |
{ |
|
87 |
sleep(seconds); |
|
88 |
} |
|
89 |
||
90 |
void |
|
91 |
md_init(void) |
|
92 |
{ |
|
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
16726
diff
changeset
|
93 |
#if defined(LINUX) || defined(_ALLBSD_SOURCE) || defined(AIX) |
2 | 94 |
/* No Hi-Res timer option? */ |
95 |
#else |
|
96 |
if ( gdata->micro_state_accounting ) { |
|
97 |
char proc_ctl_fn[48]; |
|
98 |
int procfd; |
|
99 |
||
100 |
/* Turn on micro state accounting, once per process */ |
|
101 |
(void)md_snprintf(proc_ctl_fn, sizeof(proc_ctl_fn), |
|
102 |
"/proc/%d/ctl", md_getpid()); |
|
103 |
||
104 |
procfd = open(proc_ctl_fn, O_WRONLY); |
|
105 |
if (procfd >= 0) { |
|
106 |
long ctl_op[2]; |
|
107 |
||
108 |
ctl_op[0] = PCSET; |
|
109 |
ctl_op[1] = PR_MSACCT; |
|
110 |
(void)write(procfd, ctl_op, sizeof(ctl_op)); |
|
111 |
(void)close(procfd); |
|
112 |
} |
|
113 |
} |
|
114 |
#endif |
|
115 |
} |
|
116 |
||
117 |
int |
|
118 |
md_connect(char *hostname, unsigned short port) |
|
119 |
{ |
|
120 |
struct hostent *hentry; |
|
121 |
struct sockaddr_in s; |
|
122 |
int fd; |
|
123 |
||
124 |
/* create a socket */ |
|
125 |
fd = socket(AF_INET, SOCK_STREAM, 0); |
|
13014
e2fe1611bb04
7176138: Fixes for missing close() calls and possible null pointer reference instead of fatal error
ohair
parents:
12047
diff
changeset
|
126 |
if ( fd < 0 ) { |
e2fe1611bb04
7176138: Fixes for missing close() calls and possible null pointer reference instead of fatal error
ohair
parents:
12047
diff
changeset
|
127 |
return -1; |
e2fe1611bb04
7176138: Fixes for missing close() calls and possible null pointer reference instead of fatal error
ohair
parents:
12047
diff
changeset
|
128 |
} |
2 | 129 |
|
130 |
/* find remote host's addr from name */ |
|
131 |
if ((hentry = gethostbyname(hostname)) == NULL) { |
|
13014
e2fe1611bb04
7176138: Fixes for missing close() calls and possible null pointer reference instead of fatal error
ohair
parents:
12047
diff
changeset
|
132 |
(void)close(fd); |
2 | 133 |
return -1; |
134 |
} |
|
135 |
(void)memset((char *)&s, 0, sizeof(s)); |
|
136 |
/* set remote host's addr; its already in network byte order */ |
|
137 |
(void)memcpy(&s.sin_addr.s_addr, *(hentry->h_addr_list), |
|
138 |
(int)sizeof(s.sin_addr.s_addr)); |
|
139 |
/* set remote host's port */ |
|
140 |
s.sin_port = htons(port); |
|
141 |
s.sin_family = AF_INET; |
|
142 |
||
143 |
/* now try connecting */ |
|
144 |
if (-1 == connect(fd, (struct sockaddr*)&s, sizeof(s))) { |
|
13014
e2fe1611bb04
7176138: Fixes for missing close() calls and possible null pointer reference instead of fatal error
ohair
parents:
12047
diff
changeset
|
145 |
(void)close(fd); |
2 | 146 |
return 0; |
147 |
} |
|
148 |
return fd; |
|
149 |
} |
|
150 |
||
151 |
int |
|
152 |
md_recv(int f, char *buf, int len, int option) |
|
153 |
{ |
|
154 |
return recv(f, buf, len, option); |
|
155 |
} |
|
156 |
||
157 |
int |
|
158 |
md_shutdown(int filedes, int option) |
|
159 |
{ |
|
160 |
return shutdown(filedes, option); |
|
161 |
} |
|
162 |
||
163 |
int |
|
164 |
md_open(const char *filename) |
|
165 |
{ |
|
166 |
return open(filename, O_RDONLY); |
|
167 |
} |
|
168 |
||
169 |
int |
|
170 |
md_open_binary(const char *filename) |
|
171 |
{ |
|
172 |
return md_open(filename); |
|
173 |
} |
|
174 |
||
175 |
int |
|
176 |
md_creat(const char *filename) |
|
177 |
{ |
|
178 |
return open(filename, O_WRONLY | O_CREAT | O_TRUNC, |
|
179 |
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); |
|
180 |
} |
|
181 |
||
182 |
int |
|
183 |
md_creat_binary(const char *filename) |
|
184 |
{ |
|
185 |
return md_creat(filename); |
|
186 |
} |
|
187 |
||
188 |
jlong |
|
189 |
md_seek(int filedes, jlong cur) |
|
190 |
{ |
|
191 |
jlong new_pos; |
|
192 |
||
193 |
if ( cur == (jlong)-1 ) { |
|
194 |
new_pos = lseek(filedes, 0, SEEK_END); |
|
195 |
} else { |
|
196 |
new_pos = lseek(filedes, cur, SEEK_SET); |
|
197 |
} |
|
198 |
return new_pos; |
|
199 |
} |
|
200 |
||
201 |
void |
|
202 |
md_close(int filedes) |
|
203 |
{ |
|
204 |
(void)close(filedes); |
|
205 |
} |
|
206 |
||
207 |
int |
|
208 |
md_send(int s, const char *msg, int len, int flags) |
|
209 |
{ |
|
210 |
int res; |
|
211 |
||
212 |
do { |
|
213 |
res = send(s, msg, len, flags); |
|
214 |
} while ((res < 0) && (errno == EINTR)); |
|
215 |
||
216 |
return res; |
|
217 |
} |
|
218 |
||
219 |
int |
|
220 |
md_write(int filedes, const void *buf, int nbyte) |
|
221 |
{ |
|
222 |
int res; |
|
223 |
||
224 |
do { |
|
225 |
res = write(filedes, buf, nbyte); |
|
226 |
} while ((res < 0) && (errno == EINTR)); |
|
227 |
||
228 |
return res; |
|
229 |
} |
|
230 |
||
231 |
int |
|
232 |
md_read(int filedes, void *buf, int nbyte) |
|
233 |
{ |
|
234 |
int res; |
|
235 |
||
236 |
do { |
|
237 |
res = read(filedes, buf, nbyte); |
|
238 |
} while ((res < 0) && (errno == EINTR)); |
|
239 |
||
240 |
return res; |
|
241 |
} |
|
242 |
||
243 |
/* Time of day in milli-seconds */ |
|
244 |
static jlong |
|
245 |
md_timeofday(void) |
|
246 |
{ |
|
247 |
struct timeval tv; |
|
248 |
||
249 |
if ( gettimeofday(&tv, (void *)0) != 0 ) { |
|
250 |
return (jlong)0; /* EOVERFLOW ? */ |
|
251 |
} |
|
252 |
/*LINTED*/ |
|
253 |
return ((jlong)tv.tv_sec * (jlong)1000) + (jlong)(tv.tv_usec / 1000); |
|
254 |
} |
|
255 |
||
256 |
/* Hi-res timer in micro-seconds */ |
|
257 |
jlong |
|
258 |
md_get_microsecs(void) |
|
259 |
{ |
|
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
16726
diff
changeset
|
260 |
#if defined(LINUX) || defined(_ALLBSD_SOURCE) || defined(AIX) |
2 | 261 |
return (jlong)(md_timeofday() * (jlong)1000); /* Milli to micro */ |
262 |
#else |
|
263 |
return (jlong)(gethrtime()/(hrtime_t)1000); /* Nano seconds to micro seconds */ |
|
264 |
#endif |
|
265 |
} |
|
266 |
||
267 |
/* Time of day in milli-seconds */ |
|
268 |
jlong |
|
269 |
md_get_timemillis(void) |
|
270 |
{ |
|
271 |
return md_timeofday(); |
|
272 |
} |
|
273 |
||
274 |
/* Current CPU hi-res CPU time used */ |
|
275 |
jlong |
|
276 |
md_get_thread_cpu_timemillis(void) |
|
277 |
{ |
|
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
16726
diff
changeset
|
278 |
#if defined(LINUX) || defined(_ALLBSD_SOURCE) || defined(AIX) |
2 | 279 |
return md_timeofday(); |
280 |
#else |
|
281 |
return (jlong)(gethrvtime()/1000); /* Nano seconds to milli seconds */ |
|
282 |
#endif |
|
283 |
} |
|
284 |
||
285 |
void |
|
286 |
md_get_prelude_path(char *path, int path_len, char *filename) |
|
287 |
{ |
|
288 |
void *addr; |
|
289 |
char libdir[FILENAME_MAX+1]; |
|
290 |
Dl_info dlinfo; |
|
291 |
||
292 |
libdir[0] = 0; |
|
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
16726
diff
changeset
|
293 |
#if defined(LINUX) || defined(_ALLBSD_SOURCE) || defined(AIX) |
2 | 294 |
addr = (void*)&Agent_OnLoad; |
295 |
#else |
|
296 |
/* Just using &Agent_OnLoad will get the first external symbol with |
|
297 |
* this name in the first .so, which may not be libhprof.so. |
|
298 |
* On Solaris we can actually ask for the address of our Agent_OnLoad. |
|
299 |
*/ |
|
300 |
addr = dlsym(RTLD_SELF, "Agent_OnLoad"); |
|
301 |
/* Just in case the above didn't work (missing linker patch?). */ |
|
302 |
if ( addr == NULL ) { |
|
303 |
addr = (void*)&Agent_OnLoad; |
|
304 |
} |
|
305 |
#endif |
|
306 |
||
307 |
/* Use dladdr() to get the full path to libhprof.so, which we use to find |
|
308 |
* the prelude file. |
|
309 |
*/ |
|
310 |
dlinfo.dli_fname = NULL; |
|
311 |
(void)dladdr(addr, &dlinfo); |
|
312 |
if ( dlinfo.dli_fname != NULL ) { |
|
313 |
char * lastSlash; |
|
314 |
||
315 |
/* Full path to library name, need to move up one directory to 'lib' */ |
|
316 |
(void)strcpy(libdir, (char *)dlinfo.dli_fname); |
|
317 |
lastSlash = strrchr(libdir, '/'); |
|
318 |
if ( lastSlash != NULL ) { |
|
319 |
*lastSlash = '\0'; |
|
320 |
} |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
10292
diff
changeset
|
321 |
#ifndef __APPLE__ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
10292
diff
changeset
|
322 |
// not sure why other platforms have to go up two levels, but on macos we only need up one |
2 | 323 |
lastSlash = strrchr(libdir, '/'); |
324 |
if ( lastSlash != NULL ) { |
|
325 |
*lastSlash = '\0'; |
|
326 |
} |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
10292
diff
changeset
|
327 |
#endif /* __APPLE__ */ |
2 | 328 |
} |
329 |
(void)snprintf(path, path_len, "%s/%s", libdir, filename); |
|
330 |
} |
|
331 |
||
332 |
||
333 |
int |
|
334 |
md_vsnprintf(char *s, int n, const char *format, va_list ap) |
|
335 |
{ |
|
336 |
return vsnprintf(s, n, format, ap); |
|
337 |
} |
|
338 |
||
339 |
int |
|
340 |
md_snprintf(char *s, int n, const char *format, ...) |
|
341 |
{ |
|
342 |
int ret; |
|
343 |
va_list ap; |
|
344 |
||
345 |
va_start(ap, format); |
|
346 |
ret = md_vsnprintf(s, n, format, ap); |
|
347 |
va_end(ap); |
|
348 |
return ret; |
|
349 |
} |
|
350 |
||
351 |
void |
|
352 |
md_system_error(char *buf, int len) |
|
353 |
{ |
|
354 |
char *p; |
|
355 |
||
356 |
buf[0] = 0; |
|
357 |
p = strerror(errno); |
|
358 |
if ( p != NULL ) { |
|
359 |
(void)strcpy(buf, p); |
|
360 |
} |
|
361 |
} |
|
362 |
||
363 |
unsigned |
|
364 |
md_htons(unsigned short s) |
|
365 |
{ |
|
366 |
return htons(s); |
|
367 |
} |
|
368 |
||
369 |
unsigned |
|
370 |
md_htonl(unsigned l) |
|
371 |
{ |
|
372 |
return htonl(l); |
|
373 |
} |
|
374 |
||
375 |
unsigned |
|
376 |
md_ntohs(unsigned short s) |
|
377 |
{ |
|
378 |
return ntohs(s); |
|
379 |
} |
|
380 |
||
381 |
unsigned |
|
382 |
md_ntohl(unsigned l) |
|
383 |
{ |
|
384 |
return ntohl(l); |
|
385 |
} |
|
386 |
||
14698
9294fcf94c46
7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents:
14342
diff
changeset
|
387 |
static void dll_build_name(char* buffer, size_t buflen, |
16726
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
388 |
const char* paths, const char* fname) { |
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
389 |
char *path, *paths_copy, *next_token; |
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
390 |
|
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
391 |
paths_copy = strdup(paths); |
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
392 |
if (paths_copy == NULL) { |
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
393 |
return; |
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
394 |
} |
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
395 |
|
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
396 |
next_token = NULL; |
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
397 |
path = strtok_r(paths_copy, ":", &next_token); |
14698
9294fcf94c46
7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents:
14342
diff
changeset
|
398 |
|
16726
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
399 |
while (path != NULL) { |
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
400 |
snprintf(buffer, buflen, "%s/lib%s" JNI_LIB_SUFFIX, path, fname); |
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
401 |
if (access(buffer, F_OK) == 0) { |
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
402 |
break; |
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
403 |
} |
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
404 |
*buffer = '\0'; |
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
405 |
path = strtok_r(NULL, ":", &next_token); |
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
406 |
} |
14698
9294fcf94c46
7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents:
14342
diff
changeset
|
407 |
|
16726
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
408 |
free(paths_copy); |
14698
9294fcf94c46
7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents:
14342
diff
changeset
|
409 |
} |
9294fcf94c46
7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents:
14342
diff
changeset
|
410 |
|
2 | 411 |
/* Create the actual fill filename for a dynamic library. */ |
412 |
void |
|
16726
f76b2e6bd199
8009558: linked_md.c::dll_build_name can get stuck in an infinite loop
sla
parents:
16057
diff
changeset
|
413 |
md_build_library_name(char *holder, int holderlen, const char *pname, const char *fname) |
2 | 414 |
{ |
415 |
int pnamelen; |
|
416 |
||
417 |
/* Length of options directory location. */ |
|
418 |
pnamelen = pname ? strlen(pname) : 0; |
|
419 |
||
14698
9294fcf94c46
7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents:
14342
diff
changeset
|
420 |
*holder = '\0'; |
2 | 421 |
/* Quietly truncate on buffer overflow. Should be an error. */ |
422 |
if (pnamelen + (int)strlen(fname) + 10 > holderlen) { |
|
423 |
return; |
|
424 |
} |
|
425 |
||
426 |
/* Construct path to library */ |
|
427 |
if (pnamelen == 0) { |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
10292
diff
changeset
|
428 |
(void)snprintf(holder, holderlen, "lib%s" JNI_LIB_SUFFIX, fname); |
2 | 429 |
} else { |
14698
9294fcf94c46
7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents:
14342
diff
changeset
|
430 |
dll_build_name(holder, holderlen, pname, fname); |
2 | 431 |
} |
432 |
} |
|
433 |
||
434 |
/* Load this library (return NULL on error, and error message in err_buf) */ |
|
435 |
void * |
|
436 |
md_load_library(const char *name, char *err_buf, int err_buflen) |
|
437 |
{ |
|
438 |
void * result; |
|
439 |
||
440 |
result = dlopen(name, RTLD_LAZY); |
|
441 |
if (result == NULL) { |
|
442 |
(void)strncpy(err_buf, dlerror(), err_buflen-2); |
|
443 |
err_buf[err_buflen-1] = '\0'; |
|
444 |
} |
|
445 |
return result; |
|
446 |
} |
|
447 |
||
448 |
/* Unload this library */ |
|
449 |
void |
|
450 |
md_unload_library(void *handle) |
|
451 |
{ |
|
452 |
(void)dlclose(handle); |
|
453 |
} |
|
454 |
||
455 |
/* Find an entry point inside this library (return NULL if not found) */ |
|
456 |
void * |
|
457 |
md_find_library_entry(void *handle, const char *name) |
|
458 |
{ |
|
459 |
void * sym; |
|
460 |
||
461 |
sym = dlsym(handle, name); |
|
462 |
return sym; |
|
463 |
} |
|
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
16726
diff
changeset
|
464 |
|
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
16726
diff
changeset
|
465 |