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 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
21pub mod aarch64;
23pub mod arm;
25pub mod loongarch64;
27pub mod m68k;
29pub mod microblaze;
31pub mod mips;
33pub mod mips64;
35pub mod mipsn32;
37pub mod or1k;
39pub mod powerpc;
41pub mod powerpc64;
43pub mod riscv32;
45pub mod riscv64;
47pub mod s390x;
49pub mod sh;
51pub mod x32;
53pub mod x86;
55pub 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
103use core::ffi::c_long;
116
117pub(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
131pub(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}