From f63205a695131db5df00c6f14f6be80b5e72cfe8 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Mon, 19 Feb 2024 21:34:10 +0100 Subject: [PATCH] Add alignment --- rustler/src/alloc.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rustler/src/alloc.rs b/rustler/src/alloc.rs index 92099a92..d58d3b7a 100644 --- a/rustler/src/alloc.rs +++ b/rustler/src/alloc.rs @@ -10,7 +10,10 @@ pub struct EnifAllocator; unsafe impl GlobalAlloc for EnifAllocator { unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - // TODO: Check the requested alignment. + // TODO: Check enif_alloc's real alignment + if layout.align() > (((((layout.size()) - 1) / 8) + 1) * 8) { + return std::ptr::null_mut(); + } rustler_sys::enif_alloc(layout.size()) as *mut u8 }