-
Notifications
You must be signed in to change notification settings - Fork 995
/
mod.rs
475 lines (430 loc) · 14.1 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
// The following definitions are correct for aarch64 and x86_64,
// but may be wrong for mips64
pub type c_long = i64;
pub type c_ulong = u64;
pub type mode_t = u32;
pub type off64_t = i64;
pub type socklen_t = u32;
s! {
pub struct sigset_t {
__val: [::c_ulong; 1],
}
pub struct sigaction {
pub sa_flags: ::c_int,
pub sa_sigaction: ::sighandler_t,
pub sa_mask: ::sigset_t,
pub sa_restorer: ::Option<extern fn()>,
}
pub struct rlimit64 {
pub rlim_cur: ::c_ulonglong,
pub rlim_max: ::c_ulonglong,
}
pub struct pthread_attr_t {
pub flags: u32,
pub stack_base: *mut ::c_void,
pub stack_size: ::size_t,
pub guard_size: ::size_t,
pub sched_policy: i32,
pub sched_priority: i32,
__reserved: [::c_char; 16],
}
pub struct passwd {
pub pw_name: *mut ::c_char,
pub pw_passwd: *mut ::c_char,
pub pw_uid: ::uid_t,
pub pw_gid: ::gid_t,
pub pw_gecos: *mut ::c_char,
pub pw_dir: *mut ::c_char,
pub pw_shell: *mut ::c_char,
}
pub struct statfs {
pub f_type: u64,
pub f_bsize: u64,
pub f_blocks: u64,
pub f_bfree: u64,
pub f_bavail: u64,
pub f_files: u64,
pub f_ffree: u64,
pub f_fsid: ::__fsid_t,
pub f_namelen: u64,
pub f_frsize: u64,
pub f_flags: u64,
pub f_spare: [u64; 4],
}
pub struct sysinfo {
pub uptime: ::c_long,
pub loads: [::c_ulong; 3],
pub totalram: ::c_ulong,
pub freeram: ::c_ulong,
pub sharedram: ::c_ulong,
pub bufferram: ::c_ulong,
pub totalswap: ::c_ulong,
pub freeswap: ::c_ulong,
pub procs: ::c_ushort,
pub pad: ::c_ushort,
pub totalhigh: ::c_ulong,
pub freehigh: ::c_ulong,
pub mem_unit: ::c_uint,
pub _f: [::c_char; 0],
}
pub struct statfs64 {
pub f_type: u64,
pub f_bsize: u64,
pub f_blocks: u64,
pub f_bfree: u64,
pub f_bavail: u64,
pub f_files: u64,
pub f_ffree: u64,
pub f_fsid: ::__fsid_t,
pub f_namelen: u64,
pub f_frsize: u64,
pub f_flags: u64,
pub f_spare: [u64; 4],
}
pub struct statvfs64 {
pub f_bsize: ::c_ulong,
pub f_frsize: ::c_ulong,
pub f_blocks: u64,
pub f_bfree: u64,
pub f_bavail: u64,
pub f_files: u64,
pub f_ffree: u64,
pub f_favail: u64,
pub f_fsid: ::c_ulong,
pub f_flag: ::c_ulong,
pub f_namemax: ::c_ulong,
__f_spare: [::c_int; 6],
}
pub struct pthread_barrier_t {
__private: [i64; 4],
}
pub struct pthread_spinlock_t {
__private: i64,
}
pub struct user_regs_struct {
pub r15: ::c_ulong,
pub r14: ::c_ulong,
pub r13: ::c_ulong,
pub r12: ::c_ulong,
pub rbp: ::c_ulong,
pub rbx: ::c_ulong,
pub r11: ::c_ulong,
pub r10: ::c_ulong,
pub r9: ::c_ulong,
pub r8: ::c_ulong,
pub rax: ::c_ulong,
pub rcx: ::c_ulong,
pub rdx: ::c_ulong,
pub rsi: ::c_ulong,
pub rdi: ::c_ulong,
pub orig_rax: ::c_ulong,
pub rip: ::c_ulong,
pub cs: ::c_ulong,
pub eflags: ::c_ulong,
pub rsp: ::c_ulong,
pub ss: ::c_ulong,
pub fs_base: ::c_ulong,
pub gs_base: ::c_ulong,
pub ds: ::c_ulong,
pub es: ::c_ulong,
pub fs: ::c_ulong,
pub gs: ::c_ulong,
}
pub struct user {
pub regs: user_regs_struct,
pub u_fpvalid: ::c_int,
pub i387: user_fpregs_struct,
pub u_tsize: ::c_ulong,
pub u_dsize: ::c_ulong,
pub u_ssize: ::c_ulong,
pub start_code: ::c_ulong,
pub start_stack: ::c_ulong,
pub signal: ::c_long,
__reserved: ::c_int,
#[cfg(target_pointer_width = "32")]
__pad1: u32,
pub u_ar0: *mut user_regs_struct,
#[cfg(target_pointer_width = "32")]
__pad2: u32,
pub u_fpstate: *mut user_fpregs_struct,
pub magic: ::c_ulong,
pub u_comm: [::c_char; 32],
pub u_debugreg: [::c_ulong; 8],
pub error_code: ::c_ulong,
pub fault_address: ::c_ulong,
}
}
s_no_extra_traits! {
pub struct pthread_mutex_t {
value: ::c_int,
__reserved: [::c_char; 36],
}
pub struct pthread_cond_t {
value: ::c_int,
__reserved: [::c_char; 44],
}
pub struct pthread_rwlock_t {
numLocks: ::c_int,
writerThreadId: ::c_int,
pendingReaders: ::c_int,
pendingWriters: ::c_int,
attr: i32,
__reserved: [::c_char; 36],
}
pub struct sigset64_t {
__bits: [::c_ulong; 1]
}
pub struct user_fpregs_struct {
pub cwd: ::c_ushort,
pub swd: ::c_ushort,
pub ftw: ::c_ushort,
pub fop: ::c_ushort,
pub rip: ::c_ulong,
pub rdp: ::c_ulong,
pub mxcsr: ::c_uint,
pub mxcr_mask: ::c_uint,
pub st_space: [::c_uint; 32],
pub xmm_space: [::c_uint; 64],
padding: [::c_uint; 24],
}
}
cfg_if! {
if #[cfg(feature = "extra_traits")] {
impl PartialEq for pthread_mutex_t {
fn eq(&self, other: &pthread_mutex_t) -> bool {
self.value == other.value
&& self
.__reserved
.iter()
.zip(other.__reserved.iter())
.all(|(a,b)| a == b)
}
}
impl Eq for pthread_mutex_t {}
impl ::fmt::Debug for pthread_mutex_t {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("pthread_mutex_t")
.field("value", &self.value)
// FIXME: .field("__reserved", &self.__reserved)
.finish()
}
}
impl ::hash::Hash for pthread_mutex_t {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.value.hash(state);
self.__reserved.hash(state);
}
}
impl PartialEq for pthread_cond_t {
fn eq(&self, other: &pthread_cond_t) -> bool {
self.value == other.value
&& self
.__reserved
.iter()
.zip(other.__reserved.iter())
.all(|(a,b)| a == b)
}
}
impl Eq for pthread_cond_t {}
impl ::fmt::Debug for pthread_cond_t {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("pthread_cond_t")
.field("value", &self.value)
// FIXME: .field("__reserved", &self.__reserved)
.finish()
}
}
impl ::hash::Hash for pthread_cond_t {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.value.hash(state);
self.__reserved.hash(state);
}
}
impl PartialEq for pthread_rwlock_t {
fn eq(&self, other: &pthread_rwlock_t) -> bool {
self.numLocks == other.numLocks
&& self.writerThreadId == other.writerThreadId
&& self.pendingReaders == other.pendingReaders
&& self.pendingWriters == other.pendingWriters
&& self.attr == other.attr
&& self
.__reserved
.iter()
.zip(other.__reserved.iter())
.all(|(a,b)| a == b)
}
}
impl Eq for pthread_rwlock_t {}
impl ::fmt::Debug for pthread_rwlock_t {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("pthread_rwlock_t")
.field("numLocks", &self.numLocks)
.field("writerThreadId", &self.writerThreadId)
.field("pendingReaders", &self.pendingReaders)
.field("pendingWriters", &self.pendingWriters)
.field("attr", &self.attr)
// FIXME: .field("__reserved", &self.__reserved)
.finish()
}
}
impl ::hash::Hash for pthread_rwlock_t {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.numLocks.hash(state);
self.writerThreadId.hash(state);
self.pendingReaders.hash(state);
self.pendingWriters.hash(state);
self.attr.hash(state);
self.__reserved.hash(state);
}
}
impl ::fmt::Debug for sigset64_t {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("sigset64_t")
.field("__bits", &self.__bits)
.finish()
}
}
impl PartialEq for user_fpregs_struct {
fn eq(&self, other: &user_fpregs_struct) -> bool {
self.cwd == other.cwd
&& self.swd == other.swd
&& self.ftw == other.ftw
&& self.fop == other.fop
&& self.rip == other.rip
&& self.rdp == other.rdp
&& self.mxcsr == other.mxcsr
&& self.mxcr_mask == other.mxcr_mask
&& self.st_space == other.st_space
&& self
.xmm_space
.iter()
.zip(other.xmm_space.iter())
.all(|(a,b)| a == b)
// Ignore padding field
}
}
impl Eq for user_fpregs_struct {}
impl ::fmt::Debug for user_fpregs_struct {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("user_fpregs_struct")
.field("cwd", &self.cwd)
.field("ftw", &self.ftw)
.field("fop", &self.fop)
.field("rip", &self.rip)
.field("rdp", &self.rdp)
.field("mxcsr", &self.mxcsr)
.field("mxcr_mask", &self.mxcr_mask)
.field("st_space", &self.st_space)
// FIXME: .field("xmm_space", &self.xmm_space)
// Ignore padding field
.finish()
}
}
impl ::hash::Hash for user_fpregs_struct {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.cwd.hash(state);
self.ftw.hash(state);
self.fop.hash(state);
self.rip.hash(state);
self.rdp.hash(state);
self.mxcsr.hash(state);
self.mxcr_mask.hash(state);
self.st_space.hash(state);
self.xmm_space.hash(state);
// Ignore padding field
}
}
}
}
// These constants must be of the same type of sigaction.sa_flags
pub const SA_NOCLDSTOP: ::c_int = 0x00000001;
pub const SA_NOCLDWAIT: ::c_int = 0x00000002;
pub const SA_NODEFER: ::c_int = 0x40000000;
pub const SA_ONSTACK: ::c_int = 0x08000000;
pub const SA_RESETHAND: ::c_int = 0x80000000;
pub const SA_RESTART: ::c_int = 0x10000000;
pub const SA_SIGINFO: ::c_int = 0x00000004;
pub const RTLD_GLOBAL: ::c_int = 0x00100;
pub const RTLD_NOW: ::c_int = 2;
pub const RTLD_DEFAULT: *mut ::c_void = 0i64 as *mut ::c_void;
// From NDK's linux/auxvec.h
pub const AT_NULL: ::c_ulong = 0;
pub const AT_IGNORE: ::c_ulong = 1;
pub const AT_EXECFD: ::c_ulong = 2;
pub const AT_PHDR: ::c_ulong = 3;
pub const AT_PHENT: ::c_ulong = 4;
pub const AT_PHNUM: ::c_ulong = 5;
pub const AT_PAGESZ: ::c_ulong = 6;
pub const AT_BASE: ::c_ulong = 7;
pub const AT_FLAGS: ::c_ulong = 8;
pub const AT_ENTRY: ::c_ulong = 9;
pub const AT_NOTELF: ::c_ulong = 10;
pub const AT_UID: ::c_ulong = 11;
pub const AT_EUID: ::c_ulong = 12;
pub const AT_GID: ::c_ulong = 13;
pub const AT_EGID: ::c_ulong = 14;
pub const AT_PLATFORM: ::c_ulong = 15;
pub const AT_HWCAP: ::c_ulong = 16;
pub const AT_CLKTCK: ::c_ulong = 17;
pub const AT_SECURE: ::c_ulong = 23;
pub const AT_BASE_PLATFORM: ::c_ulong = 24;
pub const AT_RANDOM: ::c_ulong = 25;
pub const AT_HWCAP2: ::c_ulong = 26;
pub const AT_EXECFN: ::c_ulong = 31;
pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
value: 0,
__reserved: [0; 36],
};
pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
value: 0,
__reserved: [0; 44],
};
pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
numLocks: 0,
writerThreadId: 0,
pendingReaders: 0,
pendingWriters: 0,
attr: 0,
__reserved: [0; 36],
};
pub const PTHREAD_STACK_MIN: ::size_t = 4096 * 4;
pub const CPU_SETSIZE: ::size_t = 1024;
pub const __CPU_BITS: ::size_t = 64;
pub const UT_LINESIZE: usize = 32;
pub const UT_NAMESIZE: usize = 32;
pub const UT_HOSTSIZE: usize = 256;
f! {
// Sadly, Android before 5.0 (API level 21), the accept4 syscall is not
// exposed by the libc. As work-around, we implement it through `syscall`
// directly. This workaround can be removed if the minimum version of
// Android is bumped. When the workaround is removed, `accept4` can be
// moved back to `linux_like/mod.rs`
pub fn accept4(
fd: ::c_int,
addr: *mut ::sockaddr,
len: *mut ::socklen_t,
flg: ::c_int
) -> ::c_int {
::syscall(SYS_accept4, fd, addr, len, flg) as ::c_int
}
}
extern "C" {
pub fn getauxval(type_: ::c_ulong) -> ::c_ulong;
pub fn __system_property_wait(
pi: *const ::prop_info,
__old_serial: u32,
__new_serial_ptr: *mut u32,
__relative_timeout: *const ::timespec,
) -> bool;
}
cfg_if! {
if #[cfg(target_arch = "x86_64")] {
mod x86_64;
pub use self::x86_64::*;
} else if #[cfg(target_arch = "aarch64")] {
mod aarch64;
pub use self::aarch64::*;
} else {
// Unknown target_arch
}
}