262 263 // Helper for dll_locate_lib. 264 // Pass buffer and printbuffer as we already printed the path to buffer 265 // when we called get_current_directory. This way we avoid another buffer 266 // of size MAX_PATH. 267 static bool conc_path_file_and_check(char *buffer, char *printbuffer, size_t printbuflen, 268 const char* pname, char lastchar, const char* fname) { 269 270 // Concatenate path and file name, but don't print double path separators. 271 const char *filesep = (WINDOWS_ONLY(lastchar == ':' ||) lastchar == os::file_separator()[0]) ? 272 "" : os::file_separator(); 273 int ret = jio_snprintf(printbuffer, printbuflen, "%s%s%s", pname, filesep, fname); 274 // Check whether file exists. 275 if (ret != -1) { 276 struct stat statbuf; 277 return os::stat(buffer, &statbuf) == 0; 278 } 279 return false; 280 } 281 282 bool os::dll_locate_lib(char *buffer, size_t buflen, 283 const char* pname, const char* fname) { 284 bool retval = false; 285 286 size_t fullfnamelen = strlen(JNI_LIB_PREFIX) + strlen(fname) + strlen(JNI_LIB_SUFFIX); 287 char* fullfname = (char*)NEW_C_HEAP_ARRAY(char, fullfnamelen + 1, mtInternal); 288 if (dll_build_name(fullfname, fullfnamelen + 1, fname)) { 289 const size_t pnamelen = pname ? strlen(pname) : 0; 290 291 if (pnamelen == 0) { 292 // If no path given, use current working directory. 293 const char* p = get_current_directory(buffer, buflen); 294 if (p != NULL) { 295 const size_t plen = strlen(buffer); 296 const char lastchar = buffer[plen - 1]; 297 retval = conc_path_file_and_check(buffer, &buffer[plen], buflen - plen, 298 "", lastchar, fullfname); 299 } 300 } else if (strchr(pname, *os::path_separator()) != NULL) { 301 // A list of paths. Search for the path that contains the library. 302 int n; 303 char** pelements = split_path(pname, &n); 304 if (pelements != NULL) { 305 for (int i = 0; i < n; i++) { 306 char* path = pelements[i]; 307 // Really shouldn't be NULL, but check can't hurt. 308 size_t plen = (path == NULL) ? 0 : strlen(path); 309 if (plen == 0) { 310 continue; // Skip the empty path values. 311 } 312 const char lastchar = path[plen - 1]; 313 retval = conc_path_file_and_check(buffer, buffer, buflen, path, lastchar, fullfname); 314 if (retval) break; 315 } 316 // Release the storage allocated by split_path. 317 for (int i = 0; i < n; i++) { 318 if (pelements[i] != NULL) { 319 FREE_C_HEAP_ARRAY(char, pelements[i]); 320 } 321 } 322 FREE_C_HEAP_ARRAY(char*, pelements); 323 } 324 } else { 325 // A definite path. 326 const char lastchar = pname[pnamelen-1]; 327 retval = conc_path_file_and_check(buffer, buffer, buflen, pname, lastchar, fullfname); 328 } 329 } 330 331 FREE_C_HEAP_ARRAY(char*, fullfname); 332 return retval; 333 } 334 335 // --------------------- sun.misc.Signal (optional) --------------------- 336 337 338 // SIGBREAK is sent by the keyboard to query the VM state 339 #ifndef SIGBREAK 340 #define SIGBREAK SIGQUIT 341 #endif 342 1295 if (has_jimage) { 1296 Arguments::set_sysclasspath(jimage, true); 1297 FREE_C_HEAP_ARRAY(char, jimage); 1298 return true; 1299 } 1300 FREE_C_HEAP_ARRAY(char, jimage); 1301 1302 // check if developer build with exploded modules 1303 char* base_classes = format_boot_path("%/modules/" JAVA_BASE_NAME, home, home_len, fileSep, pathSep); 1304 if (base_classes == NULL) return false; 1305 if (os::stat(base_classes, &st) == 0) { 1306 Arguments::set_sysclasspath(base_classes, false); 1307 FREE_C_HEAP_ARRAY(char, base_classes); 1308 return true; 1309 } 1310 FREE_C_HEAP_ARRAY(char, base_classes); 1311 1312 return false; 1313 } 1314 1315 /* 1316 * Splits a path, based on its separator, the number of 1317 * elements is returned back in n. 1318 * It is the callers responsibility to: 1319 * a> check the value of n, and n may be 0. 1320 * b> ignore any empty path elements 1321 * c> free up the data. 1322 */ 1323 char** os::split_path(const char* path, int* n) { 1324 *n = 0; 1325 if (path == NULL || strlen(path) == 0) { 1326 return NULL; 1327 } 1328 const char psepchar = *os::path_separator(); 1329 char* inpath = (char*)NEW_C_HEAP_ARRAY(char, strlen(path) + 1, mtInternal); 1330 if (inpath == NULL) { 1331 return NULL; 1332 } 1333 strcpy(inpath, path); 1334 int count = 1; 1335 char* p = strchr(inpath, psepchar); 1336 // Get a count of elements to allocate memory 1337 while (p != NULL) { 1338 count++; 1339 p++; 1340 p = strchr(p, psepchar); 1341 } 1342 char** opath = (char**) NEW_C_HEAP_ARRAY(char*, count, mtInternal); 1343 if (opath == NULL) { 1344 return NULL; 1345 } 1346 1347 // do the actual splitting 1348 p = inpath; 1349 for (int i = 0 ; i < count ; i++) { 1350 size_t len = strcspn(p, os::path_separator()); 1351 if (len > JVM_MAXPATHLEN) { 1352 return NULL; 1353 } 1354 // allocate the string and add terminator storage 1355 char* s = (char*)NEW_C_HEAP_ARRAY(char, len + 1, mtInternal); 1356 if (s == NULL) { 1357 return NULL; 1358 } 1359 strncpy(s, p, len); 1360 s[len] = '\0'; 1361 opath[i] = s; 1362 p += len + 1; 1363 } 1364 FREE_C_HEAP_ARRAY(char, inpath); 1365 *n = count; 1366 return opath; 1367 } 1368 1369 // Returns true if the current stack pointer is above the stack shadow 1370 // pages, false otherwise. 1371 bool os::stack_shadow_pages_available(Thread *thread, const methodHandle& method, address sp) { 1372 if (!thread->is_Java_thread()) return false; 1373 // Check if we have StackShadowPages above the yellow zone. This parameter 1374 // is dependent on the depth of the maximum VM call stack possible from 1375 // the handler for stack overflow. 'instanceof' in the stack overflow 1376 // handler or a println uses at least 8k stack of VM and native code 1377 // respectively. 1378 const int framesize_in_bytes = 1379 Interpreter::size_top_interpreter_activation(method()) * wordSize; 1380 1381 address limit = ((JavaThread*)thread)->stack_end() + 1382 (JavaThread::stack_guard_zone_size() + JavaThread::stack_shadow_zone_size()); 1383 1384 return sp > (limit + framesize_in_bytes); 1385 } | 262 263 // Helper for dll_locate_lib. 264 // Pass buffer and printbuffer as we already printed the path to buffer 265 // when we called get_current_directory. This way we avoid another buffer 266 // of size MAX_PATH. 267 static bool conc_path_file_and_check(char *buffer, char *printbuffer, size_t printbuflen, 268 const char* pname, char lastchar, const char* fname) { 269 270 // Concatenate path and file name, but don't print double path separators. 271 const char *filesep = (WINDOWS_ONLY(lastchar == ':' ||) lastchar == os::file_separator()[0]) ? 272 "" : os::file_separator(); 273 int ret = jio_snprintf(printbuffer, printbuflen, "%s%s%s", pname, filesep, fname); 274 // Check whether file exists. 275 if (ret != -1) { 276 struct stat statbuf; 277 return os::stat(buffer, &statbuf) == 0; 278 } 279 return false; 280 } 281 282 // Frees all memory allocated on the heap for the 283 // supplied array of arrays of chars (a), where n 284 // is the number of elements in the array. 285 static void free_array_of_char_arrays(char** a, size_t n) { 286 while (n > 0) { 287 n--; 288 if (a[n] != NULL) { 289 FREE_C_HEAP_ARRAY(char, a[n]); 290 } 291 } 292 FREE_C_HEAP_ARRAY(char*, a); 293 } 294 295 bool os::dll_locate_lib(char *buffer, size_t buflen, 296 const char* pname, const char* fname) { 297 bool retval = false; 298 299 size_t fullfnamelen = strlen(JNI_LIB_PREFIX) + strlen(fname) + strlen(JNI_LIB_SUFFIX); 300 char* fullfname = (char*)NEW_C_HEAP_ARRAY(char, fullfnamelen + 1, mtInternal); 301 if (dll_build_name(fullfname, fullfnamelen + 1, fname)) { 302 const size_t pnamelen = pname ? strlen(pname) : 0; 303 304 if (pnamelen == 0) { 305 // If no path given, use current working directory. 306 const char* p = get_current_directory(buffer, buflen); 307 if (p != NULL) { 308 const size_t plen = strlen(buffer); 309 const char lastchar = buffer[plen - 1]; 310 retval = conc_path_file_and_check(buffer, &buffer[plen], buflen - plen, 311 "", lastchar, fullfname); 312 } 313 } else if (strchr(pname, *os::path_separator()) != NULL) { 314 // A list of paths. Search for the path that contains the library. 315 size_t n; 316 char** pelements = split_path(pname, &n, fullfnamelen); 317 if (pelements != NULL) { 318 for (size_t i = 0; i < n; i++) { 319 char* path = pelements[i]; 320 // Really shouldn't be NULL, but check can't hurt. 321 size_t plen = (path == NULL) ? 0 : strlen(path); 322 if (plen == 0) { 323 continue; // Skip the empty path values. 324 } 325 const char lastchar = path[plen - 1]; 326 retval = conc_path_file_and_check(buffer, buffer, buflen, path, lastchar, fullfname); 327 if (retval) break; 328 } 329 // Release the storage allocated by split_path. 330 free_array_of_char_arrays(pelements, n); 331 } 332 } else { 333 // A definite path. 334 const char lastchar = pname[pnamelen-1]; 335 retval = conc_path_file_and_check(buffer, buffer, buflen, pname, lastchar, fullfname); 336 } 337 } 338 339 FREE_C_HEAP_ARRAY(char*, fullfname); 340 return retval; 341 } 342 343 // --------------------- sun.misc.Signal (optional) --------------------- 344 345 346 // SIGBREAK is sent by the keyboard to query the VM state 347 #ifndef SIGBREAK 348 #define SIGBREAK SIGQUIT 349 #endif 350 1303 if (has_jimage) { 1304 Arguments::set_sysclasspath(jimage, true); 1305 FREE_C_HEAP_ARRAY(char, jimage); 1306 return true; 1307 } 1308 FREE_C_HEAP_ARRAY(char, jimage); 1309 1310 // check if developer build with exploded modules 1311 char* base_classes = format_boot_path("%/modules/" JAVA_BASE_NAME, home, home_len, fileSep, pathSep); 1312 if (base_classes == NULL) return false; 1313 if (os::stat(base_classes, &st) == 0) { 1314 Arguments::set_sysclasspath(base_classes, false); 1315 FREE_C_HEAP_ARRAY(char, base_classes); 1316 return true; 1317 } 1318 FREE_C_HEAP_ARRAY(char, base_classes); 1319 1320 return false; 1321 } 1322 1323 // Splits a path, based on its separator, the number of 1324 // elements is returned back in "elements". 1325 // file_name_length is used as a modifier for each path's 1326 // length when compared to JVM_MAXPATHLEN. So if you know 1327 // each returned path will have something appended when 1328 // in use, you can pass the length of that in 1329 // file_name_length, to ensure we detect if any path 1330 // exceeds the maximum path length once prepended onto 1331 // the sub-path/file name. 1332 // It is the callers responsibility to: 1333 // a> check the value of "elements", which may be 0. 1334 // b> ignore any empty path elements 1335 // c> free up the data. 1336 char** os::split_path(const char* path, size_t* elements, size_t file_name_length) { 1337 *elements = (size_t)0; 1338 if (path == NULL || strlen(path) == 0 || file_name_length == (size_t)NULL) { 1339 return NULL; 1340 } 1341 const char psepchar = *os::path_separator(); 1342 char* inpath = (char*)NEW_C_HEAP_ARRAY(char, strlen(path) + 1, mtInternal); 1343 if (inpath == NULL) { 1344 return NULL; 1345 } 1346 strcpy(inpath, path); 1347 size_t count = 1; 1348 char* p = strchr(inpath, psepchar); 1349 // Get a count of elements to allocate memory 1350 while (p != NULL) { 1351 count++; 1352 p++; 1353 p = strchr(p, psepchar); 1354 } 1355 char** opath = (char**) NEW_C_HEAP_ARRAY(char*, count, mtInternal); 1356 1357 // do the actual splitting 1358 p = inpath; 1359 for (size_t i = 0 ; i < count ; i++) { 1360 size_t len = strcspn(p, os::path_separator()); 1361 if (len + file_name_length > JVM_MAXPATHLEN) { 1362 // release allocated storage before exiting the vm 1363 free_array_of_char_arrays(opath, i++); 1364 vm_exit_during_initialization("The VM tried to use a path that exceeds the maximum path length for " 1365 "this system. Review path-containing parameters and properties, such as " 1366 "sun.boot.library.path, to identify potential sources for this path."); 1367 } 1368 // allocate the string and add terminator storage 1369 char* s = (char*)NEW_C_HEAP_ARRAY_RETURN_NULL(char, len + 1, mtInternal); 1370 if (s == NULL) { 1371 // release allocated storage before returning null 1372 free_array_of_char_arrays(opath, i++); 1373 return NULL; 1374 } 1375 strncpy(s, p, len); 1376 s[len] = '\0'; 1377 opath[i] = s; 1378 p += len + 1; 1379 } 1380 FREE_C_HEAP_ARRAY(char, inpath); 1381 *elements = count; 1382 return opath; 1383 } 1384 1385 // Returns true if the current stack pointer is above the stack shadow 1386 // pages, false otherwise. 1387 bool os::stack_shadow_pages_available(Thread *thread, const methodHandle& method, address sp) { 1388 if (!thread->is_Java_thread()) return false; 1389 // Check if we have StackShadowPages above the yellow zone. This parameter 1390 // is dependent on the depth of the maximum VM call stack possible from 1391 // the handler for stack overflow. 'instanceof' in the stack overflow 1392 // handler or a println uses at least 8k stack of VM and native code 1393 // respectively. 1394 const int framesize_in_bytes = 1395 Interpreter::size_top_interpreter_activation(method()) * wordSize; 1396 1397 address limit = ((JavaThread*)thread)->stack_end() + 1398 (JavaThread::stack_guard_zone_size() + JavaThread::stack_shadow_zone_size()); 1399 1400 return sp > (limit + framesize_in_bytes); 1401 } |