1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
mod useradd;
mod showgif;
mod pwd;
mod cd;
mod test_threads;
mod test_divide_by_zero;
mod test_page_fault;
mod connect;
mod ps;
mod kill;
mod help;
mod exit;
use sunrise_libuser::error::Error;
use sunrise_libuser::twili::IPipeProxy;
use lazy_static::lazy_static;
use alloc::collections::BTreeMap;
use alloc::boxed::Box;
use alloc::vec::Vec;
use alloc::string::String;
use alloc::sync::Arc;
use spin::Once;
type SubcommandFn = fn(IPipeProxy, IPipeProxy, IPipeProxy, Vec<String>) -> Result<(), Error>;
lazy_static! {
pub static ref SUBCOMMANDS: BTreeMap<&'static str, (SubcommandFn, &'static str)> = {
let mut subcommands = BTreeMap::new();
subcommands.insert("exit", (exit::main as _, exit::HELP));
subcommands.insert("useradd", (useradd::main as _, useradd::HELP));
subcommands.insert("showgif", (showgif::main as _, showgif::HELP));
subcommands.insert("pwd", (pwd::main as _, pwd::HELP));
subcommands.insert("cd", (cd::main as _, cd::HELP));
subcommands.insert("test_threads", (test_threads::main as _, test_threads::HELP));
subcommands.insert("test_divide_by_zero", (test_divide_by_zero::main as _, test_divide_by_zero::HELP));
subcommands.insert("test_page_fault", (test_page_fault::main as _, test_page_fault::HELP));
subcommands.insert("connect", (connect::main as _, connect::HELP));
subcommands.insert("ps", (ps::main as _, ps::HELP));
subcommands.insert("kill", (kill::main as _, kill::HELP));
subcommands.insert("help", (help::main as _, help::HELP));
subcommands
};
}
pub struct RunArgs {
pub stdin: IPipeProxy,
pub stdout: IPipeProxy,
pub stderr: IPipeProxy,
pub args: Vec<String>,
pub ret: Arc<Once<Result<(), Error>>>,
pub f: fn(IPipeProxy, IPipeProxy, IPipeProxy, Vec<String>) -> Result<(), Error>
}
pub fn run(arg: usize) {
let args: Box<RunArgs> = unsafe { Box::from_raw(arg as *mut RunArgs) };
let RunArgs {
stdin, stdout, stderr, args, ret, f
} = *args;
ret.call_once(move || f(stdin, stdout, stderr, args));
}