5377 inline BOOL os::Advapi32Dll::AdjustTokenPrivileges(HANDLE TokenHandle, 5378 BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, 5379 PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength) { 5380 return ::AdjustTokenPrivileges(TokenHandle, DisableAllPrivileges, NewState, 5381 BufferLength, PreviousState, ReturnLength); 5382 } 5383 5384 inline BOOL os::Advapi32Dll::OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, 5385 PHANDLE TokenHandle) { 5386 return ::OpenProcessToken(ProcessHandle, DesiredAccess, TokenHandle); 5387 } 5388 5389 inline BOOL os::Advapi32Dll::LookupPrivilegeValue(LPCTSTR lpSystemName, LPCTSTR lpName, PLUID lpLuid) { 5390 return ::LookupPrivilegeValue(lpSystemName, lpName, lpLuid); 5391 } 5392 5393 inline BOOL os::Advapi32Dll::AdvapiAvailable() { 5394 return true; 5395 } 5396 5397 #else 5398 // Kernel32 API 5399 typedef BOOL (WINAPI* SwitchToThread_Fn)(void); 5400 typedef HANDLE (WINAPI* CreateToolhelp32Snapshot_Fn)(DWORD,DWORD); 5401 typedef BOOL (WINAPI* Module32First_Fn)(HANDLE,LPMODULEENTRY32); 5402 typedef BOOL (WINAPI* Module32Next_Fn)(HANDLE,LPMODULEENTRY32); 5403 typedef void (WINAPI* GetNativeSystemInfo_Fn)(LPSYSTEM_INFO); 5404 5405 SwitchToThread_Fn os::Kernel32Dll::_SwitchToThread = NULL; 5406 CreateToolhelp32Snapshot_Fn os::Kernel32Dll::_CreateToolhelp32Snapshot = NULL; 5407 Module32First_Fn os::Kernel32Dll::_Module32First = NULL; 5408 Module32Next_Fn os::Kernel32Dll::_Module32Next = NULL; 5409 GetNativeSystemInfo_Fn os::Kernel32Dll::_GetNativeSystemInfo = NULL; 5410 5411 void os::Kernel32Dll::initialize() { 5412 if (!initialized) { 5413 HMODULE handle = ::GetModuleHandle("Kernel32.dll"); 5414 assert(handle != NULL, "Just check"); 5415 5416 _SwitchToThread = (SwitchToThread_Fn)::GetProcAddress(handle, "SwitchToThread"); | 5377 inline BOOL os::Advapi32Dll::AdjustTokenPrivileges(HANDLE TokenHandle, 5378 BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, 5379 PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength) { 5380 return ::AdjustTokenPrivileges(TokenHandle, DisableAllPrivileges, NewState, 5381 BufferLength, PreviousState, ReturnLength); 5382 } 5383 5384 inline BOOL os::Advapi32Dll::OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, 5385 PHANDLE TokenHandle) { 5386 return ::OpenProcessToken(ProcessHandle, DesiredAccess, TokenHandle); 5387 } 5388 5389 inline BOOL os::Advapi32Dll::LookupPrivilegeValue(LPCTSTR lpSystemName, LPCTSTR lpName, PLUID lpLuid) { 5390 return ::LookupPrivilegeValue(lpSystemName, lpName, lpLuid); 5391 } 5392 5393 inline BOOL os::Advapi32Dll::AdvapiAvailable() { 5394 return true; 5395 } 5396 5397 void* os::get_default_process_handle() { 5398 return (void*)GetModuleHandle(NULL); 5399 } 5400 5401 // Builds a platform dependent Agent_OnLoad_<lib_name> function name 5402 // which is used to find statically linked in agents. 5403 // Additionally for windows, takes into account __stdcall names. 5404 // Parameters: 5405 // sym_name: Symbol in library we are looking for 5406 // lib_name: Name of library to look in, NULL for shared libs. 5407 // is_absolute_path == true if lib_name is absolute path to agent 5408 // such as "C:/a/b/L.dll" 5409 // == false if only the base name of the library is passed in 5410 // such as "L" 5411 char* os::build_agent_function_name(const char *sym_name, const char *lib_name, 5412 bool is_absolute_path) { 5413 char *agent_entry_name; 5414 size_t len; 5415 size_t name_len; 5416 size_t prefix_len = strlen(JNI_LIB_PREFIX); 5417 size_t suffix_len = strlen(JNI_LIB_SUFFIX); 5418 const char *start; 5419 5420 if (lib_name != NULL) { 5421 len = name_len = strlen(lib_name); 5422 if (is_absolute_path) { 5423 // Need to strip path, prefix and suffix 5424 if ((start = strrchr(lib_name, *os::file_separator())) != NULL) { 5425 lib_name = ++start; 5426 } else { 5427 // Need to check for C: 5428 if ((start = strchr(lib_name, ':')) != NULL) { 5429 lib_name = ++start; 5430 } 5431 } 5432 if (len <= (prefix_len + suffix_len)) { 5433 return NULL; 5434 } 5435 lib_name += prefix_len; 5436 name_len = strlen(lib_name) - suffix_len; 5437 } 5438 } 5439 len = (lib_name != NULL ? name_len : 0) + strlen(sym_name) + 2; 5440 agent_entry_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, len, mtThread); 5441 if (agent_entry_name == NULL) { 5442 return NULL; 5443 } 5444 if (lib_name != NULL) { 5445 const char *p = strrchr(sym_name, '@'); 5446 if (p != NULL && p != sym_name) { 5447 // sym_name == _Agent_OnLoad@XX 5448 strncpy(agent_entry_name, sym_name, (p - sym_name)); 5449 agent_entry_name[(p-sym_name)] = '\0'; 5450 // agent_entry_name == _Agent_OnLoad 5451 strcat(agent_entry_name, "_"); 5452 strncat(agent_entry_name, lib_name, name_len); 5453 strcat(agent_entry_name, p); 5454 // agent_entry_name == _Agent_OnLoad_lib_name@XX 5455 } else { 5456 strcpy(agent_entry_name, sym_name); 5457 strcat(agent_entry_name, "_"); 5458 strncat(agent_entry_name, lib_name, name_len); 5459 } 5460 } else { 5461 strcpy(agent_entry_name, sym_name); 5462 } 5463 return agent_entry_name; 5464 } 5465 5466 #else 5467 // Kernel32 API 5468 typedef BOOL (WINAPI* SwitchToThread_Fn)(void); 5469 typedef HANDLE (WINAPI* CreateToolhelp32Snapshot_Fn)(DWORD,DWORD); 5470 typedef BOOL (WINAPI* Module32First_Fn)(HANDLE,LPMODULEENTRY32); 5471 typedef BOOL (WINAPI* Module32Next_Fn)(HANDLE,LPMODULEENTRY32); 5472 typedef void (WINAPI* GetNativeSystemInfo_Fn)(LPSYSTEM_INFO); 5473 5474 SwitchToThread_Fn os::Kernel32Dll::_SwitchToThread = NULL; 5475 CreateToolhelp32Snapshot_Fn os::Kernel32Dll::_CreateToolhelp32Snapshot = NULL; 5476 Module32First_Fn os::Kernel32Dll::_Module32First = NULL; 5477 Module32Next_Fn os::Kernel32Dll::_Module32Next = NULL; 5478 GetNativeSystemInfo_Fn os::Kernel32Dll::_GetNativeSystemInfo = NULL; 5479 5480 void os::Kernel32Dll::initialize() { 5481 if (!initialized) { 5482 HMODULE handle = ::GetModuleHandle("Kernel32.dll"); 5483 assert(handle != NULL, "Just check"); 5484 5485 _SwitchToThread = (SwitchToThread_Fn)::GetProcAddress(handle, "SwitchToThread"); |