浏览代码

fix(execve): return error code instead of panicking when interpreter can't be found

greatbridf 7 月之前
父节点
当前提交
2c152fdca0
共有 2 个文件被更改,包括 17 次插入20 次删除
  1. 15 17
      src/kernel/syscall/procops.rs
  2. 2 3
      src/kernel/task/loader/elf.rs

+ 15 - 17
src/kernel/syscall/procops.rs

@@ -170,24 +170,22 @@ fn execve(exec: *const u8, argv: *const PtrT, envp: *const PtrT) -> KResult<Sysc
 
     // TODO: When `execve` is called by one of the threads in a process, the other threads
     //       should be terminated and `execve` is performed in the thread group leader.
-    if let Ok(load_info) = ProgramLoader::parse(dentry.clone())?.load(argv, envp) {
-        unsafe {
-            // SAFETY: We are doing execve, all other threads are terminated.
-            thread.process.mm_list.replace(Some(load_info.mm_list));
-        }
-        thread.files.on_exec();
-        thread.signal_list.clear_non_ignore();
-        thread.set_name(dentry.name().clone());
-
-        let mut trap_ctx = thread.trap_ctx.borrow();
-        trap_ctx.set_program_counter(load_info.entry_ip.addr());
-        trap_ctx.set_stack_pointer(load_info.sp.addr());
-        Ok(SyscallNoReturn)
-    } else {
-        // We can't hold any ownership when we call `kill_current`.
-        // ProcessList::kill_current(Signal::SIGSEGV);
-        todo!()
+    let load_info = ProgramLoader::parse(dentry.clone())?.load(argv, envp)?;
+
+    unsafe {
+        // SAFETY: We are doing execve, all other threads are terminated.
+        thread.process.mm_list.replace(Some(load_info.mm_list));
     }
+
+    thread.files.on_exec();
+    thread.signal_list.clear_non_ignore();
+    thread.set_name(dentry.name().clone());
+
+    let mut trap_ctx = thread.trap_ctx.borrow();
+    trap_ctx.set_program_counter(load_info.entry_ip.addr());
+    trap_ctx.set_stack_pointer(load_info.sp.addr());
+
+    Ok(SyscallNoReturn)
 }
 
 #[eonix_macros::define_syscall(SYS_EXIT)]

+ 2 - 3
src/kernel/task/loader/elf.rs

@@ -377,9 +377,8 @@ impl<E: ElfArch> Elf<E> {
 
         if let Some(ldso_path) = ldso_path {
             let fs_context = FsContext::global();
-            let ldso_file =
-                Dentry::open(fs_context, Path::new(ldso_path.as_bytes()).unwrap(), true).unwrap();
-            let ldso_elf = Elf::<E>::parse(ldso_file).unwrap();
+            let ldso_file = Dentry::open(fs_context, Path::new(ldso_path.as_bytes())?, true)?;
+            let ldso_elf = Elf::<E>::parse(ldso_file)?;
 
             let base = VAddr::from(E::LDSO_BASE_ADDR);