[PATCH 3/7] msvcrt: Make _beginthread() error out as documented.

Arkadiusz Hiler ahiler at codeweavers.com
Tue May 4 06:49:37 CDT 2021


The functions uses EACCESS for insufficient resources, so we cannot
leave errno set by malloc().

msvcrt_set_errno() seems to be doing the right thing in case of too many
threads, invalid parameters, etc.

Signed-off-by: Arkadiusz Hiler <ahiler at codeweavers.com>
---
 dlls/msvcrt/thread.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/dlls/msvcrt/thread.c b/dlls/msvcrt/thread.c
index c2fc863dd33..3ab53166192 100644
--- a/dlls/msvcrt/thread.c
+++ b/dlls/msvcrt/thread.c
@@ -118,9 +118,14 @@ uintptr_t CDECL _beginthread(
 
   TRACE("(%p, %d, %p)\n", start_address, stack_size, arglist);
 
+  if(!start_address) {
+      *_errno() = EINVAL;
+      return -1;
+  }
+
   trampoline = malloc(sizeof(*trampoline));
   if(!trampoline) {
-      *_errno() = EAGAIN;
+      *_errno() = EACCES;
       return -1;
   }
 
@@ -128,7 +133,7 @@ uintptr_t CDECL _beginthread(
           trampoline, CREATE_SUSPENDED, NULL);
   if(!thread) {
       free(trampoline);
-      *_errno() = EAGAIN;
+      msvcrt_set_errno(GetLastError());
       return -1;
   }
 
-- 
2.31.1




More information about the wine-devel mailing list