1 use crate::prelude::*; 2 3 // The following definitions are correct for aarch64 and x86_64, 4 // but may be wrong for mips64 5 6 pub type mode_t = u32; 7 pub type off64_t = i64; 8 pub type socklen_t = u32; 9 10 s! { 11 pub struct sigset_t { 12 __val: [c_ulong; 1], 13 } 14 15 // FIXME(1.0): This should not implement `PartialEq` 16 #[allow(unpredictable_function_pointer_comparisons)] 17 pub struct sigaction { 18 pub sa_flags: c_int, 19 pub sa_sigaction: crate::sighandler_t, 20 pub sa_mask: crate::sigset_t, 21 pub sa_restorer: Option<extern "C" fn()>, 22 } 23 24 pub struct rlimit64 { 25 pub rlim_cur: c_ulonglong, 26 pub rlim_max: c_ulonglong, 27 } 28 29 pub struct pthread_attr_t { 30 pub flags: u32, 31 pub stack_base: *mut c_void, 32 pub stack_size: size_t, 33 pub guard_size: size_t, 34 pub sched_policy: i32, 35 pub sched_priority: i32, 36 __reserved: [c_char; 16], 37 } 38 39 pub struct passwd { 40 pub pw_name: *mut c_char, 41 pub pw_passwd: *mut c_char, 42 pub pw_uid: crate::uid_t, 43 pub pw_gid: crate::gid_t, 44 pub pw_gecos: *mut c_char, 45 pub pw_dir: *mut c_char, 46 pub pw_shell: *mut c_char, 47 } 48 49 pub struct statfs { 50 pub f_type: u64, 51 pub f_bsize: u64, 52 pub f_blocks: u64, 53 pub f_bfree: u64, 54 pub f_bavail: u64, 55 pub f_files: u64, 56 pub f_ffree: u64, 57 pub f_fsid: crate::__fsid_t, 58 pub f_namelen: u64, 59 pub f_frsize: u64, 60 pub f_flags: u64, 61 pub f_spare: [u64; 4], 62 } 63 64 pub struct sysinfo { 65 pub uptime: c_long, 66 pub loads: [c_ulong; 3], 67 pub totalram: c_ulong, 68 pub freeram: c_ulong, 69 pub sharedram: c_ulong, 70 pub bufferram: c_ulong, 71 pub totalswap: c_ulong, 72 pub freeswap: c_ulong, 73 pub procs: c_ushort, 74 pub pad: c_ushort, 75 pub totalhigh: c_ulong, 76 pub freehigh: c_ulong, 77 pub mem_unit: c_uint, 78 pub _f: [c_char; 0], 79 } 80 81 pub struct statfs64 { 82 pub f_type: u64, 83 pub f_bsize: u64, 84 pub f_blocks: u64, 85 pub f_bfree: u64, 86 pub f_bavail: u64, 87 pub f_files: u64, 88 pub f_ffree: u64, 89 pub f_fsid: crate::__fsid_t, 90 pub f_namelen: u64, 91 pub f_frsize: u64, 92 pub f_flags: u64, 93 pub f_spare: [u64; 4], 94 } 95 96 pub struct statvfs64 { 97 pub f_bsize: c_ulong, 98 pub f_frsize: c_ulong, 99 pub f_blocks: u64, 100 pub f_bfree: u64, 101 pub f_bavail: u64, 102 pub f_files: u64, 103 pub f_ffree: u64, 104 pub f_favail: u64, 105 pub f_fsid: c_ulong, 106 pub f_flag: c_ulong, 107 pub f_namemax: c_ulong, 108 __f_spare: [c_int; 6], 109 } 110 111 pub struct pthread_barrier_t { 112 __private: [i64; 4], 113 } 114 115 pub struct pthread_spinlock_t { 116 __private: i64, 117 } 118 } 119 120 s_no_extra_traits! { 121 pub struct pthread_mutex_t { 122 value: c_int, 123 __reserved: [c_char; 36], 124 } 125 126 pub struct pthread_cond_t { 127 value: c_int, 128 __reserved: [c_char; 44], 129 } 130 131 pub struct pthread_rwlock_t { 132 numLocks: c_int, 133 writerThreadId: c_int, 134 pendingReaders: c_int, 135 pendingWriters: c_int, 136 attr: i32, 137 __reserved: [c_char; 36], 138 } 139 140 pub struct sigset64_t { 141 __bits: [c_ulong; 1], 142 } 143 } 144 145 cfg_if! { 146 if #[cfg(feature = "extra_traits")] { 147 impl PartialEq for pthread_mutex_t { 148 fn eq(&self, other: &pthread_mutex_t) -> bool { 149 self.value == other.value 150 && self 151 .__reserved 152 .iter() 153 .zip(other.__reserved.iter()) 154 .all(|(a, b)| a == b) 155 } 156 } 157 158 impl Eq for pthread_mutex_t {} 159 160 impl hash::Hash for pthread_mutex_t { 161 fn hash<H: hash::Hasher>(&self, state: &mut H) { 162 self.value.hash(state); 163 self.__reserved.hash(state); 164 } 165 } 166 167 impl PartialEq for pthread_cond_t { 168 fn eq(&self, other: &pthread_cond_t) -> bool { 169 self.value == other.value 170 && self 171 .__reserved 172 .iter() 173 .zip(other.__reserved.iter()) 174 .all(|(a, b)| a == b) 175 } 176 } 177 178 impl Eq for pthread_cond_t {} 179 180 impl hash::Hash for pthread_cond_t { 181 fn hash<H: hash::Hasher>(&self, state: &mut H) { 182 self.value.hash(state); 183 self.__reserved.hash(state); 184 } 185 } 186 187 impl PartialEq for pthread_rwlock_t { 188 fn eq(&self, other: &pthread_rwlock_t) -> bool { 189 self.numLocks == other.numLocks 190 && self.writerThreadId == other.writerThreadId 191 && self.pendingReaders == other.pendingReaders 192 && self.pendingWriters == other.pendingWriters 193 && self.attr == other.attr 194 && self 195 .__reserved 196 .iter() 197 .zip(other.__reserved.iter()) 198 .all(|(a, b)| a == b) 199 } 200 } 201 202 impl Eq for pthread_rwlock_t {} 203 204 impl hash::Hash for pthread_rwlock_t { 205 fn hash<H: hash::Hasher>(&self, state: &mut H) { 206 self.numLocks.hash(state); 207 self.writerThreadId.hash(state); 208 self.pendingReaders.hash(state); 209 self.pendingWriters.hash(state); 210 self.attr.hash(state); 211 self.__reserved.hash(state); 212 } 213 } 214 } 215 } 216 217 // These constants must be of the same type of sigaction.sa_flags 218 pub const SA_NOCLDSTOP: c_int = 0x00000001; 219 pub const SA_NOCLDWAIT: c_int = 0x00000002; 220 pub const SA_NODEFER: c_int = 0x40000000; 221 pub const SA_ONSTACK: c_int = 0x08000000; 222 pub const SA_RESETHAND: c_int = 0x80000000; 223 pub const SA_RESTART: c_int = 0x10000000; 224 pub const SA_SIGINFO: c_int = 0x00000004; 225 226 pub const RTLD_GLOBAL: c_int = 0x00100; 227 pub const RTLD_NOW: c_int = 2; 228 pub const RTLD_DEFAULT: *mut c_void = 0i64 as *mut c_void; 229 230 pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { 231 value: 0, 232 __reserved: [0; 36], 233 }; 234 pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { 235 value: 0, 236 __reserved: [0; 44], 237 }; 238 pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { 239 numLocks: 0, 240 writerThreadId: 0, 241 pendingReaders: 0, 242 pendingWriters: 0, 243 attr: 0, 244 __reserved: [0; 36], 245 }; 246 pub const PTHREAD_STACK_MIN: size_t = 4096 * 4; 247 pub const CPU_SETSIZE: size_t = 1024; 248 pub const __CPU_BITS: size_t = 64; 249 250 pub const UT_LINESIZE: usize = 32; 251 pub const UT_NAMESIZE: usize = 32; 252 pub const UT_HOSTSIZE: usize = 256; 253 254 f! { 255 // Sadly, Android before 5.0 (API level 21), the accept4 syscall is not 256 // exposed by the libc. As work-around, we implement it through `syscall` 257 // directly. This workaround can be removed if the minimum version of 258 // Android is bumped. When the workaround is removed, `accept4` can be 259 // moved back to `linux_like/mod.rs` 260 pub fn accept4( 261 fd: c_int, 262 addr: *mut crate::sockaddr, 263 len: *mut crate::socklen_t, 264 flg: c_int, 265 ) -> c_int { 266 crate::syscall(SYS_accept4, fd, addr, len, flg) as c_int 267 } 268 } 269 270 extern "C" { __system_property_wait( pi: *const crate::prop_info, __old_serial: u32, __new_serial_ptr: *mut u32, __relative_timeout: *const crate::timespec, ) -> bool271 pub fn __system_property_wait( 272 pi: *const crate::prop_info, 273 __old_serial: u32, 274 __new_serial_ptr: *mut u32, 275 __relative_timeout: *const crate::timespec, 276 ) -> bool; 277 } 278 279 cfg_if! { 280 if #[cfg(target_arch = "x86_64")] { 281 mod x86_64; 282 pub use self::x86_64::*; 283 } else if #[cfg(target_arch = "aarch64")] { 284 mod aarch64; 285 pub use self::aarch64::*; 286 } else if #[cfg(target_arch = "riscv64")] { 287 mod riscv64; 288 pub use self::riscv64::*; 289 } else { 290 // Unknown target_arch 291 } 292 } 293