diff --git a/crates/kernel/src/process.rs b/crates/kernel/src/process.rs index 99e1adf13..393199435 100644 --- a/crates/kernel/src/process.rs +++ b/crates/kernel/src/process.rs @@ -1,6 +1,6 @@ extern crate alloc; -use alloc::vec::Vec; +use alloc::{boxed::Box, vec::Vec}; use wasm_posix_shared::{Errno, WasmStat, WasmStatfs}; use crate::fd::FdTable; @@ -597,6 +597,17 @@ impl Process { /// - OFD 1 = stdout (CharDevice, O_WRONLY, host_handle=1) /// - OFD 2 = stderr (CharDevice, O_WRONLY, host_handle=2) pub fn new(pid: u32) -> Self { + *Self::new_boxed(pid) + } + + /// Heap-allocate a new process record for call sites that should avoid + /// keeping a `Process` value in their own stack frame. + #[inline(never)] + pub fn new_boxed(pid: u32) -> Box { + Box::new(Self::new_value(pid)) + } + + fn new_value(pid: u32) -> Self { use crate::ofd::FileType; use wasm_posix_shared::flags::{O_RDONLY, O_WRONLY}; diff --git a/crates/shared/src/lib.rs b/crates/shared/src/lib.rs index 544a50c24..0e61c2316 100644 --- a/crates/shared/src/lib.rs +++ b/crates/shared/src/lib.rs @@ -733,6 +733,27 @@ pub struct WasmStat { pub _pad: u32, } +impl Default for WasmStat { + fn default() -> Self { + Self { + st_dev: 0, + st_ino: 0, + st_mode: 0, + st_nlink: 0, + st_uid: 0, + st_gid: 0, + st_size: 0, + st_atime_sec: 0, + st_atime_nsec: 0, + st_mtime_sec: 0, + st_mtime_nsec: 0, + st_ctime_sec: 0, + st_ctime_nsec: 0, + _pad: 0, + } + } +} + /// Directory entry structure for the Wasm POSIX interface. /// /// Uses `repr(C)` for a stable, predictable memory layout that can be