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