1.1 --- a/src/os/posix/launcher/java_md.c Tue Sep 20 23:50:16 2011 -0700 1.2 +++ b/src/os/posix/launcher/java_md.c Sun Sep 25 16:03:29 2011 -0700 1.3 @@ -41,14 +41,21 @@ 1.4 #include "version_comp.h" 1.5 #endif 1.6 1.7 -#ifdef __linux__ 1.8 +#if defined(__linux__) || defined(_ALLBSD_SOURCE) 1.9 #include <pthread.h> 1.10 #else 1.11 #include <thread.h> 1.12 #endif 1.13 1.14 +#ifdef __APPLE__ 1.15 +#define JVM_DLL "libjvm.dylib" 1.16 +#define JAVA_DLL "libjava.dylib" 1.17 +#define LD_LIBRARY_PATH "DYLD_LIBRARY_PATH" 1.18 +#else 1.19 #define JVM_DLL "libjvm.so" 1.20 #define JAVA_DLL "libjava.so" 1.21 +#define LD_LIBRARY_PATH "LD_LIBRARY_PATH" 1.22 +#endif 1.23 1.24 #ifndef GAMMA /* launcher.make defines ARCH */ 1.25 /* 1.26 @@ -423,10 +430,10 @@ 1.27 * If not on Solaris, assume only a single LD_LIBRARY_PATH 1.28 * variable. 1.29 */ 1.30 - runpath = getenv("LD_LIBRARY_PATH"); 1.31 + runpath = getenv(LD_LIBRARY_PATH); 1.32 #endif /* __sun */ 1.33 1.34 -#ifdef __linux 1.35 +#if defined(__linux__) 1.36 /* 1.37 * On linux, if a binary is running as sgid or suid, glibc sets 1.38 * LD_LIBRARY_PATH to the empty string for security purposes. (In 1.39 @@ -442,6 +449,22 @@ 1.40 if((getgid() != getegid()) || (getuid() != geteuid()) ) { 1.41 return; 1.42 } 1.43 +#elif defined(_ALLBSD_SOURCE) 1.44 + /* 1.45 + * On BSD, if a binary is running as sgid or suid, libc sets 1.46 + * LD_LIBRARY_PATH to the empty string for security purposes. (In 1.47 + * contrast, on Solaris the LD_LIBRARY_PATH variable for a 1.48 + * privileged binary does not lose its settings; but the dynamic 1.49 + * linker does apply more scrutiny to the path.) The launcher uses 1.50 + * the value of LD_LIBRARY_PATH to prevent an exec loop. 1.51 + * Therefore, if we are running sgid or suid, this function's 1.52 + * setting of LD_LIBRARY_PATH will be ineffective and we should 1.53 + * return from the function now. Getting the right libraries to 1.54 + * be found must be handled through other mechanisms. 1.55 + */ 1.56 + if(issetugid()) { 1.57 + return; 1.58 + } 1.59 #endif 1.60 1.61 /* runpath contains current effective LD_LIBRARY_PATH setting */ 1.62 @@ -450,7 +473,7 @@ 1.63 new_runpath = JLI_MemAlloc( ((runpath!=NULL)?strlen(runpath):0) + 1.64 2*strlen(jrepath) + 2*strlen(arch) + 1.65 strlen(jvmpath) + 52); 1.66 - newpath = new_runpath + strlen("LD_LIBRARY_PATH="); 1.67 + newpath = new_runpath + strlen(LD_LIBRARY_PATH "="); 1.68 1.69 1.70 /* 1.71 @@ -465,7 +488,7 @@ 1.72 1.73 /* jvmpath, ((running != wanted)?((wanted==64)?"/"LIBARCH64NAME:"/.."):""), */ 1.74 1.75 - sprintf(new_runpath, "LD_LIBRARY_PATH=" 1.76 + sprintf(new_runpath, LD_LIBRARY_PATH "=" 1.77 "%s:" 1.78 "%s/lib/%s:" 1.79 "%s/../lib/%s", 1.80 @@ -792,7 +815,7 @@ 1.81 jboolean 1.82 GetApplicationHome(char *buf, jint bufsize) 1.83 { 1.84 -#ifdef __linux__ 1.85 +#if defined(__linux__) || defined(_ALLBSD_SOURCE) 1.86 char *execname = GetExecname(); 1.87 if (execname) { 1.88 strncpy(buf, execname, bufsize-1); 1.89 @@ -1175,7 +1198,7 @@ 1.90 1.91 #endif /* __sun && i586 */ 1.92 1.93 -#if defined(__linux__) && defined(i586) 1.94 +#if (defined(__linux__) || defined(_ALLBSD_SOURCE)) && defined(i586) 1.95 1.96 /* 1.97 * A utility method for asking the CPU about itself. 1.98 @@ -1452,6 +1475,39 @@ 1.99 1.100 #endif /* __linux__ && i586 */ 1.101 1.102 +#if defined(_ALLBSD_SOURCE) && defined(i586) 1.103 + 1.104 +/* The definition of a server-class machine for bsd-i586 */ 1.105 +jboolean 1.106 +bsd_i586_ServerClassMachine(void) { 1.107 + jboolean result = JNI_FALSE; 1.108 + /* How big is a server class machine? */ 1.109 + const unsigned long server_processors = 2UL; 1.110 + const uint64_t server_memory = 2UL * GB; 1.111 + /* 1.112 + * We seem not to get our full complement of memory. 1.113 + * We allow some part (1/8?) of the memory to be "missing", 1.114 + * based on the sizes of DIMMs, and maybe graphics cards. 1.115 + */ 1.116 + const uint64_t missing_memory = 256UL * MB; 1.117 + const uint64_t actual_memory = physical_memory(); 1.118 + 1.119 + /* Is this a server class machine? */ 1.120 + if (actual_memory >= (server_memory - missing_memory)) { 1.121 + const unsigned long actual_processors = physical_processors(); 1.122 + if (actual_processors >= server_processors) { 1.123 + result = JNI_TRUE; 1.124 + } 1.125 + } 1.126 + if (_launcher_debug) { 1.127 + printf("linux_" LIBARCHNAME "_ServerClassMachine: %s\n", 1.128 + (result == JNI_TRUE ? "true" : "false")); 1.129 + } 1.130 + return result; 1.131 +} 1.132 + 1.133 +#endif /* _ALLBSD_SOURCE && i586 */ 1.134 + 1.135 /* Dispatch to the platform-specific definition of "server-class" */ 1.136 jboolean 1.137 ServerClassMachine(void) { 1.138 @@ -1466,6 +1522,8 @@ 1.139 result = solaris_i586_ServerClassMachine(); 1.140 #elif defined(__linux__) && defined(i586) 1.141 result = linux_i586_ServerClassMachine(); 1.142 +#elif defined(_ALLBSD_SOURCE) && defined(i586) 1.143 + result = bsd_i586_ServerClassMachine(); 1.144 #else 1.145 if (_launcher_debug) { 1.146 printf("ServerClassMachine: returns default value of %s\n", 1.147 @@ -1821,7 +1879,7 @@ 1.148 int 1.149 ContinueInNewThread(int (JNICALL *continuation)(void *), jlong stack_size, void * args) { 1.150 int rslt; 1.151 -#ifdef __linux__ 1.152 +#if defined(__linux__) || defined(_ALLBSD_SOURCE) 1.153 pthread_t tid; 1.154 pthread_attr_t attr; 1.155 pthread_attr_init(&attr);