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