diff --git a/src/lib.rs b/src/lib.rs index 6f3e8d5bc6..f71a5f50ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,6 +33,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 @@ -52,6 +54,12 @@ pub extern "C" fn __rust_allocate(size: usize, align: usize) -> *mut u8 { unsafe { ffi::mallocx(size as size_t, flags) as *mut u8 } } +#[no_mangle] +pub extern "C" 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 "C" fn __rust_reallocate(ptr: *mut u8, _old_size: usize,