linux_syscalls/
lib.rs

1#![no_std]
2#![cfg(any(
3    all(
4        any(target_os = "linux", target_os = "android"),
5        any(
6            all(
7                target_arch = "x86_64",
8                target_endian = "little",
9                target_pointer_width = "64"
10            ),
11            all(target_arch = "aarch64", target_pointer_width = "64"),
12            all(target_arch = "arm", target_pointer_width = "32"),
13            all(
14                target_arch = "x86",
15                target_endian = "little",
16                target_pointer_width = "32"
17            )
18        )
19    ),
20    all(
21        target_os = "linux",
22        any(
23            all(
24                target_arch = "x86_64",
25                target_endian = "little",
26                target_pointer_width = "32"
27            ),
28            all(
29                target_arch = "riscv64",
30                target_endian = "little",
31                target_pointer_width = "64"
32            ),
33            all(
34                target_arch = "riscv32",
35                target_endian = "little",
36                target_pointer_width = "32"
37            ),
38            all(target_arch = "mips", target_pointer_width = "32"),
39            all(target_arch = "mips64", target_pointer_width = "64"),
40            all(
41                target_arch = "s390x",
42                target_endian = "big",
43                target_pointer_width = "64"
44            ),
45            all(
46                target_arch = "loongarch64",
47                target_endian = "little",
48                target_pointer_width = "64"
49            ),
50            all(
51                target_arch = "powerpc",
52                target_endian = "big",
53                target_pointer_width = "32"
54            ),
55            all(target_arch = "powerpc64", target_pointer_width = "64"),
56        )
57    )
58))]
59#![cfg_attr(asm_experimental_arch, feature(asm_experimental_arch))]
60#![cfg_attr(docs_rs, feature(doc_cfg))]
61
62mod bitflags;
63
64pub use linux_errnos::Errno;
65pub use linux_sysno::Sysno;
66
67pub mod env;
68mod init;
69#[cfg_attr(
70    all(target_arch = "mips", target_pointer_width = "32"),
71    path = "macros/mips.rs"
72)]
73mod macros;
74
75#[cfg(any(doc, not(feature = "bare")))]
76pub use init::init;
77#[cfg(any(doc, feature = "bare"))]
78pub use init::{init_from_args, init_from_auxv, init_from_environ};
79
80#[cfg(outline_syscalls)]
81#[cfg_attr(
82    not(any(
83        all(
84            target_arch = "x86",
85            target_endian = "little",
86            target_pointer_width = "32"
87        ),
88        all(target_arch = "powerpc64", target_pointer_width = "64"),
89    )),
90    path = "outline/common.rs"
91)]
92#[cfg_attr(
93    all(
94        target_arch = "x86",
95        target_endian = "little",
96        target_pointer_width = "32"
97    ),
98    path = "outline/x86.rs"
99)]
100#[cfg_attr(
101    all(target_arch = "powerpc64", target_pointer_width = "64"),
102    path = "outline/powerpc64.rs"
103)]
104mod arch;
105
106#[cfg(not(outline_syscalls))]
107#[cfg_attr(
108    all(target_arch = "arm", target_pointer_width = "32", not(thumb_mode)),
109    path = "inline/arm.rs"
110)]
111#[cfg_attr(
112    all(target_arch = "arm", target_pointer_width = "32", thumb_mode),
113    path = "inline/thumb.rs"
114)]
115#[cfg_attr(
116    all(target_arch = "aarch64", target_pointer_width = "64"),
117    path = "inline/aarch64.rs"
118)]
119#[cfg_attr(
120    all(target_arch = "x86_64", target_endian = "little"),
121    path = "inline/x86_64.rs"
122)]
123#[cfg_attr(
124    all(
125        target_arch = "x86",
126        target_endian = "little",
127        target_pointer_width = "32"
128    ),
129    path = "inline/x86.rs"
130)]
131#[cfg_attr(
132    any(
133        all(
134            target_arch = "riscv32",
135            target_endian = "little",
136            target_pointer_width = "32"
137        ),
138        all(
139            target_arch = "riscv64",
140            target_endian = "little",
141            target_pointer_width = "64"
142        )
143    ),
144    path = "inline/riscv.rs"
145)]
146#[cfg_attr(
147    all(
148        target_arch = "powerpc",
149        target_endian = "big",
150        target_pointer_width = "32"
151    ),
152    path = "inline/powerpc.rs"
153)]
154#[cfg_attr(
155    all(target_arch = "powerpc64", target_pointer_width = "64"),
156    path = "inline/powerpc64.rs"
157)]
158#[cfg_attr(
159    all(target_arch = "mips", target_pointer_width = "32"),
160    path = "inline/mips.rs"
161)]
162#[cfg_attr(
163    all(target_arch = "mips64", target_pointer_width = "64"),
164    path = "inline/mips64.rs"
165)]
166#[cfg_attr(
167    all(
168        target_arch = "s390x",
169        target_endian = "big",
170        target_pointer_width = "64"
171    ),
172    path = "inline/s390x.rs"
173)]
174#[cfg_attr(
175    all(
176        target_arch = "loongarch64",
177        target_endian = "little",
178        target_pointer_width = "64"
179    ),
180    path = "inline/loongarch64.rs"
181)]
182mod arch;
183
184#[cfg(all(target_arch = "powerpc64", target_pointer_width = "64"))]
185pub use arch::has_scv;
186
187/// Make a raw system call with 0 arguments.
188///
189/// Returns a `Result<usize, Errno>`.
190///
191/// # Safety
192///
193/// A system call is unsafe by definition.
194/// It's the caller's responsibility to ensure safety.
195pub use arch::syscall0;
196
197/// Make a raw system call with 1 argument.
198///
199/// Returns a `Result<usize, Errno>`.
200///
201/// # Safety
202///
203/// A system call is unsafe by definition.
204/// It's the caller's responsibility to ensure safety.
205pub use arch::syscall1;
206
207/// Make a raw system call with 2 arguments.
208///
209/// Returns a `Result<usize, Errno>`.
210///
211/// # Safety
212///
213/// A system call is unsafe by definition.
214/// It's the caller's responsibility to ensure safety.
215pub use arch::syscall2;
216
217/// Make a raw system call with 3 arguments.
218///
219/// Returns a `Result<usize, Errno>`.
220///
221/// # Safety
222///
223/// A system call is unsafe by definition.
224/// It's the caller's responsibility to ensure safety.
225pub use arch::syscall3;
226
227/// Make a raw system call with 4 arguments.
228///
229/// Returns a `Result<usize, Errno>`.
230///
231/// # Safety
232///
233/// A system call is unsafe by definition.
234/// It's the caller's responsibility to ensure safety.
235pub use arch::syscall4;
236
237/// Make a raw system call with 5 arguments.
238///
239/// Returns a `Result<usize, Errno>`.
240///
241/// # Safety
242///
243/// A system call is unsafe by definition.
244/// It's the caller's responsibility to ensure safety.
245pub use arch::syscall5;
246
247/// Make a raw system call with 6 arguments.
248///
249/// Returns a `Result<usize, Errno>`.
250///
251/// # Safety
252///
253/// A system call is unsafe by definition.
254/// It's the caller's responsibility to ensure safety.
255pub use arch::syscall6;
256
257#[cfg(all(target_arch = "mips", target_pointer_width = "32"))]
258/// Make a raw system call with 7 arguments.
259///
260/// Returns a `Result<usize, Errno>`.
261///
262/// # Safety
263///
264/// A system call is unsafe by definition.
265/// It's the caller's responsibility to ensure safety.
266pub use arch::syscall7;
267
268/// Make a raw system call with 0 arguments.
269/// Like the non `_readonly` version but you declare that syscall does not mutate any memory.
270///
271/// Returns a `Result<usize, Errno>`.
272///
273/// # Safety
274///
275/// A system call is unsafe by definition.
276/// It's the caller's responsibility to ensure safety.
277pub use arch::syscall0_readonly;
278
279/// Make a raw system call with 1 argument.
280/// Like the non `_readonly` version but you declare that syscall does not mutate any memory.
281///
282/// Returns a `Result<usize, Errno>`.
283///
284/// # Safety
285///
286/// A system call is unsafe by definition.
287/// It's the caller's responsibility to ensure safety.
288pub use arch::syscall1_readonly;
289
290/// Make a raw system call with 7 arguments.
291/// It's assured that it will not return.
292///
293/// # Safety
294///
295/// A system call is unsafe by definition.
296/// It's the caller's responsibility to ensure safety.
297pub use arch::syscall1_noreturn;
298
299/// Make a raw system call with 2 arguments.
300/// Like the non `_readonly` version but you declare that syscall does not mutate any memory.
301///
302/// Returns a `Result<usize, Errno>`.
303///
304/// # Safety
305///
306/// A system call is unsafe by definition.
307/// It's the caller's responsibility to ensure safety.
308pub use arch::syscall2_readonly;
309
310/// Make a raw system call with 3 arguments.
311/// Like the non `_readonly` version but you declare that syscall does not mutate any memory.
312///
313/// Returns a `Result<usize, Errno>`.
314///
315/// # Safety
316///
317/// A system call is unsafe by definition.
318/// It's the caller's responsibility to ensure safety.
319pub use arch::syscall3_readonly;
320
321/// Make a raw system call with 4 arguments.
322/// Like the non `_readonly` version but you declare that syscall does not mutate any memory.
323///
324/// Returns a `Result<usize, Errno>`.
325///
326/// # Safety
327///
328/// A system call is unsafe by definition.
329/// It's the caller's responsibility to ensure safety.
330pub use arch::syscall4_readonly;
331
332/// Make a raw system call with 5 arguments.
333/// Like the non `_readonly` version but you declare that syscall does not mutate any memory.
334///
335/// Returns a `Result<usize, Errno>`.
336///
337/// # Safety
338///
339/// A system call is unsafe by definition.
340/// It's the caller's responsibility to ensure safety.
341pub use arch::syscall5_readonly;
342
343/// Make a raw system call with 6 arguments.
344/// Like the non `_readonly` version but you declare that syscall does not mutate any memory.
345///
346/// Returns a `Result<usize, Errno>`.
347///
348/// # Safety
349///
350/// A system call is unsafe by definition.
351/// It's the caller's responsibility to ensure safety.
352pub use arch::syscall6_readonly;
353
354#[cfg(all(target_arch = "mips", target_pointer_width = "32"))]
355/// Make a raw system call with 7 arguments.
356/// Like the non `_readonly` version but you declare that syscall does not mutate any memory.
357///
358/// Returns a `Result<usize, Errno>`.
359///
360/// # Safety
361///
362/// A system call is unsafe by definition.
363/// It's the caller's responsibility to ensure safety.
364pub use arch::syscall7_readonly;
365
366/// Make a raw system call with 0 arguments.
367///
368/// Returns a raw `usize`, doesn't not check for errors.
369///
370/// # Safety
371///
372/// A system call is unsafe by definition.
373/// It's the caller's responsibility to ensure safety.
374pub use arch::raw_syscall0;
375
376/// Make a raw system call with 1 argument.
377///
378/// Returns a raw `usize`, doesn't not check for errors.
379///
380/// # Safety
381///
382/// A system call is unsafe by definition.
383/// It's the caller's responsibility to ensure safety.
384pub use arch::raw_syscall1;
385
386/// Make a raw system call with 2 arguments.
387///
388/// Returns a raw `usize`, doesn't not check for errors.
389///
390/// # Safety
391///
392/// A system call is unsafe by definition.
393/// It's the caller's responsibility to ensure safety.
394pub use arch::raw_syscall2;
395
396/// Make a raw system call with 3 arguments.
397///
398/// Returns a raw `usize`, doesn't not check for errors.
399///
400/// # Safety
401///
402/// A system call is unsafe by definition.
403/// It's the caller's responsibility to ensure safety.
404pub use arch::raw_syscall3;
405
406/// Make a raw system call with 4 arguments.
407///
408/// Returns a raw `usize`, doesn't not check for errors.
409///
410/// # Safety
411///
412/// A system call is unsafe by definition.
413/// It's the caller's responsibility to ensure safety.
414pub use arch::raw_syscall4;
415
416/// Make a raw system call with 5 arguments.
417///
418/// Returns a raw `usize`, doesn't not check for errors.
419///
420/// # Safety
421///
422/// A system call is unsafe by definition.
423/// It's the caller's responsibility to ensure safety.
424pub use arch::raw_syscall5;
425
426/// Make a raw system call with 6 arguments.
427///
428/// Returns a raw `usize`, doesn't not check for errors.
429///
430/// # Safety
431///
432/// A system call is unsafe by definition.
433/// It's the caller's responsibility to ensure safety.
434pub use arch::raw_syscall6;
435
436#[cfg(all(target_arch = "mips", target_pointer_width = "32"))]
437/// Make a raw system call with 7 arguments.
438///
439/// Returns a raw `usize`, doesn't not check for errors.
440///
441/// # Safety
442///
443/// A system call is unsafe by definition.
444/// It's the caller's responsibility to ensure safety.
445pub use arch::raw_syscall7;
446
447/// Make a raw system call with 0 arguments.
448/// Like the non `_readonly` version but you declare that syscall does not mutate any memory.
449///
450/// Returns a raw `usize`, doesn't not check for errors.
451///
452/// # Safety
453///
454/// A system call is unsafe by definition.
455/// It's the caller's responsibility to ensure safety.
456pub use arch::raw_syscall0_readonly;
457
458/// Make a raw system call with 1 argument.
459/// Like the non `_readonly` version but you declare that syscall does not mutate any memory.
460///
461/// Returns a raw `usize`, doesn't not check for errors.
462///
463/// # Safety
464///
465/// A system call is unsafe by definition.
466/// It's the caller's responsibility to ensure safety.
467pub use arch::raw_syscall1_readonly;
468
469/// Make a raw system call with 2 arguments.
470/// Like the non `_readonly` version but you declare that syscall does not mutate any memory.
471///
472/// Returns a raw `usize`, doesn't not check for errors.
473///
474/// # Safety
475///
476/// A system call is unsafe by definition.
477/// It's the caller's responsibility to ensure safety.
478pub use arch::raw_syscall2_readonly;
479
480/// Make a raw system call with 3 arguments.
481/// Like the non `_readonly` version but you declare that syscall does not mutate any memory.
482///
483/// Returns a raw `usize`, doesn't not check for errors.
484///
485/// # Safety
486///
487/// A system call is unsafe by definition.
488/// It's the caller's responsibility to ensure safety.
489pub use arch::raw_syscall3_readonly;
490
491/// Make a raw system call with 4 arguments.
492/// Like the non `_readonly` version but you declare that syscall does not mutate any memory.
493///
494/// Returns a raw `usize`, doesn't not check for errors.
495///
496/// # Safety
497///
498/// A system call is unsafe by definition.
499/// It's the caller's responsibility to ensure safety.
500pub use arch::raw_syscall4_readonly;
501
502/// Make a raw system call with 5 arguments.
503/// Like the non `_readonly` version but you declare that syscall does not mutate any memory.
504///
505/// Returns a raw `usize`, doesn't not check for errors.
506///
507/// # Safety
508///
509/// A system call is unsafe by definition.
510/// It's the caller's responsibility to ensure safety.
511pub use arch::raw_syscall5_readonly;
512
513/// Make a raw system call with 6 arguments.
514/// Like the non `_readonly` version but you declare that syscall does not mutate any memory.
515///
516/// Returns a raw `usize`, doesn't not check for errors.
517///
518/// # Safety
519///
520/// A system call is unsafe by definition.
521/// It's the caller's responsibility to ensure safety.
522pub use arch::raw_syscall6_readonly;
523
524#[cfg(all(target_arch = "mips", target_pointer_width = "32"))]
525/// Make a raw system call with 7 arguments.
526///
527/// Returns a raw `usize`, doesn't not check for errors.
528///
529/// # Safety
530///
531/// A system call is unsafe by definition.
532/// It's the caller's responsibility to ensure safety.
533pub use arch::raw_syscall7_readonly;