< prev index next >

src/os/windows/vm/os_windows.cpp

Print this page




1134         && (dirp->path[2] == '\0'
1135             || (dirp->path[2] == '\\' && dirp->path[3] == '\0'))) {
1136         /* No '\\' needed for cases like "Z:" or "Z:\" */
1137         strcat(dirp->path, "*.*");
1138     } else {
1139         strcat(dirp->path, "\\*.*");
1140     }
1141 
1142     dirp->handle = FindFirstFile(dirp->path, &dirp->find_data);
1143     if (dirp->handle == INVALID_HANDLE_VALUE) {
1144         if (GetLastError() != ERROR_FILE_NOT_FOUND) {
1145             free(dirp->path, mtInternal);
1146             free(dirp, mtInternal);
1147             errno = EACCES;
1148             return 0;
1149         }
1150     }
1151     return dirp;
1152 }
1153 
1154 /* parameter dbuf unused on Windows */
1155 
1156 struct dirent *
1157 os::readdir(DIR *dirp, dirent *dbuf)
1158 {
1159     assert(dirp != NULL, "just checking");      // hotspot change
1160     if (dirp->handle == INVALID_HANDLE_VALUE) {
1161         return 0;
1162     }
1163 
1164     strcpy(dirp->dirent.d_name, dirp->find_data.cFileName);
1165 
1166     if (!FindNextFile(dirp->handle, &dirp->find_data)) {
1167         if (GetLastError() == ERROR_INVALID_HANDLE) {
1168             errno = EBADF;
1169             return 0;
1170         }
1171         FindClose(dirp->handle);
1172         dirp->handle = INVALID_HANDLE_VALUE;
1173     }
1174 
1175     return &dirp->dirent;
1176 }
1177 
1178 int
1179 os::closedir(DIR *dirp)
1180 {
1181     assert(dirp != NULL, "just checking");      // hotspot change
1182     if (dirp->handle != INVALID_HANDLE_VALUE) {
1183         if (!FindClose(dirp->handle)) {
1184             errno = EBADF;
1185             return -1;
1186         }
1187         dirp->handle = INVALID_HANDLE_VALUE;
1188     }
1189     free(dirp->path, mtInternal);


1633       lib_arch_str,running_arch_str);
1634   }
1635   else
1636   {
1637     // don't know what architecture this dll was build for
1638     ::_snprintf(ebuf, ebuflen-1,
1639       "Can't load this .dll (machine code=0x%x) on a %s-bit platform",
1640       lib_arch,running_arch_str);
1641   }
1642 
1643   return NULL;
1644 }
1645 
1646 
1647 void os::print_dll_info(outputStream *st) {
1648    int pid = os::current_process_id();
1649    st->print_cr("Dynamic libraries:");
1650    enumerate_modules(pid, _print_module, (void *)st);
1651 }
1652 












































1653 void os::print_os_info_brief(outputStream* st) {
1654   os::print_os_info(st);
1655 }
1656 
1657 void os::print_os_info(outputStream* st) {
1658   st->print("OS:");
1659 
1660   os::win32::print_windows_version(st);
1661 }
1662 
1663 void os::win32::print_windows_version(outputStream* st) {
1664   OSVERSIONINFOEX osvi;
1665   VS_FIXEDFILEINFO *file_info;
1666   TCHAR kernel32_path[MAX_PATH];
1667   UINT len, ret;
1668 
1669   // Use the GetVersionEx information to see if we're on a server or
1670   // workstation edition of Windows. Starting with Windows 8.1 we can't
1671   // trust the OS version information returned by this API.
1672   ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));


