Initialize contexts, add getpid
This commit is contained in:
parent
3b8f396229
commit
5b9c821ff5
4 changed files with 37 additions and 8 deletions
|
@ -28,6 +28,8 @@ pub enum Call {
|
|||
Close = 6,
|
||||
/// Execute syscall
|
||||
Exec = 11,
|
||||
/// Get process ID
|
||||
GetPid = 20,
|
||||
}
|
||||
|
||||
/// Convert numbers to calls
|
||||
|
@ -41,6 +43,7 @@ impl Call {
|
|||
5 => Ok(Call::Open),
|
||||
6 => Ok(Call::Close),
|
||||
11 => Ok(Call::Exec),
|
||||
20 => Ok(Call::GetPid),
|
||||
_ => Err(Error::NoCall)
|
||||
}
|
||||
}
|
||||
|
@ -90,7 +93,8 @@ pub fn handle(a: usize, b: usize, c: usize, d: usize, e: usize, _f: usize) -> Re
|
|||
Call::Write => write(b, convert_slice(c as *const u8, d)?),
|
||||
Call::Open => open(convert_slice(b as *const u8, c)?, d),
|
||||
Call::Close => close(b),
|
||||
Call::Exec => exec(convert_slice(b as *const u8, c)?, convert_slice(d as *const [usize; 2], e)?)
|
||||
Call::Exec => exec(convert_slice(b as *const u8, c)?, convert_slice(d as *const [usize; 2], e)?),
|
||||
Call::GetPid => getpid(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
use arch::interrupt::halt;
|
||||
|
||||
use super::{convert_slice, Result};
|
||||
use context;
|
||||
|
||||
use super::{convert_slice, Error, Result};
|
||||
|
||||
pub fn exit(status: usize) -> ! {
|
||||
println!("Exit {}", status);
|
||||
|
@ -19,3 +21,12 @@ pub fn exec(path: &[u8], args: &[[usize; 2]]) -> Result<usize> {
|
|||
println!("");
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
pub fn getpid() -> Result<usize> {
|
||||
if let Some(context_lock) = context::contexts().current() {
|
||||
let context = context_lock.read();
|
||||
Ok(context.id)
|
||||
} else {
|
||||
Err(Error::NoProcess)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue