Vendor deps.

This commit is contained in:
jimmy committed 2026-09-16 20:10:35 -04:00
1 parent 294527085e
commit 91e18fde3a
1714 files changed
+556667 -7

No files matched your search

+69
View File
@@ -0,0 +1,69 @@
use crate::off_t;
use crate::prelude::*;
pub type __u64 = c_ulonglong;
pub type wchar_t = u32;
pub type nlink_t = c_ulong;
pub type blksize_t = c_long;
s! {
pub struct stat {
pub st_dev: crate::dev_t,
pub st_ino: crate::ino_t,
pub st_mode: crate::mode_t,
pub st_nlink: crate::nlink_t,
pub st_uid: crate::uid_t,
pub st_gid: crate::gid_t,
pub st_rdev: crate::dev_t,
__pad0: Padding<c_ulong>,
pub st_size: off_t,
pub st_blksize: crate::blksize_t,
__pad1: Padding<c_int>,
pub st_blocks: crate::blkcnt_t,
pub st_atime: crate::time_t,
pub st_atime_nsec: c_long,
pub st_mtime: crate::time_t,
pub st_mtime_nsec: c_long,
pub st_ctime: crate::time_t,
pub st_ctime_nsec: c_long,
__unused: Padding<[c_uint; 2]>,
}
pub struct stat64 {
pub st_dev: crate::dev_t,
pub st_ino: crate::ino_t,
pub st_mode: crate::mode_t,
pub st_nlink: crate::nlink_t,
pub st_uid: crate::uid_t,
pub st_gid: crate::gid_t,
pub st_rdev: crate::dev_t,
__pad0: Padding<c_ulong>,
pub st_size: off_t,
pub st_blksize: crate::blksize_t,
__pad1: Padding<c_int>,
pub st_blocks: crate::blkcnt_t,
pub st_atime: crate::time_t,
pub st_atime_nsec: c_long,
pub st_mtime: crate::time_t,
pub st_mtime_nsec: c_long,
pub st_ctime: crate::time_t,
pub st_ctime_nsec: c_long,
__unused: Padding<[c_uint; 2]>,
}
pub struct ipc_perm {
pub __ipc_perm_key: crate::key_t,
pub uid: crate::uid_t,
pub gid: crate::gid_t,
pub cuid: crate::uid_t,
pub cgid: crate::gid_t,
pub mode: crate::mode_t,
pub __seq: c_ushort,
__unused1: Padding<c_ulong>,
__unused2: Padding<c_ulong>,
}
}
// From https://cs.opensource.google/fuchsia/fuchsia/+/main:zircon/third_party/ulib/musl/include/bits/signal.h;l=20-21;drc=0827b18ab9540c46f8037f407d17ea15a79e9ba7
pub const MINSIGSTKSZ: size_t = 6144;
pub const SIGSTKSZ: size_t = 12288;
+4028
View File
File diff suppressed because it is too large. Load diff
+46
View File
@@ -0,0 +1,46 @@
use crate::off_t;
use crate::prelude::*;
// From psABI Calling Convention for RV64
pub type __u64 = c_ulonglong;
pub type wchar_t = i32;
pub type nlink_t = c_ulong;
pub type blksize_t = c_long;
pub type stat64 = stat;
s! {
pub struct stat {
pub st_dev: crate::dev_t,
pub st_ino: crate::ino_t,
pub st_nlink: crate::nlink_t,
pub st_mode: crate::mode_t,
pub st_uid: crate::uid_t,
pub st_gid: crate::gid_t,
__pad0: Padding<c_int>,
pub st_rdev: crate::dev_t,
pub st_size: off_t,
pub st_blksize: crate::blksize_t,
pub st_blocks: crate::blkcnt_t,
pub st_atime: crate::time_t,
pub st_atime_nsec: c_long,
pub st_mtime: crate::time_t,
pub st_mtime_nsec: c_long,
pub st_ctime: crate::time_t,
pub st_ctime_nsec: c_long,
__unused: Padding<[c_long; 3]>,
}
// Not actually used, IPC calls just return ENOSYS
pub struct ipc_perm {
pub __ipc_perm_key: crate::key_t,
pub uid: crate::uid_t,
pub gid: crate::gid_t,
pub cuid: crate::uid_t,
pub cgid: crate::gid_t,
pub mode: crate::mode_t,
pub __seq: c_ushort,
__unused1: Padding<c_ulong>,
__unused2: Padding<c_ulong>,
}
}
+110
View File
@@ -0,0 +1,110 @@
use crate::off_t;
use crate::prelude::*;
pub type wchar_t = i32;
pub type nlink_t = u64;
pub type blksize_t = c_long;
pub type __u64 = c_ulonglong;
s! {
pub struct stat {
pub st_dev: crate::dev_t,
pub st_ino: crate::ino_t,
pub st_nlink: crate::nlink_t,
pub st_mode: crate::mode_t,
pub st_uid: crate::uid_t,
pub st_gid: crate::gid_t,
__pad0: Padding<c_int>,
pub st_rdev: crate::dev_t,
pub st_size: off_t,
pub st_blksize: crate::blksize_t,
pub st_blocks: crate::blkcnt_t,
pub st_atime: crate::time_t,
pub st_atime_nsec: c_long,
pub st_mtime: crate::time_t,
pub st_mtime_nsec: c_long,
pub st_ctime: crate::time_t,
pub st_ctime_nsec: c_long,
__unused: Padding<[c_long; 3]>,
}
pub struct stat64 {
pub st_dev: crate::dev_t,
pub st_ino: crate::ino64_t,
pub st_nlink: crate::nlink_t,
pub st_mode: crate::mode_t,
pub st_uid: crate::uid_t,
pub st_gid: crate::gid_t,
__pad0: Padding<c_int>,
pub st_rdev: crate::dev_t,
pub st_size: off_t,
pub st_blksize: crate::blksize_t,
pub st_blocks: crate::blkcnt64_t,
pub st_atime: crate::time_t,
pub st_atime_nsec: c_long,
pub st_mtime: crate::time_t,
pub st_mtime_nsec: c_long,
pub st_ctime: crate::time_t,
pub st_ctime_nsec: c_long,
__reserved: Padding<[c_long; 3]>,
}
pub struct mcontext_t {
__private: [u64; 32],
}
pub struct ipc_perm {
pub __ipc_perm_key: crate::key_t,
pub uid: crate::uid_t,
pub gid: crate::gid_t,
pub cuid: crate::uid_t,
pub cgid: crate::gid_t,
pub mode: crate::mode_t,
pub __seq: c_int,
__unused1: Padding<c_long>,
__unused2: Padding<c_long>,
}
pub struct ucontext_t {
pub uc_flags: c_ulong,
pub uc_link: *mut ucontext_t,
pub uc_stack: crate::stack_t,
pub uc_mcontext: mcontext_t,
pub uc_sigmask: crate::sigset_t,
__private: [u8; 512],
}
}
// offsets in user_regs_structs, from sys/reg.h
pub const R15: c_int = 0;
pub const R14: c_int = 1;
pub const R13: c_int = 2;
pub const R12: c_int = 3;
pub const RBP: c_int = 4;
pub const RBX: c_int = 5;
pub const R11: c_int = 6;
pub const R10: c_int = 7;
pub const R9: c_int = 8;
pub const R8: c_int = 9;
pub const RAX: c_int = 10;
pub const RCX: c_int = 11;
pub const RDX: c_int = 12;
pub const RSI: c_int = 13;
pub const RDI: c_int = 14;
pub const ORIG_RAX: c_int = 15;
pub const RIP: c_int = 16;
pub const CS: c_int = 17;
pub const EFLAGS: c_int = 18;
pub const RSP: c_int = 19;
pub const SS: c_int = 20;
pub const FS_BASE: c_int = 21;
pub const GS_BASE: c_int = 22;
pub const DS: c_int = 23;
pub const ES: c_int = 24;
pub const FS: c_int = 25;
pub const GS: c_int = 26;
pub const MAP_32BIT: c_int = 0x0040;
pub const SIGSTKSZ: size_t = 8192;
pub const MINSIGSTKSZ: size_t = 2048;
+562
View File
@@ -0,0 +1,562 @@
//! Hermit C type definitions
use crate::prelude::*;
pub type intmax_t = i64;
pub type uintmax_t = u64;
pub type intptr_t = isize;
pub type uintptr_t = usize;
pub type size_t = usize;
pub type ssize_t = isize;
pub type ptrdiff_t = isize;
pub type clockid_t = i32;
pub type in_addr_t = u32;
pub type in_port_t = u16;
pub type mode_t = u32;
pub type nfds_t = usize;
pub type pid_t = i32;
pub type sa_family_t = u8;
pub type socklen_t = u32;
pub type time_t = i64;
s! {
pub struct addrinfo {
pub ai_flags: i32,
pub ai_family: i32,
pub ai_socktype: i32,
pub ai_protocol: i32,
pub ai_addrlen: socklen_t,
pub ai_canonname: *mut c_char,
pub ai_addr: *mut sockaddr,
pub ai_next: *mut addrinfo,
}
pub struct dirent64 {
pub d_ino: u64,
pub d_off: i64,
pub d_reclen: u16,
pub d_type: u8,
pub d_name: [c_char; 256],
}
#[repr(align(4))]
pub struct in6_addr {
pub s6_addr: [u8; 16],
}
pub struct in_addr {
pub s_addr: in_addr_t,
}
pub struct iovec {
iov_base: *mut c_void,
iov_len: usize,
}
pub struct pollfd {
pub fd: i32,
pub events: i16,
pub revents: i16,
}
pub struct sockaddr {
pub sa_len: u8,
pub sa_family: sa_family_t,
pub sa_data: [c_char; 14],
}
pub struct sockaddr_in {
pub sin_len: u8,
pub sin_family: sa_family_t,
pub sin_port: in_port_t,
pub sin_addr: in_addr,
pub sin_zero: [c_char; 8],
}
pub struct sockaddr_in6 {
pub sin6_len: u8,
pub sin6_family: sa_family_t,
pub sin6_port: in_port_t,
pub sin6_flowinfo: u32,
pub sin6_addr: in6_addr,
pub sin6_scope_id: u32,
}
pub struct sockaddr_storage {
pub ss_len: u8,
pub ss_family: sa_family_t,
__ss_pad1: Padding<[u8; 6]>,
__ss_align: i64,
__ss_pad2: Padding<[u8; 112]>,
}
pub struct stat {
pub st_dev: u64,
pub st_ino: u64,
pub st_nlink: u64,
pub st_mode: mode_t,
pub st_uid: u32,
pub st_gid: u32,
pub st_rdev: u64,
pub st_size: i64,
pub st_blksize: i64,
pub st_blocks: i64,
pub st_atim: timespec,
pub st_mtim: timespec,
pub st_ctim: timespec,
}
#[derive(Default)]
pub struct timespec {
pub tv_sec: time_t,
pub tv_nsec: i32,
}
}
pub const AF_UNSPEC: i32 = 0;
pub const AF_INET: i32 = 3;
pub const AF_INET6: i32 = 1;
pub const AF_VSOCK: i32 = 2;
pub const CLOCK_REALTIME: clockid_t = 1;
pub const CLOCK_MONOTONIC: clockid_t = 4;
pub const DT_UNKNOWN: u8 = 0;
pub const DT_FIFO: u8 = 1;
pub const DT_CHR: u8 = 2;
pub const DT_DIR: u8 = 4;
pub const DT_BLK: u8 = 6;
pub const DT_REG: u8 = 8;
pub const DT_LNK: u8 = 10;
pub const DT_SOCK: u8 = 12;
pub const DT_WHT: u8 = 14;
pub const EAI_AGAIN: i32 = 2;
pub const EAI_BADFLAGS: i32 = 3;
pub const EAI_FAIL: i32 = 4;
pub const EAI_FAMILY: i32 = 5;
pub const EAI_MEMORY: i32 = 6;
pub const EAI_NODATA: i32 = 7;
pub const EAI_NONAME: i32 = 8;
pub const EAI_SERVICE: i32 = 9;
pub const EAI_SOCKTYPE: i32 = 10;
pub const EAI_SYSTEM: i32 = 11;
pub const EAI_OVERFLOW: i32 = 14;
pub const EFD_SEMAPHORE: i16 = 0o1;
pub const EFD_NONBLOCK: i16 = 0o4000;
pub const EFD_CLOEXEC: i16 = 0o40000;
pub const F_DUPFD: i32 = 0;
pub const F_GETFD: i32 = 1;
pub const F_SETFD: i32 = 2;
pub const F_GETFL: i32 = 3;
pub const F_SETFL: i32 = 4;
pub const FD_CLOEXEC: i32 = 1;
pub const FIONBIO: i32 = u32_cast_int(0x8008667e);
pub const FUTEX_RELATIVE_TIMEOUT: u32 = 1;
pub const IP_TOS: i32 = 1;
pub const IP_TTL: i32 = 2;
pub const IP_ADD_MEMBERSHIP: i32 = 3;
pub const IP_DROP_MEMBERSHIP: i32 = 4;
pub const IP_MULTICAST_TTL: i32 = 5;
pub const IP_MULTICAST_LOOP: i32 = 7;
pub const IPPROTO_IP: i32 = 0;
pub const IPPROTO_TCP: i32 = 6;
pub const IPPROTO_UDP: i32 = 17;
pub const IPPROTO_IPV6: i32 = 41;
pub const IPV6_ADD_MEMBERSHIP: i32 = 12;
pub const IPV6_DROP_MEMBERSHIP: i32 = 13;
pub const IPV6_MULTICAST_LOOP: i32 = 19;
pub const IPV6_V6ONLY: i32 = 27;
pub const MSG_PEEK: i32 = 1;
pub const O_RDONLY: i32 = 0o0;
pub const O_WRONLY: i32 = 0o1;
pub const O_RDWR: i32 = 0o2;
pub const O_CREAT: i32 = 0o100;
pub const O_EXCL: i32 = 0o200;
pub const O_TRUNC: i32 = 0o1000;
pub const O_APPEND: i32 = 0o2000;
pub const O_NONBLOCK: i32 = 0o4000;
pub const O_DIRECTORY: i32 = 0o200000;
pub const POLLIN: i16 = 0x1;
pub const POLLPRI: i16 = 0x2;
pub const POLLOUT: i16 = 0x4;
pub const POLLERR: i16 = 0x8;
pub const POLLHUP: i16 = 0x10;
pub const POLLNVAL: i16 = 0x20;
pub const POLLRDNORM: i16 = 0x040;
pub const POLLRDBAND: i16 = 0x080;
pub const POLLWRNORM: i16 = 0x0100;
pub const POLLWRBAND: i16 = 0x0200;
pub const POLLRDHUP: i16 = 0x2000;
pub const S_IRWXU: mode_t = 0o0700;
pub const S_IRUSR: mode_t = 0o0400;
pub const S_IWUSR: mode_t = 0o0200;
pub const S_IXUSR: mode_t = 0o0100;
pub const S_IRWXG: mode_t = 0o0070;
pub const S_IRGRP: mode_t = 0o0040;
pub const S_IWGRP: mode_t = 0o0020;
pub const S_IXGRP: mode_t = 0o0010;
pub const S_IRWXO: mode_t = 0o0007;
pub const S_IROTH: mode_t = 0o0004;
pub const S_IWOTH: mode_t = 0o0002;
pub const S_IXOTH: mode_t = 0o0001;
pub const S_IFMT: mode_t = 0o17_0000;
pub const S_IFSOCK: mode_t = 0o14_0000;
pub const S_IFLNK: mode_t = 0o12_0000;
pub const S_IFREG: mode_t = 0o10_0000;
pub const S_IFBLK: mode_t = 0o6_0000;
pub const S_IFDIR: mode_t = 0o4_0000;
pub const S_IFCHR: mode_t = 0o2_0000;
pub const S_IFIFO: mode_t = 0o1_0000;
pub const SHUT_RD: i32 = 0;
pub const SHUT_WR: i32 = 1;
pub const SHUT_RDWR: i32 = 2;
pub const SO_REUSEADDR: i32 = 0x0004;
pub const SO_KEEPALIVE: i32 = 0x0008;
pub const SO_BROADCAST: i32 = 0x0020;
pub const SO_LINGER: i32 = 0x0080;
pub const SO_SNDBUF: i32 = 0x1001;
pub const SO_RCVBUF: i32 = 0x1002;
pub const SO_SNDTIMEO: i32 = 0x1005;
pub const SO_RCVTIMEO: i32 = 0x1006;
pub const SO_ERROR: i32 = 0x1007;
pub const SOCK_STREAM: i32 = 1;
pub const SOCK_DGRAM: i32 = 2;
pub const SOCK_NONBLOCK: i32 = 0o4000;
pub const SOCK_CLOEXEC: i32 = 0o40000;
pub const SOL_SOCKET: i32 = 4095;
pub const STDIN_FILENO: c_int = 0;
pub const STDOUT_FILENO: c_int = 1;
pub const STDERR_FILENO: c_int = 2;
pub const TCP_NODELAY: i32 = 1;
pub const EPERM: i32 = 1;
pub const ENOENT: i32 = 2;
pub const ESRCH: i32 = 3;
pub const EINTR: i32 = 4;
pub const EIO: i32 = 5;
pub const ENXIO: i32 = 6;
pub const E2BIG: i32 = 7;
pub const ENOEXEC: i32 = 8;
pub const EBADF: i32 = 9;
pub const ECHILD: i32 = 10;
pub const EAGAIN: i32 = 11;
pub const ENOMEM: i32 = 12;
pub const EACCES: i32 = 13;
pub const EFAULT: i32 = 14;
pub const ENOTBLK: i32 = 15;
pub const EBUSY: i32 = 16;
pub const EEXIST: i32 = 17;
pub const EXDEV: i32 = 18;
pub const ENODEV: i32 = 19;
pub const ENOTDIR: i32 = 20;
pub const EISDIR: i32 = 21;
pub const EINVAL: i32 = 22;
pub const ENFILE: i32 = 23;
pub const EMFILE: i32 = 24;
pub const ENOTTY: i32 = 25;
pub const ETXTBSY: i32 = 26;
pub const EFBIG: i32 = 27;
pub const ENOSPC: i32 = 28;
pub const ESPIPE: i32 = 29;
pub const EROFS: i32 = 30;
pub const EMLINK: i32 = 31;
pub const EPIPE: i32 = 32;
pub const EDOM: i32 = 33;
pub const ERANGE: i32 = 34;
pub const EDEADLK: i32 = 35;
pub const ENAMETOOLONG: i32 = 36;
pub const ENOLCK: i32 = 37;
pub const ENOSYS: i32 = 38;
pub const ENOTEMPTY: i32 = 39;
pub const ELOOP: i32 = 40;
pub const EWOULDBLOCK: i32 = EAGAIN;
pub const ENOMSG: i32 = 42;
pub const EIDRM: i32 = 43;
pub const ECHRNG: i32 = 44;
pub const EL2NSYNC: i32 = 45;
pub const EL3HLT: i32 = 46;
pub const EL3RST: i32 = 47;
pub const ELNRNG: i32 = 48;
pub const EUNATCH: i32 = 49;
pub const ENOCSI: i32 = 50;
pub const EL2HLT: i32 = 51;
pub const EBADE: i32 = 52;
pub const EBADR: i32 = 53;
pub const EXFULL: i32 = 54;
pub const ENOANO: i32 = 55;
pub const EBADRQC: i32 = 56;
pub const EBADSLT: i32 = 57;
pub const EDEADLOCK: i32 = EDEADLK;
pub const EBFONT: i32 = 59;
pub const ENOSTR: i32 = 60;
pub const ENODATA: i32 = 61;
pub const ETIME: i32 = 62;
pub const ENOSR: i32 = 63;
pub const ENONET: i32 = 64;
pub const ENOPKG: i32 = 65;
pub const EREMOTE: i32 = 66;
pub const ENOLINK: i32 = 67;
pub const EADV: i32 = 68;
pub const ESRMNT: i32 = 69;
pub const ECOMM: i32 = 70;
pub const EPROTO: i32 = 71;
pub const EMULTIHOP: i32 = 72;
pub const EDOTDOT: i32 = 73;
pub const EBADMSG: i32 = 74;
pub const EOVERFLOW: i32 = 75;
pub const ENOTUNIQ: i32 = 76;
pub const EBADFD: i32 = 77;
pub const EREMCHG: i32 = 78;
pub const ELIBACC: i32 = 79;
pub const ELIBBAD: i32 = 80;
pub const ELIBSCN: i32 = 81;
pub const ELIBMAX: i32 = 82;
pub const ELIBEXEC: i32 = 83;
pub const EILSEQ: i32 = 84;
pub const ERESTART: i32 = 85;
pub const ESTRPIPE: i32 = 86;
pub const EUSERS: i32 = 87;
pub const ENOTSOCK: i32 = 88;
pub const EDESTADDRREQ: i32 = 89;
pub const EMSGSIZE: i32 = 90;
pub const EPROTOTYPE: i32 = 91;
pub const ENOPROTOOPT: i32 = 92;
pub const EPROTONOSUPPORT: i32 = 93;
pub const ESOCKTNOSUPPORT: i32 = 94;
pub const EOPNOTSUPP: i32 = 95;
pub const EPFNOSUPPORT: i32 = 96;
pub const EAFNOSUPPORT: i32 = 97;
pub const EADDRINUSE: i32 = 98;
pub const EADDRNOTAVAIL: i32 = 99;
pub const ENETDOWN: i32 = 100;
pub const ENETUNREACH: i32 = 101;
pub const ENETRESET: i32 = 102;
pub const ECONNABORTED: i32 = 103;
pub const ECONNRESET: i32 = 104;
pub const ENOBUFS: i32 = 105;
pub const EISCONN: i32 = 106;
pub const ENOTCONN: i32 = 107;
pub const ESHUTDOWN: i32 = 108;
pub const ETOOMANYREFS: i32 = 109;
pub const ETIMEDOUT: i32 = 110;
pub const ECONNREFUSED: i32 = 111;
pub const EHOSTDOWN: i32 = 112;
pub const EHOSTUNREACH: i32 = 113;
pub const EALREADY: i32 = 114;
pub const EINPROGRESS: i32 = 115;
pub const ESTALE: i32 = 116;
pub const EUCLEAN: i32 = 117;
pub const ENOTNAM: i32 = 118;
pub const ENAVAIL: i32 = 119;
pub const EISNAM: i32 = 120;
pub const EREMOTEIO: i32 = 121;
pub const EDQUOT: i32 = 122;
pub const ENOMEDIUM: i32 = 123;
pub const EMEDIUMTYPE: i32 = 124;
pub const ECANCELED: i32 = 125;
pub const ENOKEY: i32 = 126;
pub const EKEYEXPIRED: i32 = 127;
pub const EKEYREVOKED: i32 = 128;
pub const EKEYREJECTED: i32 = 129;
pub const EOWNERDEAD: i32 = 130;
pub const ENOTRECOVERABLE: i32 = 131;
pub const ERFKILL: i32 = 132;
pub const EHWPOISON: i32 = 133;
extern "C" {
#[link_name = "sys_alloc"]
pub fn alloc(size: usize, align: usize) -> *mut u8;
#[link_name = "sys_alloc_zeroed"]
pub fn alloc_zeroed(size: usize, align: usize) -> *mut u8;
#[link_name = "sys_realloc"]
pub fn realloc(ptr: *mut u8, size: usize, align: usize, new_size: usize) -> *mut u8;
#[link_name = "sys_dealloc"]
pub fn dealloc(ptr: *mut u8, size: usize, align: usize);
#[link_name = "sys_exit"]
pub fn exit(status: i32) -> !;
#[link_name = "sys_abort"]
pub fn abort() -> !;
#[link_name = "sys_errno"]
pub fn errno() -> i32;
#[link_name = "sys_clock_gettime"]
pub fn clock_gettime(clockid: clockid_t, tp: *mut timespec) -> i32;
#[link_name = "sys_nanosleep"]
pub fn nanosleep(req: *const timespec) -> i32;
#[link_name = "sys_available_parallelism"]
pub fn available_parallelism() -> usize;
#[link_name = "sys_futex_wait"]
pub fn futex_wait(
address: *mut u32,
expected: u32,
timeout: *const timespec,
flags: u32,
) -> i32;
#[link_name = "sys_futex_wake"]
pub fn futex_wake(address: *mut u32, count: i32) -> i32;
#[link_name = "sys_stat"]
pub fn stat(path: *const c_char, stat: *mut stat) -> i32;
#[link_name = "sys_fstat"]
pub fn fstat(fd: i32, stat: *mut stat) -> i32;
#[link_name = "sys_lstat"]
pub fn lstat(path: *const c_char, stat: *mut stat) -> i32;
#[link_name = "sys_open"]
pub fn open(path: *const c_char, flags: i32, mode: mode_t) -> i32;
#[link_name = "sys_unlink"]
pub fn unlink(path: *const c_char) -> i32;
#[link_name = "sys_mkdir"]
pub fn mkdir(path: *const c_char, mode: mode_t) -> i32;
#[link_name = "sys_rmdir"]
pub fn rmdir(path: *const c_char) -> i32;
#[link_name = "sys_read"]
pub fn read(fd: i32, buf: *mut u8, len: usize) -> isize;
#[link_name = "sys_write"]
pub fn write(fd: i32, buf: *const u8, len: usize) -> isize;
#[link_name = "sys_readv"]
pub fn readv(fd: i32, iov: *const iovec, iovcnt: usize) -> isize;
#[link_name = "sys_writev"]
pub fn writev(fd: i32, iov: *const iovec, iovcnt: usize) -> isize;
#[link_name = "sys_close"]
pub fn close(fd: i32) -> i32;
#[link_name = "sys_dup"]
pub fn dup(fd: i32) -> i32;
#[link_name = "sys_fcntl"]
pub fn fcntl(fd: i32, cmd: i32, arg: i32) -> i32;
#[link_name = "sys_getdents64"]
pub fn getdents64(fd: i32, dirp: *mut dirent64, count: usize) -> isize;
#[link_name = "sys_getaddrinfo"]
pub fn getaddrinfo(
nodename: *const c_char,
servname: *const c_char,
hints: *const addrinfo,
res: *mut *mut addrinfo,
) -> i32;
#[link_name = "sys_freeaddrinfo"]
pub fn freeaddrinfo(ai: *mut addrinfo);
#[link_name = "sys_socket"]
pub fn socket(domain: i32, ty: i32, protocol: i32) -> i32;
#[link_name = "sys_bind"]
pub fn bind(sockfd: i32, addr: *const sockaddr, addrlen: socklen_t) -> i32;
#[link_name = "sys_listen"]
pub fn listen(sockfd: i32, backlog: i32) -> i32;
#[link_name = "sys_accept"]
pub fn accept(sockfd: i32, addr: *mut sockaddr, addrlen: *mut socklen_t) -> i32;
#[link_name = "sys_connect"]
pub fn connect(sockfd: i32, addr: *const sockaddr, addrlen: socklen_t) -> i32;
#[link_name = "sys_recv"]
pub fn recv(sockfd: i32, buf: *mut u8, len: usize, flags: i32) -> isize;
#[link_name = "sys_recvfrom"]
pub fn recvfrom(
sockfd: i32,
buf: *mut c_void,
len: usize,
flags: i32,
addr: *mut sockaddr,
addrlen: *mut socklen_t,
) -> isize;
#[link_name = "sys_send"]
pub fn send(sockfd: i32, buf: *const c_void, len: usize, flags: i32) -> isize;
#[link_name = "sys_sendto"]
pub fn sendto(
sockfd: i32,
buf: *const c_void,
len: usize,
flags: i32,
to: *const sockaddr,
tolen: socklen_t,
) -> isize;
#[link_name = "sys_getpeername"]
pub fn getpeername(sockfd: i32, addr: *mut sockaddr, addrlen: *mut socklen_t) -> i32;
#[link_name = "sys_getsockname"]
pub fn getsockname(sockfd: i32, addr: *mut sockaddr, addrlen: *mut socklen_t) -> i32;
#[link_name = "sys_getsockopt"]
pub fn getsockopt(
sockfd: i32,
level: i32,
optname: i32,
optval: *mut c_void,
optlen: *mut socklen_t,
) -> i32;
#[link_name = "sys_setsockopt"]
pub fn setsockopt(
sockfd: i32,
level: i32,
optname: i32,
optval: *const c_void,
optlen: socklen_t,
) -> i32;
#[link_name = "sys_ioctl"]
pub fn ioctl(sockfd: i32, cmd: i32, argp: *mut c_void) -> i32;
#[link_name = "sys_shutdown"]
pub fn shutdown(sockfd: i32, how: i32) -> i32;
#[link_name = "sys_eventfd"]
pub fn eventfd(initval: u64, flags: i16) -> i32;
#[link_name = "sys_poll"]
pub fn poll(fds: *mut pollfd, nfds: nfds_t, timeout: i32) -> i32;
}
+309
View File
@@ -0,0 +1,309 @@
//! Raw FFI bindings to platform system libraries.
//!
//! # Usage Guidelines
//!
//! `libc` exposes non-Rust interfaces in Rust, which makes for some caveats to its use that are
//! not present in most Rust libraries. Observing the following guidelines are recommended to help
//! avoid soundness and stability pitfalls.
//!
//! 1. *Never* construct a `libc` struct with `MaybeUninit::uninit()`, initialize it, then call
//! `assume_init`. Many structures have padding fields or may gain fields in the future, and
//! it is far too easy to end up calling `assume_init` on partially initialized data.
//!
//! Instead, use `MaybeUninit::zeroed()` or the `Default` implementations that are slowly being
//! added. Alternatively, access fields only via raw pointer without ever using `assume_init`.
//!
//! 2. Avoid relying on the exact value of constants, the exact length of arrays, or the exact
//! types of type aliases, as they may change across `libc` versions. That is, if `libc`
//! contains code like:
//!
//! <!-- relevant for how rustdoc displays these structs:
//! https://github.com/rust-lang/rust/issues/102456 -->
//! ```ignore
//! const IFNAMSIZ: usize = 16;
//!
//! pub struct ifreq {
//! pub ifr_name: [c_char; IFNAMSIZ],
//! // ...
//! }
//!
//! extern "C" {
//! pub fn time(time: *mut time_t) -> time_t;
//! }
//! ```
//!
//! Then avoid writing code like:
//!
//! ```ignore
//! // Bad assumption that the length will always be 16.
//! fn takes_ifr_name(ifr_name: [c_char; 16]) { /* ... */ }
//!
//! fn process_ifr(ifr: ifreq) {
//! takes_ifr_name(ifr.ifr_name);
//! }
//!
//! // Bad assumption that `time_t` will always be an `i64`. Use `-> time_t` instead, or
//! // explicitly cast to an `i64`.`
//! fn get_time() -> i64 {
//! unsafe { time(ptr::null_mut()) }
//! }
//!
//! ```
//!
//! For `takes_ifr_name`, use `[c_char; IFNAMSIZ]` or just `&[c_char]` instead. For `get_time`,
//! return a `time_t` or explicitly cast to an `i64`.
//!
//! Along the same lines, if you write code along the lines of `assert_eq!(libc::ELAST, 97)`,
//! expect that there may be a release where this starts to fail.
//!
//! 3. Do not name `__c_anonymous_*` types anywhere, which exist to represent anonymous fields in
//! C. For example, FreeBSD defines:
//!
//! ```c
//! struct filestat {
//! int fs_type;
//! // ...
//! struct { struct filestat stqe_next; } next;
//! };
//! ```
//!
//! Which is represented in `libc` as:
//!
//! ```ignore
//! struct filestat {
//! fs_type: c_int,
//! // ...
//! next: __c_anonymous_filestat,
//! }
//!
//! struct __c_anonymous_filestat { stqe_next: *mut filestat }
//! ```
//!
//! Accessing `some_filestat.next.stqe_next` is completely fine, but `__c_anonymous_filestat`
//! should not be used anywhere (e.g. in a function signature). This is done to permit `libc` to
//! switch to anonymous fields if the feature is ever added to Rust.
//!
//! 4. Avoid accessing fields with names such as `__reserved`, `_pad`, or `_spare`. Usually the
//! platform libraries use these to allow adding new fields without changing the size of a
//! struct, but this means their types change frequently.
//!
//! 5. Be aware of deprecation warnings. These are used as a way to migrate necessary API changes.
//!
//! # Cargo Features
//!
//! - `std`: by default `libc` assumes that the standard library contains link directives necessary
//! to use the APIs in this crate. If `std` is disabled, `libc` will emit the directives instead.
//!
//! This feature is slated for removal in `libc` 1.0. The intention is that no-std users of
//! `libc` should use their own `#[link]` attributes, `rustc-link-lib` build script directives,
//! or `-l` arguments for only the system libraries they need to link, rather than `libc`
//! possibly linking more than is needed or available. If you are using `libc` without the `std`
//! feature, consider starting to add link directives now for a smoother 1.0 transition.
//!
//! - `extra_traits`: all types in `libc` implement `Clone`, `Copy`, and `Debug`. The
//! `extra_traits` feature adds `Eq`, `Hash`, and `PartialEq`.
//!
//! This feature is expected to be removed in libc 1.0. Libraries should instead hash or check
//! equality of only needed fields.
//!
//! - The features `const-extern-fn`, `align`, and `use_std` are all deprecated and do nothing.
//!
//! # Stability Expectations
//!
//! Due to `libc`'s position in the ecosystem, it can effectively never publish semver-breaking
//! releases. However, the API that `libc` binds changes _all the time_; sometimes in ways that
//! are harmless, sometimes in ways that are technically API-breaking for all users but unlikely
//! to be noticed (e.g. removing deprecated API), and sometimes in ways that are nonbreaking in
//! C but translate to breaking changes in Rust (e.g. changing the type of an integer). `libc`
//! tries to strike a balance but all of this means that unfortunately, `libc` must occasionally
//! ship changes within a semver-compatible release that are technically semver-breaking.
//!
//! The following are examples of changes that fall into this category:
//!
//! - Fields are added to a struct that is otherwise exhaustive.
//! - Fields with names such as `padding` or `reserved` change type or are removed.
//! - The length of an array type changes.
//! - A struct field (with available padding) is changed from `int` to `long`.
//!
//! In general, `libc` aims to follow platform API changes, even when this means changes that are
//! user-visible in Rust. There are a few guidelines used here:
//!
//! - Adding struct fields is not considered breaking, nor is changing fields named `reserved`,
//! `padding`, or similar. This is because users are expected to use field-by-field
//! initialization.
//! - Changing type aliases, values of constants, or array lengths is not considered breaking.
//! - If the platform libc has accepted breakage on the C side (typically in the form of removing
//! old API), the `libc` crate will follow suit.
//! - Where possible, `#[deprecated(...)]` will be used to warn about changes before applying them.
//! Alternative mitigations may be considered.
//! - Potentially breaking changes will be well-identified in release notes.
//! - Beyond this, public API is not expected to change on Tier 1 targets. Tier 2 targets have
//! relaxed API stability requirements, and API stability is not enforced on tier 3 targets.
//!
//! While this section seems scary, keep in mind that it is meant to cover worst-case scenarios. In
//! practice, breakage is rare and following the above-discussed [Usage Guidelines](#usage-guidelines)
//! means that most `libc` users will never encounter a problem.
// Make it a bit easier to build without Cargo
#![crate_name = "libc"]
#![crate_type = "rlib"]
// Pretty much all C API doesn't match Rust conventions.
#![allow(nonstandard_style)]
// Not all macros and all patterns are used on all targets.
#![allow(unused_macros)]
#![allow(unused_macro_rules)]
// All traits should be `Copy` and `Debug`.
#![warn(missing_copy_implementations)]
#![warn(missing_debug_implementations)]
// Downgrade deny to a warning.
#![warn(overflowing_literals)]
// Prepare for a future upgrade.
#![warn(rust_2024_compatibility)]
// Things missing for 2024 that are blocked on MSRV or breakage.
#![allow(missing_unsafe_on_extern)]
#![allow(edition_2024_expr_fragment_specifier)]
// Allowed globally, the warning is enabled in individual modules as we work through them
#![allow(unsafe_op_in_unsafe_fn)]
#![cfg_attr(libc_deny_warnings, deny(warnings))]
// Attributes needed when building as part of the standard library
#![cfg_attr(feature = "rustc-dep-of-std", feature(link_cfg, no_core))]
#![cfg_attr(feature = "rustc-dep-of-std", allow(internal_features))]
// Some targets don't need `link_cfg` and emit a warning.
#![cfg_attr(feature = "rustc-dep-of-std", allow(unused_features))]
// DIFF(1.0): The thread local references that raise this lint were removed in 1.0
#![cfg_attr(feature = "rustc-dep-of-std", allow(static_mut_refs))]
#![cfg_attr(not(feature = "rustc-dep-of-std"), no_std)]
#![cfg_attr(feature = "rustc-dep-of-std", no_core)]
#[macro_use]
mod macros;
mod new;
cfg_if! {
if #[cfg(feature = "rustc-dep-of-std")] {
extern crate rustc_std_workspace_core as core;
}
}
pub use core::ffi::c_void;
#[allow(unused_imports)] // needed while the module is empty on some platforms
pub use new::*;
cfg_if! {
if #[cfg(windows)] {
mod primitives;
pub use crate::primitives::*;
mod windows;
pub use crate::windows::*;
prelude!();
} else if #[cfg(target_os = "fuchsia")] {
mod primitives;
pub use crate::primitives::*;
mod fuchsia;
pub use crate::fuchsia::*;
prelude!();
} else if #[cfg(target_os = "switch")] {
mod primitives;
pub use primitives::*;
mod switch;
pub use switch::*;
prelude!();
} else if #[cfg(target_os = "psp")] {
mod primitives;
pub use primitives::*;
mod psp;
pub use crate::psp::*;
prelude!();
} else if #[cfg(target_os = "vxworks")] {
mod primitives;
pub use crate::primitives::*;
mod vxworks;
pub use crate::vxworks::*;
prelude!();
} else if #[cfg(target_os = "qurt")] {
mod primitives;
pub use crate::primitives::*;
mod qurt;
pub use crate::qurt::*;
prelude!();
} else if #[cfg(target_os = "solid_asp3")] {
mod primitives;
pub use crate::primitives::*;
mod solid;
pub use crate::solid::*;
prelude!();
} else if #[cfg(unix)] {
mod primitives;
pub use crate::primitives::*;
mod unix;
pub use crate::unix::*;
prelude!();
} else if #[cfg(target_os = "hermit")] {
mod primitives;
pub use crate::primitives::*;
mod hermit;
pub use crate::hermit::*;
prelude!();
} else if #[cfg(target_os = "teeos")] {
mod primitives;
pub use primitives::*;
mod teeos;
pub use teeos::*;
prelude!();
} else if #[cfg(target_os = "trusty")] {
mod primitives;
pub use crate::primitives::*;
mod trusty;
pub use crate::trusty::*;
prelude!();
} else if #[cfg(all(target_env = "sgx", target_vendor = "fortanix"))] {
mod primitives;
pub use crate::primitives::*;
mod sgx;
pub use crate::sgx::*;
prelude!();
} else if #[cfg(any(target_env = "wasi", target_os = "wasi"))] {
mod primitives;
pub use crate::primitives::*;
mod wasi;
pub use crate::wasi::*;
prelude!();
} else if #[cfg(target_os = "xous")] {
mod primitives;
pub use crate::primitives::*;
mod xous;
pub use crate::xous::*;
prelude!();
} else {
// non-supported targets: empty...
}
}
+700
View File
@@ -0,0 +1,700 @@
/// A macro for defining #[cfg] if-else statements.
///
/// This is similar to the `if/elif` C preprocessor macro by allowing definition
/// of a cascade of `#[cfg]` cases, emitting the implementation which matches
/// first.
///
/// This allows you to conveniently provide a long list #[cfg]'d blocks of code
/// without having to rewrite each clause multiple times.
macro_rules! cfg_if {
// match if/else chains with a final `else`
($(
if #[cfg($($meta:meta),*)] { $($it:item)* }
) else * else {
$($it2:item)*
}) => {
cfg_if! {
@__items
() ;
$( ( ($($meta),*) ($($it)*) ), )*
( () ($($it2)*) ),
}
};
// match if/else chains lacking a final `else`
(
if #[cfg($($i_met:meta),*)] { $($i_it:item)* }
$(
else if #[cfg($($e_met:meta),*)] { $($e_it:item)* }
)*
) => {
cfg_if! {
@__items
() ;
( ($($i_met),*) ($($i_it)*) ),
$( ( ($($e_met),*) ($($e_it)*) ), )*
( () () ),
}
};
// Internal and recursive macro to emit all the items
//
// Collects all the negated `cfg`s in a list at the beginning and after the
// semicolon is all the remaining items
(@__items ($($not:meta,)*) ; ) => {};
(@__items ($($not:meta,)*) ; ( ($($m:meta),*) ($($it:item)*) ),
$($rest:tt)*) => {
// Emit all items within one block, applying an appropriate #[cfg]. The
// #[cfg] will require all `$m` matchers specified and must also negate
// all previous matchers.
cfg_if! { @__apply cfg(all($($m,)* not(any($($not),*)))), $($it)* }
// Recurse to emit all other items in `$rest`, and when we do so add all
// our `$m` matchers to the list of `$not` matchers as future emissions
// will have to negate everything we just matched as well.
cfg_if! { @__items ($($not,)* $($m,)*) ; $($rest)* }
};
// Internal macro to Apply a cfg attribute to a list of items
(@__apply $m:meta, $($it:item)*) => {
$(#[$m] $it)*
};
}
/// Create an internal crate prelude with `core` reexports and common types.
macro_rules! prelude {
() => {
mod types;
/// Frequently-used types that are available on all platforms
///
/// We need to reexport the core types so this works with `rust-dep-of-std`.
mod prelude {
// Exports from `core`
#[allow(unused_imports)]
pub(crate) use core::clone::Clone;
#[allow(unused_imports)]
pub(crate) use core::default::Default;
#[allow(unused_imports)]
pub(crate) use core::marker::{
Copy,
Send,
Sync,
};
#[allow(unused_imports)]
pub(crate) use core::option::Option;
#[allow(unused_imports)]
pub(crate) use core::prelude::v1::derive;
#[allow(unused_imports)]
pub(crate) use core::{
assert,
cfg,
debug_assert,
fmt,
hash,
iter,
mem,
ptr,
};
#[allow(unused_imports)]
pub(crate) use fmt::Debug;
#[allow(unused_imports)]
pub(crate) use mem::{
align_of,
align_of_val,
size_of,
size_of_val,
};
#[allow(unused_imports)]
#[cfg(any(target_os = "linux", target_os = "android", target_os = "l4re"))]
pub(crate) use crate::types::u32_cast_ioctl;
#[allow(unused_imports)]
pub(crate) use crate::types::{
replace_array_items,
u16_cast_short,
u32_cast_int,
u32_cast_long,
u8_slice_cast_char_slice,
ulong_cast_int,
ulong_cast_uint,
CEnumRepr,
Padding,
};
// Commonly used types defined in this crate
#[allow(unused_imports)]
pub(crate) use crate::{
c_char,
c_double,
c_float,
c_int,
c_long,
c_longlong,
c_short,
c_uchar,
c_uint,
c_ulong,
c_ulonglong,
c_ushort,
c_void,
intptr_t,
size_t,
ssize_t,
uintptr_t,
};
}
};
}
/// Implement `Clone`, `Copy`, and `Debug` for one or more structs, as well as `PartialEq`, `Eq`,
/// and `Hash` if the `extra_traits` feature is enabled.
///
/// Also mark the type with `repr(C)`.
///
/// Use [`s_no_extra_traits`] for structs where the `extra_traits` feature does not
/// make sense, and for unions.
macro_rules! s {
($(
$(#[$attr:meta])*
$pub:vis $t:ident $i:ident { $($field:tt)* }
)*) => ($(
s!(it: $(#[$attr])* $pub $t $i { $($field)* });
)*);
(it: $(#[$attr:meta])* $pub:vis union $i:ident { $($field:tt)* }) => (
compile_error!("unions cannot derive extra traits, use s_no_extra_traits instead");
);
(it: $(#[$attr:meta])* $pub:vis struct $i:ident { $($field:tt)* }) => (
#[repr(C)]
#[::core::prelude::v1::derive(
::core::clone::Clone,
::core::marker::Copy,
::core::fmt::Debug,
)]
#[cfg_attr(
feature = "extra_traits",
::core::prelude::v1::derive(PartialEq, Eq, Hash)
)]
#[allow(deprecated)]
$(#[$attr])*
$pub struct $i { $($field)* }
);
}
/// Implement `Clone`, `Copy`, and `Debug` for a tuple struct, as well as `PartialEq`, `Eq`,
/// and `Hash` if the `extra_traits` feature is enabled.
///
/// Unlike `s!`, this does *not* mark the type with `repr(C)`. Users should provide their own
/// `repr` attribute via `$attr` as necessary.
macro_rules! s_paren {
($(
$(#[$attr:meta])*
$pub:vis struct $i:ident ( $($field:tt)* );
)*) => ($(
#[::core::prelude::v1::derive(
::core::clone::Clone,
::core::marker::Copy,
::core::fmt::Debug,
)]
#[cfg_attr(
feature = "extra_traits",
::core::prelude::v1::derive(PartialEq, Eq, Hash)
)]
$(#[$attr])*
$pub struct $i ( $($field)* );
)*);
}
/// Implement `Clone`, `Copy`, and `Debug` for one or more structs/unions, but exclude `PartialEq`,
/// `Eq`, and `Hash`.
///
/// Also mark the type with `repr(C)`.
///
/// Most structs will prefer to use [`s`].
macro_rules! s_no_extra_traits {
($(
$(#[$attr:meta])*
$pub:vis $t:ident $i:ident { $($field:tt)* }
)*) => ($(
s_no_extra_traits!(it: $(#[$attr])* $pub $t $i { $($field)* });
)*);
(it: $(#[$attr:meta])* $pub:vis union $i:ident { $($field:tt)* }) => (
#[repr(C)]
#[::core::prelude::v1::derive(
::core::clone::Clone,
::core::marker::Copy,
)]
$(#[$attr])*
$pub union $i { $($field)* }
impl ::core::fmt::Debug for $i {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_struct(::core::stringify!($i)).finish_non_exhaustive()
}
}
);
(it: $(#[$attr:meta])* $pub:vis struct $i:ident { $($field:tt)* }) => (
#[repr(C)]
#[::core::prelude::v1::derive(
::core::clone::Clone,
::core::marker::Copy,
::core::fmt::Debug,
)]
$(#[$attr])*
$pub struct $i { $($field)* }
);
}
/// Create an uninhabited type that can't be constructed. It implements `Debug`, `Clone`,
/// and `Copy`, but these aren't meaningful for extern types so they should eventually
/// be removed.
///
/// Really what we want here is something that also can't be named without indirection (in
/// ADTs or function signatures), but this doesn't exist.
macro_rules! extern_ty {
($(
$(#[$attr:meta])*
$vis:vis type $i:ident;
)*) => ($(
$(#[$attr])*
/// This is an extern type ("opaque" or "incomplete" type in C).
///
/// <div class="warning">
/// This type's current representation allows inspecting some properties, such as via
/// <code>size_of</code>, and it is technically possible to construct the type within
/// <code>MaybeUninit</code>, However, this <strong>MUST NOT</strong> be relied upon
/// because a future version of <code>libc</code> may switch to a proper
/// <a href="https://rust-lang.github.io/rfcs/1861-extern-types.html">extern type</a>
/// representation when available.
/// </div>
// ^ unfortunately warning blocks currently don't render markdown so we need to
// use raw HTML.
//
// Representation based on the Nomicon:
// <https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs>.
//
// FIXME(1.0): These traits are unreachable and should be removed.
#[::core::prelude::v1::derive(
::core::clone::Clone,
::core::marker::Copy,
::core::fmt::Debug,
)]
#[repr(C)]
$vis struct $i {
_data: (),
_marker: ::core::marker::PhantomData<(*mut u8, ::core::marker::PhantomPinned)>,
}
)*);
}
/// Implement `Clone` and `Copy` for an enum, as well as `Debug`, `Eq`, `Hash`, and
/// `PartialEq` if the `extra_traits` feature is enabled.
// FIXME(#4419): Replace all uses of `e!` with `c_enum!`
macro_rules! e {
($(
$(#[$attr:meta])*
pub enum $i:ident { $($field:tt)* }
)*) => ($(
#[cfg_attr(
feature = "extra_traits",
::core::prelude::v1::derive(Eq, Hash, PartialEq)
)]
#[::core::prelude::v1::derive(
::core::clone::Clone,
::core::marker::Copy,
::core::fmt::Debug,
)]
$(#[$attr])*
pub enum $i { $($field)* }
)*);
}
/// Represent a C enum as Rust constants and a type.
///
/// C enums can't soundly be mapped to Rust enums since C enums are allowed to have duplicates or
/// unlisted values, but this is UB in Rust. This enum doesn't implement any traits, its main
/// purpose is to calculate the correct enum values.
///
/// Use the magic name `#anon` if the C enum doesn't create a type.
///
/// See <https://github.com/rust-lang/libc/issues/4419> for more.
macro_rules! c_enum {
// Matcher for multiple enums
($(
$(#[repr($repr:ty)])?
$vis:vis enum $($ty_name:ident)? $(#$anon:ident)? {
$($field_vis:vis $variant:ident $(= $value:expr)?,)+
}
)+) => {
$(c_enum!(@single;
$(#[repr($repr)])?
$vis enum $($ty_name)? $(#$anon)? {
$($field_vis $variant $(= $value)?,)+
}
);)+
};
// Matcher for a single enum
(@single;
$(#[repr($repr:ty)])?
$vis:vis enum $ty_name:ident {
$($field_vis:vis $variant:ident $(= $value:expr)?,)+
}
) => {
$vis type $ty_name = c_enum!(@ty $($repr)?);
c_enum! {
@variant;
ty: $ty_name;
default: 0;
variants: [$($field_vis $variant $(= $value)?,)+]
}
};
// Matcher for a single anonymous enum
(@single;
$(#[repr($repr:ty)])?
$vis:vis enum #anon {
$($field_vis:vis $variant:ident $(= $value:expr)?,)+
}
) => {
c_enum! {
@variant;
ty: c_enum!(@ty $($repr)?);
default: 0;
variants: [$($field_vis $variant $(= $value)?,)+]
}
};
// Matcher for variants: eats a single variant then recurses with the rest
(@variant; ty: $_ty_name:ty; default: $_idx:expr; variants: []) => { /* end of the chain */ };
(
@variant;
ty: $ty_name:ty;
default: $default_val:expr;
variants: [
$field_vis:vis $variant:ident $(= $value:expr)?,
$($tail:tt)*
]
) => {
$field_vis const $variant: $ty_name = {
#[allow(unused_variables)]
let r = $default_val;
$(let r = $value;)?
r
};
// The next value is always one more than the previous value, unless
// set explicitly.
c_enum! {
@variant;
ty: $ty_name;
default: $variant + 1;
variants: [$($tail)*]
}
};
// Use a specific type if provided, otherwise default to `CEnumRepr`
(@ty $repr:ty) => { $repr };
(@ty) => { $crate::prelude::CEnumRepr };
}
/// Define a `unsafe` function.
macro_rules! f {
($(
$(#[$attr:meta])*
pub $(const $($const_dummy:literal)?)? unsafe
fn $i:ident ($($arg:ident: $argty:ty),* $(,)?) -> $ret:ty
$body:block
)+) => {$(
#[inline]
$(#[$attr])*
pub $(const $($const_dummy)?)? unsafe extern "C"
fn $i ($($arg: $argty),*) -> $ret
$body
)+};
}
/// Define a safe function.
macro_rules! safe_f {
($(
$(#[$attr:meta])*
pub $(const $($const_dummy:literal)?)? safe
fn $i:ident ($($arg:ident: $argty:ty),* $(,)?) -> $ret:ty
$body:block
)+) => {$(
#[inline]
$(#[$attr])*
pub $(const $($const_dummy)?)? extern "C"
fn $i ($($arg: $argty),*) -> $ret
$body
)+};
}
// This macro is used to deprecate items that should be accessed via the mach2 crate
macro_rules! deprecated_mach {
(pub const $id:ident: $ty:ty = $expr:expr;) => {
#[deprecated(
since = "0.2.55",
note = "Use the `mach2` crate instead",
)]
#[allow(deprecated)]
pub const $id: $ty = $expr;
};
($(pub const $id:ident: $ty:ty = $expr:expr;)*) => {
$(
deprecated_mach!(
pub const $id: $ty = $expr;
);
)*
};
(pub type $id:ident = $ty:ty;) => {
#[deprecated(
since = "0.2.55",
note = "Use the `mach2` crate instead",
)]
#[allow(deprecated)]
pub type $id = $ty;
};
($(pub type $id:ident = $ty:ty;)*) => {
$(
deprecated_mach!(
pub type $id = $ty;
);
)*
}
}
/// Polyfill for std's `offset_of`.
// FIXME(msrv): stabilized in std in 1.77
macro_rules! offset_of {
($Ty:path, $field:ident) => {{
// Taken from bytemuck, avoids accidentally calling on deref
#[allow(clippy::unneeded_wildcard_pattern)]
let $Ty { $field: _, .. };
let data = core::mem::MaybeUninit::<$Ty>::uninit();
let ptr = data.as_ptr();
// nested unsafe, see f!
#[allow(unused_unsafe)]
// SAFETY: computed address is inbounds since we have a stack alloc for T
let fptr = unsafe { core::ptr::addr_of!((*ptr).$field) };
let off = (fptr as usize).checked_sub(ptr as usize).unwrap();
core::assert!(off <= core::mem::size_of::<$Ty>());
off
}};
}
#[cfg(test)]
mod tests {
use core::any::TypeId;
use crate::types::CEnumRepr;
#[test]
fn c_enum_basic() {
// By default, variants get sequential values.
c_enum! {
pub enum e {
VAR0,
VAR1,
VAR2,
}
// Also check enums that don't create a type.
pub enum #anon {
ANON0,
ANON1,
ANON2,
}
// No visibility required.
enum #anon {
ANON3,
ANON4,
ANON5,
}
}
assert_eq!(TypeId::of::<e>(), TypeId::of::<CEnumRepr>());
assert_eq!(VAR0, 0 as CEnumRepr);
assert_eq!(VAR1, 1 as CEnumRepr);
assert_eq!(VAR2, 2 as CEnumRepr);
assert_eq!(type_id_of_val(&ANON0), TypeId::of::<CEnumRepr>());
assert_eq!(ANON0, 0 as CEnumRepr);
assert_eq!(ANON1, 1 as CEnumRepr);
assert_eq!(ANON2, 2 as CEnumRepr);
assert_eq!(type_id_of_val(&ANON3), TypeId::of::<CEnumRepr>());
assert_eq!(ANON3, 0 as CEnumRepr);
assert_eq!(ANON4, 1 as CEnumRepr);
assert_eq!(ANON5, 2 as CEnumRepr);
}
#[test]
fn c_enum_repr() {
// Check specifying the integer representation
c_enum! {
#[repr(u16)]
pub enum e {
VAR0,
}
#[repr(u16)]
pub enum #anon {
ANON0,
}
}
assert_eq!(TypeId::of::<e>(), TypeId::of::<u16>());
assert_eq!(VAR0, 0_u16);
assert_eq!(type_id_of_val(&ANON0), TypeId::of::<u16>());
assert_eq!(ANON0, 0_u16);
}
#[test]
fn c_enum_set_value() {
// Setting an explicit value resets the count.
c_enum! {
pub enum e {
VAR2 = 2,
VAR3,
VAR4,
}
}
assert_eq!(VAR2, 2 as CEnumRepr);
assert_eq!(VAR3, 3 as CEnumRepr);
assert_eq!(VAR4, 4 as CEnumRepr);
}
#[test]
fn c_enum_multiple_set_value() {
// C enums always take one more than the previous value, unless set to a specific
// value. Duplicates are allowed.
c_enum! {
pub enum e {
VAR0,
VAR2_0 = 2,
VAR3_0,
VAR4_0,
VAR2_1 = 2,
VAR3_1,
VAR4_1,
}
}
assert_eq!(VAR0, 0 as CEnumRepr);
assert_eq!(VAR2_0, 2 as CEnumRepr);
assert_eq!(VAR3_0, 3 as CEnumRepr);
assert_eq!(VAR4_0, 4 as CEnumRepr);
assert_eq!(VAR2_1, 2 as CEnumRepr);
assert_eq!(VAR3_1, 3 as CEnumRepr);
assert_eq!(VAR4_1, 4 as CEnumRepr);
}
#[test]
fn c_enum_vis() {
mod priv1 {
c_enum! {
#[repr(u8)]
pub enum e1 {
PRIV_ON_1 = 10,
// Variant should still be usable within its visibility
pub PUB1 = PRIV_ON_1 * 2,
}
}
}
mod priv2 {
c_enum! {
#[repr(u16)]
pub enum e2 {
pub PRIV_ON_1 = 42,
pub PUB2 = PRIV_ON_1 * 2,
}
}
}
use priv1::*;
use priv2::*;
assert_eq!(TypeId::of::<e1>(), TypeId::of::<u8>());
assert_eq!(TypeId::of::<e2>(), TypeId::of::<u16>());
assert_eq!(PUB1, 10u8 * 2);
assert_eq!(PUB2, 42u16 * 2);
// Verify that the default is private. If `PRIV_ON_1` was actually public in `priv1`, this
// would be an ambiguous import and/or type mismatch error.
assert_eq!(PRIV_ON_1, 42u16);
}
fn type_id_of_val<T: 'static>(_: &T) -> TypeId {
TypeId::of::<T>()
}
#[test]
fn test_offset_of() {
#[repr(C)]
struct Off1 {
a: u8,
b: u32,
c: Off2,
d: u64,
}
#[repr(C)]
#[repr(align(128))]
struct Off2 {}
assert_eq!(core::mem::offset_of!(Off1, a), offset_of!(Off1, a));
assert_eq!(core::mem::offset_of!(Off1, b), offset_of!(Off1, b));
assert_eq!(core::mem::offset_of!(Off1, c), offset_of!(Off1, c));
assert_eq!(core::mem::offset_of!(Off1, d), offset_of!(Off1, d));
}
}
#[cfg(test)]
#[allow(unused)]
mod macro_checks {
s! {
pub struct S1 {
pub a: u32,
b: u32,
}
struct S1Priv {
pub a: u32,
b: u32,
}
}
s_no_extra_traits! {
pub struct S2 {
pub a: u32,
b: u32,
}
struct S2Priv {
pub a: u32,
b: u32,
}
pub union U2 {
pub a: u32,
b: f32,
}
union U2Priv {
pub a: u32,
b: f32,
}
}
extern_ty! {
type Foo;
pub type Bar;
}
}
+6
View File
@@ -0,0 +1,6 @@
//! IBM AIX libc.
//!
//! * Headers are not public
//! * Manual pages: <https://www.ibm.com/docs/en/aix> (under "Technical reference" for that version)
pub(crate) mod unistd;
+7
View File
@@ -0,0 +1,7 @@
//! Header: `unistd.h`
pub use crate::new::common::posix::unistd::{
STDERR_FILENO,
STDIN_FILENO,
STDOUT_FILENO,
};
+5
View File
@@ -0,0 +1,5 @@
//! Header: `signal.h`
//!
//! <https://github.com/apple-oss-distributions/Libc/blob/main/include/signal.h>
pub use crate::sys::signal::*;
+7
View File
@@ -0,0 +1,7 @@
//! Header: `unistd.h`
pub use crate::new::common::posix::unistd::{
STDERR_FILENO,
STDIN_FILENO,
STDOUT_FILENO,
};
+20
View File
@@ -0,0 +1,20 @@
//! Source from libpthread <https://github.com/apple-oss-distributions/libpthread/tree/main>
/// Directory: `pthread/`
///
/// Note that this module has a trailing underscore to avoid conflicting with its child `pthread`
/// module.
///
/// <https://github.com/apple-oss-distributions/libpthread/tree/main/include/pthread>
pub(crate) mod pthread_ {
pub(crate) mod introspection;
pub(crate) mod pthread;
pub(crate) mod pthread_impl;
pub(crate) mod pthread_spis;
pub(crate) mod qos;
pub(crate) mod sched;
pub(crate) mod spawn;
pub(crate) mod stack_np;
}
pub(crate) mod sys;
@@ -0,0 +1,36 @@
//! Header: `pthread/introspection.h`
//!
//! <https://github.com/apple-oss-distributions/libpthread/blob/main/include/pthread/introspection.h>
use crate::prelude::*;
pub use crate::pthread_::pthread::*;
c_enum! {
#[repr(c_uint)]
pub enum #anon {
pub PTHREAD_INTROSPECTION_THREAD_CREATE = 1,
pub PTHREAD_INTROSPECTION_THREAD_START,
pub PTHREAD_INTROSPECTION_THREAD_TERMINATE,
pub PTHREAD_INTROSPECTION_THREAD_DESTROY,
}
}
pub type pthread_introspection_hook_t =
extern "C" fn(event: c_uint, thread: pthread_t, addr: *mut c_void, size: size_t);
extern "C" {
// Available from Big Sur
pub fn pthread_introspection_hook_install(
hook: pthread_introspection_hook_t,
) -> pthread_introspection_hook_t;
pub fn pthread_introspection_setspecific_np(
thread: pthread_t,
key: pthread_key_t,
value: *const c_void,
) -> c_int;
pub fn pthread_introspection_getspecific_np(
thread: pthread_t,
key: pthread_key_t,
) -> *mut c_void;
}
@@ -0,0 +1,76 @@
//! Header: `pthread.h` or `pthread/pthread.h`
//!
//! <https://github.com/apple-oss-distributions/libpthread/blob/main/include/pthread/pthread.h>
use crate::prelude::*;
pub use crate::pthread_::qos::*;
pub use crate::pthread_::sched::*;
// No need to import from the `_pthread_attr_t` and similar modules since `_pthread_types` has
// everything we need.
pub use crate::sys::_pthread::_pthread_types::*;
pub const PTHREAD_CREATE_JOINABLE: c_int = 1;
pub const PTHREAD_CREATE_DETACHED: c_int = 2;
pub const PTHREAD_INHERIT_SCHED: c_int = 1;
pub const PTHREAD_EXPLICIT_SCHED: c_int = 2;
pub const PTHREAD_CANCEL_ENABLE: c_int = 0x01;
pub const PTHREAD_CANCEL_DISABLE: c_int = 0x00;
pub const PTHREAD_CANCEL_DEFERRED: c_int = 0x02;
pub const PTHREAD_CANCEL_ASYNCHRONOUS: c_int = 0x00;
pub const PTHREAD_CANCELED: *mut c_void = 1 as *mut c_void;
pub const PTHREAD_SCOPE_SYSTEM: c_int = 1;
pub const PTHREAD_SCOPE_PROCESS: c_int = 2;
pub const PTHREAD_PROCESS_SHARED: c_int = 1;
pub const PTHREAD_PROCESS_PRIVATE: c_int = 2;
pub const PTHREAD_PRIO_NONE: c_int = 0;
pub const PTHREAD_PRIO_INHERIT: c_int = 1;
pub const PTHREAD_PRIO_PROTECT: c_int = 2;
pub const PTHREAD_MUTEX_NORMAL: c_int = 0;
pub const PTHREAD_MUTEX_ERRORCHECK: c_int = 1;
pub const PTHREAD_MUTEX_RECURSIVE: c_int = 2;
pub const PTHREAD_MUTEX_DEFAULT: c_int = PTHREAD_MUTEX_NORMAL;
pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
__sig: _PTHREAD_RWLOCK_SIG_init,
__opaque: [0; __PTHREAD_RWLOCK_SIZE__],
};
pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
__sig: _PTHREAD_MUTEX_SIG_init,
__opaque: [0; __PTHREAD_MUTEX_SIZE__],
};
pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
__sig: _PTHREAD_COND_SIG_init,
__opaque: [0; __PTHREAD_COND_SIZE__],
};
pub const PTHREAD_ONCE_INIT: crate::pthread_once_t = crate::pthread_once_t {
__sig: _PTHREAD_ONCE_SIG_INIT,
__opaque: [0; __PTHREAD_ONCE_SIZE__],
};
pub use crate::new::common::posix::pthread::{
pthread_attr_getinheritsched,
pthread_attr_getschedparam,
pthread_attr_getschedpolicy,
pthread_attr_setinheritsched,
pthread_attr_setschedparam,
pthread_attr_setschedpolicy,
pthread_condattr_getpshared,
pthread_condattr_setpshared,
pthread_getschedparam,
pthread_mutexattr_getpshared,
pthread_mutexattr_setpshared,
pthread_once,
pthread_rwlockattr_getpshared,
pthread_rwlockattr_setpshared,
pthread_setschedparam,
};
@@ -0,0 +1,12 @@
use crate::prelude::*;
// FIXME(apple): these should all be `pub(crate)`
pub const _PTHREAD_MUTEX_SIG_init: c_long = 0x32AAABA7;
pub const _PTHREAD_COND_SIG_init: c_long = 0x3CB0B1BB;
pub(crate) const _PTHREAD_ONCE_SIG_INIT: c_long = 0x30B1BCBA;
pub const _PTHREAD_RWLOCK_SIG_init: c_long = 0x2DA8B3B4;
pub const SCHED_OTHER: c_int = 1;
pub const SCHED_FIFO: c_int = 4;
pub const SCHED_RR: c_int = 2;
@@ -0,0 +1,14 @@
//! Header: `pthread/pthread_spis.h`
//!
//! <https://github.com/apple-oss-distributions/libpthread/blob/main/include/pthread/pthread_spis.h>
use crate::prelude::*;
extern "C" {
pub fn pthread_create_from_mach_thread(
thread: *mut crate::pthread_t,
attr: *const crate::pthread_attr_t,
f: extern "C" fn(*mut c_void) -> *mut c_void,
value: *mut c_void,
) -> c_int;
}
+25
View File
@@ -0,0 +1,25 @@
//! Header: `pthread/qos.h`
//!
//! <https://github.com/apple-oss-distributions/libpthread/blob/main/include/pthread/qos.h>
use crate::prelude::*;
pub use crate::sys::qos::*;
extern "C" {
pub fn pthread_attr_set_qos_class_np(
attr: *mut crate::pthread_attr_t,
class: qos_class_t,
priority: c_int,
) -> c_int;
pub fn pthread_attr_get_qos_class_np(
attr: *mut crate::pthread_attr_t,
class: *mut qos_class_t,
priority: *mut c_int,
) -> c_int;
pub fn pthread_set_qos_class_self_np(class: qos_class_t, priority: c_int) -> c_int;
pub fn pthread_get_qos_class_np(
thread: crate::pthread_t,
class: *mut qos_class_t,
priority: *mut c_int,
) -> c_int;
}
@@ -0,0 +1,9 @@
pub use crate::new::pthread_::pthread_impl::*;
use crate::prelude::*;
s! {
pub struct sched_param {
pub sched_priority: c_int,
__opaque: [c_char; 4],
}
}
+16
View File
@@ -0,0 +1,16 @@
//! Header: `pthread/spawn.h`
//!
//! <https://github.com/apple-oss-distributions/libpthread/blob/main/include/pthread/spawn.h>
use crate::prelude::*;
extern "C" {
pub fn posix_spawnattr_set_qos_class_np(
attr: *mut crate::posix_spawnattr_t,
qos_class: crate::qos_class_t,
) -> c_int;
pub fn posix_spawnattr_get_qos_class_np(
attr: *const crate::posix_spawnattr_t,
qos_class: *mut crate::qos_class_t,
) -> c_int;
}
@@ -0,0 +1,12 @@
//! Header: `pthread/stack_np.h`
//!
//! <https://github.com/apple-oss-distributions/libpthread/blob/main/include/pthread/stack_np.h>
use crate::prelude::*;
extern "C" {
pub fn pthread_stack_frame_decode_np(
frame_addr: uintptr_t,
return_addr: *mut uintptr_t,
) -> uintptr_t;
}
@@ -0,0 +1,79 @@
//! Header: `sys/_pthread/_pthread_types.h`
//!
//! <https://github.com/apple-oss-distributions/libpthread/blob/main/include/sys/_pthread/_pthread_types.h>
//!
//! Note that the actual header defines `_opaque_pthread_*` structs which are typedefed to
//! `__darwin_pthread*` structs, and typedefed again in separate `_pthread_*.h` files to their final
//! `pthread_` name. This isn't useful for us so we simplify a bit and just define everything here.
use crate::prelude::*;
cfg_if! {
if #[cfg(target_pointer_width = "64")] {
pub const __PTHREAD_SIZE__: usize = 8176;
pub const __PTHREAD_ATTR_SIZE__: usize = 56;
pub const __PTHREAD_MUTEXATTR_SIZE__: usize = 8;
pub const __PTHREAD_MUTEX_SIZE__: usize = 56;
pub const __PTHREAD_CONDATTR_SIZE__: usize = 8;
pub const __PTHREAD_COND_SIZE__: usize = 40;
pub const __PTHREAD_ONCE_SIZE__: usize = 8;
pub const __PTHREAD_RWLOCK_SIZE__: usize = 192;
pub const __PTHREAD_RWLOCKATTR_SIZE__: usize = 16;
} else {
pub const __PTHREAD_SIZE__: usize = 4088;
pub const __PTHREAD_ATTR_SIZE__: usize = 36;
pub const __PTHREAD_MUTEXATTR_SIZE__: usize = 8;
pub const __PTHREAD_MUTEX_SIZE__: usize = 40;
pub const __PTHREAD_CONDATTR_SIZE__: usize = 4;
pub const __PTHREAD_COND_SIZE__: usize = 24;
pub const __PTHREAD_ONCE_SIZE__: usize = 4;
pub const __PTHREAD_RWLOCK_SIZE__: usize = 124;
pub const __PTHREAD_RWLOCKATTR_SIZE__: usize = 12;
}
}
s! {
pub struct pthread_attr_t {
pub(crate) __sig: c_long,
pub(crate) __opaque: [c_char; __PTHREAD_ATTR_SIZE__],
}
pub struct pthread_cond_t {
pub(crate) __sig: c_long,
pub(crate) __opaque: [u8; __PTHREAD_COND_SIZE__],
}
pub struct pthread_condattr_t {
pub(crate) __sig: c_long,
pub(crate) __opaque: [u8; __PTHREAD_CONDATTR_SIZE__],
}
pub struct pthread_mutex_t {
pub(crate) __sig: c_long,
pub(crate) __opaque: [u8; __PTHREAD_MUTEX_SIZE__],
}
pub struct pthread_mutexattr_t {
pub(crate) __sig: c_long,
pub(crate) __opaque: [u8; __PTHREAD_MUTEXATTR_SIZE__],
}
pub struct pthread_once_t {
pub(crate) __sig: c_long,
pub(crate) __opaque: [c_char; __PTHREAD_ONCE_SIZE__],
}
pub struct pthread_rwlock_t {
pub(crate) __sig: c_long,
pub(crate) __opaque: [u8; __PTHREAD_RWLOCK_SIZE__],
}
pub struct pthread_rwlockattr_t {
pub(crate) __sig: c_long,
pub(crate) __opaque: [u8; __PTHREAD_RWLOCKATTR_SIZE__],
}
}
pub type pthread_key_t = c_ulong;
pub use crate::pthread_t;
+14
View File
@@ -0,0 +1,14 @@
//! Directory: `sys/`
//!
//! <https://github.com/apple-oss-distributions/libpthread/tree/main/include/sys/_pthread>
/// Directory: `sys/_pthread/`
///
/// <https://github.com/apple-oss-distributions/libpthread/tree/main/include/sys>
pub(crate) mod _pthread {
// We don't have the `_pthread_attr_t` and similar modules to match `_pthread_attr_t.h`,
// everything is defined in `_pthread_types`.
pub(crate) mod _pthread_types;
}
pub(crate) mod qos;
+22
View File
@@ -0,0 +1,22 @@
//! Header: `sys/qos.h`
//!
//! <https://github.com/apple-oss-distributions/libpthread/blob/main/include/sys/qos.h>
use crate::prelude::*;
#[derive(Debug)]
#[repr(u32)]
pub enum qos_class_t {
QOS_CLASS_USER_INTERACTIVE = 0x21,
QOS_CLASS_USER_INITIATED = 0x19,
QOS_CLASS_DEFAULT = 0x15,
QOS_CLASS_UTILITY = 0x11,
QOS_CLASS_BACKGROUND = 0x09,
QOS_CLASS_UNSPECIFIED = 0x00,
}
impl Copy for qos_class_t {}
impl Clone for qos_class_t {
fn clone(&self) -> qos_class_t {
*self
}
}
+19
View File
@@ -0,0 +1,19 @@
//! Apple interfaces.
//!
//! The Xcode SDK includes interfaces that are split across a couple of different libraries. Most
//! of these are available at <https://github.com/apple-oss-distributions>.
/// Entrypoint for Apple headers, usually found as part of the Xcode SDK.
///
/// <https://github.com/apple-oss-distributions/Libc/tree/main/include>
mod libc {
pub(crate) mod signal;
pub(crate) mod unistd;
}
mod libpthread;
mod xnu;
pub(crate) use libc::*;
pub(crate) use libpthread::pthread_;
pub(crate) use xnu::*;
+15
View File
@@ -0,0 +1,15 @@
//! Header: `arm/_mcontext.h`
//!
//! <https://github.com/apple-oss-distributions/xnu/blob/main/bsd/arm/_mcontext.h>
pub use crate::mach::machine::_structs::*;
s! {
pub struct __darwin_mcontext64 {
pub __es: __darwin_arm_exception_state64,
pub __ss: __darwin_arm_thread_state64,
pub __ns: __darwin_arm_neon_state64,
}
}
pub type mcontext_t = *mut __darwin_mcontext64;
+15
View File
@@ -0,0 +1,15 @@
//! Header: `i386/_mcontext.h`
//!
//! <https://github.com/apple-oss-distributions/xnu/blob/main/bsd/i386/_mcontext.h>
pub use crate::mach::machine::_structs::*;
s! {
pub struct __darwin_mcontext64 {
pub __es: __darwin_x86_exception_state64,
pub __ss: __darwin_x86_thread_state64,
pub __fs: __darwin_x86_float_state64,
}
}
pub type mcontext_t = *mut __darwin_mcontext64;
+37
View File
@@ -0,0 +1,37 @@
//! Header: `arm/_structs.h`
//!
//! <https://github.com/apple-oss-distributions/xnu/blob/main/osfmk/mach/arm/_structs.h>
#[cfg(target_arch = "arm")]
use crate::prelude::*;
s! {
pub struct __darwin_arm_exception_state64 {
pub __far: u64,
pub __esr: u32,
pub __exception: u32,
}
pub struct __darwin_arm_thread_state64 {
pub __x: [u64; 29],
pub __fp: u64,
pub __lr: u64,
pub __sp: u64,
pub __pc: u64,
pub __cpsr: u32,
pub __pad: u32,
}
#[cfg(target_arch = "aarch64")]
pub struct __darwin_arm_neon_state64 {
pub __v: [u128; 32],
pub __fpsr: u32,
pub __fpcr: u32,
}
#[cfg(target_arch = "arm")]
#[repr(align(16))]
pub struct __darwin_arm_neon_state64 {
opaque: [c_char; (32 * 16) + (2 * size_of::<u32>())],
}
}
+92
View File
@@ -0,0 +1,92 @@
//! Header: `i386/_structs.h`
//!
//! <https://github.com/apple-oss-distributions/xnu/blob/main/osfmk/mach/i386/_structs.h>
use crate::prelude::*;
s! {
pub struct __darwin_mmst_reg {
pub __mmst_reg: [c_char; 10],
pub __mmst_rsrv: [c_char; 6],
}
pub struct __darwin_xmm_reg {
pub __xmm_reg: [c_char; 16],
}
pub struct __darwin_x86_thread_state64 {
pub __rax: u64,
pub __rbx: u64,
pub __rcx: u64,
pub __rdx: u64,
pub __rdi: u64,
pub __rsi: u64,
pub __rbp: u64,
pub __rsp: u64,
pub __r8: u64,
pub __r9: u64,
pub __r10: u64,
pub __r11: u64,
pub __r12: u64,
pub __r13: u64,
pub __r14: u64,
pub __r15: u64,
pub __rip: u64,
pub __rflags: u64,
pub __cs: u64,
pub __fs: u64,
pub __gs: u64,
}
pub struct __darwin_x86_exception_state64 {
pub __trapno: u16,
pub __cpu: u16,
pub __err: u32,
pub __faultvaddr: u64,
}
pub struct __darwin_x86_float_state64 {
pub __fpu_reserved: [c_int; 2],
__fpu_fcw: c_short,
__fpu_fsw: c_short,
pub __fpu_ftw: u8,
pub __fpu_rsrv1: u8,
pub __fpu_fop: u16,
pub __fpu_ip: u32,
pub __fpu_cs: u16,
pub __fpu_rsrv2: u16,
pub __fpu_dp: u32,
pub __fpu_ds: u16,
pub __fpu_rsrv3: u16,
pub __fpu_mxcsr: u32,
pub __fpu_mxcsrmask: u32,
pub __fpu_stmm0: __darwin_mmst_reg,
pub __fpu_stmm1: __darwin_mmst_reg,
pub __fpu_stmm2: __darwin_mmst_reg,
pub __fpu_stmm3: __darwin_mmst_reg,
pub __fpu_stmm4: __darwin_mmst_reg,
pub __fpu_stmm5: __darwin_mmst_reg,
pub __fpu_stmm6: __darwin_mmst_reg,
pub __fpu_stmm7: __darwin_mmst_reg,
pub __fpu_xmm0: __darwin_xmm_reg,
pub __fpu_xmm1: __darwin_xmm_reg,
pub __fpu_xmm2: __darwin_xmm_reg,
pub __fpu_xmm3: __darwin_xmm_reg,
pub __fpu_xmm4: __darwin_xmm_reg,
pub __fpu_xmm5: __darwin_xmm_reg,
pub __fpu_xmm6: __darwin_xmm_reg,
pub __fpu_xmm7: __darwin_xmm_reg,
pub __fpu_xmm8: __darwin_xmm_reg,
pub __fpu_xmm9: __darwin_xmm_reg,
pub __fpu_xmm10: __darwin_xmm_reg,
pub __fpu_xmm11: __darwin_xmm_reg,
pub __fpu_xmm12: __darwin_xmm_reg,
pub __fpu_xmm13: __darwin_xmm_reg,
pub __fpu_xmm14: __darwin_xmm_reg,
pub __fpu_xmm15: __darwin_xmm_reg,
// FIXME(apple): this field is actually [u8; 96], but defining it with a bigger type allows
// us to auto-implement traits for it since the length of the array is less than 32
__fpu_rsrv4: [u32; 24],
pub __fpu_reserved1: c_int,
}
}
+13
View File
@@ -0,0 +1,13 @@
//! Header: `mach/machine/_structs.h`
//!
//! <https://github.com/apple-oss-distributions/xnu/blob/main/osfmk/mach/machine/_structs.h>
cfg_if! {
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
pub use crate::mach::i386::_structs::*;
} else if #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] {
pub use crate::mach::arm::_structs::*;
} else {
// Unsupported arch
}
}
+20
View File
@@ -0,0 +1,20 @@
//! Directory: `mach/`
//!
//! <https://github.com/apple-oss-distributions/xnu/tree/main/osfmk/mach>
/// Directory: `mach/arm`
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
pub(crate) mod arm {
pub(crate) mod _structs;
}
/// Directory: `mach/i386`
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub(crate) mod i386 {
pub(crate) mod _structs;
}
/// Directory: `mach/machine`
pub(crate) mod machine {
pub(crate) mod _structs;
}
+11
View File
@@ -0,0 +1,11 @@
//! Header: `machine/_mcontext.h`
cfg_if! {
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
pub use crate::i386::_mcontext::*;
} else if #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] {
pub use crate::arm::_mcontext::*;
} else {
// Unsupported arch
}
}
+34
View File
@@ -0,0 +1,34 @@
//! Source from XNU <https://github.com/apple-oss-distributions/xnu/tree/main>
//!
//! We omit nesting for the `bsd` module since most items of interest are in there.
/// Directory: `arm/`
///
/// https://github.com/apple-oss-distributions/xnu/tree/main/bsd/arm
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
pub(crate) mod arm {
pub(crate) mod _mcontext;
}
/// Directory: `i386/`
///
/// https://github.com/apple-oss-distributions/xnu/tree/main/bsd/i386
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub(crate) mod i386 {
pub(crate) mod _mcontext;
}
pub(crate) mod mach;
/// Directory: `machine/`
///
/// https://github.com/apple-oss-distributions/xnu/tree/main/bsd/machine
pub(crate) mod machine {
pub(crate) mod _mcontext;
}
pub(crate) mod net;
pub(crate) mod netinet6;
pub(crate) mod sys;
+57
View File
@@ -0,0 +1,57 @@
//! Header: `net/bpf.h`
//!
//! <https://github.com/apple-oss-distributions/xnu/blob/main/bsd/net/bpf.h>
use crate::prelude::*;
use crate::sys::ioccom::*;
s! {
pub struct bpf_insn {
pub code: c_ushort,
pub jt: c_uchar,
pub jf: c_uchar,
pub k: u32,
}
pub struct bpf_program {
pub bf_len: c_uint,
pub bf_insns: *mut bpf_insn,
}
}
s_no_extra_traits! {
#[repr(packed(4))]
pub struct bpf_dltlist {
pub bfl_len: u32,
pub bfl_u: __c_anonymous_bfl_u,
}
pub union __c_anonymous_bfl_u {
pub bflu_list: *mut u32,
pub bflu_pad: u64,
}
}
pub const DLT_NULL: c_uint = 0; // no link-layer encapsulation
pub const DLT_EN10MB: c_uint = 1; // Ethernet (10Mb)
pub const DLT_EN3MB: c_uint = 2; // Experimental Ethernet (3Mb)
pub const DLT_AX25: c_uint = 3; // Amateur Radio AX.25
pub const DLT_PRONET: c_uint = 4; // Proteon ProNET Token Ring
pub const DLT_CHAOS: c_uint = 5; // Chaos
pub const DLT_IEEE802: c_uint = 6; // IEEE 802 Networks
pub const DLT_ARCNET: c_uint = 7; // ARCNET
pub const DLT_SLIP: c_uint = 8; // Serial Line IP
pub const DLT_PPP: c_uint = 9; // Point-to-point Protocol
pub const DLT_FDDI: c_uint = 10; // FDDI
pub const DLT_ATM_RFC1483: c_uint = 11; // LLC/SNAP encapsulated atm
pub const DLT_RAW: c_uint = 12; // raw IP
pub const DLT_LOOP: c_uint = 108;
pub const BPF_ALIGNMENT: c_int = size_of::<i32>() as c_int;
pub const BIOCGRSIG: c_ulong = _IOR::<c_uint>('B' as c_ulong, 114);
pub const BIOCSRSIG: c_ulong = _IOW::<c_uint>('B' as c_ulong, 115);
pub const BIOCGSEESENT: c_ulong = _IOR::<c_uint>('B' as c_ulong, 118);
pub const BIOCSSEESENT: c_ulong = _IOW::<c_uint>('B' as c_ulong, 119);
pub const BIOCSDLT: c_ulong = _IOW::<c_uint>('B' as c_ulong, 120);
pub const BIOCGDLTLIST: c_ulong = _IOWR::<bpf_dltlist>('B' as c_ulong, 121);
+5
View File
@@ -0,0 +1,5 @@
//! Directory: `net/`
//!
//! <https://github.com/apple-oss-distributions/xnu/tree/main/bsd/net>
pub(crate) mod bpf;
+22
View File
@@ -0,0 +1,22 @@
//! Header: `netinet6/in6_var.h`
//!
//! <https://github.com/apple-oss-distributions/xnu/blob/main/bsd/netinet6/in6_var.h>
use crate::prelude::*;
use crate::sys::ioccom::*;
pub const IN6_IFF_ANYCAST: c_int = 0x0001;
pub const IN6_IFF_TENTATIVE: c_int = 0x0002;
pub const IN6_IFF_DUPLICATED: c_int = 0x0004;
pub const IN6_IFF_DETACHED: c_int = 0x0008;
pub const IN6_IFF_DEPRECATED: c_int = 0x0010;
pub const IN6_IFF_NODAD: c_int = 0x0020;
pub const IN6_IFF_AUTOCONF: c_int = 0x0040;
pub const IN6_IFF_TEMPORARY: c_int = 0x0080;
pub const IN6_IFF_DYNAMIC: c_int = 0x0100;
pub const IN6_IFF_OPTIMISTIC: c_int = 0x0200;
pub const IN6_IFF_SECURED: c_int = 0x0400;
pub const IN6_IFF_CLAT46: c_int = 0x1000;
pub const IN6_IFF_NOPFX: c_int = 0x8000;
pub const SIOCGIFAFLAG_IN6: c_ulong = _IOWR::<crate::in6_ifreq>('i' as c_ulong, 73);
+5
View File
@@ -0,0 +1,5 @@
//! Directory: `netinet6/`
//!
//! <https://github.com/apple-oss-distributions/xnu/tree/main/bsd/netinet6>
pub(crate) mod in6_var;
+17
View File
@@ -0,0 +1,17 @@
//! Header: `sys/_types/_ucontext.h`
pub use crate::machine::_mcontext::*;
use crate::prelude::*;
s! {
pub struct __darwin_ucontext {
pub uc_onstack: c_int,
pub uc_sigmask: crate::sigset_t,
pub uc_stack: crate::stack_t,
pub uc_link: *mut ucontext_t,
pub uc_mcsize: usize,
pub uc_mcontext: mcontext_t,
}
}
pub type ucontext_t = __darwin_ucontext;
+49
View File
@@ -0,0 +1,49 @@
//! Header: `sys/ioccom.h`
//!
//! <https://github.com/apple-oss-distributions/xnu/blob/main/bsd/sys/ioccom.h>
use crate::prelude::*;
const IOCPARM_MASK: c_ulong = 0x1fff;
const IOCPARM_MAX: c_ulong = IOCPARM_MASK + 1;
// These are u32 in source but would probably be more practical as c_ulong if we ever need
// to make them public.
pub(crate) const IOC_VOID: u32 = 0x20000000;
pub(crate) const IOC_OUT: u32 = 0x40000000;
pub(crate) const IOC_IN: u32 = 0x80000000;
pub(crate) const IOC_INOUT: u32 = IOC_IN | IOC_OUT;
pub(crate) const IOC_DIRMASK: u32 = 0xe0000000;
// Only pub(crate) for the above reason.
pub(crate) const fn _IOC(inout: u32, group: c_ulong, num: c_ulong, len: c_ulong) -> c_ulong {
debug_assert!(inout <= IOC_DIRMASK);
debug_assert!(group <= 0xff);
debug_assert!(num <= 0xff);
debug_assert!(len <= IOCPARM_MAX);
// Sanity check the cast
assert!(size_of::<u32>() <= size_of::<c_ulong>());
(inout as c_ulong) | ((len & IOCPARM_MASK) << 16) | (group << 8) | num
}
pub const fn _IO(g: c_ulong, n: c_ulong) -> c_ulong {
_IOC(IOC_VOID, g, n, 0)
}
/// Build an ioctl number for an read-only ioctl.
pub const fn _IOR<T>(g: c_ulong, n: c_ulong) -> c_ulong {
_IOC(IOC_OUT, g, n, mem::size_of::<T>() as c_ulong)
}
/// Build an ioctl number for an write-only ioctl.
pub const fn _IOW<T>(g: c_ulong, n: c_ulong) -> c_ulong {
_IOC(IOC_IN, g, n, mem::size_of::<T>() as c_ulong)
}
/// Build an ioctl number for a read-write ioctl.
pub const fn _IOWR<T>(g: c_ulong, n: c_ulong) -> c_ulong {
_IOC(IOC_INOUT, g, n, mem::size_of::<T>() as c_ulong)
}
+18
View File
@@ -0,0 +1,18 @@
//! Directory: `sys/`
//!
//! <https://github.com/apple-oss-distributions/xnu/tree/main/bsd/sys>
pub(crate) mod ioccom;
pub(crate) mod signal;
pub(crate) mod sockio;
pub(crate) mod ttycom;
/// Directory: `sys/_types`
///
/// https://github.com/apple-oss-distributions/xnu/tree/main/bsd/sys/_types
pub(crate) mod _types {
pub(crate) mod _ucontext;
}
// Bit of a hack since the directories get merged and we can't have >1 sys module.
pub(crate) use crate::new::apple::libpthread::sys::*;
+6
View File
@@ -0,0 +1,6 @@
//! Header: `sys/signal.h`
//!
//! <https://github.com/apple-oss-distributions/xnu/blob/main/bsd/sys/signal.h>
pub use crate::machine::_mcontext::*;
pub use crate::sys::_types::_ucontext::*;
+88
View File
@@ -0,0 +1,88 @@
//! Header: `sys/sockio.h`
//!
//! <https://github.com/apple-oss-distributions/xnu/blob/main/bsd/sys/sockio.h>
use crate::prelude::*;
use crate::sys::ioccom::*;
pub const SIOCSHIWAT: c_ulong = _IOW::<c_int>('s' as c_ulong, 0);
pub const SIOCGHIWAT: c_ulong = _IOR::<c_int>('s' as c_ulong, 1);
pub const SIOCSLOWAT: c_ulong = _IOW::<c_int>('s' as c_ulong, 2);
pub const SIOCGLOWAT: c_ulong = _IOR::<c_int>('s' as c_ulong, 3);
pub const SIOCATMARK: c_ulong = _IOR::<c_int>('s' as c_ulong, 7);
pub const SIOCSPGRP: c_ulong = _IOW::<c_int>('s' as c_ulong, 8);
pub const SIOCGPGRP: c_ulong = _IOR::<c_int>('s' as c_ulong, 9);
pub const SIOCSIFADDR: c_ulong = _IOW::<crate::ifreq>('i' as c_ulong, 12);
pub const SIOCSIFDSTADDR: c_ulong = _IOW::<crate::ifreq>('i' as c_ulong, 14);
pub const SIOCSIFFLAGS: c_ulong = _IOW::<crate::ifreq>('i' as c_ulong, 16);
pub const SIOCGIFFLAGS: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 17);
pub const SIOCSIFBRDADDR: c_ulong = _IOW::<crate::ifreq>('i' as c_ulong, 19);
pub const SIOCSIFNETMASK: c_ulong = _IOW::<crate::ifreq>('i' as c_ulong, 22);
pub const SIOCGIFMETRIC: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 23);
pub const SIOCSIFMETRIC: c_ulong = _IOW::<crate::ifreq>('i' as c_ulong, 24);
pub const SIOCDIFADDR: c_ulong = _IOW::<crate::ifreq>('i' as c_ulong, 25);
// struct ifaliasreq
pub const SIOCAIFADDR: c_ulong = _IOC(IOC_IN, 'i' as c_ulong, 26, 64);
pub const SIOCGIFDSTADDR: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 34);
pub const SIOCGIFBRDADDR: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 35);
pub const SIOCGIFCONF: c_ulong = _IOWR::<crate::ifconf>('i' as c_ulong, 36);
pub const SIOCGIFNETMASK: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 37);
pub const SIOCAUTOADDR: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 38);
pub const SIOCAUTONETMASK: c_ulong = _IOW::<crate::ifreq>('i' as c_ulong, 39);
pub const SIOCARPIPLL: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 40);
pub const SIOCADDMULTI: c_ulong = _IOW::<crate::ifreq>('i' as c_ulong, 49);
pub const SIOCDELMULTI: c_ulong = _IOW::<crate::ifreq>('i' as c_ulong, 50);
pub const SIOCGIFMTU: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 51);
pub const SIOCSIFMTU: c_ulong = _IOW::<crate::ifreq>('i' as c_ulong, 52);
pub const SIOCGIFPHYS: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 53);
pub const SIOCSIFPHYS: c_ulong = _IOW::<crate::ifreq>('i' as c_ulong, 54);
pub const SIOCSIFMEDIA: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 55);
// struct ifmediareq
pub const SIOCGIFMEDIA: c_ulong = _IOC(IOC_INOUT, 'i' as c_ulong, 56, 44);
pub const SIOCSIFGENERIC: c_ulong = _IOW::<crate::ifreq>('i' as c_ulong, 57);
pub const SIOCGIFGENERIC: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 58);
// struct rslvmulti_req
pub const SIOCRSLVMULTI: c_ulong = _IOC(IOC_INOUT, 'i' as c_ulong, 59, 16);
pub const SIOCSIFLLADDR: c_ulong = _IOW::<crate::ifreq>('i' as c_ulong, 60);
// struct ifstat
pub const SIOCGIFSTATUS: c_ulong = _IOC(IOC_INOUT, 'i' as c_ulong, 61, 817);
// struct ifaliasreq
pub const SIOCSIFPHYADDR: c_ulong = _IOC(IOC_IN, 'i' as c_ulong, 62, 64);
pub const SIOCGIFPSRCADDR: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 63);
pub const SIOCGIFPDSTADDR: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 64);
pub const SIOCDIFPHYADDR: c_ulong = _IOW::<crate::ifreq>('i' as c_ulong, 65);
pub const SIOCGIFDEVMTU: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 68);
pub const SIOCSIFALTMTU: c_ulong = _IOW::<crate::ifreq>('i' as c_ulong, 69);
pub const SIOCGIFALTMTU: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 72);
pub const SIOCSIFBOND: c_ulong = _IOW::<crate::ifreq>('i' as c_ulong, 70);
pub const SIOCGIFBOND: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 71);
// struct ifmediareq
pub const SIOCGIFXMEDIA: c_ulong = _IOC(IOC_INOUT, 'i' as c_ulong, 72, 44);
pub const SIOCSIFCAP: c_ulong = _IOW::<crate::ifreq>('i' as c_ulong, 90);
pub const SIOCGIFCAP: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 91);
pub const SIOCSIFMANAGEMENT: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 92);
pub const SIOCIFCREATE: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 120);
pub const SIOCIFDESTROY: c_ulong = _IOW::<crate::ifreq>('i' as c_ulong, 121);
pub const SIOCIFCREATE2: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 122);
// struct ifdrv
pub const SIOCSDRVSPEC: c_ulong = _IOC(IOC_IN, 'i' as c_ulong, 123, 40);
// struct ifdrv
pub const SIOCGDRVSPEC: c_ulong = _IOC(IOC_INOUT, 'i' as c_ulong, 123, 40);
pub const SIOCSIFVLAN: c_ulong = _IOW::<crate::ifreq>('i' as c_ulong, 126);
pub const SIOCGIFVLAN: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 127);
pub const SIOCSETVLAN: c_ulong = SIOCSIFVLAN;
pub const SIOCGETVLAN: c_ulong = SIOCGIFVLAN;
// struct if_clonereq
pub const SIOCIFGCLONERS: c_ulong = _IOC(IOC_INOUT, 'i' as c_ulong, 129, 16);
pub const SIOCGIFASYNCMAP: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 124);
pub const SIOCSIFASYNCMAP: c_ulong = _IOW::<crate::ifreq>('i' as c_ulong, 125);
pub const SIOCGIFMAC: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 130);
pub const SIOCSIFMAC: c_ulong = _IOW::<crate::ifreq>('i' as c_ulong, 131);
pub const SIOCSIFKPI: c_ulong = _IOW::<crate::ifreq>('i' as c_ulong, 134);
pub const SIOCGIFKPI: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 135);
pub const SIOCGIFWAKEFLAGS: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 136);
pub const SIOCGIFFUNCTIONALTYPE: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 173);
pub const SIOCSIF6LOWPAN: c_ulong = _IOW::<crate::ifreq>('i' as c_ulong, 196);
pub const SIOCGIF6LOWPAN: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 197);
pub const SIOCGIFDIRECTLINK: c_ulong = _IOWR::<crate::ifreq>('i' as c_ulong, 222);
+93
View File
@@ -0,0 +1,93 @@
//! Header: `sys/ttycom.h`
//!
//! <https://github.com/apple-oss-distributions/xnu/blob/main/bsd/sys/ttycom.h>
use crate::prelude::*;
use crate::sys::ioccom::*;
/* FIXME(1.0): a number of ioctl numbers are `c_int` or `c_uint` and should be changed to
* `c_ulong` to match the others. */
pub const TIOCMODG: c_ulong = _IOR::<c_int>('t' as c_ulong, 3);
pub const TIOCMODS: c_ulong = _IOW::<c_int>('t' as c_ulong, 4);
pub const TIOCM_LE: c_int = 0o0001;
pub const TIOCM_DTR: c_int = 0o0002;
pub const TIOCM_RTS: c_int = 0o0004;
pub const TIOCM_ST: c_int = 0o0010;
pub const TIOCM_SR: c_int = 0o0020;
pub const TIOCM_CTS: c_int = 0o0040;
pub const TIOCM_CAR: c_int = 0o0100;
pub const TIOCM_CD: c_int = TIOCM_CAR;
pub const TIOCM_RNG: c_int = 0o0200;
pub const TIOCM_RI: c_int = TIOCM_RNG;
pub const TIOCM_DSR: c_int = 0o0400;
pub const TIOCEXCL: c_int = ulong_cast_int(_IO('t' as c_ulong, 13));
pub const TIOCNXCL: c_int = ulong_cast_int(_IO('t' as c_ulong, 14));
pub const TIOCFLUSH: c_ulong = _IOW::<c_int>('t' as c_ulong, 16);
pub const TIOCGETA: c_ulong = _IOR::<crate::termios>('t' as c_ulong, 19);
pub const TIOCSETA: c_ulong = _IOW::<crate::termios>('t' as c_ulong, 20);
pub const TIOCSETAW: c_ulong = _IOW::<crate::termios>('t' as c_ulong, 21);
pub const TIOCSETAF: c_ulong = _IOW::<crate::termios>('t' as c_ulong, 22);
pub const TIOCGETD: c_ulong = _IOR::<c_int>('t' as c_ulong, 26);
pub const TIOCSETD: c_ulong = _IOW::<c_int>('t' as c_ulong, 27);
pub const TIOCIXON: c_int = ulong_cast_int(_IO('t' as c_ulong, 129));
pub const TIOCIXOFF: c_int = ulong_cast_int(_IO('t' as c_ulong, 128));
pub const TIOCSBRK: c_int = ulong_cast_int(_IO('t' as c_ulong, 123));
pub const TIOCCBRK: c_int = ulong_cast_int(_IO('t' as c_ulong, 122));
pub const TIOCSDTR: c_int = ulong_cast_int(_IO('t' as c_ulong, 121));
pub const TIOCCDTR: c_int = ulong_cast_int(_IO('t' as c_ulong, 120));
pub const TIOCGPGRP: c_ulong = _IOR::<c_int>('t' as c_ulong, 119);
pub const TIOCSPGRP: c_ulong = _IOW::<c_int>('t' as c_ulong, 118);
pub const TIOCOUTQ: c_ulong = _IOR::<c_int>('t' as c_ulong, 115);
pub const TIOCSTI: c_ulong = _IOW::<c_char>('t' as c_ulong, 114);
pub const TIOCNOTTY: c_ulong = _IO('t' as c_ulong, 113);
pub const TIOCPKT: c_ulong = _IOW::<c_int>('t' as c_ulong, 112);
pub const TIOCPKT_DATA: c_int = 0x00;
pub const TIOCPKT_FLUSHREAD: c_int = 0x01;
pub const TIOCPKT_FLUSHWRITE: c_int = 0x02;
pub const TIOCPKT_STOP: c_int = 0x04;
pub const TIOCPKT_START: c_int = 0x08;
pub const TIOCPKT_NOSTOP: c_int = 0x10;
pub const TIOCPKT_DOSTOP: c_int = 0x20;
pub const TIOCPKT_IOCTL: c_int = 0x40;
pub const TIOCSTOP: c_uint = ulong_cast_uint(_IO('t' as c_ulong, 111));
pub const TIOCSTART: c_uint = ulong_cast_uint(_IO('t' as c_ulong, 110));
pub const TIOCMSET: c_ulong = _IOW::<c_int>('t' as c_ulong, 109);
pub const TIOCMBIS: c_ulong = _IOW::<c_int>('t' as c_ulong, 108);
pub const TIOCMBIC: c_ulong = _IOW::<c_int>('t' as c_ulong, 107);
pub const TIOCMGET: c_ulong = _IOR::<c_int>('t' as c_ulong, 106);
#[deprecated(since = "0.2.178", note = "Removed in MacOSX 12.0.1")]
pub const TIOCREMOTE: c_ulong = 0x80047469;
pub const TIOCGWINSZ: c_ulong = _IOR::<crate::winsize>('t' as c_ulong, 104);
pub const TIOCSWINSZ: c_ulong = _IOW::<crate::winsize>('t' as c_ulong, 103);
pub const TIOCUCNTL: c_ulong = _IOW::<c_int>('t' as c_ulong, 102);
pub const TIOCSTAT: c_uint = ulong_cast_uint(_IO('t' as c_ulong, 101));
pub const TIOCSCONS: c_uint = ulong_cast_uint(_IO('t' as c_ulong, 99));
pub const TIOCCONS: c_ulong = _IOW::<c_int>('t' as c_ulong, 98);
pub const TIOCSCTTY: c_uint = ulong_cast_uint(_IO('t' as c_ulong, 97));
pub const TIOCEXT: c_ulong = _IOW::<c_int>('t' as c_ulong, 96);
pub const TIOCSIG: c_uint = ulong_cast_uint(_IO('t' as c_ulong, 95));
pub const TIOCDRAIN: c_uint = ulong_cast_uint(_IO('t' as c_ulong, 94));
pub const TIOCMSDTRWAIT: c_ulong = _IOW::<c_int>('t' as c_ulong, 91);
pub const TIOCMGDTRWAIT: c_ulong = _IOR::<c_int>('t' as c_ulong, 90);
pub const TIOCTIMESTAMP: c_ulong = _IOR::<crate::timeval>('t' as c_ulong, 89);
pub const TIOCDCDTIMESTAMP: c_ulong = _IOR::<crate::timeval>('t' as c_ulong, 88);
pub const TIOCSDRAINWAIT: c_ulong = _IOW::<c_int>('t' as c_ulong, 87);
pub const TIOCGDRAINWAIT: c_ulong = _IOR::<c_int>('t' as c_ulong, 86);
pub const TIOCDSIMICROCODE: c_uint = ulong_cast_uint(_IO('t' as c_ulong, 85));
pub const TIOCPTYGRANT: c_uint = ulong_cast_uint(_IO('t' as c_ulong, 84));
pub const TIOCPTYGNAME: c_uint = ulong_cast_uint(_IOC(IOC_OUT, 't' as c_ulong, 83, 128));
pub const TIOCPTYUNLK: c_uint = ulong_cast_uint(_IO('t' as c_ulong, 82));
@@ -0,0 +1,5 @@
//! Directory: `bionic/libc/kernel/uapi/linux/`
//!
//! <https://cs.android.com/android/platform/superproject/main/+/main:bionic/libc/kernel/uapi/linux/>
pub(crate) mod types;
@@ -0,0 +1,21 @@
//! * Header: `bionic/libc/kernel/uapi/linux/types.h`
//! * Header: `bionic/libc/kernel/uapi/asm-generic/int-ll64.h`
use crate::prelude::*;
/* Definitions from `asm/types.h` -> `asm-generic/types.h` -> `asm-generic/int-ll64.h` */
pub type __u8 = c_uchar;
pub type __u16 = c_ushort;
pub type __s16 = c_short;
pub type __u32 = c_uint;
pub type __s32 = c_int;
pub type __s64 = c_longlong;
pub type __u64 = c_ulonglong;
/* From `uapi/linux/types.h` */
pub type __be16 = __u16;
+3
View File
@@ -0,0 +1,3 @@
//! Directory: `bionic/libc/kernel/uapi`
pub(crate) mod linux;
+10
View File
@@ -0,0 +1,10 @@
//! This directory maps to `bionic/libc/include` in the Android source. `bionic/libc/kernel` is
//! the source of UAPI definitions, which are a cleaned form of the default Linux headers.
//!
//! <https://cs.android.com/android/platform/superproject/main/+/main:bionic/libc/include/>,
//! <https://cs.android.com/android/platform/superproject/main/+/main:bionic/libc/kernel/uapi/>
pub(crate) mod kernel_uapi;
pub(crate) mod pthread;
pub(crate) mod sys;
pub(crate) mod unistd;
+42
View File
@@ -0,0 +1,42 @@
//! Header: `unistd.h`
pub use crate::new::common::linux_like::pthread::{
pthread_getattr_np,
pthread_setname_np,
};
pub use crate::new::common::posix::pthread::{
pthread_atfork,
pthread_attr_getguardsize,
pthread_attr_getinheritsched,
pthread_attr_getstack,
pthread_attr_setguardsize,
pthread_attr_setinheritsched,
pthread_attr_setstack,
pthread_barrier_destroy,
pthread_barrier_init,
pthread_barrier_wait,
pthread_barrierattr_destroy,
pthread_barrierattr_getpshared,
pthread_barrierattr_init,
pthread_barrierattr_setpshared,
pthread_condattr_getclock,
pthread_condattr_getpshared,
pthread_condattr_setclock,
pthread_condattr_setpshared,
pthread_create,
pthread_getcpuclockid,
pthread_getschedparam,
pthread_kill,
pthread_mutex_timedlock,
pthread_mutexattr_getpshared,
pthread_mutexattr_setpshared,
pthread_rwlockattr_getpshared,
pthread_rwlockattr_setpshared,
pthread_setschedparam,
pthread_sigmask,
pthread_spin_destroy,
pthread_spin_init,
pthread_spin_lock,
pthread_spin_trylock,
pthread_spin_unlock,
};
+3
View File
@@ -0,0 +1,3 @@
//! Directory: `sys/`
pub(crate) mod socket;
+51
View File
@@ -0,0 +1,51 @@
//! Header: `sys/socket.h`
use crate::prelude::*;
s! {
pub struct msghdr {
pub msg_name: *mut c_void,
pub msg_namelen: crate::socklen_t,
pub msg_iov: *mut crate::iovec,
pub msg_iovlen: size_t,
pub msg_control: *mut c_void,
pub msg_controllen: size_t,
pub msg_flags: c_int,
}
pub struct cmsghdr {
pub cmsg_len: size_t,
pub cmsg_level: c_int,
pub cmsg_type: c_int,
}
pub struct ucred {
pub pid: crate::pid_t,
pub uid: crate::uid_t,
pub gid: crate::gid_t,
}
}
extern "C" {
pub fn recvmmsg(
sockfd: c_int,
msgvec: *mut crate::mmsghdr,
vlen: c_uint,
flags: c_int,
timeout: *const crate::timespec,
) -> c_int;
pub fn sendmmsg(
sockfd: c_int,
msgvec: *const crate::mmsghdr,
vlen: c_uint,
flags: c_int,
) -> c_int;
pub fn recvfrom(
socket: c_int,
buf: *mut c_void,
len: size_t,
flags: c_int,
addr: *mut crate::sockaddr,
addrlen: *mut crate::socklen_t,
) -> ssize_t;
}
+7
View File
@@ -0,0 +1,7 @@
//! Header: `unistd.h`
pub use crate::new::common::posix::unistd::{
STDERR_FILENO,
STDIN_FILENO,
STDOUT_FILENO,
};
+1
View File
@@ -0,0 +1 @@
//! Interfaces common across the BSD family.
+1
View File
@@ -0,0 +1 @@
//! Interfaces common in FreeBSD-derived operating systems. This includes FreeBSD and DragonFlyBSD.
+9
View File
@@ -0,0 +1,9 @@
//! API that primarily comes from Linux but is also used other platforms (e.g. Android).
#[cfg(any(
target_os = "android",
target_os = "emscripten",
target_os = "l4re",
target_os = "linux"
))]
pub(crate) mod pthread;
+25
View File
@@ -0,0 +1,25 @@
use crate::prelude::*;
extern "C" {
#[cfg(any(target_os = "linux", target_os = "l4re"))]
pub fn pthread_getaffinity_np(
thread: crate::pthread_t,
cpusetsize: size_t,
cpuset: *mut crate::cpu_set_t,
) -> c_int;
pub fn pthread_getattr_np(native: crate::pthread_t, attr: *mut crate::pthread_attr_t) -> c_int;
#[cfg(target_os = "linux")]
pub fn pthread_getname_np(thread: crate::pthread_t, name: *mut c_char, len: size_t) -> c_int;
#[cfg(any(target_os = "linux", target_os = "l4re"))]
pub fn pthread_setaffinity_np(
thread: crate::pthread_t,
cpusetsize: size_t,
cpuset: *const crate::cpu_set_t,
) -> c_int;
#[cfg(any(target_os = "android", target_os = "linux"))]
pub fn pthread_setname_np(thread: crate::pthread_t, name: *const c_char) -> c_int;
}
+39
View File
@@ -0,0 +1,39 @@
//! Interfaces that are common across multiple platforms
//!
//! We make these available everywhere but each platform must opt in to reexporting.
//!
//! There shouldn't be any repeated definitions or complex configuration in this module. On
//! platforms that don't use common APIs it is fine to use `#[cfg(not(...))]`, but if a platform
//! needs a custom definition then it should be defined in the platform-specific module.
//!
//! The goal is that platforms need to opt in to the definitions here, so that worst case we have
//! an unused warning on untested platforms (rather than exposing incorrect API).
#[cfg(any(
target_vendor = "apple",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
))]
pub(crate) mod bsd;
#[cfg(any(
target_os = "android",
target_os = "emscripten",
target_os = "l4re",
target_os = "linux",
))]
pub(crate) mod linux_like;
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
pub(crate) mod freebsd_like;
#[cfg(any(target_os = "netbsd", target_os = "openbsd"))]
pub(crate) mod netbsd_like;
#[cfg(any(target_os = "illumos", target_os = "solaris"))]
pub(crate) mod solarish;
#[cfg(target_family = "unix")]
pub(crate) mod posix;
+1
View File
@@ -0,0 +1 @@
//! Interfaces common in NetBSD-derived operating systems. This includes NetBSD and OpenBSD.
+15
View File
@@ -0,0 +1,15 @@
//! POSIX APIs that are used by a number of platforms
//!
//! These can be found at: <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/contents.html>.
// FIXME(pthread): eventually all platforms should use this module
#[cfg(any(
target_os = "android",
target_os = "emscripten",
target_os = "l4re",
target_os = "linux",
target_os = "qurt",
target_vendor = "apple",
))]
pub(crate) mod pthread;
pub(crate) mod unistd;
+332
View File
@@ -0,0 +1,332 @@
//! Header: `pthread.h`
//!
//! <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/pthread.h.html>
use crate::prelude::*;
extern "C" {
#[cfg(any(target_os = "android", target_os = "linux"))]
pub fn pthread_atfork(
prepare: Option<unsafe extern "C" fn()>,
parent: Option<unsafe extern "C" fn()>,
child: Option<unsafe extern "C" fn()>,
) -> c_int;
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_attr_getguardsize(
attr: *const crate::pthread_attr_t,
guardsize: *mut size_t,
) -> c_int;
#[cfg(any(
target_os = "android",
target_os = "l4re",
target_os = "linux",
target_vendor = "apple",
))]
pub fn pthread_attr_getinheritsched(
attr: *const crate::pthread_attr_t,
inheritsched: *mut c_int,
) -> c_int;
#[cfg(any(target_os = "l4re", target_os = "linux", target_vendor = "apple"))]
pub fn pthread_attr_getschedparam(
attr: *const crate::pthread_attr_t,
param: *mut crate::sched_param,
) -> c_int;
#[cfg(any(target_os = "l4re", target_os = "linux", target_vendor = "apple"))]
pub fn pthread_attr_getschedpolicy(
attr: *const crate::pthread_attr_t,
policy: *mut c_int,
) -> c_int;
#[cfg(any(
target_os = "android",
target_os = "emscripten",
target_os = "linux",
target_os = "l4re"
))]
pub fn pthread_attr_getstack(
attr: *const crate::pthread_attr_t,
stackaddr: *mut *mut c_void,
stacksize: *mut size_t,
) -> c_int;
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_attr_setguardsize(attr: *mut crate::pthread_attr_t, guardsize: size_t) -> c_int;
#[cfg(any(
target_os = "android",
target_os = "l4re",
target_os = "linux",
target_vendor = "apple"
))]
pub fn pthread_attr_setinheritsched(
attr: *mut crate::pthread_attr_t,
inheritsched: c_int,
) -> c_int;
#[cfg(any(target_os = "l4re", target_os = "linux", target_vendor = "apple"))]
pub fn pthread_attr_setschedparam(
attr: *mut crate::pthread_attr_t,
param: *const crate::sched_param,
) -> c_int;
#[cfg(any(target_os = "l4re", target_os = "linux", target_vendor = "apple"))]
pub fn pthread_attr_setschedpolicy(attr: *mut crate::pthread_attr_t, policy: c_int) -> c_int;
#[cfg(any(
target_os = "android",
target_os = "emscripten",
target_os = "linux",
target_os = "l4re"
))]
pub fn pthread_attr_setstack(
attr: *mut crate::pthread_attr_t,
stackaddr: *mut c_void,
stacksize: size_t,
) -> c_int;
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_barrier_destroy(barrier: *mut crate::pthread_barrier_t) -> c_int;
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_barrier_init(
barrier: *mut crate::pthread_barrier_t,
attr: *const crate::pthread_barrierattr_t,
count: c_uint,
) -> c_int;
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_barrier_wait(barrier: *mut crate::pthread_barrier_t) -> c_int;
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_barrierattr_destroy(attr: *mut crate::pthread_barrierattr_t) -> c_int;
#[cfg(any(target_os = "android", target_os = "linux"))]
pub fn pthread_barrierattr_getpshared(
attr: *const crate::pthread_barrierattr_t,
shared: *mut c_int,
) -> c_int;
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_barrierattr_init(attr: *mut crate::pthread_barrierattr_t) -> c_int;
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_barrierattr_setpshared(
attr: *mut crate::pthread_barrierattr_t,
shared: c_int,
) -> c_int;
#[cfg(any(target_os = "l4re", all(target_os = "linux", not(target_env = "ohos"))))]
pub fn pthread_cancel(thread: crate::pthread_t) -> c_int;
#[cfg(any(target_os = "android", target_os = "emscripten", target_os = "linux",))]
pub fn pthread_condattr_getclock(
attr: *const crate::pthread_condattr_t,
clock_id: *mut crate::clockid_t,
) -> c_int;
#[cfg(any(
target_os = "android",
target_os = "l4re",
target_os = "linux",
target_vendor = "apple",
))]
pub fn pthread_condattr_getpshared(
attr: *const crate::pthread_condattr_t,
pshared: *mut c_int,
) -> c_int;
#[cfg(any(target_os = "android", target_os = "emscripten", target_os = "linux",))]
pub fn pthread_condattr_setclock(
attr: *mut crate::pthread_condattr_t,
clock_id: crate::clockid_t,
) -> c_int;
#[cfg(any(
target_os = "android",
target_os = "emscripten",
target_os = "linux",
target_os = "l4re",
target_vendor = "apple",
))]
pub fn pthread_condattr_setpshared(
attr: *mut crate::pthread_condattr_t,
pshared: c_int,
) -> c_int;
#[cfg(any(
target_os = "android",
target_os = "emscripten",
target_os = "l4re",
target_os = "linux",
))]
pub fn pthread_create(
native: *mut crate::pthread_t,
attr: *const crate::pthread_attr_t,
f: extern "C" fn(*mut c_void) -> *mut c_void,
value: *mut c_void,
) -> c_int;
#[cfg(any(target_os = "android", target_os = "linux"))]
pub fn pthread_getcpuclockid(thread: crate::pthread_t, clk_id: *mut crate::clockid_t) -> c_int;
#[cfg(any(
target_os = "android",
target_os = "l4re",
target_os = "linux",
target_vendor = "apple",
))]
pub fn pthread_getschedparam(
native: crate::pthread_t,
policy: *mut c_int,
param: *mut crate::sched_param,
) -> c_int;
// FIXME(reorg): In recent POSIX versions, this is a signal.h function and not required
// in pthread.
#[cfg(any(
target_os = "android",
target_os = "emscripten",
target_os = "l4re",
target_os = "linux"
))]
pub fn pthread_kill(thread: crate::pthread_t, sig: c_int) -> c_int;
#[cfg(all(target_os = "linux", not(target_env = "ohos")))]
pub fn pthread_mutex_consistent(mutex: *mut crate::pthread_mutex_t) -> c_int;
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
#[cfg_attr(gnu_time_bits64, link_name = "__pthread_mutex_timedlock64")]
#[cfg_attr(musl_redir_time64, link_name = "__pthread_mutex_timedlock_time64")]
pub fn pthread_mutex_timedlock(
lock: *mut crate::pthread_mutex_t,
abstime: *const crate::timespec,
) -> c_int;
#[cfg(target_os = "linux")]
pub fn pthread_mutexattr_getprotocol(
attr: *const crate::pthread_mutexattr_t,
protocol: *mut c_int,
) -> c_int;
#[cfg(any(
target_os = "android",
target_os = "l4re",
target_os = "linux",
target_vendor = "apple",
))]
pub fn pthread_mutexattr_getpshared(
attr: *const crate::pthread_mutexattr_t,
pshared: *mut c_int,
) -> c_int;
#[cfg(all(target_os = "linux", not(target_env = "ohos")))]
pub fn pthread_mutexattr_getrobust(
attr: *const crate::pthread_mutexattr_t,
robustness: *mut c_int,
) -> c_int;
#[cfg(target_os = "linux")]
pub fn pthread_mutexattr_setprotocol(
attr: *mut crate::pthread_mutexattr_t,
protocol: c_int,
) -> c_int;
#[cfg(any(
target_os = "android",
target_os = "emscripten",
target_os = "linux",
target_os = "l4re",
target_vendor = "apple",
))]
pub fn pthread_mutexattr_setpshared(
attr: *mut crate::pthread_mutexattr_t,
pshared: c_int,
) -> c_int;
#[cfg(all(target_os = "linux", not(target_env = "ohos")))]
pub fn pthread_mutexattr_setrobust(
attr: *mut crate::pthread_mutexattr_t,
robustness: c_int,
) -> c_int;
#[cfg(any(
target_os = "android",
target_os = "emscripten",
target_os = "linux",
target_os = "l4re",
target_vendor = "apple",
))]
pub fn pthread_rwlockattr_getpshared(
attr: *const crate::pthread_rwlockattr_t,
val: *mut c_int,
) -> c_int;
#[cfg(any(
target_os = "android",
target_os = "emscripten",
target_os = "linux",
target_os = "l4re",
target_vendor = "apple",
))]
pub fn pthread_rwlockattr_setpshared(
attr: *mut crate::pthread_rwlockattr_t,
val: c_int,
) -> c_int;
// FIXME(1.0): These shoul be combined to the version that takes an optional unsafe function.
#[cfg(any(target_os = "l4re", target_os = "linux"))]
pub fn pthread_once(control: *mut crate::pthread_once_t, routine: extern "C" fn()) -> c_int;
#[cfg(target_vendor = "apple")]
pub fn pthread_once(
once_control: *mut crate::pthread_once_t,
init_routine: Option<unsafe extern "C" fn()>,
) -> c_int;
#[cfg(any(
target_os = "android",
target_os = "l4re",
target_os = "linux",
target_vendor = "apple",
))]
pub fn pthread_setschedparam(
native: crate::pthread_t,
policy: c_int,
param: *const crate::sched_param,
) -> c_int;
#[cfg(target_os = "linux")]
pub fn pthread_setschedprio(native: crate::pthread_t, priority: c_int) -> c_int;
// FIXME(reorg): In recent POSIX versions, this is a signal.h function and not required
// in pthread.
#[cfg(any(
target_os = "android",
target_os = "emscripten",
target_os = "l4re",
target_os = "linux"
))]
pub fn pthread_sigmask(
how: c_int,
set: *const crate::sigset_t,
oldset: *mut crate::sigset_t,
) -> c_int;
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_spin_destroy(lock: *mut crate::pthread_spinlock_t) -> c_int;
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_spin_init(lock: *mut crate::pthread_spinlock_t, pshared: c_int) -> c_int;
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_spin_lock(lock: *mut crate::pthread_spinlock_t) -> c_int;
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_spin_trylock(lock: *mut crate::pthread_spinlock_t) -> c_int;
#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
pub fn pthread_spin_unlock(lock: *mut crate::pthread_spinlock_t) -> c_int;
}
+9
View File
@@ -0,0 +1,9 @@
//! Header: `unistd.h`
//!
//! <https://pubs.opengroup.org/onlinepubs/007904975/basedefs/unistd.h.html>
use crate::prelude::*;
pub const STDIN_FILENO: c_int = 0;
pub const STDOUT_FILENO: c_int = 1;
pub const STDERR_FILENO: c_int = 2;
+1
View File
@@ -0,0 +1 @@
//! Interfaces common in solaris-derived operating systems. This includes Solaris and Illumos.
+5
View File
@@ -0,0 +1,5 @@
//! Cygwin libc.
//!
//! * Headers: <https://github.com/cygwin/cygwin/tree/main/winsup/cygwin/include>
pub(crate) mod unistd;
+7
View File
@@ -0,0 +1,7 @@
//! Header: `unistd.h`
pub use crate::new::common::posix::unistd::{
STDERR_FILENO,
STDIN_FILENO,
STDOUT_FILENO,
};
+6
View File
@@ -0,0 +1,6 @@
//! DragonFly BSD libc.
//!
//! * Headers: <https://github.com/DragonFlyBSD/DragonFlyBSD>
//! * Manual pages: <https://leaf.dragonflybsd.org/cgi/web-man>
pub(crate) mod unistd;
+7
View File
@@ -0,0 +1,7 @@
//! Header: `unistd.h`
pub use crate::new::common::posix::unistd::{
STDERR_FILENO,
STDIN_FILENO,
STDOUT_FILENO,
};
+7
View File
@@ -0,0 +1,7 @@
//! Emscripten libc.
//!
//! * Headers: <https://github.com/emscripten-core/emscripten/tree/main/system/lib/libc>
pub(crate) mod pthread;
pub(crate) mod sched;
pub(crate) mod unistd;
+16
View File
@@ -0,0 +1,16 @@
//! Header: `pthread.h`
pub use crate::new::common::linux_like::pthread::pthread_getattr_np;
pub use crate::new::common::posix::pthread::{
pthread_attr_getstack,
pthread_attr_setstack,
pthread_condattr_getclock,
pthread_condattr_setclock,
pthread_condattr_setpshared,
pthread_create,
pthread_kill,
pthread_mutexattr_setpshared,
pthread_rwlockattr_getpshared,
pthread_rwlockattr_setpshared,
pthread_sigmask,
};
+38
View File
@@ -0,0 +1,38 @@
use crate::prelude::*;
cfg_if! {
if #[cfg(musl_v1_2_3)] {
s! {
struct __c_anon_sched_param__reserved2 {
__reserved1: crate::time_t,
__reserved2: c_long,
}
pub struct sched_param {
pub sched_priority: c_int,
__reserved1: Padding<c_int>,
#[cfg(musl32_time64)]
__reserved2: Padding<[c_long; 4]>,
#[cfg(not(musl32_time64))]
__reserved2: Padding<[__c_anon_sched_param__reserved2; 2]>,
__reserved3: Padding<c_int>,
}
}
} else {
s! {
pub struct sched_param {
pub sched_priority: c_int,
#[deprecated(since = "0.2.173", note = "This field has been removed upstream")]
pub sched_ss_low_priority: c_int,
#[deprecated(since = "0.2.173", note = "This field has been removed upstream")]
pub sched_ss_repl_period: crate::timespec,
#[deprecated(since = "0.2.173", note = "This field has been removed upstream")]
pub sched_ss_init_budget: crate::timespec,
#[deprecated(since = "0.2.173", note = "This field has been removed upstream")]
pub sched_ss_max_repl: c_int,
}
}
}
}
+7
View File
@@ -0,0 +1,7 @@
//! Header: `unistd.h`
pub use crate::new::common::posix::unistd::{
STDERR_FILENO,
STDIN_FILENO,
STDOUT_FILENO,
};
+2
View File
@@ -0,0 +1,2 @@
//! Expressif libc.
// FIXME(espidf): link to headers needed.
+9
View File
@@ -0,0 +1,9 @@
//! FreeBSD libc.
//!
//! * Headers: <https://github.com/freebsd/freebsd-src/blob/main/sys/riscv/include/ucontext.h>
//! * Symbol map: <https://github.com/freebsd/freebsd-src/blob/main/lib/libc/gen/Symbol.map>
pub(crate) mod net;
pub(crate) mod netinet6;
pub(crate) mod sys;
pub(crate) mod unistd;
+20
View File
@@ -0,0 +1,20 @@
//! Header: `net/dlt.h`
//!
//! https://github.com/freebsd/freebsd-src/blob/main/sys/net/dlt.h
use crate::prelude::*;
pub const DLT_NULL: c_uint = 0; // no link-layer encapsulation
pub const DLT_EN10MB: c_uint = 1; // Ethernet (10Mb)
pub const DLT_EN3MB: c_uint = 2; // Experimental Ethernet (3Mb)
pub const DLT_AX25: c_uint = 3; // Amateur Radio AX.25
pub const DLT_PRONET: c_uint = 4; // Proteon ProNET Token Ring
pub const DLT_CHAOS: c_uint = 5; // Chaos
pub const DLT_IEEE802: c_uint = 6; // IEEE 802 Networks
pub const DLT_ARCNET: c_uint = 7; // ARCNET
pub const DLT_SLIP: c_uint = 8; // Serial Line IP
pub const DLT_PPP: c_uint = 9; // Point-to-point Protocol
pub const DLT_FDDI: c_uint = 10; // FDDI
pub const DLT_ATM_RFC1483: c_uint = 11; // LLC/SNAP encapsulated atm
pub const DLT_RAW: c_uint = 12; // raw IP
pub const DLT_LOOP: c_uint = 108;
+5
View File
@@ -0,0 +1,5 @@
//! Directory: `net/`
//!
//! https://github.com/freebsd/freebsd-src/tree/main/sys/net
pub(crate) mod dlt;
+107
View File
@@ -0,0 +1,107 @@
//! Header: `netinet6/in6_var.h`
//!
//! https://github.com/freebsd/freebsd-src/blob/main/sys/netinet6/in6_var.h
use crate::prelude::*;
use crate::sys::ioccom::*;
s! {
pub struct in6_addrlifetime {
pub ia6t_expire: crate::time_t,
pub ia6t_preferred: crate::time_t,
pub ia6t_vltime: u32,
pub ia6t_pltime: u32,
}
pub struct in6_ifstat {
pub ifs6_in_receive: u64,
pub ifs6_in_hdrerr: u64,
pub ifs6_in_toobig: u64,
pub ifs6_in_noroute: u64,
pub ifs6_in_addrerr: u64,
pub ifs6_in_protounknown: u64,
pub ifs6_in_truncated: u64,
pub ifs6_in_discard: u64,
pub ifs6_in_deliver: u64,
pub ifs6_out_forward: u64,
pub ifs6_out_request: u64,
pub ifs6_out_discard: u64,
pub ifs6_out_fragok: u64,
pub ifs6_out_fragfail: u64,
pub ifs6_out_fragcreat: u64,
pub ifs6_reass_reqd: u64,
pub ifs6_reass_ok: u64,
pub ifs6_reass_fail: u64,
pub ifs6_in_mcast: u64,
pub ifs6_out_mcast: u64,
}
pub struct icmp6_ifstat {
pub ifs6_in_msg: u64,
pub ifs6_in_error: u64,
pub ifs6_in_dstunreach: u64,
pub ifs6_in_adminprohib: u64,
pub ifs6_in_timeexceed: u64,
pub ifs6_in_paramprob: u64,
pub ifs6_in_pkttoobig: u64,
pub ifs6_in_echo: u64,
pub ifs6_in_echoreply: u64,
pub ifs6_in_routersolicit: u64,
pub ifs6_in_routeradvert: u64,
pub ifs6_in_neighborsolicit: u64,
pub ifs6_in_neighboradvert: u64,
pub ifs6_in_redirect: u64,
pub ifs6_in_mldquery: u64,
pub ifs6_in_mldreport: u64,
pub ifs6_in_mlddone: u64,
pub ifs6_out_msg: u64,
pub ifs6_out_error: u64,
pub ifs6_out_dstunreach: u64,
pub ifs6_out_adminprohib: u64,
pub ifs6_out_timeexceed: u64,
pub ifs6_out_paramprob: u64,
pub ifs6_out_pkttoobig: u64,
pub ifs6_out_echo: u64,
pub ifs6_out_echoreply: u64,
pub ifs6_out_routersolicit: u64,
pub ifs6_out_routeradvert: u64,
pub ifs6_out_neighborsolicit: u64,
pub ifs6_out_neighboradvert: u64,
pub ifs6_out_redirect: u64,
pub ifs6_out_mldquery: u64,
pub ifs6_out_mldreport: u64,
pub ifs6_out_mlddone: u64,
}
}
s_no_extra_traits! {
pub struct in6_ifreq {
pub ifr_name: [c_char; crate::IFNAMSIZ],
pub ifr_ifru: __c_anonymous_ifr_ifru6,
}
pub union __c_anonymous_ifr_ifru6 {
pub ifru_addr: crate::sockaddr_in6,
pub ifru_dstaddr: crate::sockaddr_in6,
pub ifru_flags: c_int,
pub ifru_flags6: c_int,
pub ifru_metric: c_int,
pub ifru_data: crate::caddr_t,
pub ifru_lifetime: in6_addrlifetime,
pub ifru_stat: in6_ifstat,
pub ifru_icmp6stat: icmp6_ifstat,
pub ifru_scope_id: [u32; 16],
}
}
pub const IN6_IFF_ANYCAST: c_int = 0x01;
pub const IN6_IFF_TENTATIVE: c_int = 0x02;
pub const IN6_IFF_DUPLICATED: c_int = 0x04;
pub const IN6_IFF_DETACHED: c_int = 0x08;
pub const IN6_IFF_DEPRECATED: c_int = 0x10;
pub const IN6_IFF_NODAD: c_int = 0x20;
pub const IN6_IFF_AUTOCONF: c_int = 0x40;
pub const IN6_IFF_TEMPORARY: c_int = 0x80;
pub const IN6_IFF_PREFER_SOURCE: c_int = 0x0100;
pub const SIOCGIFAFLAG_IN6: c_ulong = _IOWR::<crate::in6_ifreq>('i' as c_ulong, 73);
+5
View File
@@ -0,0 +1,5 @@
//! Directory: `netinet6/`
//!
//! https://github.com/freebsd/freebsd-src/tree/main/sys/netinet6
pub(crate) mod in6_var;
+46
View File
@@ -0,0 +1,46 @@
//! Header: `sys/file.h`
//!
//! https://github.com/freebsd/freebsd-src/blob/main/sys/sys/file.h
use crate::prelude::*;
pub const DTYPE_NONE: c_int = 0;
pub const DTYPE_VNODE: c_int = 1;
pub const DTYPE_SOCKET: c_int = 2;
pub const DTYPE_PIPE: c_int = 3;
pub const DTYPE_FIFO: c_int = 4;
pub const DTYPE_KQUEUE: c_int = 5;
pub const DTYPE_CRYPTO: c_int = 6;
pub const DTYPE_MQUEUE: c_int = 7;
pub const DTYPE_SHM: c_int = 8;
pub const DTYPE_SEM: c_int = 9;
pub const DTYPE_PTS: c_int = 10;
pub const DTYPE_DEV: c_int = 11;
pub const DTYPE_PROCDESC: c_int = 12;
pub const DTYPE_EVENTFD: c_int = 13;
pub const DTYPE_TIMERFD: c_int = 14;
pub const DTYPE_INOTIFY: c_int = 15;
pub const DTYPE_JAILDESC: c_int = 16;
s! {
#[cfg(not(any(freebsd10, freebsd11)))]
pub struct xfile {
pub xf_size: crate::ksize_t,
pub xf_pid: crate::pid_t,
pub xf_uid: crate::uid_t,
pub xf_fd: c_int,
_xf_int_pad1: Padding<c_int>,
pub xf_file: crate::kvaddr_t,
pub xf_type: c_short,
_xf_short_pad1: Padding<c_short>,
pub xf_count: c_int,
pub xf_msgcount: c_int,
_xf_int_pad2: Padding<c_int>,
pub xf_offset: crate::off_t,
pub xf_data: crate::kvaddr_t,
pub xf_vnode: crate::kvaddr_t,
pub xf_flag: c_uint,
_xf_int_pad3: Padding<c_int>,
_xf_int64_pad: Padding<[i64; 6]>,
}
}
+49
View File
@@ -0,0 +1,49 @@
//! Header: `sys/ioccom.h`
//!
//! https://github.com/freebsd/freebsd-src/blob/main/sys/sys/ioccom.h
use crate::prelude::*;
const IOCPARM_SHIFT: c_ulong = 13;
const IOCPARM_MASK: c_ulong = (1 << IOCPARM_SHIFT) - 1;
const IOCPARM_MAX: c_ulong = 1 << IOCPARM_SHIFT;
pub(crate) const IOC_VOID: c_ulong = 0x20000000;
pub(crate) const IOC_OUT: c_ulong = 0x40000000;
pub(crate) const IOC_IN: c_ulong = 0x80000000;
pub(crate) const IOC_INOUT: c_ulong = IOC_IN | IOC_OUT;
pub(crate) const IOC_DIRMASK: c_ulong = IOC_VOID | IOC_OUT | IOC_IN;
pub(crate) const fn _IOC(inout: c_ulong, group: c_ulong, num: c_ulong, len: c_ulong) -> c_ulong {
debug_assert!(inout <= IOC_DIRMASK);
debug_assert!(group <= 0xff);
debug_assert!(num <= 0xff);
debug_assert!(len <= IOCPARM_MAX);
inout | ((len & IOCPARM_MASK) << 16) | (group << 8) | num
}
pub const fn _IO(g: c_ulong, n: c_ulong) -> c_ulong {
_IOC(IOC_VOID, g, n, 0)
}
/// Build an ioctl number for an ioctl that passes an `int` by value.
pub const fn _IOWINT(g: c_ulong, n: c_ulong) -> c_ulong {
_IOC(IOC_VOID, g, n, mem::size_of::<c_int>() as c_ulong)
}
/// Build an ioctl number for an read-only ioctl.
pub const fn _IOR<T>(g: c_ulong, n: c_ulong) -> c_ulong {
_IOC(IOC_OUT, g, n, mem::size_of::<T>() as c_ulong)
}
/// Build an ioctl number for an write-only ioctl.
pub const fn _IOW<T>(g: c_ulong, n: c_ulong) -> c_ulong {
_IOC(IOC_IN, g, n, mem::size_of::<T>() as c_ulong)
}
/// Build an ioctl number for a read-write ioctl.
pub const fn _IOWR<T>(g: c_ulong, n: c_ulong) -> c_ulong {
_IOC(IOC_INOUT, g, n, mem::size_of::<T>() as c_ulong)
}
+7
View File
@@ -0,0 +1,7 @@
//! Directory: `sys/`
//!
//! https://github.com/freebsd/freebsd-src/tree/main/sys/sys'
pub(crate) mod file;
pub(crate) mod ioccom;
pub(crate) mod socket;
+7
View File
@@ -0,0 +1,7 @@
//! Header: `sys/socket.h`
//!
//! https://github.com/freebsd/freebsd-src/blob/main/sys/sys/socket.h
use crate::prelude::*;
pub const SO_RERROR: c_int = 0x0002_0000;
+7
View File
@@ -0,0 +1,7 @@
//! Header: `unistd.h`
pub use crate::new::common::posix::unistd::{
STDERR_FILENO,
STDIN_FILENO,
STDOUT_FILENO,
};
+4
View File
@@ -0,0 +1,4 @@
//! Fuschia libc.
// FIXME(fuchsia): link to headers needed.
pub(crate) mod unistd;
+7
View File
@@ -0,0 +1,7 @@
//! Header: `unistd.h`
pub use crate::new::common::posix::unistd::{
STDERR_FILENO,
STDIN_FILENO,
STDOUT_FILENO,
};
+34
View File
@@ -0,0 +1,34 @@
//! GNU libc.
//!
//! * Headers: <https://sourceware.org/git/?p=glibc.git> (official)
//! * Headers: <https://github.com/bminor/glibc> (mirror)
//!
//! This module structure is modeled after glibc's source tree. Its build system selects headers
//! from different locations based on the platform, which we mimic here with reexports.
/// Source directory: `posix/`
///
/// <https://github.com/bminor/glibc/tree/master/posix>
mod posix {
pub(crate) mod unistd;
}
/// Source directory: `sysdeps/`
///
/// <https://github.com/bminor/glibc/tree/master/sysdeps>
mod sysdeps {
// FIXME(pthread): eventually all platforms should use this module
#[cfg(target_os = "linux")]
pub(crate) mod nptl;
pub(crate) mod unix;
// You'll notice some directories that provide a `bits` module. These are included via
// `path = "..."` wherever the generic implementation lives.
}
pub(crate) use posix::*;
// FIXME(pthread): eventually all platforms should use this module
#[cfg(target_os = "linux")]
pub(crate) use sysdeps::nptl::*;
#[cfg(target_os = "linux")]
pub(crate) use sysdeps::unix::linux::*;
+9
View File
@@ -0,0 +1,9 @@
//! Header: `unistd.h`
//!
//! <https://github.com/bminor/glibc/blob/master/posix/unistd.h>
pub use crate::new::common::posix::unistd::{
STDERR_FILENO,
STDIN_FILENO,
STDOUT_FILENO,
};
+6
View File
@@ -0,0 +1,6 @@
//! Directory: `sysdeps/mips`
#[cfg(target_os = "linux")]
pub(crate) mod nptl {
pub(crate) mod bits;
}
@@ -0,0 +1,3 @@
//! Directory: `sysdeps/mips/nptl/bits`
pub(crate) mod struct_mutex;
@@ -0,0 +1,19 @@
//! Header: `sysdeps/mips/nptl/bits/struct_mutex.h`
use crate::prelude::*;
pub const fn __PTHREAD_MUTEX_INITIALIZER(__kind: c_int) -> crate::pthread_mutex_t {
// We don't need the whole complicated `__pthread_mutex_s` definition, just use the
// offset of the `__kind` field.
let kind_offset = if cfg!(target_abi = "abi64") {
4 * size_of::<c_int>()
} else {
3 * size_of::<c_int>()
};
let size = [0; crate::__SIZEOF_PTHREAD_MUTEX_T];
let kind_bytes = __kind.to_ne_bytes();
let repl = u8_slice_cast_char_slice(&kind_bytes);
let size = replace_array_items(size, repl, kind_offset);
crate::pthread_mutex_t { size }
}
@@ -0,0 +1,20 @@
//! Header: `sysdeps/nptl/bits/struct_mutex.h`
use crate::prelude::*;
pub const fn __PTHREAD_MUTEX_INITIALIZER(__kind: c_int) -> crate::pthread_mutex_t {
// We don't need the whole complicated `__pthread_mutex_s` definition, just use the
// offset of the `__kind` field.
let __PTHREAD_MUTEX_HAVE_PREV = cfg!(target_pointer_width = "64");
let kind_offset = if __PTHREAD_MUTEX_HAVE_PREV {
4 * size_of::<c_int>()
} else {
3 * size_of::<c_int>()
};
let size = [0; crate::__SIZEOF_PTHREAD_MUTEX_T];
let kind_bytes = __kind.to_ne_bytes();
let repl = u8_slice_cast_char_slice(&kind_bytes);
let size = replace_array_items(size, repl, kind_offset);
crate::pthread_mutex_t { size }
}
+29
View File
@@ -0,0 +1,29 @@
//! Source directory: `sysdeps/nptl/`o
//!
//! Native POSIX threading library.
//!
//! <https://github.com/bminor/glibc/tree/master/sysdeps/nptl>
pub(crate) mod bits {
#[cfg_attr(
any(
target_arch = "mips",
target_arch = "mips32r6",
target_arch = "mips",
target_arch = "mips32r6",
),
path = "../../mips/nptl/bits/struct_mutex.rs"
)]
#[cfg_attr(
any(target_arch = "powerpc", target_arch = "powerpc64"),
path = "../../powerpc/nptl/bits/struct_mutex.rs"
)]
#[cfg_attr(target_arch = "s390x", path = "../../s390/nptl/bits/struct_mutex.rs")]
#[cfg_attr(
any(target_arch = "x86", target_arch = "x86_64"),
path = "../../x86/nptl/bits/struct_mutex.rs"
)]
pub(crate) mod struct_mutex;
}
pub(crate) mod pthread;
+81
View File
@@ -0,0 +1,81 @@
//! Source header: `sysdeps/nptl/pthread.h`
//!
//! <https://github.com/bminor/glibc/blob/master/sysdeps/nptl/pthread.h>
use super::bits::struct_mutex::*;
use crate::prelude::*;
c_enum! {
#[repr(c_int)]
enum #anon {
PTHREAD_MUTEX_TIMED_NP,
PTHREAD_MUTEX_RECURSIVE_NP,
PTHREAD_MUTEX_ERRORCHECK_NP,
pub PTHREAD_MUTEX_ADAPTIVE_NP,
}
}
pub const PTHREAD_MUTEX_INITIALIZER: crate::pthread_mutex_t =
__PTHREAD_MUTEX_INITIALIZER(PTHREAD_MUTEX_TIMED_NP);
pub const PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP: crate::pthread_mutex_t =
__PTHREAD_MUTEX_INITIALIZER(PTHREAD_MUTEX_RECURSIVE_NP);
pub const PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP: crate::pthread_mutex_t =
__PTHREAD_MUTEX_INITIALIZER(PTHREAD_MUTEX_ERRORCHECK_NP);
pub const PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP: crate::pthread_mutex_t =
__PTHREAD_MUTEX_INITIALIZER(PTHREAD_MUTEX_ADAPTIVE_NP);
pub use crate::new::common::linux_like::pthread::{
pthread_getaffinity_np,
pthread_getattr_np,
pthread_getname_np,
pthread_setaffinity_np,
pthread_setname_np,
};
pub use crate::new::common::posix::pthread::{
pthread_atfork,
pthread_attr_getguardsize,
pthread_attr_getinheritsched,
pthread_attr_getschedparam,
pthread_attr_getschedpolicy,
pthread_attr_getstack,
pthread_attr_setguardsize,
pthread_attr_setinheritsched,
pthread_attr_setschedparam,
pthread_attr_setschedpolicy,
pthread_attr_setstack,
pthread_barrier_destroy,
pthread_barrier_init,
pthread_barrier_wait,
pthread_barrierattr_destroy,
pthread_barrierattr_getpshared,
pthread_barrierattr_init,
pthread_barrierattr_setpshared,
pthread_cancel,
pthread_condattr_getclock,
pthread_condattr_getpshared,
pthread_condattr_setclock,
pthread_condattr_setpshared,
pthread_create,
pthread_getcpuclockid,
pthread_getschedparam,
pthread_kill,
pthread_mutex_consistent,
pthread_mutex_timedlock,
pthread_mutexattr_getprotocol,
pthread_mutexattr_getpshared,
pthread_mutexattr_getrobust,
pthread_mutexattr_setprotocol,
pthread_mutexattr_setpshared,
pthread_mutexattr_setrobust,
pthread_once,
pthread_rwlockattr_getpshared,
pthread_rwlockattr_setpshared,
pthread_setschedparam,
pthread_setschedprio,
pthread_sigmask,
pthread_spin_destroy,
pthread_spin_init,
pthread_spin_lock,
pthread_spin_trylock,
pthread_spin_unlock,
};
+6
View File
@@ -0,0 +1,6 @@
//! Directory: `sysdeps/powerpc`
#[cfg(target_os = "linux")]
pub(crate) mod nptl {
pub(crate) mod bits;
}
@@ -0,0 +1,3 @@
//! Directory: `sysdeps/powerpc/nptl/bits`
pub(crate) mod struct_mutex;
@@ -0,0 +1,19 @@
//! Header: `sysdeps/powerpc/nptl/bits/struct_mutex.h`
use crate::prelude::*;
pub const fn __PTHREAD_MUTEX_INITIALIZER(__kind: c_int) -> crate::pthread_mutex_t {
// We don't need the whole complicated `__pthread_mutex_s` definition, just use the
// offset of the `__kind` field.
let kind_offset = if cfg!(target_pointer_width = "64") {
4 * size_of::<c_int>()
} else {
3 * size_of::<c_int>()
};
let size = [0; crate::__SIZEOF_PTHREAD_MUTEX_T];
let kind_bytes = __kind.to_ne_bytes();
let repl = u8_slice_cast_char_slice(&kind_bytes);
let size = replace_array_items(size, repl, kind_offset);
crate::pthread_mutex_t { size }
}
+6
View File
@@ -0,0 +1,6 @@
//! Directory: `sysdeps/s390`
#[cfg(target_os = "linux")]
pub(crate) mod nptl {
pub(crate) mod bits;
}
@@ -0,0 +1,3 @@
//! Directory: `sysdeps/s390/nptl/bits`
pub(crate) mod struct_mutex;
@@ -0,0 +1,19 @@
//! Header: `sysdeps/s390/nptl/bits/struct_mutex.h`
use crate::prelude::*;
pub const fn __PTHREAD_MUTEX_INITIALIZER(__kind: c_int) -> crate::pthread_mutex_t {
// We don't need the whole complicated `__pthread_mutex_s` definition, just use the
// offset of the `__kind` field.
let kind_offset = if cfg!(target_pointer_width = "64") {
4 * size_of::<c_int>()
} else {
3 * size_of::<c_int>()
};
let size = [0; crate::__SIZEOF_PTHREAD_MUTEX_T];
let kind_bytes = __kind.to_ne_bytes();
let repl = u8_slice_cast_char_slice(&kind_bytes);
let size = replace_array_items(size, repl, kind_offset);
crate::pthread_mutex_t { size }
}
+10
View File
@@ -0,0 +1,10 @@
//! Source directory: `sysdeps/unix/sysv/linux` (the `sysv` is flattened).
//!
//! <https://github.com/bminor/glibc/tree/master/sysdeps/unix/sysv/linux>
/// Directory: `net/`
///
/// Source directory: `sysdeps/unix/sysv/linux/net`
pub(crate) mod net {
pub(crate) mod route;
}
@@ -0,0 +1,30 @@
//! Header: `net/route.h`
//!
//! Source header: `sysdeps/unix/sysv/linux/net/route.h`
//! <https://github.com/bminor/glibc/blob/master/sysdeps/unix/sysv/linux/net/route.h>
use crate::prelude::*;
s! {
pub struct rtentry {
pub rt_pad1: c_ulong,
pub rt_dst: crate::sockaddr,
pub rt_gateway: crate::sockaddr,
pub rt_genmask: crate::sockaddr,
pub rt_flags: c_ushort,
pub rt_pad2: c_short,
pub rt_pad3: c_ulong,
pub rt_tos: c_uchar,
pub rt_class: c_uchar,
// FIXME(1.0): private padding fields
#[cfg(target_pointer_width = "64")]
pub rt_pad4: [c_short; 3usize],
#[cfg(not(target_pointer_width = "64"))]
pub rt_pad4: c_short,
pub rt_metric: c_short,
pub rt_dev: *mut c_char,
pub rt_mtu: c_ulong,
pub rt_window: c_ulong,
pub rt_irtt: c_ushort,
}
}
+6
View File
@@ -0,0 +1,6 @@
//! Source directory: `sysdeps/unix/`
//!
//! <https://github.com/bminor/glibc/tree/master/sysdeps/unix>
#[cfg(target_os = "linux")]
pub(crate) mod linux;
+6
View File
@@ -0,0 +1,6 @@
//! Directory: `sysdeps/x86`
#[cfg(target_os = "linux")]
pub(crate) mod nptl {
pub(crate) mod bits;
}
@@ -0,0 +1,3 @@
//! Directory: `sysdeps/x86/nptl/bits`
pub(crate) mod struct_mutex;
Loaded 100 of 1714 files, more files were not shown because too many files have changed in this diff. Show more