#include
#include
#include
#define MAXSIZE 10
/*
*
*/
struct region
{
int startAdress;
int offset;
int allocated;
};
typedef struct region* Region;
struct perProcessRegion
{
int type;
Region region;
int allocated;
};
typedef struct perProcessRegion* PerProcessRegion;
struct process
{
PerProcessRegion textArea;
PerProcessRegion dataArea;
PerProcessRegion stackArea;
int allocated;
};
typedef struct process* Process;
struct uarea
{
Process procees;
int allocated;
};
typedef struct uarea* Uarea;
Uarea u;
Uarea uareaTable[MAXSIZE];
Process processTable[MAXSIZE];
PerProcessRegion perProcessRegionTable[MAXSIZE];
Region regionTable[MAXSIZE];
void init();
void display();
Uarea allocateUare();
Process allocateProcess();
PerProcessRegion allocatePerProcessRegion(int);
Region allocateRegion(int);
void init()
{
int i;
for(i=0;i
uareaTable[i]= (Uarea) malloc(sizeof (struct uarea));
uareaTable[i]->allocated =0;
processTable[i]= (Process) malloc(sizeof (struct process));
processTable[i]->allocated =0;
perProcessRegionTable[i]= (PerProcessRegion) malloc(sizeof (struct perProcessRegion));
perProcessRegionTable[i]->allocated =0;
regionTable[i]= (Region) malloc(sizeof (struct region));
regionTable[i]->allocated =0;
u = uareaTable[0];
}
}
void display()
{
int i;
printf("\nUser Areas\n");
for(i=0;i
printf("%p\t %d\n",uareaTable[i]->procees,uareaTable[i]->allocated);
}
printf("\nProcess Table\n");
for(i=0;i
printf("%p \t%p \t%p \t%d\n",processTable[i]->textArea,processTable[i]->dataArea,processTable[i]->stackArea,processTable[i]->allocated);
}
printf("\nPer Process Region Table\n");
for(i=0;i
printf("%p \t%d \t %d\n",perProcessRegionTable[i]->region,perProcessRegionTable[i]->type,perProcessRegionTable[i]->allocated);
}
printf("\nRegion Table\n");
for(i=0;i
printf("%d \t %d \t %d\n",regionTable[i]->startAdress,regionTable[i]->offset,regionTable[i]->allocated);
}
}
Uarea allocateUarea()
{
int i;
for(i=0;i
if(uareaTable[i]->allocated==0)
break;
}
if(i==MAXSIZE)
{
printf("uarea Table FUll");
return NULL;
}
uareaTable[i]->procees=allocateProcess();
if(uareaTable[i]->procees==NULL)
return NULL;
uareaTable[i]->allocated=1;
return uareaTable[i];
}
Process allocateProcess()
{
int i;
for(i=0;i
if(processTable[i]->allocated==0)
break;
}
if(i==MAXSIZE)
{
printf("Process Table FUll");
return NULL;
}
processTable[i]->textArea= allocatePerProcessRegion(0);
processTable[i]->dataArea= allocatePerProcessRegion(1);
processTable[i]->stackArea= allocatePerProcessRegion(2);
if((processTable[i]->textArea==NULL)||(processTable[i]->dataArea==NULL)||(processTable[i]->stackArea==NULL))
return NULL;
processTable[i]->allocated=1;
return processTable[i];
}
PerProcessRegion allocatePerProcessRegion(int type)
{
int i;
for(i=0;i
if(perProcessRegionTable[i]->allocated==0)
break;
}
if(i==MAXSIZE)
{
printf("Per Process RegionTable FUll");
return NULL;
}
perProcessRegionTable[i]->region=allocateRegion(type);
if(perProcessRegionTable[i]->region==NULL)
return NULL;
perProcessRegionTable[i]->allocated =1;
return perProcessRegionTable[i];
}
Region allocateRegion(int type)
{
int i;
for(i=0;i
if(regionTable[i]->allocated==0)
break;
}
if(i==MAXSIZE)
{
printf("RegionTable FUll");
return NULL;
}
switch(type)
{
case 0:
regionTable[i]->startAdress=0;
regionTable[i]->offset=1024;
break;
case 1:
regionTable[i]->startAdress=1024;
regionTable[i]->offset=1024;
break;
case 2:
regionTable[i]->startAdress=2048;
regionTable[i]->offset=1024;
break;
}
regionTable[i]->allocated =1;
return regionTable[i];
}
int main(int argc, char** argv) {
init();
u=allocateUarea();
display();
return 0;
}
No comments:
Post a Comment