win: lazy-load [GS]etThreadDescription symbols
As said symbols are unavailable on Windows Server 2016. Fixes: https://github.com/libuv/libuv/issues/4677
This commit is contained in:
parent
0f31978c30
commit
8d32a0e494
@ -146,6 +146,8 @@ Threads
|
||||
a thread name can be: Linux, IBM i (16), macOS (64), Windows (32767), and NetBSD (32), etc. `uv_thread_setname()`
|
||||
will truncate it in case `name` is larger than the limit of the platform.
|
||||
|
||||
Not supported on Windows Server 2016, returns `UV_ENOSYS`.
|
||||
|
||||
.. versionadded:: 1.50.0
|
||||
|
||||
.. c:function:: int uv_thread_getname(uv_thread_t* tid, char* name, size_t* size)
|
||||
@ -155,6 +157,8 @@ Threads
|
||||
The buffer should be large enough to hold the name of the thread plus the trailing NUL, or it will be truncated to fit
|
||||
with the trailing NUL.
|
||||
|
||||
Not supported on Windows Server 2016, returns `UV_ENOSYS`.
|
||||
|
||||
.. versionadded:: 1.50.0
|
||||
|
||||
.. c:function:: int uv_thread_setpriority(uv_thread_t tid, int priority)
|
||||
|
||||
@ -284,6 +284,9 @@ int uv_thread_setname(const char* name) {
|
||||
int err;
|
||||
char namebuf[UV_PTHREAD_MAX_NAMELEN_NP];
|
||||
|
||||
if (pSetThreadDescription == NULL)
|
||||
return UV_ENOSYS;
|
||||
|
||||
if (name == NULL)
|
||||
return UV_EINVAL;
|
||||
|
||||
@ -295,7 +298,7 @@ int uv_thread_setname(const char* name) {
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
hr = SetThreadDescription(GetCurrentThread(), namew);
|
||||
hr = pSetThreadDescription(GetCurrentThread(), namew);
|
||||
uv__free(namew);
|
||||
if (FAILED(hr))
|
||||
return uv_translate_sys_error(HRESULT_CODE(hr));
|
||||
@ -312,6 +315,9 @@ int uv_thread_getname(uv_thread_t* tid, char* name, size_t size) {
|
||||
int r;
|
||||
DWORD exit_code;
|
||||
|
||||
if (pGetThreadDescription == NULL)
|
||||
return UV_ENOSYS;
|
||||
|
||||
if (name == NULL || size == 0)
|
||||
return UV_EINVAL;
|
||||
|
||||
@ -324,7 +330,7 @@ int uv_thread_getname(uv_thread_t* tid, char* name, size_t size) {
|
||||
|
||||
namew = NULL;
|
||||
thread_name = NULL;
|
||||
hr = GetThreadDescription(*tid, &namew);
|
||||
hr = pGetThreadDescription(*tid, &namew);
|
||||
if (FAILED(hr))
|
||||
return uv_translate_sys_error(HRESULT_CODE(hr));
|
||||
|
||||
|
||||
@ -35,6 +35,8 @@ sNtQueryVolumeInformationFile pNtQueryVolumeInformationFile;
|
||||
sNtQueryDirectoryFile pNtQueryDirectoryFile;
|
||||
sNtQuerySystemInformation pNtQuerySystemInformation;
|
||||
sNtQueryInformationProcess pNtQueryInformationProcess;
|
||||
sGetThreadDescription pGetThreadDescription;
|
||||
sSetThreadDescription pSetThreadDescription;
|
||||
|
||||
/* Powrprof.dll function pointer */
|
||||
sPowerRegisterSuspendResumeNotification pPowerRegisterSuspendResumeNotification;
|
||||
@ -51,6 +53,7 @@ sGetFileInformationByName pGetFileInformationByName;
|
||||
void uv__winapi_init(void) {
|
||||
HMODULE ntdll_module;
|
||||
HMODULE powrprof_module;
|
||||
HMODULE kernel32_module;
|
||||
HMODULE user32_module;
|
||||
HMODULE ws2_32_module;
|
||||
HMODULE api_win_core_file_module;
|
||||
@ -123,6 +126,14 @@ void uv__winapi_init(void) {
|
||||
GetProcAddress(powrprof_module, "PowerRegisterSuspendResumeNotification");
|
||||
}
|
||||
|
||||
kernel32_module = GetModuleHandleA("kernel32.dll");
|
||||
if (kernel32_module != NULL) {
|
||||
pGetThreadDescription = (sGetThreadDescription)
|
||||
GetProcAddress(kernel32_module, "GetThreadDescription");
|
||||
pSetThreadDescription = (sSetThreadDescription)
|
||||
GetProcAddress(kernel32_module, "SetThreadDescription");
|
||||
}
|
||||
|
||||
user32_module = GetModuleHandleA("user32.dll");
|
||||
if (user32_module != NULL) {
|
||||
pSetWinEventHook = (sSetWinEventHook)
|
||||
|
||||
@ -4829,12 +4829,12 @@ typedef int (WINAPI *uv_sGetHostNameW)
|
||||
extern uv_sGetHostNameW pGetHostNameW;
|
||||
|
||||
/* processthreadsapi.h */
|
||||
#if defined(__MINGW32__)
|
||||
WINBASEAPI
|
||||
HRESULT WINAPI GetThreadDescription(HANDLE hThread,
|
||||
PWSTR *ppszThreadDescription);
|
||||
WINBASEAPI
|
||||
HRESULT WINAPI SetThreadDescription(HANDLE hThread, PCWSTR lpThreadDescription);
|
||||
#endif
|
||||
typedef HRESULT (WINAPI *sGetThreadDescription)(HANDLE hThread,
|
||||
PWSTR *ppszThreadDescription);
|
||||
typedef HRESULT (WINAPI *sSetThreadDescription)(HANDLE hThread,
|
||||
PCWSTR lpThreadDescription);
|
||||
|
||||
extern sGetThreadDescription pGetThreadDescription;
|
||||
extern sSetThreadDescription pSetThreadDescription;
|
||||
|
||||
#endif /* UV_WIN_WINAPI_H_ */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user