syscall_numbers/
lib.rs

1#![doc = include_str!("../README.md")]
2#![doc(html_root_url = "https://docs.rs/syscall-numbers/4.0.1")]
3#![warn(
4    unsafe_op_in_unsafe_fn,
5    //missing_docs,
6    keyword_idents,
7    macro_use_extern_crate,
8    missing_debug_implementations,
9    non_ascii_idents,
10    trivial_casts,
11    trivial_numeric_casts,
12    unstable_features,
13    unused_extern_crates,
14    unused_import_braces,
15    unused_labels,
16    variant_size_differences,
17    unused_qualifications
18)]
19#![no_std]
20
21/// AArch64 definitions.
22pub mod aarch64;
23/// ARM definitions.
24pub mod arm;
25/// LoongArch 64-bit definitions.
26pub mod loongarch64;
27/// Motorola 68000 series definitions.
28pub mod m68k;
29/// MicroBlaze definitions.
30pub mod microblaze;
31/// MIPS definitions.
32pub mod mips;
33/// MIPS64 definitions.
34pub mod mips64;
35/// MIPS N32 definitions.
36pub mod mipsn32;
37/// OpenRISC 1000 definitions.
38pub mod or1k;
39/// PowerPC definitions.
40pub mod powerpc;
41/// PowerPC64 definitions.
42pub mod powerpc64;
43/// RISC-V 32-bit definitions.
44pub mod riscv32;
45/// RISC-V 64-bit definitions.
46pub mod riscv64;
47/// IBM System Z 64-bit definitions.
48pub mod s390x;
49/// SuperH definitions.
50pub mod sh;
51/// X86_32 definitions.
52pub mod x32;
53/// X86 definitions.
54pub mod x86;
55/// AMD64 definitions.
56pub mod x86_64;
57
58#[cfg(target_arch = "aarch64")]
59pub use aarch64 as native;
60
61#[cfg(target_arch = "arm")]
62pub use arm as native;
63
64#[cfg(target_arch = "loongarch64")]
65pub use loongarch64 as native;
66
67#[cfg(target_arch = "m68k")]
68pub use m68k as native;
69
70#[cfg(target_arch = "mips")]
71pub use mips as native;
72
73#[cfg(target_arch = "mips64")]
74pub use mips64 as native;
75
76#[cfg(target_arch = "mips32r6")]
77pub use mipsn32 as native;
78
79#[cfg(target_arch = "powerpc")]
80pub use powerpc as native;
81
82#[cfg(target_arch = "powerpc64")]
83pub use powerpc64 as native;
84
85#[cfg(target_arch = "riscv32")]
86pub use riscv32 as native;
87
88#[cfg(target_arch = "riscv64")]
89pub use riscv64 as native;
90
91#[cfg(target_arch = "s390x")]
92pub use s390x as native;
93
94#[cfg(all(target_arch = "x86_64", target_abi = "x32"))]
95pub use x32 as native;
96
97#[cfg(target_arch = "x86")]
98pub use x86 as native;
99
100#[cfg(all(target_arch = "x86_64", not(target_abi = "x32")))]
101pub use x86_64 as native;
102
103// These architectures are not currently supported by Rust.
104/*
105#[cfg(target_arch = "microblaze")]
106pub use microblaze as native;
107
108#[cfg(target_arch = "or1k")]
109pub use or1k as native;
110
111#[cfg(target_arch = "sh")]
112pub use sh as native;
113*/
114
115use core::ffi::c_long;
116
117/// Returns the name of a system call, given its number.
118pub(crate) fn sys_call_name(
119    names: &'static [&'static str],
120    base_index: c_long,
121    number: c_long,
122) -> Option<&'static str> {
123    if number >= base_index {
124        if let Ok(index) = usize::try_from(number - base_index) {
125            return names.get(index).filter(|&&name| !name.is_empty()).cloned();
126        }
127    }
128    None
129}
130
131/// Returns `true` if `number` is a valid system call number.
132pub(crate) fn is_valid_sys_call_number(
133    names: &'static [&'static str],
134    base_index: c_long,
135    number: c_long,
136) -> bool {
137    if let Ok(names_len) = c_long::try_from(names.len()) {
138        let last_number = base_index + names_len - 1;
139        return number >= base_index && number <= last_number;
140    }
141    false
142}