39 #ifndef GAMMA |
39 #ifndef GAMMA |
40 #include "manifest_info.h" |
40 #include "manifest_info.h" |
41 #include "version_comp.h" |
41 #include "version_comp.h" |
42 #endif |
42 #endif |
43 |
43 |
44 #ifdef __linux__ |
44 #if defined(__linux__) || defined(_ALLBSD_SOURCE) |
45 #include <pthread.h> |
45 #include <pthread.h> |
46 #else |
46 #else |
47 #include <thread.h> |
47 #include <thread.h> |
48 #endif |
48 #endif |
49 |
49 |
|
50 #ifdef __APPLE__ |
|
51 #define JVM_DLL "libjvm.dylib" |
|
52 #define JAVA_DLL "libjava.dylib" |
|
53 #define LD_LIBRARY_PATH "DYLD_LIBRARY_PATH" |
|
54 #else |
50 #define JVM_DLL "libjvm.so" |
55 #define JVM_DLL "libjvm.so" |
51 #define JAVA_DLL "libjava.so" |
56 #define JAVA_DLL "libjava.so" |
|
57 #define LD_LIBRARY_PATH "LD_LIBRARY_PATH" |
|
58 #endif |
52 |
59 |
53 #ifndef GAMMA /* launcher.make defines ARCH */ |
60 #ifndef GAMMA /* launcher.make defines ARCH */ |
54 /* |
61 /* |
55 * If a processor / os combination has the ability to run binaries of |
62 * If a processor / os combination has the ability to run binaries of |
56 * two data models and cohabitation of jre/jdk bits with both data |
63 * two data models and cohabitation of jre/jdk bits with both data |
421 #else |
428 #else |
422 /* |
429 /* |
423 * If not on Solaris, assume only a single LD_LIBRARY_PATH |
430 * If not on Solaris, assume only a single LD_LIBRARY_PATH |
424 * variable. |
431 * variable. |
425 */ |
432 */ |
426 runpath = getenv("LD_LIBRARY_PATH"); |
433 runpath = getenv(LD_LIBRARY_PATH); |
427 #endif /* __sun */ |
434 #endif /* __sun */ |
428 |
435 |
429 #ifdef __linux |
436 #if defined(__linux__) |
430 /* |
437 /* |
431 * On linux, if a binary is running as sgid or suid, glibc sets |
438 * On linux, if a binary is running as sgid or suid, glibc sets |
432 * LD_LIBRARY_PATH to the empty string for security purposes. (In |
439 * LD_LIBRARY_PATH to the empty string for security purposes. (In |
433 * contrast, on Solaris the LD_LIBRARY_PATH variable for a |
440 * contrast, on Solaris the LD_LIBRARY_PATH variable for a |
434 * privileged binary does not lose its settings; but the dynamic |
441 * privileged binary does not lose its settings; but the dynamic |
440 * be found must be handled through other mechanisms. |
447 * be found must be handled through other mechanisms. |
441 */ |
448 */ |
442 if((getgid() != getegid()) || (getuid() != geteuid()) ) { |
449 if((getgid() != getegid()) || (getuid() != geteuid()) ) { |
443 return; |
450 return; |
444 } |
451 } |
|
452 #elif defined(_ALLBSD_SOURCE) |
|
453 /* |
|
454 * On BSD, if a binary is running as sgid or suid, libc sets |
|
455 * LD_LIBRARY_PATH to the empty string for security purposes. (In |
|
456 * contrast, on Solaris the LD_LIBRARY_PATH variable for a |
|
457 * privileged binary does not lose its settings; but the dynamic |
|
458 * linker does apply more scrutiny to the path.) The launcher uses |
|
459 * the value of LD_LIBRARY_PATH to prevent an exec loop. |
|
460 * Therefore, if we are running sgid or suid, this function's |
|
461 * setting of LD_LIBRARY_PATH will be ineffective and we should |
|
462 * return from the function now. Getting the right libraries to |
|
463 * be found must be handled through other mechanisms. |
|
464 */ |
|
465 if(issetugid()) { |
|
466 return; |
|
467 } |
445 #endif |
468 #endif |
446 |
469 |
447 /* runpath contains current effective LD_LIBRARY_PATH setting */ |
470 /* runpath contains current effective LD_LIBRARY_PATH setting */ |
448 |
471 |
449 jvmpath = JLI_StringDup(jvmpath); |
472 jvmpath = JLI_StringDup(jvmpath); |
450 new_runpath = JLI_MemAlloc( ((runpath!=NULL)?strlen(runpath):0) + |
473 new_runpath = JLI_MemAlloc( ((runpath!=NULL)?strlen(runpath):0) + |
451 2*strlen(jrepath) + 2*strlen(arch) + |
474 2*strlen(jrepath) + 2*strlen(arch) + |
452 strlen(jvmpath) + 52); |
475 strlen(jvmpath) + 52); |
453 newpath = new_runpath + strlen("LD_LIBRARY_PATH="); |
476 newpath = new_runpath + strlen(LD_LIBRARY_PATH "="); |
454 |
477 |
455 |
478 |
456 /* |
479 /* |
457 * Create desired LD_LIBRARY_PATH value for target data model. |
480 * Create desired LD_LIBRARY_PATH value for target data model. |
458 */ |
481 */ |
790 * "/foo" into buf. |
813 * "/foo" into buf. |
791 */ |
814 */ |
792 jboolean |
815 jboolean |
793 GetApplicationHome(char *buf, jint bufsize) |
816 GetApplicationHome(char *buf, jint bufsize) |
794 { |
817 { |
795 #ifdef __linux__ |
818 #if defined(__linux__) || defined(_ALLBSD_SOURCE) |
796 char *execname = GetExecname(); |
819 char *execname = GetExecname(); |
797 if (execname) { |
820 if (execname) { |
798 strncpy(buf, execname, bufsize-1); |
821 strncpy(buf, execname, bufsize-1); |
799 buf[bufsize-1] = '\0'; |
822 buf[bufsize-1] = '\0'; |
800 } else { |
823 } else { |
1173 #endif |
1196 #endif |
1174 } |
1197 } |
1175 |
1198 |
1176 #endif /* __sun && i586 */ |
1199 #endif /* __sun && i586 */ |
1177 |
1200 |
1178 #if defined(__linux__) && defined(i586) |
1201 #if (defined(__linux__) || defined(_ALLBSD_SOURCE)) && defined(i586) |
1179 |
1202 |
1180 /* |
1203 /* |
1181 * A utility method for asking the CPU about itself. |
1204 * A utility method for asking the CPU about itself. |
1182 * There's a corresponding version of solaris-i586 |
1205 * There's a corresponding version of solaris-i586 |
1183 * because the compilers are different. |
1206 * because the compilers are different. |
1450 return result; |
1473 return result; |
1451 } |
1474 } |
1452 |
1475 |
1453 #endif /* __linux__ && i586 */ |
1476 #endif /* __linux__ && i586 */ |
1454 |
1477 |
|
1478 #if defined(_ALLBSD_SOURCE) && defined(i586) |
|
1479 |
|
1480 /* The definition of a server-class machine for bsd-i586 */ |
|
1481 jboolean |
|
1482 bsd_i586_ServerClassMachine(void) { |
|
1483 jboolean result = JNI_FALSE; |
|
1484 /* How big is a server class machine? */ |
|
1485 const unsigned long server_processors = 2UL; |
|
1486 const uint64_t server_memory = 2UL * GB; |
|
1487 /* |
|
1488 * We seem not to get our full complement of memory. |
|
1489 * We allow some part (1/8?) of the memory to be "missing", |
|
1490 * based on the sizes of DIMMs, and maybe graphics cards. |
|
1491 */ |
|
1492 const uint64_t missing_memory = 256UL * MB; |
|
1493 const uint64_t actual_memory = physical_memory(); |
|
1494 |
|
1495 /* Is this a server class machine? */ |
|
1496 if (actual_memory >= (server_memory - missing_memory)) { |
|
1497 const unsigned long actual_processors = physical_processors(); |
|
1498 if (actual_processors >= server_processors) { |
|
1499 result = JNI_TRUE; |
|
1500 } |
|
1501 } |
|
1502 if (_launcher_debug) { |
|
1503 printf("linux_" LIBARCHNAME "_ServerClassMachine: %s\n", |
|
1504 (result == JNI_TRUE ? "true" : "false")); |
|
1505 } |
|
1506 return result; |
|
1507 } |
|
1508 |
|
1509 #endif /* _ALLBSD_SOURCE && i586 */ |
|
1510 |
1455 /* Dispatch to the platform-specific definition of "server-class" */ |
1511 /* Dispatch to the platform-specific definition of "server-class" */ |
1456 jboolean |
1512 jboolean |
1457 ServerClassMachine(void) { |
1513 ServerClassMachine(void) { |
1458 jboolean result = JNI_FALSE; |
1514 jboolean result = JNI_FALSE; |
1459 #if defined(NEVER_ACT_AS_SERVER_CLASS_MACHINE) |
1515 #if defined(NEVER_ACT_AS_SERVER_CLASS_MACHINE) |
1464 result = solaris_sparc_ServerClassMachine(); |
1520 result = solaris_sparc_ServerClassMachine(); |
1465 #elif defined(__sun) && defined(i586) |
1521 #elif defined(__sun) && defined(i586) |
1466 result = solaris_i586_ServerClassMachine(); |
1522 result = solaris_i586_ServerClassMachine(); |
1467 #elif defined(__linux__) && defined(i586) |
1523 #elif defined(__linux__) && defined(i586) |
1468 result = linux_i586_ServerClassMachine(); |
1524 result = linux_i586_ServerClassMachine(); |
|
1525 #elif defined(_ALLBSD_SOURCE) && defined(i586) |
|
1526 result = bsd_i586_ServerClassMachine(); |
1469 #else |
1527 #else |
1470 if (_launcher_debug) { |
1528 if (_launcher_debug) { |
1471 printf("ServerClassMachine: returns default value of %s\n", |
1529 printf("ServerClassMachine: returns default value of %s\n", |
1472 (result == JNI_TRUE ? "true" : "false")); |
1530 (result == JNI_TRUE ? "true" : "false")); |
1473 } |
1531 } |
1819 * Block current thread and continue execution in a new thread |
1877 * Block current thread and continue execution in a new thread |
1820 */ |
1878 */ |
1821 int |
1879 int |
1822 ContinueInNewThread(int (JNICALL *continuation)(void *), jlong stack_size, void * args) { |
1880 ContinueInNewThread(int (JNICALL *continuation)(void *), jlong stack_size, void * args) { |
1823 int rslt; |
1881 int rslt; |
1824 #ifdef __linux__ |
1882 #if defined(__linux__) || defined(_ALLBSD_SOURCE) |
1825 pthread_t tid; |
1883 pthread_t tid; |
1826 pthread_attr_t attr; |
1884 pthread_attr_t attr; |
1827 pthread_attr_init(&attr); |
1885 pthread_attr_init(&attr); |
1828 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); |
1886 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); |
1829 |
1887 |