From b02f5ea47cb5316a0f9bcdcace1d452c26ad1202 Mon Sep 17 00:00:00 2001 From: fslongjin Date: Wed, 25 May 2022 14:37:06 +0800 Subject: [PATCH] =?UTF-8?q?bug=20fix:=20=E4=BF=AE=E5=A4=8D=E4=BA=86?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E8=BF=9B=E7=A8=8B=E6=97=B6=E6=9C=AA=E5=AF=B9?= =?UTF-8?q?=E5=86=85=E5=AD=98=E7=A9=BA=E9=97=B4=E6=B8=85=E9=9B=B6=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/process/process.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kernel/process/process.c b/kernel/process/process.c index e174aef1b..1f88c972d 100644 --- a/kernel/process/process.c +++ b/kernel/process/process.c @@ -365,7 +365,8 @@ static int process_load_elf_file(struct pt_regs *regs, char *path) return (unsigned long)filp; } - void *buf = kmalloc(sizeof(PAGE_4K_SIZE), 0); + void *buf = kmalloc(PAGE_4K_SIZE, 0); + memset(buf, 0, PAGE_4K_SIZE); uint64_t pos = 0; pos = filp->file_ops->lseek(filp, 0, SEEK_SET); retval = filp->file_ops->read(filp, (char *)buf, sizeof(Elf64_Ehdr), &pos); @@ -419,6 +420,7 @@ static int process_load_elf_file(struct pt_regs *regs, char *path) } Elf64_Phdr *phdr = buf; + // 将程序加载到内存中 for (int i = 0; i < ehdr.e_phnum; ++i, ++phdr) { // kdebug("phdr[%d] phdr->p_offset=%#018lx phdr->p_vaddr=%#018lx phdr->p_memsz=%ld phdr->p_filesz=%ld phdr->p_type=%d", i, phdr->p_offset, phdr->p_vaddr, phdr->p_memsz, phdr->p_filesz, phdr->p_type); @@ -439,6 +441,7 @@ static int process_load_elf_file(struct pt_regs *regs, char *path) if (!mm_check_mapped((uint64_t)current_pcb->mm->pgd, virt_base)) // 未映射,则新增物理页 { mm_map_proc_page_table((uint64_t)current_pcb->mm->pgd, true, virt_base, alloc_pages(ZONE_NORMAL, 1, PAGE_PGT_MAPPED)->addr_phys, PAGE_2M_SIZE, PAGE_USER_PAGE, true); + memset((void*)virt_base, 0, PAGE_2M_SIZE); } pos = filp->file_ops->lseek(filp, pos, SEEK_SET); int64_t val = 0; @@ -461,6 +464,8 @@ static int process_load_elf_file(struct pt_regs *regs, char *path) regs->rsp = current_pcb->mm->stack_start; regs->rbp = current_pcb->mm->stack_start; mm_map_proc_page_table((uint64_t)current_pcb->mm->pgd, true, current_pcb->mm->stack_start - PAGE_2M_SIZE, alloc_pages(ZONE_NORMAL, 1, PAGE_PGT_MAPPED)->addr_phys, PAGE_2M_SIZE, PAGE_USER_PAGE, true); + // 清空栈空间 + memset((void*)(current_pcb->mm->stack_start - PAGE_2M_SIZE), 0, PAGE_2M_SIZE); load_elf_failed:; if (buf != NULL)