| 75 | // NOTE: This will return a tuple, containing the list-node, and the start address of the allocation. |
| 76 | |
| 77 | fn findrgn(&mut self, size: usize, align: usize) -> Option<(&'static mut ListNode, usize)> |
| 78 | { |
| 79 | // Refers to current list-node: |
| 80 | // NOTE: Each iteration will update the list-node. |
| 81 | let mut current = &mut self.head; |
| 82 | // Locate a memreg with sufficient size from linked-list. |
| 83 | while let Some(ref mut region) = current.next |
| 84 | { |
| 85 | if let Ok(alloc_start) = Self::alloc_fromrgn(®ion, size, align) |
| 86 | { |
| 87 | // If region is appropriate for allocation, the node is removed from the list. |
| 88 | let next = region.next.take(); |
| 89 | let ret = Some((current.next.take().unwrap(), alloc_start)); |
| 90 | current.next = next; |
| 91 | return ret; |
| 92 | } |
| 93 | else |
| 94 | { |
| 95 | // If the region is inappropriate, continue to the next region. |
| 96 | current = current.next.as_mut().unwrap(); |
| 97 | } |
| 98 | } |
| 99 | // If no appropriate region is able to be located: |
| 100 | None |
| 101 | } |
| 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, ()> |