1 // The following definitions are correct for aarch64 and x86_64, 2 // but may be wrong for mips64 3 4 pub type c_long = i64; 5 pub type c_ulong = u64; 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 pub struct sigaction { 16 pub sa_flags: ::c_int, 17 pub sa_sigaction: ::sighandler_t, 18 pub sa_mask: ::sigset_t, 19 pub sa_restorer: ::Option<extern fn()>, 20 } 21 22 pub struct rlimit64 { 23 pub rlim_cur: ::c_ulonglong, 24 pub rlim_max: ::c_ulonglong, 25 } 26 27 pub struct pthread_attr_t { 28 pub flags: u32, 29 pub stack_base: *mut ::c_void, 30 pub stack_size: ::size_t, 31 pub guard_size: ::size_t, 32 pub sched_policy: i32, 33 pub sched_priority: i32, 34 __reserved: [::c_char; 16], 35 } 36 37 pub struct passwd { 38 pub pw_name: *mut ::c_char, 39 pub pw_passwd: *mut ::c_char, 40 pub pw_uid: ::uid_t, 41 pub pw_gid: ::gid_t, 42 pub pw_gecos: *mut ::c_char, 43 pub pw_dir: *mut ::c_char, 44 pub pw_shell: *mut ::c_char, 45 } 46 47 pub struct statfs { 48 pub f_type: u64, 49 pub f_bsize: u64, 50 pub f_blocks: u64, 51 pub f_bfree: u64, 52 pub f_bavail: u64, 53 pub f_files: u64, 54 pub f_ffree: u64, 55 pub f_fsid: ::__fsid_t, 56 pub f_namelen: u64, 57 pub f_frsize: u64, 58 pub f_flags: u64, 59 pub f_spare: [u64; 4], 60 } 61 62 pub struct sysinfo { 63 pub uptime: ::c_long, 64 pub loads: [::c_ulong; 3], 65 pub totalram: ::c_ulong, 66 pub freeram: ::c_ulong, 67 pub sharedram: ::c_ulong, 68 pub bufferram: ::c_ulong, 69 pub totalswap: ::c_ulong, 70 pub freeswap: ::c_ulong, 71 pub procs: ::c_ushort, 72 pub pad: ::c_ushort, 73 pub totalhigh: ::c_ulong, 74 pub freehigh: ::c_ulong, 75 pub mem_unit: ::c_uint, 76 pub _f: [::c_char; 0], 77 } 78 79 pub struct statfs64 { 80 pub f_type: u64, 81 pub f_bsize: u64, 82 pub f_blocks: u64, 83 pub f_bfree: u64, 84 pub f_bavail: u64, 85 pub f_files: u64, 86 pub f_ffree: u64, 87 pub f_fsid: ::__fsid_t, 88 pub f_namelen: u64, 89 pub f_frsize: u64, 90 pub f_flags: u64, 91 pub f_spare: [u64; 4], 92 } 93 94 pub struct statvfs64 { 95 pub f_bsize: ::c_ulong, 96 pub f_frsize: ::c_ulong, 97 pub f_blocks: u64, 98 pub f_bfree: u64, 99 pub f_bavail: u64, 100 pub f_files: u64, 101 pub f_ffree: u64, 102 pub f_favail: u64, 103 pub f_fsid: ::c_ulong, 104 pub f_flag: ::c_ulong, 105 pub f_namemax: ::c_ulong, 106 __f_spare: [::c_int; 6], 107 } 108 } 109 110 s_no_extra_traits! { 111 pub struct pthread_mutex_t { 112 value: ::c_int, 113 __reserved: [::c_char; 36], 114 } 115 116 pub struct pthread_cond_t { 117 value: ::c_int, 118 __reserved: [::c_char; 44], 119 } 120 121 pub struct pthread_rwlock_t { 122 numLocks: ::c_int, 123 writerThreadId: ::c_int, 124 pendingReaders: ::c_int, 125 pendingWriters: ::c_int, 126 attr: i32, 127 __reserved: [::c_char; 36], 128 } 129 130 pub struct sigset64_t { 131 __bits: [::c_ulong; 1] 132 } 133 } 134 135 cfg_if! { 136 if #[cfg(feature = "extra_traits")] { 137 impl PartialEq for pthread_mutex_t { 138 fn eq(&self, other: &pthread_mutex_t) -> bool { 139 self.value == other.value 140 && self 141 .__reserved 142 .iter() 143 .zip(other.__reserved.iter()) 144 .all(|(a,b)| a == b) 145 } 146 } 147 148 impl Eq for pthread_mutex_t {} 149 150 impl ::fmt::Debug for pthread_mutex_t { 151 fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { 152 f.debug_struct("pthread_mutex_t") 153 .field("value", &self.value) 154 // FIXME: .field("__reserved", &self.__reserved) 155 .finish() 156 } 157 } 158 159 impl ::hash::Hash for pthread_mutex_t { 160 fn hash<H: ::hash::Hasher>(&self, state: &mut H) { 161 self.value.hash(state); 162 self.__reserved.hash(state); 163 } 164 } 165 166 impl PartialEq for pthread_cond_t { 167 fn eq(&self, other: &pthread_cond_t) -> bool { 168 self.value == other.value 169 && self 170 .__reserved 171 .iter() 172 .zip(other.__reserved.iter()) 173 .all(|(a,b)| a == b) 174 } 175 } 176 177 impl Eq for pthread_cond_t {} 178 179 impl ::fmt::Debug for pthread_cond_t { 180 fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { 181 f.debug_struct("pthread_cond_t") 182 .field("value", &self.value) 183 // FIXME: .field("__reserved", &self.__reserved) 184 .finish() 185 } 186 } 187 188 impl ::hash::Hash for pthread_cond_t { 189 fn hash<H: ::hash::Hasher>(&self, state: &mut H) { 190 self.value.hash(state); 191 self.__reserved.hash(state); 192 } 193 } 194 195 impl PartialEq for pthread_rwlock_t { 196 fn eq(&self, other: &pthread_rwlock_t) -> bool { 197 self.numLocks == other.numLocks 198 && self.writerThreadId == other.writerThreadId 199 && self.pendingReaders == other.pendingReaders 200 && self.pendingWriters == other.pendingWriters 201 && self.attr == other.attr 202 && self 203 .__reserved 204 .iter() 205 .zip(other.__reserved.iter()) 206 .all(|(a,b)| a == b) 207 } 208 } 209 210 impl Eq for pthread_rwlock_t {} 211 212 impl ::fmt::Debug for pthread_rwlock_t { 213 fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { 214 f.debug_struct("pthread_rwlock_t") 215 .field("numLocks", &self.numLocks) 216 .field("writerThreadId", &self.writerThreadId) 217 .field("pendingReaders", &self.pendingReaders) 218 .field("pendingWriters", &self.pendingWriters) 219 .field("attr", &self.attr) 220 // FIXME: .field("__reserved", &self.__reserved) 221 .finish() 222 } 223 } 224 225 impl ::hash::Hash for pthread_rwlock_t { 226 fn hash<H: ::hash::Hasher>(&self, state: &mut H) { 227 self.numLocks.hash(state); 228 self.writerThreadId.hash(state); 229 self.pendingReaders.hash(state); 230 self.pendingWriters.hash(state); 231 self.attr.hash(state); 232 self.__reserved.hash(state); 233 } 234 } 235 236 impl ::fmt::Debug for sigset64_t { 237 fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { 238 f.debug_struct("sigset64_t") 239 .field("__bits", &self.__bits) 240 .finish() 241 } 242 } 243 } 244 } 245 246 // These constants must be of the same type of sigaction.sa_flags 247 pub const SA_NOCLDSTOP: ::c_int = 0x00000001; 248 pub const SA_NOCLDWAIT: ::c_int = 0x00000002; 249 pub const SA_NODEFER: ::c_int = 0x40000000; 250 pub const SA_ONSTACK: ::c_int = 0x08000000; 251 pub const SA_RESETHAND: ::c_int = 0x80000000; 252 pub const SA_RESTART: ::c_int = 0x10000000; 253 pub const SA_SIGINFO: ::c_int = 0x00000004; 254 255 pub const RTLD_GLOBAL: ::c_int = 0x00100; 256 pub const RTLD_NOW: ::c_int = 2; 257 pub const RTLD_DEFAULT: *mut ::c_void = 0i64 as *mut ::c_void; 258 259 // From NDK's linux/auxvec.h 260 pub const AT_NULL: ::c_ulong = 0; 261 pub const AT_IGNORE: ::c_ulong = 1; 262 pub const AT_EXECFD: ::c_ulong = 2; 263 pub const AT_PHDR: ::c_ulong = 3; 264 pub const AT_PHENT: ::c_ulong = 4; 265 pub const AT_PHNUM: ::c_ulong = 5; 266 pub const AT_PAGESZ: ::c_ulong = 6; 267 pub const AT_BASE: ::c_ulong = 7; 268 pub const AT_FLAGS: ::c_ulong = 8; 269 pub const AT_ENTRY: ::c_ulong = 9; 270 pub const AT_NOTELF: ::c_ulong = 10; 271 pub const AT_UID: ::c_ulong = 11; 272 pub const AT_EUID: ::c_ulong = 12; 273 pub const AT_GID: ::c_ulong = 13; 274 pub const AT_EGID: ::c_ulong = 14; 275 pub const AT_PLATFORM: ::c_ulong = 15; 276 pub const AT_HWCAP: ::c_ulong = 16; 277 pub const AT_CLKTCK: ::c_ulong = 17; 278 pub const AT_SECURE: ::c_ulong = 23; 279 pub const AT_BASE_PLATFORM: ::c_ulong = 24; 280 pub const AT_RANDOM: ::c_ulong = 25; 281 pub const AT_HWCAP2: ::c_ulong = 26; 282 pub const AT_EXECFN: ::c_ulong = 31; 283 284 pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { 285 value: 0, 286 __reserved: [0; 36], 287 }; 288 pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { 289 value: 0, 290 __reserved: [0; 44], 291 }; 292 pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { 293 numLocks: 0, 294 writerThreadId: 0, 295 pendingReaders: 0, 296 pendingWriters: 0, 297 attr: 0, 298 __reserved: [0; 36], 299 }; 300 pub const PTHREAD_STACK_MIN: ::size_t = 4096 * 4; 301 pub const CPU_SETSIZE: ::size_t = 1024; 302 pub const __CPU_BITS: ::size_t = 64; 303 304 pub const UT_LINESIZE: usize = 32; 305 pub const UT_NAMESIZE: usize = 32; 306 pub const UT_HOSTSIZE: usize = 256; 307 308 extern "C" { getauxval(type_: ::c_ulong) -> ::c_ulong309 pub fn getauxval(type_: ::c_ulong) -> ::c_ulong; 310 } 311 312 cfg_if! { 313 if #[cfg(target_arch = "x86_64")] { 314 mod x86_64; 315 pub use self::x86_64::*; 316 } else if #[cfg(target_arch = "aarch64")] { 317 mod aarch64; 318 pub use self::aarch64::*; 319 } else { 320 // Unknown target_arch 321 } 322 } 323