Added is_address_range_covered(), returning whether the given address range

is fully covered by the ranges in the array.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36631 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2010-05-05 21:09:11 +00:00
parent 9e24c4190f
commit 863c623f9a
2 changed files with 36 additions and 2 deletions

View File

@ -25,6 +25,8 @@ status_t remove_address_range(addr_range *ranges, uint32 *_numRanges,
uint32 maxRanges, addr_t start, uint32 size);
bool get_free_address_range(addr_range *ranges, uint32 numRanges, addr_t base,
size_t size, addr_t *_rangeBase);
bool is_address_range_covered(addr_range *ranges, uint32 numRanges, addr_t base,
size_t size);
status_t insert_physical_memory_range(addr_t start, uint32 size);
status_t insert_physical_allocated_range(addr_t start, uint32 size);

View File

@ -6,12 +6,14 @@
#include <OS.h>
#include <string.h>
#include <algorithm>
#include <kernel.h>
#include <boot/stage2.h>
#include <boot/platform.h>
#include <string.h>
static const size_t kChunkSize = 8 * B_PAGE_SIZE;
@ -214,6 +216,36 @@ get_free_address_range(addr_range *ranges, uint32 numRanges, addr_t base,
}
bool
is_address_range_covered(addr_range* ranges, uint32 numRanges, addr_t base,
size_t size)
{
// Note: We don't assume that the ranges are sorted, so we can't do this
// in a simple loop. Instead we restart the loop whenever the start of the
// given range intersects with an existing one.
for (uint32 i = 0; i < numRanges;) {
addr_t rangeStart = ranges[i].start;
addr_t rangeSize = ranges[i].size;
if (rangeStart <= base && rangeSize > base - rangeStart) {
size_t intersect = std::min(rangeStart + rangeSize - base, size);
base += intersect;
size -= intersect;
if (size == 0)
return true;
i = 0;
continue;
}
i++;
}
return false;
}
status_t
insert_physical_memory_range(addr_t start, uint32 size)
{