os::paging::page_allocator_t::block os::paging::page_allocator_t::allocate(std::uint64_t count) {
for (auto it = begin(); it != end(); it = it->next) {
- if (count == it->size) {
- erase(it);
- memset((void*)it, 0, count * 0x1000);
- return {
- .ptr = phys_ptr<paging::page>(it.get_phys_addr()),
- .size = count,
- };
- } else if (count < it->size) {
- erase(split_at_offset(it, count));
- memset((void*)it, 0, count * 0x1000);
- return {
- .ptr = phys_ptr<paging::page>(it.get_phys_addr()),
- .size = count,
- };
+ if (it->size < count) {
+ continue;
+ }
+ if (count < it->size) {
+ split_at_offset(it, count);
}
+ erase(it);
+ memset((void*)it, 0, count * 0x1000);
+ return {
+ .ptr = phys_ptr<paging::page>(it.get_phys_addr()),
+ .size = count,
+ };
}
return { .ptr = nullptr, .size = count };
}