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

Method alloc

src/allocator/lnls.rs:143–163  ·  view source on GitHub ↗
(&self, layout: Layout)

Source from the content-addressed store, hash-verified

141unsafe impl GlobalAlloc for Locked<LnLsAlloc>
142{
143 unsafe fn alloc(&self, layout: Layout) -> *mut u8
144 {
145 // Make adjustment(s) to layout:
146 let (size, align) = LnLsAlloc::sizealign(layout);
147 let mut allocator = self.lock();
148
149 if let Some((region, alloc_start)) = allocator.findrgn(size, align)
150 {
151 let alloc_end = alloc_start.checked_add(size).expect("[ERR] OVERFLOW");
152 let excess_size = region.addr_end() - alloc_end;
153 if excess_size > 0
154 {
155 allocator.add_freergn(alloc_end, excess_size);
156 }
157 alloc_start as *mut u8
158 }
159 else
160 {
161 ptr::null_mut()
162 }
163 }
164
165 unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout)
166 {

Callers

nothing calls this directly

Calls 4

lockMethod · 0.80
findrgnMethod · 0.80
addr_endMethod · 0.80
add_freergnMethod · 0.80

Tested by

no test coverage detected