233 } |
233 } |
234 priority = (ThreadPriority)p; |
234 priority = (ThreadPriority)p; |
235 return OS_OK; |
235 return OS_OK; |
236 } |
236 } |
237 |
237 |
|
238 bool os::dll_build_name(char* buffer, size_t size, const char* fname) { |
|
239 int n = jio_snprintf(buffer, size, "%s%s%s", JNI_LIB_PREFIX, fname, JNI_LIB_SUFFIX); |
|
240 return (n != -1); |
|
241 } |
|
242 |
|
243 // Helper for dll_locate_lib. |
|
244 // Pass buffer and printbuffer as we already printed the path to buffer |
|
245 // when we called get_current_directory. This way we avoid another buffer |
|
246 // of size MAX_PATH. |
|
247 static bool conc_path_file_and_check(char *buffer, char *printbuffer, size_t printbuflen, |
|
248 const char* pname, char lastchar, const char* fname) { |
|
249 |
|
250 // Concatenate path and file name, but don't print double path separators. |
|
251 const char *filesep = (WINDOWS_ONLY(lastchar == ':' ||) lastchar == os::file_separator()[0]) ? |
|
252 "" : os::file_separator(); |
|
253 int ret = jio_snprintf(printbuffer, printbuflen, "%s%s%s", pname, filesep, fname); |
|
254 // Check whether file exists. |
|
255 if (ret != -1) { |
|
256 struct stat statbuf; |
|
257 return os::stat(buffer, &statbuf) == 0; |
|
258 } |
|
259 return false; |
|
260 } |
|
261 |
|
262 bool os::dll_locate_lib(char *buffer, size_t buflen, |
|
263 const char* pname, const char* fname) { |
|
264 bool retval = false; |
|
265 |
|
266 size_t fullfnamelen = strlen(JNI_LIB_PREFIX) + strlen(fname) + strlen(JNI_LIB_SUFFIX); |
|
267 char* fullfname = (char*)NEW_C_HEAP_ARRAY(char, fullfnamelen + 1, mtInternal); |
|
268 if (dll_build_name(fullfname, fullfnamelen + 1, fname)) { |
|
269 const size_t pnamelen = pname ? strlen(pname) : 0; |
|
270 |
|
271 if (pnamelen == 0) { |
|
272 // If no path given, use current working directory. |
|
273 const char* p = get_current_directory(buffer, buflen); |
|
274 if (p != NULL) { |
|
275 const size_t plen = strlen(buffer); |
|
276 const char lastchar = buffer[plen - 1]; |
|
277 retval = conc_path_file_and_check(buffer, &buffer[plen], buflen - plen, |
|
278 "", lastchar, fullfname); |
|
279 } |
|
280 } else if (strchr(pname, *os::path_separator()) != NULL) { |
|
281 // A list of paths. Search for the path that contains the library. |
|
282 int n; |
|
283 char** pelements = split_path(pname, &n); |
|
284 if (pelements != NULL) { |
|
285 for (int i = 0; i < n; i++) { |
|
286 char* path = pelements[i]; |
|
287 // Really shouldn't be NULL, but check can't hurt. |
|
288 size_t plen = (path == NULL) ? 0 : strlen(path); |
|
289 if (plen == 0) { |
|
290 continue; // Skip the empty path values. |
|
291 } |
|
292 const char lastchar = path[plen - 1]; |
|
293 retval = conc_path_file_and_check(buffer, buffer, buflen, path, lastchar, fullfname); |
|
294 if (retval) break; |
|
295 } |
|
296 // Release the storage allocated by split_path. |
|
297 for (int i = 0; i < n; i++) { |
|
298 if (pelements[i] != NULL) { |
|
299 FREE_C_HEAP_ARRAY(char, pelements[i]); |
|
300 } |
|
301 } |
|
302 FREE_C_HEAP_ARRAY(char*, pelements); |
|
303 } |
|
304 } else { |
|
305 // A definite path. |
|
306 const char lastchar = pname[pnamelen-1]; |
|
307 retval = conc_path_file_and_check(buffer, buffer, buflen, pname, lastchar, fullfname); |
|
308 } |
|
309 } |
|
310 |
|
311 FREE_C_HEAP_ARRAY(char*, fullfname); |
|
312 return retval; |
|
313 } |
238 |
314 |
239 // --------------------- sun.misc.Signal (optional) --------------------- |
315 // --------------------- sun.misc.Signal (optional) --------------------- |
240 |
316 |
241 |
317 |
242 // SIGBREAK is sent by the keyboard to query the VM state |
318 // SIGBREAK is sent by the keyboard to query the VM state |
425 char ebuf[1024]; |
501 char ebuf[1024]; |
426 |
502 |
427 // Try to load verify dll first. In 1.3 java dll depends on it and is not |
503 // Try to load verify dll first. In 1.3 java dll depends on it and is not |
428 // always able to find it when the loading executable is outside the JDK. |
504 // always able to find it when the loading executable is outside the JDK. |
429 // In order to keep working with 1.2 we ignore any loading errors. |
505 // In order to keep working with 1.2 we ignore any loading errors. |
430 if (dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(), |
506 if (dll_locate_lib(buffer, sizeof(buffer), Arguments::get_dll_dir(), |
431 "verify")) { |
507 "verify")) { |
432 dll_load(buffer, ebuf, sizeof(ebuf)); |
508 dll_load(buffer, ebuf, sizeof(ebuf)); |
433 } |
509 } |
434 |
510 |
435 // Load java dll |
511 // Load java dll |
436 if (dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(), |
512 if (dll_locate_lib(buffer, sizeof(buffer), Arguments::get_dll_dir(), |
437 "java")) { |
513 "java")) { |
438 _native_java_library = dll_load(buffer, ebuf, sizeof(ebuf)); |
514 _native_java_library = dll_load(buffer, ebuf, sizeof(ebuf)); |
439 } |
515 } |
440 if (_native_java_library == NULL) { |
516 if (_native_java_library == NULL) { |
441 vm_exit_during_initialization("Unable to load native library", ebuf); |
517 vm_exit_during_initialization("Unable to load native library", ebuf); |
442 } |
518 } |
443 |
519 |
444 #if defined(__OpenBSD__) |
520 #if defined(__OpenBSD__) |
445 // Work-around OpenBSD's lack of $ORIGIN support by pre-loading libnet.so |
521 // Work-around OpenBSD's lack of $ORIGIN support by pre-loading libnet.so |
446 // ignore errors |
522 // ignore errors |
447 if (dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(), |
523 if (dll_locate_lib(buffer, sizeof(buffer), Arguments::get_dll_dir(), |
448 "net")) { |
524 "net")) { |
449 dll_load(buffer, ebuf, sizeof(ebuf)); |
525 dll_load(buffer, ebuf, sizeof(ebuf)); |
450 } |
526 } |
451 #endif |
527 #endif |
452 } |
528 } |