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 SFD_CLOEXEC: ::c_int = 0x080000;
147 
148 pub const NCCS: usize = 32;
149 
150 pub const O_TRUNC: ::c_int = 512;
151 
152 pub const O_CLOEXEC: ::c_int = 0x80000;
153 
154 pub const EBFONT: ::c_int = 59;
155 pub const ENOSTR: ::c_int = 60;
156 pub const ENODATA: ::c_int = 61;
157 pub const ETIME: ::c_int = 62;
158 pub const ENOSR: ::c_int = 63;
159 pub const ENONET: ::c_int = 64;
160 pub const ENOPKG: ::c_int = 65;
161 pub const EREMOTE: ::c_int = 66;
162 pub const ENOLINK: ::c_int = 67;
163 pub const EADV: ::c_int = 68;
164 pub const ESRMNT: ::c_int = 69;
165 pub const ECOMM: ::c_int = 70;
166 pub const EPROTO: ::c_int = 71;
167 pub const EDOTDOT: ::c_int = 73;
168 
169 pub const SA_NODEFER: ::c_int = 0x40000000;
170 pub const SA_RESETHAND: ::c_int = 0x80000000;
171 pub const SA_RESTART: ::c_int = 0x10000000;
172 pub const SA_NOCLDSTOP: ::c_int = 0x00000001;
173 
174 pub const EPOLL_CLOEXEC: ::c_int = 0x80000;
175 
176 pub const EFD_CLOEXEC: ::c_int = 0x80000;
177 
178 pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
179 pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 24;
180 pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32;
181 pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
182 pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;
183 
184 align_const! {
185     #[cfg(target_endian = "little")]
186     pub const PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t =
187         pthread_mutex_t {
188             size: [
189                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
190                 0, 0, 0,
191             ],
192         };
193     #[cfg(target_endian = "little")]
194     pub const PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP: ::pthread_mutex_t =
195         pthread_mutex_t {
196             size: [
197                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0,
198                 0, 0, 0,
199             ],
200         };
201     #[cfg(target_endian = "little")]
202     pub const PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t =
203         pthread_mutex_t {
204             size: [
205                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0,
206                 0, 0, 0,
207             ],
208         };
209     #[cfg(target_endian = "big")]
210     pub const PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t =
211         pthread_mutex_t {
212             size: [
213                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
214                 0, 0, 0,
215             ],
216         };
217     #[cfg(target_endian = "big")]
218     pub const PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP: ::pthread_mutex_t =
219         pthread_mutex_t {
220             size: [
221                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0,
222                 0, 0, 0,
223             ],
224         };
225     #[cfg(target_endian = "big")]
226     pub const PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP: ::pthread_mutex_t =
227         pthread_mutex_t {
228             size: [
229                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0,
230                 0, 0, 0,
231             ],
232         };
233 }
234 
235 pub const PTRACE_GETFPREGS: ::c_uint = 14;
236 pub const PTRACE_SETFPREGS: ::c_uint = 15;
237 pub const PTRACE_GETREGS: ::c_uint = 12;
238 pub const PTRACE_SETREGS: ::c_uint = 13;
239 
240 #[link(name = "util")]
241 extern {
sysctl(name: *mut ::c_int, namelen: ::c_int, oldp: *mut ::c_void, oldlenp: *mut ::size_t, newp: *mut ::c_void, newlen: ::size_t) -> ::c_int242     pub fn sysctl(name: *mut ::c_int,
243                   namelen: ::c_int,
244                   oldp: *mut ::c_void,
245                   oldlenp: *mut ::size_t,
246                   newp: *mut ::c_void,
247                   newlen: ::size_t)
248                   -> ::c_int;
249 }
250 
251 cfg_if! {
252     if #[cfg(target_arch = "x86")] {
253         mod x86;
254         pub use self::x86::*;
255     } else if #[cfg(target_arch = "arm")] {
256         mod arm;
257         pub use self::arm::*;
258     } else if #[cfg(target_arch = "mips")] {
259         mod mips;
260         pub use self::mips::*;
261     } else if #[cfg(target_arch = "powerpc")] {
262         mod powerpc;
263         pub use self::powerpc::*;
264     } else {
265         // Unknown target_arch
266     }
267 }
268