MCPcopy Create free account
hub / github.com/LibertyOS-Development/kernel / alloc

Method alloc

src/allocator/bump.rs:47–70  ·  view source on GitHub ↗
(&self, layout: Layout)

Source from the content-addressed store, hash-verified

45unsafe impl GlobalAlloc for Locked<BumpAlloc>
46{
47 unsafe fn alloc(&self, layout: Layout) -> *mut u8
48 {
49 // Get a mutable reference.
50 let mut bump = self.lock();
51
52 let alloc_init = alignup(bump.next, layout.align());
53 let alloc_end = match alloc_init.checked_add(layout.size())
54 {
55 Some(end) => end,
56 None => return ptr::null_mut(),
57 };
58
59 if alloc_end > bump.endheap
60 {
61 // No memory remaining.
62 ptr::null_mut()
63 }
64 else
65 {
66 bump.next = alloc_end;
67 bump.allocations += 1;
68 alloc_init as *mut u8
69 }
70 }
71
72 unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout)
73 {

Callers

nothing calls this directly

Calls 3

lockMethod · 0.80
alignupFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected