Skip to main content

aya_friday_ebpf_cty/
lib.rs

1//! Type aliases to C types like `c_int` for use with bindgen
2//!
3//! # MSRV
4//!
5//! This crate is guaranteed to compile on stable Rust 1.30.0 and up. It *might* compile with older
6//! versions but that may change in any new patch release.
7#![no_std]
8#![expect(non_camel_case_types, reason = "C type aliases use libc naming")]
9
10// AD = Architecture dependent
11pub use ad::*;
12// OD = OS dependent
13pub use od::*;
14
15#[cfg(target_arch = "bpf")]
16mod ad {
17    pub type c_int = i32;
18    pub type c_uint = u32;
19
20    #[cfg(any(
21        bpf_target_arch = "aarch64",
22        bpf_target_arch = "arm",
23        bpf_target_arch = "powerpc64",
24        bpf_target_arch = "riscv64",
25        bpf_target_arch = "s390x",
26        bpf_target_arch = "mips",
27    ))]
28    pub type c_char = super::c_uchar;
29
30    #[cfg(any(
31        bpf_target_arch = "loongarch64",
32        bpf_target_arch = "mips64",
33        bpf_target_arch = "x86_64",
34    ))]
35    pub type c_char = super::c_schar;
36}
37
38#[cfg(any(
39    target_arch = "aarch64",
40    target_arch = "arm",
41    target_arch = "asmjs",
42    target_arch = "wasm32",
43    target_arch = "wasm64",
44    target_arch = "powerpc",
45    target_arch = "powerpc64",
46    target_arch = "s390x",
47    target_arch = "riscv32",
48    target_arch = "riscv64"
49))]
50mod ad {
51    pub type c_char = super::c_uchar;
52
53    pub type c_int = i32;
54    pub type c_uint = u32;
55}
56
57#[cfg(any(
58    target_arch = "loongarch64",
59    target_arch = "mips",
60    target_arch = "mips64",
61    target_arch = "nvptx",
62    target_arch = "nvptx64",
63    target_arch = "sparc64",
64    target_arch = "x86",
65    target_arch = "x86_64",
66    target_arch = "xtensa",
67))]
68mod ad {
69    pub type c_char = super::c_schar;
70
71    pub type c_int = i32;
72    pub type c_uint = u32;
73}
74
75#[cfg(target_arch = "msp430")]
76mod ad {
77    pub type c_char = super::c_uchar;
78
79    pub type c_int = i16;
80    pub type c_uint = u16;
81}
82
83// NOTE c_{,u}long definitions come from libc v0.2.3
84#[cfg(not(any(windows, target_os = "redox", target_os = "solaris")))]
85mod od {
86    #[cfg(any(target_pointer_width = "16", target_pointer_width = "32"))]
87    pub type c_long = i32;
88    #[cfg(any(target_pointer_width = "16", target_pointer_width = "32"))]
89    pub type c_ulong = u32;
90
91    #[cfg(target_pointer_width = "64")]
92    pub type c_long = i64;
93    #[cfg(target_pointer_width = "64")]
94    pub type c_ulong = u64;
95}
96
97#[cfg(windows)]
98mod od {
99    pub type c_long = i32;
100    pub type c_ulong = u32;
101}
102
103#[cfg(any(target_os = "redox", target_os = "solaris"))]
104mod od {
105    pub type c_long = i64;
106    pub type c_ulong = u64;
107}
108
109pub type int8_t = i8;
110pub type int16_t = i16;
111pub type int32_t = i32;
112pub type int64_t = i64;
113
114pub type uint8_t = u8;
115pub type uint16_t = u16;
116pub type uint32_t = u32;
117pub type uint64_t = u64;
118
119pub type c_schar = i8;
120pub type c_short = i16;
121pub type c_longlong = i64;
122
123pub type c_uchar = u8;
124pub type c_ushort = u16;
125pub type c_ulonglong = u64;
126
127pub type c_float = f32;
128pub type c_double = f64;
129
130pub type intmax_t = i64;
131pub type uintmax_t = u64;
132
133pub type size_t = usize;
134pub type ptrdiff_t = isize;
135pub type intptr_t = isize;
136pub type uintptr_t = usize;
137pub type ssize_t = isize;
138
139pub type c_void = core::ffi::c_void;