final version of munmap

master
forever-learner 2 years ago
parent 0e544a13f5
commit a0c6239d1e

@ -15,7 +15,7 @@
int sys_pause(void);
int sys_close(int fd);
extern int sys_munmap(void * start ,size_t size);
void release(struct task_struct * p)
{
int i;
@ -102,7 +102,15 @@ static void tell_father(int pid)
int do_exit(long code)
{
int i;
struct mmap_struct *temp=current->mmap;
while(temp)
{
printk("%x\n.",temp->address);
printk("%x\n.",temp->endaddr);
printk("%d\n.",temp->next);
sys_munmap((void *)temp->address,temp->size);
temp=temp->next;
}
free_page_tables(get_base(current->ldt[1]),get_limit(0x0f));
free_page_tables(get_base(current->ldt[2]),get_limit(0x17));
for (i=0 ; i<NR_TASKS ; i++)

@ -625,7 +625,7 @@ long sys_mmap(void * start,size_t len,...)// int prot,int flags,int fd,off_t off
*(unsigned long *)from_page= tpage | 7;
mem_map[(tpage-LOW_MEM)>>12]++;
}
*(unsigned long *)from_page &= (prot&PROT_WRITE); //分配读写权限
*(unsigned long *)from_page &= (prot&PROT_WRITE)?0xffffffff:0xfffffffd; //分配读写权限
if(flags & MAP_SHARED)
{
@ -709,9 +709,9 @@ int sys_munmap(void * start ,size_t size)
if(!pre)
{
if(current->mmap_tail==current->mmap)current->mmap_tail=NULL;
current->mmap==current->mmap->next;
current->mmap=current->mmap->next;
}
if(temp->next=NULL)
else if(temp->next=NULL)
{
current->mmap_tail=pre;
pre->next=NULL;
@ -726,12 +726,13 @@ int sys_munmap(void * start ,size_t size)
unsigned long phys_addr;
unsigned long tpage;
unsigned long address=temp->address;
printk("%lx\n",address);
if(!(temp->ps & MAP_SHARED))
goto mytag;
//若为共享,执行下面的代码
while (address < temp ->endaddr)
{
printk("addr: %lx\n",address);
//printk("addr: %lx\n",address);
from_page = ((address>>20) & 0xffc);
from_page += ((current->start_code>>20) & 0xffc);//页目录
from=*(unsigned long *)from_page; //页表项
@ -741,7 +742,8 @@ int sys_munmap(void * start ,size_t size)
//printk("addr: %lx",*(unsigned long *)from_page);
if(!(*(unsigned long *)from_page & 1))
{
printk("error of deleting page.");
printk("error of deleting page at %x.\n",*(unsigned long *)from_page);
printk("current address:%x\n",address);
return -1;
}
if(temp->ps & MAP_SHARED)
@ -778,8 +780,10 @@ int sys_munmap(void * start ,size_t size)
}
mytag:
//取消物理页写权限
address=temp->address;
while (address < temp ->endaddr)
{
//printk("%lx\n",address);
from_page = ((address>>20) & 0xffc);
from_page += ((current->start_code>>20) & 0xffc);//页目录
from=*(unsigned long *)from_page; //页表项
@ -789,7 +793,8 @@ mytag:
//printk("addr: %lx",*(unsigned long *)from_page);
if(!(*(unsigned long *)from_page & 1))
{
printk("error of deleting page.");
printk("error of deleting page at %x.\n",*(unsigned long *)from_page);
printk("current address:%x\n",address);
return -1;
}
else{

Loading…
Cancel
Save