[KERNEL32] Add an (incomplete) pre-implementation for SetThreadStackGuarantee().... 803/head
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Thu, 23 Aug 2018 19:30:56 +0000 (21:30 +0200)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 27 Apr 2019 16:41:50 +0000 (18:41 +0200)
This should remove some of the "SetThreadStackGuarantee(): stub" messages in some simple cases.

dll/win32/kernel32/client/thread.c

index 2ff0102..1a593ba 100644 (file)
@@ -5,7 +5,6 @@
  * PURPOSE:         Thread functions
  * PROGRAMMERS:     Alex Ionescu (alex.ionescu@reactos.org)
  *                  Ariadne (ariadne@xs4all.nl)
- *
  */
 
 /* INCLUDES *******************************************************************/
@@ -950,16 +949,44 @@ QueueUserAPC(IN PAPCFUNC pfnAPC,
 }
 
 /*
- * @implemented
+ * @unimplemented
  */
 BOOL
 WINAPI
 SetThreadStackGuarantee(IN OUT PULONG StackSizeInBytes)
 {
-    static int once;
-    if (once++ == 0)
-         DPRINT1("SetThreadStackGuarantee(%p): stub\n", StackSizeInBytes);
-    return TRUE;
+    PTEB Teb = NtCurrentTeb();
+    ULONG GuaranteedStackBytes;
+    ULONG AllocationSize;
+
+    if (!StackSizeInBytes)
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
+
+    AllocationSize = *StackSizeInBytes;
+
+    /* Retrieve the current stack size */
+    GuaranteedStackBytes = Teb->GuaranteedStackBytes;
+
+    /* Return the size of the previous stack */
+    *StackSizeInBytes = GuaranteedStackBytes;
+
+    /*
+     * If the new stack size is either zero or is less than the current size,
+     * the previous stack size is returned and we return success.
+     */
+    if ((AllocationSize == 0) || (AllocationSize < GuaranteedStackBytes))
+    {
+        return TRUE;
+    }
+
+    // FIXME: Unimplemented!
+    UNIMPLEMENTED_ONCE;
+
+    // return TRUE;
+    return FALSE;
 }
 
 /*