Skip to content

Commit

Permalink
Loader: Add wait function
Browse files Browse the repository at this point in the history
Waits until the given pid has exited. launch_title now returns the pid.

Shell will now wait until the subprocess has waited before prompting.
  • Loading branch information
roblabla committed Sep 23, 2019
1 parent d6fbfcb commit 605f3ea
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 44 deletions.
32 changes: 17 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion ipcdefs/loader.id
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
interface sunrise_libuser::ldr::ILoaderInterface is ldr:shel {
[0] launch_title(array<u8, 9> title_name, array<u8, 9> args);
[0] launch_title(array<u8, 9> title_name, array<u8, 9> args) -> u64 pid;
[1] wait(u64 pid) -> u32 exit_status;
}
50 changes: 35 additions & 15 deletions libuser/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ pub enum Error {
Kernel(KernelError, Backtrace),
/// Loader error.
Loader(LoaderError, Backtrace),
/// Process Manager error.
Pm(PmError, Backtrace),
/// Service Manager error.
Sm(SmError, Backtrace),
//Vi(ViError, Backtrace),
Expand Down Expand Up @@ -76,6 +78,7 @@ impl Error {
Module::Kernel => Error::Kernel(KernelError::from_description(description), Backtrace::new()),
Module::FileSystem => Error::FileSystem(FileSystemError(description), Backtrace::new()),
Module::Loader => Error::Loader(LoaderError(description), Backtrace::new()),
Module::Pm => Error::Pm(PmError(description), Backtrace::new()),
Module::Sm => Error::Sm(SmError(description), Backtrace::new()),
//Module::Vi => Error::Vi(ViError(description), Backtrace::new()),
Module::Libuser => Error::Libuser(LibuserError(description), Backtrace::new()),
Expand All @@ -94,6 +97,7 @@ impl Error {
Error::Kernel(err, ..) => err.description() << 9 | Module::Kernel.0,
Error::FileSystem(err, ..) => err.0 << 9 | Module::FileSystem.0,
Error::Loader(err, ..) => err.0 << 9 | Module::Loader.0,
Error::Pm(err, ..) => err.0 << 9 | Module::Pm.0,
Error::Sm(err, ..) => err.0 << 9 | Module::Sm.0,
//Error::Vi(err, ..) => err.0 << 9 | Module::Vi.0,
Error::Libuser(err, ..) => err.0 << 9 | Module::Libuser.0,
Expand All @@ -105,6 +109,22 @@ impl Error {
}
}

enum_with_val! {
#[derive(PartialEq, Eq, Clone, Copy)]
struct Module(u32) {
Kernel = 1,
FileSystem = 2,
Loader = 9,
Pm = 15,
Sm = 21,
Vi = 114,
Time = 116,
Hid = 202,
Libuser = 415,
Ahci = 416,
}
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// TODO: Better Display implementation for libuser::Error
Expand Down Expand Up @@ -190,21 +210,6 @@ impl From<FileSystemError> for Error {
}
}

enum_with_val! {
#[derive(PartialEq, Eq, Clone, Copy)]
struct Module(u32) {
Kernel = 1,
FileSystem = 2,
Loader = 9,
Sm = 21,
Vi = 114,
Time = 116,
Hid = 202,
Libuser = 415,
Ahci = 416,
}
}

enum_with_val! {
/// Internal libuser errors.
#[derive(PartialEq, Eq, Clone, Copy)]
Expand Down Expand Up @@ -329,6 +334,21 @@ impl From<LoaderError> for Error {
}
}

enum_with_val! {
/// PM Errors.
#[derive(PartialEq, Eq, Clone, Copy)]
pub struct PmError(u32) {
/// Pid not found
PidNotFound = 1,
}
}

impl From<PmError> for Error {
fn from(error: PmError) -> Self {
Error::Pm(error, Backtrace::new())
}
}

enum_with_val! {
/// HID driver errors.
#[derive(PartialEq, Eq, Clone, Copy)]
Expand Down
4 changes: 2 additions & 2 deletions libuser/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl<'a> HandleRef<'a> {
/// Panics if used from outside the context of a Future spawned on a libuser
/// future executor. Please make sure you only call this function from a
/// future spawned on a WaitableManager.
fn wait_async<'b>(self, queue: WorkQueue<'b>)-> impl core::future::Future<Output = Result<(), Error>> + Unpin +'b {
pub fn wait_async<'b>(self, queue: WorkQueue<'b>)-> impl core::future::Future<Output = Result<(), Error>> + Unpin +'b {
#[allow(missing_docs, clippy::missing_docs_in_private_items)]
struct MyFuture<'a> {
queue: crate::futures::WorkQueue<'a>,
Expand Down Expand Up @@ -638,5 +638,5 @@ impl Drop for MappedSharedMemory {
/// Each process in Horizon is given a unique, non-reusable PID. It may be used
/// to associate capabilities or resources to a particular process. For instance,
/// sm might associate a process' service access permissions to its pid.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct Pid(pub u64);
2 changes: 2 additions & 0 deletions loader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ sunrise-libutils = { path = "../libutils" }
log = "0.4"
xmas-elf = "0.7.0"
futures-preview = { version = "0.3.0-alpha.16", default-features = false, features = ["nightly", "alloc"] }
spin = "0.5.2"
core = { package = "core-futures-tls", version = "0.1.1" }

[dependencies.lazy_static]
features = ["spin_no_std"]
Expand Down
Loading

0 comments on commit 605f3ea

Please sign in to comment.