From 799c17192523c0377edd00dcaa86e199e384a102 Mon Sep 17 00:00:00 2001 From: AZero13 Date: Wed, 10 Dec 2025 11:52:17 -0500 Subject: [PATCH 1/3] Stack size returns an incorrect value Yield the total return of the stack, not the bottom limit. --- Sources/Foundation/Thread.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sources/Foundation/Thread.swift b/Sources/Foundation/Thread.swift index ac1aa0eed4..e7f95ed3e4 100644 --- a/Sources/Foundation/Thread.swift +++ b/Sources/Foundation/Thread.swift @@ -323,10 +323,16 @@ open class Thread : NSObject { #if os(Windows) open var stackSize: Int { get { + // If we set a stack size for this thread. + // Otherwise, query the actual limits. + if _attr.dwThreadStackReservation != 0 { + return Int(_attr.dwThreadStackReservation) + } var ulLowLimit: ULONG_PTR = 0 var ulHighLimit: ULONG_PTR = 0 GetCurrentThreadStackLimits(&ulLowLimit, &ulHighLimit) - return Int(ulLowLimit) + // Return the reserved stack span. + return Int(ulHighLimit &- ulLowLimit) } set { _attr.dwThreadStackReservation = DWORD(newValue) From f9105895d9317e8ef0f0e16276ff97cdde9c9b5c Mon Sep 17 00:00:00 2001 From: AZero13 Date: Wed, 10 Dec 2025 12:01:46 -0500 Subject: [PATCH 2/3] Update Sources/Foundation/Thread.swift Co-authored-by: Saleem Abdulrasool --- Sources/Foundation/Thread.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Foundation/Thread.swift b/Sources/Foundation/Thread.swift index e7f95ed3e4..8ca2802d3f 100644 --- a/Sources/Foundation/Thread.swift +++ b/Sources/Foundation/Thread.swift @@ -325,7 +325,7 @@ open class Thread : NSObject { get { // If we set a stack size for this thread. // Otherwise, query the actual limits. - if _attr.dwThreadStackReservation != 0 { + guard _attr.dwThreadStackReservation == 0 else { return Int(_attr.dwThreadStackReservation) } var ulLowLimit: ULONG_PTR = 0 From 75e4a521d6f8d01805ce5042500f37e66243a776 Mon Sep 17 00:00:00 2001 From: AZero13 Date: Wed, 10 Dec 2025 12:03:08 -0500 Subject: [PATCH 3/3] Update Thread.swift --- Sources/Foundation/Thread.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Foundation/Thread.swift b/Sources/Foundation/Thread.swift index 8ca2802d3f..bb6e166184 100644 --- a/Sources/Foundation/Thread.swift +++ b/Sources/Foundation/Thread.swift @@ -332,7 +332,7 @@ open class Thread : NSObject { var ulHighLimit: ULONG_PTR = 0 GetCurrentThreadStackLimits(&ulLowLimit, &ulHighLimit) // Return the reserved stack span. - return Int(ulHighLimit &- ulLowLimit) + return Int(ulHighLimit - ulLowLimit) } set { _attr.dwThreadStackReservation = DWORD(newValue)