MCPcopy Create free account
hub / github.com/IBM/ACE-RISCV / alloc

Method alloc

security-monitor/src/core/heap_allocator/allocator.rs:135–152  ·  view source on GitHub ↗
(&self, layout: Layout)

Source from the content-addressed store, hash-verified

133
134unsafe impl GlobalAlloc for Locked<LinkedListAllocator> {
135 unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
136 // perform layout adjustments
137 let (size, align) = LinkedListAllocator::size_align(layout);
138 let mut allocator = self.lock();
139
140 if let Some((region, alloc_start)) = allocator.find_region(size, align) {
141 let alloc_end = alloc_start.checked_add(size).expect("overflow");
142 let excess_size = region.end_addr() - alloc_end;
143 if excess_size > 0 {
144 unsafe {
145 allocator.add_free_region(alloc_end, excess_size);
146 }
147 }
148 alloc_start as *mut u8
149 } else {
150 ptr::null_mut()
151 }
152 }
153
154 unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
155 // perform layout adjustments

Callers

nothing calls this directly

Calls 4

lockMethod · 0.80
find_regionMethod · 0.80
end_addrMethod · 0.80
add_free_regionMethod · 0.80

Tested by

no test coverage detected