-
Notifications
You must be signed in to change notification settings - Fork 960
Expand file tree
/
Copy pathproc_raise.rs
More file actions
46 lines (40 loc) · 1.36 KB
/
proc_raise.rs
File metadata and controls
46 lines (40 loc) · 1.36 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
use super::*;
use crate::syscalls::*;
/// ### `proc_raise()`
/// Send a signal to the process of the calling thread.
/// Note: This is similar to `raise` in POSIX.
/// Inputs:
/// - `Signal`
/// Signal to be raised for this process
#[instrument(level = "trace", skip_all, fields(sig), ret)]
pub fn proc_raise(mut ctx: FunctionEnvMut<'_, WasiEnv>, sig: Signal) -> Result<Errno, WasiError> {
let env = ctx.data();
env.process.signal_process(sig);
WasiEnv::do_pending_operations(&mut ctx)?;
Ok(Errno::Success)
}
/// ### `proc_raise_interval()`
/// Send a signal to the process of the calling thread with an interval.
/// Note: This is similar to `setitimer` in POSIX.
/// Inputs:
/// - `sig`: Signal to be raised for this process
/// - `interval`: The time interval in milliseconds
/// - `repeat`: Whether repeat the `sig` with `interval` or not
pub fn proc_raise_interval(
mut ctx: FunctionEnvMut<'_, WasiEnv>,
sig: Signal,
interval: Timestamp,
repeat: Bool,
) -> Result<Errno, WasiError> {
let env = ctx.data();
let interval = match interval {
0 => None,
a => Some(Duration::from_millis(a)),
};
let repeat = matches!(repeat, Bool::True);
let _ = env
.process
.signal_interval(sig, interval, if repeat { interval } else { None });
WasiEnv::do_pending_operations(&mut ctx)?;
Ok(Errno::Success)
}