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

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// devela::sys::os::linux::fns::syscalls::shared_docs
//
//! Defines constants for shared documentation for linux syscalls.
//

crate::CONST! {
pub(super) SYS_EXIT = r#"Performs an `exit` syscall.

Terminate the process with an exit status.

# Info
- <https://www.man7.org/linux/man-pages/man2/exit.2.html>

# Example
```
use devela::linux_sys_exit;

# #[cfg(target_os = "linux")]
unsafe { linux_sys_exit(0) };
```

# Safety
TODO
"#;

pub(super) SYS_GETPID = r#"Performs a `getpid` syscall.

Get process identification.

# Info
- <https://www.man7.org/linux/man-pages/man2/getpid.2.html>

# Example
```no_run
use devela::linux_sys_getpid;

# #[cfg(target_os = "linux")]
let pid: i32 = unsafe { linux_sys_getpid() };
```

# Safety
TODO
"#;

pub(super) SYS_GETRANDOM = r#"Performs a `getrandom` syscall.

Obtain a series of random bytes.

# Info
- <https://www.man7.org/linux/man-pages/man2/getrandom.2.html>

# Example
```no_run
use devela::linux_sys_getrandom;

let mut r = 0u8;
# #[cfg(target_os = "linux")]
unsafe { linux_sys_getrandom(&mut r as *mut u8, 1, 0) };
```

# Flags

- `GRND_RANDOM` = 0x001

  Use the `/dev/random` (blocking) source instead of the `/dev/urandom`
  (non-blocking) source to obtain randomness.

  If this flag is specified, the call may block, potentially for quite some
  time, even after the randomness source has been initialized. If it is not
  specified, the call can only block when the system has just booted and the
  randomness source has not yet been initialized.

- `GRND_NONBLOCK` = 0x002

  Instead of blocking, return to the caller immediately if no data is available.

- `GRND_INSECURE` = 0x0004

  Write random data that may not be cryptographically secure. 

# Safety
TODO
"#;

pub(super) SYS_IOCTL = r#"Performs an `ioctl` syscall.

Performs a generic I/O control operation (ioctl) on the given file descriptor.

The operation to perform and the data to use is determined by the `request`
argument, which is a device-specific request code, and the `argp` argument,
which is a pointer to the data.

# Info
- <https://www.man7.org/linux/man-pages/man2/ioctl.2.html>

# Safety
TODO
"#;

pub(super) SYS_NANOSLEEP = r#"Performs a `nanosleep` syscall.

Suspend execution of calling thread.

Suspension will last until either the time interval specified in `*req`
has elapsed or a signal is delivered to the calling thread, in which
case the remaining time will be stored in `rem`.

Returns the syscall return value.

# Info
- <https://www.man7.org/linux/man-pages/man2/nanosleep.2.html>

# Example
```
use devela::{linux_sys_nanosleep, Duration, LinuxTimespec};

let mut req = LinuxTimespec::from(Duration::from_millis(99));
let mut rem = LinuxTimespec::default();
# #[cfg(target_os = "linux")]
assert_eq![0, unsafe { linux_sys_nanosleep(&mut req, &mut rem) }];
```

# Safety
TODO
"#;

pub(super) SYS_READ = r#"Performs a `read` syscall.

Read `count` bytes from a file descriptor `fd` into a buffer `buf`.

# Info
- <https://www.man7.org/linux/man-pages/man2/read.2.html>

# Example
```no_run
use devela::{linux_sys_read, LINUX_FILENO};

# #[cfg(target_os = "linux")] {
let mut buf: [u8; 1024] = [0; 1024];
let bytes_read: isize = unsafe {
    linux_sys_read(LINUX_FILENO::STDIN, buf.as_mut_ptr(), buf.len())
};
assert![bytes_read > 0];
# }
```

# Safety
TODO
"#;

pub(super) SYS_RT_SIGACTION = r#"Performs an `rt_sigaction` syscall.

Examine and change a signal action.

# Info
- <https://man7.org/linux/man-pages/man2/rt_sigaction.2.html>

# Flags

# Safety
TODO
"#;

pub(super) SYS_WRITE = r#"Performs a `write` syscall.

Writes `count` bytes from a buffer `buf` into a file descriptor `fd`.

Returns the syscall return value.

# Info
- <https://www.man7.org/linux/man-pages/man2/write.2.html>

# Example
```
use devela::{LINUX_FILENO, linux_sys_write};

# #[cfg(target_os = "linux")] {
let buf = "Hello\n".as_bytes();
let bytes_written: isize = unsafe {
    linux_sys_write(LINUX_FILENO::STDOUT, buf.as_ptr(), buf.len())
};
assert![bytes_written > 0];
# }
```

# Safety
TODO
"#;
}