1 //! 32-bit specific definitions for linux-like values
2 
3 use pthread_mutex_t;
4 
5 pub type c_long = i32;
6 pub type c_ulong = u32;
7 pub type clock_t = i32;
8 
9 pub type shmatt_t = ::c_ulong;
10 pub type msgqnum_t = ::c_ulong;
11 pub type msglen_t = ::c_ulong;
12 pub type nlink_t = u32;
13 pub type __u64 = ::c_ulonglong;
14 pub type __fsword_t = i32;
15 pub type fsblkcnt64_t = u64;
16 pub type fsfilcnt64_t = u64;
17 pub type __syscall_ulong_t = ::c_ulong;
18 
19 cfg_if! {
20     if #[cfg(target_arch = "riscv32")] {
21         pub type time_t = i64;
22         pub type suseconds_t = i64;
23         pub type ino_t = u64;
24         pub type off_t = i64;
25         pub type blkcnt_t = i64;
26         pub type fsblkcnt_t = u64;
27         pub type fsfilcnt_t = u64;
28         pub type rlim_t = u64;
29         pub type blksize_t = i64;
30     } else {
31         pub type time_t = i32;
32         pub type suseconds_t = i32;
33         pub type ino_t = u32;
34         pub type off_t = i32;
35         pub type blkcnt_t = i32;
36         pub type fsblkcnt_t = ::c_ulong;
37         pub type fsfilcnt_t = ::c_ulong;
38         pub type rlim_t = c_ulong;
39         pub type blksize_t = i32;
40     }
41 }
42 
43 s! {
44     pub struct stat {
45         #[cfg(not(target_arch = "mips"))]
46         pub st_dev: ::dev_t,
47         #[cfg(target_arch = "mips")]
48         pub st_dev: ::c_ulong,
49 
50         #[cfg(not(target_arch = "mips"))]
51         __pad1: ::c_short,
52         #[cfg(target_arch = "mips")]
53         st_pad1: [::c_long; 3],
54         pub st_ino: ::ino_t,
55         pub st_mode: ::mode_t,
56         pub st_nlink: ::nlink_t,
57         pub st_uid: ::uid_t,
58         pub st_gid: ::gid_t,
59         #[cfg(not(target_arch = "mips"))]
60         pub st_rdev: ::dev_t,
61         #[cfg(target_arch = "mips")]
62         pub st_rdev: ::c_ulong,
63         #[cfg(not(target_arch = "mips"))]
64         __pad2: ::c_short,
65         #[cfg(target_arch = "mips")]
66         st_pad2: [::c_long; 2],
67         pub st_size: ::off_t,
68         #[cfg(target_arch = "mips")]
69         st_pad3: ::c_long,
70         #[cfg(not(target_arch = "mips"))]
71         pub st_blksize: ::blksize_t,
72         #[cfg(not(target_arch = "mips"))]
73         pub st_blocks: ::blkcnt_t,
74         pub st_atime: ::time_t,
75         pub st_atime_nsec: ::c_long,
76         pub st_mtime: ::time_t,
77         pub st_mtime_nsec: ::c_long,
78         pub st_ctime: ::time_t,
79         pub st_ctime_nsec: ::c_long,
80         #[cfg(not(target_arch = "mips"))]
81         __unused4: ::c_long,
82         #[cfg(not(target_arch = "mips"))]
83         __unused5: ::c_long,
84         #[cfg(target_arch = "mips")]
85         pub st_blksize: ::blksize_t,
86         #[cfg(target_arch = "mips")]
87         pub st_blocks: ::blkcnt_t,
88         #[cfg(target_arch = "mips")]
89         st_pad5: [::c_long; 14],
90     }
91 
92     pub struct statvfs {
93         pub f_bsize: ::c_ulong,
94         pub f_frsize: ::c_ulong,
95         pub f_blocks: ::fsblkcnt_t,
96         pub f_bfree: ::fsblkcnt_t,
97         pub f_bavail: ::fsblkcnt_t,
98         pub f_files: ::fsfilcnt_t,
99         pub f_ffree: ::fsfilcnt_t,
100         pub f_favail: ::fsfilcnt_t,
101         pub f_fsid: ::c_ulong,
102         __f_unused: ::c_int,
103         pub f_flag: ::c_ulong,
104         pub f_namemax: ::c_ulong,
105         __f_spare: [::c_int; 6],
106     }
107 
108     pub struct pthread_attr_t {
109         __size: [u32; 9]
110     }
111 
112     pub struct sigset_t {
113         __val: [::c_ulong; 32],
114     }
115 
116     pub struct sysinfo {
117         pub uptime: ::c_long,
118         pub loads: [::c_ulong; 3],
119         pub totalram: ::c_ulong,
120         pub freeram: ::c_ulong,
121         pub sharedram: ::c_ulong,
122         pub bufferram: ::c_ulong,
123         pub totalswap: ::c_ulong,
124         pub freeswap: ::c_ulong,
125         pub procs: ::c_ushort,
126         #[deprecated(
127             since = "0.2.58",
128             note = "This padding field might become private in the future"
129         )]
130         pub pad: ::c_ushort,
131         pub totalhigh: ::c_ulong,
132         pub freehigh: ::c_ulong,
133         pub mem_unit: ::c_uint,
134         pub _f: [::c_char; 8],
135     }
136 
137     pub struct ip_mreqn {
138         pub imr_multiaddr: ::in_addr,
139         pub imr_address: ::in_addr,
140         pub imr_ifindex: ::c_int,
141     }
142 
143     pub struct semid_ds {
144         pub sem_perm: ipc_perm,
145         #[cfg(target_arch = "powerpc")]
146         __reserved: ::__syscall_ulong_t,
147         pub sem_otime: ::time_t,
148         #[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))]
149         __reserved: ::__syscall_ulong_t,
150         #[cfg(target_arch = "powerpc")]
151         __reserved2: ::__syscall_ulong_t,
152         pub sem_ctime: ::time_t,
153         #[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))]
154         __reserved2: ::__syscall_ulong_t,
155         pub sem_nsems: ::__syscall_ulong_t,
156         __glibc_reserved3: ::__syscall_ulong_t,
157         __glibc_reserved4: ::__syscall_ulong_t,
158     }
159 }
160 
161 pub const POSIX_FADV_DONTNEED: ::c_int = 4;
162 pub const POSIX_FADV_NOREUSE: ::c_int = 5;
163 
164 pub const F_OFD_GETLK: ::c_int = 36;
165 pub const F_OFD_SETLK: ::c_int = 37;
166 pub const F_OFD_SETLKW: ::c_int = 38;
167 
168 pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
169 pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 24;
170 pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32;
171 pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
172 pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;
173 
174 cfg_if! {
175     if #[cfg(target_arch = "sparc")] {
176         pub const O_NOATIME: ::c_int = 0x200000;
177         pub const O_PATH: ::c_int = 0x1000000;
178         pub const O_TMPFILE: ::c_int = 0x2000000 | O_DIRECTORY;
179 
180         pub const SA_ONSTACK: ::c_int = 1;
181 
182         pub const PTRACE_DETACH: ::c_uint = 11;
183 
184         pub const F_SETLK: ::c_int = 8;
185         pub const F_SETLKW: ::c_int = 9;
186 
187         pub const F_RDLCK: ::c_int = 1;
188         pub const F_WRLCK: ::c_int = 2;
189         pub const F_UNLCK: ::c_int = 3;
190 
191         pub const SFD_CLOEXEC: ::c_int = 0x400000;
192 
193         pub const NCCS: usize = 17;
194 
195         pub const O_TRUNC: ::c_int = 0x400;
196         pub const O_CLOEXEC: ::c_int = 0x400000;
197 
198         pub const EBFONT: ::c_int = 109;
199         pub const ENOSTR: ::c_int = 72;
200         pub const ENODATA: ::c_int = 111;
201         pub const ETIME: ::c_int = 73;
202         pub const ENOSR: ::c_int = 74;
203         pub const ENONET: ::c_int = 80;
204         pub const ENOPKG: ::c_int = 113;
205         pub const EREMOTE: ::c_int = 71;
206         pub const ENOLINK: ::c_int = 82;
207         pub const EADV: ::c_int = 83;
208         pub const ESRMNT: ::c_int = 84;
209         pub const ECOMM: ::c_int = 85;
210         pub const EPROTO: ::c_int = 86;
211         pub const EDOTDOT: ::c_int = 88;
212 
213         pub const SA_NODEFER: ::c_int = 0x20;
214         pub const SA_RESETHAND: ::c_int = 0x4;
215         pub const SA_RESTART: ::c_int = 0x2;
216         pub const SA_NOCLDSTOP: ::c_int = 0x00000008;
217 
218         pub const EPOLL_CLOEXEC: ::c_int = 0x400000;
219 
220         pub const EFD_CLOEXEC: ::c_int = 0x400000;
221     } else {
222         pub const O_NOATIME: ::c_int = 0o1000000;
223         pub const O_PATH: ::c_int = 0o10000000;
224         pub const O_TMPFILE: ::c_int = 0o20000000 | O_DIRECTORY;
225 
226         pub const SA_ONSTACK: ::c_int = 0x08000000;
227 
228         pub const PTRACE_DETACH: ::c_uint = 17;
229 
230         pub const F_SETLK: ::c_int = 6;
231         pub const F_SETLKW: ::c_int = 7;
232 
233         pub const F_RDLCK: ::c_int = 0;
234         pub const F_WRLCK: ::c_int = 1;
235         pub const F_UNLCK: ::c_int = 2;
236 
237         pub const SFD_CLOEXEC: ::c_int = 0x080000;
238 
239         pub const NCCS: usize = 32;
240 
241         pub const O_TRUNC: ::c_int = 512;
242         pub const O_CLOEXEC: ::c_int = 0x80000;
243         pub const EBFONT: ::c_int = 59;
244         pub const ENOSTR: ::c_int = 60;
245         pub const ENODATA: ::c_int = 61;
246         pub const ETIME: ::c_int = 62;
247         pub const ENOSR: ::c_int = 63;
248         pub const ENONET: ::c_int = 64;
249         pub const ENOPKG: ::c_int = 65;
250         pub const EREMOTE: ::c_int = 66;
251         pub const ENOLINK: ::c_int = 67;
252         pub const EADV: ::c_int = 68;
253         pub const ESRMNT: ::c_int = 69;
254         pub const ECOMM: ::c_int = 70;
255         pub const EPROTO: ::c_int = 71;
256         pub const EDOTDOT: ::c_int = 73;
257 
258         pub const SA_NODEFER: ::c_int = 0x40000000;
259         pub const SA_RESETHAND: ::c_int = 0x80000000;
260         pub const SA_RESTART: ::c_int = 0x10000000;
261         pub const SA_NOCLDSTOP: ::c_int = 0x00000001;
262 
263         pub const EPOLL_CLOEXEC: ::c_int = 0x80000;
264 
265         pub const EFD_CLOEXEC: ::c_int = 0x80000;
266     }
267 }
268 
269 align_const! {
270     #[cfg(target_endian = "little")]
271     pub const PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t =
272         pthread_mutex_t {
273             size: [
274                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
275                 0, 0, 0,
276             ],
277         };
278     #[cfg(target_endian = "little")]
279     pub const PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP: ::pthread_mutex_t =
280         pthread_mutex_t {
281             size: [
282                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0,
283                 0, 0, 0,
284             ],
285         };
286     #[cfg(target_endian = "little")]
287     pub const PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t =
288         pthread_mutex_t {
289             size: [
290                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0,
291                 0, 0, 0,
292             ],
293         };
294     #[cfg(target_endian = "big")]
295     pub const PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t =
296         pthread_mutex_t {
297             size: [
298                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
299                 0, 0, 0,
300             ],
301         };
302     #[cfg(target_endian = "big")]
303     pub const PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP: ::pthread_mutex_t =
304         pthread_mutex_t {
305             size: [
306                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0,
307                 0, 0, 0,
308             ],
309         };
310     #[cfg(target_endian = "big")]
311     pub const PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t =
312         pthread_mutex_t {
313             size: [
314                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0,
315                 0, 0, 0,
316             ],
317         };
318 }
319 
320 pub const PTRACE_GETFPREGS: ::c_uint = 14;
321 pub const PTRACE_SETFPREGS: ::c_uint = 15;
322 pub const PTRACE_GETREGS: ::c_uint = 12;
323 pub const PTRACE_SETREGS: ::c_uint = 13;
324 
325 pub const TIOCSBRK: ::c_int = 0x5427;
326 pub const TIOCCBRK: ::c_int = 0x5428;
327 
328 extern "C" {
sysctl( name: *mut ::c_int, namelen: ::c_int, oldp: *mut ::c_void, oldlenp: *mut ::size_t, newp: *mut ::c_void, newlen: ::size_t, ) -> ::c_int329     pub fn sysctl(
330         name: *mut ::c_int,
331         namelen: ::c_int,
332         oldp: *mut ::c_void,
333         oldlenp: *mut ::size_t,
334         newp: *mut ::c_void,
335         newlen: ::size_t,
336     ) -> ::c_int;
337 }
338 
339 cfg_if! {
340     if #[cfg(target_arch = "x86")] {
341         mod x86;
342         pub use self::x86::*;
343     } else if #[cfg(target_arch = "arm")] {
344         mod arm;
345         pub use self::arm::*;
346     } else if #[cfg(target_arch = "mips")] {
347         mod mips;
348         pub use self::mips::*;
349     } else if #[cfg(target_arch = "powerpc")] {
350         mod powerpc;
351         pub use self::powerpc::*;
352     } else if #[cfg(target_arch = "sparc")] {
353         mod sparc;
354         pub use self::sparc::*;
355     } else if #[cfg(target_arch = "riscv32")] {
356         mod riscv32;
357         pub use self::riscv32::*;
358     } else {
359         // Unknown target_arch
360     }
361 }
362