Repository navigation
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
…ntext Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # src/coreclr/nativeaot/Runtime/unix/NativeContext.cpp
The hand extraction dropped PAL branches (wasm, Apple) and left a function fragment in the shared header. Regenerate it from main's pal/context.h so the preprocessor structure is unchanged, and add the riscv64 MCREG_R0 that NativeAOT uses. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
- Move the signal to exception code translation used by the PAL and NativeAOT to runtime/unix/ExceptionCodeForSignal.h. The PAL keeps its GC marker check for SIGSEGV with SI_KERNEL through a callback. - Move INJECT_ACTIVATION_SIGNAL and the Apple dispatch_allow_send_signals lookup to runtime/unix/ActivationSignal.h. - Add MCREG_InstructionPointer/MCREG_StackPointer for the native context PC/SP accessors. - Move the x64 DIV/IDIV operand decoding used by the VM and NativeAOT to runtime/amd64/DivInstructionDecoder.h. APX prefix decoding stays VM-only since NativeAOT does not read R16..R31 from the signal context. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Note
Copilot was unable to run its full agentic suite in this review.
Copilot review overview
3 open issues
This now depends on DivInstructionHasNonZeroDivisor and stdint types (uint8_t/uint32_t/uint64_t),… · New This introduces (and centralizes) unaligned pointer dereferences by casting uint8_t* to… · New AllowActivationSignalOnDispatchQueueThreads leaks the dlopen() handle on both the success path and… · New
What changed in this PR
This PR factors several Unix/AMD64 low-level runtime helpers into shared headers and replaces duplicated signal/exception decoding logic with reusable implementations across CoreCLR PAL and NativeAOT.
Changes:
- Introduces shared Unix headers for native-context register access, activation signal selection, and signal→Win32 exception code translation.
- Replaces local DIV/IDIV fault decoding with a shared x64 decoder (including APX-related prefix decoding support for CoreCLR).
- Updates PAL/NativeAOT call sites to use the new shared headers and helper APIs.
| File | Description |
|---|---|
| src/coreclr/vm/exceptionhandling.cpp | Switches divide overflow detection to shared DIV/IDIV decoder and adds decoder include (currently Unix-only). |
| src/coreclr/runtime/unix/NativeContextRegs.h | Adds shared macro set for accessing registers from Unix machine contexts. |
| src/coreclr/runtime/unix/ExceptionCodeForSignal.h | Adds shared signal→Win32 exception code translation helper with optional SI_KERNEL callback. |
| src/coreclr/runtime/unix/ActivationSignal.h | Centralizes activation signal choice and macOS dispatch queue signal enabling helper. |
| src/coreclr/runtime/amd64/DivInstructionDecoder.h | Adds shared x64 DIV/IDIV instruction decoder used by CoreCLR and NativeAOT. |
| src/coreclr/pal/src/thread/context.cpp | Replaces in-file signal→exception mapping with shared helper and uses unified PC/SP accessors. |
| src/coreclr/pal/src/include/pal/context.h | Replaces duplicated register-access macros with shared NativeContextRegs.h include. |
| src/coreclr/pal/src/exception/signal.cpp | Replaces INJECT_ACTIVATION_SIGNAL macro + macOS lookup code with ActivationSignal.h helper. |
| src/coreclr/nativeaot/Runtime/unix/UnixSignals.h | Uses ActivationSignal.h for INJECT_ACTIVATION_SIGNAL. |
| src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp | Uses ActivationSignal.h helper for macOS dispatch queue signal enablement. |
| src/coreclr/nativeaot/Runtime/unix/NativeContext.cpp | Replaces large local register macro block with shared NativeContextRegs.h. |
| src/coreclr/nativeaot/Runtime/unix/HardwareExceptions.cpp | Uses shared signal→exception mapping and shared DIV/IDIV decoder. |
Review effort: Lite
Co-authored-by: Cursor <cursoragent@cursor.com>
…divide decoder Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
🟡 Changes recommended
The RISC-V fallback leaves required context accessors undefined when both layout probes are false, breaking compilation of context conversion and redirection.
2 open issues
3 resolved since last review
Review effort: Balanced
Co-authored-by: Cursor <cursoragent@cursor.com>
…ntext # Conflicts: # src/coreclr/pal/src/include/pal/context.h
There was a problem hiding this comment.
🟡 Changes recommended
The shared APX cache has an unsynchronized data race during concurrent NativeAOT divide faults, potentially causing divisor decoding to read the wrong signal-frame location.
1 open issue
2 resolved since last review
Review effort: Balanced
Co-authored-by: Cursor <cursoragent@cursor.com>


The CoreCLR PAL, the VM and NativeAOT each carried their own copies of the same Unix signal-context code. This moves the shared parts under
src/coreclr/runtime:runtime/unix/NativeContextRegs.h: theMCREG_*machine-context register accessors frompal/context.hand NativeAOT'sNativeContext.cpp, plusMCREG_InstructionPointer/MCREG_StackPointerused byGetNativeContextPC/GetNativeContextSPand NativeAOT'sGetPC. Drops the unsupported non-Windows x86 accessors.runtime/unix/NativeContextXstate.h: access to the x64 extended state saved in Linux signal contexts, including the APX R16-R31 registers, moved frompal/context.h. NativeAOT now uses it as well.runtime/unix/ExceptionCodes.handruntime/unix/ExceptionCodeForSignal.h: hardware exception codes and the signal to exception code translation shared by PALCONTEXTGetExceptionCodeForSignaland NativeAOTGetExceptionCodeForSignal.runtime/unix/ActivationSignal.h:INJECT_ACTIVATION_SIGNALand the Appledispatch_allow_send_signalscall.runtime/amd64/DivInstructionDecoder.h: x64DIV/IDIVoperand decoding used to tell divide-by-zero from overflow, shared by the VM and NativeAOT, including APX (REX2/EVEX) encodings.With the shared xstate helpers, NativeAOT on Linux glibc x64 now reads R16-R31 from the signal context when decoding APX encoded divides, same as CoreCLR.