mod.rs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  1. pub type pthread_t = *mut ::c_void;
  2. pub type clock_t = c_long;
  3. pub type time_t = i64;
  4. pub type suseconds_t = i64;
  5. pub type ino_t = u64;
  6. pub type off_t = i64;
  7. pub type blkcnt_t = i64;
  8. pub type shmatt_t = ::c_ulong;
  9. pub type msgqnum_t = ::c_ulong;
  10. pub type msglen_t = ::c_ulong;
  11. pub type fsblkcnt_t = ::c_ulonglong;
  12. pub type fsfilcnt_t = ::c_ulonglong;
  13. pub type rlim_t = ::c_ulonglong;
  14. cfg_if! {
  15. if #[cfg(doc)] {
  16. // Used in `linux::arch` to define ioctl constants.
  17. pub(crate) type Ioctl = ::c_int;
  18. } else {
  19. #[doc(hidden)]
  20. pub type Ioctl = ::c_int;
  21. }
  22. }
  23. impl siginfo_t {
  24. pub unsafe fn si_addr(&self) -> *mut ::c_void {
  25. #[repr(C)]
  26. struct siginfo_sigfault {
  27. _si_signo: ::c_int,
  28. _si_errno: ::c_int,
  29. _si_code: ::c_int,
  30. si_addr: *mut ::c_void,
  31. }
  32. (*(self as *const siginfo_t as *const siginfo_sigfault)).si_addr
  33. }
  34. pub unsafe fn si_value(&self) -> ::sigval {
  35. #[repr(C)]
  36. struct siginfo_si_value {
  37. _si_signo: ::c_int,
  38. _si_errno: ::c_int,
  39. _si_code: ::c_int,
  40. _si_timerid: ::c_int,
  41. _si_overrun: ::c_int,
  42. si_value: ::sigval,
  43. }
  44. (*(self as *const siginfo_t as *const siginfo_si_value)).si_value
  45. }
  46. }
  47. cfg_if! {
  48. if #[cfg(libc_union)] {
  49. // Internal, for casts to access union fields
  50. #[repr(C)]
  51. struct sifields_sigchld {
  52. si_pid: ::pid_t,
  53. si_uid: ::uid_t,
  54. si_status: ::c_int,
  55. si_utime: ::c_long,
  56. si_stime: ::c_long,
  57. }
  58. impl ::Copy for sifields_sigchld {}
  59. impl ::Clone for sifields_sigchld {
  60. fn clone(&self) -> sifields_sigchld {
  61. *self
  62. }
  63. }
  64. // Internal, for casts to access union fields
  65. #[repr(C)]
  66. union sifields {
  67. _align_pointer: *mut ::c_void,
  68. sigchld: sifields_sigchld,
  69. }
  70. // Internal, for casts to access union fields. Note that some variants
  71. // of sifields start with a pointer, which makes the alignment of
  72. // sifields vary on 32-bit and 64-bit architectures.
  73. #[repr(C)]
  74. struct siginfo_f {
  75. _siginfo_base: [::c_int; 3],
  76. sifields: sifields,
  77. }
  78. impl siginfo_t {
  79. unsafe fn sifields(&self) -> &sifields {
  80. &(*(self as *const siginfo_t as *const siginfo_f)).sifields
  81. }
  82. pub unsafe fn si_pid(&self) -> ::pid_t {
  83. self.sifields().sigchld.si_pid
  84. }
  85. pub unsafe fn si_uid(&self) -> ::uid_t {
  86. self.sifields().sigchld.si_uid
  87. }
  88. pub unsafe fn si_status(&self) -> ::c_int {
  89. self.sifields().sigchld.si_status
  90. }
  91. pub unsafe fn si_utime(&self) -> ::c_long {
  92. self.sifields().sigchld.si_utime
  93. }
  94. pub unsafe fn si_stime(&self) -> ::c_long {
  95. self.sifields().sigchld.si_stime
  96. }
  97. }
  98. }
  99. }
  100. s! {
  101. pub struct aiocb {
  102. pub aio_fildes: ::c_int,
  103. pub aio_lio_opcode: ::c_int,
  104. pub aio_reqprio: ::c_int,
  105. pub aio_buf: *mut ::c_void,
  106. pub aio_nbytes: ::size_t,
  107. pub aio_sigevent: ::sigevent,
  108. __td: *mut ::c_void,
  109. __lock: [::c_int; 2],
  110. __err: ::c_int,
  111. __ret: ::ssize_t,
  112. pub aio_offset: off_t,
  113. __next: *mut ::c_void,
  114. __prev: *mut ::c_void,
  115. #[cfg(target_pointer_width = "32")]
  116. __dummy4: [::c_char; 24],
  117. #[cfg(target_pointer_width = "64")]
  118. __dummy4: [::c_char; 16],
  119. }
  120. pub struct sigaction {
  121. pub sa_sigaction: ::sighandler_t,
  122. pub sa_mask: ::sigset_t,
  123. pub sa_flags: ::c_int,
  124. pub sa_restorer: ::Option<unsafe extern fn()>,
  125. }
  126. pub struct statvfs {
  127. pub f_bsize: ::c_ulong,
  128. pub f_frsize: ::c_ulong,
  129. pub f_blocks: ::fsblkcnt_t,
  130. pub f_bfree: ::fsblkcnt_t,
  131. pub f_bavail: ::fsblkcnt_t,
  132. pub f_files: ::fsfilcnt_t,
  133. pub f_ffree: ::fsfilcnt_t,
  134. pub f_favail: ::fsfilcnt_t,
  135. #[cfg(target_endian = "little")]
  136. pub f_fsid: ::c_ulong,
  137. #[cfg(target_pointer_width = "32")]
  138. __f_unused: ::c_int,
  139. #[cfg(target_endian = "big")]
  140. pub f_fsid: ::c_ulong,
  141. pub f_flag: ::c_ulong,
  142. pub f_namemax: ::c_ulong,
  143. __f_spare: [::c_int; 6],
  144. }
  145. pub struct termios {
  146. pub c_iflag: ::tcflag_t,
  147. pub c_oflag: ::tcflag_t,
  148. pub c_cflag: ::tcflag_t,
  149. pub c_lflag: ::tcflag_t,
  150. pub c_line: ::cc_t,
  151. pub c_cc: [::cc_t; ::NCCS],
  152. pub __c_ispeed: ::speed_t,
  153. pub __c_ospeed: ::speed_t,
  154. }
  155. pub struct flock {
  156. pub l_type: ::c_short,
  157. pub l_whence: ::c_short,
  158. pub l_start: ::off_t,
  159. pub l_len: ::off_t,
  160. pub l_pid: ::pid_t,
  161. }
  162. pub struct flock64 {
  163. pub l_type: ::c_short,
  164. pub l_whence: ::c_short,
  165. pub l_start: ::off64_t,
  166. pub l_len: ::off64_t,
  167. pub l_pid: ::pid_t,
  168. }
  169. pub struct regex_t {
  170. __re_nsub: ::size_t,
  171. __opaque: *mut ::c_void,
  172. __padding: [*mut ::c_void; 4usize],
  173. __nsub2: ::size_t,
  174. __padding2: ::c_char,
  175. }
  176. pub struct rtentry {
  177. pub rt_pad1: ::c_ulong,
  178. pub rt_dst: ::sockaddr,
  179. pub rt_gateway: ::sockaddr,
  180. pub rt_genmask: ::sockaddr,
  181. pub rt_flags: ::c_ushort,
  182. pub rt_pad2: ::c_short,
  183. pub rt_pad3: ::c_ulong,
  184. pub rt_tos: ::c_uchar,
  185. pub rt_class: ::c_uchar,
  186. #[cfg(target_pointer_width = "64")]
  187. pub rt_pad4: [::c_short; 3usize],
  188. #[cfg(not(target_pointer_width = "64"))]
  189. pub rt_pad4: [::c_short; 1usize],
  190. pub rt_metric: ::c_short,
  191. pub rt_dev: *mut ::c_char,
  192. pub rt_mtu: ::c_ulong,
  193. pub rt_window: ::c_ulong,
  194. pub rt_irtt: ::c_ushort,
  195. }
  196. pub struct __exit_status {
  197. pub e_termination: ::c_short,
  198. pub e_exit: ::c_short,
  199. }
  200. pub struct Elf64_Chdr {
  201. pub ch_type: ::Elf64_Word,
  202. pub ch_reserved: ::Elf64_Word,
  203. pub ch_size: ::Elf64_Xword,
  204. pub ch_addralign: ::Elf64_Xword,
  205. }
  206. pub struct Elf32_Chdr {
  207. pub ch_type: ::Elf32_Word,
  208. pub ch_size: ::Elf32_Word,
  209. pub ch_addralign: ::Elf32_Word,
  210. }
  211. pub struct timex {
  212. pub modes: ::c_uint,
  213. pub offset: ::c_long,
  214. pub freq: ::c_long,
  215. pub maxerror: ::c_long,
  216. pub esterror: ::c_long,
  217. pub status: ::c_int,
  218. pub constant: ::c_long,
  219. pub precision: ::c_long,
  220. pub tolerance: ::c_long,
  221. pub time: ::timeval,
  222. pub tick: ::c_long,
  223. pub ppsfreq: ::c_long,
  224. pub jitter: ::c_long,
  225. pub shift: ::c_int,
  226. pub stabil: ::c_long,
  227. pub jitcnt: ::c_long,
  228. pub calcnt: ::c_long,
  229. pub errcnt: ::c_long,
  230. pub stbcnt: ::c_long,
  231. pub tai: ::c_int,
  232. pub __padding: [::c_int; 11],
  233. }
  234. pub struct ntptimeval {
  235. pub time: ::timeval,
  236. pub maxerror: ::c_long,
  237. pub esterror: ::c_long,
  238. }
  239. }
  240. s_no_extra_traits! {
  241. pub struct sysinfo {
  242. pub uptime: ::c_ulong,
  243. pub loads: [::c_ulong; 3],
  244. pub totalram: ::c_ulong,
  245. pub freeram: ::c_ulong,
  246. pub sharedram: ::c_ulong,
  247. pub bufferram: ::c_ulong,
  248. pub totalswap: ::c_ulong,
  249. pub freeswap: ::c_ulong,
  250. pub procs: ::c_ushort,
  251. pub pad: ::c_ushort,
  252. pub totalhigh: ::c_ulong,
  253. pub freehigh: ::c_ulong,
  254. pub mem_unit: ::c_uint,
  255. pub __reserved: [::c_char; 256],
  256. }
  257. // FIXME: musl added paddings and adjusted
  258. // layout in 1.2.0 but our CI is still 1.1.24.
  259. // So, I'm leaving some fields as cfg for now.
  260. // ref. https://github.com/bminor/musl/commit/
  261. // 1e7f0fcd7ff2096904fd93a2ee6d12a2392be392
  262. //
  263. // OpenHarmony uses the musl 1.2 layout.
  264. pub struct utmpx {
  265. pub ut_type: ::c_short,
  266. __ut_pad1: ::c_short,
  267. pub ut_pid: ::pid_t,
  268. pub ut_line: [::c_char; 32],
  269. pub ut_id: [::c_char; 4],
  270. pub ut_user: [::c_char; 32],
  271. pub ut_host: [::c_char; 256],
  272. pub ut_exit: __exit_status,
  273. #[cfg(target_env = "musl")]
  274. pub ut_session: ::c_long,
  275. #[cfg(target_env = "ohos")]
  276. #[cfg(target_endian = "little")]
  277. pub ut_session: ::c_int,
  278. #[cfg(target_env = "ohos")]
  279. #[cfg(target_endian = "little")]
  280. __ut_pad2: ::c_int,
  281. #[cfg(target_env = "ohos")]
  282. #[cfg(not(target_endian = "little"))]
  283. __ut_pad2: ::c_int,
  284. #[cfg(target_env = "ohos")]
  285. #[cfg(not(target_endian = "little"))]
  286. pub ut_session: ::c_int,
  287. pub ut_tv: ::timeval,
  288. pub ut_addr_v6: [::c_uint; 4],
  289. __unused: [::c_char; 20],
  290. }
  291. }
  292. cfg_if! {
  293. if #[cfg(feature = "extra_traits")] {
  294. impl PartialEq for sysinfo {
  295. fn eq(&self, other: &sysinfo) -> bool {
  296. self.uptime == other.uptime
  297. && self.loads == other.loads
  298. && self.totalram == other.totalram
  299. && self.freeram == other.freeram
  300. && self.sharedram == other.sharedram
  301. && self.bufferram == other.bufferram
  302. && self.totalswap == other.totalswap
  303. && self.freeswap == other.freeswap
  304. && self.procs == other.procs
  305. && self.pad == other.pad
  306. && self.totalhigh == other.totalhigh
  307. && self.freehigh == other.freehigh
  308. && self.mem_unit == other.mem_unit
  309. && self
  310. .__reserved
  311. .iter()
  312. .zip(other.__reserved.iter())
  313. .all(|(a,b)| a == b)
  314. }
  315. }
  316. impl Eq for sysinfo {}
  317. impl ::fmt::Debug for sysinfo {
  318. fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
  319. f.debug_struct("sysinfo")
  320. .field("uptime", &self.uptime)
  321. .field("loads", &self.loads)
  322. .field("totalram", &self.totalram)
  323. .field("freeram", &self.freeram)
  324. .field("sharedram", &self.sharedram)
  325. .field("bufferram", &self.bufferram)
  326. .field("totalswap", &self.totalswap)
  327. .field("freeswap", &self.freeswap)
  328. .field("procs", &self.procs)
  329. .field("pad", &self.pad)
  330. .field("totalhigh", &self.totalhigh)
  331. .field("freehigh", &self.freehigh)
  332. .field("mem_unit", &self.mem_unit)
  333. // FIXME: .field("__reserved", &self.__reserved)
  334. .finish()
  335. }
  336. }
  337. impl ::hash::Hash for sysinfo {
  338. fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
  339. self.uptime.hash(state);
  340. self.loads.hash(state);
  341. self.totalram.hash(state);
  342. self.freeram.hash(state);
  343. self.sharedram.hash(state);
  344. self.bufferram.hash(state);
  345. self.totalswap.hash(state);
  346. self.freeswap.hash(state);
  347. self.procs.hash(state);
  348. self.pad.hash(state);
  349. self.totalhigh.hash(state);
  350. self.freehigh.hash(state);
  351. self.mem_unit.hash(state);
  352. self.__reserved.hash(state);
  353. }
  354. }
  355. impl PartialEq for utmpx {
  356. fn eq(&self, other: &utmpx) -> bool {
  357. self.ut_type == other.ut_type
  358. //&& self.__ut_pad1 == other.__ut_pad1
  359. && self.ut_pid == other.ut_pid
  360. && self.ut_line == other.ut_line
  361. && self.ut_id == other.ut_id
  362. && self.ut_user == other.ut_user
  363. && self
  364. .ut_host
  365. .iter()
  366. .zip(other.ut_host.iter())
  367. .all(|(a,b)| a == b)
  368. && self.ut_exit == other.ut_exit
  369. && self.ut_session == other.ut_session
  370. //&& self.__ut_pad2 == other.__ut_pad2
  371. && self.ut_tv == other.ut_tv
  372. && self.ut_addr_v6 == other.ut_addr_v6
  373. && self.__unused == other.__unused
  374. }
  375. }
  376. impl Eq for utmpx {}
  377. impl ::fmt::Debug for utmpx {
  378. fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
  379. f.debug_struct("utmpx")
  380. .field("ut_type", &self.ut_type)
  381. //.field("__ut_pad1", &self.__ut_pad1)
  382. .field("ut_pid", &self.ut_pid)
  383. .field("ut_line", &self.ut_line)
  384. .field("ut_id", &self.ut_id)
  385. .field("ut_user", &self.ut_user)
  386. //FIXME: .field("ut_host", &self.ut_host)
  387. .field("ut_exit", &self.ut_exit)
  388. .field("ut_session", &self.ut_session)
  389. //.field("__ut_pad2", &self.__ut_pad2)
  390. .field("ut_tv", &self.ut_tv)
  391. .field("ut_addr_v6", &self.ut_addr_v6)
  392. .field("__unused", &self.__unused)
  393. .finish()
  394. }
  395. }
  396. impl ::hash::Hash for utmpx {
  397. fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
  398. self.ut_type.hash(state);
  399. //self.__ut_pad1.hash(state);
  400. self.ut_pid.hash(state);
  401. self.ut_line.hash(state);
  402. self.ut_id.hash(state);
  403. self.ut_user.hash(state);
  404. self.ut_host.hash(state);
  405. self.ut_exit.hash(state);
  406. self.ut_session.hash(state);
  407. //self.__ut_pad2.hash(state);
  408. self.ut_tv.hash(state);
  409. self.ut_addr_v6.hash(state);
  410. self.__unused.hash(state);
  411. }
  412. }
  413. }
  414. }
  415. // include/sys/mman.h
  416. /*
  417. * Huge page size encoding when MAP_HUGETLB is specified, and a huge page
  418. * size other than the default is desired. See hugetlb_encode.h.
  419. * All known huge page size encodings are provided here. It is the
  420. * responsibility of the application to know which sizes are supported on
  421. * the running system. See mmap(2) man page for details.
  422. */
  423. pub const MAP_HUGE_SHIFT: ::c_int = 26;
  424. pub const MAP_HUGE_MASK: ::c_int = 0x3f;
  425. pub const MAP_HUGE_64KB: ::c_int = 16 << MAP_HUGE_SHIFT;
  426. pub const MAP_HUGE_512KB: ::c_int = 19 << MAP_HUGE_SHIFT;
  427. pub const MAP_HUGE_1MB: ::c_int = 20 << MAP_HUGE_SHIFT;
  428. pub const MAP_HUGE_2MB: ::c_int = 21 << MAP_HUGE_SHIFT;
  429. pub const MAP_HUGE_8MB: ::c_int = 23 << MAP_HUGE_SHIFT;
  430. pub const MAP_HUGE_16MB: ::c_int = 24 << MAP_HUGE_SHIFT;
  431. pub const MAP_HUGE_32MB: ::c_int = 25 << MAP_HUGE_SHIFT;
  432. pub const MAP_HUGE_256MB: ::c_int = 28 << MAP_HUGE_SHIFT;
  433. pub const MAP_HUGE_512MB: ::c_int = 29 << MAP_HUGE_SHIFT;
  434. pub const MAP_HUGE_1GB: ::c_int = 30 << MAP_HUGE_SHIFT;
  435. pub const MAP_HUGE_2GB: ::c_int = 31 << MAP_HUGE_SHIFT;
  436. pub const MAP_HUGE_16GB: ::c_int = 34 << MAP_HUGE_SHIFT;
  437. pub const MS_RMT_MASK: ::c_ulong = 0x02800051;
  438. pub const SFD_CLOEXEC: ::c_int = 0x080000;
  439. pub const NCCS: usize = 32;
  440. pub const O_TRUNC: ::c_int = 512;
  441. pub const O_NOATIME: ::c_int = 0o1000000;
  442. pub const O_CLOEXEC: ::c_int = 0x80000;
  443. pub const O_TMPFILE: ::c_int = 0o20000000 | O_DIRECTORY;
  444. pub const EBFONT: ::c_int = 59;
  445. pub const ENOSTR: ::c_int = 60;
  446. pub const ENODATA: ::c_int = 61;
  447. pub const ETIME: ::c_int = 62;
  448. pub const ENOSR: ::c_int = 63;
  449. pub const ENONET: ::c_int = 64;
  450. pub const ENOPKG: ::c_int = 65;
  451. pub const EREMOTE: ::c_int = 66;
  452. pub const ENOLINK: ::c_int = 67;
  453. pub const EADV: ::c_int = 68;
  454. pub const ESRMNT: ::c_int = 69;
  455. pub const ECOMM: ::c_int = 70;
  456. pub const EPROTO: ::c_int = 71;
  457. pub const EDOTDOT: ::c_int = 73;
  458. pub const F_RDLCK: ::c_int = 0;
  459. pub const F_WRLCK: ::c_int = 1;
  460. pub const F_UNLCK: ::c_int = 2;
  461. pub const SA_NODEFER: ::c_int = 0x40000000;
  462. pub const SA_RESETHAND: ::c_int = 0x80000000;
  463. pub const SA_RESTART: ::c_int = 0x10000000;
  464. pub const SA_NOCLDSTOP: ::c_int = 0x00000001;
  465. pub const EPOLL_CLOEXEC: ::c_int = 0x80000;
  466. pub const EFD_CLOEXEC: ::c_int = 0x80000;
  467. pub const BUFSIZ: ::c_uint = 1024;
  468. pub const TMP_MAX: ::c_uint = 10000;
  469. pub const FOPEN_MAX: ::c_uint = 1000;
  470. pub const FILENAME_MAX: ::c_uint = 4096;
  471. pub const O_PATH: ::c_int = 0o10000000;
  472. pub const O_EXEC: ::c_int = 0o10000000;
  473. pub const O_SEARCH: ::c_int = 0o10000000;
  474. pub const O_ACCMODE: ::c_int = 0o10000003;
  475. pub const O_NDELAY: ::c_int = O_NONBLOCK;
  476. pub const NI_MAXHOST: ::socklen_t = 255;
  477. pub const PTHREAD_STACK_MIN: ::size_t = 2048;
  478. pub const POSIX_MADV_DONTNEED: ::c_int = 4;
  479. pub const MAP_ANONYMOUS: ::c_int = MAP_ANON;
  480. pub const SOCK_DCCP: ::c_int = 6;
  481. pub const SOCK_PACKET: ::c_int = 10;
  482. pub const SOMAXCONN: ::c_int = 128;
  483. #[deprecated(since = "0.2.55", note = "Use SIGSYS instead")]
  484. pub const SIGUNUSED: ::c_int = ::SIGSYS;
  485. pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
  486. pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
  487. pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;
  488. pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4;
  489. pub const CPU_SETSIZE: ::c_int = 128;
  490. pub const PTRACE_TRACEME: ::c_int = 0;
  491. pub const PTRACE_PEEKTEXT: ::c_int = 1;
  492. pub const PTRACE_PEEKDATA: ::c_int = 2;
  493. pub const PTRACE_PEEKUSER: ::c_int = 3;
  494. pub const PTRACE_POKETEXT: ::c_int = 4;
  495. pub const PTRACE_POKEDATA: ::c_int = 5;
  496. pub const PTRACE_POKEUSER: ::c_int = 6;
  497. pub const PTRACE_CONT: ::c_int = 7;
  498. pub const PTRACE_KILL: ::c_int = 8;
  499. pub const PTRACE_SINGLESTEP: ::c_int = 9;
  500. pub const PTRACE_GETREGS: ::c_int = 12;
  501. pub const PTRACE_SETREGS: ::c_int = 13;
  502. pub const PTRACE_GETFPREGS: ::c_int = 14;
  503. pub const PTRACE_SETFPREGS: ::c_int = 15;
  504. pub const PTRACE_ATTACH: ::c_int = 16;
  505. pub const PTRACE_DETACH: ::c_int = 17;
  506. pub const PTRACE_GETFPXREGS: ::c_int = 18;
  507. pub const PTRACE_SETFPXREGS: ::c_int = 19;
  508. pub const PTRACE_SYSCALL: ::c_int = 24;
  509. pub const PTRACE_SETOPTIONS: ::c_int = 0x4200;
  510. pub const PTRACE_GETEVENTMSG: ::c_int = 0x4201;
  511. pub const PTRACE_GETSIGINFO: ::c_int = 0x4202;
  512. pub const PTRACE_SETSIGINFO: ::c_int = 0x4203;
  513. pub const PTRACE_GETREGSET: ::c_int = 0x4204;
  514. pub const PTRACE_SETREGSET: ::c_int = 0x4205;
  515. pub const PTRACE_SEIZE: ::c_int = 0x4206;
  516. pub const PTRACE_INTERRUPT: ::c_int = 0x4207;
  517. pub const PTRACE_LISTEN: ::c_int = 0x4208;
  518. pub const PTRACE_PEEKSIGINFO: ::c_int = 0x4209;
  519. pub const FAN_MARK_INODE: ::c_uint = 0x0000_0000;
  520. pub const FAN_MARK_MOUNT: ::c_uint = 0x0000_0010;
  521. // NOTE: FAN_MARK_FILESYSTEM requires Linux Kernel >= 4.20.0
  522. pub const FAN_MARK_FILESYSTEM: ::c_uint = 0x0000_0100;
  523. pub const AF_IB: ::c_int = 27;
  524. pub const AF_MPLS: ::c_int = 28;
  525. pub const AF_NFC: ::c_int = 39;
  526. pub const AF_VSOCK: ::c_int = 40;
  527. pub const AF_XDP: ::c_int = 44;
  528. pub const PF_IB: ::c_int = AF_IB;
  529. pub const PF_MPLS: ::c_int = AF_MPLS;
  530. pub const PF_NFC: ::c_int = AF_NFC;
  531. pub const PF_VSOCK: ::c_int = AF_VSOCK;
  532. pub const PF_XDP: ::c_int = AF_XDP;
  533. pub const EFD_NONBLOCK: ::c_int = ::O_NONBLOCK;
  534. pub const SFD_NONBLOCK: ::c_int = ::O_NONBLOCK;
  535. pub const PIDFD_NONBLOCK: ::c_uint = O_NONBLOCK as ::c_uint;
  536. pub const TCSANOW: ::c_int = 0;
  537. pub const TCSADRAIN: ::c_int = 1;
  538. pub const TCSAFLUSH: ::c_int = 2;
  539. pub const RTLD_GLOBAL: ::c_int = 0x100;
  540. pub const RTLD_NOLOAD: ::c_int = 0x4;
  541. pub const CLOCK_SGI_CYCLE: ::clockid_t = 10;
  542. pub const B0: ::speed_t = 0o000000;
  543. pub const B50: ::speed_t = 0o000001;
  544. pub const B75: ::speed_t = 0o000002;
  545. pub const B110: ::speed_t = 0o000003;
  546. pub const B134: ::speed_t = 0o000004;
  547. pub const B150: ::speed_t = 0o000005;
  548. pub const B200: ::speed_t = 0o000006;
  549. pub const B300: ::speed_t = 0o000007;
  550. pub const B600: ::speed_t = 0o000010;
  551. pub const B1200: ::speed_t = 0o000011;
  552. pub const B1800: ::speed_t = 0o000012;
  553. pub const B2400: ::speed_t = 0o000013;
  554. pub const B4800: ::speed_t = 0o000014;
  555. pub const B9600: ::speed_t = 0o000015;
  556. pub const B19200: ::speed_t = 0o000016;
  557. pub const B38400: ::speed_t = 0o000017;
  558. pub const EXTA: ::speed_t = B19200;
  559. pub const EXTB: ::speed_t = B38400;
  560. pub const REG_OK: ::c_int = 0;
  561. pub const PRIO_PROCESS: ::c_int = 0;
  562. pub const PRIO_PGRP: ::c_int = 1;
  563. pub const PRIO_USER: ::c_int = 2;
  564. pub const ADJ_OFFSET: ::c_uint = 0x0001;
  565. pub const ADJ_FREQUENCY: ::c_uint = 0x0002;
  566. pub const ADJ_MAXERROR: ::c_uint = 0x0004;
  567. pub const ADJ_ESTERROR: ::c_uint = 0x0008;
  568. pub const ADJ_STATUS: ::c_uint = 0x0010;
  569. pub const ADJ_TIMECONST: ::c_uint = 0x0020;
  570. pub const ADJ_TAI: ::c_uint = 0x0080;
  571. pub const ADJ_SETOFFSET: ::c_uint = 0x0100;
  572. pub const ADJ_MICRO: ::c_uint = 0x1000;
  573. pub const ADJ_NANO: ::c_uint = 0x2000;
  574. pub const ADJ_TICK: ::c_uint = 0x4000;
  575. pub const ADJ_OFFSET_SINGLESHOT: ::c_uint = 0x8001;
  576. pub const ADJ_OFFSET_SS_READ: ::c_uint = 0xa001;
  577. pub const MOD_OFFSET: ::c_uint = ADJ_OFFSET;
  578. pub const MOD_FREQUENCY: ::c_uint = ADJ_FREQUENCY;
  579. pub const MOD_MAXERROR: ::c_uint = ADJ_MAXERROR;
  580. pub const MOD_ESTERROR: ::c_uint = ADJ_ESTERROR;
  581. pub const MOD_STATUS: ::c_uint = ADJ_STATUS;
  582. pub const MOD_TIMECONST: ::c_uint = ADJ_TIMECONST;
  583. pub const MOD_CLKB: ::c_uint = ADJ_TICK;
  584. pub const MOD_CLKA: ::c_uint = ADJ_OFFSET_SINGLESHOT;
  585. pub const MOD_TAI: ::c_uint = ADJ_TAI;
  586. pub const MOD_MICRO: ::c_uint = ADJ_MICRO;
  587. pub const MOD_NANO: ::c_uint = ADJ_NANO;
  588. pub const STA_PLL: ::c_int = 0x0001;
  589. pub const STA_PPSFREQ: ::c_int = 0x0002;
  590. pub const STA_PPSTIME: ::c_int = 0x0004;
  591. pub const STA_FLL: ::c_int = 0x0008;
  592. pub const STA_INS: ::c_int = 0x0010;
  593. pub const STA_DEL: ::c_int = 0x0020;
  594. pub const STA_UNSYNC: ::c_int = 0x0040;
  595. pub const STA_FREQHOLD: ::c_int = 0x0080;
  596. pub const STA_PPSSIGNAL: ::c_int = 0x0100;
  597. pub const STA_PPSJITTER: ::c_int = 0x0200;
  598. pub const STA_PPSWANDER: ::c_int = 0x0400;
  599. pub const STA_PPSERROR: ::c_int = 0x0800;
  600. pub const STA_CLOCKERR: ::c_int = 0x1000;
  601. pub const STA_NANO: ::c_int = 0x2000;
  602. pub const STA_MODE: ::c_int = 0x4000;
  603. pub const STA_CLK: ::c_int = 0x8000;
  604. pub const STA_RONLY: ::c_int = STA_PPSSIGNAL
  605. | STA_PPSJITTER
  606. | STA_PPSWANDER
  607. | STA_PPSERROR
  608. | STA_CLOCKERR
  609. | STA_NANO
  610. | STA_MODE
  611. | STA_CLK;
  612. pub const TIME_OK: ::c_int = 0;
  613. pub const TIME_INS: ::c_int = 1;
  614. pub const TIME_DEL: ::c_int = 2;
  615. pub const TIME_OOP: ::c_int = 3;
  616. pub const TIME_WAIT: ::c_int = 4;
  617. pub const TIME_ERROR: ::c_int = 5;
  618. pub const TIME_BAD: ::c_int = TIME_ERROR;
  619. pub const MAXTC: ::c_long = 6;
  620. cfg_if! {
  621. if #[cfg(target_arch = "s390x")] {
  622. pub const POSIX_FADV_DONTNEED: ::c_int = 6;
  623. pub const POSIX_FADV_NOREUSE: ::c_int = 7;
  624. } else {
  625. pub const POSIX_FADV_DONTNEED: ::c_int = 4;
  626. pub const POSIX_FADV_NOREUSE: ::c_int = 5;
  627. }
  628. }
  629. #[allow(dead_code)]
  630. extern "C" {
  631. pub fn sendmmsg(
  632. sockfd: ::c_int,
  633. msgvec: *mut ::mmsghdr,
  634. vlen: ::c_uint,
  635. flags: ::c_uint,
  636. ) -> ::c_int;
  637. pub fn recvmmsg(
  638. sockfd: ::c_int,
  639. msgvec: *mut ::mmsghdr,
  640. vlen: ::c_uint,
  641. flags: ::c_uint,
  642. timeout: *mut ::timespec,
  643. ) -> ::c_int;
  644. pub fn getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int;
  645. pub fn setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int;
  646. pub fn prlimit(
  647. pid: ::pid_t,
  648. resource: ::c_int,
  649. new_limit: *const ::rlimit,
  650. old_limit: *mut ::rlimit,
  651. ) -> ::c_int;
  652. pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int;
  653. //pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int;
  654. pub fn ptrace(request: ::c_int, ...) -> ::c_long;
  655. pub fn getpriority(which: ::c_int, who: ::id_t) -> ::c_int;
  656. pub fn setpriority(which: ::c_int, who: ::id_t, prio: ::c_int) -> ::c_int;
  657. // Musl targets need the `mask` argument of `fanotify_mark` be specified
  658. // `::c_ulonglong` instead of `u64` or there will be a type mismatch between
  659. // `long long unsigned int` and the expected `uint64_t`.
  660. pub fn fanotify_mark(
  661. fd: ::c_int,
  662. flags: ::c_uint,
  663. mask: ::c_ulonglong,
  664. dirfd: ::c_int,
  665. path: *const ::c_char,
  666. ) -> ::c_int;
  667. pub fn getauxval(type_: ::c_ulong) -> ::c_ulong;
  668. // Added in `musl` 1.1.20
  669. pub fn explicit_bzero(s: *mut ::c_void, len: ::size_t);
  670. // Added in `musl` 1.2.2
  671. pub fn reallocarray(ptr: *mut ::c_void, nmemb: ::size_t, size: ::size_t) -> *mut ::c_void;
  672. pub fn adjtimex(buf: *mut ::timex) -> ::c_int;
  673. pub fn clock_adjtime(clk_id: ::clockid_t, buf: *mut ::timex) -> ::c_int;
  674. pub fn ctermid(s: *mut ::c_char) -> *mut ::c_char;
  675. pub fn memfd_create(name: *const ::c_char, flags: ::c_uint) -> ::c_int;
  676. pub fn mlock2(addr: *const ::c_void, len: ::size_t, flags: ::c_uint) -> ::c_int;
  677. pub fn malloc_usable_size(ptr: *mut ::c_void) -> ::size_t;
  678. pub fn euidaccess(pathname: *const ::c_char, mode: ::c_int) -> ::c_int;
  679. pub fn eaccess(pathname: *const ::c_char, mode: ::c_int) -> ::c_int;
  680. pub fn asctime_r(tm: *const ::tm, buf: *mut ::c_char) -> *mut ::c_char;
  681. pub fn strftime(
  682. s: *mut ::c_char,
  683. max: ::size_t,
  684. format: *const ::c_char,
  685. tm: *const ::tm,
  686. ) -> ::size_t;
  687. pub fn strptime(s: *const ::c_char, format: *const ::c_char, tm: *mut ::tm) -> *mut ::c_char;
  688. pub fn dirname(path: *mut ::c_char) -> *mut ::c_char;
  689. pub fn basename(path: *mut ::c_char) -> *mut ::c_char;
  690. }
  691. // Alias <foo> to <foo>64 to mimic glibc's LFS64 support
  692. mod lfs64;
  693. pub use self::lfs64::*;
  694. cfg_if! {
  695. if #[cfg(any(target_arch = "x86_64",
  696. target_arch = "aarch64",
  697. target_arch = "mips64",
  698. target_arch = "powerpc64",
  699. target_arch = "s390x",
  700. target_arch = "riscv64"))] {
  701. mod b64;
  702. pub use self::b64::*;
  703. } else if #[cfg(any(target_arch = "x86",
  704. target_arch = "mips",
  705. target_arch = "powerpc",
  706. target_arch = "hexagon",
  707. target_arch = "riscv32",
  708. target_arch = "arm"))] {
  709. mod b32;
  710. pub use self::b32::*;
  711. } else { }
  712. }