From 0e5210cb4dca298ba4bea5bf7308551506f34ac6 Mon Sep 17 00:00:00 2001 From: R Aadarsh Date: Sun, 24 May 2026 14:19:13 +0530 Subject: [PATCH] Make close operation work --- Cargo.lock | 110 ++++++++++++------------------- Cargo.toml | 3 +- redox-ioctl/Cargo.toml | 3 + src/header/spawn/cbindgen.toml | 4 +- src/header/spawn/file_actions.rs | 33 ++++------ src/platform/redox/mod.rs | 32 ++++++++- 6 files changed, 92 insertions(+), 93 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aa6e71ad98..a9ce26fefa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,15 +16,15 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" [[package]] name = "base64ct" -version = "1.8.0" +version = "1.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55248b47b0caf0546f7988906588779981c43bb1bc9d0c44087278f80cdb44ba" +checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06" [[package]] name = "bcrypt-pbkdf" @@ -39,9 +39,9 @@ dependencies = [ [[package]] name = "bitflags" -version = "2.10.0" +version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" +checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" [[package]] name = "blake2" @@ -102,9 +102,9 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] name = "chrono" -version = "0.4.42" +version = "0.4.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2" +checksum = "c673075a2e0e5f4a1dde27ce9dee1ea4558c7ffe648f576438a20ca1d2acc4b0" dependencies = [ "num-traits", ] @@ -181,9 +181,9 @@ dependencies = [ [[package]] name = "drm-sys" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bafb66c8dbc944d69e15cfcc661df7e703beffbaec8bd63151368b06c5f9858c" +checksum = "ecc8e1361066d91f5ffccff060a3c3be9c3ecde15be2959c1937595f7a82a9f8" dependencies = [ "libc", "linux-raw-sys", @@ -244,15 +244,15 @@ version = "0.1.0" [[package]] name = "libc" -version = "0.2.177" +version = "0.2.186" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" +checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" [[package]] name = "libm" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" +checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" [[package]] name = "libredox" @@ -268,9 +268,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.6.5" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a385b1be4e5c3e362ad2ffa73c392e53f031eaa5b7d648e64cd87f27f6063d7" +checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" [[package]] name = "lock_api" @@ -299,9 +299,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.6" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" [[package]] name = "num-traits" @@ -374,29 +374,29 @@ checksum = "66df580334caab2f744839ab1be85493d7ec731a92d6cf928008ab0b212bf3bc" [[package]] name = "proc-macro2" -version = "1.0.103" +version = "1.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.42" +version = "1.0.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" dependencies = [ "proc-macro2", ] [[package]] name = "rand" -version = "0.10.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc266eb313df6c5c09c1c7b1fbe2510961e5bcd3add930c1e31f7ed9da0feff8" +checksum = "d2e8e8bcc7961af1fdac401278c6a831614941f6164ee3bf4ce61b7edb162207" dependencies = [ - "rand_core 0.10.0", + "rand_core 0.10.1", ] [[package]] @@ -407,19 +407,19 @@ checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" [[package]] name = "rand_core" -version = "0.10.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c8d0fd677905edcbeedbf2edb6494d676f0e98d54d5cf9bda0b061cb8fb8aba" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" [[package]] name = "rand_jitter" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a02dd27aa28665e46e60168c8f355240c73b8a344d2557a92318849441ffda33" +checksum = "3fdcd80e68f0a8f9ca5ec7cfd02fd5fbb8fbe6ef4e9b90ea2f48bb929b74f88e" dependencies = [ "libc", - "rand_core 0.10.0", - "winapi", + "rand_core 0.10.1", + "windows-sys", ] [[package]] @@ -428,7 +428,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60aa6af80be32871323012e02e6e65f8a7cc7890931ae421d217ad8fe0df2ccf" dependencies = [ - "rand_core 0.10.0", + "rand_core 0.10.1", ] [[package]] @@ -461,9 +461,8 @@ dependencies = [ [[package]] name = "redox_event" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c07d0d6d291e3a951bd847b1cd4af32fc6243d64116cf7702838c02797688b7" +version = "0.4.6" +source = "git+https://gitlab.redox-os.org/EuclidDivisionLemma/event?branch=spawn#17c4e4c5f0aaf83a2a8057b78ad75364e1f2242a" dependencies = [ "bitflags", "libredox", @@ -473,8 +472,7 @@ dependencies = [ [[package]] name = "redox_syscall" version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c7591fa2c6b601dfcfe5f043f65a1c39fcdf50efefcd7f1572e538c1f4b398d" +source = "git+https://gitlab.redox-os.org/EuclidDivisionLemma/syscall/?branch=spawn#5ae449893d6bc3731ad122d8320372cfbe83c245" dependencies = [ "bitflags", ] @@ -602,9 +600,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "siphasher" -version = "1.0.1" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" +checksum = "8ee5873ec9cce0195efcb7a4e9507a04cd49aec9c83d0389df45b1ef7ba2e649" [[package]] name = "spin" @@ -623,9 +621,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.110" +version = "2.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a99801b5bd34ede4cf3fc688c5919368fea4e4814a4664359503e6015b280aea" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" dependencies = [ "proc-macro2", "quote", @@ -634,15 +632,15 @@ dependencies = [ [[package]] name = "typenum" -version = "1.19.0" +version = "1.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" +checksum = "40ce102ab67701b8526c123c1bab5cbe42d7040ccfd0f64af1a385808d2f43de" [[package]] name = "unicode-ident" -version = "1.0.22" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" [[package]] name = "unicode-width" @@ -656,28 +654,6 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - [[package]] name = "windows-sys" version = "0.59.0" diff --git a/Cargo.toml b/Cargo.toml index 24dbc8c66b..8c7a9595d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -121,7 +121,7 @@ sc = "0.2.7" redox_syscall.workspace = true redox-rt = { path = "redox-rt" } redox-path.workspace = true -redox_event = { version = "0.4.7", default-features = false, features = [ +redox_event = { git = "https://gitlab.redox-os.org/EuclidDivisionLemma/event", branch = "spawn", default-features = false, features = [ "redox_syscall", ] } ioslice.workspace = true @@ -145,3 +145,4 @@ panic = "abort" [patch.crates-io] cc-11 = { git = "https://github.com/tea/cc-rs", branch = "riscv-abi-arch-fix", package = "cc" } +redox_syscall = {git = "https://gitlab.redox-os.org/EuclidDivisionLemma/syscall/", branch = "spawn"} diff --git a/redox-ioctl/Cargo.toml b/redox-ioctl/Cargo.toml index 0bf8029cab..8a9c484bad 100644 --- a/redox-ioctl/Cargo.toml +++ b/redox-ioctl/Cargo.toml @@ -10,4 +10,7 @@ description = "Ioctl definitions and (de)serialization for Redox" drm-sys = "0.8.0" redox_syscall = "0.8" +[patch.crates-io] +redox_syscall = {git = "https://gitlab.redox-os.org/EuclidDivisionLemma/syscall/", branch = "spawn"} + [features] diff --git a/src/header/spawn/cbindgen.toml b/src/header/spawn/cbindgen.toml index 0ebe663c2b..fdf8013426 100644 --- a/src/header/spawn/cbindgen.toml +++ b/src/header/spawn/cbindgen.toml @@ -1,4 +1,4 @@ -sys_includes = ["sched.h", "bits/sigset-t.h"] +sys_includes = ["sched.h", "bits/sigset-t.h", "bits/mode-t.h"] include_guard = "_RELIBC_SPAWN_H" language = "C" cpp_compat = true @@ -7,4 +7,4 @@ cpp_compat = true prefix_with_name = true [export.rename] -"sched_param" = "struct sched_param" \ No newline at end of file +"sched_param" = "struct sched_param" diff --git a/src/header/spawn/file_actions.rs b/src/header/spawn/file_actions.rs index f8a3add872..ca2b7322ad 100644 --- a/src/header/spawn/file_actions.rs +++ b/src/header/spawn/file_actions.rs @@ -6,7 +6,7 @@ use core::{ use crate::{ error::{Errno, Result}, header::{ - errno::{EBADF, EINVAL, ENOMEM}, + errno::{EBADF, ENOMEM}, stdlib::{free, malloc}, }, platform::types::{c_void, mode_t}, @@ -19,6 +19,7 @@ const FCHDIR: c_char = 4; const DUP2: c_char = 5; #[repr(C)] +#[derive(Debug, Clone, Copy)] pub enum Operation { Open { fd: c_int, @@ -32,16 +33,18 @@ pub enum Operation { Dup2(c_int, c_int), } +#[derive(Debug, Clone, Copy)] pub struct OperationNode { pub operation: Operation, next: *const OperationNode, } #[repr(C)] +#[derive(Debug)] pub struct posix_spawn_file_actions_t { len: usize, - head: *const OperationNode, - tail: *mut OperationNode, + pub head: *const OperationNode, + pub tail: *mut OperationNode, } pub struct FileActionsIter<'a> { @@ -72,11 +75,11 @@ impl<'a> IntoIterator for &'a posix_spawn_file_actions_t { fn copy_op(file_actions: &mut posix_spawn_file_actions_t, op: Operation) -> Result<()> { let new = unsafe { malloc(size_of::()) }; - let new_ref = unsafe { - (new as *const OperationNode) - .as_ref() - .ok_or(Errno(ENOMEM))? - }; + + let new_ref = unsafe { (new as *mut OperationNode).as_mut().ok_or(Errno(ENOMEM))? }; + + (*new_ref).next = null(); + (*new_ref).operation = op; if (*file_actions).head.is_null() && (*file_actions).tail.is_null() { (*file_actions).head = new as *const OperationNode; @@ -94,13 +97,8 @@ fn copy_op(file_actions: &mut posix_spawn_file_actions_t, op: Operation) -> Resu #[unsafe(no_mangle)] pub unsafe extern "C" fn posix_spawn_file_actions_init( - file_actions: *mut posix_spawn_file_actions_t, + file_actions: &mut posix_spawn_file_actions_t, ) -> c_int { - let file_actions = match unsafe { file_actions.as_mut().ok_or(Errno(EINVAL)) } { - Ok(v) => v, - Err(_) => return EINVAL, - }; - (*file_actions).head = null(); (*file_actions).tail = null_mut(); (*file_actions).len = 0; @@ -110,13 +108,8 @@ pub unsafe extern "C" fn posix_spawn_file_actions_init( #[unsafe(no_mangle)] pub unsafe extern "C" fn posix_spawn_file_actions_destroy( - file_actions: *mut posix_spawn_file_actions_t, + file_actions: &mut posix_spawn_file_actions_t, ) -> c_int { - let file_actions = match unsafe { file_actions.as_mut().ok_or(Errno(EINVAL)) } { - Ok(v) => v, - Err(_) => return EINVAL, - }; - if (*file_actions).head.is_null() { assert!((*file_actions).tail.is_null() && (*file_actions).len == 0); return 0; diff --git a/src/platform/redox/mod.rs b/src/platform/redox/mod.rs index fb36b17447..084fa231e9 100644 --- a/src/platform/redox/mod.rs +++ b/src/platform/redox/mod.rs @@ -1215,9 +1215,10 @@ impl Pal for Sys { .dup(b"filetable")? .dup(b"copy")?; - let new_file_table = child.thr_fd.dup(b"current-filetable")?; - - new_file_table.write(&file_table.as_raw_fd().to_ne_bytes())?; + { + let new_file_table = child.thr_fd.dup(b"current-filetable")?; + new_file_table.write(&file_table.as_raw_fd().to_ne_bytes())?; + } let extra_info = redox_rt::proc::ExtraInfo { cwd: Some(cwd.as_bytes()), @@ -1258,6 +1259,31 @@ impl Pal for Sys { envp = unsafe { envp.add(1) }; } + let new_file_table = child.thr_fd.dup(b"filetable")?; + + if let Some(fac) = fac { + for action in fac { + match action.operation { + crate::header::spawn::Operation::Open { + fd, + path, + flag, + mode, + } => todo!(), + crate::header::spawn::Operation::Close(fd) => { + new_file_table.call_wo( + &(fd as usize).to_ne_bytes(), + syscall::CallFlags::empty(), + &[syscall::flag::FileTableVerb::Close as u64], + )?; + } + crate::header::spawn::Operation::Chdir(_) => todo!(), + crate::header::spawn::Operation::FChdir(_) => todo!(), + crate::header::spawn::Operation::Dup2(_, _) => todo!(), + } + } + } + if let Some(redox_rt::proc::FexecResult::Interp { path: interp_path, interp_override,