diff options
| author | Kunshan Wang <wks1986@gmail.com> | 2025-07-19 16:22:46 +0800 |
|---|---|---|
| committer | Alan Wu <XrXr@users.noreply.github.com> | 2025-07-24 11:37:44 -0400 |
| commit | 5ef20b3a274e855b802edd03cd432464d2a49b35 (patch) | |
| tree | 40e0736b3f73e59b51aa2c523774699465398fb9 | |
| parent | fd492a45eb747f49d1f35c09332b654ada0280dc (diff) | |
YJIT: Use raw memory write to update pointers in code
Because we have set all code memory to writable before the reference
updating phase, we can use raw memory writes directly.
| -rw-r--r-- | yjit/src/core.rs | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/yjit/src/core.rs b/yjit/src/core.rs index 57756e86ce..d42726bcc7 100644 --- a/yjit/src/core.rs +++ b/yjit/src/core.rs @@ -2091,11 +2091,9 @@ pub extern "C" fn rb_yjit_iseq_update_references(iseq: IseqPtr) { // Only write when the VALUE moves, to be copy-on-write friendly. if new_addr != object { - for (byte_idx, &byte) in new_addr.as_u64().to_le_bytes().iter().enumerate() { - let byte_code_ptr = value_code_ptr.add_bytes(byte_idx); - cb.write_mem(byte_code_ptr, byte) - .expect("patching existing code should be within bounds"); - } + // SAFETY: Since we already set code memory writable before the compacting phase, + // we can use raw memory accesses directly. + unsafe { value_ptr.write_unaligned(new_addr); } } } } |
