Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
135dbba5
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
135dbba5
编写于
4月 04, 2011
作者:
A
alanb
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7030249: Eliminate use of LoadLibrary and other clean-ups
Reviewed-by: ohair, chegar, mchung
上级
59e6a22b
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
77 addition
and
318 deletion
+77
-318
make/java/java/Makefile
make/java/java/Makefile
+3
-1
make/java/management/Makefile
make/java/management/Makefile
+2
-1
src/windows/native/com/sun/management/OperatingSystem_md.c
src/windows/native/com/sun/management/OperatingSystem_md.c
+14
-66
src/windows/native/java/io/WinNTFileSystem_md.c
src/windows/native/java/io/WinNTFileSystem_md.c
+10
-18
src/windows/native/java/lang/java_props_md.c
src/windows/native/java/lang/java_props_md.c
+18
-38
src/windows/native/sun/management/FileSystemImpl.c
src/windows/native/sun/management/FileSystemImpl.c
+8
-95
src/windows/native/sun/nio/fs/WindowsNativeDispatcher.c
src/windows/native/sun/nio/fs/WindowsNativeDispatcher.c
+18
-69
src/windows/native/sun/security/provider/WinCAPISeedGenerator.c
...ndows/native/sun/security/provider/WinCAPISeedGenerator.c
+4
-30
未找到文件。
make/java/java/Makefile
浏览文件 @
135dbba5
...
@@ -198,10 +198,12 @@ INSTALL_DOT_LIB = true
...
@@ -198,10 +198,12 @@ INSTALL_DOT_LIB = true
#
#
# What to link?
# What to link?
# On Windows, shell32 is not normally required and so it is delay loaded.
#
#
ifeq
($(PLATFORM),windows)
ifeq
($(PLATFORM),windows)
OTHER_LDLIBS
+=
$(JVMLIB)
-libpath
:
$(OBJDIR)
/../../../fdlibm/
$(OBJDIRNAME)
fdlibm.lib
\
OTHER_LDLIBS
+=
$(JVMLIB)
-libpath
:
$(OBJDIR)
/../../../fdlibm/
$(OBJDIRNAME)
fdlibm.lib
\
-libpath
:
$(OBJDIR)
/../../../verify/
$(OBJDIRNAME)
verify.lib
-libpath
:
$(OBJDIR)
/../../../verify/
$(OBJDIRNAME)
verify.lib
\
shell32.lib delayimp.lib /DELAYLOAD:shell32.dll
else
else
OTHER_LDLIBS
+=
$(JVMLIB)
-lverify
$(LIBSOCKET)
$(LIBNSL)
-ldl
\
OTHER_LDLIBS
+=
$(JVMLIB)
-lverify
$(LIBSOCKET)
$(LIBNSL)
-ldl
\
-L
$(OBJDIR)
/../../../fdlibm/
$(OBJDIRNAME)
-lfdlibm
.
$(ARCH)
-L
$(OBJDIR)
/../../../fdlibm/
$(OBJDIRNAME)
-lfdlibm
.
$(ARCH)
...
...
make/java/management/Makefile
浏览文件 @
135dbba5
...
@@ -86,7 +86,8 @@ OTHER_INCLUDES += \
...
@@ -86,7 +86,8 @@ OTHER_INCLUDES += \
-I
$(SHARE_SRC)
/native/sun/management
-I
$(SHARE_SRC)
/native/sun/management
ifeq
($(PLATFORM),windows)
ifeq
($(PLATFORM),windows)
OTHER_LDLIBS
+=
$(JVMLIB)
# Need process status helper API (psapi) on Windows
OTHER_LDLIBS
+=
$(JVMLIB)
psapi.lib
endif
endif
#
#
...
...
src/windows/native/com/sun/management/OperatingSystem_md.c
浏览文件 @
135dbba5
...
@@ -30,6 +30,7 @@
...
@@ -30,6 +30,7 @@
#include "management.h"
#include "management.h"
#include "com_sun_management_OperatingSystem.h"
#include "com_sun_management_OperatingSystem.h"
#include <psapi.h>
#include <errno.h>
#include <errno.h>
#include <stdlib.h>
#include <stdlib.h>
...
@@ -53,41 +54,12 @@ static jlong jlong_from(jint h, jint l) {
...
@@ -53,41 +54,12 @@ static jlong jlong_from(jint h, jint l) {
return
result
;
return
result
;
}
}
// From psapi.h
typedef
struct
_PROCESS_MEMORY_COUNTERS
{
DWORD
cb
;
DWORD
PageFaultCount
;
SIZE_T
PeakWorkingSetSize
;
SIZE_T
WorkingSetSize
;
SIZE_T
QuotaPeakPagedPoolUsage
;
SIZE_T
QuotaPagedPoolUsage
;
SIZE_T
QuotaPeakNonPagedPoolUsage
;
SIZE_T
QuotaNonPagedPoolUsage
;
SIZE_T
PagefileUsage
;
SIZE_T
PeakPagefileUsage
;
}
PROCESS_MEMORY_COUNTERS
;
static
HINSTANCE
hInstPsapi
=
NULL
;
typedef
BOOL
(
WINAPI
*
LPFNGETPROCESSMEMORYINFO
)(
HANDLE
,
PROCESS_MEMORY_COUNTERS
*
,
DWORD
);
static
jboolean
is_nt
=
JNI_FALSE
;
static
HANDLE
main_process
;
static
HANDLE
main_process
;
JNIEXPORT
void
JNICALL
JNIEXPORT
void
JNICALL
Java_com_sun_management_OperatingSystem_initialize
Java_com_sun_management_OperatingSystem_initialize
(
JNIEnv
*
env
,
jclass
cls
)
(
JNIEnv
*
env
,
jclass
cls
)
{
{
OSVERSIONINFO
oi
;
oi
.
dwOSVersionInfoSize
=
sizeof
(
OSVERSIONINFO
);
GetVersionEx
(
&
oi
);
switch
(
oi
.
dwPlatformId
)
{
case
VER_PLATFORM_WIN32_WINDOWS
:
is_nt
=
JNI_FALSE
;
break
;
case
VER_PLATFORM_WIN32_NT
:
is_nt
=
JNI_TRUE
;
break
;
default:
throw_internal_error
(
env
,
"Unsupported Platform"
);
return
;
}
main_process
=
GetCurrentProcess
();
main_process
=
GetCurrentProcess
();
}
}
...
@@ -95,31 +67,12 @@ JNIEXPORT jlong JNICALL
...
@@ -95,31 +67,12 @@ JNIEXPORT jlong JNICALL
Java_com_sun_management_OperatingSystem_getCommittedVirtualMemorySize0
Java_com_sun_management_OperatingSystem_getCommittedVirtualMemorySize0
(
JNIEnv
*
env
,
jobject
mbean
)
(
JNIEnv
*
env
,
jobject
mbean
)
{
{
/*
* In bytes. NT/2000/XP only - using GetProcessMemoryInfo from psapi.dll
*/
static
LPFNGETPROCESSMEMORYINFO
lpfnGetProcessMemoryInfo
=
NULL
;
static
volatile
jboolean
psapi_inited
=
JNI_FALSE
;
PROCESS_MEMORY_COUNTERS
pmc
;
PROCESS_MEMORY_COUNTERS
pmc
;
if
(
GetProcessMemoryInfo
(
main_process
,
&
pmc
,
sizeof
(
PROCESS_MEMORY_COUNTERS
))
==
0
)
{
if
(
!
is_nt
)
return
-
1
;
return
(
jlong
)
-
1L
;
}
else
{
if
(
!
psapi_inited
)
{
psapi_inited
=
JNI_TRUE
;
if
((
hInstPsapi
=
LoadLibrary
(
"PSAPI.DLL"
))
==
NULL
)
return
-
1
;
if
((
lpfnGetProcessMemoryInfo
=
(
LPFNGETPROCESSMEMORYINFO
)
GetProcAddress
(
hInstPsapi
,
"GetProcessMemoryInfo"
))
==
NULL
)
{
FreeLibrary
(
hInstPsapi
);
return
-
1
;
}
}
if
(
lpfnGetProcessMemoryInfo
==
NULL
)
return
-
1
;
lpfnGetProcessMemoryInfo
(
main_process
,
&
pmc
,
sizeof
(
PROCESS_MEMORY_COUNTERS
));
return
(
jlong
)
pmc
.
PagefileUsage
;
return
(
jlong
)
pmc
.
PagefileUsage
;
}
}
}
JNIEXPORT
jlong
JNICALL
JNIEXPORT
jlong
JNICALL
...
@@ -148,8 +101,6 @@ Java_com_sun_management_OperatingSystem_getProcessCpuTime
...
@@ -148,8 +101,6 @@ Java_com_sun_management_OperatingSystem_getProcessCpuTime
FILETIME
process_creation_time
,
process_exit_time
,
FILETIME
process_creation_time
,
process_exit_time
,
process_user_time
,
process_kernel_time
;
process_user_time
,
process_kernel_time
;
// Windows NT only
if
(
is_nt
)
{
// Using static variables declared above
// Using static variables declared above
// Units are 100-ns intervals. Convert to ns.
// Units are 100-ns intervals. Convert to ns.
GetProcessTimes
(
main_process
,
&
process_creation_time
,
GetProcessTimes
(
main_process
,
&
process_creation_time
,
...
@@ -159,9 +110,6 @@ Java_com_sun_management_OperatingSystem_getProcessCpuTime
...
@@ -159,9 +110,6 @@ Java_com_sun_management_OperatingSystem_getProcessCpuTime
process_user_time
.
dwLowDateTime
)
+
process_user_time
.
dwLowDateTime
)
+
jlong_from
(
process_kernel_time
.
dwHighDateTime
,
jlong_from
(
process_kernel_time
.
dwHighDateTime
,
process_kernel_time
.
dwLowDateTime
))
*
100
;
process_kernel_time
.
dwLowDateTime
))
*
100
;
}
else
{
return
-
1
;
}
}
}
JNIEXPORT
jlong
JNICALL
JNIEXPORT
jlong
JNICALL
...
...
src/windows/native/java/io/WinNTFileSystem_md.c
浏览文件 @
135dbba5
...
@@ -23,9 +23,9 @@
...
@@ -23,9 +23,9 @@
* questions.
* questions.
*/
*/
/* Access APIs for Win
2K
and above */
/* Access APIs for Win
XP
and above */
#ifndef _WIN32_WINNT
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x050
0
#define _WIN32_WINNT 0x050
1
#endif
#endif
#include <assert.h>
#include <assert.h>
...
@@ -60,13 +60,17 @@ static GetFinalPathNameByHandleProc GetFinalPathNameByHandle_func;
...
@@ -60,13 +60,17 @@ static GetFinalPathNameByHandleProc GetFinalPathNameByHandle_func;
JNIEXPORT
void
JNICALL
JNIEXPORT
void
JNICALL
Java_java_io_WinNTFileSystem_initIDs
(
JNIEnv
*
env
,
jclass
cls
)
Java_java_io_WinNTFileSystem_initIDs
(
JNIEnv
*
env
,
jclass
cls
)
{
{
H
AND
LE
handle
;
H
MODU
LE
handle
;
jclass
fileClass
=
(
*
env
)
->
FindClass
(
env
,
"java/io/File"
);
jclass
fileClass
=
(
*
env
)
->
FindClass
(
env
,
"java/io/File"
);
if
(
!
fileClass
)
return
;
if
(
!
fileClass
)
return
;
ids
.
path
=
ids
.
path
=
(
*
env
)
->
GetFieldID
(
env
,
fileClass
,
"path"
,
"Ljava/lang/String;"
);
(
*
env
)
->
GetFieldID
(
env
,
fileClass
,
"path"
,
"Ljava/lang/String;"
);
handle
=
LoadLibrary
(
"kernel32"
);
if
(
handle
!=
NULL
)
{
// GetFinalPathNameByHandle requires Windows Vista or newer
if
(
GetModuleHandleExW
((
GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
|
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT
),
(
LPCWSTR
)
&
CreateFileW
,
&
handle
)
!=
0
)
{
GetFinalPathNameByHandle_func
=
(
GetFinalPathNameByHandleProc
)
GetFinalPathNameByHandle_func
=
(
GetFinalPathNameByHandleProc
)
GetProcAddress
(
handle
,
"GetFinalPathNameByHandleW"
);
GetProcAddress
(
handle
,
"GetFinalPathNameByHandleW"
);
}
}
...
@@ -824,8 +828,6 @@ Java_java_io_WinNTFileSystem_getDriveDirectory(JNIEnv *env, jobject this,
...
@@ -824,8 +828,6 @@ Java_java_io_WinNTFileSystem_getDriveDirectory(JNIEnv *env, jobject this,
return
ret
;
return
ret
;
}
}
typedef
BOOL
(
WINAPI
*
GetVolumePathNameProc
)
(
LPCWSTR
,
LPWSTR
,
DWORD
);
JNIEXPORT
jlong
JNICALL
JNIEXPORT
jlong
JNICALL
Java_java_io_WinNTFileSystem_getSpace0
(
JNIEnv
*
env
,
jobject
this
,
Java_java_io_WinNTFileSystem_getSpace0
(
JNIEnv
*
env
,
jobject
this
,
jobject
file
,
jint
t
)
jobject
file
,
jint
t
)
...
@@ -834,14 +836,7 @@ Java_java_io_WinNTFileSystem_getSpace0(JNIEnv *env, jobject this,
...
@@ -834,14 +836,7 @@ Java_java_io_WinNTFileSystem_getSpace0(JNIEnv *env, jobject this,
jlong
rv
=
0L
;
jlong
rv
=
0L
;
WCHAR
*
pathbuf
=
fileToNTPath
(
env
,
file
,
ids
.
path
);
WCHAR
*
pathbuf
=
fileToNTPath
(
env
,
file
,
ids
.
path
);
HMODULE
h
=
LoadLibrary
(
"kernel32"
);
if
(
GetVolumePathNameW
(
pathbuf
,
volname
,
MAX_PATH_LENGTH
))
{
GetVolumePathNameProc
getVolumePathNameW
=
NULL
;
if
(
h
)
{
getVolumePathNameW
=
(
GetVolumePathNameProc
)
GetProcAddress
(
h
,
"GetVolumePathNameW"
);
}
if
(
getVolumePathNameW
(
pathbuf
,
volname
,
MAX_PATH_LENGTH
))
{
ULARGE_INTEGER
totalSpace
,
freeSpace
,
usableSpace
;
ULARGE_INTEGER
totalSpace
,
freeSpace
,
usableSpace
;
if
(
GetDiskFreeSpaceExW
(
volname
,
&
usableSpace
,
&
totalSpace
,
&
freeSpace
))
{
if
(
GetDiskFreeSpaceExW
(
volname
,
&
usableSpace
,
&
totalSpace
,
&
freeSpace
))
{
switch
(
t
)
{
switch
(
t
)
{
...
@@ -860,9 +855,6 @@ Java_java_io_WinNTFileSystem_getSpace0(JNIEnv *env, jobject this,
...
@@ -860,9 +855,6 @@ Java_java_io_WinNTFileSystem_getSpace0(JNIEnv *env, jobject this,
}
}
}
}
if
(
h
)
{
FreeLibrary
(
h
);
}
free
(
pathbuf
);
free
(
pathbuf
);
return
rv
;
return
rv
;
}
}
src/windows/native/java/lang/java_props_md.c
浏览文件 @
135dbba5
...
@@ -196,42 +196,23 @@ getHomeFromRegistry()
...
@@ -196,42 +196,23 @@ getHomeFromRegistry()
/*
/*
* Code to figure out the user's home directory using shell32.dll
* Code to figure out the user's home directory using shell32.dll
*/
*/
typedef
HRESULT
(
WINAPI
*
GetSpecialFolderType
)(
HWND
,
int
,
LPITEMIDLIST
*
);
typedef
BOOL
(
WINAPI
*
GetPathFromIDListType
)(
LPCITEMIDLIST
,
LPSTR
);
WCHAR
*
WCHAR
*
getHomeFromShell32
()
getHomeFromShell32
()
{
{
HMODULE
lib
=
LoadLibraryW
(
L"SHELL32.DLL"
);
GetSpecialFolderType
do_get_folder
;
GetPathFromIDListType
do_get_path
;
HRESULT
rc
;
HRESULT
rc
;
LPITEMIDLIST
item_list
=
0
;
LPITEMIDLIST
item_list
=
0
;
WCHAR
*
p
;
WCHAR
*
p
;
WCHAR
path
[
MAX_PATH
+
1
];
WCHAR
path
[
MAX_PATH
+
1
];
int
size
=
MAX_PATH
+
1
;
int
size
=
MAX_PATH
+
1
;
if
(
lib
==
0
)
{
rc
=
SHGetSpecialFolderLocation
(
NULL
,
CSIDL_DESKTOPDIRECTORY
,
&
item_list
);
// We can't load the library !!??
return
NULL
;
}
do_get_folder
=
(
GetSpecialFolderType
)
GetProcAddress
(
lib
,
"SHGetSpecialFolderLocation"
);
do_get_path
=
(
GetPathFromIDListType
)
GetProcAddress
(
lib
,
"SHGetPathFromIDListW"
);
if
(
do_get_folder
==
0
||
do_get_path
==
0
)
{
// the library doesn't hold the right functions !!??
return
NULL
;
}
rc
=
(
*
do_get_folder
)(
NULL
,
CSIDL_DESKTOPDIRECTORY
,
&
item_list
);
if
(
!
SUCCEEDED
(
rc
))
{
if
(
!
SUCCEEDED
(
rc
))
{
// we can't find the shell folder.
// we can't find the shell folder.
return
NULL
;
return
NULL
;
}
}
path
[
0
]
=
0
;
path
[
0
]
=
0
;
(
*
do_get_path
)(
item_list
,
(
LP
STR
)
path
);
SHGetPathFromIDListW
(
item_list
,
(
LPW
STR
)
path
);
/* Get the parent of Desktop directory */
/* Get the parent of Desktop directory */
p
=
wcsrchr
(
path
,
L'\\'
);
p
=
wcsrchr
(
path
,
L'\\'
);
...
@@ -253,17 +234,7 @@ getHomeFromShell32()
...
@@ -253,17 +234,7 @@ getHomeFromShell32()
static
boolean
static
boolean
haveMMX
(
void
)
haveMMX
(
void
)
{
{
boolean
mmx
=
0
;
return
IsProcessorFeaturePresent
(
PF_MMX_INSTRUCTIONS_AVAILABLE
);
HMODULE
lib
=
LoadLibrary
(
"KERNEL32"
);
if
(
lib
!=
NULL
)
{
BOOL
(
WINAPI
*
isProcessorFeaturePresent
)(
DWORD
)
=
(
BOOL
(
WINAPI
*
)(
DWORD
))
GetProcAddress
(
lib
,
"IsProcessorFeaturePresent"
);
if
(
isProcessorFeaturePresent
!=
NULL
)
mmx
=
isProcessorFeaturePresent
(
PF_MMX_INSTRUCTIONS_AVAILABLE
);
FreeLibrary
(
lib
);
}
return
mmx
;
}
}
static
const
char
*
static
const
char
*
...
@@ -532,10 +503,19 @@ GetJavaProperties(JNIEnv* env)
...
@@ -532,10 +503,19 @@ GetJavaProperties(JNIEnv* env)
if
(
uname
!=
NULL
&&
wcslen
(
uname
)
>
0
)
{
if
(
uname
!=
NULL
&&
wcslen
(
uname
)
>
0
)
{
sprops
.
user_name
=
_wcsdup
(
uname
);
sprops
.
user_name
=
_wcsdup
(
uname
);
}
else
{
}
else
{
WCHAR
buf
[
100
];
DWORD
buflen
=
0
;
int
buflen
=
sizeof
(
buf
);
if
(
GetUserNameW
(
NULL
,
&
buflen
)
==
0
&&
sprops
.
user_name
=
GetLastError
()
==
ERROR_INSUFFICIENT_BUFFER
)
GetUserNameW
(
buf
,
&
buflen
)
?
_wcsdup
(
buf
)
:
L"unknown"
;
{
uname
=
(
WCHAR
*
)
malloc
(
buflen
*
sizeof
(
WCHAR
));
if
(
uname
!=
NULL
&&
GetUserNameW
(
uname
,
&
buflen
)
==
0
)
{
free
(
uname
);
uname
=
NULL
;
}
}
else
{
uname
=
NULL
;
}
sprops
.
user_name
=
(
uname
!=
NULL
)
?
uname
:
L"unknown"
;
}
}
}
}
...
@@ -633,7 +613,7 @@ GetJavaProperties(JNIEnv* env)
...
@@ -633,7 +613,7 @@ GetJavaProperties(JNIEnv* env)
/* Current directory */
/* Current directory */
{
{
WCHAR
buf
[
MAX_PATH
];
WCHAR
buf
[
MAX_PATH
];
GetCurrentDirectoryW
(
sizeof
(
buf
),
buf
);
if
(
GetCurrentDirectoryW
(
sizeof
(
buf
)
/
sizeof
(
WCHAR
),
buf
)
!=
0
)
sprops
.
user_dir
=
_wcsdup
(
buf
);
sprops
.
user_dir
=
_wcsdup
(
buf
);
}
}
...
...
src/windows/native/sun/management/FileSystemImpl.c
浏览文件 @
135dbba5
...
@@ -36,45 +36,6 @@
...
@@ -36,45 +36,6 @@
*/
*/
#define ANY_ACCESS (FILE_GENERIC_READ | FILE_GENERIC_WRITE | FILE_GENERIC_EXECUTE)
#define ANY_ACCESS (FILE_GENERIC_READ | FILE_GENERIC_WRITE | FILE_GENERIC_EXECUTE)
/*
* Function prototypes for security functions - we can't statically
* link because these functions aren't on Windows 9x.
*/
typedef
BOOL
(
WINAPI
*
GetFileSecurityFunc
)
(
LPCTSTR
lpFileName
,
SECURITY_INFORMATION
RequestedInformation
,
PSECURITY_DESCRIPTOR
pSecurityDescriptor
,
DWORD
nLength
,
LPDWORD
lpnLengthNeeded
);
typedef
BOOL
(
WINAPI
*
GetSecurityDescriptorOwnerFunc
)
(
PSECURITY_DESCRIPTOR
pSecurityDescriptor
,
PSID
*
pOwner
,
LPBOOL
lpbOwnerDefaulted
);
typedef
BOOL
(
WINAPI
*
GetSecurityDescriptorDaclFunc
)
(
PSECURITY_DESCRIPTOR
pSecurityDescriptor
,
LPBOOL
lpbDaclPresent
,
PACL
*
pDacl
,
LPBOOL
lpbDaclDefaulted
);
typedef
BOOL
(
WINAPI
*
GetAclInformationFunc
)
(
PACL
pAcl
,
LPVOID
pAclInformation
,
DWORD
nAclInformationLength
,
ACL_INFORMATION_CLASS
dwAclInformationClass
);
typedef
BOOL
(
WINAPI
*
GetAceFunc
)
(
PACL
pAcl
,
DWORD
dwAceIndex
,
LPVOID
*
pAce
);
typedef
BOOL
(
WINAPI
*
EqualSidFunc
)(
PSID
pSid1
,
PSID
pSid2
);
/* Addresses of the security functions */
static
GetFileSecurityFunc
GetFileSecurity_func
;
static
GetSecurityDescriptorOwnerFunc
GetSecurityDescriptorOwner_func
;
static
GetSecurityDescriptorDaclFunc
GetSecurityDescriptorDacl_func
;
static
GetAclInformationFunc
GetAclInformation_func
;
static
GetAceFunc
GetAce_func
;
static
EqualSidFunc
EqualSid_func
;
/* True if this OS is NT kernel based (NT/2000/XP) */
static
int
isNT
;
/*
/*
* Returns JNI_TRUE if the specified file is on a file system that supports
* Returns JNI_TRUE if the specified file is on a file system that supports
* persistent ACLs (On NTFS file systems returns true, on FAT32 file systems
* persistent ACLs (On NTFS file systems returns true, on FAT32 file systems
...
@@ -165,7 +126,7 @@ static SECURITY_DESCRIPTOR* getFileSecurityDescriptor(JNIEnv* env, const char* p
...
@@ -165,7 +126,7 @@ static SECURITY_DESCRIPTOR* getFileSecurityDescriptor(JNIEnv* env, const char* p
SECURITY_INFORMATION
info
=
SECURITY_INFORMATION
info
=
OWNER_SECURITY_INFORMATION
|
DACL_SECURITY_INFORMATION
;
OWNER_SECURITY_INFORMATION
|
DACL_SECURITY_INFORMATION
;
(
*
GetFileSecurity_func
)
(
path
,
info
,
0
,
0
,
&
len
);
GetFileSecurityA
(
path
,
info
,
0
,
0
,
&
len
);
if
(
GetLastError
()
!=
ERROR_INSUFFICIENT_BUFFER
)
{
if
(
GetLastError
()
!=
ERROR_INSUFFICIENT_BUFFER
)
{
JNU_ThrowIOExceptionWithLastError
(
env
,
"GetFileSecurity failed"
);
JNU_ThrowIOExceptionWithLastError
(
env
,
"GetFileSecurity failed"
);
return
NULL
;
return
NULL
;
...
@@ -174,7 +135,7 @@ static SECURITY_DESCRIPTOR* getFileSecurityDescriptor(JNIEnv* env, const char* p
...
@@ -174,7 +135,7 @@ static SECURITY_DESCRIPTOR* getFileSecurityDescriptor(JNIEnv* env, const char* p
if
(
sd
==
NULL
)
{
if
(
sd
==
NULL
)
{
JNU_ThrowOutOfMemoryError
(
env
,
0
);
JNU_ThrowOutOfMemoryError
(
env
,
0
);
}
else
{
}
else
{
if
(
!
(
*
GetFileSecurity
_func
)(
path
,
info
,
sd
,
len
,
&
len
))
{
if
(
!
(
*
GetFileSecurity
A
)(
path
,
info
,
sd
,
len
,
&
len
))
{
JNU_ThrowIOExceptionWithLastError
(
env
,
"GetFileSecurity failed"
);
JNU_ThrowIOExceptionWithLastError
(
env
,
"GetFileSecurity failed"
);
free
(
sd
);
free
(
sd
);
return
NULL
;
return
NULL
;
...
@@ -191,7 +152,7 @@ static SID* getFileOwner(JNIEnv* env, SECURITY_DESCRIPTOR* sd) {
...
@@ -191,7 +152,7 @@ static SID* getFileOwner(JNIEnv* env, SECURITY_DESCRIPTOR* sd) {
SID
*
owner
;
SID
*
owner
;
BOOL
defaulted
;
BOOL
defaulted
;
if
(
!
(
*
GetSecurityDescriptorOwner_func
)
(
sd
,
&
owner
,
&
defaulted
))
{
if
(
!
GetSecurityDescriptorOwner
(
sd
,
&
owner
,
&
defaulted
))
{
JNU_ThrowIOExceptionWithLastError
(
env
,
"GetSecurityDescriptorOwner failed"
);
JNU_ThrowIOExceptionWithLastError
(
env
,
"GetSecurityDescriptorOwner failed"
);
return
NULL
;
return
NULL
;
}
}
...
@@ -206,7 +167,7 @@ static ACL* getFileDACL(JNIEnv* env, SECURITY_DESCRIPTOR* sd) {
...
@@ -206,7 +167,7 @@ static ACL* getFileDACL(JNIEnv* env, SECURITY_DESCRIPTOR* sd) {
ACL
*
acl
;
ACL
*
acl
;
int
defaulted
,
present
;
int
defaulted
,
present
;
if
(
!
(
*
GetSecurityDescriptorDacl_func
)
(
sd
,
&
present
,
&
acl
,
&
defaulted
))
{
if
(
!
GetSecurityDescriptorDacl
(
sd
,
&
present
,
&
acl
,
&
defaulted
))
{
JNU_ThrowIOExceptionWithLastError
(
env
,
"GetSecurityDescriptorDacl failed"
);
JNU_ThrowIOExceptionWithLastError
(
env
,
"GetSecurityDescriptorDacl failed"
);
return
NULL
;
return
NULL
;
}
}
...
@@ -235,7 +196,7 @@ static jboolean isAccessUserOnly(JNIEnv* env, SID* owner, ACL* acl) {
...
@@ -235,7 +196,7 @@ static jboolean isAccessUserOnly(JNIEnv* env, SID* owner, ACL* acl) {
/*
/*
* Get the ACE count
* Get the ACE count
*/
*/
if
(
!
(
*
GetAclInformation_func
)
(
acl
,
(
void
*
)
&
acl_size_info
,
sizeof
(
acl_size_info
),
if
(
!
GetAclInformation
(
acl
,
(
void
*
)
&
acl_size_info
,
sizeof
(
acl_size_info
),
AclSizeInformation
))
{
AclSizeInformation
))
{
JNU_ThrowIOExceptionWithLastError
(
env
,
"GetAclInformation failed"
);
JNU_ThrowIOExceptionWithLastError
(
env
,
"GetAclInformation failed"
);
return
JNI_FALSE
;
return
JNI_FALSE
;
...
@@ -250,7 +211,7 @@ static jboolean isAccessUserOnly(JNIEnv* env, SID* owner, ACL* acl) {
...
@@ -250,7 +211,7 @@ static jboolean isAccessUserOnly(JNIEnv* env, SID* owner, ACL* acl) {
ACCESS_ALLOWED_ACE
*
access
;
ACCESS_ALLOWED_ACE
*
access
;
SID
*
sid
;
SID
*
sid
;
if
(
!
(
*
GetAce_func
)
(
acl
,
i
,
&
ace
))
{
if
(
!
GetAce
(
acl
,
i
,
&
ace
))
{
JNU_ThrowIOExceptionWithLastError
(
env
,
"GetAce failed"
);
JNU_ThrowIOExceptionWithLastError
(
env
,
"GetAce failed"
);
return
-
1
;
return
-
1
;
}
}
...
@@ -280,51 +241,7 @@ static jboolean isAccessUserOnly(JNIEnv* env, SID* owner, ACL* acl) {
...
@@ -280,51 +241,7 @@ static jboolean isAccessUserOnly(JNIEnv* env, SID* owner, ACL* acl) {
JNIEXPORT
void
JNICALL
Java_sun_management_FileSystemImpl_init0
JNIEXPORT
void
JNICALL
Java_sun_management_FileSystemImpl_init0
(
JNIEnv
*
env
,
jclass
ignored
)
(
JNIEnv
*
env
,
jclass
ignored
)
{
{
OSVERSIONINFO
ver
;
/* nothing to do */
HINSTANCE
hInst
;
/*
* Get the OS version. If dwPlatformId is VER_PLATFORM_WIN32_NT
* it means we're running on a Windows NT, 2000, or XP machine.
*/
ver
.
dwOSVersionInfoSize
=
sizeof
(
ver
);
GetVersionEx
(
&
ver
);
isNT
=
(
ver
.
dwPlatformId
==
VER_PLATFORM_WIN32_NT
);
if
(
!
isNT
)
{
return
;
}
/*
* On NT/2000/XP we need the addresses of the security functions
*/
hInst
=
LoadLibrary
(
"ADVAPI32.DLL"
);
if
(
hInst
==
NULL
)
{
JNU_ThrowIOExceptionWithLastError
(
env
,
"Unable to load ADVAPI32.DLL"
);
return
;
}
GetFileSecurity_func
=
(
GetFileSecurityFunc
)
GetProcAddress
(
hInst
,
"GetFileSecurityA"
);
GetSecurityDescriptorOwner_func
=
(
GetSecurityDescriptorOwnerFunc
)
GetProcAddress
(
hInst
,
"GetSecurityDescriptorOwner"
);
GetSecurityDescriptorDacl_func
=
(
GetSecurityDescriptorDaclFunc
)
GetProcAddress
(
hInst
,
"GetSecurityDescriptorDacl"
);
GetAclInformation_func
=
(
GetAclInformationFunc
)
GetProcAddress
(
hInst
,
"GetAclInformation"
);
GetAce_func
=
(
GetAceFunc
)
GetProcAddress
(
hInst
,
"GetAce"
);
EqualSid_func
=
(
EqualSidFunc
)
GetProcAddress
(
hInst
,
"EqualSid"
);
if
(
GetFileSecurity_func
==
NULL
||
GetSecurityDescriptorDacl_func
==
NULL
||
GetSecurityDescriptorDacl_func
==
NULL
||
GetAclInformation_func
==
NULL
||
GetAce_func
==
NULL
||
EqualSid_func
==
NULL
)
{
JNU_ThrowIOExceptionWithLastError
(
env
,
"Unable to get address of security functions"
);
return
;
}
}
}
/*
/*
...
@@ -339,10 +256,6 @@ JNIEXPORT jboolean JNICALL Java_sun_management_FileSystemImpl_isSecuritySupporte
...
@@ -339,10 +256,6 @@ JNIEXPORT jboolean JNICALL Java_sun_management_FileSystemImpl_isSecuritySupporte
jboolean
isCopy
;
jboolean
isCopy
;
const
char
*
path
;
const
char
*
path
;
if
(
!
isNT
)
{
return
JNI_FALSE
;
}
path
=
JNU_GetStringPlatformChars
(
env
,
str
,
&
isCopy
);
path
=
JNU_GetStringPlatformChars
(
env
,
str
,
&
isCopy
);
if
(
path
!=
NULL
)
{
if
(
path
!=
NULL
)
{
res
=
isSecuritySupported
(
env
,
path
);
res
=
isSecuritySupported
(
env
,
path
);
...
...
src/windows/native/sun/nio/fs/WindowsNativeDispatcher.c
浏览文件 @
135dbba5
...
@@ -24,7 +24,7 @@
...
@@ -24,7 +24,7 @@
*/
*/
#ifndef _WIN32_WINNT
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x050
0
#define _WIN32_WINNT 0x050
1
#endif
#endif
#include <stdio.h>
#include <stdio.h>
...
@@ -36,6 +36,7 @@
...
@@ -36,6 +36,7 @@
#include <windows.h>
#include <windows.h>
#include <aclapi.h>
#include <aclapi.h>
#include <winioctl.h>
#include <winioctl.h>
#include <Sddl.h>
#include "jni.h"
#include "jni.h"
#include "jni_util.h"
#include "jni_util.h"
...
@@ -77,40 +78,20 @@ static jfieldID backupResult_context;
...
@@ -77,40 +78,20 @@ static jfieldID backupResult_context;
/**
/**
* Win32 APIs not
defined in Visual Studio 2003 header files
* Win32 APIs not
available in Windows XP
*/
*/
typedef
HANDLE
(
WINAPI
*
FindFirstStream_Proc
)(
LPCWSTR
,
STREAM_INFO_LEVELS
,
LPVOID
,
DWORD
);
typedef
enum
{
FindStreamInfoStandard
}
MY_STREAM_INFO_LEVELS
;
typedef
struct
_MY_WIN32_FIND_STREAM_DATA
{
LARGE_INTEGER
StreamSize
;
WCHAR
cStreamName
[
MAX_PATH
+
36
];
}
MY_WIN32_FIND_STREAM_DATA
;
typedef
HANDLE
(
WINAPI
*
FindFirstStream_Proc
)(
LPCWSTR
,
MY_STREAM_INFO_LEVELS
,
LPVOID
,
DWORD
);
typedef
BOOL
(
WINAPI
*
FindNextStream_Proc
)(
HANDLE
,
LPVOID
);
typedef
BOOL
(
WINAPI
*
FindNextStream_Proc
)(
HANDLE
,
LPVOID
);
typedef
BOOLEAN
(
WINAPI
*
CreateSymbolicLinkProc
)
(
LPCWSTR
,
LPCWSTR
,
DWORD
);
typedef
BOOLEAN
(
WINAPI
*
CreateSymbolicLinkProc
)
(
LPCWSTR
,
LPCWSTR
,
DWORD
);
typedef
BOOL
(
WINAPI
*
CreateHardLinkProc
)
(
LPCWSTR
,
LPCWSTR
,
LPSECURITY_ATTRIBUTES
);
typedef
BOOL
(
WINAPI
*
GetFinalPathNameByHandleProc
)
(
HANDLE
,
LPWSTR
,
DWORD
,
DWORD
);
typedef
BOOL
(
WINAPI
*
GetFinalPathNameByHandleProc
)
(
HANDLE
,
LPWSTR
,
DWORD
,
DWORD
);
typedef
BOOL
(
WINAPI
*
ConvertSidToStringSidProc
)
(
PSID
,
LPWSTR
*
);
typedef
BOOL
(
WINAPI
*
ConvertStringSidToSidProc
)
(
LPWSTR
,
PSID
*
);
typedef
DWORD
(
WINAPI
*
GetLengthSidProc
)
(
PSID
);
static
FindFirstStream_Proc
FindFirstStream_func
;
static
FindFirstStream_Proc
FindFirstStream_func
;
static
FindNextStream_Proc
FindNextStream_func
;
static
FindNextStream_Proc
FindNextStream_func
;
static
CreateSymbolicLinkProc
CreateSymbolicLink_func
;
static
CreateSymbolicLinkProc
CreateSymbolicLink_func
;
static
CreateHardLinkProc
CreateHardLink_func
;
static
GetFinalPathNameByHandleProc
GetFinalPathNameByHandle_func
;
static
GetFinalPathNameByHandleProc
GetFinalPathNameByHandle_func
;
static
ConvertSidToStringSidProc
ConvertSidToStringSid_func
;
static
ConvertStringSidToSidProc
ConvertStringSidToSid_func
;
static
GetLengthSidProc
GetLengthSid_func
;
static
void
throwWindowsException
(
JNIEnv
*
env
,
DWORD
lastError
)
{
static
void
throwWindowsException
(
JNIEnv
*
env
,
DWORD
lastError
)
{
jobject
x
=
JNU_NewObjectByName
(
env
,
"sun/nio/fs/WindowsException"
,
jobject
x
=
JNU_NewObjectByName
(
env
,
"sun/nio/fs/WindowsException"
,
"(I)V"
,
lastError
);
"(I)V"
,
lastError
);
...
@@ -190,33 +171,23 @@ Java_sun_nio_fs_WindowsNativeDispatcher_initIDs(JNIEnv* env, jclass this)
...
@@ -190,33 +171,23 @@ Java_sun_nio_fs_WindowsNativeDispatcher_initIDs(JNIEnv* env, jclass this)
backupResult_bytesTransferred
=
(
*
env
)
->
GetFieldID
(
env
,
clazz
,
"bytesTransferred"
,
"I"
);
backupResult_bytesTransferred
=
(
*
env
)
->
GetFieldID
(
env
,
clazz
,
"bytesTransferred"
,
"I"
);
backupResult_context
=
(
*
env
)
->
GetFieldID
(
env
,
clazz
,
"context"
,
"J"
);
backupResult_context
=
(
*
env
)
->
GetFieldID
(
env
,
clazz
,
"context"
,
"J"
);
// get handle to kernel32
h
=
LoadLibrary
(
"kernel32"
);
if
(
GetModuleHandleExW
((
GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
|
if
(
h
!=
INVALID_HANDLE_VALUE
)
{
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT
),
(
LPCWSTR
)
&
CreateFileW
,
&
h
)
!=
0
)
{
// requires Windows Server 2003 or newer
FindFirstStream_func
=
FindFirstStream_func
=
(
FindFirstStream_Proc
)
GetProcAddress
(
h
,
"FindFirstStreamW"
);
(
FindFirstStream_Proc
)
GetProcAddress
(
h
,
"FindFirstStreamW"
);
FindNextStream_func
=
FindNextStream_func
=
(
FindNextStream_Proc
)
GetProcAddress
(
h
,
"FindNextStreamW"
);
(
FindNextStream_Proc
)
GetProcAddress
(
h
,
"FindNextStreamW"
);
// requires Windows Vista or newer
CreateSymbolicLink_func
=
CreateSymbolicLink_func
=
(
CreateSymbolicLinkProc
)
GetProcAddress
(
h
,
"CreateSymbolicLinkW"
);
(
CreateSymbolicLinkProc
)
GetProcAddress
(
h
,
"CreateSymbolicLinkW"
);
CreateHardLink_func
=
(
CreateHardLinkProc
)
GetProcAddress
(
h
,
"CreateHardLinkW"
);
GetFinalPathNameByHandle_func
=
GetFinalPathNameByHandle_func
=
(
GetFinalPathNameByHandleProc
)
GetProcAddress
(
h
,
"GetFinalPathNameByHandleW"
);
(
GetFinalPathNameByHandleProc
)
GetProcAddress
(
h
,
"GetFinalPathNameByHandleW"
);
FreeLibrary
(
h
);
}
}
h
=
LoadLibrary
(
"advapi32"
);
if
(
h
!=
INVALID_HANDLE_VALUE
)
{
ConvertSidToStringSid_func
=
(
ConvertSidToStringSidProc
)
GetProcAddress
(
h
,
"ConvertSidToStringSidW"
);
ConvertStringSidToSid_func
=
(
ConvertStringSidToSidProc
)
GetProcAddress
(
h
,
"ConvertStringSidToSidW"
);
GetLengthSid_func
=
(
GetLengthSidProc
)
GetProcAddress
(
h
,
"GetLengthSid"
);
FreeLibrary
(
h
);
}
}
}
JNIEXPORT
jstring
JNICALL
JNIEXPORT
jstring
JNICALL
...
@@ -413,7 +384,7 @@ JNIEXPORT void JNICALL
...
@@ -413,7 +384,7 @@ JNIEXPORT void JNICALL
Java_sun_nio_fs_WindowsNativeDispatcher_FindFirstStream0
(
JNIEnv
*
env
,
jclass
this
,
Java_sun_nio_fs_WindowsNativeDispatcher_FindFirstStream0
(
JNIEnv
*
env
,
jclass
this
,
jlong
address
,
jobject
obj
)
jlong
address
,
jobject
obj
)
{
{
MY_
WIN32_FIND_STREAM_DATA
data
;
WIN32_FIND_STREAM_DATA
data
;
LPCWSTR
lpFileName
=
jlong_to_ptr
(
address
);
LPCWSTR
lpFileName
=
jlong_to_ptr
(
address
);
HANDLE
handle
;
HANDLE
handle
;
...
@@ -443,7 +414,7 @@ JNIEXPORT jstring JNICALL
...
@@ -443,7 +414,7 @@ JNIEXPORT jstring JNICALL
Java_sun_nio_fs_WindowsNativeDispatcher_FindNextStream
(
JNIEnv
*
env
,
jclass
this
,
Java_sun_nio_fs_WindowsNativeDispatcher_FindNextStream
(
JNIEnv
*
env
,
jclass
this
,
jlong
handle
)
jlong
handle
)
{
{
MY_
WIN32_FIND_STREAM_DATA
data
;
WIN32_FIND_STREAM_DATA
data
;
HANDLE
h
=
(
HANDLE
)
jlong_to_ptr
(
handle
);
HANDLE
h
=
(
HANDLE
)
jlong_to_ptr
(
handle
);
if
(
FindNextStream_func
==
NULL
)
{
if
(
FindNextStream_func
==
NULL
)
{
...
@@ -909,12 +880,7 @@ Java_sun_nio_fs_WindowsNativeDispatcher_GetLengthSid(JNIEnv* env,
...
@@ -909,12 +880,7 @@ Java_sun_nio_fs_WindowsNativeDispatcher_GetLengthSid(JNIEnv* env,
jclass
this
,
jlong
address
)
jclass
this
,
jlong
address
)
{
{
PSID
sid
=
jlong_to_ptr
(
address
);
PSID
sid
=
jlong_to_ptr
(
address
);
return
(
jint
)
GetLengthSid
(
sid
);
if
(
GetLengthSid_func
==
NULL
)
{
JNU_ThrowInternalError
(
env
,
"Should not get here"
);
return
0
;
}
return
(
jint
)(
*
GetLengthSid_func
)(
sid
);
}
}
...
@@ -924,13 +890,7 @@ Java_sun_nio_fs_WindowsNativeDispatcher_ConvertSidToStringSid(JNIEnv* env,
...
@@ -924,13 +890,7 @@ Java_sun_nio_fs_WindowsNativeDispatcher_ConvertSidToStringSid(JNIEnv* env,
{
{
PSID
sid
=
jlong_to_ptr
(
address
);
PSID
sid
=
jlong_to_ptr
(
address
);
LPWSTR
string
;
LPWSTR
string
;
if
(
ConvertSidToStringSidW
(
sid
,
&
string
)
==
0
)
{
if
(
ConvertSidToStringSid_func
==
NULL
)
{
JNU_ThrowInternalError
(
env
,
"Should not get here"
);
return
NULL
;
}
if
((
*
ConvertSidToStringSid_func
)(
sid
,
&
string
)
==
0
)
{
throwWindowsException
(
env
,
GetLastError
());
throwWindowsException
(
env
,
GetLastError
());
return
NULL
;
return
NULL
;
}
else
{
}
else
{
...
@@ -947,15 +907,8 @@ Java_sun_nio_fs_WindowsNativeDispatcher_ConvertStringSidToSid0(JNIEnv* env,
...
@@ -947,15 +907,8 @@ Java_sun_nio_fs_WindowsNativeDispatcher_ConvertStringSidToSid0(JNIEnv* env,
{
{
LPWSTR
lpStringSid
=
jlong_to_ptr
(
address
);
LPWSTR
lpStringSid
=
jlong_to_ptr
(
address
);
PSID
pSid
;
PSID
pSid
;
if
(
ConvertStringSidToSidW
(
lpStringSid
,
&
pSid
)
==
0
)
if
(
ConvertStringSidToSid_func
==
NULL
)
{
JNU_ThrowInternalError
(
env
,
"Should not get here"
);
return
(
jlong
)
0
;
}
if
((
*
ConvertStringSidToSid_func
)(
lpStringSid
,
&
pSid
)
==
0
)
throwWindowsException
(
env
,
GetLastError
());
throwWindowsException
(
env
,
GetLastError
());
return
ptr_to_jlong
(
pSid
);
return
ptr_to_jlong
(
pSid
);
}
}
...
@@ -1137,11 +1090,7 @@ Java_sun_nio_fs_WindowsNativeDispatcher_CreateHardLink0(JNIEnv* env,
...
@@ -1137,11 +1090,7 @@ Java_sun_nio_fs_WindowsNativeDispatcher_CreateHardLink0(JNIEnv* env,
LPCWSTR
newFile
=
jlong_to_ptr
(
newFileAddress
);
LPCWSTR
newFile
=
jlong_to_ptr
(
newFileAddress
);
LPCWSTR
existingFile
=
jlong_to_ptr
(
existingFileAddress
);
LPCWSTR
existingFile
=
jlong_to_ptr
(
existingFileAddress
);
if
(
CreateHardLink_func
==
NULL
)
{
if
(
CreateHardLinkW
(
newFile
,
existingFile
,
NULL
)
==
0
)
JNU_ThrowInternalError
(
env
,
"Should not get here"
);
return
;
}
if
((
*
CreateHardLink_func
)(
newFile
,
existingFile
,
NULL
)
==
0
)
throwWindowsException
(
env
,
GetLastError
());
throwWindowsException
(
env
,
GetLastError
());
}
}
...
...
src/windows/native/sun/security/provider/WinCAPISeedGenerator.c
浏览文件 @
135dbba5
...
@@ -33,11 +33,6 @@
...
@@ -33,11 +33,6 @@
#include <jni.h>
#include <jni.h>
#include "sun_security_provider_NativeSeedGenerator.h"
#include "sun_security_provider_NativeSeedGenerator.h"
/* Typedefs for runtime linking. */
typedef
BOOL
(
WINAPI
*
CryptAcquireContextType
)(
HCRYPTPROV
*
,
LPCTSTR
,
LPCTSTR
,
DWORD
,
DWORD
);
typedef
BOOL
(
WINAPI
*
CryptGenRandomType
)(
HCRYPTPROV
,
DWORD
,
BYTE
*
);
typedef
BOOL
(
WINAPI
*
CryptReleaseContextType
)(
HCRYPTPROV
,
DWORD
);
/*
/*
* Get a random seed from the MS CryptoAPI. Return true if successful, false
* Get a random seed from the MS CryptoAPI. Return true if successful, false
* otherwise.
* otherwise.
...
@@ -49,48 +44,27 @@ typedef BOOL (WINAPI *CryptReleaseContextType)(HCRYPTPROV, DWORD);
...
@@ -49,48 +44,27 @@ typedef BOOL (WINAPI *CryptReleaseContextType)(HCRYPTPROV, DWORD);
JNIEXPORT
jboolean
JNICALL
Java_sun_security_provider_NativeSeedGenerator_nativeGenerateSeed
JNIEXPORT
jboolean
JNICALL
Java_sun_security_provider_NativeSeedGenerator_nativeGenerateSeed
(
JNIEnv
*
env
,
jclass
clazz
,
jbyteArray
randArray
)
(
JNIEnv
*
env
,
jclass
clazz
,
jbyteArray
randArray
)
{
{
HMODULE
lib
;
CryptAcquireContextType
acquireContext
;
CryptGenRandomType
genRandom
;
CryptReleaseContextType
releaseContext
;
HCRYPTPROV
hCryptProv
;
HCRYPTPROV
hCryptProv
;
jboolean
result
=
JNI_FALSE
;
jboolean
result
=
JNI_FALSE
;
jsize
numBytes
;
jsize
numBytes
;
jbyte
*
randBytes
;
jbyte
*
randBytes
;
lib
=
LoadLibrary
(
"ADVAPI32.DLL"
);
if
(
CryptAcquireContextA
(
&
hCryptProv
,
"J2SE"
,
NULL
,
PROV_RSA_FULL
,
0
)
==
FALSE
)
{
if
(
lib
==
NULL
)
{
return
result
;
}
acquireContext
=
(
CryptAcquireContextType
)
GetProcAddress
(
lib
,
"CryptAcquireContextA"
);
genRandom
=
(
CryptGenRandomType
)
GetProcAddress
(
lib
,
"CryptGenRandom"
);
releaseContext
=
(
CryptReleaseContextType
)
GetProcAddress
(
lib
,
"CryptReleaseContext"
);
if
(
acquireContext
==
NULL
||
genRandom
==
NULL
||
releaseContext
==
NULL
)
{
FreeLibrary
(
lib
);
return
result
;
}
if
(
acquireContext
(
&
hCryptProv
,
"J2SE"
,
NULL
,
PROV_RSA_FULL
,
0
)
==
FALSE
)
{
/* If CSP context hasn't been created, create one. */
/* If CSP context hasn't been created, create one. */
if
(
acquireContext
(
&
hCryptProv
,
"J2SE"
,
NULL
,
PROV_RSA_FULL
,
if
(
CryptAcquireContextA
(
&
hCryptProv
,
"J2SE"
,
NULL
,
PROV_RSA_FULL
,
CRYPT_NEWKEYSET
)
==
FALSE
)
{
CRYPT_NEWKEYSET
)
==
FALSE
)
{
FreeLibrary
(
lib
);
return
result
;
return
result
;
}
}
}
}
numBytes
=
(
*
env
)
->
GetArrayLength
(
env
,
randArray
);
numBytes
=
(
*
env
)
->
GetArrayLength
(
env
,
randArray
);
randBytes
=
(
*
env
)
->
GetByteArrayElements
(
env
,
randArray
,
NULL
);
randBytes
=
(
*
env
)
->
GetByteArrayElements
(
env
,
randArray
,
NULL
);
if
(
g
enRandom
(
hCryptProv
,
numBytes
,
randBytes
))
{
if
(
CryptG
enRandom
(
hCryptProv
,
numBytes
,
randBytes
))
{
result
=
JNI_TRUE
;
result
=
JNI_TRUE
;
}
}
(
*
env
)
->
ReleaseByteArrayElements
(
env
,
randArray
,
randBytes
,
0
);
(
*
env
)
->
ReleaseByteArrayElements
(
env
,
randArray
,
randBytes
,
0
);
releaseContext
(
hCryptProv
,
0
);
CryptReleaseContext
(
hCryptProv
,
0
);
FreeLibrary
(
lib
);
return
result
;
return
result
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录