hermit::syscalls

Function sys_realloc

Source
#[no_mangle]
pub unsafe extern "C" fn sys_realloc(
    ptr: *mut u8,
    size: usize,
    align: usize,
    new_size: usize,
) -> *mut u8
Expand description

Shrink or grow a block of memory to the given new_size. The block is described by the given ptr pointer and layout. If this returns a non-null pointer, then ownership of the memory block referenced by ptr has been transferred to this allocator. The memory may or may not have been deallocated, and should be considered unusable (unless of course it was transferred back to the caller again via the return value of this method). The new memory block is allocated with layout, but with the size updated to new_size. If this method returns null, then ownership of the memory block has not been transferred to this allocator, and the contents of the memory block are unaltered.

§Safety

This function is unsafe because undefined behavior can result if the caller does not ensure all of the following:

  • ptr must be currently allocated via this allocator,
  • size and align must be the same layout that was used to allocate that block of memory. ToDO: verify if the same values for size and align always lead to the same layout

§Errors

Returns null if the new layout does not meet the size and alignment constraints of the allocator, or if reallocation otherwise fails.