5703 strcpy(agent_entry_name, sym_name); |
5701 strcpy(agent_entry_name, sym_name); |
5704 } |
5702 } |
5705 return agent_entry_name; |
5703 return agent_entry_name; |
5706 } |
5704 } |
5707 |
5705 |
5708 #else |
|
5709 // Kernel32 API |
|
5710 typedef BOOL (WINAPI* SwitchToThread_Fn)(void); |
|
5711 typedef HANDLE (WINAPI* CreateToolhelp32Snapshot_Fn)(DWORD, DWORD); |
|
5712 typedef BOOL (WINAPI* Module32First_Fn)(HANDLE, LPMODULEENTRY32); |
|
5713 typedef BOOL (WINAPI* Module32Next_Fn)(HANDLE, LPMODULEENTRY32); |
|
5714 typedef void (WINAPI* GetNativeSystemInfo_Fn)(LPSYSTEM_INFO); |
|
5715 |
|
5716 SwitchToThread_Fn os::Kernel32Dll::_SwitchToThread = NULL; |
|
5717 CreateToolhelp32Snapshot_Fn os::Kernel32Dll::_CreateToolhelp32Snapshot = NULL; |
|
5718 Module32First_Fn os::Kernel32Dll::_Module32First = NULL; |
|
5719 Module32Next_Fn os::Kernel32Dll::_Module32Next = NULL; |
|
5720 GetNativeSystemInfo_Fn os::Kernel32Dll::_GetNativeSystemInfo = NULL; |
|
5721 |
|
5722 void os::Kernel32Dll::initialize() { |
|
5723 if (!initialized) { |
|
5724 HMODULE handle = ::GetModuleHandle("Kernel32.dll"); |
|
5725 assert(handle != NULL, "Just check"); |
|
5726 |
|
5727 _SwitchToThread = (SwitchToThread_Fn)::GetProcAddress(handle, "SwitchToThread"); |
|
5728 _CreateToolhelp32Snapshot = (CreateToolhelp32Snapshot_Fn) |
|
5729 ::GetProcAddress(handle, "CreateToolhelp32Snapshot"); |
|
5730 _Module32First = (Module32First_Fn)::GetProcAddress(handle, "Module32First"); |
|
5731 _Module32Next = (Module32Next_Fn)::GetProcAddress(handle, "Module32Next"); |
|
5732 _GetNativeSystemInfo = (GetNativeSystemInfo_Fn)::GetProcAddress(handle, "GetNativeSystemInfo"); |
|
5733 initializeCommon(); // resolve the functions that always need resolving |
|
5734 |
|
5735 initialized = TRUE; |
|
5736 } |
|
5737 } |
|
5738 |
|
5739 BOOL os::Kernel32Dll::SwitchToThread() { |
|
5740 assert(initialized && _SwitchToThread != NULL, |
|
5741 "SwitchToThreadAvailable() not yet called"); |
|
5742 return _SwitchToThread(); |
|
5743 } |
|
5744 |
|
5745 |
|
5746 BOOL os::Kernel32Dll::SwitchToThreadAvailable() { |
|
5747 if (!initialized) { |
|
5748 initialize(); |
|
5749 } |
|
5750 return _SwitchToThread != NULL; |
|
5751 } |
|
5752 |
|
5753 // Help tools |
|
5754 BOOL os::Kernel32Dll::HelpToolsAvailable() { |
|
5755 if (!initialized) { |
|
5756 initialize(); |
|
5757 } |
|
5758 return _CreateToolhelp32Snapshot != NULL && |
|
5759 _Module32First != NULL && |
|
5760 _Module32Next != NULL; |
|
5761 } |
|
5762 |
|
5763 HANDLE os::Kernel32Dll::CreateToolhelp32Snapshot(DWORD dwFlags, |
|
5764 DWORD th32ProcessId) { |
|
5765 assert(initialized && _CreateToolhelp32Snapshot != NULL, |
|
5766 "HelpToolsAvailable() not yet called"); |
|
5767 |
|
5768 return _CreateToolhelp32Snapshot(dwFlags, th32ProcessId); |
|
5769 } |
|
5770 |
|
5771 BOOL os::Kernel32Dll::Module32First(HANDLE hSnapshot,LPMODULEENTRY32 lpme) { |
|
5772 assert(initialized && _Module32First != NULL, |
|
5773 "HelpToolsAvailable() not yet called"); |
|
5774 |
|
5775 return _Module32First(hSnapshot, lpme); |
|
5776 } |
|
5777 |
|
5778 inline BOOL os::Kernel32Dll::Module32Next(HANDLE hSnapshot, |
|
5779 LPMODULEENTRY32 lpme) { |
|
5780 assert(initialized && _Module32Next != NULL, |
|
5781 "HelpToolsAvailable() not yet called"); |
|
5782 |
|
5783 return _Module32Next(hSnapshot, lpme); |
|
5784 } |
|
5785 |
|
5786 |
|
5787 BOOL os::Kernel32Dll::GetNativeSystemInfoAvailable() { |
|
5788 if (!initialized) { |
|
5789 initialize(); |
|
5790 } |
|
5791 return _GetNativeSystemInfo != NULL; |
|
5792 } |
|
5793 |
|
5794 void os::Kernel32Dll::GetNativeSystemInfo(LPSYSTEM_INFO lpSystemInfo) { |
|
5795 assert(initialized && _GetNativeSystemInfo != NULL, |
|
5796 "GetNativeSystemInfoAvailable() not yet called"); |
|
5797 |
|
5798 _GetNativeSystemInfo(lpSystemInfo); |
|
5799 } |
|
5800 |
|
5801 // PSAPI API |
|
5802 |
|
5803 |
|
5804 typedef BOOL (WINAPI *EnumProcessModules_Fn)(HANDLE, HMODULE *, DWORD, LPDWORD); |
|
5805 typedef BOOL (WINAPI *GetModuleFileNameEx_Fn)(HANDLE, HMODULE, LPTSTR, DWORD); |
|
5806 typedef BOOL (WINAPI *GetModuleInformation_Fn)(HANDLE, HMODULE, LPMODULEINFO, DWORD); |
|
5807 |
|
5808 EnumProcessModules_Fn os::PSApiDll::_EnumProcessModules = NULL; |
|
5809 GetModuleFileNameEx_Fn os::PSApiDll::_GetModuleFileNameEx = NULL; |
|
5810 GetModuleInformation_Fn os::PSApiDll::_GetModuleInformation = NULL; |
|
5811 BOOL os::PSApiDll::initialized = FALSE; |
|
5812 |
|
5813 void os::PSApiDll::initialize() { |
|
5814 if (!initialized) { |
|
5815 HMODULE handle = os::win32::load_Windows_dll("PSAPI.DLL", NULL, 0); |
|
5816 if (handle != NULL) { |
|
5817 _EnumProcessModules = (EnumProcessModules_Fn)::GetProcAddress(handle, |
|
5818 "EnumProcessModules"); |
|
5819 _GetModuleFileNameEx = (GetModuleFileNameEx_Fn)::GetProcAddress(handle, |
|
5820 "GetModuleFileNameExA"); |
|
5821 _GetModuleInformation = (GetModuleInformation_Fn)::GetProcAddress(handle, |
|
5822 "GetModuleInformation"); |
|
5823 } |
|
5824 initialized = TRUE; |
|
5825 } |
|
5826 } |
|
5827 |
|
5828 |
|
5829 |
|
5830 BOOL os::PSApiDll::EnumProcessModules(HANDLE hProcess, HMODULE *lpModule, |
|
5831 DWORD cb, LPDWORD lpcbNeeded) { |
|
5832 assert(initialized && _EnumProcessModules != NULL, |
|
5833 "PSApiAvailable() not yet called"); |
|
5834 return _EnumProcessModules(hProcess, lpModule, cb, lpcbNeeded); |
|
5835 } |
|
5836 |
|
5837 DWORD os::PSApiDll::GetModuleFileNameEx(HANDLE hProcess, HMODULE hModule, |
|
5838 LPTSTR lpFilename, DWORD nSize) { |
|
5839 assert(initialized && _GetModuleFileNameEx != NULL, |
|
5840 "PSApiAvailable() not yet called"); |
|
5841 return _GetModuleFileNameEx(hProcess, hModule, lpFilename, nSize); |
|
5842 } |
|
5843 |
|
5844 BOOL os::PSApiDll::GetModuleInformation(HANDLE hProcess, HMODULE hModule, |
|
5845 LPMODULEINFO lpmodinfo, DWORD cb) { |
|
5846 assert(initialized && _GetModuleInformation != NULL, |
|
5847 "PSApiAvailable() not yet called"); |
|
5848 return _GetModuleInformation(hProcess, hModule, lpmodinfo, cb); |
|
5849 } |
|
5850 |
|
5851 BOOL os::PSApiDll::PSApiAvailable() { |
|
5852 if (!initialized) { |
|
5853 initialize(); |
|
5854 } |
|
5855 return _EnumProcessModules != NULL && |
|
5856 _GetModuleFileNameEx != NULL && |
|
5857 _GetModuleInformation != NULL; |
|
5858 } |
|
5859 |
|
5860 |
|
5861 // WinSock2 API |
|
5862 typedef int (PASCAL FAR* WSAStartup_Fn)(WORD, LPWSADATA); |
|
5863 typedef struct hostent *(PASCAL FAR *gethostbyname_Fn)(...); |
|
5864 |
|
5865 WSAStartup_Fn os::WinSock2Dll::_WSAStartup = NULL; |
|
5866 gethostbyname_Fn os::WinSock2Dll::_gethostbyname = NULL; |
|
5867 BOOL os::WinSock2Dll::initialized = FALSE; |
|
5868 |
|
5869 void os::WinSock2Dll::initialize() { |
|
5870 if (!initialized) { |
|
5871 HMODULE handle = os::win32::load_Windows_dll("ws2_32.dll", NULL, 0); |
|
5872 if (handle != NULL) { |
|
5873 _WSAStartup = (WSAStartup_Fn)::GetProcAddress(handle, "WSAStartup"); |
|
5874 _gethostbyname = (gethostbyname_Fn)::GetProcAddress(handle, "gethostbyname"); |
|
5875 } |
|
5876 initialized = TRUE; |
|
5877 } |
|
5878 } |
|
5879 |
|
5880 |
|
5881 BOOL os::WinSock2Dll::WSAStartup(WORD wVersionRequested, LPWSADATA lpWSAData) { |
|
5882 assert(initialized && _WSAStartup != NULL, |
|
5883 "WinSock2Available() not yet called"); |
|
5884 return _WSAStartup(wVersionRequested, lpWSAData); |
|
5885 } |
|
5886 |
|
5887 struct hostent* os::WinSock2Dll::gethostbyname(const char *name) { |
|
5888 assert(initialized && _gethostbyname != NULL, |
|
5889 "WinSock2Available() not yet called"); |
|
5890 return _gethostbyname(name); |
|
5891 } |
|
5892 |
|
5893 BOOL os::WinSock2Dll::WinSock2Available() { |
|
5894 if (!initialized) { |
|
5895 initialize(); |
|
5896 } |
|
5897 return _WSAStartup != NULL && |
|
5898 _gethostbyname != NULL; |
|
5899 } |
|
5900 |
|
5901 typedef BOOL (WINAPI *AdjustTokenPrivileges_Fn)(HANDLE, BOOL, PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD); |
|
5902 typedef BOOL (WINAPI *OpenProcessToken_Fn)(HANDLE, DWORD, PHANDLE); |
|
5903 typedef BOOL (WINAPI *LookupPrivilegeValue_Fn)(LPCTSTR, LPCTSTR, PLUID); |
|
5904 |
|
5905 AdjustTokenPrivileges_Fn os::Advapi32Dll::_AdjustTokenPrivileges = NULL; |
|
5906 OpenProcessToken_Fn os::Advapi32Dll::_OpenProcessToken = NULL; |
|
5907 LookupPrivilegeValue_Fn os::Advapi32Dll::_LookupPrivilegeValue = NULL; |
|
5908 BOOL os::Advapi32Dll::initialized = FALSE; |
|
5909 |
|
5910 void os::Advapi32Dll::initialize() { |
|
5911 if (!initialized) { |
|
5912 HMODULE handle = os::win32::load_Windows_dll("advapi32.dll", NULL, 0); |
|
5913 if (handle != NULL) { |
|
5914 _AdjustTokenPrivileges = (AdjustTokenPrivileges_Fn)::GetProcAddress(handle, |
|
5915 "AdjustTokenPrivileges"); |
|
5916 _OpenProcessToken = (OpenProcessToken_Fn)::GetProcAddress(handle, |
|
5917 "OpenProcessToken"); |
|
5918 _LookupPrivilegeValue = (LookupPrivilegeValue_Fn)::GetProcAddress(handle, |
|
5919 "LookupPrivilegeValueA"); |
|
5920 } |
|
5921 initialized = TRUE; |
|
5922 } |
|
5923 } |
|
5924 |
|
5925 BOOL os::Advapi32Dll::AdjustTokenPrivileges(HANDLE TokenHandle, |
|
5926 BOOL DisableAllPrivileges, |
|
5927 PTOKEN_PRIVILEGES NewState, |
|
5928 DWORD BufferLength, |
|
5929 PTOKEN_PRIVILEGES PreviousState, |
|
5930 PDWORD ReturnLength) { |
|
5931 assert(initialized && _AdjustTokenPrivileges != NULL, |
|
5932 "AdvapiAvailable() not yet called"); |
|
5933 return _AdjustTokenPrivileges(TokenHandle, DisableAllPrivileges, NewState, |
|
5934 BufferLength, PreviousState, ReturnLength); |
|
5935 } |
|
5936 |
|
5937 BOOL os::Advapi32Dll::OpenProcessToken(HANDLE ProcessHandle, |
|
5938 DWORD DesiredAccess, |
|
5939 PHANDLE TokenHandle) { |
|
5940 assert(initialized && _OpenProcessToken != NULL, |
|
5941 "AdvapiAvailable() not yet called"); |
|
5942 return _OpenProcessToken(ProcessHandle, DesiredAccess, TokenHandle); |
|
5943 } |
|
5944 |
|
5945 BOOL os::Advapi32Dll::LookupPrivilegeValue(LPCTSTR lpSystemName, |
|
5946 LPCTSTR lpName, PLUID lpLuid) { |
|
5947 assert(initialized && _LookupPrivilegeValue != NULL, |
|
5948 "AdvapiAvailable() not yet called"); |
|
5949 return _LookupPrivilegeValue(lpSystemName, lpName, lpLuid); |
|
5950 } |
|
5951 |
|
5952 BOOL os::Advapi32Dll::AdvapiAvailable() { |
|
5953 if (!initialized) { |
|
5954 initialize(); |
|
5955 } |
|
5956 return _AdjustTokenPrivileges != NULL && |
|
5957 _OpenProcessToken != NULL && |
|
5958 _LookupPrivilegeValue != NULL; |
|
5959 } |
|
5960 |
|
5961 #endif |
|
5962 |
|
5963 #ifndef PRODUCT |
5706 #ifndef PRODUCT |
5964 |
5707 |
5965 // test the code path in reserve_memory_special() that tries to allocate memory in a single |
5708 // test the code path in reserve_memory_special() that tries to allocate memory in a single |
5966 // contiguous memory block at a particular address. |
5709 // contiguous memory block at a particular address. |
5967 // The test first tries to find a good approximate address to allocate at by using the same |
5710 // The test first tries to find a good approximate address to allocate at by using the same |