diff --git a/src/lib.rs b/src/lib.rs index dddbffcb9d..a2b1b30b95 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,6 +32,8 @@ const MIN_ALIGN: usize = 8; target_arch = "powerpc64le")))] const MIN_ALIGN: usize = 16; +const MALLOCX_ZERO: c_int = 0x40; + // MALLOCX_ALIGN(a) macro fn mallocx_align(a: usize) -> c_int { a.trailing_zeros() as c_int @@ -51,6 +53,12 @@ pub extern fn __rust_allocate(size: usize, align: usize) -> *mut u8 { unsafe { ffi::mallocx(size as size_t, flags) as *mut u8 } } +#[no_mangle] +pub extern fn __rust_allocate_zeroed(size: usize, align: usize) -> *mut u8 { + let flags = align_to_flags(align) | MALLOCX_ZERO; + unsafe { ffi::mallocx(size as size_t, flags) as *mut u8 } +} + #[no_mangle] pub extern fn __rust_reallocate(ptr: *mut u8, _old_size: usize,