1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10 
11 // liblibc port for HermitCore (https://hermitcore.org)
12 // HermitCore is a unikernel based on lwIP, newlib, and
13 // pthread-embedded.
14 // Consider these definitions when porting liblibc to another
15 // lwIP/newlib/pte-based target.
16 //
17 // Ported by Colin Finck <colin.finck@rwth-aachen.de>
18 
19 pub type c_long = i64;
20 pub type c_ulong = u64;
21 
22 pub type uid_t = u16;
23 pub type gid_t = u16;
24 pub type speed_t = ::c_uint;
25 pub type mode_t = u32;
26 pub type dev_t = i16;
27 pub type nfds_t = ::c_ulong;
28 pub type socklen_t = u32;
29 pub type sa_family_t = u8;
30 pub type clock_t = c_ulong;
31 pub type time_t = c_long;
32 pub type suseconds_t = c_long;
33 pub type off_t = i64;
34 pub type rlim_t = ::c_ulonglong;
35 pub type sigset_t = ::c_ulong;
36 pub type ino_t = u16;
37 pub type nlink_t = u16;
38 pub type blksize_t = c_long;
39 pub type blkcnt_t = c_long;
40 pub type stat64 = stat;
41 pub type clockid_t = c_ulong;
42 pub type pthread_t = pte_handle_t;
43 pub type pthread_attr_t = usize;
44 pub type pthread_cond_t = usize;
45 pub type pthread_condattr_t = usize;
46 pub type pthread_key_t = usize;
LayoutControlPanel(ToggleButtonDemo demo)47 pub type pthread_mutex_t = usize;
48 pub type pthread_mutexattr_t = usize;
49 pub type pthread_rwlock_t = usize;
50 pub type pthread_rwlockattr_t = usize;
51 
52 s! {
53     pub struct in_addr {
54         pub s_addr: ::in_addr_t,
55     }
56 
57     pub struct ip_mreq {
58         pub imr_multiaddr: in_addr,
59         pub imr_interface: in_addr,
60     }
61 
62     pub struct addrinfo {
63         pub ai_flags: ::c_int,
64         pub ai_family: ::c_int,
65         pub ai_socktype: ::c_int,
66         pub ai_protocol: ::c_int,
67         pub ai_addrlen: socklen_t,
68         pub ai_addr: *mut ::sockaddr,
69         pub ai_canonname: *mut c_char,
70         pub ai_next: *mut addrinfo,
71     }
72 
73     pub struct dirent {
74         pub d_ino: ::c_long,
75         pub d_off: off_t,
76         pub d_reclen: u16,
77         pub d_name: [::c_char; 256],
78     }
79 
80     pub struct Dl_info {}
81 
82     pub struct fd_set {
83         fds_bits: [::c_ulong; FD_SETSIZE / ULONG_SIZE],
84     }
85 
86     pub struct lconv {
87         pub decimal_point: *mut ::c_char,
88         pub thousands_sep: *mut ::c_char,
89         pub grouping: *mut ::c_char,
90         pub int_curr_symbol: *mut ::c_char,
91         pub currency_symbol: *mut ::c_char,
92         pub mon_decimal_point: *mut ::c_char,
93         pub mon_thousands_sep: *mut ::c_char,
94         pub mon_grouping: *mut ::c_char,
95         pub positive_sign: *mut ::c_char,
96         pub negative_sign: *mut ::c_char,
97         pub int_frac_digits: ::c_char,
98         pub frac_digits: ::c_char,
99         pub p_cs_precedes: ::c_char,
100         pub p_sep_by_space: ::c_char,
101         pub n_cs_precedes: ::c_char,
102         pub n_sep_by_space: ::c_char,
103         pub p_sign_posn: ::c_char,
104         pub n_sign_posn: ::c_char,
105         pub int_p_cs_precedes: ::c_char,
106         pub int_p_sep_by_space: ::c_char,
107         pub int_n_cs_precedes: ::c_char,
108         pub int_n_sep_by_space: ::c_char,
109         pub int_p_sign_posn: ::c_char,
110         pub int_n_sign_posn: ::c_char,
111     }
112 
113     pub struct passwd { // Unverified
114         pub pw_name: *mut ::c_char,
115         pub pw_passwd: *mut ::c_char,
116         pub pw_uid: ::uid_t,
117         pub pw_gid: ::gid_t,
actionPerformed(ActionEvent e)118         pub pw_gecos: *mut ::c_char,
119         pub pw_dir: *mut ::c_char,
120         pub pw_shell: *mut ::c_char,
121     }
122 
123     pub struct pte_handle_t {
124         pub p: usize,
125         pub x: ::c_uint,
126     }
127 
128     pub struct sched_param {
129         pub sched_priority: ::c_int,
130     }
131 
132     pub struct sem_t {
133         pub value: i32,
134         pub lock: usize,
135         pub sem: usize,
136     }
137 
138     pub struct sigaction {
139         pub sa_flags: ::c_int,
140         pub sa_mask: sigset_t,
141         pub sa_handler: usize,
142     }
143 
144     pub struct sockaddr {
145         pub sa_len: u8,
146         pub sa_family: sa_family_t,
147         pub sa_data: [::c_char; 14],
148     }
149 
150     pub struct sockaddr_in {
151         pub sin_len: u8,
152         pub sin_family: sa_family_t,
153         pub sin_port: ::in_port_t,
154         pub sin_addr: ::in_addr,
155         pub sin_zero: [::c_char; 8],
156     }
157 
158     pub struct sockaddr_in6 {
159         pub sin6_len: u8,
160         pub sin6_family: sa_family_t,
161         pub sin6_port: ::in_port_t,
162         pub sin6_flowinfo: u32,
163         pub sin6_addr: ::in6_addr,
164         pub sin6_scope_id: u32,
165     }
166 
167     pub struct sockaddr_storage {
168         pub s2_len: u8,
169         pub ss_family: sa_family_t,
170         pub s2_data1: [::c_char; 2],
171         pub s2_data2: [u32; 3],
172         pub s2_data3: [u32; 3],
173     }
174 
175     // Dummy
176     pub struct sockaddr_un {
actionPerformed(ActionEvent e)177         pub sun_family: sa_family_t,
178         pub sun_path: [::c_char; 108],
179     }
180 
181     pub struct stat {
182         pub st_dev: ::dev_t,
183         pub st_ino: ::ino_t,
184         pub st_mode: ::mode_t,
185         pub st_nlink: ::nlink_t,
186         pub st_uid: ::uid_t,
187         pub st_gid: ::gid_t,
188         pub st_rdev: dev_t,
189         pub st_size: off_t,
190         pub st_atime: time_t,
191         pub st_atime_nsec: ::c_long,
192         pub st_mtime: time_t,
193         pub st_mtime_nsec: ::c_long,
194         pub st_ctime: time_t,
195         pub st_ctime_nsec: ::c_long,
196         pub st_blksize: blksize_t,
197         pub st_blocks: blkcnt_t,
198         pub st_spare4: [::c_long; 2],
199     }
200 
201     pub struct statvfs {}
202 
203     pub struct tm {
204         pub tm_sec: ::c_int,
205         pub tm_min: ::c_int,
206         pub tm_hour: ::c_int,
207         pub tm_mday: ::c_int,
208         pub tm_mon: ::c_int,
209         pub tm_year: ::c_int,
210         pub tm_wday: ::c_int,
211         pub tm_yday: ::c_int,
212         pub tm_isdst: ::c_int,
213     }
214 
215     pub struct tms {
216         pub tms_utime: ::clock_t,
217         pub tms_stime: ::clock_t,
218         pub tms_cutime: ::clock_t,
219         pub tms_cstime: ::clock_t,
220     }
221 
222     pub struct termios {}
223 
224     pub struct utsname {}
225 }
226 
227 pub const AF_UNSPEC: ::c_int = 0;
228 pub const AF_INET: ::c_int = 2;
229 pub const AF_INET6: ::c_int = 10;
230 
231 // Dummy
232 pub const AF_UNIX: ::c_int = 1;
233 
setPosition(Component c, int hPos, int vPos)234 pub const CLOCK_REALTIME: ::clockid_t = 1;
235 pub const CLOCK_MONOTONIC: ::clockid_t = 4;
236 
237 // Dummy
238 pub const EAI_SYSTEM: ::c_int = -11;
239 
240 pub const EPERM: ::c_int = 1;
241 pub const ENOENT: ::c_int = 2;
242 pub const ESRCH: ::c_int = 3;
243 pub const EINTR: ::c_int = 4;
244 pub const EIO: ::c_int = 5;
245 pub const ENXIO: ::c_int = 6;
246 pub const E2BIG: ::c_int = 7;
247 pub const ENOEXEC: ::c_int = 8;
248 pub const EBADF: ::c_int = 9;
249 pub const ECHILD: ::c_int = 10;
250 pub const EAGAIN: ::c_int = 11;
251 pub const ENOMEM: ::c_int = 12;
252 pub const EACCES: ::c_int = 13;
253 pub const EFAULT: ::c_int = 14;
254 pub const EBUSY: ::c_int = 16;
255 pub const EEXIST: ::c_int = 17;
256 pub const EXDEV: ::c_int = 18;
257 pub const ENODEV: ::c_int = 19;
setAlignment(Component c, int hPos, int vPos)258 pub const ENOTDIR: ::c_int = 20;
259 pub const EISDIR: ::c_int = 21;
260 pub const EINVAL: ::c_int = 22;
261 pub const ENFILE: ::c_int = 23;
262 pub const EMFILE: ::c_int = 24;
263 pub const ENOTTY: ::c_int = 25;
264 pub const ETXTBSY: ::c_int = 26;
265 pub const EFBIG: ::c_int = 27;
266 pub const ENOSPC: ::c_int = 28;
267 pub const ESPIPE: ::c_int = 29;
268 pub const EROFS: ::c_int = 30;
269 pub const EMLINK: ::c_int = 31;
270 pub const EPIPE: ::c_int = 32;
271 pub const EDOM: ::c_int = 33;
272 pub const ERANGE: ::c_int = 34;
273 pub const EDEADLK: ::c_int = 35;
274 pub const ENAMETOOLONG: ::c_int = 36;
275 pub const ENOLCK: ::c_int = 37;
276 pub const ENOSYS: ::c_int = 38;
277 pub const ENOTEMPTY: ::c_int = 39;
278 pub const ELOOP: ::c_int = 40;
279 pub const EWOULDBLOCK: ::c_int = EAGAIN;
280 pub const ENOMSG: ::c_int = 42;
281 pub const EIDRM: ::c_int = 43;
282 pub const ECHRNG: ::c_int = 44;
283 pub const EL2NSYNC: ::c_int = 45;
284 pub const EL3HLT: ::c_int = 46;
285 pub const EL3RST: ::c_int = 47;
286 pub const ELNRNG: ::c_int = 48;
287 pub const EUNATCH: ::c_int = 49;
288 pub const ENOCSI: ::c_int = 50;
289 pub const EL2HLT: ::c_int = 51;
290 pub const EBADE: ::c_int = 52;
291 pub const EBADR: ::c_int = 53;
292 pub const EXFULL: ::c_int = 54;
293 pub const ENOANO: ::c_int = 55;
294 pub const EBADRQC: ::c_int = 56;
295 pub const EBADSLT: ::c_int = 57;
296 pub const EDEADLOCK: ::c_int = EDEADLK;
297 pub const EBFONT: ::c_int = 59;
298 pub const ENOSTR: ::c_int = 60;
299 pub const ENODATA: ::c_int = 61;
300 pub const ETIME: ::c_int = 62;
301 pub const ENOSR: ::c_int = 63;
302 pub const ENONET: ::c_int = 64;
303 pub const ENOPKG: ::c_int = 65;
304 pub const EREMOTE: ::c_int = 66;
305 pub const ENOLINK: ::c_int = 67;
306 pub const EADV: ::c_int = 68;
307 pub const ESRMNT: ::c_int = 69;
308 pub const ECOMM: ::c_int = 70;
309 pub const EPROTO: ::c_int = 71;
310 pub const EMULTIHOP: ::c_int = 72;
311 pub const EDOTDOT: ::c_int = 73;
312 pub const EBADMSG: ::c_int = 74;
313 pub const EOVERFLOW: ::c_int = 75;
314 pub const ENOTUNIQ: ::c_int = 76;
315 pub const EBADFD: ::c_int = 77;
316 pub const EREMCHG: ::c_int = 78;
317 pub const ELIBACC: ::c_int = 79;
318 pub const ELIBBAD: ::c_int = 80;
319 pub const ELIBSCN: ::c_int = 81;
320 pub const ELIBMAX: ::c_int = 82;
321 pub const ELIBEXEC: ::c_int = 83;
322 pub const EILSEQ: ::c_int = 84;
323 pub const ERESTART: ::c_int = 85;
324 pub const ESTRPIPE: ::c_int = 86;
325 pub const EUSERS: ::c_int = 87;
326 pub const ENOTSOCK: ::c_int = 88;
327 pub const EDESTADDRREQ: ::c_int = 89;
328 pub const EMSGSIZE: ::c_int = 90;
329 pub const EPROTOTYPE: ::c_int = 91;
330 pub const ENOPROTOOPT: ::c_int = 92;
331 pub const EPROTONOSUPPORT: ::c_int = 93;
332 pub const ESOCKTNOSUPPORT: ::c_int = 94;
333 pub const EOPNOTSUPP: ::c_int = 95;
334 pub const EPFNOSUPPORT: ::c_int = 96;
335 pub const EAFNOSUPPORT: ::c_int = 97;
336 pub const EADDRINUSE: ::c_int = 98;
337 pub const EADDRNOTAVAIL: ::c_int = 99;
338 pub const ENETDOWN: ::c_int = 100;
339 pub const ENETUNREACH: ::c_int = 101;
340 pub const ENETRESET: ::c_int = 102;
341 pub const ECONNABORTED: ::c_int = 103;
342 pub const ECONNRESET: ::c_int = 104;
343 pub const ENOBUFS: ::c_int = 105;
344 pub const EISCONN: ::c_int = 106;
345 pub const ENOTCONN: ::c_int = 107;
346 pub const ESHUTDOWN: ::c_int = 108;
347 pub const ETOOMANYREFS: ::c_int = 109;
348 pub const ETIMEDOUT: ::c_int = 110;
349 pub const ECONNREFUSED: ::c_int = 111;
350 pub const EHOSTDOWN: ::c_int = 112;
351 pub const EHOSTUNREACH: ::c_int = 113;
352 pub const EALREADY: ::c_int = 114;
353 pub const EINPROGRESS: ::c_int = 115;
354 pub const ESTALE: ::c_int = 116;
355 pub const EUCLEAN: ::c_int = 117;
356 pub const ENOTNAM: ::c_int = 118;
357 pub const ENAVAIL: ::c_int = 119;
358 pub const EISNAM: ::c_int = 120;
359 pub const EREMOTEIO: ::c_int = 121;
360 pub const EDQUOT: ::c_int = 122;
361 pub const ENOMEDIUM: ::c_int = 123;
362 pub const EMEDIUMTYPE: ::c_int = 124;
363 pub const ECANCELED: ::c_int = 125;
364 pub const ENOKEY: ::c_int = 126;
365 pub const EKEYEXPIRED: ::c_int = 127;
366 pub const EKEYREVOKED: ::c_int = 128;
367 pub const EKEYREJECTED: ::c_int = 129;
368 pub const EOWNERDEAD: ::c_int = 130;
369 pub const ENOTRECOVERABLE: ::c_int = 131;
370 pub const ERFKILL: ::c_int = 132;
371 pub const EHWPOISON: ::c_int = 133;
372 
373 pub const EXIT_FAILURE: ::c_int = 1;
374 pub const EXIT_SUCCESS: ::c_int = 0;
375 
376 pub const F_DUPFD: ::c_int = 0;
377 pub const F_GETFD: ::c_int = 1;
378 pub const F_SETFD: ::c_int = 2;
379 pub const F_GETFL: ::c_int = 3;
380 pub const F_SETFL: ::c_int = 4;
381 pub const F_GETOWN: ::c_int = 5;
382 pub const F_SETOWN: ::c_int = 6;
383 pub const F_GETLK: ::c_int = 7;
384 pub const F_SETLK: ::c_int = 8;
385 pub const F_SETLKW: ::c_int = 9;
386 pub const F_RGETLK: ::c_int = 10;
387 pub const F_RSETLK: ::c_int = 11;
388 pub const F_CNVT: ::c_int = 12;
389 pub const F_RSETLKW: ::c_int = 13;
390 pub const F_DUPFD_CLOEXEC: ::c_int = 14;
391 
392 pub const FD_SETSIZE: usize = 1024;
393 
394 // Dummy
395 pub const FIOCLEX: ::c_int = 0x5451;
396 
397 pub const FIONBIO: ::c_int = 0x8004667e;
398 pub const FIONREAD: ::c_int = 0x4004667f;
399 
400 pub const IP_ADD_MEMBERSHIP: ::c_int = 3;
401 pub const IP_DROP_MEMBERSHIP: ::c_int = 4;
402 
403 pub const IP_TOS: ::c_int = 1;
404 pub const IP_TTL: ::c_int = 2;
405 
406 pub const IP_MULTICAST_TTL: ::c_int = 5;
407 pub const IP_MULTICAST_IF: ::c_int = 6;
408 pub const IP_MULTICAST_LOOP: ::c_int = 7;
409 
410 pub const IPV6_JOIN_GROUP: ::c_int = 12;
411 pub const IPV6_ADD_MEMBERSHIP: ::c_int = 12;
412 pub const IPV6_LEAVE_GROUP: ::c_int = 13;
413 pub const IPV6_DROP_MEMBERSHIP: ::c_int = 13;
414 pub const IPV6_V6ONLY: ::c_int = 27;
415 
416 // Dummy
417 pub const IPV6_MULTICAST_LOOP: ::c_int = 7;
418 
419 pub const MSG_PEEK: ::c_int = 0x01;
420 pub const MSG_WAITALL: ::c_int = 0x02;
421 pub const MSG_OOB: ::c_int = 0x04;
422 pub const MSG_DONTWAIT: ::c_int = 0x08;
423 pub const MSG_MORE: ::c_int = 0x10;
424 
425 pub const O_ACCMODE: ::c_int = 3;
426 pub const O_RDONLY: ::c_int = 0;
427 pub const O_WRONLY: ::c_int = 1;
428 pub const O_RDWR: ::c_int = 2;
429 pub const O_APPEND: ::c_int = 1024;
430 pub const O_CREAT: ::c_int = 64;
431 pub const O_EXCL: ::c_int = 128;
432 pub const O_NOCTTY: ::c_int = 256;
433 pub const O_NONBLOCK: ::c_int = 2048;
434 pub const O_TRUNC: ::c_int = 512;
435 pub const O_CLOEXEC: ::c_int = 524288;
436 
437 pub const POLLIN: ::c_short = 0x1;
438 pub const POLLPRI: ::c_short = 0x2;
439 pub const POLLOUT: ::c_short = 0x4;
440 pub const POLLERR: ::c_short = 0x8;
441 pub const POLLHUP: ::c_short = 0x10;
442 pub const POLLNVAL: ::c_short = 0x20;
443 
444 pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = usize::max_value();
445 pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = usize::max_value();
446 pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = usize::max_value();
447 
448 pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0;
449 pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 1;
450 pub const PTHREAD_STACK_MIN: ::size_t = 0;
451 
452 // Dummy
453 pub const RTLD_DEFAULT: *mut ::c_void = 0i64 as *mut ::c_void;
454 
455 pub const _SC_ARG_MAX: ::c_int = 0;
456 pub const _SC_CHILD_MAX: ::c_int = 1;
457 pub const _SC_CLK_TCK: ::c_int = 2;
458 pub const _SC_NGROUPS_MAX: ::c_int = 3;
459 pub const _SC_OPEN_MAX: ::c_int = 4;
460 pub const _SC_JOB_CONTROL: ::c_int = 5;
461 pub const _SC_SAVED_IDS: ::c_int = 6;
462 pub const _SC_VERSION: ::c_int = 7;
463 pub const _SC_PAGESIZE: ::c_int = 8;
464 pub const _SC_PAGE_SIZE: ::c_int = _SC_PAGESIZE;
465 pub const _SC_NPROCESSORS_CONF: ::c_int = 9;
466 pub const _SC_NPROCESSORS_ONLN: ::c_int = 10;
467 pub const _SC_PHYS_PAGES: ::c_int = 11;
468 pub const _SC_AVPHYS_PAGES: ::c_int = 12;
469 pub const _SC_MQ_OPEN_MAX: ::c_int = 13;
470 pub const _SC_MQ_PRIO_MAX: ::c_int = 14;
471 pub const _SC_RTSIG_MAX: ::c_int = 15;
472 pub const _SC_SEM_NSEMS_MAX: ::c_int = 16;
473 pub const _SC_SEM_VALUE_MAX: ::c_int = 17;
474 pub const _SC_SIGQUEUE_MAX: ::c_int = 18;
475 pub const _SC_TIMER_MAX: ::c_int = 19;
476 pub const _SC_TZNAME_MAX: ::c_int = 20;
477 pub const _SC_ASYNCHRONOUS_IO: ::c_int = 21;
478 pub const _SC_FSYNC: ::c_int = 22;
479 pub const _SC_MAPPED_FILES: ::c_int = 23;
480 pub const _SC_MEMLOCK: ::c_int = 24;
481 pub const _SC_MEMLOCK_RANGE: ::c_int = 25;
482 pub const _SC_MEMORY_PROTECTION: ::c_int = 26;
483 pub const _SC_MESSAGE_PASSING: ::c_int = 27;
484 pub const _SC_PRIORITIZED_IO: ::c_int = 28;
485 pub const _SC_REALTIME_SIGNALS: ::c_int = 29;
486 pub const _SC_SEMAPHORES: ::c_int = 30;
487 pub const _SC_SHARED_MEMORY_OBJECTS: ::c_int = 31;
488 pub const _SC_SYNCHRONIZED_IO: ::c_int = 32;
489 pub const _SC_TIMERS: ::c_int = 33;
490 pub const _SC_AIO_LISTIO_MAX: ::c_int = 34;
491 pub const _SC_AIO_MAX: ::c_int = 35;
492 pub const _SC_AIO_PRIO_DELTA_MAX: ::c_int = 36;
493 pub const _SC_DELAYTIMER_MAX: ::c_int = 37;
494 pub const _SC_THREAD_KEYS_MAX: ::c_int = 38;
495 pub const _SC_THREAD_STACK_MIN: ::c_int = 39;
496 pub const _SC_THREAD_THREADS_MAX: ::c_int = 40;
497 pub const _SC_TTY_NAME_MAX: ::c_int = 41;
498 pub const _SC_THREADS: ::c_int = 42;
499 pub const _SC_THREAD_ATTR_STACKADDR: ::c_int = 43;
500 pub const _SC_THREAD_ATTR_STACKSIZE: ::c_int = 44;
501 pub const _SC_THREAD_PRIORITY_SCHEDULING: ::c_int = 45;
502 pub const _SC_THREAD_PRIO_INHERIT: ::c_int = 46;
503 pub const _SC_THREAD_PRIO_PROTECT: ::c_int = 47;
504 pub const _SC_THREAD_PRIO_CEILING: ::c_int = _SC_THREAD_PRIO_PROTECT;
505 pub const _SC_THREAD_PROCESS_SHARED: ::c_int = 48;
506 pub const _SC_THREAD_SAFE_FUNCTIONS: ::c_int = 49;
507 pub const _SC_GETGR_R_SIZE_MAX: ::c_int = 50;
508 pub const _SC_GETPW_R_SIZE_MAX: ::c_int = 51;
509 pub const _SC_LOGIN_NAME_MAX: ::c_int = 52;
510 pub const _SC_THREAD_DESTRUCTOR_ITERATIONS: ::c_int = 53;
511 pub const _SC_ADVISORY_INFO: ::c_int = 54;
512 pub const _SC_ATEXIT_MAX: ::c_int = 55;
513 pub const _SC_BARRIERS: ::c_int = 56;
514 pub const _SC_BC_BASE_MAX: ::c_int = 57;
515 pub const _SC_BC_DIM_MAX: ::c_int = 58;
516 pub const _SC_BC_SCALE_MAX: ::c_int = 59;
517 pub const _SC_BC_STRING_MAX: ::c_int = 60;
518 pub const _SC_CLOCK_SELECTION: ::c_int = 61;
519 pub const _SC_COLL_WEIGHTS_MAX: ::c_int = 62;
520 pub const _SC_CPUTIME: ::c_int = 63;
521 pub const _SC_EXPR_NEST_MAX: ::c_int = 64;
522 pub const _SC_HOST_NAME_MAX: ::c_int = 65;
523 pub const _SC_IOV_MAX: ::c_int = 66;
524 pub const _SC_IPV6: ::c_int = 67;
525 pub const _SC_LINE_MAX: ::c_int = 68;
526 pub const _SC_MONOTONIC_CLOCK: ::c_int = 69;
527 pub const _SC_RAW_SOCKETS: ::c_int = 70;
528 pub const _SC_READER_WRITER_LOCKS: ::c_int = 71;
529 pub const _SC_REGEXP: ::c_int = 72;
530 pub const _SC_RE_DUP_MAX: ::c_int = 73;
531 pub const _SC_SHELL: ::c_int = 74;
532 pub const _SC_SPAWN: ::c_int = 75;
533 pub const _SC_SPIN_LOCKS: ::c_int = 76;
534 pub const _SC_SPORADIC_SERVER: ::c_int = 77;
535 pub const _SC_SS_REPL_MAX: ::c_int = 78;
536 pub const _SC_SYMLOOP_MAX: ::c_int = 79;
537 pub const _SC_THREAD_CPUTIME: ::c_int = 80;
538 pub const _SC_THREAD_SPORADIC_SERVER: ::c_int = 81;
539 pub const _SC_TIMEOUTS: ::c_int = 82;
540 pub const _SC_TRACE: ::c_int = 83;
541 pub const _SC_TRACE_EVENT_FILTER: ::c_int = 84;
542 pub const _SC_TRACE_EVENT_NAME_MAX: ::c_int = 85;
543 pub const _SC_TRACE_INHERIT: ::c_int = 86;
544 pub const _SC_TRACE_LOG: ::c_int = 87;
545 pub const _SC_TRACE_NAME_MAX: ::c_int = 88;
546 pub const _SC_TRACE_SYS_MAX: ::c_int = 89;
547 pub const _SC_TRACE_USER_EVENT_MAX: ::c_int = 90;
548 pub const _SC_TYPED_MEMORY_OBJECTS: ::c_int = 91;
549 pub const _SC_V7_ILP32_OFF32: ::c_int = 92;
550 pub const _SC_V6_ILP32_OFF32: ::c_int =_SC_V7_ILP32_OFF32;
551 pub const _SC_XBS5_ILP32_OFF32: ::c_int = _SC_V7_ILP32_OFF32;
552 pub const _SC_V7_ILP32_OFFBIG: ::c_int = 93;
553 pub const _SC_V6_ILP32_OFFBIG: ::c_int = _SC_V7_ILP32_OFFBIG;
554 pub const _SC_XBS5_ILP32_OFFBIG: ::c_int = _SC_V7_ILP32_OFFBIG;
555 pub const _SC_V7_LP64_OFF64: ::c_int = 94;
556 pub const _SC_V6_LP64_OFF64: ::c_int = _SC_V7_LP64_OFF64;
557 pub const _SC_XBS5_LP64_OFF64: ::c_int = _SC_V7_LP64_OFF64;
558 pub const _SC_V7_LPBIG_OFFBIG: ::c_int = 95;
559 pub const _SC_V6_LPBIG_OFFBIG: ::c_int = _SC_V7_LPBIG_OFFBIG;
560 pub const _SC_XBS5_LPBIG_OFFBIG: ::c_int = _SC_V7_LPBIG_OFFBIG;
561 pub const _SC_XOPEN_CRYPT: ::c_int = 96;
562 pub const _SC_XOPEN_ENH_I18N: ::c_int = 97;
563 pub const _SC_XOPEN_LEGACY: ::c_int = 98;
564 pub const _SC_XOPEN_REALTIME: ::c_int = 99;
565 pub const _SC_STREAM_MAX: ::c_int = 100;
566 pub const _SC_PRIORITY_SCHEDULING: ::c_int = 101;
567 pub const _SC_XOPEN_REALTIME_THREADS: ::c_int = 102;
568 pub const _SC_XOPEN_SHM: ::c_int = 103;
569 pub const _SC_XOPEN_STREAMS: ::c_int = 104;
570 pub const _SC_XOPEN_UNIX: ::c_int = 105;
571 pub const _SC_XOPEN_VERSION: ::c_int = 106;
572 pub const _SC_2_CHAR_TERM: ::c_int = 107;
573 pub const _SC_2_C_BIND: ::c_int = 108;
574 pub const _SC_2_C_DEV: ::c_int = 109;
575 pub const _SC_2_FORT_DEV: ::c_int = 110;
576 pub const _SC_2_FORT_RUN: ::c_int = 111;
577 pub const _SC_2_LOCALEDEF: ::c_int = 112;
578 pub const _SC_2_PBS: ::c_int = 113;
579 pub const _SC_2_PBS_ACCOUNTING: ::c_int = 114;
580 pub const _SC_2_PBS_CHECKPOINT: ::c_int = 115;
581 pub const _SC_2_PBS_LOCATE: ::c_int = 116;
582 pub const _SC_2_PBS_MESSAGE: ::c_int = 117;
583 pub const _SC_2_PBS_TRACK: ::c_int = 118;
584 pub const _SC_2_SW_DEV: ::c_int = 119;
585 pub const _SC_2_UPE: ::c_int = 120;
586 pub const _SC_2_VERSION: ::c_int = 121;
587 pub const _SC_THREAD_ROBUST_PRIO_INHERIT: ::c_int = 122;
588 pub const _SC_THREAD_ROBUST_PRIO_PROTECT: ::c_int = 123;
589 pub const _SC_XOPEN_UUCP: ::c_int = 124;
590 pub const _SC_LEVEL1_ICACHE_SIZE: ::c_int = 125;
591 pub const _SC_LEVEL1_ICACHE_ASSOC: ::c_int = 126;
592 pub const _SC_LEVEL1_ICACHE_LINESIZE: ::c_int = 127;
593 pub const _SC_LEVEL1_DCACHE_SIZE: ::c_int = 128;
594 pub const _SC_LEVEL1_DCACHE_ASSOC: ::c_int = 129;
595 pub const _SC_LEVEL1_DCACHE_LINESIZE: ::c_int = 130;
596 pub const _SC_LEVEL2_CACHE_SIZE: ::c_int = 131;
597 pub const _SC_LEVEL2_CACHE_ASSOC: ::c_int = 132;
598 pub const _SC_LEVEL2_CACHE_LINESIZE: ::c_int = 133;
599 pub const _SC_LEVEL3_CACHE_SIZE: ::c_int = 134;
600 pub const _SC_LEVEL3_CACHE_ASSOC: ::c_int = 135;
601 pub const _SC_LEVEL3_CACHE_LINESIZE: ::c_int = 136;
602 pub const _SC_LEVEL4_CACHE_SIZE: ::c_int = 137;
603 pub const _SC_LEVEL4_CACHE_ASSOC: ::c_int = 138;
604 pub const _SC_LEVEL4_CACHE_LINESIZE: ::c_int = 139;
605 
606 pub const S_BLKSIZE: ::mode_t = 1024;
607 pub const S_IREAD: ::mode_t = 256;
608 pub const S_IWRITE: ::mode_t = 128;
609 pub const S_IEXEC: ::mode_t = 64;
610 pub const S_ENFMT: ::mode_t = 1024;
611 pub const S_IFMT: ::mode_t = 61440;
612 pub const S_IFDIR: ::mode_t = 16384;
613 pub const S_IFCHR: ::mode_t = 8192;
614 pub const S_IFBLK: ::mode_t = 24576;
615 pub const S_IFREG: ::mode_t = 32768;
616 pub const S_IFLNK: ::mode_t = 40960;
617 pub const S_IFSOCK: ::mode_t = 49152;
618 pub const S_IFIFO: ::mode_t = 4096;
619 pub const S_IRUSR: ::mode_t = 256;
620 pub const S_IWUSR: ::mode_t = 128;
621 pub const S_IXUSR: ::mode_t = 64;
622 pub const S_IRGRP: ::mode_t = 32;
623 pub const S_IWGRP: ::mode_t = 16;
624 pub const S_IXGRP: ::mode_t = 8;
625 pub const S_IROTH: ::mode_t = 4;
626 pub const S_IWOTH: ::mode_t = 2;
627 pub const S_IXOTH: ::mode_t = 1;
628 
629 pub const SEEK_SET: ::c_int = 0;
630 pub const SEEK_CUR: ::c_int = 1;
631 pub const SEEK_END: ::c_int = 2;
632 
633 pub const SHUT_RD: ::c_int = 0;
634 pub const SHUT_WR: ::c_int = 1;
635 pub const SHUT_RDWR: ::c_int = 2;
636 
637 pub const SIG_SETMASK: ::c_int = 0;
638 
639 pub const SIGHUP: ::c_int = 1;
640 pub const SIGINT: ::c_int = 2;
641 pub const SIGQUIT: ::c_int = 3;
642 pub const SIGILL: ::c_int = 4;
643 pub const SIGABRT: ::c_int = 6;
644 pub const SIGEMT: ::c_int = 7;
645 pub const SIGFPE: ::c_int = 8;
646 pub const SIGKILL: ::c_int = 9;
647 pub const SIGSEGV: ::c_int = 11;
648 pub const SIGPIPE: ::c_int = 13;
649 pub const SIGALRM: ::c_int = 14;
650 pub const SIGTERM: ::c_int = 15;
651 
652 pub const SO_DEBUG: ::c_int = 0x0001;
653 pub const SO_ACCEPTCONN: ::c_int = 0x0002;
654 pub const SO_REUSEADDR: ::c_int = 0x0004;
655 pub const SO_KEEPALIVE: ::c_int = 0x0008;
656 pub const SO_DONTROUTE: ::c_int = 0x0010;
657 pub const SO_BROADCAST: ::c_int = 0x0020;
658 pub const SO_USELOOPBACK: ::c_int = 0x0040;
659 pub const SO_LINGER: ::c_int = 0x0080;
660 pub const SO_OOBINLINE: ::c_int = 0x0100;
661 pub const SO_REUSEPORT: ::c_int = 0x0200;
662 pub const SO_SNDBUF: ::c_int = 0x1001;
663 pub const SO_RCVBUF: ::c_int = 0x1002;
664 pub const SO_SNDLOWAT: ::c_int = 0x1003;
665 pub const SO_RCVLOWAT: ::c_int = 0x1004;
666 pub const SO_SNDTIMEO: ::c_int = 0x1005;
667 pub const SO_RCVTIMEO: ::c_int = 0x1006;
668 pub const SO_ERROR: ::c_int = 0x1007;
669 pub const SO_TYPE: ::c_int = 0x1008;
670 pub const SO_CONTIMEO: ::c_int = 0x1009;
671 pub const SO_NO_CHECK: ::c_int = 0x100a;
672 
673 pub const SOCK_STREAM: ::c_int = 1;
674 pub const SOCK_DGRAM: ::c_int = 2;
675 pub const SOCK_RAW: ::c_int = 3;
676 
677 pub const SOL_SOCKET: ::c_int = 0xfff;
678 
679 pub const STDIN_FILENO: ::c_int = 0;
680 pub const STDOUT_FILENO: ::c_int = 1;
681 pub const STDERR_FILENO: ::c_int = 2;
682 
683 pub const TCP_NODELAY: ::c_int = 0x01;
684 pub const TCP_KEEPALIVE: ::c_int = 0x02;
685 pub const TCP_KEEPIDLE: ::c_int = 0x03;
686 pub const TCP_KEEPINTVL: ::c_int = 0x04;
687 pub const TCP_KEEPCNT: ::c_int = 0x05;
688 
689 const ULONG_SIZE: usize = 64;
690 
691 pub const WNOHANG: ::c_int = 0x00000001;
692 
693 f! {
694     pub fn WEXITSTATUS(status: ::c_int) -> ::c_int {
695         (status >> 8) & 0xff
696     }
697 
698     pub fn WIFEXITED(status: ::c_int) -> bool {
699         (status & 0xff) == 0
700     }
701 
702     pub fn WTERMSIG(status: ::c_int) -> ::c_int {
703         status & 0x7f
704     }
705 }
706 
707 extern {
708     pub fn sem_destroy(sem: *mut sem_t) -> ::c_int;
709     pub fn sem_init(sem: *mut sem_t,
710                     pshared: ::c_int,
711                     value: ::c_uint)
712                     -> ::c_int;
713 
714     pub fn abs(i: ::c_int) -> ::c_int;
715     pub fn atof(s: *const ::c_char) -> ::c_double;
716     pub fn labs(i: ::c_long) -> ::c_long;
717     pub fn rand() -> ::c_int;
718     pub fn srand(seed: ::c_uint);
719 
720     pub fn bind(s: ::c_int, name: *const ::sockaddr, namelen: ::socklen_t)
721         -> ::c_int;
722 
723     pub fn clock_gettime(clock_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int;
724 
725     pub fn getpwuid_r(uid: ::uid_t, pwd: *mut passwd, buf: *mut ::c_char,
726         buflen: ::size_t, result: *mut *mut passwd) -> ::c_int;
727 
728     // Dummy
729     pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int;
730 
731     pub fn memalign(align: ::size_t, nbytes: ::size_t) -> *mut ::c_void;
732 
733     pub fn pthread_create(tid: *mut ::pthread_t, attr: *const ::pthread_attr_t,
734         start: extern fn(*mut ::c_void) -> *mut ::c_void, arg: *mut ::c_void)
735         -> ::c_int;
736 
737     pub fn pthread_sigmask(how: ::c_int, set: *const ::sigset_t,
738         oset: *mut ::sigset_t) -> ::c_int;
739 
740     pub fn recvfrom(s: ::c_int, mem: *mut ::c_void, len: ::size_t,
741         flags: ::c_int, from: *mut ::sockaddr, fromlen: *mut ::socklen_t)
742         -> ::c_int;
743 
744     pub fn setgroups(ngroups: ::c_int, grouplist: *const ::gid_t) -> ::c_int;
745     pub fn uname(buf: *mut ::utsname) -> ::c_int;
746 }
747 
748 cfg_if! {
749     if #[cfg(target_arch = "aarch64")] {
750         mod aarch64;
751         pub use self::aarch64::*;
752     } else if #[cfg(target_arch = "x86_64")] {
753         mod x86_64;
754         pub use self::x86_64::*;
755     } else {
756         // Unknown target_arch
757     }
758 }
759