< prev index next >

src/hotspot/os/windows/os_windows.cpp

Print this page




1350   return (vm_lib_location[0] <= addr) && (addr < vm_lib_location[1]);
1351 }
1352 
1353 // print module info; param is outputStream*
1354 static int _print_module(const char* fname, address base_address,
1355                          address top_address, void* param) {
1356   if (!param) return -1;
1357 
1358   outputStream* st = (outputStream*)param;
1359 
1360   st->print(PTR_FORMAT " - " PTR_FORMAT " \t%s\n", base_address, top_address, fname);
1361   return 0;
1362 }
1363 
1364 // Loads .dll/.so and
1365 // in case of error it checks if .dll/.so was built for the
1366 // same architecture as Hotspot is running on
1367 void * os::dll_load(const char *name, char *ebuf, int ebuflen) {
1368   void * result = LoadLibrary(name);
1369   if (result != NULL) {
1370     Events::log(NULL, "Loaded shared library %s", name);
1371     // Recalculate pdb search path if a DLL was loaded successfully.
1372     SymbolEngine::recalc_search_path();
1373     return result;
1374   }
1375   DWORD errcode = GetLastError();
1376   // Read system error message into ebuf
1377   // It may or may not be overwritten below (in the for loop and just above)
1378   lasterror(ebuf, (size_t) ebuflen);
1379   ebuf[ebuflen - 1] = '\0';
1380   Events::log(NULL, "Loading shared library %s failed, error code %lu", name, errcode);
1381 

1382   if (errcode == ERROR_MOD_NOT_FOUND) {
1383     strncpy(ebuf, "Can't find dependent libraries", ebuflen - 1);
1384     ebuf[ebuflen - 1] = '\0';
1385     return NULL;
1386   }
1387 
1388   // Parsing dll below
1389   // If we can read dll-info and find that dll was built
1390   // for an architecture other than Hotspot is running in
1391   // - then print to buffer "DLL was built for a different architecture"
1392   // else call os::lasterror to obtain system error message





1393   int fd = ::open(name, O_RDONLY | O_BINARY, 0);
1394   if (fd < 0) {
1395     return NULL;
1396   }
1397 
1398   uint32_t signature_offset;
1399   uint16_t lib_arch = 0;
1400   bool failed_to_get_lib_arch =
1401     ( // Go to position 3c in the dll
1402      (os::seek_to_file_offset(fd, IMAGE_FILE_PTR_TO_SIGNATURE) < 0)
1403      ||
1404      // Read location of signature
1405      (sizeof(signature_offset) !=
1406      (os::read(fd, (void*)&signature_offset, sizeof(signature_offset))))
1407      ||
1408      // Go to COFF File Header in dll
1409      // that is located after "signature" (4 bytes long)
1410      (os::seek_to_file_offset(fd,
1411      signature_offset + IMAGE_FILE_SIGNATURE_LENGTH) < 0)
1412      ||


4893   }
4894 
4895   if (allow_exec) {
4896     // CreateFileMapping/MapViewOfFileEx can't map executable memory
4897     // unless it comes from a PE image (which the shared archive is not.)
4898     // Even VirtualProtect refuses to give execute access to mapped memory
4899     // that was not previously executable.
4900     //
4901     // Instead, stick the executable region in anonymous memory.  Yuck.
4902     // Penalty is that ~4 pages will not be shareable - in the future
4903     // we might consider DLLizing the shared archive with a proper PE
4904     // header so that mapping executable + sharing is possible.
4905 
4906     base = (char*) VirtualAlloc(addr, bytes, MEM_COMMIT | MEM_RESERVE,
4907                                 PAGE_READWRITE);
4908     if (base == NULL) {
4909       log_info(os)("VirtualAlloc() failed: GetLastError->%ld.", GetLastError());
4910       CloseHandle(hFile);
4911       return NULL;
4912     }
4913 
4914     // Record virtual memory allocation
4915     MemTracker::record_virtual_memory_reserve_and_commit((address)addr, bytes, CALLER_PC);
4916 
4917     DWORD bytes_read;
4918     OVERLAPPED overlapped;
4919     overlapped.Offset = (DWORD)file_offset;
4920     overlapped.OffsetHigh = 0;
4921     overlapped.hEvent = NULL;
4922     // ReadFile guarantees that if the return value is true, the requested
4923     // number of bytes were read before returning.
4924     bool res = ReadFile(hFile, base, (DWORD)bytes, &bytes_read, &overlapped) != 0;
4925     if (!res) {
4926       log_info(os)("ReadFile() failed: GetLastError->%ld.", GetLastError());
4927       release_memory(base, bytes);
4928       CloseHandle(hFile);
4929       return NULL;
4930     }
4931   } else {
4932     HANDLE hMap = CreateFileMapping(hFile, NULL, PAGE_WRITECOPY, 0, 0,
4933                                     NULL /* file_name */);
4934     if (hMap == NULL) {
4935       log_info(os)("CreateFileMapping() failed: GetLastError->%ld.", GetLastError());




1350   return (vm_lib_location[0] <= addr) && (addr < vm_lib_location[1]);
1351 }
1352 
1353 // print module info; param is outputStream*
1354 static int _print_module(const char* fname, address base_address,
1355                          address top_address, void* param) {
1356   if (!param) return -1;
1357 
1358   outputStream* st = (outputStream*)param;
1359 
1360   st->print(PTR_FORMAT " - " PTR_FORMAT " \t%s\n", base_address, top_address, fname);
1361   return 0;
1362 }
1363 
1364 // Loads .dll/.so and
1365 // in case of error it checks if .dll/.so was built for the
1366 // same architecture as Hotspot is running on
1367 void * os::dll_load(const char *name, char *ebuf, int ebuflen) {
1368   void * result = LoadLibrary(name);
1369   if (result != NULL) {

1370     // Recalculate pdb search path if a DLL was loaded successfully.
1371     SymbolEngine::recalc_search_path();
1372     return result;
1373   }






1374 
1375   DWORD errcode = GetLastError();
1376   if (errcode == ERROR_MOD_NOT_FOUND) {
1377     strncpy(ebuf, "Can't find dependent libraries", ebuflen - 1);
1378     ebuf[ebuflen - 1] = '\0';
1379     return NULL;
1380   }
1381 
1382   // Parsing dll below
1383   // If we can read dll-info and find that dll was built
1384   // for an architecture other than Hotspot is running in
1385   // - then print to buffer "DLL was built for a different architecture"
1386   // else call os::lasterror to obtain system error message
1387 
1388   // Read system error message into ebuf
1389   // It may or may not be overwritten below (in the for loop and just above)
1390   lasterror(ebuf, (size_t) ebuflen);
1391   ebuf[ebuflen - 1] = '\0';
1392   int fd = ::open(name, O_RDONLY | O_BINARY, 0);
1393   if (fd < 0) {
1394     return NULL;
1395   }
1396 
1397   uint32_t signature_offset;
1398   uint16_t lib_arch = 0;
1399   bool failed_to_get_lib_arch =
1400     ( // Go to position 3c in the dll
1401      (os::seek_to_file_offset(fd, IMAGE_FILE_PTR_TO_SIGNATURE) < 0)
1402      ||
1403      // Read location of signature
1404      (sizeof(signature_offset) !=
1405      (os::read(fd, (void*)&signature_offset, sizeof(signature_offset))))
1406      ||
1407      // Go to COFF File Header in dll
1408      // that is located after "signature" (4 bytes long)
1409      (os::seek_to_file_offset(fd,
1410      signature_offset + IMAGE_FILE_SIGNATURE_LENGTH) < 0)
1411      ||


4892   }
4893 
4894   if (allow_exec) {
4895     // CreateFileMapping/MapViewOfFileEx can't map executable memory
4896     // unless it comes from a PE image (which the shared archive is not.)
4897     // Even VirtualProtect refuses to give execute access to mapped memory
4898     // that was not previously executable.
4899     //
4900     // Instead, stick the executable region in anonymous memory.  Yuck.
4901     // Penalty is that ~4 pages will not be shareable - in the future
4902     // we might consider DLLizing the shared archive with a proper PE
4903     // header so that mapping executable + sharing is possible.
4904 
4905     base = (char*) VirtualAlloc(addr, bytes, MEM_COMMIT | MEM_RESERVE,
4906                                 PAGE_READWRITE);
4907     if (base == NULL) {
4908       log_info(os)("VirtualAlloc() failed: GetLastError->%ld.", GetLastError());
4909       CloseHandle(hFile);
4910       return NULL;
4911     }



4912 
4913     DWORD bytes_read;
4914     OVERLAPPED overlapped;
4915     overlapped.Offset = (DWORD)file_offset;
4916     overlapped.OffsetHigh = 0;
4917     overlapped.hEvent = NULL;
4918     // ReadFile guarantees that if the return value is true, the requested
4919     // number of bytes were read before returning.
4920     bool res = ReadFile(hFile, base, (DWORD)bytes, &bytes_read, &overlapped) != 0;
4921     if (!res) {
4922       log_info(os)("ReadFile() failed: GetLastError->%ld.", GetLastError());
4923       release_memory(base, bytes);
4924       CloseHandle(hFile);
4925       return NULL;
4926     }
4927   } else {
4928     HANDLE hMap = CreateFileMapping(hFile, NULL, PAGE_WRITECOPY, 0, 0,
4929                                     NULL /* file_name */);
4930     if (hMap == NULL) {
4931       log_info(os)("CreateFileMapping() failed: GetLastError->%ld.", GetLastError());


< prev index next >