summaryrefslogtreecommitdiff
path: root/zjit.c
diff options
context:
space:
mode:
authorTakashi Kokubun <[email protected]>2025-02-06 15:21:08 -0500
committerTakashi Kokubun <[email protected]>2025-04-18 21:52:56 +0900
commit6a0748d2c5b434615327eed0e3934a77b41c7903 (patch)
tree63013ee324e0c37f9e5995d7c7a589552b42ed94 /zjit.c
parent82e4c07343de7cd6f235b646c7aee17142c76aa3 (diff)
Port align_ptr for x86
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/13131
Diffstat (limited to 'zjit.c')
-rw-r--r--zjit.c19
1 files changed, 19 insertions, 0 deletions
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 *