提交 53591c51 编写于 作者: Z zgu

7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls

Summary: Created Windows Dll wrapped to handle jdk6 and jdk7 platform requirements, also provided more restictive Dll search orders for Windows system Dlls.
Reviewed-by: acorn, dcubed, ohair, alanb
上级 f8f12702
...@@ -81,7 +81,6 @@ CPP=ARCH_ERROR ...@@ -81,7 +81,6 @@ CPP=ARCH_ERROR
!endif !endif
CPP_FLAGS=$(CPP_FLAGS) /D "WIN32" /D "_WINDOWS" CPP_FLAGS=$(CPP_FLAGS) /D "WIN32" /D "_WINDOWS"
# Must specify this for sharedRuntimeTrig.cpp # Must specify this for sharedRuntimeTrig.cpp
CPP_FLAGS=$(CPP_FLAGS) /D "VM_LITTLE_ENDIAN" CPP_FLAGS=$(CPP_FLAGS) /D "VM_LITTLE_ENDIAN"
...@@ -232,6 +231,11 @@ LINK_FLAGS= $(LINK_FLAGS) kernel32.lib user32.lib gdi32.lib winspool.lib \ ...@@ -232,6 +231,11 @@ LINK_FLAGS= $(LINK_FLAGS) kernel32.lib user32.lib gdi32.lib winspool.lib \
uuid.lib Wsock32.lib winmm.lib /nologo /machine:$(MACHINE) /opt:REF \ uuid.lib Wsock32.lib winmm.lib /nologo /machine:$(MACHINE) /opt:REF \
/opt:ICF,8 /map /debug /opt:ICF,8 /map /debug
!if $(MSC_VER) >= 1600
LINK_FLAGS= $(LINK_FLAGS) psapi.lib
!endif
# Resource compiler settings # Resource compiler settings
RC=rc.exe RC=rc.exe
RC_FLAGS=/D "HS_VER=$(HS_VER)" \ RC_FLAGS=/D "HS_VER=$(HS_VER)" \
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "precompiled.hpp" #include "precompiled.hpp"
#include "prims/jvm.h" #include "prims/jvm.h"
#include "runtime/os.hpp"
#include "utilities/decoder.hpp" #include "utilities/decoder.hpp"
HMODULE Decoder::_dbghelp_handle = NULL; HMODULE Decoder::_dbghelp_handle = NULL;
...@@ -35,7 +36,7 @@ void Decoder::initialize() { ...@@ -35,7 +36,7 @@ void Decoder::initialize() {
if (!_initialized) { if (!_initialized) {
_initialized = true; _initialized = true;
HMODULE handle = ::LoadLibrary("dbghelp.dll"); HINSTANCE handle = os::win32::load_Windows_dll("dbghelp.dll", NULL, 0);
if (!handle) { if (!handle) {
_decoder_status = helper_not_found; _decoder_status = helper_not_found;
return; return;
......
...@@ -30,10 +30,33 @@ ...@@ -30,10 +30,33 @@
* JNI conversion, which should be sorted out later. * JNI conversion, which should be sorted out later.
*/ */
// JDK7 requires VS2010
#if _MSC_VER >= 1600
// JDK7 minimum platform requirement: Windows XP
#if _WIN32_WINNT < 0x0501
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif
#endif
#include <windows.h> #include <windows.h>
// #include <windef.h>
// #include <winbase.h>
#if _MSC_VER <= 1200
// Psapi.h doesn't come with Visual Studio 6; it can be downloaded as Platform
// SDK from Microsoft. Here are the definitions copied from Psapi.h
typedef struct _MODULEINFO {
LPVOID lpBaseOfDll;
DWORD SizeOfImage;
LPVOID EntryPoint;
} MODULEINFO, *LPMODULEINFO;
#else
#include <Psapi.h>
#endif
#include <Tlhelp32.h>
// #include "jni.h" // #include "jni.h"
......
此差异已折叠。
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#ifndef OS_WINDOWS_VM_OS_WINDOWS_HPP #ifndef OS_WINDOWS_VM_OS_WINDOWS_HPP
#define OS_WINDOWS_VM_OS_WINDOWS_HPP #define OS_WINDOWS_VM_OS_WINDOWS_HPP
// Win32_OS defines the interface to windows operating systems // Win32_OS defines the interface to windows operating systems
class win32 { class win32 {
...@@ -55,6 +54,9 @@ class win32 { ...@@ -55,6 +54,9 @@ class win32 {
static julong available_memory(); static julong available_memory();
static julong physical_memory() { return _physical_memory; } static julong physical_memory() { return _physical_memory; }
// load dll from Windows system directory or Windows directory
static HINSTANCE load_Windows_dll(const char* name, char *ebuf, int ebuflen);
public: public:
// Generic interface: // Generic interface:
...@@ -132,4 +134,100 @@ class PlatformParker : public CHeapObj { ...@@ -132,4 +134,100 @@ class PlatformParker : public CHeapObj {
} ; } ;
// JDK7 requires VS2010
#if _MSC_VER < 1600
#define JDK6_OR_EARLIER 1
#endif
class WinSock2Dll: AllStatic {
public:
static BOOL WSAStartup(WORD, LPWSADATA);
static struct hostent* gethostbyname(const char *name);
static BOOL WinSock2Available();
#ifdef JDK6_OR_EARLIER
private:
static int (PASCAL FAR* _WSAStartup)(WORD, LPWSADATA);
static struct hostent *(PASCAL FAR *_gethostbyname)(...);
static BOOL initialized;
static void initialize();
#endif
};
class Kernel32Dll: AllStatic {
public:
static BOOL SwitchToThread();
static SIZE_T GetLargePageMinimum();
static BOOL SwitchToThreadAvailable();
static BOOL GetLargePageMinimumAvailable();
// Help tools
static BOOL HelpToolsAvailable();
static HANDLE CreateToolhelp32Snapshot(DWORD,DWORD);
static BOOL Module32First(HANDLE,LPMODULEENTRY32);
static BOOL Module32Next(HANDLE,LPMODULEENTRY32);
static BOOL GetNativeSystemInfoAvailable();
static void GetNativeSystemInfo(LPSYSTEM_INFO);
private:
// GetLargePageMinimum available on Windows Vista/Windows Server 2003
// and later
static SIZE_T (WINAPI *_GetLargePageMinimum)(void);
static BOOL initialized;
static void initialize();
#ifdef JDK6_OR_EARLIER
private:
static BOOL (WINAPI *_SwitchToThread)(void);
static HANDLE (WINAPI* _CreateToolhelp32Snapshot)(DWORD,DWORD);
static BOOL (WINAPI* _Module32First)(HANDLE,LPMODULEENTRY32);
static BOOL (WINAPI* _Module32Next)(HANDLE,LPMODULEENTRY32);
static void (WINAPI *_GetNativeSystemInfo)(LPSYSTEM_INFO);
#endif
};
class Advapi32Dll: AllStatic {
public:
static BOOL AdjustTokenPrivileges(HANDLE, BOOL, PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD);
static BOOL OpenProcessToken(HANDLE, DWORD, PHANDLE);
static BOOL LookupPrivilegeValue(LPCTSTR, LPCTSTR, PLUID);
static BOOL AdvapiAvailable();
#ifdef JDK6_OR_EARLIER
private:
static BOOL (WINAPI *_AdjustTokenPrivileges)(HANDLE, BOOL, PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD);
static BOOL (WINAPI *_OpenProcessToken)(HANDLE, DWORD, PHANDLE);
static BOOL (WINAPI *_LookupPrivilegeValue)(LPCTSTR, LPCTSTR, PLUID);
static BOOL initialized;
static void initialize();
#endif
};
class PSApiDll: AllStatic {
public:
static BOOL EnumProcessModules(HANDLE, HMODULE *, DWORD, LPDWORD);
static DWORD GetModuleFileNameEx(HANDLE, HMODULE, LPTSTR, DWORD);
static BOOL GetModuleInformation(HANDLE, HMODULE, LPMODULEINFO, DWORD);
static BOOL PSApiAvailable();
#ifdef JDK6_OR_EARLIER
private:
static BOOL (WINAPI *_EnumProcessModules)(HANDLE, HMODULE *, DWORD, LPDWORD);
static BOOL (WINAPI *_GetModuleFileNameEx)(HANDLE, HMODULE, LPTSTR, DWORD);;
static BOOL (WINAPI *_GetModuleInformation)(HANDLE, HMODULE, LPMODULEINFO, DWORD);
static BOOL initialized;
static void initialize();
#endif
};
#endif // OS_WINDOWS_VM_OS_WINDOWS_HPP #endif // OS_WINDOWS_VM_OS_WINDOWS_HPP
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册