| ... | @@ -10,6 +10,7 @@ | ... | @@ -10,6 +10,7 @@ |
| 10 | | 10 | |
| 11 | const std = @import("std.zig"); | 11 | const std = @import("std.zig"); |
| 12 | const os = std.os; | 12 | const os = std.os; |
| | 13 | const assert = std.debug.assert; |
| 13 | const target = std.Target.current; | 14 | const target = std.Target.current; |
| 14 | const Atomic = std.atomic.Atomic; | 15 | const Atomic = std.atomic.Atomic; |
| 15 | | 16 | |
| ... | @@ -259,11 +260,20 @@ const WindowsThreadImpl = struct { | ... | @@ -259,11 +260,20 @@ const WindowsThreadImpl = struct { |
| 259 | }, | 260 | }, |
| 260 | }; | 261 | }; |
| 261 | | 262 | |
| 262 | const stack_size = std.math.min(64 * 1024, std.math.cast(u32, config.stack_size) catch std.math.maxInt(u32)); | 263 | // Windows appears to only support SYSTEM_INFO.dwAllocationGranularity minimum stack size. |
| 263 | | 264 | // Going lower makes it default to that specified in the executable (~1mb). |
| 264 | const parameter = @ptrCast(*c_void, impl); | 265 | // Its also fine if the limit here is incorrect as stack size is only a hint. |
| | 266 | var stack_size = std.math.cast(u32, config.stack_size) catch std.math.maxInt(u32); |
| | 267 | stack_size = std.math.max(64 * 1024, stack_size); |
| 265 | | 268 | |
| 266 | instance.thread.thread_handle = windows.CreateThread(null, stack_size, Impl.entry, parameter, 0, null) orelse { | 269 | instance.thread.thread_handle = windows.CreateThread( |
| | 270 | null, |
| | 271 | stack_size, |
| | 272 | Instance.entry, |
| | 273 | @ptrCast(*c_void, instance), |
| | 274 | 0, |
| | 275 | null, |
| | 276 | ) orelse { |
| 267 | return windows.unexpectedError(windows.kernel32.GetLastError()); | 277 | return windows.unexpectedError(windows.kernel32.GetLastError()); |
| 268 | }; | 278 | }; |
| 269 | | 279 | |