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