1 use crate::prelude::*;
2 
3 // The following definitions are correct for arm and i686,
4 // but may be wrong for mips
5 
6 pub type mode_t = u16;
7 pub type off64_t = c_longlong;
8 pub type sigset_t = c_ulong;
9 pub type socklen_t = i32;
10 pub type time64_t = i64;
11 pub type __u64 = c_ulonglong;
12 pub type __s64 = c_longlong;
13 
14 s! {
15     // FIXME(1.0): This should not implement `PartialEq`
16     #[allow(unpredictable_function_pointer_comparisons)]
17     pub struct sigaction {
18         pub sa_sigaction: crate::sighandler_t,
19         pub sa_mask: crate::sigset_t,
20         pub sa_flags: c_int,
21         pub sa_restorer: Option<extern "C" fn()>,
22     }
23 
24     pub struct rlimit64 {
25         pub rlim_cur: u64,
26         pub rlim_max: u64,
27     }
28 
29     pub struct stat {
30         pub st_dev: c_ulonglong,
31         __pad0: [c_uchar; 4],
32         __st_ino: crate::ino_t,
33         pub st_mode: c_uint,
34         pub st_nlink: crate::nlink_t,
35         pub st_uid: crate::uid_t,
36         pub st_gid: crate::gid_t,
37         pub st_rdev: c_ulonglong,
38         __pad3: [c_uchar; 4],
39         pub st_size: c_longlong,
40         pub st_blksize: crate::blksize_t,
41         pub st_blocks: c_ulonglong,
42         pub st_atime: c_long,
43         pub st_atime_nsec: c_long,
44         pub st_mtime: c_long,
45         pub st_mtime_nsec: c_long,
46         pub st_ctime: c_long,
47         pub st_ctime_nsec: c_long,
48         pub st_ino: c_ulonglong,
49     }
50 
51     pub struct stat64 {
52         pub st_dev: c_ulonglong,
53         __pad0: [c_uchar; 4],
54         __st_ino: crate::ino_t,
55         pub st_mode: c_uint,
56         pub st_nlink: crate::nlink_t,
57         pub st_uid: crate::uid_t,
58         pub st_gid: crate::gid_t,
59         pub st_rdev: c_ulonglong,
60         __pad3: [c_uchar; 4],
61         pub st_size: c_longlong,
62         pub st_blksize: crate::blksize_t,
63         pub st_blocks: c_ulonglong,
64         pub st_atime: c_long,
65         pub st_atime_nsec: c_long,
66         pub st_mtime: c_long,
67         pub st_mtime_nsec: c_long,
68         pub st_ctime: c_long,
69         pub st_ctime_nsec: c_long,
70         pub st_ino: c_ulonglong,
71     }
72 
73     pub struct statfs64 {
74         pub f_type: u32,
75         pub f_bsize: u32,
76         pub f_blocks: u64,
77         pub f_bfree: u64,
78         pub f_bavail: u64,
79         pub f_files: u64,
80         pub f_ffree: u64,
81         pub f_fsid: crate::__fsid_t,
82         pub f_namelen: u32,
83         pub f_frsize: u32,
84         pub f_flags: u32,
85         pub f_spare: [u32; 4],
86     }
87 
88     pub struct statvfs64 {
89         pub f_bsize: c_ulong,
90         pub f_frsize: c_ulong,
91         pub f_blocks: c_ulong,
92         pub f_bfree: c_ulong,
93         pub f_bavail: c_ulong,
94         pub f_files: c_ulong,
95         pub f_ffree: c_ulong,
96         pub f_favail: c_ulong,
97         pub f_fsid: c_ulong,
98         pub f_flag: c_ulong,
99         pub f_namemax: c_ulong,
100     }
101 
102     pub struct pthread_attr_t {
103         pub flags: u32,
104         pub stack_base: *mut c_void,
105         pub stack_size: size_t,
106         pub guard_size: size_t,
107         pub sched_policy: i32,
108         pub sched_priority: i32,
109     }
110 
111     pub struct pthread_mutex_t {
112         value: c_int,
113     }
114 
115     pub struct pthread_cond_t {
116         value: c_int,
117     }
118 
119     pub struct pthread_rwlock_t {
120         lock: pthread_mutex_t,
121         cond: pthread_cond_t,
122         numLocks: c_int,
123         writerThreadId: c_int,
124         pendingReaders: c_int,
125         pendingWriters: c_int,
126         attr: i32,
127         __reserved: [c_char; 12],
128     }
129 
130     pub struct pthread_barrier_t {
131         __private: [i32; 8],
132     }
133 
134     pub struct pthread_spinlock_t {
135         __private: [i32; 2],
136     }
137 
138     pub struct passwd {
139         pub pw_name: *mut c_char,
140         pub pw_passwd: *mut c_char,
141         pub pw_uid: crate::uid_t,
142         pub pw_gid: crate::gid_t,
143         pub pw_dir: *mut c_char,
144         pub pw_shell: *mut c_char,
145     }
146 
147     pub struct statfs {
148         pub f_type: u32,
149         pub f_bsize: u32,
150         pub f_blocks: u64,
151         pub f_bfree: u64,
152         pub f_bavail: u64,
153         pub f_files: u64,
154         pub f_ffree: u64,
155         pub f_fsid: crate::__fsid_t,
156         pub f_namelen: u32,
157         pub f_frsize: u32,
158         pub f_flags: u32,
159         pub f_spare: [u32; 4],
160     }
161 
162     pub struct sysinfo {
163         pub uptime: c_long,
164         pub loads: [c_ulong; 3],
165         pub totalram: c_ulong,
166         pub freeram: c_ulong,
167         pub sharedram: c_ulong,
168         pub bufferram: c_ulong,
169         pub totalswap: c_ulong,
170         pub freeswap: c_ulong,
171         pub procs: c_ushort,
172         pub pad: c_ushort,
173         pub totalhigh: c_ulong,
174         pub freehigh: c_ulong,
175         pub mem_unit: c_uint,
176         pub _f: [c_char; 8],
177     }
178 }
179 
180 s_no_extra_traits! {
181     pub struct sigset64_t {
182         __bits: [c_ulong; 2],
183     }
184 }
185 
186 // These constants must be of the same type of sigaction.sa_flags
187 pub const SA_NOCLDSTOP: c_int = 0x00000001;
188 pub const SA_NOCLDWAIT: c_int = 0x00000002;
189 pub const SA_NODEFER: c_int = 0x40000000;
190 pub const SA_ONSTACK: c_int = 0x08000000;
191 pub const SA_RESETHAND: c_int = 0x80000000;
192 pub const SA_RESTART: c_int = 0x10000000;
193 pub const SA_SIGINFO: c_int = 0x00000004;
194 
195 pub const RTLD_GLOBAL: c_int = 2;
196 pub const RTLD_NOW: c_int = 0;
197 pub const RTLD_DEFAULT: *mut c_void = -1isize as *mut c_void;
198 
199 pub const PTRACE_GETFPREGS: c_int = 14;
200 pub const PTRACE_SETFPREGS: c_int = 15;
201 
202 pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { value: 0 };
203 pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { value: 0 };
204 pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
205     lock: PTHREAD_MUTEX_INITIALIZER,
206     cond: PTHREAD_COND_INITIALIZER,
207     numLocks: 0,
208     writerThreadId: 0,
209     pendingReaders: 0,
210     pendingWriters: 0,
211     attr: 0,
212     __reserved: [0; 12],
213 };
214 pub const PTHREAD_STACK_MIN: size_t = 4096 * 2;
215 pub const CPU_SETSIZE: size_t = 32;
216 pub const __CPU_BITS: size_t = 32;
217 
218 pub const UT_LINESIZE: usize = 8;
219 pub const UT_NAMESIZE: usize = 8;
220 pub const UT_HOSTSIZE: usize = 16;
221 
222 pub const SIGSTKSZ: size_t = 8192;
223 pub const MINSIGSTKSZ: size_t = 2048;
224 
225 extern "C" {
timegm64(tm: *const crate::tm) -> crate::time64_t226     pub fn timegm64(tm: *const crate::tm) -> crate::time64_t;
227 }
228 
229 cfg_if! {
230     if #[cfg(target_arch = "x86")] {
231         mod x86;
232         pub use self::x86::*;
233     } else if #[cfg(target_arch = "arm")] {
234         mod arm;
235         pub use self::arm::*;
236     } else {
237         // Unknown target_arch
238     }
239 }
240