mapp_struct is developed

master
forever-learner 2 years ago
parent 09608b155c
commit 2394428ba7

@ -104,8 +104,20 @@ struct task_struct {
struct desc_struct ldt[3]; struct desc_struct ldt[3];
/* tss for this task */ /* tss for this task */
struct tss_struct tss; struct tss_struct tss;
struct mmap_struct *mmap;
struct mmap_struct *mmap_tail;
}; };
struct mmap_struct
{
//映射区域以4096字节为单位 (endaddr-address)%4096=0 每个进程addr起始地址0x2000000 + n*0x1000
unsigned long address;
unsigned long endaddr;
int rw;//
int ps;//private or shared
struct mmap_struct *next;
int size;
};
/* /*
* INIT_TASK is used to set up the first task table, touch at * INIT_TASK is used to set up the first task table, touch at
* your own risk!. Base=0, limit=0x9ffff (=640kB) * your own risk!. Base=0, limit=0x9ffff (=640kB)
@ -131,6 +143,8 @@ struct task_struct {
_LDT(0),0x80000000, \ _LDT(0),0x80000000, \
{} \ {} \
}, \ }, \
/*mmap*/ NULL, \
/*mmap_tail*/ NULL,\
} }
extern struct task_struct *task[NR_TASKS]; extern struct task_struct *task[NR_TASKS];

@ -463,7 +463,7 @@ int sys_umask(int mask)
return (old); return (old);
} }
// rememeber to sync when munmap exit manual
long sys_mmap(void * start,size_t len,...)// int prot,int flags,int fd,off_t off long sys_mmap(void * start,size_t len,...)// int prot,int flags,int fd,off_t off
{ {
printk("start mmaping\n"); printk("start mmaping\n");
@ -481,6 +481,7 @@ long sys_mmap(void * start,size_t len,...)// int prot,int flags,int fd,off_t off
char *temp,*p1,*p2; char *temp,*p1,*p2;
void * buf=start; void * buf=start;
int tempprot=0; int tempprot=0;
//因为new.h和namei.c定义不一样要修改
if(prot &PROT_READ) tempprot |=4; if(prot &PROT_READ) tempprot |=4;
if(prot &PROT_EXEC) tempprot |=1; if(prot &PROT_EXEC) tempprot |=1;
if(prot &PROT_WRITE) tempprot |=2; if(prot &PROT_WRITE) tempprot |=2;
@ -504,53 +505,38 @@ long sys_mmap(void * start,size_t len,...)// int prot,int flags,int fd,off_t off
printk("error permission."); printk("error permission.");
return MAP_FAILED; return MAP_FAILED;
} }
//end of permission check
printk("end of permissions\n"); printk("end of permissions\n");
if(start<=current->brk || start>=current->start_stack-0x8000 || start==NULL) if(start<=current->brk || start>=current->start_stack-0x8000 || start==NULL)
{ {
if(!current->mmap_tail)
buf=0x2000000; buf=0x2000000;
} else
buf=current->mmap_tail->endaddr;
}
struct mmap_struct *mmap=(struct mmap_struct *)malloc(sizeof(struct mmap_struct));
mmap->address=buf;mmap->size=len;
mmap->endaddr=buf+(len + 0xfff)&0xfffff000;
mmap->rw=prot;mmap->ps=flags;
mmap->next=NULL;
if(!current->mmap)
{current->mmap=current->mapp_tail=mapp;}
else
current->mmap_tail->next=mapp;
printk("buf: %x\n",(unsigned long )buf); printk("buf: %x\n",(unsigned long )buf);
//read and put in
if (!(block = inode->i_zone[0])) if (!(block = inode->i_zone[0]))
return NULL; return NULL;
if (!(bh = bread(inode->i_dev,block))) if (!(bh = bread(inode->i_dev,block)))
return NULL; return NULL;
temp = (char *) bh->b_data; temp = (char *) bh->b_data;
/* int nr[4];
unsigned long page;
int i;
unsigned long address=current->start_code+(unsigned long)buf;
printk("start of page\n");
//this part comes from do_no_page as achievement of immediate loading of cs and ds
while(address<=current->start_code+len+(unsigned long)buf)
{
printk("address: %x\n",address);
address &= 0xfffff000;
if (!(page = get_free_page()))
return MAP_FAILED;
for (i=0 ; i<4 ; block++,i++)
nr[i] = bmap(inode,block);
bread_page(page,inode->i_dev,nr);
if (!put_page(page,address))
{
free_page(page);
return MAP_FAILED;
}
int k=0;char c=0;
while(k++<60){c=get_fs_byte(address-current->start_code);printk("%c",c);}
printk("\n");
address+=PAGE_SIZE;
k=0;
while(k++<60)printk("%c",(char*)(page+k));
printk("\n");
} */
printk("end of mmap\n"); printk("end of mmap\n");
p1=temp;p2=buf; p1=temp;p2=buf;
while(l--) while(l--)
put_fs_byte(*(p1++),p2++); put_fs_byte(*(p1++),p2++);
printk("%s\n",temp); printk("%s\n",temp);
return buf; return buf;
return MAP_FAILED;
} }
int sys_munmap() int sys_munmap()
{ {

Loading…
Cancel
Save