Added tests for and fixed freeArea. Note that this generated some more work to do.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@542 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
SubDir OBOS_TOP src kernel vm2 ;
|
||||
|
||||
C++FLAGS += -g ;
|
||||
CCFLAGS += -g ;
|
||||
|
||||
Server vmTest : area.C areaManager.C cacheManager.C page.C pageManager.C swapFileManager.C test.C vmInterface.C vpage.C ;
|
||||
|
||||
LinkSharedOSLibs vmTest : root be ;
|
||||
|
||||
@@ -79,14 +79,22 @@ status_t area::createArea(char *name, int pageCount,void **address, addressSpec
|
||||
|
||||
void area::freeArea(void)
|
||||
{
|
||||
printf ("area::freeArea: starting \n");
|
||||
|
||||
manager->lock();
|
||||
for (struct node *cur=vpages.rock;cur;cur=cur->next)
|
||||
vpages.dump();
|
||||
for (struct node *cur=vpages.rock;cur;)
|
||||
{
|
||||
printf ("area::freeArea: wasting a page: %x\n",cur);
|
||||
vpage *page=(vpage *)cur;
|
||||
page->flush();
|
||||
printf ("area::freeArea: flushed a page \n");
|
||||
cur=cur->next;
|
||||
delete page; // Probably need to add a destructor
|
||||
}
|
||||
printf ("area::freeArea: unlocking \n");
|
||||
manager->unlock();
|
||||
printf ("area::freeArea: ending \n");
|
||||
}
|
||||
|
||||
status_t area::getInfo(area_info *dest)
|
||||
|
||||
@@ -22,14 +22,14 @@ class list {
|
||||
//int count(void) {printf ("list::count: About to return %d\n",nodeCount);return nodeCount;}
|
||||
int count(void) {return nodeCount;}
|
||||
void *next(void) {nodeCount--;node *n=rock;if (rock) rock=rock->next;return n;}
|
||||
void remove(void *in)
|
||||
void remove(node *toNuke)
|
||||
{
|
||||
struct node *toNuke=(node *)in;
|
||||
for (struct node *cur=rock;cur;cur=cur->next)
|
||||
bool done=false;
|
||||
for (struct node *cur=rock;!done && cur->next;cur=cur->next)
|
||||
if (cur->next==toNuke)
|
||||
{
|
||||
cur->next=toNuke->next;
|
||||
cur=NULL; // To bust out of the loop...
|
||||
done=true;
|
||||
}
|
||||
}
|
||||
void dump(void)
|
||||
|
||||
@@ -36,3 +36,9 @@ vnode swapFileManager::findNode(void)
|
||||
tmp.valid=false;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void swapFileManager::freeVNode(vnode v)
|
||||
{
|
||||
printf ("swapFileManager::freeNode: Freeing a new node for you, Master\n");
|
||||
// Should put this one on the free list, someday
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ class swapFileManager {
|
||||
public:
|
||||
swapFileManager (void);
|
||||
vnode findNode(void); // Get an unused node
|
||||
void freeVNode(vnode); // Free a node
|
||||
void write_block(vnode node,void *loc,unsigned long size);
|
||||
void read_block(vnode node,void *loc,unsigned long size);
|
||||
private:
|
||||
|
||||
+24
-4
@@ -19,7 +19,8 @@ unsigned char readByte(unsigned int offset )
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
vm.createArea("Mine",2,(void **)(&addr));
|
||||
int area1,area2;
|
||||
area1=vm.createArea("Mine",2,(void **)(&addr));
|
||||
writeByte(0,99);
|
||||
readByte(0);
|
||||
printf ("\n\n\n\n\n");
|
||||
@@ -31,8 +32,8 @@ int main(int argc,char **argv)
|
||||
for (int i=0;i<8192;i++)
|
||||
if (i%256!=readByte(i))
|
||||
printf ("ERROR! Byte at offset %d does not match: expected: %d, found: %d\n",i,i%256,readByte(i));
|
||||
snooze(10000000);
|
||||
vm.createArea("Mine",2,(void **)(&addr));
|
||||
snooze(5000000);
|
||||
area2=vm.createArea("Mine2",2,(void **)(&addr));
|
||||
writeByte(0,99);
|
||||
readByte(0);
|
||||
printf ("\n\n\n\n\n");
|
||||
@@ -44,7 +45,26 @@ int main(int argc,char **argv)
|
||||
for (int i=0;i<8192;i++)
|
||||
if (i%256!=readByte(i))
|
||||
printf ("ERROR! Byte at offset %d does not match: expected: %d, found: %d\n",i,i%256,readByte(i));
|
||||
snooze(2000000);
|
||||
snooze(500000);
|
||||
printf ("Freeing area1\n");
|
||||
vm.freeArea(area1);
|
||||
printf ("Freeing area2\n");
|
||||
vm.freeArea(area2);
|
||||
printf ("Done Freeing area2\n");
|
||||
snooze(20000000);
|
||||
|
||||
printf ("Creating a new area\n");
|
||||
area1=vm.createArea("Mine",2,(void **)(&addr));
|
||||
writeByte(0,99);
|
||||
readByte(0);
|
||||
printf ("\n\n\n\n\n");
|
||||
writeByte(4097,99);
|
||||
readByte(4097);
|
||||
printf ("\n\n\n\n\n");
|
||||
for (int i=0;i<8192;i++)
|
||||
writeByte(i,i%256);
|
||||
for (int i=0;i<8192;i++)
|
||||
if (i%256!=readByte(i))
|
||||
printf ("ERROR! Byte at offset %d does not match: expected: %d, found: %d\n",i,i%256,readByte(i));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -76,9 +76,22 @@ int vmInterface::createArea(char *AreaName,int pageCount,void **address, address
|
||||
|
||||
void vmInterface::freeArea(int Area)
|
||||
{
|
||||
printf ("vmInterface::freeArea: begin\n");
|
||||
area *oldArea=getAM()->findArea(Area);
|
||||
getAM()->removeArea(oldArea);
|
||||
delete oldArea;
|
||||
printf ("vmInterface::freeArea: found area %x\n",oldArea);
|
||||
if (oldArea)
|
||||
{
|
||||
printf ("vmInterface::freeArea: removing area %x from linked list\n",oldArea);
|
||||
areaManager *foo=getAM();
|
||||
printf ("vmInterface::freeArea: areaManager = %x \n",foo);
|
||||
foo->removeArea(oldArea);
|
||||
printf ("vmInterface::freeArea: deleting area %x \n",oldArea);
|
||||
oldArea->freeArea();
|
||||
printf ("vmInterface::freeArea: freeArea complete \n");
|
||||
delete oldArea;
|
||||
}
|
||||
else
|
||||
printf ("vmInterface::freeArea: unable to find requested area\n");
|
||||
}
|
||||
|
||||
status_t vmInterface::getAreaInfo(int Area,area_info *dest)
|
||||
|
||||
@@ -39,6 +39,14 @@ vpage::vpage(unsigned long start,vnode backing, page *physMem,protectType prot,p
|
||||
physPage=physMem;
|
||||
}
|
||||
|
||||
vpage::~vpage(void)
|
||||
{
|
||||
if (physPage) // I doubt that this is always true. Probably need to check for sharing...
|
||||
pageMan.freePage(physPage);
|
||||
if (backingNode.fd)
|
||||
swapMan.freeVNode(backingNode);
|
||||
}
|
||||
|
||||
void vpage::setProtection(protectType prot)
|
||||
{
|
||||
protection=prot;
|
||||
|
||||
@@ -21,6 +21,7 @@ class vpage : public node
|
||||
// If we are read only, it is read only.
|
||||
// If we are read/write, both pages are copy on write
|
||||
vpage(unsigned long start,vnode backing, page *physMem,protectType prot,pageState state); // backing and/or physMem can be NULL/0.
|
||||
~vpage(void);
|
||||
void setProtection(protectType prot);
|
||||
protectType getProtection(void) {return protection;}
|
||||
void *getStartAddress(void) {return (void *)start_address;}
|
||||
|
||||
Reference in New Issue
Block a user