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

Method alloc_fromrgn

src/allocator/lnls.rs:104–125  ·  view source on GitHub ↗

Attempt to allocate using a specific region, with a specifc size and alignment:

(region: &ListNode, size: usize, align: usize)

Source from the content-addressed store, hash-verified

102
103 // Attempt to allocate using a specific region, with a specifc size and alignment:
104 fn alloc_fromrgn(region: &ListNode, size: usize, align: usize) -> Result<usize, ()>
105 {
106 let alloc_start = alignup(region.addr_start(), align);
107 let alloc_end = alloc_start.checked_add(size).ok_or(())?;
108
109 if alloc_end > region.addr_end()
110 {
111 // If memory region is too small:
112 return Err(());
113 }
114
115 let excess_size = region.addr_end() - alloc_end;
116
117 if excess_size > 0 && excess_size < mem::size_of::<ListNode>()
118 {
119 // If the remaining region is insufficient in size to hold a ListNode:
120 return Err(());
121 }
122
123 // If memory region is viable for allocation:
124 Ok(alloc_start)
125 }
126
127 // Modify specified layout so that the allocated memory region can also hold a ListNode:
128 // NOTE: This will return a tuple, consisting of the adjusted size, and the alignment (size, align).

Callers

nothing calls this directly

Calls 4

addr_startMethod · 0.80
addr_endMethod · 0.80
alignupFunction · 0.70
ErrEnum · 0.50

Tested by

no test coverage detected