< prev index next >

src/os/windows/vm/os_windows.cpp

Print this page
rev 7972 : 8075044: Query dbghelp.dll version number at run time, not at compile time
Summary: use ImagehlpApiVersion() instead of API_VERSION_NUMBER to determine dbghelp.dll version
Contributed-by: Thomas Stuefe


 965     return true;
 966   } else {
 967     return false;
 968   }
 969 }
 970 
 971 void os::shutdown() {
 972   // allow PerfMemory to attempt cleanup of any persistent resources
 973   perfMemory_exit();
 974 
 975   // flush buffered output, finish log files
 976   ostream_abort();
 977 
 978   // Check for abort hook
 979   abort_hook_t abort_hook = Arguments::abort_hook();
 980   if (abort_hook != NULL) {
 981     abort_hook();
 982   }
 983 }
 984 
 985 
 986 static BOOL (WINAPI *_MiniDumpWriteDump)(HANDLE, DWORD, HANDLE, MINIDUMP_TYPE,
 987                                          PMINIDUMP_EXCEPTION_INFORMATION,
 988                                          PMINIDUMP_USER_STREAM_INFORMATION,
 989                                          PMINIDUMP_CALLBACK_INFORMATION);




 990 
 991 void os::check_or_create_dump(void* exceptionRecord, void* contextRecord, char* buffer, size_t bufferSize) {
 992   HINSTANCE dbghelp;
 993   EXCEPTION_POINTERS ep;
 994   MINIDUMP_EXCEPTION_INFORMATION mei;
 995   MINIDUMP_EXCEPTION_INFORMATION* pmei;
 996 
 997   HANDLE hProcess = GetCurrentProcess();
 998   DWORD processId = GetCurrentProcessId();
 999   HANDLE dumpFile;
1000   MINIDUMP_TYPE dumpType;
1001   static const char* cwd;
1002 
1003 // Default is to always create dump for debug builds, on product builds only dump on server versions of Windows.
1004 #ifndef ASSERT
1005   // If running on a client version of Windows and user has not explicitly enabled dumping
1006   if (!os::win32::is_windows_server() && !CreateMinidumpOnCrash) {
1007     VMError::report_coredump_status("Minidumps are not enabled by default on client versions of Windows", false);
1008     return;
1009     // If running on a server version of Windows and user has explictly disabled dumping
1010   } else if (os::win32::is_windows_server() && !FLAG_IS_DEFAULT(CreateMinidumpOnCrash) && !CreateMinidumpOnCrash) {
1011     VMError::report_coredump_status("Minidump has been disabled from the command line", false);
1012     return;
1013   }
1014 #else
1015   if (!FLAG_IS_DEFAULT(CreateMinidumpOnCrash) && !CreateMinidumpOnCrash) {
1016     VMError::report_coredump_status("Minidump has been disabled from the command line", false);
1017     return;
1018   }
1019 #endif
1020 
1021   dbghelp = os::win32::load_Windows_dll("DBGHELP.DLL", NULL, 0);
1022 
1023   if (dbghelp == NULL) {
1024     VMError::report_coredump_status("Failed to load dbghelp.dll", false);
1025     return;
1026   }
1027 
1028   _MiniDumpWriteDump =
1029       CAST_TO_FN_PTR(BOOL(WINAPI *)(HANDLE, DWORD, HANDLE, MINIDUMP_TYPE,
1030                                     PMINIDUMP_EXCEPTION_INFORMATION,
1031                                     PMINIDUMP_USER_STREAM_INFORMATION,
1032                                     PMINIDUMP_CALLBACK_INFORMATION),
1033                                     GetProcAddress(dbghelp,
1034                                     "MiniDumpWriteDump"));
1035 
1036   if (_MiniDumpWriteDump == NULL) {
1037     VMError::report_coredump_status("Failed to find MiniDumpWriteDump() in module dbghelp.dll", false);






1038     return;
1039   }



1040 
1041   dumpType = (MINIDUMP_TYPE)(MiniDumpWithFullMemory | MiniDumpWithHandleData);
1042 
1043 // Older versions of dbghelp.h doesn't contain all the dumptypes we want, dbghelp.h with
1044 // API_VERSION_NUMBER 11 or higher contains the ones we want though
1045 #if API_VERSION_NUMBER >= 11
1046   dumpType = (MINIDUMP_TYPE)(dumpType | MiniDumpWithFullMemoryInfo | MiniDumpWithThreadInfo |
1047                              MiniDumpWithUnloadedModules);
1048 #endif
1049 
1050   cwd = get_current_directory(NULL, 0);
1051   jio_snprintf(buffer, bufferSize, "%s\\hs_err_pid%u.mdmp", cwd, current_process_id());
1052   dumpFile = CreateFile(buffer, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1053 
1054   if (dumpFile == INVALID_HANDLE_VALUE) {
1055     VMError::report_coredump_status("Failed to create file for dumping", false);
1056     return;
1057   }
1058   if (exceptionRecord != NULL && contextRecord != NULL) {
1059     ep.ContextRecord = (PCONTEXT) contextRecord;
1060     ep.ExceptionRecord = (PEXCEPTION_RECORD) exceptionRecord;
1061 
1062     mei.ThreadId = GetCurrentThreadId();
1063     mei.ExceptionPointers = &ep;
1064     pmei = &mei;
1065   } else {
1066     pmei = NULL;
1067   }
1068 




 965     return true;
 966   } else {
 967     return false;
 968   }
 969 }
 970 
 971 void os::shutdown() {
 972   // allow PerfMemory to attempt cleanup of any persistent resources
 973   perfMemory_exit();
 974 
 975   // flush buffered output, finish log files
 976   ostream_abort();
 977 
 978   // Check for abort hook
 979   abort_hook_t abort_hook = Arguments::abort_hook();
 980   if (abort_hook != NULL) {
 981     abort_hook();
 982   }
 983 }
 984 
 985 typedef BOOL  (WINAPI *fun_MiniDumpWriteDump_t) (HANDLE, DWORD, HANDLE, MINIDUMP_TYPE,

 986                                                    PMINIDUMP_EXCEPTION_INFORMATION,
 987                                                    PMINIDUMP_USER_STREAM_INFORMATION,
 988                                                    PMINIDUMP_CALLBACK_INFORMATION);
 989 typedef LPAPI_VERSION (WINAPI *fun_ImagehlpApiVersion_t) (VOID);
 990 
 991 static fun_MiniDumpWriteDump_t _MiniDumpWriteDump;
 992 static fun_ImagehlpApiVersion_t _ImagehlpApiVersion;
 993 
 994 void os::check_or_create_dump(void* exceptionRecord, void* contextRecord, char* buffer, size_t bufferSize) {
 995   HINSTANCE dbghelp;
 996   EXCEPTION_POINTERS ep;
 997   MINIDUMP_EXCEPTION_INFORMATION mei;
 998   MINIDUMP_EXCEPTION_INFORMATION* pmei;
 999 
1000   HANDLE hProcess = GetCurrentProcess();
1001   DWORD processId = GetCurrentProcessId();
1002   HANDLE dumpFile;
1003   MINIDUMP_TYPE dumpType;
1004   static const char* cwd;
1005 
1006 // Default is to always create dump for debug builds, on product builds only dump on server versions of Windows.
1007 #ifndef ASSERT
1008   // If running on a client version of Windows and user has not explicitly enabled dumping
1009   if (!os::win32::is_windows_server() && !CreateMinidumpOnCrash) {
1010     VMError::report_coredump_status("Minidumps are not enabled by default on client versions of Windows", false);
1011     return;
1012     // If running on a server version of Windows and user has explictly disabled dumping
1013   } else if (os::win32::is_windows_server() && !FLAG_IS_DEFAULT(CreateMinidumpOnCrash) && !CreateMinidumpOnCrash) {
1014     VMError::report_coredump_status("Minidump has been disabled from the command line", false);
1015     return;
1016   }
1017 #else
1018   if (!FLAG_IS_DEFAULT(CreateMinidumpOnCrash) && !CreateMinidumpOnCrash) {
1019     VMError::report_coredump_status("Minidump has been disabled from the command line", false);
1020     return;
1021   }
1022 #endif
1023 
1024   dbghelp = os::win32::load_Windows_dll("DBGHELP.DLL", NULL, 0);
1025 
1026   if (dbghelp == NULL) {
1027     VMError::report_coredump_status("Failed to load dbghelp.dll", false);
1028     return;
1029   }
1030 








1031   if (_MiniDumpWriteDump == NULL) {
1032     _MiniDumpWriteDump =
1033         CAST_TO_FN_PTR(fun_MiniDumpWriteDump_t, GetProcAddress(dbghelp, "MiniDumpWriteDump"));
1034     _ImagehlpApiVersion =
1035         CAST_TO_FN_PTR(fun_ImagehlpApiVersion_t, GetProcAddress(dbghelp, "ImagehlpApiVersion"));
1036     if (_MiniDumpWriteDump == NULL || _ImagehlpApiVersion == NULL) {
1037       VMError::report_coredump_status("Failed to find MiniDumpWriteDump() or ImagehlpApiVersion() "
1038         "in module dbghelp.dll", false);
1039       return;
1040     }
1041   }
1042 
1043   const API_VERSION* const version = _ImagehlpApiVersion();
1044 
1045   dumpType = (MINIDUMP_TYPE)(MiniDumpWithFullMemory | MiniDumpWithHandleData);
1046 
1047   // Older versions of dbghelp.h doesn't contain all the dumptypes we want, dbghelp.h with
1048   // API_VERSION_NUMBER 11 or higher contains the ones we want though
1049   if (version->MajorVersion >= 11) {
1050     dumpType = (MINIDUMP_TYPE)(dumpType | MiniDumpWithFullMemoryInfo | MiniDumpWithThreadInfo |
1051                              MiniDumpWithUnloadedModules);
1052   }
1053 
1054   cwd = get_current_directory(NULL, 0);
1055   jio_snprintf(buffer, bufferSize, "%s\\hs_err_pid%u.mdmp", cwd, current_process_id());
1056   dumpFile = CreateFile(buffer, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1057 
1058   if (dumpFile == INVALID_HANDLE_VALUE) {
1059     VMError::report_coredump_status("Failed to create file for dumping", false);
1060     return;
1061   }
1062   if (exceptionRecord != NULL && contextRecord != NULL) {
1063     ep.ContextRecord = (PCONTEXT) contextRecord;
1064     ep.ExceptionRecord = (PEXCEPTION_RECORD) exceptionRecord;
1065 
1066     mei.ThreadId = GetCurrentThreadId();
1067     mei.ExceptionPointers = &ep;
1068     pmei = &mei;
1069   } else {
1070     pmei = NULL;
1071   }
1072 


< prev index next >