win: use ProcessPrng (#4836)
Refs: https://github.com/libuv/libuv/pull/2762#issuecomment-3065018271
This commit is contained in:
parent
917c1ad1d1
commit
7484ab251f
@ -61,7 +61,7 @@ static int uv__random(void* buf, size_t buflen) {
|
|||||||
# endif
|
# endif
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
uv__once_init();
|
uv__once_init();
|
||||||
rc = uv__random_rtlgenrandom(buf, buflen);
|
rc = uv__random_winrandom(buf, buflen);
|
||||||
#else
|
#else
|
||||||
rc = uv__random_devurandom(buf, buflen);
|
rc = uv__random_devurandom(buf, buflen);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -1269,7 +1269,7 @@ void fs__mktemp(uv_fs_t* req, uv__fs_mktemp_func func) {
|
|||||||
|
|
||||||
tries = TMP_MAX;
|
tries = TMP_MAX;
|
||||||
do {
|
do {
|
||||||
if (uv__random_rtlgenrandom((void *)&v, sizeof(v)) < 0) {
|
if (uv__random_winrandom(&v, sizeof(v)) < 0) {
|
||||||
SET_REQ_UV_ERROR(req, UV_EIO, ERROR_IO_DEVICE);
|
SET_REQ_UV_ERROR(req, UV_EIO, ERROR_IO_DEVICE);
|
||||||
goto clobber;
|
goto clobber;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -269,7 +269,7 @@ int uv__getsockpeername(const uv_handle_t* handle,
|
|||||||
int* namelen,
|
int* namelen,
|
||||||
int delayed_error);
|
int delayed_error);
|
||||||
|
|
||||||
int uv__random_rtlgenrandom(void* buf, size_t buflen);
|
int uv__random_winrandom(void* buf, size_t buflen);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -1747,10 +1747,13 @@ int uv_gettimeofday(uv_timeval64_t* tv) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int uv__random_rtlgenrandom(void* buf, size_t buflen) {
|
int uv__random_winrandom(void* buf, size_t buflen) {
|
||||||
if (buflen == 0)
|
if (buflen == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
if (pProcessPrng != NULL && pProcessPrng(buf, buflen))
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (SystemFunction036(buf, buflen) == FALSE)
|
if (SystemFunction036(buf, buflen) == FALSE)
|
||||||
return UV_EIO;
|
return UV_EIO;
|
||||||
|
|
||||||
|
|||||||
@ -39,6 +39,9 @@ sNtQueryInformationProcess pNtQueryInformationProcess;
|
|||||||
/* Powrprof.dll function pointer */
|
/* Powrprof.dll function pointer */
|
||||||
sPowerRegisterSuspendResumeNotification pPowerRegisterSuspendResumeNotification;
|
sPowerRegisterSuspendResumeNotification pPowerRegisterSuspendResumeNotification;
|
||||||
|
|
||||||
|
/* bcryptprimitives.dll function pointer */
|
||||||
|
sProcessPrng pProcessPrng;
|
||||||
|
|
||||||
/* User32.dll function pointer */
|
/* User32.dll function pointer */
|
||||||
sSetWinEventHook pSetWinEventHook;
|
sSetWinEventHook pSetWinEventHook;
|
||||||
|
|
||||||
@ -53,6 +56,7 @@ void uv__winapi_init(void) {
|
|||||||
HMODULE powrprof_module;
|
HMODULE powrprof_module;
|
||||||
HMODULE user32_module;
|
HMODULE user32_module;
|
||||||
HMODULE ws2_32_module;
|
HMODULE ws2_32_module;
|
||||||
|
HMODULE bcryptprimitives_module;
|
||||||
HMODULE api_win_core_file_module;
|
HMODULE api_win_core_file_module;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
@ -67,6 +71,7 @@ void uv__winapi_init(void) {
|
|||||||
sNtQuerySystemInformation pNtQuerySystemInformation;
|
sNtQuerySystemInformation pNtQuerySystemInformation;
|
||||||
sNtQueryInformationProcess pNtQueryInformationProcess;
|
sNtQueryInformationProcess pNtQueryInformationProcess;
|
||||||
sPowerRegisterSuspendResumeNotification pPowerRegisterSuspendResumeNotification;
|
sPowerRegisterSuspendResumeNotification pPowerRegisterSuspendResumeNotification;
|
||||||
|
sProcessPrng pProcessPrng;
|
||||||
sSetWinEventHook pSetWinEventHook;
|
sSetWinEventHook pSetWinEventHook;
|
||||||
uv_sGetHostNameW pGetHostNameW;
|
uv_sGetHostNameW pGetHostNameW;
|
||||||
sGetFileInformationByName pGetFileInformationByName;
|
sGetFileInformationByName pGetFileInformationByName;
|
||||||
@ -138,6 +143,14 @@ void uv__winapi_init(void) {
|
|||||||
u.pPowerRegisterSuspendResumeNotification;
|
u.pPowerRegisterSuspendResumeNotification;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bcryptprimitives_module = LoadLibraryExA("bcryptprimitives.dll",
|
||||||
|
NULL,
|
||||||
|
LOAD_LIBRARY_SEARCH_SYSTEM32);
|
||||||
|
if (bcryptprimitives_module != NULL) {
|
||||||
|
u.proc = GetProcAddress(bcryptprimitives_module, "ProcessPrng");
|
||||||
|
pProcessPrng = u.pProcessPrng;
|
||||||
|
}
|
||||||
|
|
||||||
user32_module = GetModuleHandleW(L"user32.dll");
|
user32_module = GetModuleHandleW(L"user32.dll");
|
||||||
if (user32_module != NULL) {
|
if (user32_module != NULL) {
|
||||||
u.proc = GetProcAddress(user32_module, "SetWinEventHook");
|
u.proc = GetProcAddress(user32_module, "SetWinEventHook");
|
||||||
|
|||||||
@ -4751,6 +4751,8 @@ typedef DWORD (WINAPI *sPowerRegisterSuspendResumeNotification)
|
|||||||
HANDLE Recipient,
|
HANDLE Recipient,
|
||||||
_PHPOWERNOTIFY RegistrationHandle);
|
_PHPOWERNOTIFY RegistrationHandle);
|
||||||
|
|
||||||
|
typedef BOOL (WINAPI *sProcessPrng)(/*_Out_*/PBYTE pbData, SIZE_T cbData);
|
||||||
|
|
||||||
/* from Winuser.h */
|
/* from Winuser.h */
|
||||||
typedef VOID (CALLBACK* WINEVENTPROC)
|
typedef VOID (CALLBACK* WINEVENTPROC)
|
||||||
(HWINEVENTHOOK hWinEventHook,
|
(HWINEVENTHOOK hWinEventHook,
|
||||||
@ -4815,6 +4817,9 @@ extern sNtQueryInformationProcess pNtQueryInformationProcess;
|
|||||||
/* Powrprof.dll function pointer */
|
/* Powrprof.dll function pointer */
|
||||||
extern sPowerRegisterSuspendResumeNotification pPowerRegisterSuspendResumeNotification;
|
extern sPowerRegisterSuspendResumeNotification pPowerRegisterSuspendResumeNotification;
|
||||||
|
|
||||||
|
/* bcryptprimitives.dll function pointer */
|
||||||
|
extern sProcessPrng pProcessPrng;
|
||||||
|
|
||||||
/* User32.dll function pointer */
|
/* User32.dll function pointer */
|
||||||
extern sSetWinEventHook pSetWinEventHook;
|
extern sSetWinEventHook pSetWinEventHook;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user