Made the VMArea fields base and size private and added accessors instead.
This makes it more explicit where the fields are modified. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34464 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
0a05bd2063
commit
bbd97b4bb4
@ -23,8 +23,6 @@ struct VMCache;
|
|||||||
struct VMArea {
|
struct VMArea {
|
||||||
char* name;
|
char* name;
|
||||||
area_id id;
|
area_id id;
|
||||||
addr_t base;
|
|
||||||
addr_t size;
|
|
||||||
uint32 protection;
|
uint32 protection;
|
||||||
uint16 wiring;
|
uint16 wiring;
|
||||||
uint16 memory_type;
|
uint16 memory_type;
|
||||||
@ -41,9 +39,15 @@ struct VMArea {
|
|||||||
struct VMArea* cache_prev;
|
struct VMArea* cache_prev;
|
||||||
struct VMArea* hash_next;
|
struct VMArea* hash_next;
|
||||||
|
|
||||||
|
addr_t Base() const { return fBase; }
|
||||||
|
size_t Size() const { return fSize; }
|
||||||
|
|
||||||
|
void SetBase(addr_t base) { fBase = base; }
|
||||||
|
void SetSize(size_t size) { fSize = size; }
|
||||||
|
|
||||||
bool ContainsAddress(addr_t address) const
|
bool ContainsAddress(addr_t address) const
|
||||||
{ return address >= base
|
{ return address >= fBase
|
||||||
&& address <= base + (size - 1); }
|
&& address <= fBase + (fSize - 1); }
|
||||||
|
|
||||||
static VMArea* Create(VMAddressSpace* addressSpace,
|
static VMArea* Create(VMAddressSpace* addressSpace,
|
||||||
const char* name, uint32 wiring,
|
const char* name, uint32 wiring,
|
||||||
@ -58,6 +62,8 @@ struct VMArea {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
DoublyLinkedListLink<VMArea> fAddressSpaceLink;
|
DoublyLinkedListLink<VMArea> fAddressSpaceLink;
|
||||||
|
addr_t fBase;
|
||||||
|
size_t fSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -303,7 +303,7 @@ print_stack_frame(struct thread *thread, addr_t eip, addr_t ebp, addr_t nextEbp,
|
|||||||
}
|
}
|
||||||
if (area != NULL) {
|
if (area != NULL) {
|
||||||
kprintf("%ld:%s@%p + %#lx\n", area->id, area->name,
|
kprintf("%ld:%s@%p + %#lx\n", area->id, area->name,
|
||||||
(void*)area->base, eip - area->base);
|
(void*)area->Base(), eip - area->Base());
|
||||||
} else
|
} else
|
||||||
kprintf("\n");
|
kprintf("\n");
|
||||||
}
|
}
|
||||||
@ -648,7 +648,7 @@ print_call(struct thread *thread, addr_t eip, addr_t ebp, addr_t nextEbp,
|
|||||||
area = thread->team->address_space->LookupArea(eip);
|
area = thread->team->address_space->LookupArea(eip);
|
||||||
if (area != NULL) {
|
if (area != NULL) {
|
||||||
kprintf("%ld:%s@%p + %#lx", area->id, area->name,
|
kprintf("%ld:%s@%p + %#lx", area->id, area->name,
|
||||||
(void *)area->base, eip - area->base);
|
(void *)area->Base(), eip - area->Base());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -662,5 +662,5 @@ arch_vm_set_memory_type(struct VMArea *area, addr_t physicalBase,
|
|||||||
uint32 type)
|
uint32 type)
|
||||||
{
|
{
|
||||||
area->memory_type = type >> MEMORY_TYPE_SHIFT;
|
area->memory_type = type >> MEMORY_TYPE_SHIFT;
|
||||||
return add_memory_type_range(area->id, physicalBase, area->size, type);
|
return add_memory_type_range(area->id, physicalBase, area->Size(), type);
|
||||||
}
|
}
|
||||||
|
@ -1314,7 +1314,7 @@ public:
|
|||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
// copy the runtime loader data structure
|
// copy the runtime loader data structure
|
||||||
if (!_Read((runtime_loader_debug_area*)area->base, fDebugArea))
|
if (!_Read((runtime_loader_debug_area*)area->Base(), fDebugArea))
|
||||||
return B_BAD_ADDRESS;
|
return B_BAD_ADDRESS;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
@ -337,8 +337,8 @@ VMAddressSpace::InsertArea(void** _address, uint32 addressSpec, addr_t size,
|
|||||||
|
|
||||||
status = _InsertAreaSlot(searchBase, size, searchEnd, addressSpec, area);
|
status = _InsertAreaSlot(searchBase, size, searchEnd, addressSpec, area);
|
||||||
if (status == B_OK) {
|
if (status == B_OK) {
|
||||||
*_address = (void*)area->base;
|
*_address = (void*)area->Base();
|
||||||
fFreeSpace -= area->size;
|
fFreeSpace -= area->Size();
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
@ -353,7 +353,7 @@ VMAddressSpace::RemoveArea(VMArea* area)
|
|||||||
|
|
||||||
if (area->id != RESERVED_AREA_ID) {
|
if (area->id != RESERVED_AREA_ID) {
|
||||||
IncrementChangeCount();
|
IncrementChangeCount();
|
||||||
fFreeSpace += area->size;
|
fFreeSpace += area->Size();
|
||||||
|
|
||||||
if (area == fAreaHint)
|
if (area == fAreaHint)
|
||||||
fAreaHint = NULL;
|
fAreaHint = NULL;
|
||||||
@ -379,8 +379,8 @@ VMAddressSpace::Dump() const
|
|||||||
for (VMAddressSpaceAreaList::ConstIterator it = fAreas.GetIterator();
|
for (VMAddressSpaceAreaList::ConstIterator it = fAreas.GetIterator();
|
||||||
VMArea* area = it.Next();) {
|
VMArea* area = it.Next();) {
|
||||||
kprintf(" area 0x%lx: ", area->id);
|
kprintf(" area 0x%lx: ", area->id);
|
||||||
kprintf("base_addr = 0x%lx ", area->base);
|
kprintf("base_addr = 0x%lx ", area->Base());
|
||||||
kprintf("size = 0x%lx ", area->size);
|
kprintf("size = 0x%lx ", area->Size());
|
||||||
kprintf("name = '%s' ", area->name);
|
kprintf("name = '%s' ", area->name);
|
||||||
kprintf("protection = 0x%lx\n", area->protection);
|
kprintf("protection = 0x%lx\n", area->protection);
|
||||||
}
|
}
|
||||||
@ -399,8 +399,8 @@ VMAddressSpace::_InsertAreaIntoReservedRegion(addr_t start, size_t size,
|
|||||||
|
|
||||||
for (VMAddressSpaceAreaList::Iterator it = fAreas.GetIterator();
|
for (VMAddressSpaceAreaList::Iterator it = fAreas.GetIterator();
|
||||||
(next = it.Next()) != NULL;) {
|
(next = it.Next()) != NULL;) {
|
||||||
if (next->base <= start
|
if (next->Base() <= start
|
||||||
&& next->base + (next->size - 1) >= start + (size - 1)) {
|
&& next->Base() + (next->Size() - 1) >= start + (size - 1)) {
|
||||||
// This area covers the requested range
|
// This area covers the requested range
|
||||||
if (next->id != RESERVED_AREA_ID) {
|
if (next->id != RESERVED_AREA_ID) {
|
||||||
// but it's not reserved space, it's a real area
|
// but it's not reserved space, it's a real area
|
||||||
@ -418,26 +418,26 @@ VMAddressSpace::_InsertAreaIntoReservedRegion(addr_t start, size_t size,
|
|||||||
// range to the new area - and remove, resize or split the old
|
// range to the new area - and remove, resize or split the old
|
||||||
// reserved area.
|
// reserved area.
|
||||||
|
|
||||||
if (start == next->base) {
|
if (start == next->Base()) {
|
||||||
// the area starts at the beginning of the reserved range
|
// the area starts at the beginning of the reserved range
|
||||||
fAreas.Insert(next, area);
|
fAreas.Insert(next, area);
|
||||||
|
|
||||||
if (size == next->size) {
|
if (size == next->Size()) {
|
||||||
// the new area fully covers the reversed range
|
// the new area fully covers the reversed range
|
||||||
fAreas.Remove(next);
|
fAreas.Remove(next);
|
||||||
Put();
|
Put();
|
||||||
free(next);
|
free(next);
|
||||||
} else {
|
} else {
|
||||||
// resize the reserved range behind the area
|
// resize the reserved range behind the area
|
||||||
next->base += size;
|
next->SetBase(next->Base() + size);
|
||||||
next->size -= size;
|
next->SetSize(next->Size() - size);
|
||||||
}
|
}
|
||||||
} else if (start + size == next->base + next->size) {
|
} else if (start + size == next->Base() + next->Size()) {
|
||||||
// the area is at the end of the reserved range
|
// the area is at the end of the reserved range
|
||||||
fAreas.Insert(fAreas.GetNext(next), area);
|
fAreas.Insert(fAreas.GetNext(next), area);
|
||||||
|
|
||||||
// resize the reserved range before the area
|
// resize the reserved range before the area
|
||||||
next->size = start - next->base;
|
next->SetSize(start - next->Base());
|
||||||
} else {
|
} else {
|
||||||
// the area splits the reserved range into two separate ones
|
// the area splits the reserved range into two separate ones
|
||||||
// we need a new reserved area to cover this space
|
// we need a new reserved area to cover this space
|
||||||
@ -450,14 +450,14 @@ VMAddressSpace::_InsertAreaIntoReservedRegion(addr_t start, size_t size,
|
|||||||
fAreas.Insert(reserved, area);
|
fAreas.Insert(reserved, area);
|
||||||
|
|
||||||
// resize regions
|
// resize regions
|
||||||
reserved->size = next->base + next->size - start - size;
|
reserved->SetSize(next->Base() + next->Size() - start - size);
|
||||||
next->size = start - next->base;
|
next->SetSize(start - next->Base());
|
||||||
reserved->base = start + size;
|
reserved->SetBase(start + size);
|
||||||
reserved->cache_offset = next->cache_offset;
|
reserved->cache_offset = next->cache_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
area->base = start;
|
area->SetBase(start);
|
||||||
area->size = size;
|
area->SetSize(size);
|
||||||
IncrementChangeCount();
|
IncrementChangeCount();
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@ -506,7 +506,7 @@ VMAddressSpace::_InsertAreaSlot(addr_t start, addr_t size, addr_t end,
|
|||||||
second_chance:
|
second_chance:
|
||||||
VMAddressSpaceAreaList::Iterator it = fAreas.GetIterator();
|
VMAddressSpaceAreaList::Iterator it = fAreas.GetIterator();
|
||||||
while ((next = it.Next()) != NULL) {
|
while ((next = it.Next()) != NULL) {
|
||||||
if (next->base > start + (size - 1)) {
|
if (next->Base() > start + (size - 1)) {
|
||||||
// we have a winner
|
// we have a winner
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -527,9 +527,9 @@ second_chance:
|
|||||||
// see if we can build it at the beginning of the virtual map
|
// see if we can build it at the beginning of the virtual map
|
||||||
addr_t alignedBase = ROUNDUP(fBase, alignment);
|
addr_t alignedBase = ROUNDUP(fBase, alignment);
|
||||||
if (is_valid_spot(fBase, alignedBase, size,
|
if (is_valid_spot(fBase, alignedBase, size,
|
||||||
next == NULL ? end : next->base)) {
|
next == NULL ? end : next->Base())) {
|
||||||
foundSpot = true;
|
foundSpot = true;
|
||||||
area->base = alignedBase;
|
area->SetBase(alignedBase);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -539,12 +539,12 @@ second_chance:
|
|||||||
|
|
||||||
// keep walking
|
// keep walking
|
||||||
while (next != NULL) {
|
while (next != NULL) {
|
||||||
addr_t alignedBase = ROUNDUP(last->base + last->size,
|
addr_t alignedBase = ROUNDUP(last->Base() + last->Size(),
|
||||||
alignment);
|
alignment);
|
||||||
if (is_valid_spot(last->base + (last->size - 1), alignedBase,
|
if (is_valid_spot(last->Base() + (last->Size() - 1),
|
||||||
size, next->base)) {
|
alignedBase, size, next->Base())) {
|
||||||
foundSpot = true;
|
foundSpot = true;
|
||||||
area->base = alignedBase;
|
area->SetBase(alignedBase);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -555,12 +555,13 @@ second_chance:
|
|||||||
if (foundSpot)
|
if (foundSpot)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
addr_t alignedBase = ROUNDUP(last->base + last->size, alignment);
|
addr_t alignedBase = ROUNDUP(last->Base() + last->Size(),
|
||||||
if (is_valid_spot(last->base + (last->size - 1), alignedBase,
|
alignment);
|
||||||
|
if (is_valid_spot(last->Base() + (last->Size() - 1), alignedBase,
|
||||||
size, end)) {
|
size, end)) {
|
||||||
// got a spot
|
// got a spot
|
||||||
foundSpot = true;
|
foundSpot = true;
|
||||||
area->base = alignedBase;
|
area->SetBase(alignedBase);
|
||||||
break;
|
break;
|
||||||
} else if (area->id != RESERVED_AREA_ID) {
|
} else if (area->id != RESERVED_AREA_ID) {
|
||||||
// We didn't find a free spot - if there are any reserved areas,
|
// We didn't find a free spot - if there are any reserved areas,
|
||||||
@ -576,41 +577,42 @@ second_chance:
|
|||||||
|
|
||||||
// TODO: take free space after the reserved area into
|
// TODO: take free space after the reserved area into
|
||||||
// account!
|
// account!
|
||||||
addr_t alignedBase = ROUNDUP(next->base, alignment);
|
addr_t alignedBase = ROUNDUP(next->Base(), alignment);
|
||||||
if (next->base == alignedBase && next->size == size) {
|
if (next->Base() == alignedBase && next->Size() == size) {
|
||||||
// The reserved area is entirely covered, and thus,
|
// The reserved area is entirely covered, and thus,
|
||||||
// removed
|
// removed
|
||||||
fAreas.Remove(next);
|
fAreas.Remove(next);
|
||||||
|
|
||||||
foundSpot = true;
|
foundSpot = true;
|
||||||
area->base = alignedBase;
|
area->SetBase(alignedBase);
|
||||||
free(next);
|
free(next);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((next->protection & RESERVED_AVOID_BASE) == 0
|
if ((next->protection & RESERVED_AVOID_BASE) == 0
|
||||||
&& alignedBase == next->base && next->size >= size) {
|
&& alignedBase == next->Base()
|
||||||
|
&& next->Size() >= size) {
|
||||||
// The new area will be placed at the beginning of the
|
// The new area will be placed at the beginning of the
|
||||||
// reserved area and the reserved area will be offset
|
// reserved area and the reserved area will be offset
|
||||||
// and resized
|
// and resized
|
||||||
foundSpot = true;
|
foundSpot = true;
|
||||||
next->base += size;
|
next->SetBase(next->Base() + size);
|
||||||
next->size -= size;
|
next->SetSize(next->Size() - size);
|
||||||
area->base = alignedBase;
|
area->SetBase(alignedBase);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_valid_spot(next->base, alignedBase, size,
|
if (is_valid_spot(next->Base(), alignedBase, size,
|
||||||
next->base + (next->size - 1))) {
|
next->Base() + (next->Size() - 1))) {
|
||||||
// The new area will be placed at the end of the
|
// The new area will be placed at the end of the
|
||||||
// reserved area, and the reserved area will be resized
|
// reserved area, and the reserved area will be resized
|
||||||
// to make space
|
// to make space
|
||||||
alignedBase = ROUNDDOWN(next->base + next->size - size,
|
alignedBase = ROUNDDOWN(
|
||||||
alignment);
|
next->Base() + next->Size() - size, alignment);
|
||||||
|
|
||||||
foundSpot = true;
|
foundSpot = true;
|
||||||
next->size = alignedBase - next->base;
|
next->SetSize(alignedBase - next->Base());
|
||||||
area->base = alignedBase;
|
area->SetBase(alignedBase);
|
||||||
last = next;
|
last = next;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -627,9 +629,9 @@ second_chance:
|
|||||||
if (last == NULL) {
|
if (last == NULL) {
|
||||||
// see if we can build it at the beginning of the specified
|
// see if we can build it at the beginning of the specified
|
||||||
// start
|
// start
|
||||||
if (next == NULL || next->base > start + (size - 1)) {
|
if (next == NULL || next->Base() > start + (size - 1)) {
|
||||||
foundSpot = true;
|
foundSpot = true;
|
||||||
area->base = start;
|
area->SetBase(start);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -639,7 +641,7 @@ second_chance:
|
|||||||
|
|
||||||
// keep walking
|
// keep walking
|
||||||
while (next != NULL) {
|
while (next != NULL) {
|
||||||
if (next->base - (last->base + last->size) >= size) {
|
if (next->Base() - (last->Base() + last->Size()) >= size) {
|
||||||
// we found a spot (it'll be filled up below)
|
// we found a spot (it'll be filled up below)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -648,14 +650,14 @@ second_chance:
|
|||||||
next = it.Next();
|
next = it.Next();
|
||||||
}
|
}
|
||||||
|
|
||||||
addr_t lastEnd = last->base + (last->size - 1);
|
addr_t lastEnd = last->Base() + (last->Size() - 1);
|
||||||
if (next != NULL || end - lastEnd >= size) {
|
if (next != NULL || end - lastEnd >= size) {
|
||||||
// got a spot
|
// got a spot
|
||||||
foundSpot = true;
|
foundSpot = true;
|
||||||
if (lastEnd < start)
|
if (lastEnd < start)
|
||||||
area->base = start;
|
area->SetBase(start);
|
||||||
else
|
else
|
||||||
area->base = lastEnd + 1;
|
area->SetBase(lastEnd + 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -669,10 +671,10 @@ second_chance:
|
|||||||
|
|
||||||
case B_EXACT_ADDRESS:
|
case B_EXACT_ADDRESS:
|
||||||
// see if we can create it exactly here
|
// see if we can create it exactly here
|
||||||
if ((last == NULL || last->base + (last->size - 1) < start)
|
if ((last == NULL || last->Base() + (last->Size() - 1) < start)
|
||||||
&& (next == NULL || next->base > start + (size - 1))) {
|
&& (next == NULL || next->Base() > start + (size - 1))) {
|
||||||
foundSpot = true;
|
foundSpot = true;
|
||||||
area->base = start;
|
area->SetBase(start);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -683,7 +685,7 @@ second_chance:
|
|||||||
if (!foundSpot)
|
if (!foundSpot)
|
||||||
return addressSpec == B_EXACT_ADDRESS ? B_BAD_VALUE : B_NO_MEMORY;
|
return addressSpec == B_EXACT_ADDRESS ? B_BAD_VALUE : B_NO_MEMORY;
|
||||||
|
|
||||||
area->size = size;
|
area->SetSize(size);
|
||||||
if (last)
|
if (last)
|
||||||
fAreas.Insert(fAreas.GetNext(last), area);
|
fAreas.Insert(fAreas.GetNext(last), area);
|
||||||
else
|
else
|
||||||
@ -736,7 +738,7 @@ VMAddressSpace::_DumpListCommand(int argc, char** argv)
|
|||||||
if (area->id != RESERVED_AREA_ID
|
if (area->id != RESERVED_AREA_ID
|
||||||
&& area->cache->type != CACHE_TYPE_NULL) {
|
&& area->cache->type != CACHE_TYPE_NULL) {
|
||||||
areaCount++;
|
areaCount++;
|
||||||
areaSize += area->size;
|
areaSize += area->Size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
kprintf("%p %6ld %#010lx %#10lx %10ld %10lld\n",
|
kprintf("%p %6ld %#010lx %#10lx %10ld %10lld\n",
|
||||||
|
@ -46,8 +46,8 @@ VMArea::Create(VMAddressSpace* addressSpace, const char* name,
|
|||||||
strlcpy(area->name, name, length);
|
strlcpy(area->name, name, length);
|
||||||
|
|
||||||
area->id = atomic_add(&sNextAreaID, 1);
|
area->id = atomic_add(&sNextAreaID, 1);
|
||||||
area->base = 0;
|
area->fBase = 0;
|
||||||
area->size = 0;
|
area->fSize = 0;
|
||||||
area->protection = protection;
|
area->protection = protection;
|
||||||
area->wiring = wiring;
|
area->wiring = wiring;
|
||||||
area->memory_type = 0;
|
area->memory_type = 0;
|
||||||
|
@ -281,7 +281,7 @@ static inline void
|
|||||||
set_area_page_protection(VMArea* area, addr_t pageAddress, uint32 protection)
|
set_area_page_protection(VMArea* area, addr_t pageAddress, uint32 protection)
|
||||||
{
|
{
|
||||||
protection &= B_READ_AREA | B_WRITE_AREA | B_EXECUTE_AREA;
|
protection &= B_READ_AREA | B_WRITE_AREA | B_EXECUTE_AREA;
|
||||||
uint32 pageIndex = (pageAddress - area->base) / B_PAGE_SIZE;
|
uint32 pageIndex = (pageAddress - area->Base()) / B_PAGE_SIZE;
|
||||||
uint8& entry = area->page_protections[pageIndex / 2];
|
uint8& entry = area->page_protections[pageIndex / 2];
|
||||||
if (pageIndex % 2 == 0)
|
if (pageIndex % 2 == 0)
|
||||||
entry = (entry & 0xf0) | protection;
|
entry = (entry & 0xf0) | protection;
|
||||||
@ -296,7 +296,7 @@ get_area_page_protection(VMArea* area, addr_t pageAddress)
|
|||||||
if (area->page_protections == NULL)
|
if (area->page_protections == NULL)
|
||||||
return area->protection;
|
return area->protection;
|
||||||
|
|
||||||
uint32 pageIndex = (pageAddress - area->base) / B_PAGE_SIZE;
|
uint32 pageIndex = (pageAddress - area->Base()) / B_PAGE_SIZE;
|
||||||
uint32 protection = area->page_protections[pageIndex / 2];
|
uint32 protection = area->page_protections[pageIndex / 2];
|
||||||
if (pageIndex % 2 == 0)
|
if (pageIndex % 2 == 0)
|
||||||
protection &= 0x0f;
|
protection &= 0x0f;
|
||||||
@ -320,12 +320,12 @@ cut_area(VMAddressSpace* addressSpace, VMArea* area, addr_t address,
|
|||||||
addr_t lastAddress, VMArea** _secondArea, bool kernel)
|
addr_t lastAddress, VMArea** _secondArea, bool kernel)
|
||||||
{
|
{
|
||||||
// Does the cut range intersect with the area at all?
|
// Does the cut range intersect with the area at all?
|
||||||
addr_t areaLast = area->base + (area->size - 1);
|
addr_t areaLast = area->Base() + (area->Size() - 1);
|
||||||
if (area->base > lastAddress || areaLast < address)
|
if (area->Base() > lastAddress || areaLast < address)
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
// Is the area fully covered?
|
// Is the area fully covered?
|
||||||
if (area->base >= address && areaLast <= lastAddress) {
|
if (area->Base() >= address && areaLast <= lastAddress) {
|
||||||
delete_area(addressSpace, area);
|
delete_area(addressSpace, area);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@ -335,10 +335,10 @@ cut_area(VMAddressSpace* addressSpace, VMArea* area, addr_t address,
|
|||||||
|
|
||||||
// Cut the end only?
|
// Cut the end only?
|
||||||
if (areaLast <= lastAddress) {
|
if (areaLast <= lastAddress) {
|
||||||
addr_t newSize = address - area->base;
|
addr_t newSize = address - area->Base();
|
||||||
|
|
||||||
// unmap pages
|
// unmap pages
|
||||||
vm_unmap_pages(area, address, area->size - newSize, false);
|
vm_unmap_pages(area, address, area->Size() - newSize, false);
|
||||||
|
|
||||||
// If no one else uses the area's cache, we can resize it, too.
|
// If no one else uses the area's cache, we can resize it, too.
|
||||||
if (cache->areas == area && area->cache_next == NULL
|
if (cache->areas == area && area->cache_next == NULL
|
||||||
@ -348,24 +348,24 @@ cut_area(VMAddressSpace* addressSpace, VMArea* area, addr_t address,
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
area->size = newSize;
|
area->SetSize(newSize);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cut the beginning only?
|
// Cut the beginning only?
|
||||||
if (area->base >= address) {
|
if (area->Base() >= address) {
|
||||||
addr_t newBase = lastAddress + 1;
|
addr_t newBase = lastAddress + 1;
|
||||||
addr_t newSize = areaLast - lastAddress;
|
addr_t newSize = areaLast - lastAddress;
|
||||||
|
|
||||||
// unmap pages
|
// unmap pages
|
||||||
vm_unmap_pages(area, area->base, newBase - area->base, false);
|
vm_unmap_pages(area, area->Base(), newBase - area->Base(), false);
|
||||||
|
|
||||||
// TODO: If no one else uses the area's cache, we should resize it, too!
|
// TODO: If no one else uses the area's cache, we should resize it, too!
|
||||||
|
|
||||||
area->cache_offset += newBase - area->base;
|
area->cache_offset += newBase - area->Base();
|
||||||
area->base = newBase;
|
area->SetBase(newBase);
|
||||||
area->size = newSize;
|
area->SetSize(newSize);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@ -374,16 +374,16 @@ cut_area(VMAddressSpace* addressSpace, VMArea* area, addr_t address,
|
|||||||
// We do that by shrinking the area to the begin section and creating a
|
// We do that by shrinking the area to the begin section and creating a
|
||||||
// new area for the end section.
|
// new area for the end section.
|
||||||
|
|
||||||
addr_t firstNewSize = address - area->base;
|
addr_t firstNewSize = address - area->Base();
|
||||||
addr_t secondBase = lastAddress + 1;
|
addr_t secondBase = lastAddress + 1;
|
||||||
addr_t secondSize = areaLast - lastAddress;
|
addr_t secondSize = areaLast - lastAddress;
|
||||||
|
|
||||||
// unmap pages
|
// unmap pages
|
||||||
vm_unmap_pages(area, address, area->size - firstNewSize, false);
|
vm_unmap_pages(area, address, area->Size() - firstNewSize, false);
|
||||||
|
|
||||||
// resize the area
|
// resize the area
|
||||||
addr_t oldSize = area->size;
|
addr_t oldSize = area->Size();
|
||||||
area->size = firstNewSize;
|
area->SetSize(firstNewSize);
|
||||||
|
|
||||||
// TODO: If no one else uses the area's cache, we might want to create a
|
// TODO: If no one else uses the area's cache, we might want to create a
|
||||||
// new cache for the second area, transfer the concerned pages from the
|
// new cache for the second area, transfer the concerned pages from the
|
||||||
@ -393,11 +393,11 @@ cut_area(VMAddressSpace* addressSpace, VMArea* area, addr_t address,
|
|||||||
VMArea* secondArea;
|
VMArea* secondArea;
|
||||||
void* secondBaseAddress = (void*)secondBase;
|
void* secondBaseAddress = (void*)secondBase;
|
||||||
status_t error = map_backing_store(addressSpace, cache, &secondBaseAddress,
|
status_t error = map_backing_store(addressSpace, cache, &secondBaseAddress,
|
||||||
area->cache_offset + (secondBase - area->base), secondSize,
|
area->cache_offset + (secondBase - area->Base()), secondSize,
|
||||||
B_EXACT_ADDRESS, area->wiring, area->protection, REGION_NO_PRIVATE_MAP,
|
B_EXACT_ADDRESS, area->wiring, area->protection, REGION_NO_PRIVATE_MAP,
|
||||||
&secondArea, area->name, false, kernel);
|
&secondArea, area->name, false, kernel);
|
||||||
if (error != B_OK) {
|
if (error != B_OK) {
|
||||||
area->size = oldSize;
|
area->SetSize(oldSize);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -452,8 +452,8 @@ unmap_address_range(VMAddressSpace* addressSpace, addr_t address, addr_t size,
|
|||||||
for (VMAddressSpace::Iterator it = addressSpace->GetIterator();
|
for (VMAddressSpace::Iterator it = addressSpace->GetIterator();
|
||||||
VMArea* area = it.Next();) {
|
VMArea* area = it.Next();) {
|
||||||
if (area->id != RESERVED_AREA_ID) {
|
if (area->id != RESERVED_AREA_ID) {
|
||||||
addr_t areaLast = area->base + (area->size - 1);
|
addr_t areaLast = area->Base() + (area->Size() - 1);
|
||||||
if (area->base < lastAddress && address < areaLast) {
|
if (area->Base() < lastAddress && address < areaLast) {
|
||||||
if ((area->protection & B_KERNEL_AREA) != 0)
|
if ((area->protection & B_KERNEL_AREA) != 0)
|
||||||
return B_NOT_ALLOWED;
|
return B_NOT_ALLOWED;
|
||||||
}
|
}
|
||||||
@ -464,8 +464,8 @@ unmap_address_range(VMAddressSpace* addressSpace, addr_t address, addr_t size,
|
|||||||
for (VMAddressSpace::Iterator it = addressSpace->GetIterator();
|
for (VMAddressSpace::Iterator it = addressSpace->GetIterator();
|
||||||
VMArea* area = it.Next();) {
|
VMArea* area = it.Next();) {
|
||||||
if (area->id != RESERVED_AREA_ID) {
|
if (area->id != RESERVED_AREA_ID) {
|
||||||
addr_t areaLast = area->base + (area->size - 1);
|
addr_t areaLast = area->Base() + (area->Size() - 1);
|
||||||
if (area->base < lastAddress && address < areaLast) {
|
if (area->Base() < lastAddress && address < areaLast) {
|
||||||
status_t error = cut_area(addressSpace, area, address,
|
status_t error = cut_area(addressSpace, area, address,
|
||||||
lastAddress, NULL, kernel);
|
lastAddress, NULL, kernel);
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
@ -652,9 +652,9 @@ vm_unreserve_address_range(team_id team, void* address, addr_t size)
|
|||||||
for (VMAddressSpace::Iterator it = locker.AddressSpace()->GetIterator();
|
for (VMAddressSpace::Iterator it = locker.AddressSpace()->GetIterator();
|
||||||
VMArea* area = it.Next();) {
|
VMArea* area = it.Next();) {
|
||||||
// the area must be completely part of the reserved range
|
// the area must be completely part of the reserved range
|
||||||
if (area->base + (area->size - 1) > endAddress)
|
if (area->Base() + (area->Size() - 1) > endAddress)
|
||||||
break;
|
break;
|
||||||
if (area->id == RESERVED_AREA_ID && area->base >= (addr_t)address) {
|
if (area->id == RESERVED_AREA_ID && area->Base() >= (addr_t)address) {
|
||||||
// remove reserved range
|
// remove reserved range
|
||||||
locker.AddressSpace()->RemoveArea(area);
|
locker.AddressSpace()->RemoveArea(area);
|
||||||
locker.AddressSpace()->Put();
|
locker.AddressSpace()->Put();
|
||||||
@ -697,7 +697,7 @@ vm_reserve_address_range(team_id team, void** _address, uint32 addressSpec,
|
|||||||
|
|
||||||
// the area is now reserved!
|
// the area is now reserved!
|
||||||
|
|
||||||
area->cache_offset = area->base;
|
area->cache_offset = area->Base();
|
||||||
// we cache the original base address here
|
// we cache the original base address here
|
||||||
|
|
||||||
locker.AddressSpace()->Get();
|
locker.AddressSpace()->Get();
|
||||||
@ -897,15 +897,15 @@ vm_create_anonymous_area(team_id team, const char* name, void** address,
|
|||||||
// Allocate and map all pages for this area
|
// Allocate and map all pages for this area
|
||||||
|
|
||||||
off_t offset = 0;
|
off_t offset = 0;
|
||||||
for (addr_t address = area->base;
|
for (addr_t address = area->Base();
|
||||||
address < area->base + (area->size - 1);
|
address < area->Base() + (area->Size() - 1);
|
||||||
address += B_PAGE_SIZE, offset += B_PAGE_SIZE) {
|
address += B_PAGE_SIZE, offset += B_PAGE_SIZE) {
|
||||||
#ifdef DEBUG_KERNEL_STACKS
|
#ifdef DEBUG_KERNEL_STACKS
|
||||||
# ifdef STACK_GROWS_DOWNWARDS
|
# ifdef STACK_GROWS_DOWNWARDS
|
||||||
if (isStack && address < area->base + KERNEL_STACK_GUARD_PAGES
|
if (isStack && address < area->Base()
|
||||||
* B_PAGE_SIZE)
|
+ KERNEL_STACK_GUARD_PAGES * B_PAGE_SIZE)
|
||||||
# else
|
# else
|
||||||
if (isStack && address >= area->base + area->size
|
if (isStack && address >= area->Base() + area->Size()
|
||||||
- KERNEL_STACK_GUARD_PAGES * B_PAGE_SIZE)
|
- KERNEL_STACK_GUARD_PAGES * B_PAGE_SIZE)
|
||||||
# endif
|
# endif
|
||||||
continue;
|
continue;
|
||||||
@ -939,9 +939,9 @@ vm_create_anonymous_area(team_id team, const char* name, void** address,
|
|||||||
|
|
||||||
map->ops->lock(map);
|
map->ops->lock(map);
|
||||||
|
|
||||||
for (addr_t virtualAddress = area->base; virtualAddress < area->base
|
for (addr_t virtualAddress = area->Base();
|
||||||
+ (area->size - 1); virtualAddress += B_PAGE_SIZE,
|
virtualAddress < area->Base() + (area->Size() - 1);
|
||||||
offset += B_PAGE_SIZE) {
|
virtualAddress += B_PAGE_SIZE, offset += B_PAGE_SIZE) {
|
||||||
addr_t physicalAddress;
|
addr_t physicalAddress;
|
||||||
uint32 flags;
|
uint32 flags;
|
||||||
status = map->ops->query(map, virtualAddress,
|
status = map->ops->query(map, virtualAddress,
|
||||||
@ -971,13 +971,13 @@ vm_create_anonymous_area(team_id team, const char* name, void** address,
|
|||||||
// just map them in the address space
|
// just map them in the address space
|
||||||
vm_translation_map* map = &addressSpace->TranslationMap();
|
vm_translation_map* map = &addressSpace->TranslationMap();
|
||||||
addr_t physicalAddress = page->physical_page_number * B_PAGE_SIZE;
|
addr_t physicalAddress = page->physical_page_number * B_PAGE_SIZE;
|
||||||
addr_t virtualAddress = area->base;
|
addr_t virtualAddress = area->Base();
|
||||||
off_t offset = 0;
|
off_t offset = 0;
|
||||||
|
|
||||||
map->ops->lock(map);
|
map->ops->lock(map);
|
||||||
|
|
||||||
for (virtualAddress = area->base; virtualAddress < area->base
|
for (virtualAddress = area->Base(); virtualAddress < area->Base()
|
||||||
+ (area->size - 1); virtualAddress += B_PAGE_SIZE,
|
+ (area->Size() - 1); virtualAddress += B_PAGE_SIZE,
|
||||||
offset += B_PAGE_SIZE, physicalAddress += B_PAGE_SIZE) {
|
offset += B_PAGE_SIZE, physicalAddress += B_PAGE_SIZE) {
|
||||||
page = vm_lookup_page(physicalAddress / B_PAGE_SIZE);
|
page = vm_lookup_page(physicalAddress / B_PAGE_SIZE);
|
||||||
if (page == NULL)
|
if (page == NULL)
|
||||||
@ -1094,14 +1094,14 @@ vm_map_physical_memory(team_id team, const char* name, void** _address,
|
|||||||
// make sure our area is mapped in completely
|
// make sure our area is mapped in completely
|
||||||
|
|
||||||
vm_translation_map* map = &locker.AddressSpace()->TranslationMap();
|
vm_translation_map* map = &locker.AddressSpace()->TranslationMap();
|
||||||
size_t reservePages = map->ops->map_max_pages_need(map, area->base,
|
size_t reservePages = map->ops->map_max_pages_need(map, area->Base(),
|
||||||
area->base + (size - 1));
|
area->Base() + (size - 1));
|
||||||
|
|
||||||
vm_page_reserve_pages(reservePages);
|
vm_page_reserve_pages(reservePages);
|
||||||
map->ops->lock(map);
|
map->ops->lock(map);
|
||||||
|
|
||||||
for (addr_t offset = 0; offset < size; offset += B_PAGE_SIZE) {
|
for (addr_t offset = 0; offset < size; offset += B_PAGE_SIZE) {
|
||||||
map->ops->map(map, area->base + offset, physicalAddress + offset,
|
map->ops->map(map, area->Base() + offset, physicalAddress + offset,
|
||||||
protection);
|
protection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1179,8 +1179,8 @@ vm_map_physical_memory_vecs(team_id team, const char* name, void** _address,
|
|||||||
return result;
|
return result;
|
||||||
|
|
||||||
vm_translation_map* map = &locker.AddressSpace()->TranslationMap();
|
vm_translation_map* map = &locker.AddressSpace()->TranslationMap();
|
||||||
size_t reservePages = map->ops->map_max_pages_need(map, area->base,
|
size_t reservePages = map->ops->map_max_pages_need(map, area->Base(),
|
||||||
area->base + (size - 1));
|
area->Base() + (size - 1));
|
||||||
|
|
||||||
vm_page_reserve_pages(reservePages);
|
vm_page_reserve_pages(reservePages);
|
||||||
map->ops->lock(map);
|
map->ops->lock(map);
|
||||||
@ -1196,7 +1196,7 @@ vm_map_physical_memory_vecs(team_id team, const char* name, void** _address,
|
|||||||
if (vecIndex >= vecCount)
|
if (vecIndex >= vecCount)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
map->ops->map(map, area->base + offset,
|
map->ops->map(map, area->Base() + offset,
|
||||||
(addr_t)vecs[vecIndex].iov_base + vecOffset, protection);
|
(addr_t)vecs[vecIndex].iov_base + vecOffset, protection);
|
||||||
|
|
||||||
vecOffset += B_PAGE_SIZE;
|
vecOffset += B_PAGE_SIZE;
|
||||||
@ -1269,10 +1269,10 @@ vm_create_vnode_cache(struct vnode* vnode, struct VMCache** cache)
|
|||||||
static void
|
static void
|
||||||
pre_map_area_pages(VMArea* area, VMCache* cache)
|
pre_map_area_pages(VMArea* area, VMCache* cache)
|
||||||
{
|
{
|
||||||
addr_t baseAddress = area->base;
|
addr_t baseAddress = area->Base();
|
||||||
addr_t cacheOffset = area->cache_offset;
|
addr_t cacheOffset = area->cache_offset;
|
||||||
page_num_t firstPage = cacheOffset / B_PAGE_SIZE;
|
page_num_t firstPage = cacheOffset / B_PAGE_SIZE;
|
||||||
page_num_t endPage = firstPage + area->size / B_PAGE_SIZE;
|
page_num_t endPage = firstPage + area->Size() / B_PAGE_SIZE;
|
||||||
|
|
||||||
for (VMCachePagesTree::Iterator it
|
for (VMCachePagesTree::Iterator it
|
||||||
= cache->pages.GetIterator(firstPage, true, true);
|
= cache->pages.GetIterator(firstPage, true, true);
|
||||||
@ -1531,7 +1531,7 @@ vm_clone_area(team_id team, const char* name, void** address,
|
|||||||
status = B_NOT_ALLOWED;
|
status = B_NOT_ALLOWED;
|
||||||
else {
|
else {
|
||||||
status = map_backing_store(targetAddressSpace, cache, address,
|
status = map_backing_store(targetAddressSpace, cache, address,
|
||||||
sourceArea->cache_offset, sourceArea->size, addressSpec,
|
sourceArea->cache_offset, sourceArea->Size(), addressSpec,
|
||||||
sourceArea->wiring, protection, mapping, &newArea, name, false,
|
sourceArea->wiring, protection, mapping, &newArea, name, false,
|
||||||
kernel);
|
kernel);
|
||||||
}
|
}
|
||||||
@ -1552,21 +1552,21 @@ vm_clone_area(team_id team, const char* name, void** address,
|
|||||||
|
|
||||||
addr_t physicalAddress;
|
addr_t physicalAddress;
|
||||||
uint32 oldProtection;
|
uint32 oldProtection;
|
||||||
map->ops->query(map, sourceArea->base, &physicalAddress,
|
map->ops->query(map, sourceArea->Base(), &physicalAddress,
|
||||||
&oldProtection);
|
&oldProtection);
|
||||||
|
|
||||||
map->ops->unlock(map);
|
map->ops->unlock(map);
|
||||||
|
|
||||||
map = &targetAddressSpace->TranslationMap();
|
map = &targetAddressSpace->TranslationMap();
|
||||||
size_t reservePages = map->ops->map_max_pages_need(map,
|
size_t reservePages = map->ops->map_max_pages_need(map,
|
||||||
newArea->base, newArea->base + (newArea->size - 1));
|
newArea->Base(), newArea->Base() + (newArea->Size() - 1));
|
||||||
|
|
||||||
vm_page_reserve_pages(reservePages);
|
vm_page_reserve_pages(reservePages);
|
||||||
map->ops->lock(map);
|
map->ops->lock(map);
|
||||||
|
|
||||||
for (addr_t offset = 0; offset < newArea->size;
|
for (addr_t offset = 0; offset < newArea->Size();
|
||||||
offset += B_PAGE_SIZE) {
|
offset += B_PAGE_SIZE) {
|
||||||
map->ops->map(map, newArea->base + offset,
|
map->ops->map(map, newArea->Base() + offset,
|
||||||
physicalAddress + offset, protection);
|
physicalAddress + offset, protection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1575,13 +1575,13 @@ vm_clone_area(team_id team, const char* name, void** address,
|
|||||||
} else {
|
} else {
|
||||||
vm_translation_map* map = &targetAddressSpace->TranslationMap();
|
vm_translation_map* map = &targetAddressSpace->TranslationMap();
|
||||||
size_t reservePages = map->ops->map_max_pages_need(map,
|
size_t reservePages = map->ops->map_max_pages_need(map,
|
||||||
newArea->base, newArea->base + (newArea->size - 1));
|
newArea->Base(), newArea->Base() + (newArea->Size() - 1));
|
||||||
vm_page_reserve_pages(reservePages);
|
vm_page_reserve_pages(reservePages);
|
||||||
|
|
||||||
// map in all pages from source
|
// map in all pages from source
|
||||||
for (VMCachePagesTree::Iterator it = cache->pages.GetIterator();
|
for (VMCachePagesTree::Iterator it = cache->pages.GetIterator();
|
||||||
vm_page* page = it.Next();) {
|
vm_page* page = it.Next();) {
|
||||||
vm_map_page(newArea, page, newArea->base
|
vm_map_page(newArea, page, newArea->Base()
|
||||||
+ ((page->cache_offset << PAGE_SHIFT)
|
+ ((page->cache_offset << PAGE_SHIFT)
|
||||||
- newArea->cache_offset), protection);
|
- newArea->cache_offset), protection);
|
||||||
}
|
}
|
||||||
@ -1610,7 +1610,7 @@ delete_area(VMAddressSpace* addressSpace, VMArea* area)
|
|||||||
// still exists in the area list.
|
// still exists in the area list.
|
||||||
|
|
||||||
// Unmap the virtual address space the area occupied
|
// Unmap the virtual address space the area occupied
|
||||||
vm_unmap_pages(area, area->base, area->size, !area->cache->temporary);
|
vm_unmap_pages(area, area->Base(), area->Size(), !area->cache->temporary);
|
||||||
|
|
||||||
if (!area->cache->temporary)
|
if (!area->cache->temporary)
|
||||||
area->cache->WriteModified();
|
area->cache->WriteModified();
|
||||||
@ -1706,8 +1706,8 @@ vm_copy_on_write_area(VMCache* lowerCache)
|
|||||||
|
|
||||||
vm_translation_map* map = &tempArea->address_space->TranslationMap();
|
vm_translation_map* map = &tempArea->address_space->TranslationMap();
|
||||||
map->ops->lock(map);
|
map->ops->lock(map);
|
||||||
map->ops->protect(map, tempArea->base,
|
map->ops->protect(map, tempArea->Base(),
|
||||||
tempArea->base - 1 + tempArea->size, protection);
|
tempArea->Base() - 1 + tempArea->Size(), protection);
|
||||||
map->ops->unlock(map);
|
map->ops->unlock(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1748,7 +1748,7 @@ vm_copy_area(team_id team, const char* name, void** _address,
|
|||||||
|
|
||||||
if (addressSpec == B_CLONE_ADDRESS) {
|
if (addressSpec == B_CLONE_ADDRESS) {
|
||||||
addressSpec = B_EXACT_ADDRESS;
|
addressSpec = B_EXACT_ADDRESS;
|
||||||
*_address = (void*)source->base;
|
*_address = (void*)source->Base();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sharedArea = (source->protection & B_SHARED_AREA) != 0;
|
bool sharedArea = (source->protection & B_SHARED_AREA) != 0;
|
||||||
@ -1758,7 +1758,7 @@ vm_copy_area(team_id team, const char* name, void** _address,
|
|||||||
|
|
||||||
VMArea* target;
|
VMArea* target;
|
||||||
status = map_backing_store(targetAddressSpace, cache, _address,
|
status = map_backing_store(targetAddressSpace, cache, _address,
|
||||||
source->cache_offset, source->size, addressSpec, source->wiring,
|
source->cache_offset, source->Size(), addressSpec, source->wiring,
|
||||||
protection, sharedArea ? REGION_NO_PRIVATE_MAP : REGION_PRIVATE_MAP,
|
protection, sharedArea ? REGION_NO_PRIVATE_MAP : REGION_PRIVATE_MAP,
|
||||||
&target, name, false, true);
|
&target, name, false, true);
|
||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
@ -1880,7 +1880,7 @@ vm_set_area_protection(team_id team, area_id areaID, uint32 newProtection,
|
|||||||
|
|
||||||
for (VMCachePagesTree::Iterator it = cache->pages.GetIterator();
|
for (VMCachePagesTree::Iterator it = cache->pages.GetIterator();
|
||||||
vm_page* page = it.Next();) {
|
vm_page* page = it.Next();) {
|
||||||
addr_t address = area->base
|
addr_t address = area->Base()
|
||||||
+ (page->cache_offset << PAGE_SHIFT);
|
+ (page->cache_offset << PAGE_SHIFT);
|
||||||
map->ops->protect(map, address, address - 1 + B_PAGE_SIZE,
|
map->ops->protect(map, address, address - 1 + B_PAGE_SIZE,
|
||||||
newProtection);
|
newProtection);
|
||||||
@ -1899,8 +1899,8 @@ vm_set_area_protection(team_id team, area_id areaID, uint32 newProtection,
|
|||||||
|
|
||||||
if (changePageProtection) {
|
if (changePageProtection) {
|
||||||
map->ops->lock(map);
|
map->ops->lock(map);
|
||||||
map->ops->protect(map, area->base, area->base - 1 + area->size,
|
map->ops->protect(map,
|
||||||
newProtection);
|
area->Base(), area->Base() - 1 + area->Size(), newProtection);
|
||||||
map->ops->unlock(map);
|
map->ops->unlock(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1930,7 +1930,7 @@ vm_get_page_mapping(team_id team, addr_t vaddr, addr_t* paddr)
|
|||||||
static inline addr_t
|
static inline addr_t
|
||||||
virtual_page_address(VMArea* area, vm_page* page)
|
virtual_page_address(VMArea* area, vm_page* page)
|
||||||
{
|
{
|
||||||
return area->base
|
return area->Base()
|
||||||
+ ((page->cache_offset << PAGE_SHIFT) - area->cache_offset);
|
+ ((page->cache_offset << PAGE_SHIFT) - area->cache_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2191,7 +2191,7 @@ vm_unmap_pages(VMArea* area, addr_t base, size_t size, bool preserveModified)
|
|||||||
map->ops->unlock(map);
|
map->ops->unlock(map);
|
||||||
|
|
||||||
if (area->wiring == B_NO_LOCK) {
|
if (area->wiring == B_NO_LOCK) {
|
||||||
uint32 startOffset = (area->cache_offset + base - area->base)
|
uint32 startOffset = (area->cache_offset + base - area->Base())
|
||||||
>> PAGE_SHIFT;
|
>> PAGE_SHIFT;
|
||||||
uint32 endOffset = startOffset + (size >> PAGE_SHIFT);
|
uint32 endOffset = startOffset + (size >> PAGE_SHIFT);
|
||||||
vm_page_mapping* mapping;
|
vm_page_mapping* mapping;
|
||||||
@ -2711,7 +2711,8 @@ dump_cache(int argc, char** argv)
|
|||||||
|
|
||||||
for (VMArea* area = cache->areas; area != NULL; area = area->cache_next) {
|
for (VMArea* area = cache->areas; area != NULL; area = area->cache_next) {
|
||||||
kprintf(" area 0x%lx, %s\n", area->id, area->name);
|
kprintf(" area 0x%lx, %s\n", area->id, area->name);
|
||||||
kprintf("\tbase_addr: 0x%lx, size: 0x%lx\n", area->base, area->size);
|
kprintf("\tbase_addr: 0x%lx, size: 0x%lx\n", area->Base(),
|
||||||
|
area->Size());
|
||||||
kprintf("\tprotection: 0x%lx\n", area->protection);
|
kprintf("\tprotection: 0x%lx\n", area->protection);
|
||||||
kprintf("\towner: 0x%lx\n", area->address_space->ID());
|
kprintf("\towner: 0x%lx\n", area->address_space->ID());
|
||||||
}
|
}
|
||||||
@ -2752,8 +2753,8 @@ dump_area_struct(VMArea* area, bool mappings)
|
|||||||
kprintf("name:\t\t'%s'\n", area->name);
|
kprintf("name:\t\t'%s'\n", area->name);
|
||||||
kprintf("owner:\t\t0x%lx\n", area->address_space->ID());
|
kprintf("owner:\t\t0x%lx\n", area->address_space->ID());
|
||||||
kprintf("id:\t\t0x%lx\n", area->id);
|
kprintf("id:\t\t0x%lx\n", area->id);
|
||||||
kprintf("base:\t\t0x%lx\n", area->base);
|
kprintf("base:\t\t0x%lx\n", area->Base());
|
||||||
kprintf("size:\t\t0x%lx\n", area->size);
|
kprintf("size:\t\t0x%lx\n", area->Size());
|
||||||
kprintf("protection:\t0x%lx\n", area->protection);
|
kprintf("protection:\t0x%lx\n", area->protection);
|
||||||
kprintf("wiring:\t\t0x%x\n", area->wiring);
|
kprintf("wiring:\t\t0x%x\n", area->wiring);
|
||||||
kprintf("memory_type:\t0x%x\n", area->memory_type);
|
kprintf("memory_type:\t0x%x\n", area->memory_type);
|
||||||
@ -2833,8 +2834,8 @@ dump_area(int argc, char** argv)
|
|||||||
if (((mode & 4) != 0 && area->name != NULL
|
if (((mode & 4) != 0 && area->name != NULL
|
||||||
&& !strcmp(argv[index], area->name))
|
&& !strcmp(argv[index], area->name))
|
||||||
|| (num != 0 && (((mode & 1) != 0 && (addr_t)area->id == num)
|
|| (num != 0 && (((mode & 1) != 0 && (addr_t)area->id == num)
|
||||||
|| (((mode & 2) != 0 && area->base <= num
|
|| (((mode & 2) != 0 && area->Base() <= num
|
||||||
&& area->base + area->size > num))))) {
|
&& area->Base() + area->Size() > num))))) {
|
||||||
dump_area_struct(area, mappings);
|
dump_area_struct(area, mappings);
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
@ -2870,8 +2871,8 @@ dump_area_list(int argc, char** argv)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
kprintf("%p %5lx %p\t%p %4lx\t%4d %s\n", area, area->id,
|
kprintf("%p %5lx %p\t%p %4lx\t%4d %s\n", area, area->id,
|
||||||
(void*)area->base, (void*)area->size, area->protection, area->wiring,
|
(void*)area->Base(), (void*)area->Size(), area->protection,
|
||||||
area->name);
|
area->wiring, area->name);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -2985,8 +2986,8 @@ vm_free_unused_boot_loader_range(addr_t start, addr_t size)
|
|||||||
|
|
||||||
for (VMAddressSpace::Iterator it = VMAddressSpace::Kernel()->GetIterator();
|
for (VMAddressSpace::Iterator it = VMAddressSpace::Kernel()->GetIterator();
|
||||||
VMArea* area = it.Next();) {
|
VMArea* area = it.Next();) {
|
||||||
addr_t areaStart = area->base;
|
addr_t areaStart = area->Base();
|
||||||
addr_t areaEnd = areaStart + (area->size - 1);
|
addr_t areaEnd = areaStart + (area->Size() - 1);
|
||||||
|
|
||||||
if (area->id == RESERVED_AREA_ID || areaEnd < start)
|
if (area->id == RESERVED_AREA_ID || areaEnd < start)
|
||||||
continue;
|
continue;
|
||||||
@ -3510,7 +3511,7 @@ vm_page_fault(addr_t address, addr_t faultAddress, bool isWrite, bool isUser,
|
|||||||
thread->name, thread->id, thread->team->name, thread->team->id,
|
thread->name, thread->id, thread->team->name, thread->team->id,
|
||||||
isWrite ? "write" : "read", address, faultAddress,
|
isWrite ? "write" : "read", address, faultAddress,
|
||||||
area ? area->name : "???",
|
area ? area->name : "???",
|
||||||
faultAddress - (area ? area->base : 0x0));
|
faultAddress - (area ? area->Base() : 0x0));
|
||||||
|
|
||||||
// We can print a stack trace of the userland thread here.
|
// We can print a stack trace of the userland thread here.
|
||||||
// TODO: The user_memcpy() below can cause a deadlock, if it causes a page
|
// TODO: The user_memcpy() below can cause a deadlock, if it causes a page
|
||||||
@ -3556,7 +3557,7 @@ vm_page_fault(addr_t address, addr_t faultAddress, bool isWrite, bool isUser,
|
|||||||
(addr_t)frame.return_address);
|
(addr_t)frame.return_address);
|
||||||
if (area) {
|
if (area) {
|
||||||
dprintf(" (%s + %#lx)", area->name,
|
dprintf(" (%s + %#lx)", area->name,
|
||||||
(addr_t)frame.return_address - area->base);
|
(addr_t)frame.return_address - area->Base());
|
||||||
}
|
}
|
||||||
dprintf("\n");
|
dprintf("\n");
|
||||||
|
|
||||||
@ -3899,7 +3900,7 @@ vm_soft_fault(VMAddressSpace* addressSpace, addr_t originalAddress,
|
|||||||
// At first, the top most cache from the area is investigated.
|
// At first, the top most cache from the area is investigated.
|
||||||
|
|
||||||
context.Prepare(vm_area_get_locked_cache(area),
|
context.Prepare(vm_area_get_locked_cache(area),
|
||||||
address - area->base + area->cache_offset);
|
address - area->Base() + area->cache_offset);
|
||||||
|
|
||||||
// See if this cache has a fault handler -- this will do all the work
|
// See if this cache has a fault handler -- this will do all the work
|
||||||
// for us.
|
// for us.
|
||||||
@ -4155,8 +4156,8 @@ fill_area_info(struct VMArea* area, area_info* info, size_t size)
|
|||||||
{
|
{
|
||||||
strlcpy(info->name, area->name, B_OS_NAME_LENGTH);
|
strlcpy(info->name, area->name, B_OS_NAME_LENGTH);
|
||||||
info->area = area->id;
|
info->area = area->id;
|
||||||
info->address = (void*)area->base;
|
info->address = (void*)area->Base();
|
||||||
info->size = area->size;
|
info->size = area->Size();
|
||||||
info->protection = area->protection;
|
info->protection = area->protection;
|
||||||
info->lock = B_FULL_LOCK;
|
info->lock = B_FULL_LOCK;
|
||||||
info->team = area->address_space->ID();
|
info->team = area->address_space->ID();
|
||||||
@ -4228,7 +4229,7 @@ vm_resize_area(area_id areaID, size_t newSize, bool kernel)
|
|||||||
// TODO: Enforce all restrictions (team, etc.)!
|
// TODO: Enforce all restrictions (team, etc.)!
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t oldSize = area->size;
|
size_t oldSize = area->Size();
|
||||||
if (newSize == oldSize)
|
if (newSize == oldSize)
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
@ -4243,15 +4244,15 @@ vm_resize_area(area_id areaID, size_t newSize, bool kernel)
|
|||||||
for (VMArea* current = cache->areas; current != NULL;
|
for (VMArea* current = cache->areas; current != NULL;
|
||||||
current = current->cache_next) {
|
current = current->cache_next) {
|
||||||
VMArea* next = current->address_space->NextArea(current);
|
VMArea* next = current->address_space->NextArea(current);
|
||||||
if (next != NULL && next->base <= (current->base + newSize)) {
|
if (next != NULL && next->Base() <= (current->Base() + newSize)) {
|
||||||
// If the area was created inside a reserved area, it can
|
// If the area was created inside a reserved area, it can
|
||||||
// also be resized in that area
|
// also be resized in that area
|
||||||
// TODO: if there is free space after the reserved area, it could
|
// TODO: if there is free space after the reserved area, it could
|
||||||
// be used as well...
|
// be used as well...
|
||||||
if (next->id == RESERVED_AREA_ID
|
if (next->id == RESERVED_AREA_ID
|
||||||
&& next->cache_offset <= current->base
|
&& next->cache_offset <= current->Base()
|
||||||
&& next->base - 1 + next->size
|
&& next->Base() - 1 + next->Size()
|
||||||
>= current->base - 1 + newSize)
|
>= current->Base() - 1 + newSize)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@ -4271,18 +4272,19 @@ vm_resize_area(area_id areaID, size_t newSize, bool kernel)
|
|||||||
for (VMArea* current = cache->areas; current != NULL;
|
for (VMArea* current = cache->areas; current != NULL;
|
||||||
current = current->cache_next) {
|
current = current->cache_next) {
|
||||||
VMArea* next = current->address_space->NextArea(current);
|
VMArea* next = current->address_space->NextArea(current);
|
||||||
if (next != NULL && next->base <= (current->base + newSize)) {
|
if (next != NULL && next->Base() <= (current->Base() + newSize)) {
|
||||||
if (next->id == RESERVED_AREA_ID
|
if (next->id == RESERVED_AREA_ID
|
||||||
&& next->cache_offset <= current->base
|
&& next->cache_offset <= current->Base()
|
||||||
&& next->base - 1 + next->size >= current->base - 1 + newSize) {
|
&& next->Base() - 1 + next->Size()
|
||||||
|
>= current->Base() - 1 + newSize) {
|
||||||
// resize reserved area
|
// resize reserved area
|
||||||
addr_t offset = current->base + newSize - next->base;
|
addr_t offset = current->Base() + newSize - next->Base();
|
||||||
if (next->size <= offset) {
|
if (next->Size() <= offset) {
|
||||||
next->address_space->RemoveArea(next);
|
next->address_space->RemoveArea(next);
|
||||||
free(next);
|
free(next);
|
||||||
} else {
|
} else {
|
||||||
next->size -= offset;
|
next->SetSize(next->Size() - offset);
|
||||||
next->base += offset;
|
next->SetBase(next->Base() + offset);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
panic("resize situation for area %p has changed although we "
|
panic("resize situation for area %p has changed although we "
|
||||||
@ -4292,12 +4294,12 @@ vm_resize_area(area_id areaID, size_t newSize, bool kernel)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
current->size = newSize;
|
current->SetSize(newSize);
|
||||||
|
|
||||||
// We also need to unmap all pages beyond the new size, if the area has
|
// We also need to unmap all pages beyond the new size, if the area has
|
||||||
// shrinked
|
// shrinked
|
||||||
if (newSize < oldSize) {
|
if (newSize < oldSize) {
|
||||||
vm_unmap_pages(current, current->base + newSize, oldSize - newSize,
|
vm_unmap_pages(current, current->Base() + newSize, oldSize - newSize,
|
||||||
false);
|
false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4310,7 +4312,7 @@ vm_resize_area(area_id areaID, size_t newSize, bool kernel)
|
|||||||
// This shouldn't really be possible, but hey, who knows
|
// This shouldn't really be possible, but hey, who knows
|
||||||
for (VMArea* current = cache->areas; current != NULL;
|
for (VMArea* current = cache->areas; current != NULL;
|
||||||
current = current->cache_next) {
|
current = current->cache_next) {
|
||||||
current->size = oldSize;
|
current->SetSize(oldSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
cache->Resize(cache->virtual_base + oldSize);
|
cache->Resize(cache->virtual_base + oldSize);
|
||||||
@ -4777,7 +4779,7 @@ _get_next_area_info(team_id team, int32* cookie, area_info* info, size_t size)
|
|||||||
if (area->id == RESERVED_AREA_ID)
|
if (area->id == RESERVED_AREA_ID)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (area->base > nextBase)
|
if (area->Base() > nextBase)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4787,7 +4789,7 @@ _get_next_area_info(team_id team, int32* cookie, area_info* info, size_t size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fill_area_info(area, info, size);
|
fill_area_info(area, info, size);
|
||||||
*cookie = (int32)(area->base);
|
*cookie = (int32)(area->Base());
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@ -5259,8 +5261,8 @@ _user_set_memory_protection(void* _address, size_t size, int protection)
|
|||||||
// protections are compatible with the file permissions. We don't have
|
// protections are compatible with the file permissions. We don't have
|
||||||
// a way to do that yet, though.
|
// a way to do that yet, though.
|
||||||
|
|
||||||
addr_t offset = currentAddress - area->base;
|
addr_t offset = currentAddress - area->Base();
|
||||||
size_t rangeSize = min_c(area->size - offset, sizeLeft);
|
size_t rangeSize = min_c(area->Size() - offset, sizeLeft);
|
||||||
|
|
||||||
currentAddress += rangeSize;
|
currentAddress += rangeSize;
|
||||||
sizeLeft -= rangeSize;
|
sizeLeft -= rangeSize;
|
||||||
@ -5276,8 +5278,8 @@ _user_set_memory_protection(void* _address, size_t size, int protection)
|
|||||||
if (area == NULL)
|
if (area == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
addr_t offset = currentAddress - area->base;
|
addr_t offset = currentAddress - area->Base();
|
||||||
size_t rangeSize = min_c(area->size - offset, sizeLeft);
|
size_t rangeSize = min_c(area->Size() - offset, sizeLeft);
|
||||||
|
|
||||||
currentAddress += rangeSize;
|
currentAddress += rangeSize;
|
||||||
sizeLeft -= rangeSize;
|
sizeLeft -= rangeSize;
|
||||||
@ -5288,7 +5290,7 @@ _user_set_memory_protection(void* _address, size_t size, int protection)
|
|||||||
|
|
||||||
// In the page protections we store only the three user protections,
|
// In the page protections we store only the three user protections,
|
||||||
// so we use 4 bits per page.
|
// so we use 4 bits per page.
|
||||||
uint32 bytes = (area->size / B_PAGE_SIZE + 1) / 2;
|
uint32 bytes = (area->Size() / B_PAGE_SIZE + 1) / 2;
|
||||||
area->page_protections = (uint8*)malloc(bytes);
|
area->page_protections = (uint8*)malloc(bytes);
|
||||||
if (area->page_protections == NULL)
|
if (area->page_protections == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
@ -5300,7 +5302,7 @@ _user_set_memory_protection(void* _address, size_t size, int protection)
|
|||||||
areaProtection | (areaProtection << 4), bytes);
|
areaProtection | (areaProtection << 4), bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (addr_t pageAddress = area->base + offset;
|
for (addr_t pageAddress = area->Base() + offset;
|
||||||
pageAddress < currentAddress; pageAddress += B_PAGE_SIZE) {
|
pageAddress < currentAddress; pageAddress += B_PAGE_SIZE) {
|
||||||
map->ops->lock(map);
|
map->ops->lock(map);
|
||||||
|
|
||||||
@ -5384,8 +5386,8 @@ _user_sync_memory(void* _address, size_t size, int flags)
|
|||||||
if (area == NULL)
|
if (area == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
uint32 offset = address - area->base;
|
uint32 offset = address - area->Base();
|
||||||
size_t rangeSize = min_c(area->size - offset, size);
|
size_t rangeSize = min_c(area->Size() - offset, size);
|
||||||
offset += area->cache_offset;
|
offset += area->cache_offset;
|
||||||
|
|
||||||
// lock the cache
|
// lock the cache
|
||||||
|
Loading…
Reference in New Issue
Block a user