devela/sys/os/linux/fns/syscalls/
shared_docs.rs

1// devela::sys::os::linux::fns::syscalls::shared_docs
2//
3//! Defines constants for shared documentation for linux syscalls.
4//
5
6crate::CONST! {
7pub(super) SYS_EXIT = r#"Performs an `exit` syscall.
8
9Terminate the process with an exit status.
10
11# Info
12- <https://www.man7.org/linux/man-pages/man2/exit.2.html>
13
14# Example
15```
16use devela::linux_sys_exit;
17
18# #[cfg(target_os = "linux")]
19unsafe { linux_sys_exit(0) };
20```
21
22# Safety
23TODO
24"#;
25
26pub(super) SYS_GETPID = r#"Performs a `getpid` syscall.
27
28Get process identification.
29
30# Info
31- <https://www.man7.org/linux/man-pages/man2/getpid.2.html>
32
33# Example
34```no_run
35use devela::linux_sys_getpid;
36
37# #[cfg(target_os = "linux")]
38let pid: i32 = unsafe { linux_sys_getpid() };
39```
40
41# Safety
42TODO
43"#;
44
45pub(super) SYS_GETRANDOM = r#"Performs a `getrandom` syscall.
46
47Obtain a series of random bytes.
48
49# Info
50- <https://www.man7.org/linux/man-pages/man2/getrandom.2.html>
51
52# Example
53```no_run
54use devela::linux_sys_getrandom;
55
56let mut r = 0u8;
57# #[cfg(target_os = "linux")]
58unsafe { linux_sys_getrandom(&mut r as *mut u8, 1, 0) };
59```
60
61# Flags
62
63- `GRND_RANDOM` = 0x001
64
65  Use the `/dev/random` (blocking) source instead of the `/dev/urandom`
66  (non-blocking) source to obtain randomness.
67
68  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.
72
73- `GRND_NONBLOCK` = 0x002
74
75  Instead of blocking, return to the caller immediately if no data is available.
76
77- `GRND_INSECURE` = 0x0004
78
79  Write random data that may not be cryptographically secure. 
80
81# Safety
82TODO
83"#;
84
85pub(super) SYS_IOCTL = r#"Performs an `ioctl` syscall.
86
87Performs a generic I/O control operation (ioctl) on the given file descriptor.
88
89The 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.
92
93# Info
94- <https://www.man7.org/linux/man-pages/man2/ioctl.2.html>
95
96# Safety
97TODO
98"#;
99
100pub(super) SYS_NANOSLEEP = r#"Performs a `nanosleep` syscall.
101
102Suspend execution of calling thread.
103
104Suspension 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`.
107
108Returns the syscall return value.
109
110# Info
111- <https://www.man7.org/linux/man-pages/man2/nanosleep.2.html>
112
113# Example
114```
115use devela::{linux_sys_nanosleep, Duration, LinuxTimespec};
116
117let 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```
122
123# Safety
124TODO
125"#;
126
127pub(super) SYS_READ = r#"Performs a `read` syscall.
128
129Read `count` bytes from a file descriptor `fd` into a buffer `buf`.
130
131# Info
132- <https://www.man7.org/linux/man-pages/man2/read.2.html>
133
134# Example
135```no_run
136use devela::{linux_sys_read, LINUX_FILENO};
137
138# #[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```
146
147# Safety
148TODO
149"#;
150
151pub(super) SYS_RT_SIGACTION = r#"Performs an `rt_sigaction` syscall.
152
153Examine and change a signal action.
154
155# Info
156- <https://man7.org/linux/man-pages/man2/rt_sigaction.2.html>
157
158# Flags
159
160# Safety
161TODO
162"#;
163
164pub(super) SYS_WRITE = r#"Performs a `write` syscall.
165
166Writes `count` bytes from a buffer `buf` into a file descriptor `fd`.
167
168Returns the syscall return value.
169
170# Info
171- <https://www.man7.org/linux/man-pages/man2/write.2.html>
172
173# Example
174```
175use devela::{LINUX_FILENO, linux_sys_write};
176
177# #[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```
185
186# Safety
187TODO
188"#;
189}