1 //! 32-bit specific definitions for linux-like values 2 3 use crate::prelude::*; 4 use crate::pthread_mutex_t; 5 6 pub type clock_t = i32; 7 8 pub type shmatt_t = c_ulong; 9 pub type msgqnum_t = c_ulong; 10 pub type msglen_t = c_ulong; 11 pub type nlink_t = u32; 12 pub type __u64 = c_ulonglong; 13 pub type __s64 = c_longlong; 14 pub type __fsword_t = i32; 15 pub type fsblkcnt64_t = u64; 16 pub type fsfilcnt64_t = u64; 17 pub type __syscall_ulong_t = c_ulong; 18 pub type __suseconds64_t = i64; 19 20 cfg_if! { 21 if #[cfg(target_arch = "riscv32")] { 22 pub type time_t = i64; 23 pub type suseconds_t = i64; 24 type __ino_t = c_ulong; 25 type __ino64_t = u64; 26 pub type ino_t = __ino64_t; 27 pub type off_t = i64; 28 pub type blkcnt_t = i64; 29 pub type fsblkcnt_t = u64; 30 pub type fsfilcnt_t = u64; 31 pub type rlim_t = u64; 32 pub type blksize_t = i64; 33 } else if #[cfg(gnu_time_bits64)] { 34 pub type time_t = i64; 35 pub type suseconds_t = i32; 36 type __ino_t = c_ulong; 37 type __ino64_t = u64; 38 pub type ino_t = __ino64_t; 39 pub type off_t = i64; 40 pub type blkcnt_t = i64; 41 pub type fsblkcnt_t = u64; 42 pub type fsfilcnt_t = u64; 43 pub type rlim_t = u64; 44 pub type blksize_t = i32; 45 } else if #[cfg(gnu_file_offset_bits64)] { 46 pub type time_t = i32; 47 pub type suseconds_t = i32; 48 type __ino_t = c_ulong; 49 type __ino64_t = u64; 50 pub type ino_t = __ino64_t; 51 pub type off_t = i64; 52 pub type blkcnt_t = i64; 53 pub type fsblkcnt_t = u64; 54 pub type fsfilcnt_t = u64; 55 pub type rlim_t = u64; 56 pub type blksize_t = i32; 57 } else { 58 pub type time_t = i32; 59 pub type suseconds_t = i32; 60 type __ino_t = c_ulong; 61 type __ino64_t = u64; 62 pub type ino_t = __ino_t; 63 pub type off_t = i32; 64 pub type blkcnt_t = i32; 65 pub type fsblkcnt_t = c_ulong; 66 pub type fsfilcnt_t = c_ulong; 67 pub type rlim_t = c_ulong; 68 pub type blksize_t = i32; 69 } 70 } 71 72 cfg_if! { 73 if #[cfg(not(any( 74 target_arch = "mips", 75 target_arch = "mips32r6", 76 target_arch = "powerpc", 77 target_arch = "sparc" 78 )))] { 79 s! { 80 pub struct stat { 81 pub st_dev: crate::dev_t, 82 83 #[cfg(not(gnu_time_bits64))] 84 __pad1: c_uint, 85 86 #[cfg(any(gnu_time_bits64, not(gnu_file_offset_bits64)))] 87 pub st_ino: crate::ino_t, 88 #[cfg(all(not(gnu_time_bits64), gnu_file_offset_bits64))] 89 __st_ino: __ino_t, 90 91 pub st_mode: crate::mode_t, 92 pub st_nlink: crate::nlink_t, 93 pub st_uid: crate::uid_t, 94 pub st_gid: crate::gid_t, 95 96 pub st_rdev: crate::dev_t, 97 98 #[cfg(not(gnu_time_bits64))] 99 __pad2: c_uint, 100 101 pub st_size: off_t, 102 103 pub st_blksize: crate::blksize_t, 104 pub st_blocks: crate::blkcnt_t, 105 106 pub st_atime: crate::time_t, 107 pub st_atime_nsec: c_long, 108 #[cfg(gnu_time_bits64)] 109 _atime_pad: c_int, 110 pub st_mtime: crate::time_t, 111 pub st_mtime_nsec: c_long, 112 #[cfg(gnu_time_bits64)] 113 _mtime_pad: c_int, 114 pub st_ctime: crate::time_t, 115 pub st_ctime_nsec: c_long, 116 #[cfg(gnu_time_bits64)] 117 _ctime_pad: c_int, 118 119 #[cfg(not(gnu_file_offset_bits64))] 120 __glibc_reserved4: c_long, 121 #[cfg(not(gnu_file_offset_bits64))] 122 __glibc_reserved5: c_long, 123 #[cfg(all(not(gnu_time_bits64), gnu_file_offset_bits64))] 124 pub st_ino: crate::ino_t, 125 } 126 } 127 } 128 } 129 130 s! { 131 pub struct statvfs { 132 pub f_bsize: c_ulong, 133 pub f_frsize: c_ulong, 134 pub f_blocks: crate::fsblkcnt_t, 135 pub f_bfree: crate::fsblkcnt_t, 136 pub f_bavail: crate::fsblkcnt_t, 137 pub f_files: crate::fsfilcnt_t, 138 pub f_ffree: crate::fsfilcnt_t, 139 pub f_favail: crate::fsfilcnt_t, 140 pub f_fsid: c_ulong, 141 __f_unused: c_int, 142 pub f_flag: c_ulong, 143 pub f_namemax: c_ulong, 144 __f_spare: [c_int; 6], 145 } 146 147 pub struct pthread_attr_t { 148 __size: [u32; 9], 149 } 150 151 pub struct sigset_t { 152 __val: [c_ulong; 32], 153 } 154 155 pub struct sysinfo { 156 pub uptime: c_long, 157 pub loads: [c_ulong; 3], 158 pub totalram: c_ulong, 159 pub freeram: c_ulong, 160 pub sharedram: c_ulong, 161 pub bufferram: c_ulong, 162 pub totalswap: c_ulong, 163 pub freeswap: c_ulong, 164 pub procs: c_ushort, 165 #[deprecated( 166 since = "0.2.58", 167 note = "This padding field might become private in the future" 168 )] 169 pub pad: c_ushort, 170 pub totalhigh: c_ulong, 171 pub freehigh: c_ulong, 172 pub mem_unit: c_uint, 173 pub _f: [c_char; 8], 174 } 175 176 pub struct semid_ds { 177 pub sem_perm: ipc_perm, 178 #[cfg(all(not(gnu_time_bits64), target_arch = "powerpc"))] 179 __reserved: crate::__syscall_ulong_t, 180 pub sem_otime: crate::time_t, 181 #[cfg(not(any( 182 gnu_time_bits64, 183 target_arch = "mips", 184 target_arch = "mips32r6", 185 target_arch = "powerpc" 186 )))] 187 __reserved: crate::__syscall_ulong_t, 188 #[cfg(all(not(gnu_time_bits64), target_arch = "powerpc"))] 189 __reserved2: crate::__syscall_ulong_t, 190 pub sem_ctime: crate::time_t, 191 #[cfg(not(any( 192 gnu_time_bits64, 193 target_arch = "mips", 194 target_arch = "mips32r6", 195 target_arch = "powerpc" 196 )))] 197 __reserved2: crate::__syscall_ulong_t, 198 pub sem_nsems: crate::__syscall_ulong_t, 199 #[cfg(all( 200 gnu_time_bits64, 201 not(any( 202 target_arch = "mips", 203 target_arch = "mips32r6", 204 target_arch = "powerpc", 205 target_arch = "arm", 206 target_arch = "x86" 207 )) 208 ))] 209 __reserved2: crate::__syscall_ulong_t, 210 __glibc_reserved3: crate::__syscall_ulong_t, 211 __glibc_reserved4: crate::__syscall_ulong_t, 212 } 213 214 #[cfg(gnu_time_bits64)] 215 pub struct timex { 216 pub modes: c_uint, 217 _pad1: c_int, 218 pub offset: c_longlong, 219 pub freq: c_longlong, 220 pub maxerror: c_longlong, 221 pub esterror: c_longlong, 222 pub status: c_int, 223 _pad2: c_int, 224 pub constant: c_longlong, 225 pub precision: c_longlong, 226 pub tolerance: c_longlong, 227 pub time: crate::timeval, 228 pub tick: c_longlong, 229 pub ppsfreq: c_longlong, 230 pub jitter: c_longlong, 231 pub shift: c_int, 232 _pad3: c_int, 233 pub stabil: c_longlong, 234 pub jitcnt: c_longlong, 235 pub calcnt: c_longlong, 236 pub errcnt: c_longlong, 237 pub stbcnt: c_longlong, 238 pub tai: c_int, 239 pub __unused1: i32, 240 pub __unused2: i32, 241 pub __unused3: i32, 242 pub __unused4: i32, 243 pub __unused5: i32, 244 pub __unused6: i32, 245 pub __unused7: i32, 246 pub __unused8: i32, 247 pub __unused9: i32, 248 pub __unused10: i32, 249 pub __unused11: i32, 250 } 251 252 #[cfg(not(gnu_time_bits64))] 253 pub struct timex { 254 pub modes: c_uint, 255 pub offset: c_long, 256 pub freq: c_long, 257 pub maxerror: c_long, 258 pub esterror: c_long, 259 pub status: c_int, 260 pub constant: c_long, 261 pub precision: c_long, 262 pub tolerance: c_long, 263 pub time: crate::timeval, 264 pub tick: c_long, 265 pub ppsfreq: c_long, 266 pub jitter: c_long, 267 pub shift: c_int, 268 pub stabil: c_long, 269 pub jitcnt: c_long, 270 pub calcnt: c_long, 271 pub errcnt: c_long, 272 pub stbcnt: c_long, 273 pub tai: c_int, 274 pub __unused1: i32, 275 pub __unused2: i32, 276 pub __unused3: i32, 277 pub __unused4: i32, 278 pub __unused5: i32, 279 pub __unused6: i32, 280 pub __unused7: i32, 281 pub __unused8: i32, 282 pub __unused9: i32, 283 pub __unused10: i32, 284 pub __unused11: i32, 285 } 286 } 287 288 pub const POSIX_FADV_DONTNEED: c_int = 4; 289 pub const POSIX_FADV_NOREUSE: c_int = 5; 290 291 pub const F_OFD_GETLK: c_int = 36; 292 pub const F_OFD_SETLK: c_int = 37; 293 pub const F_OFD_SETLKW: c_int = 38; 294 295 pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4; 296 pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 24; 297 pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32; 298 pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 20; 299 pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4; 300 pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8; 301 pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4; 302 303 cfg_if! { 304 if #[cfg(target_arch = "sparc")] { 305 pub const O_NOATIME: c_int = 0x200000; 306 pub const O_PATH: c_int = 0x1000000; 307 pub const O_TMPFILE: c_int = 0x2000000 | O_DIRECTORY; 308 309 pub const SA_ONSTACK: c_int = 1; 310 311 pub const PTRACE_DETACH: c_uint = 11; 312 313 pub const F_RDLCK: c_int = 1; 314 pub const F_WRLCK: c_int = 2; 315 pub const F_UNLCK: c_int = 3; 316 317 pub const SFD_CLOEXEC: c_int = 0x400000; 318 319 pub const NCCS: usize = 17; 320 321 pub const O_TRUNC: c_int = 0x400; 322 pub const O_CLOEXEC: c_int = 0x400000; 323 324 pub const EBFONT: c_int = 109; 325 pub const ENOSTR: c_int = 72; 326 pub const ENODATA: c_int = 111; 327 pub const ETIME: c_int = 73; 328 pub const ENOSR: c_int = 74; 329 pub const ENONET: c_int = 80; 330 pub const ENOPKG: c_int = 113; 331 pub const EREMOTE: c_int = 71; 332 pub const ENOLINK: c_int = 82; 333 pub const EADV: c_int = 83; 334 pub const ESRMNT: c_int = 84; 335 pub const ECOMM: c_int = 85; 336 pub const EPROTO: c_int = 86; 337 pub const EDOTDOT: c_int = 88; 338 339 pub const SA_NODEFER: c_int = 0x20; 340 pub const SA_RESETHAND: c_int = 0x4; 341 pub const SA_RESTART: c_int = 0x2; 342 pub const SA_NOCLDSTOP: c_int = 0x00000008; 343 344 pub const EPOLL_CLOEXEC: c_int = 0x400000; 345 346 pub const EFD_CLOEXEC: c_int = 0x400000; 347 } else { 348 pub const O_NOATIME: c_int = 0o1000000; 349 pub const O_PATH: c_int = 0o10000000; 350 pub const O_TMPFILE: c_int = 0o20000000 | O_DIRECTORY; 351 352 pub const SA_ONSTACK: c_int = 0x08000000; 353 354 pub const PTRACE_DETACH: c_uint = 17; 355 356 pub const F_RDLCK: c_int = 0; 357 pub const F_WRLCK: c_int = 1; 358 pub const F_UNLCK: c_int = 2; 359 360 pub const SFD_CLOEXEC: c_int = 0x080000; 361 362 pub const NCCS: usize = 32; 363 364 pub const O_TRUNC: c_int = 512; 365 pub const O_CLOEXEC: c_int = 0x80000; 366 pub const EBFONT: c_int = 59; 367 pub const ENOSTR: c_int = 60; 368 pub const ENODATA: c_int = 61; 369 pub const ETIME: c_int = 62; 370 pub const ENOSR: c_int = 63; 371 pub const ENONET: c_int = 64; 372 pub const ENOPKG: c_int = 65; 373 pub const EREMOTE: c_int = 66; 374 pub const ENOLINK: c_int = 67; 375 pub const EADV: c_int = 68; 376 pub const ESRMNT: c_int = 69; 377 pub const ECOMM: c_int = 70; 378 pub const EPROTO: c_int = 71; 379 pub const EDOTDOT: c_int = 73; 380 381 pub const SA_NODEFER: c_int = 0x40000000; 382 pub const SA_RESETHAND: c_int = 0x80000000; 383 pub const SA_RESTART: c_int = 0x10000000; 384 pub const SA_NOCLDSTOP: c_int = 0x00000001; 385 386 pub const EPOLL_CLOEXEC: c_int = 0x80000; 387 388 pub const EFD_CLOEXEC: c_int = 0x80000; 389 } 390 } 391 cfg_if! { 392 if #[cfg(target_arch = "sparc")] { 393 pub const F_SETLK: c_int = 8; 394 pub const F_SETLKW: c_int = 9; 395 } else if #[cfg(all( 396 gnu_file_offset_bits64, 397 any(target_arch = "mips", target_arch = "mips32r6") 398 ))] { 399 pub const F_SETLK: c_int = 34; 400 pub const F_SETLKW: c_int = 35; 401 } else if #[cfg(gnu_file_offset_bits64)] { 402 pub const F_SETLK: c_int = 13; 403 pub const F_SETLKW: c_int = 14; 404 } else { 405 pub const F_SETLK: c_int = 6; 406 pub const F_SETLKW: c_int = 7; 407 } 408 } 409 410 #[cfg(target_endian = "little")] 411 pub const PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP: crate::pthread_mutex_t = pthread_mutex_t { 412 size: [ 413 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 414 ], 415 }; 416 #[cfg(target_endian = "little")] 417 pub const PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP: crate::pthread_mutex_t = pthread_mutex_t { 418 size: [ 419 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 420 ], 421 }; 422 #[cfg(target_endian = "little")] 423 pub const PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP: crate::pthread_mutex_t = pthread_mutex_t { 424 size: [ 425 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 426 ], 427 }; 428 #[cfg(target_endian = "big")] 429 pub const PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP: crate::pthread_mutex_t = pthread_mutex_t { 430 size: [ 431 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 432 ], 433 }; 434 #[cfg(target_endian = "big")] 435 pub const PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP: crate::pthread_mutex_t = pthread_mutex_t { 436 size: [ 437 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 438 ], 439 }; 440 #[cfg(target_endian = "big")] 441 pub const PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP: crate::pthread_mutex_t = pthread_mutex_t { 442 size: [ 443 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 444 ], 445 }; 446 447 pub const PTRACE_GETFPREGS: c_uint = 14; 448 pub const PTRACE_SETFPREGS: c_uint = 15; 449 pub const PTRACE_GETREGS: c_uint = 12; 450 pub const PTRACE_SETREGS: c_uint = 13; 451 452 extern "C" { 453 pub fn sysctl( 454 name: *mut c_int, 455 namelen: c_int, 456 oldp: *mut c_void, 457 oldlenp: *mut size_t, 458 newp: *mut c_void, 459 newlen: size_t, 460 ) -> c_int; 461 } 462 463 cfg_if! { 464 if #[cfg(target_arch = "x86")] { 465 mod x86; 466 pub use self::x86::*; 467 } else if #[cfg(target_arch = "arm")] { 468 mod arm; 469 pub use self::arm::*; 470 } else if #[cfg(any(target_arch = "mips", target_arch = "mips32r6"))] { 471 mod mips; 472 pub use self::mips::*; 473 } else if #[cfg(target_arch = "m68k")] { 474 mod m68k; 475 pub use self::m68k::*; 476 } else if #[cfg(target_arch = "powerpc")] { 477 mod powerpc; 478 pub use self::powerpc::*; 479 } else if #[cfg(target_arch = "sparc")] { 480 mod sparc; 481 pub use self::sparc::*; 482 } else if #[cfg(target_arch = "riscv32")] { 483 mod riscv32; 484 pub use self::riscv32::*; 485 } else if #[cfg(target_arch = "csky")] { 486 mod csky; 487 pub use self::csky::*; 488 } else { 489 // Unknown target_arch 490 } 491 } 492