4308   int oflags = _O_CREAT | _O_WRONLY | _O_BINARY;
4309   if (!rewrite_existing) {
4310     oflags |= _O_EXCL;
4311   }
4312   return ::open(path, oflags, _S_IREAD | _S_IWRITE);
4313 }
4314 
4315 // return current position of file pointer
4316 jlong os::current_file_offset(int fd) {
4317   return (jlong)::_lseeki64(fd, (__int64)0L, SEEK_CUR);
4318 }
4319 
4320 // move file pointer to the specified offset
4321 jlong os::seek_to_file_offset(int fd, jlong offset) {
4322   return (jlong)::_lseeki64(fd, (__int64)offset, SEEK_SET);
4323 }
4324 
4325 
4326 jlong os::lseek(int fd, jlong offset, int whence) {
4327   return (jlong) ::_lseeki64(fd, offset, whence);
















4328 }
4329 
4330 // This method is a slightly reworked copy of JDK's sysNativePath
4331 // from src/windows/hpi/src/path_md.c
4332 
4333 /* Convert a pathname to native format.  On win32, this involves forcing all
4334    separators to be '\\' rather than '/' (both are legal inputs, but Win95
4335    sometimes rejects '/') and removing redundant separators.  The input path is
4336    assumed to have been converted into the character encoding used by the local
4337    system.  Because this might be a double-byte encoding, care is taken to
4338    treat double-byte lead characters correctly.
4339 
4340    This procedure modifies the given path in place, as the result is never
4341    longer than the original.  There is no error return; this operation always
4342    succeeds. */
4343 char * os::native_path(char *path) {
4344   char *src = path, *dst = path, *end = path;
4345   char *colon = NULL;           /* If a drive specifier is found, this will
4346                                         point to the colon following the drive
4347                                         letter */




1134         && (dirp->path[2] == '\0'
1135             || (dirp->path[2] == '\\' && dirp->path[3] == '\0'))) {
1136         /* No '\\' needed for cases like "Z:" or "Z:\" */
1137         strcat(dirp->path, "*.*");
1138     } else {
1139         strcat(dirp->path, "\\*.*");
1140     }
1141 
1142     dirp->handle = FindFirstFile(dirp->path, &dirp->find_data);
1143     if (dirp->handle == INVALID_HANDLE_VALUE) {
1144         if (GetLastError() != ERROR_FILE_NOT_FOUND) {
1145             free(dirp->path, mtInternal);
1146             free(dirp, mtInternal);
1147             errno = EACCES;
1148             return 0;
1149         }
1150     }
1151     return dirp;
1152 }
1153 
1154 struct dirent *os::readdir(DIR *dirp)



1155 {
1156     assert(dirp != NULL, "just checking");      // hotspot change
1157     if (dirp->handle == INVALID_HANDLE_VALUE) {
1158         return NULL;
1159     }
1160 
1161     strcpy(dirp->dirent.d_name, dirp->find_data.cFileName);
1162 
1163   if (!FindNextFile(dirp->handle, &dirp->find_data)) {
1164     if (GetLastError() == ERROR_INVALID_HANDLE) {
1165       errno = EBADF;
1166       return NULL;
1167     }
1168     FindClose(dirp->handle);
1169     dirp->handle = INVALID_HANDLE_VALUE;
1170     }
1171 
1172     return &dirp->dirent;
1173 }
1174 
1175 int
1176 os::closedir(DIR *dirp)
1177 {
1178     assert(dirp != NULL, "just checking");      // hotspot change
1179     if (dirp->handle != INVALID_HANDLE_VALUE) {
1180         if (!FindClose(dirp->handle)) {
1181             errno = EBADF;
1182             return -1;
1183         }
1184         dirp->handle = INVALID_HANDLE_VALUE;
1185     }
1186     free(dirp->path, mtInternal);


1630       lib_arch_str,running_arch_str);
1631   }
1632   else
1633   {
1634     // don't know what architecture this dll was build for
1635     ::_snprintf(ebuf, ebuflen-1,
1636       "Can't load this .dll (machine code=0x%x) on a %s-bit platform",
1637       lib_arch,running_arch_str);
1638   }
1639 
1640   return NULL;
1641 }
1642 
1643 
1644 void os::print_dll_info(outputStream *st) {
1645    int pid = os::current_process_id();
1646    st->print_cr("Dynamic libraries:");
1647    enumerate_modules(pid, _print_module, (void *)st);
1648 }
1649 
1650 int os::get_loaded_modules_info(os::LoadedModulesCallbackFunc callback, void *param) {
1651   HANDLE   hProcess;
1652 
1653 # define MAX_NUM_MODULES 128
1654   HMODULE     modules[MAX_NUM_MODULES];
1655   static char filename[MAX_PATH];
1656   int         result = 0;
1657 
1658   int pid = os::current_process_id();
1659   hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
1660                          FALSE, pid);
1661   if (hProcess == NULL) return 0;
1662 
1663   DWORD size_needed;
1664   if (!EnumProcessModules(hProcess, modules, sizeof(modules), &size_needed)) {
1665     CloseHandle(hProcess);
1666     return 0;
1667   }
1668 
1669   // number of modules that are currently loaded
1670   int num_modules = size_needed / sizeof(HMODULE);
1671 
1672   for (int i = 0; i < MIN2(num_modules, MAX_NUM_MODULES); i++) {
1673     // Get Full pathname:
1674     if (!GetModuleFileNameEx(hProcess, modules[i], filename, sizeof(filename))) {
1675       filename[0] = '\0';
1676     }
1677 
1678     MODULEINFO modinfo;
1679     if (!GetModuleInformation(hProcess, modules[i], &modinfo, sizeof(modinfo))) {
1680       modinfo.lpBaseOfDll = NULL;
1681       modinfo.SizeOfImage = 0;
1682     }
1683 
1684     // Invoke callback function
1685     result = callback(filename, (address)modinfo.lpBaseOfDll,
1686                       (address)((u8)modinfo.lpBaseOfDll + (u8)modinfo.SizeOfImage), param);
1687     if (result) break;
1688   }
1689 
1690   CloseHandle(hProcess);
1691   return result;
1692 }
1693 
1694 void os::print_os_info_brief(outputStream* st) {
1695   os::print_os_info(st);
1696 }
1697 
1698 void os::print_os_info(outputStream* st) {
1699   st->print("OS:");
1700 
1701   os::win32::print_windows_version(st);
1702 }
1703 
1704 void os::win32::print_windows_version(outputStream* st) {
1705   OSVERSIONINFOEX osvi;
1706   VS_FIXEDFILEINFO *file_info;
1707   TCHAR kernel32_path[MAX_PATH];
1708   UINT len, ret;
1709 
1710   // Use the GetVersionEx information to see if we're on a server or
1711   // workstation edition of Windows. Starting with Windows 8.1 we can't
1712   // trust the OS version information returned by this API.
1713   ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));


