From 1b0c9d0e3d6dc3630072dc16c143e0d79886b7a0 Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Wed, 12 Oct 2022 16:19:55 -0400 Subject: [PATCH] YJIT: No need to fill to get UDF on ARM64 On ARM64, all zeros is already undefined, so we don't need to do extra work to fill new memory with undefined instructions. --- yjit/src/virtualmem.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/yjit/src/virtualmem.rs b/yjit/src/virtualmem.rs index 8d34e521b9..4d7c061ec7 100644 --- a/yjit/src/virtualmem.rs +++ b/yjit/src/virtualmem.rs @@ -141,10 +141,16 @@ impl VirtualMemory { if !alloc.mark_writable(mapped_region_end.cast(), alloc_size_u32) { return Err(FailedPageMapping); } - // Fill new memory with PUSH DS (0x1E) so that executing uninitialized memory - // will fault with #UD in 64-bit mode. On Linux it becomes SIGILL and use the - // usual Ruby crash reporter. - std::slice::from_raw_parts_mut(mapped_region_end, alloc_size).fill(0x1E); + if cfg!(target_arch = "x86_64") { + // Fill new memory with PUSH DS (0x1E) so that executing uninitialized memory + // will fault with #UD in 64-bit mode. On Linux it becomes SIGILL and use the + // usual Ruby crash reporter. + std::slice::from_raw_parts_mut(mapped_region_end, alloc_size).fill(0x1E); + } else if cfg!(target_arch = "aarch64") { + // In aarch64, all zeros encodes UDF, so it's already what we want. + } else { + unreachable!("unknown arch"); + } } self.mapped_region_bytes = self.mapped_region_bytes + alloc_size; @@ -309,6 +315,7 @@ pub mod tests { } #[test] + #[cfg(target_arch = "x86_64")] fn new_memory_is_initialized() { let mut virt = new_dummy_virt_mem();