diff --git a/kernel/exec.c b/kernel/exec.c index c191b91..034f926 100644 --- a/kernel/exec.c +++ b/kernel/exec.c @@ -161,20 +161,21 @@ static u32 exec_load(u32 fd,const Elf32_Ehdr* Echo_Ehdr,const Elf32_Phdr Echo_Ph return -1; } - //我们还不能确定elf中一共能有几个program,但就目前我们查看过的elf文件中,只出现过两中program,一种.text(R-E)和一种.data(RW-) + // (This is bullshit)我们还不能确定elf中一共能有几个program,但就目前我们查看过的elf文件中,只出现过两中program,一种.text(R-E)和一种.data(RW-) + // 上面一句话导致了去年出现了诡异的错误,暂时只能说简单修复了一下,但是这个系统的权限就很混乱 for( ph_num=0; ph_nume_phnum ; ph_num++ ) { if( 0==Echo_Phdr[ph_num].p_memsz ) {//最后一个program break; } - if( Echo_Phdr[ph_num].p_flags == 0x5 || Echo_Phdr[ph_num].p_flags == 0x4) //101,只读 + if (Echo_Phdr[ph_num].p_flags & 0x1) // xx1,__E, executable seg must be code seg {//.text exec_elfcpy(fd,Echo_Phdr[ph_num],PG_P | PG_USU | PG_RWR);//进程代码段 p_proc_current->task.memmap.text_lin_base = Echo_Phdr[ph_num].p_vaddr; p_proc_current->task.memmap.text_lin_limit = Echo_Phdr[ph_num].p_vaddr + Echo_Phdr[ph_num].p_memsz; } - else if(Echo_Phdr[ph_num].p_flags == 0x6)//110,读写 + else if (Echo_Phdr[ph_num].p_flags & 0x4) // 1xx,R__, treat all readable but not executable segs as data seg, though some may be RW and some RO {//.data exec_elfcpy(fd,Echo_Phdr[ph_num],PG_P | PG_USU | PG_RWW);//进程数据段 p_proc_current->task.memmap.data_lin_base = Echo_Phdr[ph_num].p_vaddr; @@ -199,7 +200,7 @@ static int exec_pcb_init(char* path) char* p_regs; //point to registers in the new kernel stack, added by xw, 17/12/11 //名称 状态 特权级 寄存器 - strcpy(p_proc_current->task.p_name, path); //名称 + strncpy(p_proc_current->task.p_name, path, sizeof(p_proc_current->task.p_name) - 1); // 名称 p_proc_current->task.stat = READY; //状态 p_proc_current->task.ldts[0].attr1 = DA_C | PRIVILEGE_USER << 5;//特权级修改为用户级 p_proc_current->task.ldts[1].attr1 = DA_DRW | PRIVILEGE_USER << 5;//特权级修改为用户级