From ea934cfa4c82d4445d5527f246acf2dd8186f8fa Mon Sep 17 00:00:00 2001 From: lhw Date: Mon, 25 Nov 2024 13:42:51 +0800 Subject: [PATCH] add unixsocket without real inode --- Cargo.lock | 22 +- api/arceos_posix_api/src/ctypes_gen.rs | 3458 ++++++++++++++++++++++++ api/ruxos_posix_api/ctypes.h | 1 + api/ruxos_posix_api/src/imp/net.rs | 188 +- crates/axfs_devfs/src/dir.rs | 14 +- crates/axfs_ramfs/src/dir.rs | 16 +- crates/axfs_ramfs/src/file.rs | 16 +- crates/axfs_vfs/Cargo.toml | 2 + crates/axfs_vfs/src/structs.rs | 23 +- modules/rux9p/src/drv.rs | 9 +- modules/rux9p/src/fs.rs | 2 + modules/ruxfs/Cargo.toml | 1 + modules/ruxfs/src/api/file.rs | 2 +- modules/ruxfs/src/fs/fatfs.rs | 19 +- modules/ruxfs/src/lib.rs | 2 +- modules/ruxfs/src/root.rs | 13 +- modules/ruxnet/Cargo.toml | 5 + modules/ruxnet/src/lib.rs | 4 + modules/ruxnet/src/smoltcp_impl/tcp.rs | 2 +- modules/ruxnet/src/unix.rs | 702 +++++ 20 files changed, 4419 insertions(+), 82 deletions(-) create mode 100644 api/arceos_posix_api/src/ctypes_gen.rs create mode 100644 modules/ruxnet/src/unix.rs diff --git a/Cargo.lock b/Cargo.lock index 905076383..cda8aca43 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -47,6 +47,12 @@ dependencies = [ "slab_allocator", ] +[[package]] +name = "allocator-api2" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" + [[package]] name = "android-tzdata" version = "0.1.1" @@ -174,7 +180,9 @@ version = "0.1.0" dependencies = [ "axerrno", "bitflags 2.4.0", + "lazy_static", "log", + "spin 0.9.8", ] [[package]] @@ -888,9 +896,13 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.0" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", + "allocator-api2", +] [[package]] name = "heapless" @@ -1654,6 +1666,7 @@ dependencies = [ "memory_addr", "ruxdriver", "ruxtask", + "spin 0.9.8", ] [[package]] @@ -1737,17 +1750,22 @@ name = "ruxnet" version = "0.1.0" dependencies = [ "axerrno", + "axfs_vfs", "axio", "axlog", "axsync", "cfg-if", "cty", "driver_net", + "flatten_objects", + "hashbrown", "lazy_init", + "lazy_static", "log", "lwip_rust", "printf-compat", "ruxdriver", + "ruxfs", "ruxhal", "ruxtask", "smoltcp", diff --git a/api/arceos_posix_api/src/ctypes_gen.rs b/api/arceos_posix_api/src/ctypes_gen.rs new file mode 100644 index 000000000..9b2b3f2fd --- /dev/null +++ b/api/arceos_posix_api/src/ctypes_gen.rs @@ -0,0 +1,3458 @@ +/* automatically generated by rust-bindgen 0.66.1 */ + +#[repr(C)] +#[derive(Default)] +pub struct __IncompleteArrayField(::core::marker::PhantomData, [T; 0]); +impl __IncompleteArrayField { + #[inline] + pub const fn new() -> Self { + __IncompleteArrayField(::core::marker::PhantomData, []) + } + #[inline] + pub fn as_ptr(&self) -> *const T { + self as *const _ as *const T + } + #[inline] + pub fn as_mut_ptr(&mut self) -> *mut T { + self as *mut _ as *mut T + } + #[inline] + pub unsafe fn as_slice(&self, len: usize) -> &[T] { + ::core::slice::from_raw_parts(self.as_ptr(), len) + } + #[inline] + pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { + ::core::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + } +} +impl ::core::fmt::Debug for __IncompleteArrayField { + fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + fmt.write_str("__IncompleteArrayField") + } +} +pub const EINVAL: u32 = 22; +pub const O_CREAT: u32 = 64; +pub const O_EXCL: u32 = 128; +pub const O_NOCTTY: u32 = 256; +pub const O_TRUNC: u32 = 512; +pub const O_APPEND: u32 = 1024; +pub const O_NONBLOCK: u32 = 2048; +pub const O_DSYNC: u32 = 4096; +pub const O_SYNC: u32 = 1052672; +pub const O_RSYNC: u32 = 1052672; +pub const O_DIRECTORY: u32 = 65536; +pub const O_NOFOLLOW: u32 = 131072; +pub const O_CLOEXEC: u32 = 524288; +pub const O_ASYNC: u32 = 8192; +pub const O_DIRECT: u32 = 16384; +pub const O_LARGEFILE: u32 = 32768; +pub const O_NOATIME: u32 = 262144; +pub const O_PATH: u32 = 2097152; +pub const O_TMPFILE: u32 = 4259840; +pub const O_NDELAY: u32 = 2048; +pub const O_SEARCH: u32 = 2097152; +pub const O_EXEC: u32 = 2097152; +pub const O_TTY_INIT: u32 = 0; +pub const O_ACCMODE: u32 = 2097155; +pub const O_RDONLY: u32 = 0; +pub const O_WRONLY: u32 = 1; +pub const O_RDWR: u32 = 2; +pub const F_DUPFD: u32 = 0; +pub const F_GETFD: u32 = 1; +pub const F_SETFD: u32 = 2; +pub const F_GETFL: u32 = 3; +pub const F_SETFL: u32 = 4; +pub const F_SETOWN: u32 = 8; +pub const F_GETOWN: u32 = 9; +pub const F_SETSIG: u32 = 10; +pub const F_GETSIG: u32 = 11; +pub const F_GETLK: u32 = 5; +pub const F_SETLK: u32 = 6; +pub const F_SETLKW: u32 = 7; +pub const FD_CLOEXEC: u32 = 1; +pub const F_DUPFD_CLOEXEC: u32 = 1030; +pub const F_RDLCK: u32 = 0; +pub const F_WRLCK: u32 = 1; +pub const F_UNLCK: u32 = 2; +pub const F_OK: u32 = 0; +pub const F_ULOCK: u32 = 0; +pub const F_LOCK: u32 = 1; +pub const F_TLOCK: u32 = 2; +pub const F_TEST: u32 = 3; +pub const AT_FDCWD: i32 = -100; +pub const AT_EMPTY_PATH: u32 = 4096; +pub const AT_REMOVEDIR: u32 = 512; +pub const SOCK_STREAM: u32 = 1; +pub const SOCK_DGRAM: u32 = 2; +pub const SOCK_RAW: u32 = 3; +pub const SOCK_RDM: u32 = 4; +pub const SOCK_SEQPACKET: u32 = 5; +pub const SOCK_DCCP: u32 = 6; +pub const SOCK_PACKET: u32 = 10; +pub const SOCK_CLOEXEC: u32 = 524288; +pub const SOCK_NONBLOCK: u32 = 2048; +pub const AF_UNSPEC: u32 = 0; +pub const AF_LOCAL: u32 = 1; +pub const AF_UNIX: u32 = 1; +pub const AF_FILE: u32 = 1; +pub const AF_INET: u32 = 2; +pub const AF_AX25: u32 = 3; +pub const AF_IPX: u32 = 4; +pub const AF_APPLETALK: u32 = 5; +pub const AF_NETROM: u32 = 6; +pub const AF_BRIDGE: u32 = 7; +pub const AF_ATMPVC: u32 = 8; +pub const AF_X25: u32 = 9; +pub const AF_INET6: u32 = 10; +pub const AF_ROSE: u32 = 11; +pub const AF_DECnet: u32 = 12; +pub const AF_NETBEUI: u32 = 13; +pub const AF_SECURITY: u32 = 14; +pub const AF_KEY: u32 = 15; +pub const AF_NETLINK: u32 = 16; +pub const AF_ROUTE: u32 = 16; +pub const AF_PACKET: u32 = 17; +pub const AF_ASH: u32 = 18; +pub const AF_ECONET: u32 = 19; +pub const AF_ATMSVC: u32 = 20; +pub const AF_RDS: u32 = 21; +pub const AF_SNA: u32 = 22; +pub const AF_IRDA: u32 = 23; +pub const AF_PPPOX: u32 = 24; +pub const AF_WANPIPE: u32 = 25; +pub const AF_LLC: u32 = 26; +pub const AF_IB: u32 = 27; +pub const AF_MPLS: u32 = 28; +pub const AF_CAN: u32 = 29; +pub const AF_TIPC: u32 = 30; +pub const AF_BLUETOOTH: u32 = 31; +pub const AF_IUCV: u32 = 32; +pub const AF_RXRPC: u32 = 33; +pub const AF_ISDN: u32 = 34; +pub const AF_PHONET: u32 = 35; +pub const AF_IEEE802154: u32 = 36; +pub const AF_CAIF: u32 = 37; +pub const AF_ALG: u32 = 38; +pub const AF_NFC: u32 = 39; +pub const AF_VSOCK: u32 = 40; +pub const AF_KCM: u32 = 41; +pub const AF_QIPCRTR: u32 = 42; +pub const AF_SMC: u32 = 43; +pub const AF_XDP: u32 = 44; +pub const AF_MAX: u32 = 45; +pub const IPPROTO_IP: u32 = 0; +pub const IPPROTO_HOPOPTS: u32 = 0; +pub const IPPROTO_ICMP: u32 = 1; +pub const IPPROTO_IGMP: u32 = 2; +pub const IPPROTO_IPIP: u32 = 4; +pub const IPPROTO_TCP: u32 = 6; +pub const IPPROTO_EGP: u32 = 8; +pub const IPPROTO_PUP: u32 = 12; +pub const IPPROTO_UDP: u32 = 17; +pub const IPPROTO_IDP: u32 = 22; +pub const IPPROTO_TP: u32 = 29; +pub const IPPROTO_DCCP: u32 = 33; +pub const IPPROTO_IPV6: u32 = 41; +pub const IPPROTO_ROUTING: u32 = 43; +pub const IPPROTO_FRAGMENT: u32 = 44; +pub const IPPROTO_RSVP: u32 = 46; +pub const IPPROTO_GRE: u32 = 47; +pub const IPPROTO_ESP: u32 = 50; +pub const IPPROTO_AH: u32 = 51; +pub const IPPROTO_ICMPV6: u32 = 58; +pub const IPPROTO_NONE: u32 = 59; +pub const IPPROTO_DSTOPTS: u32 = 60; +pub const IPPROTO_MTP: u32 = 92; +pub const IPPROTO_BEETPH: u32 = 94; +pub const IPPROTO_ENCAP: u32 = 98; +pub const IPPROTO_PIM: u32 = 103; +pub const IPPROTO_COMP: u32 = 108; +pub const IPPROTO_SCTP: u32 = 132; +pub const IPPROTO_MH: u32 = 135; +pub const IPPROTO_UDPLITE: u32 = 136; +pub const IPPROTO_MPLS: u32 = 137; +pub const IPPROTO_ETHERNET: u32 = 143; +pub const IPPROTO_RAW: u32 = 255; +pub const IPPROTO_MPTCP: u32 = 262; +pub const IPPROTO_MAX: u32 = 263; +pub const EAI_BADFLAGS: i32 = -1; +pub const EAI_NONAME: i32 = -2; +pub const EAI_AGAIN: i32 = -3; +pub const EAI_FAIL: i32 = -4; +pub const EAI_FAMILY: i32 = -6; +pub const EAI_SOCKTYPE: i32 = -7; +pub const EAI_SERVICE: i32 = -8; +pub const EAI_MEMORY: i32 = -10; +pub const EAI_SYSTEM: i32 = -11; +pub const EAI_OVERFLOW: i32 = -12; +pub const MAXADDRS: u32 = 48; +pub const ITIMER_REAL: u32 = 0; +pub const ITIMER_VIRTUAL: u32 = 1; +pub const ITIMER_PROF: u32 = 2; +pub const SIGCANCEL: u32 = 33; +pub const CLONE_NEWTIME: u32 = 128; +pub const CLONE_VM: u32 = 256; +pub const CLONE_FS: u32 = 512; +pub const CLONE_FILES: u32 = 1024; +pub const CLONE_SIGHAND: u32 = 2048; +pub const CLONE_PIDFD: u32 = 4096; +pub const CLONE_PTRACE: u32 = 8192; +pub const CLONE_VFORK: u32 = 16384; +pub const CLONE_PARENT: u32 = 32768; +pub const CLONE_THREAD: u32 = 65536; +pub const CLONE_NEWNS: u32 = 131072; +pub const CLONE_SYSVSEM: u32 = 262144; +pub const CLONE_SETTLS: u32 = 524288; +pub const CLONE_PARENT_SETTID: u32 = 1048576; +pub const CLONE_CHILD_CLEARTID: u32 = 2097152; +pub const CLONE_DETACHED: u32 = 4194304; +pub const CLONE_UNTRACED: u32 = 8388608; +pub const CLONE_CHILD_SETTID: u32 = 16777216; +pub const CLONE_NEWCGROUP: u32 = 33554432; +pub const CLONE_NEWUTS: u32 = 67108864; +pub const CLONE_NEWIPC: u32 = 134217728; +pub const CLONE_NEWUSER: u32 = 268435456; +pub const CLONE_NEWPID: u32 = 536870912; +pub const CLONE_NEWNET: u32 = 1073741824; +pub const CLONE_IO: u32 = 2147483648; +pub const SIG_BLOCK: u32 = 0; +pub const SIG_UNBLOCK: u32 = 1; +pub const SIG_SETMASK: u32 = 2; +pub const SIGHUP: u32 = 1; +pub const SIGINT: u32 = 2; +pub const SIGQUIT: u32 = 3; +pub const SIGILL: u32 = 4; +pub const SIGTRAP: u32 = 5; +pub const SIGABRT: u32 = 6; +pub const SIGIOT: u32 = 6; +pub const SIGBUS: u32 = 7; +pub const SIGFPE: u32 = 8; +pub const SIGKILL: u32 = 9; +pub const SIGUSR1: u32 = 10; +pub const SIGSEGV: u32 = 11; +pub const SIGUSR2: u32 = 12; +pub const SIGPIPE: u32 = 13; +pub const SIGALRM: u32 = 14; +pub const SIGTERM: u32 = 15; +pub const SIGSTKFLT: u32 = 16; +pub const SIGCHLD: u32 = 17; +pub const SIGCONT: u32 = 18; +pub const SIGSTOP: u32 = 19; +pub const SIGTSTP: u32 = 20; +pub const SIGTTIN: u32 = 21; +pub const SIGTTOU: u32 = 22; +pub const SIGURG: u32 = 23; +pub const SIGXCPU: u32 = 24; +pub const SIGXFSZ: u32 = 25; +pub const SIGVTALRM: u32 = 26; +pub const SIGPROF: u32 = 27; +pub const SIGWINCH: u32 = 28; +pub const SIGIO: u32 = 29; +pub const SIGPOLL: u32 = 29; +pub const SIGPWR: u32 = 30; +pub const SIGSYS: u32 = 31; +pub const SIGUNUSED: u32 = 31; +pub const SIGERR: i32 = -1; +pub const SIGDFL: u32 = 0; +pub const SIGIGN: u32 = 1; +pub const EPOLL_CLOEXEC: u32 = 524288; +pub const EPOLL_NONBLOCK: u32 = 2048; +pub const EPOLLIN: u32 = 1; +pub const EPOLLPRI: u32 = 2; +pub const EPOLLOUT: u32 = 4; +pub const EPOLLRDNORM: u32 = 64; +pub const EPOLLNVAL: u32 = 32; +pub const EPOLLRDBAND: u32 = 128; +pub const EPOLLWRNORM: u32 = 256; +pub const EPOLLWRBAND: u32 = 512; +pub const EPOLLMSG: u32 = 1024; +pub const EPOLLERR: u32 = 8; +pub const EPOLLHUP: u32 = 16; +pub const EPOLLRDHUP: u32 = 8192; +pub const EPOLLEXCLUSIVE: u32 = 268435456; +pub const EPOLLWAKEUP: u32 = 536870912; +pub const EPOLLONESHOT: u32 = 1073741824; +pub const EPOLLET: u32 = 2147483648; +pub const EPOLL_CTL_ADD: u32 = 1; +pub const EPOLL_CTL_DEL: u32 = 2; +pub const EPOLL_CTL_MOD: u32 = 3; +pub const RLIMIT_CPU: u32 = 0; +pub const RLIMIT_FSIZE: u32 = 1; +pub const RLIMIT_DATA: u32 = 2; +pub const RLIMIT_STACK: u32 = 3; +pub const RLIMIT_CORE: u32 = 4; +pub const RLIMIT_RSS: u32 = 5; +pub const RLIMIT_NPROC: u32 = 6; +pub const RLIMIT_NOFILE: u32 = 7; +pub const RLIMIT_MEMLOCK: u32 = 8; +pub const RLIMIT_AS: u32 = 9; +pub const RLIMIT_LOCKS: u32 = 10; +pub const RLIMIT_SIGPENDING: u32 = 11; +pub const RLIMIT_MSGQUEUE: u32 = 12; +pub const RLIMIT_NICE: u32 = 13; +pub const RLIMIT_RTPRIO: u32 = 14; +pub const RLIMIT_RTTIME: u32 = 15; +pub const RLIMIT_NLIMITS: u32 = 16; +pub const FD_SETSIZE: u32 = 1024; +pub const _SC_ARG_MAX: u32 = 0; +pub const _SC_CHILD_MAX: u32 = 1; +pub const _SC_CLK_TCK: u32 = 2; +pub const _SC_NGROUPS_MAX: u32 = 3; +pub const _SC_OPEN_MAX: u32 = 4; +pub const _SC_STREAM_MAX: u32 = 5; +pub const _SC_TZNAME_MAX: u32 = 6; +pub const _SC_JOB_CONTROL: u32 = 7; +pub const _SC_SAVED_IDS: u32 = 8; +pub const _SC_REALTIME_SIGNALS: u32 = 9; +pub const _SC_PRIORITY_SCHEDULING: u32 = 10; +pub const _SC_TIMERS: u32 = 11; +pub const _SC_ASYNCHRONOUS_IO: u32 = 12; +pub const _SC_PRIORITIZED_IO: u32 = 13; +pub const _SC_SYNCHRONIZED_IO: u32 = 14; +pub const _SC_FSYNC: u32 = 15; +pub const _SC_MAPPED_FILES: u32 = 16; +pub const _SC_MEMLOCK: u32 = 17; +pub const _SC_MEMLOCK_RANGE: u32 = 18; +pub const _SC_MEMORY_PROTECTION: u32 = 19; +pub const _SC_MESSAGE_PASSING: u32 = 20; +pub const _SC_SEMAPHORES: u32 = 21; +pub const _SC_SHARED_MEMORY_OBJECTS: u32 = 22; +pub const _SC_AIO_LISTIO_MAX: u32 = 23; +pub const _SC_AIO_MAX: u32 = 24; +pub const _SC_AIO_PRIO_DELTA_MAX: u32 = 25; +pub const _SC_DELAYTIMER_MAX: u32 = 26; +pub const _SC_MQ_OPEN_MAX: u32 = 27; +pub const _SC_MQ_PRIO_MAX: u32 = 28; +pub const _SC_VERSION: u32 = 29; +pub const _SC_PAGE_SIZE: u32 = 30; +pub const _SC_PAGESIZE: u32 = 30; +pub const _SC_RTSIG_MAX: u32 = 31; +pub const _SC_SEM_NSEMS_MAX: u32 = 32; +pub const _SC_SEM_VALUE_MAX: u32 = 33; +pub const _SC_SIGQUEUE_MAX: u32 = 34; +pub const _SC_TIMER_MAX: u32 = 35; +pub const _SC_BC_BASE_MAX: u32 = 36; +pub const _SC_BC_DIM_MAX: u32 = 37; +pub const _SC_BC_SCALE_MAX: u32 = 38; +pub const _SC_BC_STRING_MAX: u32 = 39; +pub const _SC_COLL_WEIGHTS_MAX: u32 = 40; +pub const _SC_EXPR_NEST_MAX: u32 = 42; +pub const _SC_LINE_MAX: u32 = 43; +pub const _SC_RE_DUP_MAX: u32 = 44; +pub const _SC_2_VERSION: u32 = 46; +pub const _SC_2_C_BIND: u32 = 47; +pub const _SC_2_C_DEV: u32 = 48; +pub const _SC_2_FORT_DEV: u32 = 49; +pub const _SC_2_FORT_RUN: u32 = 50; +pub const _SC_2_SW_DEV: u32 = 51; +pub const _SC_2_LOCALEDEF: u32 = 52; +pub const _SC_UIO_MAXIOV: u32 = 60; +pub const _SC_IOV_MAX: u32 = 60; +pub const _SC_THREADS: u32 = 67; +pub const _SC_THREAD_SAFE_FUNCTIONS: u32 = 68; +pub const _SC_GETGR_R_SIZE_MAX: u32 = 69; +pub const _SC_GETPW_R_SIZE_MAX: u32 = 70; +pub const _SC_LOGIN_NAME_MAX: u32 = 71; +pub const _SC_TTY_NAME_MAX: u32 = 72; +pub const _SC_THREAD_DESTRUCTOR_ITERATIONS: u32 = 73; +pub const _SC_THREAD_KEYS_MAX: u32 = 74; +pub const _SC_THREAD_STACK_MIN: u32 = 75; +pub const _SC_THREAD_THREADS_MAX: u32 = 76; +pub const _SC_THREAD_ATTR_STACKADDR: u32 = 77; +pub const _SC_THREAD_ATTR_STACKSIZE: u32 = 78; +pub const _SC_THREAD_PRIORITY_SCHEDULING: u32 = 79; +pub const _SC_THREAD_PRIO_INHERIT: u32 = 80; +pub const _SC_THREAD_PRIO_PROTECT: u32 = 81; +pub const _SC_THREAD_PROCESS_SHARED: u32 = 82; +pub const _SC_NPROCESSORS_CONF: u32 = 83; +pub const _SC_NPROCESSORS_ONLN: u32 = 84; +pub const _SC_PHYS_PAGES: u32 = 85; +pub const _SC_AVPHYS_PAGES: u32 = 86; +pub const _SC_ATEXIT_MAX: u32 = 87; +pub const _SC_PASS_MAX: u32 = 88; +pub const _SC_XOPEN_VERSION: u32 = 89; +pub const _SC_XOPEN_XCU_VERSION: u32 = 90; +pub const _SC_XOPEN_UNIX: u32 = 91; +pub const _SC_XOPEN_CRYPT: u32 = 92; +pub const _SC_XOPEN_ENH_I18N: u32 = 93; +pub const _SC_XOPEN_SHM: u32 = 94; +pub const _SC_2_CHAR_TERM: u32 = 95; +pub const _SC_2_UPE: u32 = 97; +pub const _SC_XOPEN_XPG2: u32 = 98; +pub const _SC_XOPEN_XPG3: u32 = 99; +pub const _SC_XOPEN_XPG4: u32 = 100; +pub const _SC_NZERO: u32 = 109; +pub const _SC_XBS5_ILP32_OFF32: u32 = 125; +pub const _SC_XBS5_ILP32_OFFBIG: u32 = 126; +pub const _SC_XBS5_LP64_OFF64: u32 = 127; +pub const _SC_XBS5_LPBIG_OFFBIG: u32 = 128; +pub const _SC_XOPEN_LEGACY: u32 = 129; +pub const _SC_XOPEN_REALTIME: u32 = 130; +pub const _SC_XOPEN_REALTIME_THREADS: u32 = 131; +pub const _SC_ADVISORY_INFO: u32 = 132; +pub const _SC_BARRIERS: u32 = 133; +pub const _SC_CLOCK_SELECTION: u32 = 137; +pub const _SC_CPUTIME: u32 = 138; +pub const _SC_THREAD_CPUTIME: u32 = 139; +pub const _SC_MONOTONIC_CLOCK: u32 = 149; +pub const _SC_READER_WRITER_LOCKS: u32 = 153; +pub const _SC_SPIN_LOCKS: u32 = 154; +pub const _SC_REGEXP: u32 = 155; +pub const _SC_SHELL: u32 = 157; +pub const _SC_SPAWN: u32 = 159; +pub const _SC_SPORADIC_SERVER: u32 = 160; +pub const _SC_THREAD_SPORADIC_SERVER: u32 = 161; +pub const _SC_TIMEOUTS: u32 = 164; +pub const _SC_TYPED_MEMORY_OBJECTS: u32 = 165; +pub const _SC_2_PBS: u32 = 168; +pub const _SC_2_PBS_ACCOUNTING: u32 = 169; +pub const _SC_2_PBS_LOCATE: u32 = 170; +pub const _SC_2_PBS_MESSAGE: u32 = 171; +pub const _SC_2_PBS_TRACK: u32 = 172; +pub const _SC_SYMLOOP_MAX: u32 = 173; +pub const _SC_STREAMS: u32 = 174; +pub const _SC_2_PBS_CHECKPOINT: u32 = 175; +pub const _SC_V6_ILP32_OFF32: u32 = 176; +pub const _SC_V6_ILP32_OFFBIG: u32 = 177; +pub const _SC_V6_LP64_OFF64: u32 = 178; +pub const _SC_V6_LPBIG_OFFBIG: u32 = 179; +pub const _SC_HOST_NAME_MAX: u32 = 180; +pub const _SC_TRACE: u32 = 181; +pub const _SC_TRACE_EVENT_FILTER: u32 = 182; +pub const _SC_TRACE_INHERIT: u32 = 183; +pub const _SC_TRACE_LOG: u32 = 184; +pub const _SC_IPV6: u32 = 235; +pub const _SC_RAW_SOCKETS: u32 = 236; +pub const _SC_V7_ILP32_OFF32: u32 = 237; +pub const _SC_V7_ILP32_OFFBIG: u32 = 238; +pub const _SC_V7_LP64_OFF64: u32 = 239; +pub const _SC_V7_LPBIG_OFFBIG: u32 = 240; +pub const _SC_SS_REPL_MAX: u32 = 241; +pub const _SC_TRACE_EVENT_NAME_MAX: u32 = 242; +pub const _SC_TRACE_NAME_MAX: u32 = 243; +pub const _SC_TRACE_SYS_MAX: u32 = 244; +pub const _SC_TRACE_USER_EVENT_MAX: u32 = 245; +pub const _SC_XOPEN_STREAMS: u32 = 246; +pub const _SC_THREAD_ROBUST_PRIO_INHERIT: u32 = 247; +pub const _SC_THREAD_ROBUST_PRIO_PROTECT: u32 = 248; +pub type size_t = usize; +pub type ssize_t = isize; +pub type clockid_t = ::core::ffi::c_int; +pub type mode_t = ::core::ffi::c_uint; +pub type nlink_t = u32; +pub type off_t = i64; +pub type ino_t = u64; +pub type dev_t = u64; +pub type blksize_t = ::core::ffi::c_long; +pub type blkcnt_t = i64; +pub type pid_t = ::core::ffi::c_int; +pub type uid_t = ::core::ffi::c_uint; +pub type gid_t = ::core::ffi::c_uint; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct k_sigaction { + pub handler: ::core::option::Option, + pub flags: ::core::ffi::c_ulong, + pub restorer: ::core::option::Option, + pub mask: [::core::ffi::c_uint; 2usize], +} +#[test] +fn bindgen_test_layout_k_sigaction() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 32usize, + concat!("Size of: ", stringify!(k_sigaction)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(k_sigaction)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).handler) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(k_sigaction), + "::", + stringify!(handler) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).flags) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(k_sigaction), + "::", + stringify!(flags) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).restorer) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(k_sigaction), + "::", + stringify!(restorer) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(k_sigaction), + "::", + stringify!(mask) + ) + ); +} +pub type socklen_t = ::core::ffi::c_uint; +pub type sa_family_t = ::core::ffi::c_ushort; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct msghdr { + pub msg_name: *mut ::core::ffi::c_void, + pub msg_namelen: socklen_t, + pub msg_iov: *mut iovec, + pub msg_iovlen: ::core::ffi::c_int, + pub __pad1: ::core::ffi::c_int, + pub msg_control: *mut ::core::ffi::c_void, + pub msg_controllen: socklen_t, + pub __pad2: ::core::ffi::c_int, + pub msg_flags: ::core::ffi::c_int, +} +#[test] +fn bindgen_test_layout_msghdr() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 56usize, + concat!("Size of: ", stringify!(msghdr)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(msghdr)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).msg_name) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(msghdr), + "::", + stringify!(msg_name) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).msg_namelen) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(msghdr), + "::", + stringify!(msg_namelen) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).msg_iov) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(msghdr), + "::", + stringify!(msg_iov) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).msg_iovlen) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(msghdr), + "::", + stringify!(msg_iovlen) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__pad1) as usize - ptr as usize }, + 28usize, + concat!( + "Offset of field: ", + stringify!(msghdr), + "::", + stringify!(__pad1) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).msg_control) as usize - ptr as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(msghdr), + "::", + stringify!(msg_control) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).msg_controllen) as usize - ptr as usize }, + 40usize, + concat!( + "Offset of field: ", + stringify!(msghdr), + "::", + stringify!(msg_controllen) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__pad2) as usize - ptr as usize }, + 44usize, + concat!( + "Offset of field: ", + stringify!(msghdr), + "::", + stringify!(__pad2) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).msg_flags) as usize - ptr as usize }, + 48usize, + concat!( + "Offset of field: ", + stringify!(msghdr), + "::", + stringify!(msg_flags) + ) + ); +} +impl Default for msghdr { + fn default() -> Self { + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct sockaddr { + pub sa_family: sa_family_t, + pub sa_data: [::core::ffi::c_char; 14usize], +} +#[test] +fn bindgen_test_layout_sockaddr() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(sockaddr)) + ); + assert_eq!( + ::core::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(sockaddr)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sa_family) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(sockaddr), + "::", + stringify!(sa_family) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sa_data) as usize - ptr as usize }, + 2usize, + concat!( + "Offset of field: ", + stringify!(sockaddr), + "::", + stringify!(sa_data) + ) + ); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sockaddr_storage { + pub ss_family: sa_family_t, + pub __ss_padding: [::core::ffi::c_char; 118usize], + pub __ss_align: ::core::ffi::c_ulong, +} +#[test] +fn bindgen_test_layout_sockaddr_storage() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 128usize, + concat!("Size of: ", stringify!(sockaddr_storage)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(sockaddr_storage)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).ss_family) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(sockaddr_storage), + "::", + stringify!(ss_family) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__ss_padding) as usize - ptr as usize }, + 2usize, + concat!( + "Offset of field: ", + stringify!(sockaddr_storage), + "::", + stringify!(__ss_padding) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__ss_align) as usize - ptr as usize }, + 120usize, + concat!( + "Offset of field: ", + stringify!(sockaddr_storage), + "::", + stringify!(__ss_align) + ) + ); +} +impl Default for sockaddr_storage { + fn default() -> Self { + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +pub type in_port_t = u16; +pub type in_addr_t = u32; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct in_addr { + pub s_addr: in_addr_t, +} +#[test] +fn bindgen_test_layout_in_addr() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(in_addr)) + ); + assert_eq!( + ::core::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(in_addr)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).s_addr) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(in_addr), + "::", + stringify!(s_addr) + ) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct sockaddr_in { + pub sin_family: sa_family_t, + pub sin_port: in_port_t, + pub sin_addr: in_addr, + pub sin_zero: [u8; 8usize], +} +#[test] +fn bindgen_test_layout_sockaddr_in() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(sockaddr_in)) + ); + assert_eq!( + ::core::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(sockaddr_in)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sin_family) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(sockaddr_in), + "::", + stringify!(sin_family) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sin_port) as usize - ptr as usize }, + 2usize, + concat!( + "Offset of field: ", + stringify!(sockaddr_in), + "::", + stringify!(sin_port) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sin_addr) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(sockaddr_in), + "::", + stringify!(sin_addr) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sin_zero) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(sockaddr_in), + "::", + stringify!(sin_zero) + ) + ); +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct in6_addr { + pub __in6_union: in6_addr__bindgen_ty_1, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union in6_addr__bindgen_ty_1 { + pub __s6_addr: [u8; 16usize], + pub __s6_addr16: [u16; 8usize], + pub __s6_addr32: [u32; 4usize], +} +#[test] +fn bindgen_test_layout_in6_addr__bindgen_ty_1() { + const UNINIT: ::core::mem::MaybeUninit = + ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(in6_addr__bindgen_ty_1)) + ); + assert_eq!( + ::core::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(in6_addr__bindgen_ty_1)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__s6_addr) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(in6_addr__bindgen_ty_1), + "::", + stringify!(__s6_addr) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__s6_addr16) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(in6_addr__bindgen_ty_1), + "::", + stringify!(__s6_addr16) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__s6_addr32) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(in6_addr__bindgen_ty_1), + "::", + stringify!(__s6_addr32) + ) + ); +} +impl Default for in6_addr__bindgen_ty_1 { + fn default() -> Self { + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[test] +fn bindgen_test_layout_in6_addr() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(in6_addr)) + ); + assert_eq!( + ::core::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(in6_addr)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__in6_union) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(in6_addr), + "::", + stringify!(__in6_union) + ) + ); +} +impl Default for in6_addr { + fn default() -> Self { + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct sockaddr_in6 { + 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, +} +#[test] +fn bindgen_test_layout_sockaddr_in6() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 28usize, + concat!("Size of: ", stringify!(sockaddr_in6)) + ); + assert_eq!( + ::core::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(sockaddr_in6)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sin6_family) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(sockaddr_in6), + "::", + stringify!(sin6_family) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sin6_port) as usize - ptr as usize }, + 2usize, + concat!( + "Offset of field: ", + stringify!(sockaddr_in6), + "::", + stringify!(sin6_port) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sin6_flowinfo) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(sockaddr_in6), + "::", + stringify!(sin6_flowinfo) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sin6_addr) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(sockaddr_in6), + "::", + stringify!(sin6_addr) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sin6_scope_id) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(sockaddr_in6), + "::", + stringify!(sin6_scope_id) + ) + ); +} +impl Default for sockaddr_in6 { + fn default() -> Self { + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct addrinfo { + pub ai_flags: ::core::ffi::c_int, + pub ai_family: ::core::ffi::c_int, + pub ai_socktype: ::core::ffi::c_int, + pub ai_protocol: ::core::ffi::c_int, + pub ai_addrlen: socklen_t, + pub ai_addr: *mut sockaddr, + pub ai_canonname: *mut ::core::ffi::c_char, + pub ai_next: *mut addrinfo, +} +#[test] +fn bindgen_test_layout_addrinfo() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 48usize, + concat!("Size of: ", stringify!(addrinfo)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(addrinfo)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).ai_flags) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(addrinfo), + "::", + stringify!(ai_flags) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).ai_family) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(addrinfo), + "::", + stringify!(ai_family) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).ai_socktype) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(addrinfo), + "::", + stringify!(ai_socktype) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).ai_protocol) as usize - ptr as usize }, + 12usize, + concat!( + "Offset of field: ", + stringify!(addrinfo), + "::", + stringify!(ai_protocol) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).ai_addrlen) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(addrinfo), + "::", + stringify!(ai_addrlen) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).ai_addr) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(addrinfo), + "::", + stringify!(ai_addr) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).ai_canonname) as usize - ptr as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(addrinfo), + "::", + stringify!(ai_canonname) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).ai_next) as usize - ptr as usize }, + 40usize, + concat!( + "Offset of field: ", + stringify!(addrinfo), + "::", + stringify!(ai_next) + ) + ); +} +impl Default for addrinfo { + fn default() -> Self { + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct aibuf { + pub ai: addrinfo, + pub sa: aibuf_sa, + pub lock: [::core::ffi::c_int; 1usize], + pub slot: ::core::ffi::c_short, + pub ref_: ::core::ffi::c_short, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union aibuf_sa { + pub sin: sockaddr_in, + pub sin6: sockaddr_in6, +} +#[test] +fn bindgen_test_layout_aibuf_sa() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 28usize, + concat!("Size of: ", stringify!(aibuf_sa)) + ); + assert_eq!( + ::core::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(aibuf_sa)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sin) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(aibuf_sa), + "::", + stringify!(sin) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sin6) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(aibuf_sa), + "::", + stringify!(sin6) + ) + ); +} +impl Default for aibuf_sa { + fn default() -> Self { + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[test] +fn bindgen_test_layout_aibuf() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 88usize, + concat!("Size of: ", stringify!(aibuf)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(aibuf)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).ai) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(aibuf), "::", stringify!(ai)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sa) as usize - ptr as usize }, + 48usize, + concat!("Offset of field: ", stringify!(aibuf), "::", stringify!(sa)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).lock) as usize - ptr as usize }, + 76usize, + concat!( + "Offset of field: ", + stringify!(aibuf), + "::", + stringify!(lock) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).slot) as usize - ptr as usize }, + 80usize, + concat!( + "Offset of field: ", + stringify!(aibuf), + "::", + stringify!(slot) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).ref_) as usize - ptr as usize }, + 82usize, + concat!( + "Offset of field: ", + stringify!(aibuf), + "::", + stringify!(ref_) + ) + ); +} +impl Default for aibuf { + fn default() -> Self { + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct pollfd { + pub fd: ::core::ffi::c_int, + pub events: ::core::ffi::c_short, + pub revents: ::core::ffi::c_short, +} +#[test] +fn bindgen_test_layout_pollfd() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(pollfd)) + ); + assert_eq!( + ::core::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(pollfd)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).fd) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pollfd), + "::", + stringify!(fd) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).events) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(pollfd), + "::", + stringify!(events) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).revents) as usize - ptr as usize }, + 6usize, + concat!( + "Offset of field: ", + stringify!(pollfd), + "::", + stringify!(revents) + ) + ); +} +pub type nfds_t = ::core::ffi::c_ulong; +pub type time_t = ::core::ffi::c_longlong; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct timeval { + pub tv_sec: time_t, + pub tv_usec: ::core::ffi::c_long, +} +#[test] +fn bindgen_test_layout_timeval() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(timeval)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(timeval)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).tv_sec) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(timeval), + "::", + stringify!(tv_sec) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).tv_usec) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(timeval), + "::", + stringify!(tv_usec) + ) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct timespec { + pub tv_sec: time_t, + pub tv_nsec: ::core::ffi::c_long, +} +#[test] +fn bindgen_test_layout_timespec() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(timespec)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(timespec)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).tv_sec) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(timespec), + "::", + stringify!(tv_sec) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).tv_nsec) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(timespec), + "::", + stringify!(tv_nsec) + ) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct itimerval { + pub it_interval: timeval, + pub it_value: timeval, +} +#[test] +fn bindgen_test_layout_itimerval() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 32usize, + concat!("Size of: ", stringify!(itimerval)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(itimerval)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).it_interval) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(itimerval), + "::", + stringify!(it_interval) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).it_value) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(itimerval), + "::", + stringify!(it_value) + ) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct pthread_condattr_t { + pub __attr: ::core::ffi::c_uint, +} +#[test] +fn bindgen_test_layout_pthread_condattr_t() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(pthread_condattr_t)) + ); + assert_eq!( + ::core::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(pthread_condattr_t)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__attr) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_condattr_t), + "::", + stringify!(__attr) + ) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct pthread_cond_t { + pub __l: [::core::ffi::c_long; 1usize], +} +#[test] +fn bindgen_test_layout_pthread_cond_t() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(pthread_cond_t)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(pthread_cond_t)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__l) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_cond_t), + "::", + stringify!(__l) + ) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct pthread_mutex_t { + pub __l: [::core::ffi::c_long; 1usize], +} +#[test] +fn bindgen_test_layout_pthread_mutex_t() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(pthread_mutex_t)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(pthread_mutex_t)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__l) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_mutex_t), + "::", + stringify!(__l) + ) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct pthread_mutexattr_t { + pub __attr: ::core::ffi::c_uint, +} +#[test] +fn bindgen_test_layout_pthread_mutexattr_t() { + const UNINIT: ::core::mem::MaybeUninit = + ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(pthread_mutexattr_t)) + ); + assert_eq!( + ::core::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(pthread_mutexattr_t)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__attr) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_mutexattr_t), + "::", + stringify!(__attr) + ) + ); +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct pthread_attr_t { + pub __u: pthread_attr_t__bindgen_ty_1, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union pthread_attr_t__bindgen_ty_1 { + pub __i: [::core::ffi::c_int; 14usize], + pub __vi: [::core::ffi::c_int; 14usize], + pub __s: [::core::ffi::c_ulong; 7usize], +} +#[test] +fn bindgen_test_layout_pthread_attr_t__bindgen_ty_1() { + const UNINIT: ::core::mem::MaybeUninit = + ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 56usize, + concat!("Size of: ", stringify!(pthread_attr_t__bindgen_ty_1)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(pthread_attr_t__bindgen_ty_1)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__i) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_attr_t__bindgen_ty_1), + "::", + stringify!(__i) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__vi) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_attr_t__bindgen_ty_1), + "::", + stringify!(__vi) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__s) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_attr_t__bindgen_ty_1), + "::", + stringify!(__s) + ) + ); +} +impl Default for pthread_attr_t__bindgen_ty_1 { + fn default() -> Self { + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[test] +fn bindgen_test_layout_pthread_attr_t() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 56usize, + concat!("Size of: ", stringify!(pthread_attr_t)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(pthread_attr_t)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__u) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_attr_t), + "::", + stringify!(__u) + ) + ); +} +impl Default for pthread_attr_t { + fn default() -> Self { + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +pub type pthread_t = *mut ::core::ffi::c_void; +pub type pthread_key_t = ::core::ffi::c_uint; +#[repr(C)] +#[derive(Copy, Clone)] +pub union sigval { + pub sival_int: ::core::ffi::c_int, + pub sival_ptr: *mut ::core::ffi::c_void, +} +#[test] +fn bindgen_test_layout_sigval() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(sigval)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(sigval)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sival_int) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(sigval), + "::", + stringify!(sival_int) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sival_ptr) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(sigval), + "::", + stringify!(sival_ptr) + ) + ); +} +impl Default for sigval { + fn default() -> Self { + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct siginfo_t { + pub si_signo: ::core::ffi::c_int, + pub si_errno: ::core::ffi::c_int, + pub si_code: ::core::ffi::c_int, + pub __si_fields: siginfo_t__bindgen_ty_1, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union siginfo_t__bindgen_ty_1 { + pub __pad: [::core::ffi::c_char; 112usize], + pub __si_common: siginfo_t__bindgen_ty_1__bindgen_ty_1, + pub __sigfault: siginfo_t__bindgen_ty_1__bindgen_ty_2, + pub __sigpoll: siginfo_t__bindgen_ty_1__bindgen_ty_3, + pub __sigsys: siginfo_t__bindgen_ty_1__bindgen_ty_4, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct siginfo_t__bindgen_ty_1__bindgen_ty_1 { + pub __first: siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, + pub __second: siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 { + pub __piduid: siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, + pub __timer: siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2, +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 { + pub si_pid: ::core::ffi::c_int, + pub si_uid: ::core::ffi::c_uint, +} +#[test] +fn bindgen_test_layout_siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1() { + const UNINIT: ::core::mem::MaybeUninit< + siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, + > = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 8usize, + concat!( + "Size of: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) + ) + ); + assert_eq!( + ::core::mem::align_of::( + ), + 4usize, + concat!( + "Alignment of ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).si_pid) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(si_pid) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).si_uid) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(si_uid) + ) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2 { + pub si_timerid: ::core::ffi::c_int, + pub si_overrun: ::core::ffi::c_int, +} +#[test] +fn bindgen_test_layout_siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2() { + const UNINIT: ::core::mem::MaybeUninit< + siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2, + > = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 8usize, + concat!( + "Size of: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2) + ) + ); + assert_eq!( + ::core::mem::align_of::( + ), + 4usize, + concat!( + "Alignment of ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).si_timerid) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(si_timerid) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).si_overrun) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(si_overrun) + ) + ); +} +#[test] +fn bindgen_test_layout_siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1() { + const UNINIT: ::core::mem::MaybeUninit = + ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 8usize, + concat!( + "Size of: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) + ) + ); + assert_eq!( + ::core::mem::align_of::(), + 4usize, + concat!( + "Alignment of ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__piduid) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(__piduid) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__timer) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(__timer) + ) + ); +} +impl Default for siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 { + fn default() -> Self { + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2 { + pub si_value: sigval, + pub __sigchld: siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1, +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1 { + pub si_status: ::core::ffi::c_int, + pub si_utime: ::core::ffi::c_long, + pub si_stime: ::core::ffi::c_long, +} +#[test] +fn bindgen_test_layout_siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1() { + const UNINIT: ::core::mem::MaybeUninit< + siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1, + > = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 24usize, + concat!( + "Size of: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1) + ) + ); + assert_eq!( + ::core::mem::align_of::( + ), + 8usize, + concat!( + "Alignment of ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).si_status) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1), + "::", + stringify!(si_status) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).si_utime) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1), + "::", + stringify!(si_utime) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).si_stime) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1), + "::", + stringify!(si_stime) + ) + ); +} +#[test] +fn bindgen_test_layout_siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2() { + const UNINIT: ::core::mem::MaybeUninit = + ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 24usize, + concat!( + "Size of: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2) + ) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!( + "Alignment of ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).si_value) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(si_value) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__sigchld) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(__sigchld) + ) + ); +} +impl Default for siginfo_t__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2 { + fn default() -> Self { + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[test] +fn bindgen_test_layout_siginfo_t__bindgen_ty_1__bindgen_ty_1() { + const UNINIT: ::core::mem::MaybeUninit = + ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 32usize, + concat!( + "Size of: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_1) + ) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!( + "Alignment of ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_1) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__first) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(__first) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__second) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(__second) + ) + ); +} +impl Default for siginfo_t__bindgen_ty_1__bindgen_ty_1 { + fn default() -> Self { + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct siginfo_t__bindgen_ty_1__bindgen_ty_2 { + pub si_addr: *mut ::core::ffi::c_void, + pub si_addr_lsb: ::core::ffi::c_short, + pub __first: siginfo_t__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union siginfo_t__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1 { + pub __addr_bnd: siginfo_t__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1__bindgen_ty_1, + pub si_pkey: ::core::ffi::c_uint, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct siginfo_t__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1__bindgen_ty_1 { + pub si_lower: *mut ::core::ffi::c_void, + pub si_upper: *mut ::core::ffi::c_void, +} +#[test] +fn bindgen_test_layout_siginfo_t__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1__bindgen_ty_1() { + const UNINIT: ::core::mem::MaybeUninit< + siginfo_t__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1__bindgen_ty_1, + > = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 16usize, + concat!( + "Size of: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1__bindgen_ty_1) + ) + ); + assert_eq!( + ::core::mem::align_of::( + ), + 8usize, + concat!( + "Alignment of ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1__bindgen_ty_1) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).si_lower) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(si_lower) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).si_upper) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(si_upper) + ) + ); +} +impl Default for siginfo_t__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1__bindgen_ty_1 { + fn default() -> Self { + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[test] +fn bindgen_test_layout_siginfo_t__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1() { + const UNINIT: ::core::mem::MaybeUninit = + ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 16usize, + concat!( + "Size of: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1) + ) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!( + "Alignment of ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__addr_bnd) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1), + "::", + stringify!(__addr_bnd) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).si_pkey) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1), + "::", + stringify!(si_pkey) + ) + ); +} +impl Default for siginfo_t__bindgen_ty_1__bindgen_ty_2__bindgen_ty_1 { + fn default() -> Self { + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[test] +fn bindgen_test_layout_siginfo_t__bindgen_ty_1__bindgen_ty_2() { + const UNINIT: ::core::mem::MaybeUninit = + ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 32usize, + concat!( + "Size of: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_2) + ) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!( + "Alignment of ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_2) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).si_addr) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(si_addr) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).si_addr_lsb) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(si_addr_lsb) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__first) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(__first) + ) + ); +} +impl Default for siginfo_t__bindgen_ty_1__bindgen_ty_2 { + fn default() -> Self { + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct siginfo_t__bindgen_ty_1__bindgen_ty_3 { + pub si_band: ::core::ffi::c_long, + pub si_fd: ::core::ffi::c_int, +} +#[test] +fn bindgen_test_layout_siginfo_t__bindgen_ty_1__bindgen_ty_3() { + const UNINIT: ::core::mem::MaybeUninit = + ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 16usize, + concat!( + "Size of: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_3) + ) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!( + "Alignment of ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_3) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).si_band) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_3), + "::", + stringify!(si_band) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).si_fd) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_3), + "::", + stringify!(si_fd) + ) + ); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct siginfo_t__bindgen_ty_1__bindgen_ty_4 { + pub si_call_addr: *mut ::core::ffi::c_void, + pub si_syscall: ::core::ffi::c_int, + pub si_arch: ::core::ffi::c_uint, +} +#[test] +fn bindgen_test_layout_siginfo_t__bindgen_ty_1__bindgen_ty_4() { + const UNINIT: ::core::mem::MaybeUninit = + ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 16usize, + concat!( + "Size of: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_4) + ) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!( + "Alignment of ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_4) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).si_call_addr) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_4), + "::", + stringify!(si_call_addr) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).si_syscall) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_4), + "::", + stringify!(si_syscall) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).si_arch) as usize - ptr as usize }, + 12usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1__bindgen_ty_4), + "::", + stringify!(si_arch) + ) + ); +} +impl Default for siginfo_t__bindgen_ty_1__bindgen_ty_4 { + fn default() -> Self { + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[test] +fn bindgen_test_layout_siginfo_t__bindgen_ty_1() { + const UNINIT: ::core::mem::MaybeUninit = + ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 112usize, + concat!("Size of: ", stringify!(siginfo_t__bindgen_ty_1)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(siginfo_t__bindgen_ty_1)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__pad) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1), + "::", + stringify!(__pad) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__si_common) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1), + "::", + stringify!(__si_common) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__sigfault) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1), + "::", + stringify!(__sigfault) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__sigpoll) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1), + "::", + stringify!(__sigpoll) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__sigsys) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t__bindgen_ty_1), + "::", + stringify!(__sigsys) + ) + ); +} +impl Default for siginfo_t__bindgen_ty_1 { + fn default() -> Self { + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[test] +fn bindgen_test_layout_siginfo_t() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 128usize, + concat!("Size of: ", stringify!(siginfo_t)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(siginfo_t)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).si_signo) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t), + "::", + stringify!(si_signo) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).si_errno) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t), + "::", + stringify!(si_errno) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).si_code) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t), + "::", + stringify!(si_code) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__si_fields) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(siginfo_t), + "::", + stringify!(__si_fields) + ) + ); +} +impl Default for siginfo_t { + fn default() -> Self { + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct __sigset_t { + pub __bits: [::core::ffi::c_ulong; 16usize], +} +#[test] +fn bindgen_test_layout___sigset_t() { + const UNINIT: ::core::mem::MaybeUninit<__sigset_t> = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::<__sigset_t>(), + 128usize, + concat!("Size of: ", stringify!(__sigset_t)) + ); + assert_eq!( + ::core::mem::align_of::<__sigset_t>(), + 8usize, + concat!("Alignment of ", stringify!(__sigset_t)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__bits) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__sigset_t), + "::", + stringify!(__bits) + ) + ); +} +pub type sigset_t = __sigset_t; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct sigaction { + pub __sa_handler: sigaction__bindgen_ty_1, + pub sa_mask: sigset_t, + pub sa_flags: ::core::ffi::c_int, + pub sa_restorer: ::core::option::Option, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union sigaction__bindgen_ty_1 { + pub sa_handler: ::core::option::Option, + pub sa_sigaction: ::core::option::Option< + unsafe extern "C" fn( + arg1: ::core::ffi::c_int, + arg2: *mut siginfo_t, + arg3: *mut ::core::ffi::c_void, + ), + >, +} +#[test] +fn bindgen_test_layout_sigaction__bindgen_ty_1() { + const UNINIT: ::core::mem::MaybeUninit = + ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(sigaction__bindgen_ty_1)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(sigaction__bindgen_ty_1)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sa_handler) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(sigaction__bindgen_ty_1), + "::", + stringify!(sa_handler) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sa_sigaction) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(sigaction__bindgen_ty_1), + "::", + stringify!(sa_sigaction) + ) + ); +} +impl Default for sigaction__bindgen_ty_1 { + fn default() -> Self { + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[test] +fn bindgen_test_layout_sigaction() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 152usize, + concat!("Size of: ", stringify!(sigaction)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(sigaction)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__sa_handler) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(sigaction), + "::", + stringify!(__sa_handler) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sa_mask) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(sigaction), + "::", + stringify!(sa_mask) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sa_flags) as usize - ptr as usize }, + 136usize, + concat!( + "Offset of field: ", + stringify!(sigaction), + "::", + stringify!(sa_flags) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sa_restorer) as usize - ptr as usize }, + 144usize, + concat!( + "Offset of field: ", + stringify!(sigaction), + "::", + stringify!(sa_restorer) + ) + ); +} +impl Default for sigaction { + fn default() -> Self { + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union epoll_data { + pub ptr: *mut ::core::ffi::c_void, + pub fd: ::core::ffi::c_int, + pub u32_: u32, + pub u64_: u64, +} +#[test] +fn bindgen_test_layout_epoll_data() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(epoll_data)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(epoll_data)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(epoll_data), + "::", + stringify!(ptr) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).fd) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(epoll_data), + "::", + stringify!(fd) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(epoll_data), + "::", + stringify!(u32_) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).u64_) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(epoll_data), + "::", + stringify!(u64_) + ) + ); +} +impl Default for epoll_data { + fn default() -> Self { + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +pub type epoll_data_t = epoll_data; +#[repr(C, packed)] +#[derive(Copy, Clone)] +pub struct epoll_event { + pub events: u32, + pub data: epoll_data_t, +} +#[test] +fn bindgen_test_layout_epoll_event() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(epoll_event)) + ); + assert_eq!( + ::core::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(epoll_event)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).events) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(epoll_event), + "::", + stringify!(events) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(epoll_event), + "::", + stringify!(data) + ) + ); +} +impl Default for epoll_event { + fn default() -> Self { + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +pub type rlim_t = ::core::ffi::c_ulonglong; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct rlimit { + pub rlim_cur: rlim_t, + pub rlim_max: rlim_t, +} +#[test] +fn bindgen_test_layout_rlimit() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(rlimit)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rlimit)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rlim_cur) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rlimit), + "::", + stringify!(rlim_cur) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rlim_max) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rlimit), + "::", + stringify!(rlim_max) + ) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct fd_set { + pub fds_bits: [::core::ffi::c_ulong; 16usize], +} +#[test] +fn bindgen_test_layout_fd_set() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 128usize, + concat!("Size of: ", stringify!(fd_set)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(fd_set)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).fds_bits) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(fd_set), + "::", + stringify!(fds_bits) + ) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct stat { + pub st_dev: dev_t, + pub st_ino: ino_t, + pub st_mode: mode_t, + pub st_nlink: nlink_t, + pub st_uid: uid_t, + pub st_gid: gid_t, + pub st_rdev: dev_t, + pub st_size: off_t, + pub st_blksize: blksize_t, + pub st_blocks: blkcnt_t, + pub st_atime: timespec, + pub st_mtime: timespec, + pub st_ctime: timespec, +} +#[test] +fn bindgen_test_layout_stat() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 112usize, + concat!("Size of: ", stringify!(stat)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(stat)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_dev) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(stat), + "::", + stringify!(st_dev) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_ino) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(stat), + "::", + stringify!(st_ino) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_mode) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(stat), + "::", + stringify!(st_mode) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_nlink) as usize - ptr as usize }, + 20usize, + concat!( + "Offset of field: ", + stringify!(stat), + "::", + stringify!(st_nlink) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_uid) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(stat), + "::", + stringify!(st_uid) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_gid) as usize - ptr as usize }, + 28usize, + concat!( + "Offset of field: ", + stringify!(stat), + "::", + stringify!(st_gid) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_rdev) as usize - ptr as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(stat), + "::", + stringify!(st_rdev) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_size) as usize - ptr as usize }, + 40usize, + concat!( + "Offset of field: ", + stringify!(stat), + "::", + stringify!(st_size) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_blksize) as usize - ptr as usize }, + 48usize, + concat!( + "Offset of field: ", + stringify!(stat), + "::", + stringify!(st_blksize) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_blocks) as usize - ptr as usize }, + 56usize, + concat!( + "Offset of field: ", + stringify!(stat), + "::", + stringify!(st_blocks) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_atime) as usize - ptr as usize }, + 64usize, + concat!( + "Offset of field: ", + stringify!(stat), + "::", + stringify!(st_atime) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_mtime) as usize - ptr as usize }, + 80usize, + concat!( + "Offset of field: ", + stringify!(stat), + "::", + stringify!(st_mtime) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_ctime) as usize - ptr as usize }, + 96usize, + concat!( + "Offset of field: ", + stringify!(stat), + "::", + stringify!(st_ctime) + ) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct kstat { + pub st_dev: dev_t, + pub st_ino: ino_t, + pub st_nlink: nlink_t, + pub st_mode: mode_t, + pub st_uid: uid_t, + pub st_gid: gid_t, + pub __pad0: ::core::ffi::c_uint, + pub st_rdev: dev_t, + pub st_size: off_t, + pub st_blksize: blksize_t, + pub st_blocks: blkcnt_t, + pub st_atime_sec: ::core::ffi::c_long, + pub st_atime_nsec: ::core::ffi::c_long, + pub st_mtime_sec: ::core::ffi::c_long, + pub st_mtime_nsec: ::core::ffi::c_long, + pub st_ctime_sec: ::core::ffi::c_long, + pub st_ctime_nsec: ::core::ffi::c_long, + pub __unused: [::core::ffi::c_long; 3usize], +} +#[test] +fn bindgen_test_layout_kstat() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 144usize, + concat!("Size of: ", stringify!(kstat)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(kstat)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_dev) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(kstat), + "::", + stringify!(st_dev) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_ino) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(kstat), + "::", + stringify!(st_ino) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_nlink) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(kstat), + "::", + stringify!(st_nlink) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_mode) as usize - ptr as usize }, + 20usize, + concat!( + "Offset of field: ", + stringify!(kstat), + "::", + stringify!(st_mode) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_uid) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(kstat), + "::", + stringify!(st_uid) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_gid) as usize - ptr as usize }, + 28usize, + concat!( + "Offset of field: ", + stringify!(kstat), + "::", + stringify!(st_gid) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__pad0) as usize - ptr as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(kstat), + "::", + stringify!(__pad0) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_rdev) as usize - ptr as usize }, + 40usize, + concat!( + "Offset of field: ", + stringify!(kstat), + "::", + stringify!(st_rdev) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_size) as usize - ptr as usize }, + 48usize, + concat!( + "Offset of field: ", + stringify!(kstat), + "::", + stringify!(st_size) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_blksize) as usize - ptr as usize }, + 56usize, + concat!( + "Offset of field: ", + stringify!(kstat), + "::", + stringify!(st_blksize) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_blocks) as usize - ptr as usize }, + 64usize, + concat!( + "Offset of field: ", + stringify!(kstat), + "::", + stringify!(st_blocks) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_atime_sec) as usize - ptr as usize }, + 72usize, + concat!( + "Offset of field: ", + stringify!(kstat), + "::", + stringify!(st_atime_sec) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_atime_nsec) as usize - ptr as usize }, + 80usize, + concat!( + "Offset of field: ", + stringify!(kstat), + "::", + stringify!(st_atime_nsec) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_mtime_sec) as usize - ptr as usize }, + 88usize, + concat!( + "Offset of field: ", + stringify!(kstat), + "::", + stringify!(st_mtime_sec) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_mtime_nsec) as usize - ptr as usize }, + 96usize, + concat!( + "Offset of field: ", + stringify!(kstat), + "::", + stringify!(st_mtime_nsec) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_ctime_sec) as usize - ptr as usize }, + 104usize, + concat!( + "Offset of field: ", + stringify!(kstat), + "::", + stringify!(st_ctime_sec) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).st_ctime_nsec) as usize - ptr as usize }, + 112usize, + concat!( + "Offset of field: ", + stringify!(kstat), + "::", + stringify!(st_ctime_nsec) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__unused) as usize - ptr as usize }, + 120usize, + concat!( + "Offset of field: ", + stringify!(kstat), + "::", + stringify!(__unused) + ) + ); +} +#[repr(C)] +#[derive(Debug, Default)] +pub struct sysinfo { + pub uptime: ::core::ffi::c_long, + pub loads: [::core::ffi::c_ulong; 3usize], + pub totalram: ::core::ffi::c_ulong, + pub freeram: ::core::ffi::c_ulong, + pub sharedram: ::core::ffi::c_ulong, + pub bufferram: ::core::ffi::c_ulong, + pub totalswap: ::core::ffi::c_ulong, + pub freeswap: ::core::ffi::c_ulong, + pub procs: ::core::ffi::c_ushort, + pub pad: ::core::ffi::c_ushort, + pub totalhigh: ::core::ffi::c_ulong, + pub freehigh: ::core::ffi::c_ulong, + pub mem_unit: ::core::ffi::c_uint, + pub _f: __IncompleteArrayField<::core::ffi::c_char>, +} +#[test] +fn bindgen_test_layout_sysinfo() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 112usize, + concat!("Size of: ", stringify!(sysinfo)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(sysinfo)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).uptime) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(sysinfo), + "::", + stringify!(uptime) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).loads) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(sysinfo), + "::", + stringify!(loads) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).totalram) as usize - ptr as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(sysinfo), + "::", + stringify!(totalram) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).freeram) as usize - ptr as usize }, + 40usize, + concat!( + "Offset of field: ", + stringify!(sysinfo), + "::", + stringify!(freeram) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sharedram) as usize - ptr as usize }, + 48usize, + concat!( + "Offset of field: ", + stringify!(sysinfo), + "::", + stringify!(sharedram) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).bufferram) as usize - ptr as usize }, + 56usize, + concat!( + "Offset of field: ", + stringify!(sysinfo), + "::", + stringify!(bufferram) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).totalswap) as usize - ptr as usize }, + 64usize, + concat!( + "Offset of field: ", + stringify!(sysinfo), + "::", + stringify!(totalswap) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).freeswap) as usize - ptr as usize }, + 72usize, + concat!( + "Offset of field: ", + stringify!(sysinfo), + "::", + stringify!(freeswap) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).procs) as usize - ptr as usize }, + 80usize, + concat!( + "Offset of field: ", + stringify!(sysinfo), + "::", + stringify!(procs) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).pad) as usize - ptr as usize }, + 82usize, + concat!( + "Offset of field: ", + stringify!(sysinfo), + "::", + stringify!(pad) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).totalhigh) as usize - ptr as usize }, + 88usize, + concat!( + "Offset of field: ", + stringify!(sysinfo), + "::", + stringify!(totalhigh) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).freehigh) as usize - ptr as usize }, + 96usize, + concat!( + "Offset of field: ", + stringify!(sysinfo), + "::", + stringify!(freehigh) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).mem_unit) as usize - ptr as usize }, + 104usize, + concat!( + "Offset of field: ", + stringify!(sysinfo), + "::", + stringify!(mem_unit) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr)._f) as usize - ptr as usize }, + 108usize, + concat!( + "Offset of field: ", + stringify!(sysinfo), + "::", + stringify!(_f) + ) + ); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct iovec { + pub iov_base: *mut ::core::ffi::c_void, + pub iov_len: size_t, +} +#[test] +fn bindgen_test_layout_iovec() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(iovec)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(iovec)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).iov_base) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(iovec), + "::", + stringify!(iov_base) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).iov_len) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(iovec), + "::", + stringify!(iov_len) + ) + ); +} +impl Default for iovec { + fn default() -> Self { + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} diff --git a/api/ruxos_posix_api/ctypes.h b/api/ruxos_posix_api/ctypes.h index 6298ce6c3..1d43015d5 100644 --- a/api/ruxos_posix_api/ctypes.h +++ b/api/ruxos_posix_api/ctypes.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include diff --git a/api/ruxos_posix_api/src/imp/net.rs b/api/ruxos_posix_api/src/imp/net.rs index e2817c96f..387e79fe7 100644 --- a/api/ruxos_posix_api/src/imp/net.rs +++ b/api/ruxos_posix_api/src/imp/net.rs @@ -1,29 +1,53 @@ /* Copyright (c) [2023] [Syswonder Community] - * [Ruxos] is licensed under Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v2 for more details. - */ +* [Ruxos] is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ use alloc::{sync::Arc, vec, vec::Vec}; use core::ffi::{c_char, c_int, c_void}; use core::mem::size_of; use core::net::{IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4}; +use core::sync::atomic::AtomicIsize; use axerrno::{LinuxError, LinuxResult}; use axio::PollState; use axsync::Mutex; -use ruxfdtable::{FileLike, RuxStat}; -use ruxnet::{TcpSocket, UdpSocket}; +use ruxfdtable::{FileLike, RuxStat, RUX_FILE_LIMIT}; +use ruxnet::{SockaddrUn, TcpSocket, UdpSocket, UnixSocket, UnixSocketType}; use crate::ctypes; use crate::utils::char_ptr_to_str; +/*impl From<*const ctypes::sockaddr_un> for SockaddrUn { + fn from(addr: *const ctypes::sockaddr_un) -> Self { + Self { + sun_family: addr.sun_family, + sun_path: addr.sun_path, + } + } +}*/ +fn addrun_convert(addr: *const ctypes::sockaddr_un) -> SockaddrUn { + unsafe { + SockaddrUn { + sun_family: (*addr).sun_family, + sun_path: (*addr).sun_path, + } + } +} + +pub enum Sockaddr { + Net(SocketAddr), + Unix(SockaddrUn), +} + pub enum Socket { Udp(Mutex), Tcp(Mutex), + Unix(Mutex), } impl Socket { @@ -42,6 +66,7 @@ impl Socket { match self { Socket::Udp(udpsocket) => Ok(udpsocket.lock().send(buf)?), Socket::Tcp(tcpsocket) => Ok(tcpsocket.lock().send(buf)?), + Socket::Unix(socket) => Ok(socket.lock().send(buf)?), } } @@ -49,6 +74,7 @@ impl Socket { match self { Socket::Udp(udpsocket) => Ok(udpsocket.lock().recv_from(buf).map(|e| e.0)?), Socket::Tcp(tcpsocket) => Ok(tcpsocket.lock().recv(buf, flags)?), + Socket::Unix(socket) => Ok(socket.lock().recv(buf, flags)?), } } @@ -56,6 +82,7 @@ impl Socket { match self { Socket::Udp(udpsocket) => Ok(udpsocket.lock().poll()?), Socket::Tcp(tcpsocket) => Ok(tcpsocket.lock().poll()?), + Socket::Unix(socket) => Ok(socket.lock().poll()?), } } @@ -63,27 +90,71 @@ impl Socket { match self { Socket::Udp(udpsocket) => Ok(udpsocket.lock().local_addr()?), Socket::Tcp(tcpsocket) => Ok(tcpsocket.lock().local_addr()?), + Socket::Unix(_) => Err(LinuxError::EOPNOTSUPP), } } - fn peer_addr(&self) -> LinuxResult { + fn peer_addr(&self) -> LinuxResult { match self { - Socket::Udp(udpsocket) => Ok(udpsocket.lock().peer_addr()?), - Socket::Tcp(tcpsocket) => Ok(tcpsocket.lock().peer_addr()?), + Socket::Udp(udpsocket) => Ok(Sockaddr::Net(udpsocket.lock().peer_addr()?)), + Socket::Tcp(tcpsocket) => Ok(Sockaddr::Net(tcpsocket.lock().peer_addr()?)), + Socket::Unix(unixsocket) => Ok(Sockaddr::Unix(unixsocket.lock().peer_addr()?)), } } - fn bind(&self, addr: SocketAddr) -> LinuxResult { + fn bind( + &self, + socket_addr: *const ctypes::sockaddr, + addrlen: ctypes::socklen_t, + ) -> LinuxResult { match self { - Socket::Udp(udpsocket) => Ok(udpsocket.lock().bind(addr)?), - Socket::Tcp(tcpsocket) => Ok(tcpsocket.lock().bind(addr)?), + Socket::Udp(udpsocket) => { + let addr = from_sockaddr(socket_addr, addrlen)?; + Ok(udpsocket.lock().bind(addr)?) + } + Socket::Tcp(tcpsocket) => { + let addr = from_sockaddr(socket_addr, addrlen)?; + Ok(tcpsocket.lock().bind(addr)?) + } + Socket::Unix(socket) => { + if socket_addr.is_null() { + return Err(LinuxError::EFAULT); + } + if addrlen != size_of::() as _ { + return Err(LinuxError::EINVAL); + } + Ok(socket + .lock() + .bind(addrun_convert(socket_addr as *const ctypes::sockaddr_un))?) + } } } - fn connect(&self, addr: SocketAddr) -> LinuxResult { + fn connect( + &self, + socket_addr: *const ctypes::sockaddr, + addrlen: ctypes::socklen_t, + ) -> LinuxResult { match self { - Socket::Udp(udpsocket) => Ok(udpsocket.lock().connect(addr)?), - Socket::Tcp(tcpsocket) => Ok(tcpsocket.lock().connect(addr)?), + Socket::Udp(udpsocket) => { + let addr = from_sockaddr(socket_addr, addrlen)?; + Ok(udpsocket.lock().connect(addr)?) + } + Socket::Tcp(tcpsocket) => { + let addr = from_sockaddr(socket_addr, addrlen)?; + Ok(tcpsocket.lock().connect(addr)?) + } + Socket::Unix(socket) => { + if socket_addr.is_null() { + return Err(LinuxError::EFAULT); + } + if addrlen != size_of::() as _ { + return Err(LinuxError::EINVAL); + } + Ok(socket + .lock() + .connect(addrun_convert(socket_addr as *const ctypes::sockaddr_un))?) + } } } @@ -92,6 +163,7 @@ impl Socket { // diff: must bind before sendto Socket::Udp(udpsocket) => Ok(udpsocket.lock().send_to(buf, addr)?), Socket::Tcp(_) => Err(LinuxError::EISCONN), + Socket::Unix(_) => Err(LinuxError::EISCONN), } } @@ -103,6 +175,7 @@ impl Socket { .recv_from(buf) .map(|res| (res.0, Some(res.1)))?), Socket::Tcp(tcpsocket) => Ok(tcpsocket.lock().recv(buf, 0).map(|res| (res, None))?), + Socket::Unix(socket) => Ok(socket.lock().recv(buf, 0).map(|res| (res, None))?), } } @@ -110,13 +183,15 @@ impl Socket { match self { Socket::Udp(_) => Err(LinuxError::EOPNOTSUPP), Socket::Tcp(tcpsocket) => Ok(tcpsocket.lock().listen()?), + Socket::Unix(socket) => Ok(socket.lock().listen()?), } } - fn accept(&self) -> LinuxResult { + fn accept(&self) -> LinuxResult { match self { Socket::Udp(_) => Err(LinuxError::EOPNOTSUPP), - Socket::Tcp(tcpsocket) => Ok(tcpsocket.lock().accept()?), + Socket::Tcp(tcpsocket) => Ok(Socket::Tcp(Mutex::new(tcpsocket.lock().accept()?))), + Socket::Unix(unixsocket) => Ok(Socket::Unix(Mutex::new(unixsocket.lock().accept()?))), } } @@ -135,6 +210,12 @@ impl Socket { tcpsocket.shutdown()?; Ok(()) } + Socket::Unix(socket) => { + let socket = socket.lock(); + socket.peer_addr()?; + socket.shutdown()?; + Ok(()) + } } } } @@ -179,6 +260,7 @@ impl FileLike for Socket { match self { Socket::Udp(udpsocket) => udpsocket.lock().set_nonblocking(nonblock), Socket::Tcp(tcpsocket) => tcpsocket.lock().set_nonblocking(nonblock), + Socket::Unix(unixsocket) => unixsocket.lock().set_nonblocking(nonblock), } Ok(()) } @@ -199,6 +281,15 @@ impl From for ctypes::sockaddr_in { } } +impl From for ctypes::sockaddr_un { + fn from(addr: SockaddrUn) -> ctypes::sockaddr_un { + ctypes::sockaddr_un { + sun_family: addr.sun_family, + sun_path: addr.sun_path, + } + } +} + impl From for SocketAddrV4 { fn from(addr: ctypes::sockaddr_in) -> SocketAddrV4 { SocketAddrV4::new( @@ -208,6 +299,14 @@ impl From for SocketAddrV4 { } } +fn un_into_sockaddr(addr: SockaddrUn) -> (ctypes::sockaddr, ctypes::socklen_t) { + debug!(" Sockaddr: {:?}", addr); + ( + unsafe { *(&ctypes::sockaddr_un::from(addr) as *const _ as *const ctypes::sockaddr) }, + size_of::() as _, + ) +} + fn into_sockaddr(addr: SocketAddr) -> (ctypes::sockaddr, ctypes::socklen_t) { debug!(" Sockaddr: {}", addr); match addr { @@ -262,6 +361,10 @@ pub fn sys_socket(domain: c_int, socktype: c_int, protocol: c_int) -> c_int { tcp_socket.set_nonblocking(true); Socket::Tcp(Mutex::new(tcp_socket)).add_to_fd_table() } + (ctypes::AF_UNIX, ctypes::SOCK_STREAM, 0) => { + Socket::Unix(Mutex::new(UnixSocket::new(UnixSocketType::SockStream))) + .add_to_fd_table() + } _ => Err(LinuxError::EINVAL), } }) @@ -297,8 +400,7 @@ pub fn sys_bind( socket_fd, socket_addr as usize, addrlen ); syscall_body!(sys_bind, { - let addr = from_sockaddr(socket_addr, addrlen)?; - Socket::from_fd(socket_fd)?.bind(addr)?; + Socket::from_fd(socket_fd)?.bind(socket_addr, addrlen)?; Ok(0) }) } @@ -316,8 +418,7 @@ pub fn sys_connect( socket_fd, socket_addr as usize, addrlen ); syscall_body!(sys_connect, { - let addr = from_sockaddr(socket_addr, addrlen)?; - Socket::from_fd(socket_fd)?.connect(addr)?; + Socket::from_fd(socket_fd)?.connect(socket_addr, addrlen)?; Ok(0) }) } @@ -464,10 +565,16 @@ pub unsafe fn sys_accept( let socket = Socket::from_fd(socket_fd)?; let new_socket = socket.accept()?; let addr = new_socket.peer_addr()?; - let new_fd = Socket::add_to_fd_table(Socket::Tcp(Mutex::new(new_socket)))?; - unsafe { - (*socket_addr, *socket_len) = into_sockaddr(addr); + let new_fd = Socket::add_to_fd_table(new_socket)?; + match addr { + Sockaddr::Net(addr) => unsafe { + (*socket_addr, *socket_len) = into_sockaddr(addr); + }, + Sockaddr::Unix(addr) => unsafe { + (*socket_addr, *socket_len) = un_into_sockaddr(addr); + }, } + Ok(new_fd) }) } @@ -638,10 +745,23 @@ pub fn sys_getsockopt( 0 } } + Socket::Unix(unixsocket) => { + if unixsocket.lock().is_listening() { + 1 + } else { + 0 + } + } }, ctypes::SO_TYPE => match &*socket { Socket::Udp(_) => ctypes::SOCK_DGRAM, Socket::Tcp(_) => ctypes::SOCK_STREAM, + Socket::Unix(unixsocket) => match unixsocket.lock().get_sockettype() { + UnixSocketType::SockStream => ctypes::SOCK_STREAM, + UnixSocketType::SockDgram | UnixSocketType::SockSeqpacket => { + ctypes::SOCK_DGRAM + } + }, }, ctypes::SO_RCVLOWAT | ctypes::SO_SNDLOWAT | ctypes::SO_BROADCAST => 1, ctypes::SO_ERROR @@ -686,8 +806,14 @@ pub unsafe fn sys_getpeername( if unsafe { *addrlen } < size_of::() as u32 { return Err(LinuxError::EINVAL); } - unsafe { - (*addr, *addrlen) = into_sockaddr(Socket::from_fd(sock_fd)?.peer_addr()?); + let sockaddr = Socket::from_fd(sock_fd)?.peer_addr()?; + match sockaddr { + Sockaddr::Net(netaddr) => unsafe { + (*addr, *addrlen) = into_sockaddr(netaddr); + }, + Sockaddr::Unix(unixaddr) => unsafe { + (*addr, *addrlen) = un_into_sockaddr(unixaddr); + }, } Ok(0) }) @@ -726,6 +852,10 @@ pub unsafe fn sys_sendmsg( from_sockaddr(msg.msg_name as *const ctypes::sockaddr, msg.msg_namelen)?, )?, Socket::Tcp(tcpsocket) => tcpsocket.lock().send(buf)?, + Socket::Unix(unixsocket) => unixsocket.lock().sendto( + buf, + addrun_convert(msg.msg_name as *const ctypes::sockaddr_un), + )?, }; } Ok(ret) diff --git a/crates/axfs_devfs/src/dir.rs b/crates/axfs_devfs/src/dir.rs index 2245fcb49..2ba4da6ca 100644 --- a/crates/axfs_devfs/src/dir.rs +++ b/crates/axfs_devfs/src/dir.rs @@ -1,11 +1,11 @@ /* Copyright (c) [2023] [Syswonder Community] - * [Ruxos] is licensed under Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v2 for more details. - */ +* [Ruxos] is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ use alloc::collections::BTreeMap; use alloc::sync::{Arc, Weak}; diff --git a/crates/axfs_ramfs/src/dir.rs b/crates/axfs_ramfs/src/dir.rs index e685bd255..cc45a84e5 100644 --- a/crates/axfs_ramfs/src/dir.rs +++ b/crates/axfs_ramfs/src/dir.rs @@ -1,11 +1,11 @@ /* Copyright (c) [2023] [Syswonder Community] - * [Ruxos] is licensed under Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v2 for more details. - */ +* [Ruxos] is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ use alloc::collections::BTreeMap; use alloc::sync::{Arc, Weak}; @@ -13,7 +13,7 @@ use alloc::{string::String, vec::Vec}; use axfs_vfs::{VfsDirEntry, VfsNodeAttr, VfsNodeOps, VfsNodeRef, VfsNodeType}; use axfs_vfs::{VfsError, VfsResult}; -use spin::RwLock; +use spin::rwlock::RwLock; use crate::file::FileNode; diff --git a/crates/axfs_ramfs/src/file.rs b/crates/axfs_ramfs/src/file.rs index 7464c5d4e..da356938b 100644 --- a/crates/axfs_ramfs/src/file.rs +++ b/crates/axfs_ramfs/src/file.rs @@ -1,15 +1,15 @@ /* Copyright (c) [2023] [Syswonder Community] - * [Ruxos] is licensed under Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v2 for more details. - */ +* [Ruxos] is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ use alloc::vec::Vec; use axfs_vfs::{impl_vfs_non_dir_default, VfsNodeAttr, VfsNodeOps, VfsResult}; -use spin::RwLock; +use spin::rwlock::RwLock; /// The file node in the RAM filesystem. /// diff --git a/crates/axfs_vfs/Cargo.toml b/crates/axfs_vfs/Cargo.toml index 319dd8a8a..9ee8abcd5 100644 --- a/crates/axfs_vfs/Cargo.toml +++ b/crates/axfs_vfs/Cargo.toml @@ -14,5 +14,7 @@ default = [] [dependencies] log = "0.4" +spin = "0.9" bitflags = "2.2" axerrno = { path = "../axerrno" } +lazy_static = { version = "1.4", features = ["spin_no_std"] } \ No newline at end of file diff --git a/crates/axfs_vfs/src/structs.rs b/crates/axfs_vfs/src/structs.rs index 7a4b3834b..001a99fe0 100644 --- a/crates/axfs_vfs/src/structs.rs +++ b/crates/axfs_vfs/src/structs.rs @@ -1,11 +1,11 @@ /* Copyright (c) [2023] [Syswonder Community] - * [Ruxos] is licensed under Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v2 for more details. - */ +* [Ruxos] is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ /// Filesystem attributes. /// @@ -207,8 +207,9 @@ impl VfsNodeType { impl VfsNodeAttr { /// Creates a new `VfsNodeAttr` with the given permission mode, type, size - /// and number of blocks. - pub const fn new(mode: VfsNodePerm, ty: VfsNodeType, size: u64, blocks: u64) -> Self { + /// inode number and number of blocks. + /// if node number is none, means fs do not have inode then vfs will allocate it + pub fn new(mode: VfsNodePerm, ty: VfsNodeType, size: u64, blocks: u64) -> Self { Self { mode, ty, @@ -218,7 +219,7 @@ impl VfsNodeAttr { } /// Creates a new `VfsNodeAttr` for a file, with the default file permission. - pub const fn new_file(size: u64, blocks: u64) -> Self { + pub fn new_file(size: u64, blocks: u64) -> Self { Self { mode: VfsNodePerm::default_file(), ty: VfsNodeType::File, @@ -229,7 +230,7 @@ impl VfsNodeAttr { /// Creates a new `VfsNodeAttr` for a directory, with the default directory /// permission. - pub const fn new_dir(size: u64, blocks: u64) -> Self { + pub fn new_dir(size: u64, blocks: u64) -> Self { Self { mode: VfsNodePerm::default_dir(), ty: VfsNodeType::Dir, diff --git a/modules/rux9p/src/drv.rs b/modules/rux9p/src/drv.rs index 82951fb3e..379821786 100644 --- a/modules/rux9p/src/drv.rs +++ b/modules/rux9p/src/drv.rs @@ -780,7 +780,7 @@ impl _9PReq { } } -#[derive(Debug)] +#[derive(Debug, Copy, Clone)] pub struct _9PQid { ftype: u8, version: u32, @@ -795,6 +795,9 @@ impl _9PQid { path: lbytes2u64(&bytes[5..13]), } } + pub fn path(&self) -> u64 { + self.path + } } pub struct PosLock { @@ -904,6 +907,10 @@ impl FileAttr { } } + pub fn get_qid(&self) -> _9PQid { + self.qid + } + pub fn get_perm(&self) -> u32 { self.mode } diff --git a/modules/rux9p/src/fs.rs b/modules/rux9p/src/fs.rs index 9ca29f73b..3fdc0179a 100644 --- a/modules/rux9p/src/fs.rs +++ b/modules/rux9p/src/fs.rs @@ -109,6 +109,7 @@ pub struct CommonNode { inner: Arc>, fid: Arc, protocol: Arc, + attr: RwLock>, } impl CommonNode { @@ -169,6 +170,7 @@ impl CommonNode { fid: Arc::new(fid), protocol, parent: RwLock::new(parent.unwrap_or_else(|| Weak::::new())), + attr: RwLock::new(None), }) } diff --git a/modules/ruxfs/Cargo.toml b/modules/ruxfs/Cargo.toml index 0ca624616..daa4c6944 100644 --- a/modules/ruxfs/Cargo.toml +++ b/modules/ruxfs/Cargo.toml @@ -27,6 +27,7 @@ default = ["devfs", "ramfs", "fatfs", "procfs", "sysfs", "etcfs"] [dependencies] log = "0.4" +spin = "0.9" cfg-if = "1.0" lazy_init = { path = "../../crates/lazy_init" } capability = { path = "../../crates/capability" } diff --git a/modules/ruxfs/src/api/file.rs b/modules/ruxfs/src/api/file.rs index ea4eecdf0..9bbb8c656 100644 --- a/modules/ruxfs/src/api/file.rs +++ b/modules/ruxfs/src/api/file.rs @@ -101,7 +101,7 @@ impl Metadata { /// Returns the size of the file, in bytes, this metadata is for. #[allow(clippy::len_without_is_empty)] - pub const fn len(&self) -> u64 { + pub fn len(&self) -> u64 { self.0.size() } diff --git a/modules/ruxfs/src/fs/fatfs.rs b/modules/ruxfs/src/fs/fatfs.rs index 3b27b7f6f..5c72ea386 100644 --- a/modules/ruxfs/src/fs/fatfs.rs +++ b/modules/ruxfs/src/fs/fatfs.rs @@ -1,21 +1,21 @@ /* Copyright (c) [2023] [Syswonder Community] - * [Ruxos] is licensed under Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v2 for more details. - */ +* [Ruxos] is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ use alloc::sync::Arc; use core::cell::UnsafeCell; +use crate::dev::Disk; use axfs_vfs::{VfsDirEntry, VfsError, VfsNodePerm, VfsResult}; use axfs_vfs::{VfsNodeAttr, VfsNodeOps, VfsNodeRef, VfsNodeType, VfsOps}; use axsync::Mutex; use fatfs::{Dir, File, LossyOemCpConverter, NullTimeProvider, Read, Seek, SeekFrom, Write}; - -use crate::dev::Disk; +use spin::rwlock::RwLock; const BLOCK_SIZE: usize = 512; @@ -129,7 +129,6 @@ impl VfsNodeOps for DirWrapper<'static> { axfs_vfs::impl_vfs_dir_default! {} fn get_attr(&self) -> VfsResult { - // FAT fs doesn't support permissions, we just set everything to 755 Ok(VfsNodeAttr::new( VfsNodePerm::from_bits_truncate(0o755), VfsNodeType::Dir, diff --git a/modules/ruxfs/src/lib.rs b/modules/ruxfs/src/lib.rs index 6db931721..4c869ce11 100644 --- a/modules/ruxfs/src/lib.rs +++ b/modules/ruxfs/src/lib.rs @@ -38,7 +38,7 @@ extern crate alloc; mod dev; mod fs; mod mounts; -mod root; +pub mod root; #[cfg(feature = "alloc")] mod arch; diff --git a/modules/ruxfs/src/root.rs b/modules/ruxfs/src/root.rs index eb19f2c60..4b2641f46 100644 --- a/modules/ruxfs/src/root.rs +++ b/modules/ruxfs/src/root.rs @@ -28,7 +28,8 @@ pub struct MountPoint { fs: Arc, } -struct RootDirectory { +/// fs root directory +pub struct RootDirectory { main_fs: Arc, mounts: Vec, } @@ -49,6 +50,7 @@ impl Drop for MountPoint { } impl RootDirectory { + /// Creates a new `RootDirectory` with the specified main filesystem. pub const fn new(main_fs: Arc) -> Self { Self { main_fs, @@ -56,6 +58,7 @@ impl RootDirectory { } } + /// Mounts a new filesystem at the specified path within the root directory. pub fn mount(&mut self, path: &'static str, fs: Arc) -> AxResult { if path == "/" { return ax_err!(InvalidInput, "cannot mount root filesystem"); @@ -80,10 +83,12 @@ impl RootDirectory { Ok(()) } + /// Unmounts a filesystem at the specified path, if it exists. pub fn _umount(&mut self, path: &str) { self.mounts.retain(|mp| mp.path != path); } + /// Checks if a given path is a mount point in the root directory. pub fn contains(&self, path: &str) -> bool { self.mounts.iter().any(|mp| mp.path == path) } @@ -199,7 +204,8 @@ pub(crate) fn absolute_path(path: &str) -> AxResult { } } -pub(crate) fn lookup(dir: Option<&VfsNodeRef>, path: &str) -> AxResult { +/// Looks up a node in the virtual file system by its path. +pub fn lookup(dir: Option<&VfsNodeRef>, path: &str) -> AxResult { if path.is_empty() { return ax_err!(NotFound); } @@ -211,7 +217,8 @@ pub(crate) fn lookup(dir: Option<&VfsNodeRef>, path: &str) -> AxResult, path: &str) -> AxResult { +/// Creates a file in the virtual file system at the specified path. +pub fn create_file(dir: Option<&VfsNodeRef>, path: &str) -> AxResult { if path.is_empty() { return ax_err!(NotFound); } else if path.ends_with('/') { diff --git a/modules/ruxnet/Cargo.toml b/modules/ruxnet/Cargo.toml index 3c81a2510..c302c3578 100644 --- a/modules/ruxnet/Cargo.toml +++ b/modules/ruxnet/Cargo.toml @@ -15,18 +15,23 @@ smoltcp = [] default = ["smoltcp"] [dependencies] +hashbrown = "0.14.5" log = "0.4" cfg-if = "1.0" spin = "0.9" driver_net = { path = "../../crates/driver_net" } +flatten_objects = { path = "../../crates/flatten_objects" } lazy_init = { path = "../../crates/lazy_init" } +lazy_static = { version = "1.4", features = ["spin_no_std"] } lwip_rust = { path = "../../crates/lwip_rust", optional = true } printf-compat = { version = "0.1", default-features = false, optional = true } axerrno = { path = "../../crates/axerrno" } +axfs_vfs = { path = "../../crates/axfs_vfs" } ruxhal = { path = "../ruxhal" } axsync = { path = "../axsync" } axlog = { path = "../axlog" } ruxtask = { path = "../ruxtask" } +ruxfs = { path = "../ruxfs" } ruxdriver = { path = "../ruxdriver", features = ["net"] } cty = { version = "0.2.2", optional = true } axio = { path = "../../crates/axio" } diff --git a/modules/ruxnet/src/lib.rs b/modules/ruxnet/src/lib.rs index a8414b105..964b8e480 100644 --- a/modules/ruxnet/src/lib.rs +++ b/modules/ruxnet/src/lib.rs @@ -37,6 +37,9 @@ extern crate log; extern crate alloc; +mod unix; +pub use unix::{SockaddrUn, UnixSocket, UnixSocketType}; + cfg_if::cfg_if! { if #[cfg(feature = "lwip")] { mod lwip_impl; @@ -74,5 +77,6 @@ pub fn init_network(mut net_devs: AxDeviceContainer) { compile_error!("No network stack is selected"); } } + unix::init_unix(); net_impl::init(dev); } diff --git a/modules/ruxnet/src/smoltcp_impl/tcp.rs b/modules/ruxnet/src/smoltcp_impl/tcp.rs index fb2c43690..8bfb9f0a9 100644 --- a/modules/ruxnet/src/smoltcp_impl/tcp.rs +++ b/modules/ruxnet/src/smoltcp_impl/tcp.rs @@ -158,7 +158,7 @@ impl TcpSocket { ax_err!(ConnectionRefused, "socket connect() failed") } })?; - Ok(( + Ok::<(IpEndpoint, IpEndpoint), AxError>(( socket.local_endpoint().unwrap(), socket.remote_endpoint().unwrap(), )) diff --git a/modules/ruxnet/src/unix.rs b/modules/ruxnet/src/unix.rs new file mode 100644 index 000000000..34f887def --- /dev/null +++ b/modules/ruxnet/src/unix.rs @@ -0,0 +1,702 @@ +/* Copyright (c) [2023] [Syswonder Community] +* [Ruxos] is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +use alloc::{sync::Arc, vec}; +use axerrno::{ax_err, AxError, AxResult, LinuxError, LinuxResult}; +use axio::PollState; +use axsync::Mutex; +use core::ffi::{c_char, c_int}; +use core::net::SocketAddr; +use core::sync::atomic::{AtomicBool, Ordering}; +use spin::RwLock; + +use lazy_init::LazyInit; + +use smoltcp::socket::tcp::SocketBuffer; + +use hashbrown::HashMap; + +use ruxfs::root::{create_file, lookup}; +use ruxtask::yield_now; + +const SOCK_ADDR_UN_PATH_LEN: usize = 108; +const UNIX_SOCKET_BUFFER_SIZE: usize = 4096; + +/// rust form for ctype sockaddr_un +#[derive(Clone, Copy, Debug)] +pub struct SockaddrUn { + /// AF_UNIX + pub sun_family: u16, + /// socket path + pub sun_path: [c_char; SOCK_ADDR_UN_PATH_LEN], /* Pathname */ +} + +impl SockaddrUn { + /// Sets the socket address to the specified new address. + pub fn set_addr(&mut self, new_addr: &SockaddrUn) { + self.sun_family = new_addr.sun_family; + self.sun_path = new_addr.sun_path; + } +} + +//To avoid owner question of FDTABLE outside and UnixTable in this crate we split the unixsocket +struct UnixSocketInner<'a> { + pub addr: Mutex, + pub buf: SocketBuffer<'a>, + pub peer_socket: Option, + pub status: UnixSocketStatus, +} + +impl<'a> UnixSocketInner<'a> { + pub fn new() -> Self { + Self { + addr: Mutex::new(SockaddrUn { + sun_family: 1, //AF_UNIX + sun_path: [0; SOCK_ADDR_UN_PATH_LEN], + }), + buf: SocketBuffer::new(vec![0; 64 * 1024]), + peer_socket: None, + status: UnixSocketStatus::Closed, + } + } + + pub fn get_addr(&self) -> SockaddrUn { + self.addr.lock().clone() + } + + pub fn get_peersocket(&self) -> Option { + self.peer_socket + } + + pub fn set_peersocket(&mut self, peer: usize) { + self.peer_socket = Some(peer) + } + + pub fn get_state(&self) -> UnixSocketStatus { + self.status + } + + pub fn set_state(&mut self, state: UnixSocketStatus) { + self.status = state + } + + pub fn can_accept(&mut self) -> bool { + match self.status { + UnixSocketStatus::Listening => !self.buf.is_empty(), + _ => false, + } + } + + pub fn may_recv(&mut self) -> bool { + match self.status { + UnixSocketStatus::Connected => true, + //State::FinWait1 | State::FinWait2 => true, + _ if !self.buf.is_empty() => true, + _ => false, + } + } + + pub fn can_recv(&mut self) -> bool { + if !self.may_recv() { + return false; + } + + !self.buf.is_empty() + } + + pub fn may_send(&mut self) -> bool { + match self.status { + UnixSocketStatus::Connected => true, + //State::CloseWait => true, + _ => false, + } + } + + pub fn can_send(&mut self) -> bool { + self.may_send() + } +} + +/// unix domain socket. +pub struct UnixSocket { + sockethandle: Option, + unixsocket_type: UnixSocketType, + nonblock: AtomicBool, +} + +// now there is no real inode, this func is to check whether file exists +// TODO: if inode impl, this should return inode +fn get_inode(addr: SockaddrUn) -> AxResult { + let slice = unsafe { core::slice::from_raw_parts(addr.sun_path.as_ptr(), addr.sun_path.len()) }; + + let socket_path = unsafe { + core::ffi::CStr::from_ptr(slice.as_ptr()) + .to_str() + .expect("Invalid UTF-8 string") + }; + let _vfsnode = match lookup(None, socket_path) { + Ok(node) => node, + Err(_) => { + return Err(AxError::NotFound); + } + }; + + Err(AxError::Unsupported) +} + +fn create_socket_file(addr: SockaddrUn) -> AxResult { + let slice = unsafe { core::slice::from_raw_parts(addr.sun_path.as_ptr(), addr.sun_path.len()) }; + + let socket_path = unsafe { + core::ffi::CStr::from_ptr(slice.as_ptr()) + .to_str() + .expect("Invalid UTF-8 string") + }; + let _vfsnode = create_file(None, socket_path)?; + Err(AxError::Unsupported) +} + +struct HashMapWarpper<'a> { + inner: HashMap>>>, + index_allcator: Mutex, +} +impl<'a> HashMapWarpper<'a> { + pub fn new() -> Self { + Self { + inner: HashMap::new(), + index_allcator: Mutex::new(0), + } + } + pub fn find(&self, predicate: F) -> Option<(&usize, &Arc>>)> + where + F: Fn(&Arc>>) -> bool, + { + self.inner.iter().find(|(_k, v)| predicate(v)) + } + + pub fn add(&mut self, value: Arc>>) -> Option { + let index_allcator = self.index_allcator.get_mut(); + while self.inner.contains_key(index_allcator) { + *index_allcator += 1; + } + self.inner.insert(*index_allcator, value); + Some(*index_allcator) + } + + pub fn replace_handle(&mut self, old: usize, new: usize) -> Option { + if let Some(value) = self.inner.remove(&old) { + self.inner.insert(new, value); + } + Some(new) + } + + pub fn get(&self, id: usize) -> Option<&Arc>>> { + self.inner.get(&id) + } + + pub fn get_mut(&mut self, id: usize) -> Option<&mut Arc>>> { + self.inner.get_mut(&id) + } +} +static UNIX_TABLE: LazyInit> = LazyInit::new(); + +/// unix socket type +#[derive(Debug, Clone, Copy)] +pub enum UnixSocketType { + /// A stream-oriented Unix domain socket. + SockStream, + /// A datagram-oriented Unix domain socket. + SockDgram, + /// A sequenced packet Unix domain socket. + SockSeqpacket, +} + +// State transitions: +// CLOSED -(connect)-> BUSY -> CONNECTING -> CONNECTED -(shutdown)-> BUSY -> CLOSED +// | +// |-(listen)-> BUSY -> LISTENING -(shutdown)-> BUSY -> CLOSED +// | +// -(bind)-> BUSY -> CLOSED +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum UnixSocketStatus { + Closed, + Busy, + Connecting, + Connected, + Listening, +} + +impl UnixSocket { + /// create a new socket + /// only support sock_stream + pub fn new(_type: UnixSocketType) -> Self { + match _type { + UnixSocketType::SockDgram | UnixSocketType::SockSeqpacket => unimplemented!(), + UnixSocketType::SockStream => { + let mut unixsocket = UnixSocket { + sockethandle: None, + unixsocket_type: _type, + nonblock: AtomicBool::new(false), + }; + let handle = UNIX_TABLE + .write() + .add(Arc::new(Mutex::new(UnixSocketInner::new()))) + .unwrap(); + unixsocket.set_sockethandle(handle); + unixsocket + } + } + } + + /// Sets the socket handle. + pub fn set_sockethandle(&mut self, fd: usize) { + self.sockethandle = Some(fd); + } + + /// Returns the socket handle. + pub fn get_sockethandle(&self) -> usize { + self.sockethandle.unwrap() + } + + /// Returns the peer socket handle, if available. + pub fn get_peerhandle(&self) -> Option { + UNIX_TABLE + .read() + .get(self.get_sockethandle()) + .unwrap() + .lock() + .get_peersocket() + } + + /// Returns the current state of the socket. + pub fn get_state(&self) -> UnixSocketStatus { + UNIX_TABLE + .read() + .get(self.get_sockethandle()) + .unwrap() + .lock() + .status + } + + /// Enqueues data into the socket buffer. + /// returns the number of bytes enqueued, or an error if the socket is closed. + pub fn enqueue_buf(&mut self, data: &[u8]) -> AxResult { + match self.get_state() { + UnixSocketStatus::Closed => Err(AxError::BadState), + _ => Ok(UNIX_TABLE + .write() + .get_mut(self.get_sockethandle()) + .unwrap() + .lock() + .buf + .enqueue_slice(data)), + } + } + + /// Dequeues data from the socket buffer. + /// return the number of bytes dequeued, or a BadState error if the socket is closed or a WouldBlock error if buffer is empty. + pub fn dequeue_buf(&mut self, data: &mut [u8]) -> AxResult { + match self.get_state() { + UnixSocketStatus::Closed => Err(AxError::BadState), + _ => { + if UNIX_TABLE + .write() + .get_mut(self.get_sockethandle()) + .unwrap() + .lock() + .buf + .is_empty() + { + return Err(AxError::WouldBlock); + } + Ok(UNIX_TABLE + .write() + .get_mut(self.get_sockethandle()) + .unwrap() + .lock() + .buf + .dequeue_slice(data)) + } + } + } + + /// Binds the socket to a specified address, get inode number of the address as handle + // TODO: bind to file system + pub fn bind(&mut self, addr: SockaddrUn) -> LinuxResult { + let now_state = self.get_state(); + match now_state { + UnixSocketStatus::Closed => { + { + match get_inode(addr) { + Ok(inode_addr) => { + UNIX_TABLE + .write() + .replace_handle(self.get_sockethandle(), inode_addr); + self.set_sockethandle(inode_addr); + } + Err(AxError::NotFound) => match create_socket_file(addr) { + Ok(inode_addr) => { + UNIX_TABLE + .write() + .replace_handle(self.get_sockethandle(), inode_addr); + self.set_sockethandle(inode_addr); + } + _ => { + warn!("unix socket can not get real inode"); + } + }, + _ => { + warn!("unix socket can not get real inode"); + } + } + } + let mut binding = UNIX_TABLE.write(); + let mut socket_inner = binding.get_mut(self.get_sockethandle()).unwrap().lock(); + socket_inner.addr.lock().set_addr(&addr); + socket_inner.set_state(UnixSocketStatus::Busy); + Ok(()) + } + _ => Err(LinuxError::EINVAL), + } + } + + /// Sends data through the socket to the connected peer, push data into buffer of peer socket + /// this will block if not connected by default + pub fn send(&self, buf: &[u8]) -> LinuxResult { + match self.unixsocket_type { + UnixSocketType::SockDgram | UnixSocketType::SockSeqpacket => Err(LinuxError::ENOTCONN), + UnixSocketType::SockStream => loop { + let now_state = self.get_state(); + match now_state { + UnixSocketStatus::Connecting => { + if self.is_nonblocking() { + return Err(LinuxError::EINPROGRESS); + } else { + yield_now(); + } + } + UnixSocketStatus::Connected => { + let peer_handle = UNIX_TABLE + .read() + .get(self.get_sockethandle()) + .unwrap() + .lock() + .get_peersocket() + .unwrap(); + return Ok(UNIX_TABLE + .write() + .get_mut(peer_handle) + .unwrap() + .lock() + .buf + .enqueue_slice(buf)); + } + _ => { + return Err(LinuxError::ENOTCONN); + } + } + }, + } + } + + /// Receives data from the socket, check if there any data in buffer + /// this will block if not connected or buffer is empty by default + pub fn recv(&self, buf: &mut [u8], _flags: i32) -> LinuxResult { + match self.unixsocket_type { + UnixSocketType::SockDgram | UnixSocketType::SockSeqpacket => Err(LinuxError::ENOTCONN), + UnixSocketType::SockStream => loop { + let now_state = self.get_state(); + match now_state { + UnixSocketStatus::Connecting => { + if self.is_nonblocking() { + return Err(LinuxError::EAGAIN); + } else { + yield_now(); + } + } + UnixSocketStatus::Connected => { + if UNIX_TABLE + .read() + .get(self.get_sockethandle()) + .unwrap() + .lock() + .buf + .is_empty() + { + if self.is_nonblocking() { + return Err(LinuxError::EAGAIN); + } else { + yield_now(); + } + } else { + return Ok(UNIX_TABLE + .read() + .get(self.get_sockethandle()) + .unwrap() + .lock() + .buf + .dequeue_slice(buf)); + } + } + _ => { + return Err(LinuxError::ENOTCONN); + } + } + }, + } + } + + /// Polls the socket's readiness for connection. + fn poll_connect(&self) -> LinuxResult { + let writable = { + let mut binding = UNIX_TABLE.write(); + let mut socket_inner = binding.get_mut(self.get_sockethandle()).unwrap().lock(); + if !socket_inner.get_peersocket().is_none() { + socket_inner.set_state(UnixSocketStatus::Connected); + true + } else { + false + } + }; + Ok(PollState { + readable: false, + writable, + }) + } + + /// Polls the socket's readiness for reading or writing. + pub fn poll(&self) -> LinuxResult { + let now_state = self.get_state(); + match now_state { + UnixSocketStatus::Connecting => self.poll_connect(), + UnixSocketStatus::Connected => { + let mut binding = UNIX_TABLE.write(); + let mut socket_inner = binding.get_mut(self.get_sockethandle()).unwrap().lock(); + Ok(PollState { + readable: !socket_inner.may_recv() || socket_inner.can_recv(), + writable: !socket_inner.may_send() || socket_inner.can_send(), + }) + } + UnixSocketStatus::Listening => { + let mut binding = UNIX_TABLE.write(); + let mut socket_inner = binding.get_mut(self.get_sockethandle()).unwrap().lock(); + Ok(PollState { + readable: socket_inner.can_accept(), + writable: false, + }) + } + _ => Ok(PollState { + readable: false, + writable: false, + }), + } + } + + /// Returns the local address of the socket. + pub fn local_addr(&self) -> LinuxResult { + unimplemented!() + } + + /// Returns the file descriptor for the socket. + fn fd(&self) -> c_int { + UNIX_TABLE + .write() + .get_mut(self.get_sockethandle()) + .unwrap() + .lock() + .addr + .lock() + .sun_path[0] as _ + } + + /// Returns the peer address of the socket. + pub fn peer_addr(&self) -> AxResult { + let now_state = self.get_state(); + match now_state { + UnixSocketStatus::Connected | UnixSocketStatus::Listening => { + let peer_sockethandle = self.get_peerhandle().unwrap(); + Ok(UNIX_TABLE + .read() + .get(peer_sockethandle) + .unwrap() + .lock() + .get_addr()) + } + _ => Err(AxError::NotConnected), + } + } + + /// Connects the socket to a specified address, push info into remote socket + pub fn connect(&mut self, addr: SockaddrUn) -> LinuxResult { + let now_state = self.get_state(); + if now_state != UnixSocketStatus::Connecting && now_state != UnixSocketStatus::Connected { + //a new block is needed to free rwlock + { + match get_inode(addr) { + Ok(inode_addr) => { + let binding = UNIX_TABLE.write(); + let remote_socket = binding.get(inode_addr).unwrap(); + if remote_socket.lock().get_state() != UnixSocketStatus::Listening { + error!("unix conncet error: remote socket not listening"); + return Err(LinuxError::EFAULT); + } + let data = &self.get_sockethandle().to_ne_bytes(); + let _res = remote_socket.lock().buf.enqueue_slice(data); + } + Err(AxError::NotFound) => return Err(LinuxError::ENOENT), + _ => { + warn!("unix socket can not get real inode"); + let binding = UNIX_TABLE.write(); + let (_remote_sockethandle, remote_socket) = binding + .find(|socket| socket.lock().addr.lock().sun_path == addr.sun_path) + .unwrap(); + let data = &self.get_sockethandle().to_ne_bytes(); + let _res = remote_socket.lock().buf.enqueue_slice(data); + } + } + } + { + let mut binding = UNIX_TABLE.write(); + let mut socket_inner = binding.get_mut(self.get_sockethandle()).unwrap().lock(); + socket_inner.set_state(UnixSocketStatus::Connecting); + } + } + + loop { + let PollState { writable, .. } = self.poll_connect()?; + if !writable { + // When set to non_blocking, directly return inporgress + if self.is_nonblocking() { + return Err(LinuxError::EINPROGRESS); + } else { + yield_now(); + } + } else if self.get_state() == UnixSocketStatus::Connected { + return Ok(()); + } else { + // When set to non_blocking, directly return inporgress + if self.is_nonblocking() { + return Err(LinuxError::EINPROGRESS); + } + warn!("socket connect() failed") + } + } + } + + /// Sends data to a specified address. + pub fn sendto(&self, buf: &[u8], addr: SockaddrUn) -> LinuxResult { + unimplemented!() + } + + /// Receives data from the socket and returns the sender's address. + pub fn recvfrom(&self, buf: &mut [u8]) -> LinuxResult<(usize, Option)> { + unimplemented!() + } + + /// Listens for incoming connections on the socket. + // TODO: check file system + pub fn listen(&mut self) -> LinuxResult { + let now_state = self.get_state(); + match now_state { + UnixSocketStatus::Busy => { + let mut binding = UNIX_TABLE.write(); + let mut socket_inner = binding.get_mut(self.get_sockethandle()).unwrap().lock(); + socket_inner.set_state(UnixSocketStatus::Listening); + Ok(()) + } + _ => { + Ok(()) //ignore simultaneous `listen`s. + } + } + } + + /// Accepts a new connection from a listening socket, get info from self buffer + pub fn accept(&mut self) -> AxResult { + let now_state = self.get_state(); + match now_state { + UnixSocketStatus::Listening => { + //buf dequeue as handle to get socket + loop { + let data: &mut [u8] = &mut [0u8; core::mem::size_of::()]; + let res = self.dequeue_buf(data); + match res { + Ok(_len) => { + let mut array = [0u8; core::mem::size_of::()]; + array.copy_from_slice(data); + let remote_handle = usize::from_ne_bytes(array); + let unix_socket = UnixSocket::new(UnixSocketType::SockStream); + { + let mut binding = UNIX_TABLE.write(); + let remote_socket = binding.get_mut(remote_handle).unwrap(); + remote_socket + .lock() + .set_peersocket(unix_socket.get_sockethandle()); + } + let mut binding = UNIX_TABLE.write(); + let mut socket_inner = binding + .get_mut(unix_socket.get_sockethandle()) + .unwrap() + .lock(); + socket_inner.set_peersocket(remote_handle); + socket_inner.set_state(UnixSocketStatus::Connected); + return Ok(unix_socket); + } + Err(AxError::WouldBlock) => { + if self.is_nonblocking() { + return Err(AxError::WouldBlock); + } else { + yield_now(); + } + } + Err(e) => { + return Err(e); + } + } + } + } + _ => ax_err!(InvalidInput, "socket accept() failed: not listen"), + } + } + + //TODO + /// Shuts down the socket. + pub fn shutdown(&self) -> LinuxResult { + unimplemented!() + } + + /// Returns whether this socket is in nonblocking mode. + #[inline] + pub fn is_nonblocking(&self) -> bool { + self.nonblock.load(Ordering::Acquire) + } + + /// Sets the nonblocking mode for the socket. + pub fn set_nonblocking(&self, nonblocking: bool) { + self.nonblock.store(nonblocking, Ordering::Release); + } + + /// Checks if the socket is in a listening state. + pub fn is_listening(&self) -> bool { + let now_state = self.get_state(); + match now_state { + UnixSocketStatus::Listening => true, + _ => false, + } + } + + /// Returns the socket type of the `UnixSocket`. + pub fn get_sockettype(&self) -> UnixSocketType { + self.unixsocket_type + } +} + +/// Initializes the global UNIX socket table, `UNIX_TABLE`, for managing Unix domain sockets. +pub(crate) fn init_unix() { + UNIX_TABLE.init_by(RwLock::new(HashMapWarpper::new())); +}