Fix VM_Call crash in DLL mode when nargs is 0#66
Open
742617000027 wants to merge 1 commit intoDefrag-racing:mainfrom
Open
Fix VM_Call crash in DLL mode when nargs is 0#66742617000027 wants to merge 1 commit intoDefrag-racing:mainfrom
742617000027 wants to merge 1 commit intoDefrag-racing:mainfrom
Conversation
On ARM64, the compiler transforms the va_arg copy loop into a do-while (check at bottom) without a zero-trip guard. When nargs is 0, the loop never terminates and reads past the stack into the guard page, causing SIGBUS. This affects any VM_Call with nargs=0 in DLL mode, such as CG_CONSOLE_COMMAND and CG_SHUTDOWN. The VM interpreter path already handles this correctly with a `cmp w1, Defrag-racing#1; b.lt skip` guard. Zero-initialize the args array so the memset gives the compiler a separate initialization path, preventing it from folding the guard into the loop and eliminating it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a crash (SIGBUS) on ARM64 when using native DLL cgame modules (e.g. cgame-proxymod).
On ARM64 with
-O2, the compiler transforms theforloop inVM_Call's DLL path into a do-while loop without a zero-trip guard. Whennargsis 0 (used byCG_CONSOLE_COMMANDandCG_SHUTDOWN), the va_arg copy loop never terminates and reads past the stack into the guard page, causing a SIGBUS crash.The VM interpreter path already handles this correctly — the compiled code includes a
cmp w1, #1; b.lt skipguard before its copy loop.Fix
Zero-initialize the
argsarray withmemset. This gives the compiler a separate initialization path that prevents it from eliminating the loop guard during optimization.Reproduction
vm_cgame 0)Received signal 10(SIGBUS)See also: Jelvan1/cgame-proxymod#14