1#![doc = include_str!("../README.md")]
2#![doc(html_root_url = "https://docs.rs/syscall-numbers/4.0.3")]
3#![no_std]
4
5pub mod aarch64;
7pub mod arm;
9pub mod loongarch64;
11pub mod m68k;
13pub mod microblaze;
15pub mod mips;
17pub mod mips64;
19pub mod mipsn32;
21pub mod or1k;
23pub mod powerpc;
25pub mod powerpc64;
27pub mod riscv32;
29pub mod riscv64;
31pub mod s390x;
33pub mod sh;
35pub mod x32;
37pub mod x86;
39pub mod x86_64;
41
42#[cfg(target_arch = "aarch64")]
43pub use aarch64 as native;
44
45#[cfg(target_arch = "arm")]
46pub use arm as native;
47
48#[cfg(target_arch = "loongarch64")]
49pub use loongarch64 as native;
50
51#[cfg(target_arch = "m68k")]
52pub use m68k as native;
53
54#[cfg(target_arch = "mips")]
55pub use mips as native;
56
57#[cfg(target_arch = "mips64")]
58pub use mips64 as native;
59
60#[cfg(target_arch = "mips32r6")]
61pub use mipsn32 as native;
62
63#[cfg(target_arch = "powerpc")]
64pub use powerpc as native;
65
66#[cfg(target_arch = "powerpc64")]
67pub use powerpc64 as native;
68
69#[cfg(target_arch = "riscv32")]
70pub use riscv32 as native;
71
72#[cfg(target_arch = "riscv64")]
73pub use riscv64 as native;
74
75#[cfg(target_arch = "s390x")]
76pub use s390x as native;
77
78#[cfg(all(target_arch = "x86_64", target_abi = "x32"))]
79pub use x32 as native;
80
81#[cfg(target_arch = "x86")]
82pub use x86 as native;
83
84#[cfg(all(target_arch = "x86_64", not(target_abi = "x32")))]
85pub use x86_64 as native;
86
87use core::ffi::c_long;
100
101pub(crate) fn sys_call_name(
103 names: &'static [&'static str],
104 base_index: c_long,
105 number: c_long,
106) -> Option<&'static str> {
107 if number >= base_index
108 && let Ok(index) = usize::try_from(number - base_index)
109 {
110 return names.get(index).filter(|&&name| !name.is_empty()).copied();
111 }
112 None
113}
114
115pub(crate) fn is_valid_sys_call_number(
117 names: &'static [&'static str],
118 base_index: c_long,
119 number: c_long,
120) -> bool {
121 if let Ok(names_len) = c_long::try_from(names.len()) {
122 let last_number = base_index + names_len - 1;
123 return number >= base_index && number <= last_number;
124 }
125 false
126}