Skip to content

Commit 7c95623

Browse files
committed
Fix stack overflow in NVIDIA driver thread
This thread (named "nvwgf2umx!NVDEV_Thunk") has a stack size of 61440. Our `entrypoint` function in `src/entrypoint.zig` allocates more than this on the stack. This becomes a problem when it is inlined into `DllMain`. Even though the `DllMain` function will return before calling the `entrypoint` function when called with `fdwReason != .PROCESS_ATTACH`, when inlining `entrypoint`, the compiler includes entrypoint's stack usage in the stack checks inserted at the beginning of the `DllMain` function. The result is that in optimized builds, or at least those with stack checks (`ReleaseSafe` only?), the NVIDIA driver thread with a tiny stack will call our `DllMain` function and immediately abort due to stack overflow. The fix is simple: do not ever inline the `entrypoint` function into the `DllMain` function.
1 parent 4d65309 commit 7c95623

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/entrypoint.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub const windows = struct {
8585
return std.os.windows.TRUE;
8686
}
8787

88-
entrypoint(@ptrCast(hInstDll));
88+
@call(.never_inline, entrypoint, .{@as(std.os.windows.HMODULE, (@ptrCast(hInstDll)))});
8989

9090
return std.os.windows.TRUE;
9191
}

0 commit comments

Comments
 (0)