diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/random.c | 2 | ||||
-rw-r--r-- | src/win/fs.c | 2 | ||||
-rw-r--r-- | src/win/internal.h | 2 | ||||
-rw-r--r-- | src/win/udp.c | 7 | ||||
-rw-r--r-- | src/win/util.c | 12 | ||||
-rw-r--r-- | src/win/winapi.c | 13 | ||||
-rw-r--r-- | src/win/winapi.h | 5 |
7 files changed, 35 insertions, 8 deletions
diff --git a/src/random.c b/src/random.c index 57fc0d91..402678cb 100644 --- a/src/random.c +++ b/src/random.c @@ -61,7 +61,7 @@ static int uv__random(void* buf, size_t buflen) { # endif #elif defined(_WIN32) uv__once_init(); - rc = uv__random_rtlgenrandom(buf, buflen); + rc = uv__random_winrandom(buf, buflen); #else rc = uv__random_devurandom(buf, buflen); #endif diff --git a/src/win/fs.c b/src/win/fs.c index 4e156930..acaa5689 100644 --- a/src/win/fs.c +++ b/src/win/fs.c @@ -1269,7 +1269,7 @@ void fs__mktemp(uv_fs_t* req, uv__fs_mktemp_func func) { tries = TMP_MAX; 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); goto clobber; } diff --git a/src/win/internal.h b/src/win/internal.h index be408af6..db488be7 100644 --- a/src/win/internal.h +++ b/src/win/internal.h @@ -269,7 +269,7 @@ int uv__getsockpeername(const uv_handle_t* handle, int* namelen, int delayed_error); -int uv__random_rtlgenrandom(void* buf, size_t buflen); +int uv__random_winrandom(void* buf, size_t buflen); /* diff --git a/src/win/udp.c b/src/win/udp.c index e0873c2a..f8aa2435 100644 --- a/src/win/udp.c +++ b/src/win/udp.c @@ -1149,10 +1149,13 @@ int uv__udp_try_send2(uv_udp_t* handle, uv_buf_t* bufs[/*count*/], unsigned int nbufs[/*count*/], struct sockaddr* addrs[/*count*/]) { - unsigned int i; + int i; int r; - for (i = 0; i < count; i++) { + if (count > INT_MAX) + return UV_EINVAL; + + for (i = 0; i < (int) count; i++) { r = uv_udp_try_send(handle, bufs[i], nbufs[i], addrs[i]); if (r < 0) return i > 0 ? i : r; /* Error if first packet, else send count. */ diff --git a/src/win/util.c b/src/win/util.c index 8c2681fe..9e3daac8 100644 --- a/src/win/util.c +++ b/src/win/util.c @@ -513,8 +513,8 @@ int uv_uptime(double* uptime) { unsigned int uv_available_parallelism(void) { DWORD_PTR procmask; DWORD_PTR sysmask; - int count; - int i; + unsigned count; + unsigned i; /* TODO(bnoordhuis) Use GetLogicalProcessorInformationEx() to support systems * with > 64 CPUs? See https://github.com/libuv/libuv/pull/3458 @@ -1712,6 +1712,9 @@ int uv_os_uname(uv_utsname_t* buffer) { case PROCESSOR_ARCHITECTURE_ARM: uv__strscpy(buffer->machine, "arm", sizeof(buffer->machine)); break; + case PROCESSOR_ARCHITECTURE_ARM64: + uv__strscpy(buffer->machine, "arm64", sizeof(buffer->machine)); + break; default: uv__strscpy(buffer->machine, "unknown", sizeof(buffer->machine)); break; @@ -1744,10 +1747,13 @@ int uv_gettimeofday(uv_timeval64_t* tv) { return 0; } -int uv__random_rtlgenrandom(void* buf, size_t buflen) { +int uv__random_winrandom(void* buf, size_t buflen) { if (buflen == 0) return 0; + if (pProcessPrng != NULL && pProcessPrng(buf, buflen)) + return 0; + if (SystemFunction036(buf, buflen) == FALSE) return UV_EIO; diff --git a/src/win/winapi.c b/src/win/winapi.c index 758164f6..7ed08dd2 100644 --- a/src/win/winapi.c +++ b/src/win/winapi.c @@ -39,6 +39,9 @@ sNtQueryInformationProcess pNtQueryInformationProcess; /* Powrprof.dll function pointer */ sPowerRegisterSuspendResumeNotification pPowerRegisterSuspendResumeNotification; +/* bcryptprimitives.dll function pointer */ +sProcessPrng pProcessPrng; + /* User32.dll function pointer */ sSetWinEventHook pSetWinEventHook; @@ -53,6 +56,7 @@ void uv__winapi_init(void) { HMODULE powrprof_module; HMODULE user32_module; HMODULE ws2_32_module; + HMODULE bcryptprimitives_module; HMODULE api_win_core_file_module; union { @@ -67,6 +71,7 @@ void uv__winapi_init(void) { sNtQuerySystemInformation pNtQuerySystemInformation; sNtQueryInformationProcess pNtQueryInformationProcess; sPowerRegisterSuspendResumeNotification pPowerRegisterSuspendResumeNotification; + sProcessPrng pProcessPrng; sSetWinEventHook pSetWinEventHook; uv_sGetHostNameW pGetHostNameW; sGetFileInformationByName pGetFileInformationByName; @@ -138,6 +143,14 @@ void uv__winapi_init(void) { 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"); if (user32_module != NULL) { u.proc = GetProcAddress(user32_module, "SetWinEventHook"); diff --git a/src/win/winapi.h b/src/win/winapi.h index b9c9f1ab..a7e1b179 100644 --- a/src/win/winapi.h +++ b/src/win/winapi.h @@ -4751,6 +4751,8 @@ typedef DWORD (WINAPI *sPowerRegisterSuspendResumeNotification) HANDLE Recipient, _PHPOWERNOTIFY RegistrationHandle); +typedef BOOL (WINAPI *sProcessPrng)(/*_Out_*/PBYTE pbData, SIZE_T cbData); + /* from Winuser.h */ typedef VOID (CALLBACK* WINEVENTPROC) (HWINEVENTHOOK hWinEventHook, @@ -4815,6 +4817,9 @@ extern sNtQueryInformationProcess pNtQueryInformationProcess; /* Powrprof.dll function pointer */ extern sPowerRegisterSuspendResumeNotification pPowerRegisterSuspendResumeNotification; +/* bcryptprimitives.dll function pointer */ +extern sProcessPrng pProcessPrng; + /* User32.dll function pointer */ extern sSetWinEventHook pSetWinEventHook; |