4349   int oflags = _O_CREAT | _O_WRONLY | _O_BINARY;
4350   if (!rewrite_existing) {
4351     oflags |= _O_EXCL;
4352   }
4353   return ::open(path, oflags, _S_IREAD | _S_IWRITE);
4354 }
4355 
4356 // return current position of file pointer
4357 jlong os::current_file_offset(int fd) {
4358   return (jlong)::_lseeki64(fd, (__int64)0L, SEEK_CUR);
4359 }
4360 
4361 // move file pointer to the specified offset
4362 jlong os::seek_to_file_offset(int fd, jlong offset) {
4363   return (jlong)::_lseeki64(fd, (__int64)offset, SEEK_SET);
4364 }
4365 
4366 
4367 jlong os::lseek(int fd, jlong offset, int whence) {
4368   return (jlong) ::_lseeki64(fd, offset, whence);
4369 }
4370 
4371 size_t os::read_at(int fd, void *buf, unsigned int nBytes, jlong offset) {
4372   OVERLAPPED ov;
4373   DWORD nread;
4374   BOOL result;
4375 
4376   ZeroMemory(&ov, sizeof(ov));
4377   ov.Offset = (DWORD)offset;
4378   ov.OffsetHigh = (DWORD)(offset >> 32);
4379 
4380   HANDLE h = (HANDLE)::_get_osfhandle(fd);
4381 
4382   result = ReadFile(h, (LPVOID)buf, nBytes, &nread, &ov);
4383 
4384   return result ? nread : 0;
4385 }
4386 
4387 // This method is a slightly reworked copy of JDK's sysNativePath
4388 // from src/windows/hpi/src/path_md.c
4389 
4390 /* Convert a pathname to native format.  On win32, this involves forcing all
4391    separators to be '\\' rather than '/' (both are legal inputs, but Win95
4392    sometimes rejects '/') and removing redundant separators.  The input path is
4393    assumed to have been converted into the character encoding used by the local
4394    system.  Because this might be a double-byte encoding, care is taken to
4395    treat double-byte lead characters correctly.
4396 
4397    This procedure modifies the given path in place, as the result is never
4398    longer than the original.  There is no error return; this operation always
4399    succeeds. */
4400 char * os::native_path(char *path) {
4401   char *src = path, *dst = path, *end = path;
4402   char *colon = NULL;           /* If a drive specifier is found, this will
4403                                         point to the colon following the drive
4404                                         letter */


< prev index next >