-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathprocess.rs
More file actions
65 lines (60 loc) · 1.5 KB
/
Copy pathprocess.rs
File metadata and controls
65 lines (60 loc) · 1.5 KB
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
//! Process management syscalls
use crate::{
task::{exit_current_and_run_next, suspend_current_and_run_next, find_syscall_times},
timer::get_time_us,
};
#[repr(C)]
#[derive(Debug)]
pub struct TimeVal {
pub sec: usize,
pub usec: usize,
}
/// task exits and submit an exit code
pub fn sys_exit(exit_code: i32) -> ! {
trace!("[kernel] Application exited with code {}", exit_code);
exit_current_and_run_next();
panic!("Unreachable in sys_exit!");
}
/// current task gives up resources for other tasks
pub fn sys_yield() -> isize {
trace!("kernel: sys_yield");
suspend_current_and_run_next();
0
}
/// get time with second and microsecond
pub fn sys_get_time(ts: *mut TimeVal, _tz: usize) -> isize {
trace!("kernel: sys_get_time");
let us = get_time_us();
unsafe {
*ts = TimeVal {
sec: us / 1_000_000,
usec: us % 1_000_000,
};
}
0
}
/// get the information of syscall and do some change
pub fn sys_trace(_trace_request: usize, _id: usize, _data: usize) -> isize {
trace!("kernel: sys_trace");
match _trace_request {
0 => {
let ptr = _id as *const u8;
unsafe {
*ptr as isize
}
},
1 => {
let ptr = _id as *mut u8;
unsafe {
*ptr = (_data & 0xFF) as u8;
}
0
},
2 => {
find_syscall_times(_id) as isize
},
_ => {
-1
}
}
}