From 6a0748d2c5b434615327eed0e3934a77b41c7903 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Thu, 6 Feb 2025 15:21:08 -0500 Subject: [PATCH] Port align_ptr for x86 --- zjit.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/zjit.c b/zjit.c index 992d79cd46..925924b328 100644 --- a/zjit.c +++ b/zjit.c @@ -49,6 +49,25 @@ rb_zjit_get_page_size(void) #endif } +#if defined(MAP_FIXED_NOREPLACE) && defined(_SC_PAGESIZE) +// Align the current write position to a multiple of bytes +static uint8_t * +align_ptr(uint8_t *ptr, uint32_t multiple) +{ + // Compute the pointer modulo the given alignment boundary + uint32_t rem = ((uint32_t)(uintptr_t)ptr) % multiple; + + // If the pointer is already aligned, stop + if (rem == 0) + return ptr; + + // Pad the pointer by the necessary amount to align it + uint32_t pad = multiple - rem; + + return ptr + pad; +} +#endif + // Address space reservation. Memory pages are mapped on an as needed basis. // See the Rust mm module for details. uint8_t *