*/
}
+#if defined (_WIN32)
+
+int __gnat_set_thread_description(HANDLE h, char *descr, int length) {
+
+ /* This function is a no-op if Unicode support is not enabled */
+#ifdef GNAT_UNICODE_SUPPORT
+
+ if (!pSetThreadDescription) {
+ /* This is presumably not an error case, SetThreadDescription is simply
+ not available in the current Windows version. */
+ return 1;
+ }
+
+ TCHAR wdescr[length + 1];
+
+ S2WSC (wdescr, descr, length + 1);
+
+ HRESULT res = pSetThreadDescription(h, wdescr);
+ if (FAILED(res)) {
+ return 0;
+ }
+
+#endif
+
+ return 1;
+}
+
+#endif /* defined (_WIN32) */
+
#ifdef __cplusplus
}
#endif
Get_Stack_Bounds
(Self_ID.Common.Compiler_Data.Pri_Stack_Info.Base'Address,
Self_ID.Common.Compiler_Data.Pri_Stack_Info.Limit'Address);
+
+ if Self_ID.Common.Task_Image_Len > 0 then
+ declare
+ function Set_Thread_Description
+ (H : Thread_Id; Descr : Address; Length : Integer)
+ return Integer;
+ pragma
+ Import
+ (C, Set_Thread_Description, "__gnat_set_thread_description");
+
+ Nul_Terminated_Image : constant String :=
+ Self_ID.Common.Task_Image
+ (Self_ID.Common.Task_Image'First
+ ..
+ Self_ID.Common.Task_Image'First
+ + Self_ID.Common.Task_Image_Len
+ - 1)
+ & ASCII.NUL;
+
+ Result : constant Integer :=
+ Set_Thread_Description
+ (Self_ID.Common.LL.Thread,
+ Nul_Terminated_Image'Address,
+ Self_ID.Common.Task_Image_Len);
+ begin
+ pragma Assert (Result = 1);
+ end;
+ end if;
end Enter_Task;
-------------------
#define WS2S(str,wstr,len) strncpy(str,wstr,len)
#endif
+typedef HRESULT (WINAPI *SetThreadDescription_t)(
+ _In_ HANDLE hThread,
+ _In_ PCWSTR lpThreadDescription
+);
+
+extern SetThreadDescription_t pSetThreadDescription;
+
#endif /* _MINGW32_H */
(gnat_argv, argc_expanded * sizeof (char *));
}
}
+
+ /* We check whether the SetThreadDescription function is available. If so, we
+ set up a pointer to it. We follow the method that's documented on this page:
+
+ https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getprocaddress
+ */
+ HMODULE hKernel32 = GetModuleHandleW(L"kernel32.dll");
+
+ if (hKernel32) {
+ pSetThreadDescription =
+ (SetThreadDescription_t)GetProcAddress(hKernel32, "SetThreadDescription");
+ }
+
#endif
if (install_handler)
__gnat_install_handler();
}
+SetThreadDescription_t pSetThreadDescription;
+
/**************************************************/
/* __gnat_runtime_initialize (init_float version) */
/**************************************************/