MCPcopy Create free account
hub / github.com/RustCrypto/RSA / alloc

Method alloc

checkct/driver/src/allocator.rs:23–43  ·  view source on GitHub ↗
(&self, layout: Layout)

Source from the content-addressed store, hash-verified

21// and remain valid until reset, which is called before any allocation.
22unsafe impl GlobalAlloc for Allocator {
23 unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
24 if layout.align() > align_of::<Heap>() {
25 return null_mut();
26 }
27
28 // SAFETY: Only the current single-threaded analysis accesses NEXT.
29 let start = unsafe { (NEXT + layout.align() - 1) & !(layout.align() - 1) };
30 let Some(end) = start.checked_add(layout.size()) else {
31 return null_mut();
32 };
33 if end > HEAP_SIZE {
34 return null_mut();
35 }
36
37 // SAFETY: The allocation is aligned and within HEAP; advancing NEXT
38 // prevents overlap with earlier allocations.
39 unsafe {
40 NEXT = end;
41 addr_of_mut!(HEAP.0).cast::<u8>().add(start)
42 }
43 }
44
45 unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {}
46}

Callers

nothing calls this directly

Calls 1

sizeMethod · 0.80

Tested by

no test coverage detected