mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-18 12:16:31 +00:00
bugfix: exec执行的文件不存在时,自动退出进程。
This commit is contained in:
@ -11,12 +11,11 @@
|
||||
#include <common/stdio.h>
|
||||
#include <process/spinlock.h>
|
||||
#include <common/libELF/elf.h>
|
||||
#include <driver/video/video.h>
|
||||
|
||||
spinlock_t process_global_pid_write_lock; // 增加pid的写锁
|
||||
long process_global_pid = 1; // 系统中最大的pid
|
||||
|
||||
uint64_t pid_one_map_offset = 0x0000020000000000;
|
||||
int pid_one_map_count = 0;
|
||||
|
||||
extern void system_call(void);
|
||||
extern void kernel_thread_func(void);
|
||||
@ -133,8 +132,10 @@ struct vfs_file_t *process_open_exec_file(char *path)
|
||||
|
||||
dentry = vfs_path_walk(path, 0);
|
||||
|
||||
|
||||
if (dentry == NULL)
|
||||
return (void *)-ENOENT;
|
||||
|
||||
if (dentry->dir_inode->attribute == VFS_ATTR_DIR)
|
||||
return (void *)-ENOTDIR;
|
||||
|
||||
@ -162,9 +163,10 @@ static int process_load_elf_file(struct pt_regs *regs, char *path)
|
||||
{
|
||||
int retval = 0;
|
||||
struct vfs_file_t *filp = process_open_exec_file(path);
|
||||
if ((unsigned long)filp <= 0)
|
||||
|
||||
if ((long)filp <= 0 && (long)filp >=-255)
|
||||
{
|
||||
kdebug("(unsigned long)filp=%d", (long)filp);
|
||||
// kdebug("(long)filp=%ld", (long)filp);
|
||||
return (unsigned long)filp;
|
||||
}
|
||||
|
||||
@ -274,21 +276,11 @@ static int process_load_elf_file(struct pt_regs *regs, char *path)
|
||||
uint64_t pa = alloc_pages(ZONE_NORMAL, 1, PAGE_PGT_MAPPED)->addr_phys;
|
||||
|
||||
mm_map_proc_page_table((uint64_t)current_pcb->mm->pgd, true, current_pcb->mm->stack_start - PAGE_2M_SIZE, pa, PAGE_2M_SIZE, PAGE_USER_PAGE, true, true);
|
||||
// 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, 1 * PAGE_2M_SIZE, PAGE_USER_PAGE, true);
|
||||
|
||||
// 清空栈空间
|
||||
memset((void *)(current_pcb->mm->stack_start - PAGE_2M_SIZE), 0, PAGE_2M_SIZE);
|
||||
|
||||
// mm_map_proc_page_table((uint64_t)current_pcb->mm->pgd, true, current_pcb->mm->stack_start - PAGE_2M_SIZE * 2, alloc_pages(ZONE_NORMAL, 2, PAGE_PGT_MAPPED)->addr_phys, 2 * PAGE_2M_SIZE, PAGE_USER_PAGE, true);
|
||||
// // 清空栈空间
|
||||
// memset((void *)(current_pcb->mm->stack_start - 2 * PAGE_2M_SIZE), 0, 2 * PAGE_2M_SIZE);
|
||||
|
||||
// if (current_pcb->pid == 1 && pid_one_map_count < 2)
|
||||
// {
|
||||
// mm_map_proc_page_table((uint64_t)current_pcb->mm->pgd, true, pid_one_map_offset, alloc_pages(ZONE_NORMAL, 1, PAGE_PGT_MAPPED)->addr_phys, PAGE_2M_SIZE, PAGE_USER_PAGE, true);
|
||||
// memset(pid_one_map_offset, 0, PAGE_2M_SIZE);
|
||||
// pid_one_map_count++;
|
||||
// pid_one_map_offset += PAGE_2M_SIZE;
|
||||
// }
|
||||
|
||||
|
||||
load_elf_failed:;
|
||||
if (buf != NULL)
|
||||
@ -359,7 +351,7 @@ ul do_execve(struct pt_regs *regs, char *path, char *argv[], char *envp[])
|
||||
// 加载elf格式的可执行文件
|
||||
int tmp = process_load_elf_file(regs, path);
|
||||
if (tmp < 0)
|
||||
return tmp;
|
||||
goto exec_failed;
|
||||
|
||||
// 拷贝参数列表
|
||||
if (argv != NULL)
|
||||
@ -394,7 +386,7 @@ ul do_execve(struct pt_regs *regs, char *path, char *argv[], char *envp[])
|
||||
regs->rdi = argc;
|
||||
regs->rsi = (uint64_t)dst_argv;
|
||||
}
|
||||
// kdebug("execve ok");
|
||||
kdebug("execve ok");
|
||||
|
||||
regs->cs = USER_CS | 3;
|
||||
regs->ds = USER_DS | 3;
|
||||
@ -404,6 +396,9 @@ ul do_execve(struct pt_regs *regs, char *path, char *argv[], char *envp[])
|
||||
regs->es = 0;
|
||||
|
||||
return 0;
|
||||
|
||||
exec_failed:;
|
||||
process_do_exit(tmp);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -415,6 +410,7 @@ ul do_execve(struct pt_regs *regs, char *path, char *argv[], char *envp[])
|
||||
ul initial_kernel_thread(ul arg)
|
||||
{
|
||||
// kinfo("initial proc running...\targ:%#018lx", arg);
|
||||
|
||||
fat32_init();
|
||||
|
||||
struct pt_regs *regs;
|
||||
@ -463,7 +459,7 @@ void process_exit_notify()
|
||||
*/
|
||||
ul process_do_exit(ul code)
|
||||
{
|
||||
kinfo("process exiting..., code is %#018lx.", code);
|
||||
// kinfo("process exiting..., code is %ld.", (long)code);
|
||||
cli();
|
||||
struct process_control_block *pcb = current_pcb;
|
||||
|
||||
|
@ -38,7 +38,6 @@ void spin_init(spinlock_t *lock)
|
||||
*/
|
||||
void spin_lock(spinlock_t *lock)
|
||||
{
|
||||
preempt_disable();
|
||||
__asm__ __volatile__("1: \n\t"
|
||||
"lock decq %0 \n\t" // 尝试-1
|
||||
"jns 3f \n\t" // 加锁成功,跳转到步骤3
|
||||
@ -49,13 +48,14 @@ void spin_lock(spinlock_t *lock)
|
||||
"jmp 1b \n\t" // 尝试加锁
|
||||
"3:"
|
||||
: "=m"(lock->lock)::"memory");
|
||||
preempt_disable();
|
||||
}
|
||||
|
||||
void spin_unlock(spinlock_t *lock)
|
||||
{
|
||||
preempt_enable();
|
||||
__asm__ __volatile__("movq $1, %0 \n\t"
|
||||
: "=m"(lock->lock)::"memory");
|
||||
preempt_enable();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user