linux_api/
exit.rs

1use linux_syscall::Result as LinuxSyscallResult;
2
3use crate::errno::Errno;
4
5/// Exits the current thread, setting `val & 0xff` as the exit code.
6pub fn exit_raw(val: i32) -> Result<(), Errno> {
7    unsafe { linux_syscall::syscall!(linux_syscall::SYS_exit, val) }
8        .check()
9        .map_err(Errno::from)
10}
11
12/// Exits the current thread, setting `val` as the exit code.
13pub fn exit(val: i8) -> ! {
14    exit_raw(val.into()).unwrap();
15    unreachable!()
16}
17
18/// Exits the process, setting `val & 0xff` as the exit code.
19pub fn exit_group_raw(val: i32) -> Result<(), Errno> {
20    unsafe { linux_syscall::syscall!(linux_syscall::SYS_exit_group, val) }
21        .check()
22        .map_err(Errno::from)
23}
24
25/// Exits the current process, setting `val` as the exit code.
26pub fn exit_group(val: i8) -> ! {
27    exit_group_raw(val.into()).unwrap();
28    unreachable!()
29}