cfi_types/
lib.rs

1//! CFI types for cross-language LLVM CFI support.
2//!
3//! The cfi_types crate provides a new set of C types as user-defined types
4//! using the cfi_encoding attribute and repr(transparent) to be used for
5//! cross-language LLVM CFI support. This new set of C types allows the Rust
6//! compiler to identify and correctly encode C types in extern "C" function
7//! types indirectly called across the FFI boundary when CFI is enabled.
8//!
9//! The use of these types are optional and are recommended for when enforcement
10//! and explicitness of types used across the FFI boundary and no loss of
11//! granularity for cross-language LLVM CFI are preferred.
12//!
13//! Alternatively, the `-Zsanitizer-cfi-normalize-integers` option may be used
14//! with the Clang `-fsanitize-cfi-icall-experimental-normalize-integers` option
15//! for cross-language LLVM CFI support.
16
17#![feature(cfg_sanitizer_cfi)]
18#![feature(cfi_encoding)]
19#![allow(non_camel_case_types)]
20
21/// CFI type equivalent to Rust's core::ffi::c_char type alias.
22#[cfg(sanitizer_cfi_normalize_integers)]
23#[allow(dead_code)]
24#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
25#[repr(transparent)]
26pub struct c_char(pub core::ffi::c_char);
27
28/// CFI type equivalent to Rust's core::ffi::c_char type alias.
29#[cfg(not(sanitizer_cfi_normalize_integers))]
30#[allow(dead_code)]
31#[cfi_encoding = "c"]
32#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
33#[repr(transparent)]
34pub struct c_char(pub core::ffi::c_char);
35
36/// CFI type equivalent to Rust's core::ffi::c_int type alias.
37#[cfg(sanitizer_cfi_normalize_integers)]
38#[allow(dead_code)]
39#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
40#[repr(transparent)]
41pub struct c_int(pub core::ffi::c_int);
42
43/// CFI type equivalent to Rust's core::ffi::c_int type alias.
44#[cfg(not(sanitizer_cfi_normalize_integers))]
45#[allow(dead_code)]
46#[cfi_encoding = "i"]
47#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
48#[repr(transparent)]
49pub struct c_int(pub core::ffi::c_int);
50
51/// CFI type equivalent to Rust's core::ffi::c_long type alias.
52#[cfg(sanitizer_cfi_normalize_integers)]
53#[allow(dead_code)]
54#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
55#[repr(transparent)]
56pub struct c_long(pub core::ffi::c_long);
57
58/// CFI type equivalent to Rust's core::ffi::c_long type alias.
59#[cfg(not(sanitizer_cfi_normalize_integers))]
60#[allow(dead_code)]
61#[cfi_encoding = "l"]
62#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
63#[repr(transparent)]
64pub struct c_long(pub core::ffi::c_long);
65
66/// CFI type equivalent to Rust's core::ffi::c_longlong type alias.
67#[cfg(sanitizer_cfi_normalize_integers)]
68#[allow(dead_code)]
69#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
70#[repr(transparent)]
71pub struct c_longlong(pub core::ffi::c_longlong);
72
73/// CFI type equivalent to Rust's core::ffi::c_longlong type alias.
74#[cfg(not(sanitizer_cfi_normalize_integers))]
75#[allow(dead_code)]
76#[cfi_encoding = "x"]
77#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
78#[repr(transparent)]
79pub struct c_longlong(pub core::ffi::c_longlong);
80
81/// CFI type equivalent to Rust's core::ffi::c_schar type alias.
82#[cfg(sanitizer_cfi_normalize_integers)]
83#[allow(dead_code)]
84#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
85#[repr(transparent)]
86pub struct c_schar(pub core::ffi::c_schar);
87
88/// CFI type equivalent to Rust's core::ffi::c_schar type alias.
89#[cfg(not(sanitizer_cfi_normalize_integers))]
90#[allow(dead_code)]
91#[cfi_encoding = "a"]
92#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
93#[repr(transparent)]
94pub struct c_schar(pub core::ffi::c_schar);
95
96/// CFI type equivalent to Rust's core::ffi::c_short type alias.
97#[cfg(sanitizer_cfi_normalize_integers)]
98#[allow(dead_code)]
99#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
100#[repr(transparent)]
101pub struct c_short(pub core::ffi::c_short);
102
103/// CFI type equivalent to Rust's core::ffi::c_short type alias.
104#[cfg(not(sanitizer_cfi_normalize_integers))]
105#[allow(dead_code)]
106#[cfi_encoding = "s"]
107#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
108#[repr(transparent)]
109pub struct c_short(pub core::ffi::c_short);
110
111/// CFI type equivalent to Rust's core::ffi::c_uchar type alias.
112#[cfg(sanitizer_cfi_normalize_integers)]
113#[allow(dead_code)]
114#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
115#[repr(transparent)]
116pub struct c_uchar(pub core::ffi::c_uchar);
117
118/// CFI type equivalent to Rust's core::ffi::c_uchar type alias.
119#[cfg(not(sanitizer_cfi_normalize_integers))]
120#[allow(dead_code)]
121#[cfi_encoding = "h"]
122#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
123#[repr(transparent)]
124pub struct c_uchar(pub core::ffi::c_uchar);
125
126/// CFI type equivalent to Rust's core::ffi::c_uint type alias.
127#[cfg(sanitizer_cfi_normalize_integers)]
128#[allow(dead_code)]
129#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
130#[repr(transparent)]
131pub struct c_uint(pub core::ffi::c_uint);
132
133/// CFI type equivalent to Rust's core::ffi::c_uint type alias.
134#[cfg(not(sanitizer_cfi_normalize_integers))]
135#[allow(dead_code)]
136#[cfi_encoding = "j"]
137#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
138#[repr(transparent)]
139pub struct c_uint(pub core::ffi::c_uint);
140
141/// CFI type equivalent to Rust's core::ffi::c_ulong type alias.
142#[cfg(sanitizer_cfi_normalize_integers)]
143#[allow(dead_code)]
144#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
145#[repr(transparent)]
146pub struct c_ulong(pub core::ffi::c_ulong);
147
148/// CFI type equivalent to Rust's core::ffi::c_ulong type alias.
149#[cfg(not(sanitizer_cfi_normalize_integers))]
150#[allow(dead_code)]
151#[cfi_encoding = "m"]
152#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
153#[repr(transparent)]
154pub struct c_ulong(pub core::ffi::c_ulong);
155
156/// CFI type equivalent to Rust's core::ffi::c_ulonglong type alias.
157#[cfg(sanitizer_cfi_normalize_integers)]
158#[allow(dead_code)]
159#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
160#[repr(transparent)]
161pub struct c_ulonglong(pub core::ffi::c_ulonglong);
162
163/// CFI type equivalent to Rust's core::ffi::c_ulonglong type alias.
164#[cfg(not(sanitizer_cfi_normalize_integers))]
165#[allow(dead_code)]
166#[cfi_encoding = "y"]
167#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
168#[repr(transparent)]
169pub struct c_ulonglong(pub core::ffi::c_ulonglong);
170
171/// CFI type equivalent to Rust's core::ffi::c_ushort type alias.
172#[cfg(sanitizer_cfi_normalize_integers)]
173#[allow(dead_code)]
174#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
175#[repr(transparent)]
176pub struct c_ushort(pub core::ffi::c_ushort);
177
178/// CFI type equivalent to Rust's core::ffi::c_ushort type alias.
179#[cfg(not(sanitizer_cfi_normalize_integers))]
180#[allow(dead_code)]
181#[cfi_encoding = "t"]
182#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
183#[repr(transparent)]
184pub struct c_ushort(pub core::ffi::c_ushort);