1 use crate::alloc::{GlobalAlloc, Layout, System};
5 // The minimum alignment guaranteed by the architecture. This value is used to
6 // add fast paths for low alignment values.
11 target_arch = "powerpc",
12 target_arch = "powerpc64",
13 target_arch = "sparc",
14 target_arch = "asmjs",
15 target_arch = "wasm32",
16 target_arch = "hexagon",
17 all(target_arch = "riscv32", not(target_os = "espidf")),
18 all(target_arch = "xtensa", not(target_os = "espidf")),
20 pub const MIN_ALIGN: usize = 8;
22 target_arch = "x86_64",
23 target_arch = "aarch64",
24 target_arch = "mips64",
25 target_arch = "s390x",
26 target_arch = "sparc64",
27 target_arch = "riscv64",
28 target_arch = "wasm64",
30 pub const MIN_ALIGN: usize = 16;
31 // The allocator on the esp-idf platform guarantees 4 byte alignment.
33 all(target_arch = "riscv32", target_os = "espidf"),
34 all(target_arch = "xtensa", target_os = "espidf"),
36 pub const MIN_ALIGN: usize = 4;
38 pub unsafe fn realloc_fallback(
44 // Docs for GlobalAlloc::realloc require this to be valid:
45 let new_layout = Layout::from_size_align_unchecked(new_size, old_layout.align());
47 let new_ptr = GlobalAlloc::alloc(alloc, new_layout);
48 if !new_ptr.is_null() {
49 let size = cmp::min(old_layout.size(), new_size);
50 ptr::copy_nonoverlapping(ptr, new_ptr, size);
51 GlobalAlloc::dealloc(alloc, ptr, old_layout);