* Reserves a chunk of the virtual address space spanning the range [lb..ub]. * Returns `true` on success, `false` on failure. */
| 596 | * Returns `true` on success, `false` on failure. |
| 597 | */ |
| 598 | bool reserve(Binary *B, intptr_t lb, intptr_t ub) |
| 599 | { |
| 600 | Allocator &allocator = B->allocator; |
| 601 | if (!verify(lb, ub)) |
| 602 | return false; |
| 603 | lb -= (lb % PAGE_SIZE); |
| 604 | ub += (ub % PAGE_SIZE == 0? 0: PAGE_SIZE - ub % PAGE_SIZE); |
| 605 | if (ub - lb <= 0) |
| 606 | return false; |
| 607 | uint32_t flags = 0; |
| 608 | Node *n = insert(allocator.tree.root, lb, ub, (ub - lb), flags); |
| 609 | if (n == nullptr) |
| 610 | return false; |
| 611 | if (allocator.tree.root == nullptr) |
| 612 | allocator.tree.root = n; |
| 613 | rebalanceInsert(&allocator.tree, n); |
| 614 | |
| 615 | Alloc *A = &n->alloc; |
| 616 | A->T = nullptr; |
| 617 | A->I = nullptr; |
| 618 | return true; |
| 619 | } |
| 620 | |
| 621 | /* |
| 622 | * Deallocate an existing allocation. |
no test coverage detected