Skip to main content

syscall_numbers/
lib.rs

1#![doc = include_str!("../README.md")]
2#![doc(html_root_url = "https://docs.rs/syscall-numbers/4.0.3")]
3#![no_std]
4
5/// `AArch64` definitions.
6pub mod aarch64;
7/// `ARM` definitions.
8pub mod arm;
9/// `LoongArch` 64-bit definitions.
10pub mod loongarch64;
11/// `Motorola 68000` series definitions.
12pub mod m68k;
13/// `MicroBlaze` definitions.
14pub mod microblaze;
15/// `MIPS` definitions.
16pub mod mips;
17/// `MIPS64` definitions.
18pub mod mips64;
19/// `MIPS N32` definitions.
20pub mod mipsn32;
21/// `OpenRISC 1000` definitions.
22pub mod or1k;
23/// `PowerPC` definitions.
24pub mod powerpc;
25/// `PowerPC64` definitions.
26pub mod powerpc64;
27/// `RISC-V` 32-bit definitions.
28pub mod riscv32;
29/// `RISC-V` 64-bit definitions.
30pub mod riscv64;
31/// `IBM System Z` 64-bit definitions.
32pub mod s390x;
33/// `SuperH` definitions.
34pub mod sh;
35/// `X86_32` definitions.
36pub mod x32;
37/// `X86` definitions.
38pub mod x86;
39/// `AMD64` definitions.
40pub 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
87// These architectures are not currently supported by Rust.
88/*
89#[cfg(target_arch = "microblaze")]
90pub use microblaze as native;
91
92#[cfg(target_arch = "or1k")]
93pub use or1k as native;
94
95#[cfg(target_arch = "sh")]
96pub use sh as native;
97*/
98
99use core::ffi::c_long;
100
101/// Returns the name of a system call, given its number.
102pub(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
115/// Returns `true` if `number` is a valid system call number.
116pub(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}