1// devela::sys::os::linux::fns::syscalls::shared_docs
2//
3//! Defines constants for shared documentation for linux syscalls.
4//
56crate::CONST! {
7pub(super) SYS_EXIT = r#"Performs an `exit` syscall.
89Terminate the process with an exit status.
1011# Info
12- <https://www.man7.org/linux/man-pages/man2/exit.2.html>
1314# Example
15```
16use devela::linux_sys_exit;
1718# #[cfg(target_os = "linux")]
19unsafe { linux_sys_exit(0) };
20```
2122# Safety
23TODO
24"#;
2526pub(super) SYS_GETPID = r#"Performs a `getpid` syscall.
2728Get process identification.
2930# Info
31- <https://www.man7.org/linux/man-pages/man2/getpid.2.html>
3233# Example
34```no_run
35use devela::linux_sys_getpid;
3637# #[cfg(target_os = "linux")]
38let pid: i32 = unsafe { linux_sys_getpid() };
39```
4041# Safety
42TODO
43"#;
4445pub(super) SYS_GETRANDOM = r#"Performs a `getrandom` syscall.
4647Obtain a series of random bytes.
4849# Info
50- <https://www.man7.org/linux/man-pages/man2/getrandom.2.html>
5152# Example
53```no_run
54use devela::linux_sys_getrandom;
5556let mut r = 0u8;
57# #[cfg(target_os = "linux")]
58unsafe { linux_sys_getrandom(&mut r as *mut u8, 1, 0) };
59```
6061# Flags
6263- `GRND_RANDOM` = 0x001
6465 Use the `/dev/random` (blocking) source instead of the `/dev/urandom`
66 (non-blocking) source to obtain randomness.
6768 If this flag is specified, the call may block, potentially for quite some
69 time, even after the randomness source has been initialized. If it is not
70 specified, the call can only block when the system has just booted and the
71 randomness source has not yet been initialized.
7273- `GRND_NONBLOCK` = 0x002
7475 Instead of blocking, return to the caller immediately if no data is available.
7677- `GRND_INSECURE` = 0x0004
7879 Write random data that may not be cryptographically secure.
8081# Safety
82TODO
83"#;
8485pub(super) SYS_IOCTL = r#"Performs an `ioctl` syscall.
8687Performs a generic I/O control operation (ioctl) on the given file descriptor.
8889The operation to perform and the data to use is determined by the `request`
90argument, which is a device-specific request code, and the `argp` argument,
91which is a pointer to the data.
9293# Info
94- <https://www.man7.org/linux/man-pages/man2/ioctl.2.html>
9596# Safety
97TODO
98"#;
99100pub(super) SYS_NANOSLEEP = r#"Performs a `nanosleep` syscall.
101102Suspend execution of calling thread.
103104Suspension will last until either the time interval specified in `*req`
105has elapsed or a signal is delivered to the calling thread, in which
106case the remaining time will be stored in `rem`.
107108Returns the syscall return value.
109110# Info
111- <https://www.man7.org/linux/man-pages/man2/nanosleep.2.html>
112113# Example
114```
115use devela::{linux_sys_nanosleep, Duration, LinuxTimespec};
116117let mut req = LinuxTimespec::from(Duration::from_millis(99));
118let mut rem = LinuxTimespec::default();
119# #[cfg(target_os = "linux")]
120assert_eq![0, unsafe { linux_sys_nanosleep(&mut req, &mut rem) }];
121```
122123# Safety
124TODO
125"#;
126127pub(super) SYS_READ = r#"Performs a `read` syscall.
128129Read `count` bytes from a file descriptor `fd` into a buffer `buf`.
130131# Info
132- <https://www.man7.org/linux/man-pages/man2/read.2.html>
133134# Example
135```no_run
136use devela::{linux_sys_read, LINUX_FILENO};
137138# #[cfg(target_os = "linux")] {
139let mut buf: [u8; 1024] = [0; 1024];
140let bytes_read: isize = unsafe {
141 linux_sys_read(LINUX_FILENO::STDIN, buf.as_mut_ptr(), buf.len())
142};
143assert![bytes_read > 0];
144# }
145```
146147# Safety
148TODO
149"#;
150151pub(super) SYS_RT_SIGACTION = r#"Performs an `rt_sigaction` syscall.
152153Examine and change a signal action.
154155# Info
156- <https://man7.org/linux/man-pages/man2/rt_sigaction.2.html>
157158# Flags
159160# Safety
161TODO
162"#;
163164pub(super) SYS_WRITE = r#"Performs a `write` syscall.
165166Writes `count` bytes from a buffer `buf` into a file descriptor `fd`.
167168Returns the syscall return value.
169170# Info
171- <https://www.man7.org/linux/man-pages/man2/write.2.html>
172173# Example
174```
175use devela::{LINUX_FILENO, linux_sys_write};
176177# #[cfg(target_os = "linux")] {
178let buf = "Hello\n".as_bytes();
179let bytes_written: isize = unsafe {
180 linux_sys_write(LINUX_FILENO::STDOUT, buf.as_ptr(), buf.len())
181};
182assert![bytes_written > 0];
183# }
184```
185186# Safety
187TODO
188"#;
189}