From 1a5b096b94496b11ebd46cdd8d4941f3e50af154 Mon Sep 17 00:00:00 2001 From: catfood Date: Thu, 29 Dec 2022 15:56:54 +0800 Subject: [PATCH] simple fix for fork --- kernel/exec.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kernel/exec.c b/kernel/exec.c index 9d6af5a..d519a55 100644 --- a/kernel/exec.c +++ b/kernel/exec.c @@ -11,6 +11,7 @@ #include "elf.h" #include "fs.h" //added by mingxuan 2019-5-19 #include "vfs.h" +#include "stdio.h" @@ -168,15 +169,17 @@ static u32 exec_load(u32 fd,const Elf32_Ehdr* Echo_Ehdr,const Elf32_Phdr Echo_Ph {//最后一个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 == 0x5) //101,R E {//.text exec_elfcpy(fd,Echo_Phdr[ph_num],PG_P | PG_USU | PG_RWR);//进程代码段 + // kprintf("text lin base: 0x%08x\n", Echo_Phdr[ph_num].p_vaddr); 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)//110,R {//.data exec_elfcpy(fd,Echo_Phdr[ph_num],PG_P | PG_USU | PG_RWW);//进程数据段 + // kprintf("data lin base: 0x%08x\n", Echo_Phdr[ph_num].p_vaddr); p_proc_current->task.memmap.data_lin_base = Echo_Phdr[ph_num].p_vaddr; p_proc_current->task.memmap.data_lin_limit = Echo_Phdr[ph_num].p_vaddr + Echo_Phdr[ph_num].p_memsz; } @@ -199,7 +202,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;//特权级修改为用户级