Attempt to allocate using a specific region, with a specifc size and alignment:
(region: &ListNode, size: usize, align: usize)
| 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). |
nothing calls this directly
no test coverage detected