haiku/src/kernel/vm2/areaManager.C
Michael Phipps 72515139f7 Updates to make creating areas and accessing bytes work. Lots of debugging
printfs, etc in here. But some bug fixes and better code.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@426 a95241bf-73f2-0310-859d-f6bbb57e9c96
2002-07-25 01:27:00 +00:00

121 lines
2.4 KiB
C

#include "areaManager.h"
areaManager::areaManager(void)
{
team=0; // should be proc_get_current_proc_id()
myLock=create_sem(1,"Area Manager Semaphore"); // Should have team name in it.
}
unsigned long areaManager::getNextAddress(int pages, unsigned long start)
{
unsigned long end=start+(pages*PAGE_SIZE)-1;
for (struct node *cur=areas.rock;cur;cur=cur->next)
{
if (cur)
{
area *myArea=(area *)cur;
if (!myArea->couldAdd(start,end))
{ // if we don't work, there must be an overlap, so go to the end of this area.
start=myArea->getEndAddress();
end=start+(pages*PAGE_SIZE)-1;
}
}
}
return start;
}
area *areaManager::findArea(char *address)
{
for (struct node *cur=areas.rock;cur;cur=cur->next)
{
area *myArea=(area *)cur;
if (myArea->nameMatch(address))
return myArea;
}
return NULL;
}
area *areaManager::findArea(void *address)
{
for (struct node *cur=areas.rock;cur;cur=cur->next)
{
area *myArea=(area *)cur;
printf ("Looking for %d\n",address);
if (myArea->contains(address))
return myArea;
}
printf ("findArea is giving up\n");
return NULL;
}
area *areaManager::findArea(area_id id)
{
for (struct node *cur=areas.rock;cur;cur=cur->next)
{
area *myArea=(area *)cur;
if (myArea->getAreaID()==id)
return myArea;
}
return NULL;
}
bool areaManager::fault(void *fault_address, bool writeError) // true = OK, false = panic.
{
area *myArea;
if (myArea=findArea(fault_address))
return myArea->fault(fault_address,writeError);
else
return false;
}
char areaManager::getByte(unsigned long address)
{
area *myArea;
if (myArea=findArea((void *)address))
return myArea->getByte(address);
else
return 0;
}
int areaManager::getInt(unsigned long address)
{
area *myArea;
if (myArea=findArea((void *)address))
return myArea->getInt(address);
else
return 0;
}
void areaManager::setByte(unsigned long offset,char value)
{
area *myArea;
if (myArea=findArea((void *)offset))
myArea->setByte(offset,value);
}
void areaManager::setInt(unsigned long offset,int value)
{
area *myArea;
if (myArea=findArea((void *)offset))
myArea->setInt(offset,value);
}
void areaManager::pager(int desperation)
{
for (struct node *cur=areas.rock;cur;cur=cur->next)
{
area *myArea=(area *)cur;
myArea->pager(desperation);
}
}
void areaManager::saver(void)
{
for (struct node *cur=areas.rock;cur;cur=cur->next)
{
area *myArea=(area *)cur;
myArea->saver();
}
}