diff --git a/.gitmodules b/.gitmodules index 6cd704b370376..83be070b3854a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -14,3 +14,6 @@ [submodule "src/rust-installer"] path = src/rust-installer url = https://github.com/rust-lang/rust-installer +[submodule "src/liblibc"] + path = src/liblibc + url = https://github.com/rust-lang/libc diff --git a/mk/crates.mk b/mk/crates.mk index 2a627a6da2bd6..89a836eb7cb31 100644 --- a/mk/crates.mk +++ b/mk/crates.mk @@ -174,3 +174,6 @@ $(foreach crate,$(TOOLS),$(eval $(call RUST_TOOL,$(crate)))) ifdef CFG_DISABLE_ELF_TLS RUSTFLAGS_std := --cfg no_elf_tls endif + +CRATEFILE_libc := $(SREL)src/liblibc/src/lib.rs +RUSTFLAGS_libc := --cfg stdbuild diff --git a/mk/tests.mk b/mk/tests.mk index d004558d1bf3f..052d0c18ed4e2 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -22,7 +22,7 @@ $(eval $(call RUST_CRATE,coretest)) DEPS_collectionstest := $(eval $(call RUST_CRATE,collectionstest)) -TEST_TARGET_CRATES = $(filter-out core rustc_unicode alloc_system \ +TEST_TARGET_CRATES = $(filter-out core rustc_unicode alloc_system libc \ alloc_jemalloc,$(TARGET_CRATES)) \ collectionstest coretest TEST_DOC_CRATES = $(DOC_CRATES) @@ -283,6 +283,7 @@ tidy-binaries: | grep '^$(S)src/compiler-rt' -v \ | grep '^$(S)src/libbacktrace' -v \ | grep '^$(S)src/rust-installer' -v \ + | grep '^$(S)src/liblibc' -v \ | xargs $(CFG_PYTHON) $(S)src/etc/check-binaries.py .PHONY: tidy-errors diff --git a/src/etc/tidy.py b/src/etc/tidy.py index 9f5f919bce8d8..942793adc31de 100644 --- a/src/etc/tidy.py +++ b/src/etc/tidy.py @@ -108,7 +108,8 @@ def interesting_file(f): 'src/rustllvm', 'src/rt/valgrind', 'src/rt/msvc', - 'src/rust-installer' + 'src/rust-installer', + 'src/liblibc', } if any(d in dirpath for d in skippable_dirs): diff --git a/src/liballoc_jemalloc/lib.rs b/src/liballoc_jemalloc/lib.rs index f46b12e80c56a..f2ff0593bfa54 100644 --- a/src/liballoc_jemalloc/lib.rs +++ b/src/liballoc_jemalloc/lib.rs @@ -14,6 +14,7 @@ #![staged_api] #![no_std] #![cfg_attr(not(stage0), allocator)] +#![cfg_attr(stage0, allow(improper_ctypes))] #![unstable(feature = "alloc_jemalloc", reason = "this library is unlikely to be stabilized in its current \ form or name", diff --git a/src/liballoc_system/lib.rs b/src/liballoc_system/lib.rs index c447dfbec4440..93b64c9caebc9 100644 --- a/src/liballoc_system/lib.rs +++ b/src/liballoc_system/lib.rs @@ -14,6 +14,7 @@ #![staged_api] #![no_std] #![cfg_attr(not(stage0), allocator)] +#![cfg_attr(stage0, allow(improper_ctypes))] #![unstable(feature = "alloc_system", reason = "this library is unlikely to be stabilized in its current \ form or name", @@ -141,10 +142,16 @@ mod imp { } #[cfg(windows)] +#[allow(bad_style)] mod imp { - use libc::{BOOL, DWORD, HANDLE, LPVOID, SIZE_T}; use MIN_ALIGN; + type LPVOID = *mut u8; + type HANDLE = LPVOID; + type SIZE_T = usize; + type DWORD = u32; + type BOOL = i32; + extern "system" { fn GetProcessHeap() -> HANDLE; fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) -> LPVOID; diff --git a/src/libflate/lib.rs b/src/libflate/lib.rs index 521dddae78ff9..51f387523294f 100644 --- a/src/libflate/lib.rs +++ b/src/libflate/lib.rs @@ -29,6 +29,7 @@ #![feature(staged_api)] #![feature(unique)] #![cfg_attr(test, feature(rustc_private, rand, vec_push_all))] +#![cfg_attr(stage0, allow(improper_ctypes))] #[cfg(test)] #[macro_use] diff --git a/src/liblibc b/src/liblibc new file mode 160000 index 0000000000000..b1a043feeae3a --- /dev/null +++ b/src/liblibc @@ -0,0 +1 @@ +Subproject commit b1a043feeae3a67f45e75eaf10aa900a1f6832f9 diff --git a/src/liblibc/lib.rs b/src/liblibc/lib.rs deleted file mode 100644 index 13902d674379e..0000000000000 --- a/src/liblibc/lib.rs +++ /dev/null @@ -1,7184 +0,0 @@ -// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] -#![crate_name = "libc"] -#![crate_type = "rlib"] -#![cfg_attr(not(feature = "cargo-build"), - unstable(feature = "libc", reason = "use `libc` from crates.io", - issue = "27783"))] -#![cfg_attr(not(feature = "cargo-build"), feature(staged_api, no_std))] -#![cfg_attr(not(feature = "cargo-build"), staged_api)] -#![cfg_attr(not(feature = "cargo-build"), no_std)] -#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", - html_favicon_url = "https://doc.rust-lang.org/favicon.ico", - html_root_url = "https://doc.rust-lang.org/nightly/", - html_playground_url = "https://play.rust-lang.org/", - issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/")] -#![cfg_attr(test, feature(test))] -#![cfg_attr(not(feature = "cargo-build"), feature(cfg_target_vendor))] - -//! Bindings for the C standard library and other platform libraries -//! -//! **NOTE:** These are *architecture and libc* specific. On Linux, these -//! bindings are only correct for glibc. -//! -//! This module contains bindings to the C standard library, organized into -//! modules by their defining standard. Additionally, it contains some assorted -//! platform-specific definitions. For convenience, most functions and types -//! are reexported, so `use libc::*` will import the available C bindings as -//! appropriate for the target platform. The exact set of functions available -//! are platform specific. -//! -//! *Note:* Because these definitions are platform-specific, some may not appear -//! in the generated documentation. -//! -//! We consider the following specs reasonably normative with respect to -//! interoperating with the C standard library (libc/msvcrt): -//! -//! * ISO 9899:1990 ('C95', 'ANSI C', 'Standard C'), NA1, 1995. -//! * ISO 9899:1999 ('C99' or 'C9x'). -//! * ISO 9945:1988 / IEEE 1003.1-1988 ('POSIX.1'). -//! * ISO 9945:2001 / IEEE 1003.1-2001 ('POSIX:2001', 'SUSv3'). -//! * ISO 9945:2008 / IEEE 1003.1-2008 ('POSIX:2008', 'SUSv4'). -//! -//! Note that any reference to the 1996 revision of POSIX, or any revs between -//! 1990 (when '88 was approved at ISO) and 2001 (when the next actual -//! revision-revision happened), are merely additions of other chapters (1b and -//! 1c) outside the core interfaces. -//! -//! Despite having several names each, these are *reasonably* coherent -//! point-in-time, list-of-definition sorts of specs. You can get each under a -//! variety of names but will wind up with the same definition in each case. -//! -//! See standards(7) in linux-manpages for more details. -//! -//! Our interface to these libraries is complicated by the non-universality of -//! conformance to any of them. About the only thing universally supported is -//! the first (C95), beyond that definitions quickly become absent on various -//! platforms. -//! -//! We therefore wind up dividing our module-space up (mostly for the sake of -//! sanity while editing, filling-in-details and eliminating duplication) into -//! definitions common-to-all (held in modules named c95, c99, posix88, posix01 -//! and posix08) and definitions that appear only on *some* platforms (named -//! 'extra'). This would be things like significant OSX foundation kit, or Windows -//! library kernel32.dll, or various fancy glibc, Linux or BSD extensions. -//! -//! In addition to the per-platform 'extra' modules, we define a module of -//! 'common BSD' libc routines that never quite made it into POSIX but show up -//! in multiple derived systems. This is the 4.4BSD r2 / 1995 release, the final -//! one from Berkeley after the lawsuits died down and the CSRG dissolved. - -#![allow(bad_style, raw_pointer_derive)] -#![cfg_attr(target_os = "nacl", allow(unused_imports))] -#[cfg(feature = "cargo-build")] -extern crate std as core; - -#[cfg(test)] -extern crate std; -#[cfg(test)] -extern crate test; - -// Explicit export lists for the intersection (provided here) mean that -// you can write more-platform-agnostic code if you stick to just these -// symbols. - -pub use types::common::c95::*; -pub use types::common::c99::*; -pub use types::common::posix88::*; -pub use types::os::common::posix01::*; -pub use types::os::common::bsd44::*; -pub use types::os::arch::c95::*; -pub use types::os::arch::c99::*; -pub use types::os::arch::posix88::*; -pub use types::os::arch::posix01::*; -pub use types::os::arch::extra::*; - -pub use consts::os::c95::*; -pub use consts::os::posix88::*; -pub use consts::os::posix01::*; -pub use consts::os::posix08::*; -pub use consts::os::bsd44::*; -pub use consts::os::extra::*; - -pub use funcs::c95::ctype::*; -pub use funcs::c95::stdio::*; -pub use funcs::c95::stdlib::*; -pub use funcs::c95::string::*; -pub use funcs::posix88::fcntl::*; -pub use funcs::posix88::stat_::*; -pub use funcs::posix88::stdio::*; -pub use funcs::posix88::unistd::*; - -pub use funcs::bsd43::*; - -// But we also reexport most everything -// if you're interested in writing platform-specific code. - -// FIXME: This is a mess, but the design of this entire module needs to be -// reconsidered, so I'm not inclined to do better right now. As part of -// #11870 I removed all the pub globs here, leaving explicit reexports -// of everything that is actually used in-tree. -// -// So the following exports don't follow any particular plan. - -#[cfg(unix)] -pub use consts::os::sysconf::*; - -#[cfg(unix)] -pub use funcs::posix88::mman::*; -#[cfg(unix)] -pub use funcs::posix88::dirent::*; -#[cfg(unix)] -pub use funcs::posix88::net::*; -#[cfg(unix)] -pub use funcs::posix01::stat_::*; -#[cfg(unix)] -pub use funcs::posix01::unistd::*; -#[cfg(unix)] -pub use funcs::posix01::resource::*; - - -#[cfg(windows)] -pub use funcs::extra::kernel32::*; -#[cfg(windows)] -pub use funcs::extra::winsock::*; -#[cfg(windows)] -pub use funcs::extra::msvcrt::*; - -// On NaCl, these libraries are static. Thus it would be a Bad Idea to link them -// in when creating a test crate. -#[cfg(not(any(windows, - target_env = "musl", - all(target_os = "nacl", test), - all(target_os = "netbsd", target_vendor = "rumprun"))))] -#[link(name = "c")] -#[link(name = "m")] -extern { -} - -// When compiling rust with musl, statically include libc.a in liblibc.rlib. -// A cargo build of the libc crate will therefore automatically pick up the -// libc.a symbols because liblibc is transitively linked to by the stdlib. -#[cfg(all(target_env = "musl", not(feature = "cargo-build"), not(test)))] -#[link(name = "c", kind = "static")] -extern { -} - -#[cfg(all(windows, target_env = "msvc"))] -#[link(name = "kernel32")] -#[link(name = "shell32")] -#[link(name = "msvcrt")] -extern { -} - -// libnacl provides functions that require a trip through the IRT to work. -// ie: _exit, mmap, nanosleep, etc. Anything that would otherwise require a trip -// to the kernel. -#[cfg(all(target_os = "nacl", not(feature = "cargo-build"), not(test)))] -#[link(name = "nacl", kind = "static")] -extern { -} - -// pnaclmm provides a number of functions that the toolchain's Clang emits calls -// to when codegening atomic ops. All the functions within wrap various atomic -// operations. -// Yes, it could be linked by rustc explicitly, however by linking it here -// instead we save a bit of time where bins are involved (by not running the -// optimizations on the whole pnaclmm foreach binary built). -#[cfg(all(target_os = "nacl", not(feature = "cargo-build"), not(test)))] -#[link(name = "pnaclmm", kind = "static")] -extern { -} - -pub mod types { - - // Types tend to vary *per architecture* so we pull their definitions out - // into this module. - - // Standard types that are opaque or common, so are not per-target. - pub mod common { - pub mod c95 { - /// Type used to construct void pointers for use with C. - /// - /// This type is only useful as a pointer target. Do not use it as a - /// return type for FFI functions which have the `void` return type in - /// C. Use the unit type `()` or omit the return type instead. - /// - /// For LLVM to recognize the void pointer type and by extension - /// functions like malloc(), we need to have it represented as i8* - /// in LLVM bitcode. The enum used here ensures this. We need two - /// variants, because the compiler complains about the `repr` - /// attribute otherwise. - #[repr(u8)] - pub enum c_void { - #[doc(hidden)] - __variant1, - #[doc(hidden)] - __variant2, - } - - pub enum FILE {} - pub enum fpos_t {} - } - pub mod c99 { - pub type int8_t = i8; - pub type int16_t = i16; - pub type int32_t = i32; - pub type int64_t = i64; - pub type uint8_t = u8; - pub type uint16_t = u16; - pub type uint32_t = u32; - pub type uint64_t = u64; - } - pub mod posix88 { - pub enum DIR {} - pub enum dirent_t {} - } - pub mod posix01 { - } - pub mod posix08 { - } - pub mod bsd44 { - } - } - - // Standard types that are scalar but vary by OS and arch. - - #[cfg(any(target_os = "linux", target_os = "android", target_os = "nacl"))] - pub mod os { - pub mod common { - pub mod posix01 { - use types::common::c95::c_void; - use types::os::arch::c95::{c_char, c_ulong, size_t, time_t, suseconds_t, c_long}; - - #[cfg(not(target_os = "nacl"))] - pub type pthread_t = c_ulong; - #[cfg(target_os = "nacl")] - pub type pthread_t = *mut c_void; - pub type rlim_t = u64; - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct glob_t { - pub gl_pathc: size_t, - pub gl_pathv: *mut *mut c_char, - pub gl_offs: size_t, - - pub __unused1: *mut c_void, - pub __unused2: *mut c_void, - pub __unused3: *mut c_void, - pub __unused4: *mut c_void, - pub __unused5: *mut c_void, - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct timeval { - pub tv_sec: time_t, - pub tv_usec: suseconds_t, - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct timespec { - pub tv_sec: time_t, - pub tv_nsec: c_long, - } - - pub enum timezone {} - - pub type sighandler_t = size_t; - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct rlimit { - pub rlim_cur: rlim_t, - pub rlim_max: rlim_t, - } - } - - pub mod bsd43 { - use types::os::common::posix01::timeval; - use types::os::arch::c95::c_long; - // This is also specified in POSIX 2001, but only has two fields. All implementors - // implement BSD 4.3 version. - #[repr(C)] - #[derive(Copy, Clone)] - pub struct rusage { - pub ru_utime: timeval, - pub ru_stime: timeval, - pub ru_maxrss: c_long, - pub ru_ixrss: c_long, - pub ru_idrss: c_long, - pub ru_isrss: c_long, - pub ru_minflt: c_long, - pub ru_majflt: c_long, - pub ru_nswap: c_long, - pub ru_inblock: c_long, - pub ru_oublock: c_long, - pub ru_msgsnd: c_long, - pub ru_msgrcv: c_long, - pub ru_nsignals: c_long, - pub ru_nvcsw: c_long, - pub ru_nivcsw: c_long, - } - } - - pub mod bsd44 { - use types::common::c95::c_void; - use types::os::arch::c95::{c_char, c_int, c_uint}; - - pub type socklen_t = u32; - pub type sa_family_t = u16; - pub type in_port_t = u16; - pub type in_addr_t = u32; - #[repr(C)] - #[derive(Copy, Clone)] - pub struct sockaddr { - pub sa_family: sa_family_t, - pub sa_data: [u8; 14], - } - #[repr(C)] - #[derive(Copy)] - pub struct sockaddr_storage { - pub ss_family: sa_family_t, - pub __ss_align: isize, - #[cfg(target_pointer_width = "32")] - pub __ss_pad2: [u8; 128 - 2 * 4], - #[cfg(target_pointer_width = "64")] - pub __ss_pad2: [u8; 128 - 2 * 8], - } - impl ::core::clone::Clone for sockaddr_storage { - fn clone(&self) -> sockaddr_storage { - *self - } - } - #[repr(C)] - #[derive(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; 8], - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct in_addr { - pub s_addr: in_addr_t, - } - #[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, - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct in6_addr { - pub s6_addr: [u16; 8], - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct ip_mreq { - pub imr_multiaddr: in_addr, - pub imr_interface: in_addr, - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct ip6_mreq { - pub ipv6mr_multiaddr: in6_addr, - pub ipv6mr_interface: c_uint, - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct addrinfo { - pub ai_flags: c_int, - pub ai_family: c_int, - pub ai_socktype: c_int, - pub ai_protocol: c_int, - pub ai_addrlen: socklen_t, - - #[cfg(target_os = "linux")] - pub ai_addr: *mut sockaddr, - - #[cfg(target_os = "linux")] - pub ai_canonname: *mut c_char, - - #[cfg(any(target_os = "android", target_os = "nacl"))] - pub ai_canonname: *mut c_char, - - #[cfg(any(target_os = "android", target_os = "nacl"))] - pub ai_addr: *mut sockaddr, - - pub ai_next: *mut addrinfo, - } - #[repr(C)] - #[derive(Copy)] - pub struct sockaddr_un { - pub sun_family: sa_family_t, - pub sun_path: [c_char; 108], - } - impl ::core::clone::Clone for sockaddr_un { - fn clone(&self) -> sockaddr_un { - *self - } - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct ifaddrs { - pub ifa_next: *mut ifaddrs, - pub ifa_name: *mut c_char, - pub ifa_flags: c_uint, - pub ifa_addr: *mut sockaddr, - pub ifa_netmask: *mut sockaddr, - pub ifa_ifu: *mut sockaddr, // FIXME This should be a union - pub ifa_data: *mut c_void, - } - - } - } - - #[cfg(any(target_arch = "x86", - target_arch = "arm", - target_arch = "mips", - target_arch = "mipsel", - target_arch = "powerpc", - target_arch = "le32"))] - pub mod arch { - pub mod c95 { - pub type c_char = i8; - pub type c_schar = i8; - pub type c_uchar = u8; - pub type c_short = i16; - pub type c_ushort = u16; - pub type c_int = i32; - pub type c_uint = u32; - pub type c_long = i32; - pub type c_ulong = u32; - pub type c_float = f32; - pub type c_double = f64; - pub type size_t = u32; - pub type ptrdiff_t = i32; - pub type clock_t = i32; - pub type time_t = i32; - pub type suseconds_t = i32; - pub type wchar_t = i32; - } - pub mod c99 { - pub type c_longlong = i64; - pub type c_ulonglong = u64; - pub type intptr_t = i32; - pub type uintptr_t = u32; - pub type intmax_t = i64; - pub type uintmax_t = u64; - } - #[cfg(any(target_arch = "mips", - target_arch = "mipsel", - target_arch = "powerpc", - target_arch = "le32", - all(any(target_arch = "arm", target_arch = "x86"), - not(target_os = "android"))))] - pub mod posix88 { - pub type off_t = i32; - pub type dev_t = u64; - pub type ino_t = u32; - pub type pid_t = i32; - pub type uid_t = u32; - pub type gid_t = u32; - pub type useconds_t = u32; - pub type mode_t = u32; - pub type ssize_t = i32; - } - #[cfg(all(any(target_arch = "arm", target_arch = "x86"), - target_os = "android"))] - pub mod posix88 { - pub type off_t = i32; - pub type dev_t = u32; - pub type ino_t = u32; - - pub type pid_t = i32; - pub type uid_t = u32; - pub type gid_t = u32; - pub type useconds_t = u32; - - pub type mode_t = u16; - pub type ssize_t = i32; - } - #[cfg(any(all(any(target_arch = "arm", target_arch = "x86"), - not(target_os = "android")), - target_arch = "le32", - target_arch = "powerpc"))] - pub mod posix01 { - use types::os::arch::c95::{c_short, c_long, time_t}; - use types::os::arch::posix88::{dev_t, gid_t, ino_t}; - use types::os::arch::posix88::{mode_t, off_t}; - use types::os::arch::posix88::uid_t; - - pub type nlink_t = u32; - pub type blksize_t = i32; - pub type blkcnt_t = i32; - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct stat { - pub st_dev: dev_t, - pub __pad1: c_short, - 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 __pad2: c_short, - pub st_size: off_t, - pub st_blksize: blksize_t, - pub st_blocks: blkcnt_t, - pub st_atime: time_t, - pub st_atime_nsec: c_long, - pub st_mtime: time_t, - pub st_mtime_nsec: c_long, - pub st_ctime: time_t, - pub st_ctime_nsec: c_long, - pub __unused4: c_long, - pub __unused5: c_long, - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct utimbuf { - pub actime: time_t, - pub modtime: time_t, - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct pthread_attr_t { - pub __size: [u32; 9], - } - } - - #[cfg(all(any(target_arch = "arm", target_arch = "x86"), - target_os = "android"))] - pub mod posix01 { - use types::os::arch::c95::{c_uchar, c_uint, c_ulong, c_long, time_t}; - use types::os::arch::c99::{c_longlong, c_ulonglong}; - use types::os::arch::posix88::{uid_t, gid_t}; - - pub type nlink_t = u16; - pub type blksize_t = u32; - pub type blkcnt_t = u32; - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct stat { - pub st_dev: c_ulonglong, - pub __pad0: [c_uchar; 4], - pub __st_ino: c_long, - pub st_mode: c_uint, - pub st_nlink: c_uint, - pub st_uid: uid_t, - pub st_gid: gid_t, - pub st_rdev: c_ulonglong, - pub __pad3: [c_uchar; 4], - pub st_size: c_longlong, - pub st_blksize: c_ulong, - pub st_blocks: c_ulonglong, - pub st_atime: time_t, - pub st_atime_nsec: c_ulong, - pub st_mtime: time_t, - pub st_mtime_nsec: c_ulong, - pub st_ctime: time_t, - pub st_ctime_nsec: c_ulong, - pub st_ino: c_ulonglong, - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct utimbuf { - pub actime: time_t, - pub modtime: time_t, - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct pthread_attr_t { - pub __size: [u32; 9], - } - } - - #[cfg(any(target_arch = "mips", - target_arch = "mipsel"))] - pub mod posix01 { - use types::os::arch::c95::{c_long, c_ulong, time_t}; - use types::os::arch::posix88::{gid_t, ino_t}; - use types::os::arch::posix88::{mode_t, off_t}; - use types::os::arch::posix88::uid_t; - - pub type nlink_t = u32; - pub type blksize_t = i32; - pub type blkcnt_t = i32; - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct stat { - pub st_dev: c_ulong, - pub st_pad1: [c_long; 3], - 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: c_ulong, - pub st_pad2: [c_long; 2], - pub st_size: off_t, - pub st_pad3: c_long, - pub st_atime: time_t, - pub st_atime_nsec: c_long, - pub st_mtime: time_t, - pub st_mtime_nsec: c_long, - pub st_ctime: time_t, - pub st_ctime_nsec: c_long, - pub st_blksize: blksize_t, - pub st_blocks: blkcnt_t, - pub st_pad5: [c_long; 14], - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct utimbuf { - pub actime: time_t, - pub modtime: time_t, - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct pthread_attr_t { - pub __size: [u32; 9], - } - } - pub mod posix08 { - } - pub mod bsd44 { - } - pub mod extra { - use types::os::arch::c95::{c_ushort, c_int, c_uchar}; - #[repr(C)] - #[derive(Copy, Clone)] - pub struct sockaddr_ll { - pub sll_family: c_ushort, - pub sll_protocol: c_ushort, - pub sll_ifindex: c_int, - pub sll_hatype: c_ushort, - pub sll_pkttype: c_uchar, - pub sll_halen: c_uchar, - pub sll_addr: [c_uchar; 8], - } - } - - } - - #[cfg(any(target_arch = "x86_64", - target_arch = "aarch64"))] - pub mod arch { - pub mod c95 { - #[cfg(not(target_arch = "aarch64"))] - pub type c_char = i8; - #[cfg(target_arch = "aarch64")] - pub type c_char = u8; - pub type c_schar = i8; - pub type c_uchar = u8; - pub type c_short = i16; - pub type c_ushort = u16; - pub type c_int = i32; - pub type c_uint = u32; - pub type c_long = i64; - pub type c_ulong = u64; - pub type c_float = f32; - pub type c_double = f64; - pub type size_t = u64; - pub type ptrdiff_t = i64; - pub type clock_t = i64; - pub type time_t = i64; - pub type suseconds_t = i64; - #[cfg(not(target_arch = "aarch64"))] - pub type wchar_t = i32; - #[cfg(target_arch = "aarch64")] - pub type wchar_t = u32; - } - pub mod c99 { - pub type c_longlong = i64; - pub type c_ulonglong = u64; - pub type intptr_t = i64; - pub type uintptr_t = u64; - pub type intmax_t = i64; - pub type uintmax_t = u64; - } - pub mod posix88 { - pub type off_t = i64; - pub type dev_t = u64; - pub type ino_t = u64; - pub type pid_t = i32; - pub type uid_t = u32; - pub type gid_t = u32; - pub type useconds_t = u32; - pub type mode_t = u32; - pub type ssize_t = i64; - } - #[cfg(not(target_arch = "aarch64"))] - pub mod posix01 { - use types::os::arch::c95::{c_int, c_long, time_t}; - use types::os::arch::posix88::{dev_t, gid_t, ino_t}; - use types::os::arch::posix88::{mode_t, off_t}; - use types::os::arch::posix88::uid_t; - - pub type nlink_t = u64; - pub type blksize_t = i64; - pub type blkcnt_t = i64; - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct stat { - 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: c_int, - pub st_rdev: dev_t, - pub st_size: off_t, - pub st_blksize: blksize_t, - pub st_blocks: blkcnt_t, - pub st_atime: time_t, - pub st_atime_nsec: c_long, - pub st_mtime: time_t, - pub st_mtime_nsec: c_long, - pub st_ctime: time_t, - pub st_ctime_nsec: c_long, - pub __unused: [c_long; 3], - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct utimbuf { - pub actime: time_t, - pub modtime: time_t, - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct pthread_attr_t { - pub __size: [u64; 7], - } - } - #[cfg(target_arch = "aarch64")] - pub mod posix01 { - use types::os::arch::c95::{c_int, c_long, time_t}; - use types::os::arch::posix88::{dev_t, gid_t, ino_t}; - use types::os::arch::posix88::{mode_t, off_t}; - use types::os::arch::posix88::uid_t; - - pub type nlink_t = u32; - pub type blksize_t = i32; - pub type blkcnt_t = i64; - - #[repr(C)] - #[derive(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 __pad1: dev_t, - pub st_size: off_t, - pub st_blksize: blksize_t, - pub __pad2: c_int, - pub st_blocks: blkcnt_t, - pub st_atime: time_t, - pub st_atime_nsec: c_long, - pub st_mtime: time_t, - pub st_mtime_nsec: c_long, - pub st_ctime: time_t, - pub st_ctime_nsec: c_long, - pub __unused: [c_int; 2], - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct utimbuf { - pub actime: time_t, - pub modtime: time_t, - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct pthread_attr_t { - pub __size: [u64; 8], - } - } - pub mod posix08 { - } - pub mod bsd44 { - } - pub mod extra { - use types::os::arch::c95::{c_ushort, c_int, c_uchar}; - #[derive(Copy, Clone)] - pub struct sockaddr_ll { - pub sll_family: c_ushort, - pub sll_protocol: c_ushort, - pub sll_ifindex: c_int, - pub sll_hatype: c_ushort, - pub sll_pkttype: c_uchar, - pub sll_halen: c_uchar, - pub sll_addr: [c_uchar; 8], - } - - } - } - } - - #[cfg(target_os = "freebsd")] - pub mod os { - pub mod common { - pub mod posix01 { - use types::common::c95::c_void; - use types::os::arch::c95::{c_char, c_int, size_t, time_t, suseconds_t, c_long}; - use types::os::arch::c99::uintptr_t; - - pub type pthread_t = uintptr_t; - pub type rlim_t = i64; - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct glob_t { - pub gl_pathc: size_t, - pub __unused1: size_t, - pub gl_offs: size_t, - pub __unused2: c_int, - pub gl_pathv: *mut *mut c_char, - - pub __unused3: *mut c_void, - - pub __unused4: *mut c_void, - pub __unused5: *mut c_void, - pub __unused6: *mut c_void, - pub __unused7: *mut c_void, - pub __unused8: *mut c_void, - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct timeval { - pub tv_sec: time_t, - pub tv_usec: suseconds_t, - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct timespec { - pub tv_sec: time_t, - pub tv_nsec: c_long, - } - - pub enum timezone {} - - pub type sighandler_t = size_t; - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct rlimit { - pub rlim_cur: rlim_t, - pub rlim_max: rlim_t, - } - } - - pub mod bsd43 { - use types::os::common::posix01::timeval; - use types::os::arch::c95::c_long; - #[repr(C)] - #[derive(Copy, Clone)] - pub struct rusage { - pub ru_utime: timeval, - pub ru_stime: timeval, - pub ru_maxrss: c_long, - pub ru_ixrss: c_long, - pub ru_idrss: c_long, - pub ru_isrss: c_long, - pub ru_minflt: c_long, - pub ru_majflt: c_long, - pub ru_nswap: c_long, - pub ru_inblock: c_long, - pub ru_oublock: c_long, - pub ru_msgsnd: c_long, - pub ru_msgrcv: c_long, - pub ru_nsignals: c_long, - pub ru_nvcsw: c_long, - pub ru_nivcsw: c_long, - } - } - - pub mod bsd44 { - use types::common::c95::c_void; - use types::os::arch::c95::{c_char, c_int, c_uint}; - - pub type socklen_t = u32; - pub type sa_family_t = u8; - pub type in_port_t = u16; - pub type in_addr_t = u32; - #[repr(C)] - #[derive(Copy, Clone)] - pub struct sockaddr { - pub sa_len: u8, - pub sa_family: sa_family_t, - pub sa_data: [u8; 14], - } - #[repr(C)] - #[derive(Copy)] - pub struct sockaddr_storage { - pub ss_len: u8, - pub ss_family: sa_family_t, - pub __ss_pad1: [u8; 6], - pub __ss_align: i64, - pub __ss_pad2: [u8; 112], - } - impl ::core::clone::Clone for sockaddr_storage { - fn clone(&self) -> sockaddr_storage { - *self - } - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct sockaddr_in { - pub sin_len: u8, - pub sin_family: sa_family_t, - pub sin_port: in_port_t, - pub sin_addr: in_addr, - pub sin_zero: [u8; 8], - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct in_addr { - pub s_addr: in_addr_t, - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct sockaddr_in6 { - pub sin6_len: u8, - pub sin6_family: sa_family_t, - pub sin6_port: in_port_t, - pub sin6_flowinfo: u32, - pub sin6_addr: in6_addr, - pub sin6_scope_id: u32, - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct in6_addr { - pub s6_addr: [u16; 8], - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct ip_mreq { - pub imr_multiaddr: in_addr, - pub imr_interface: in_addr, - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct ip6_mreq { - pub ipv6mr_multiaddr: in6_addr, - pub ipv6mr_interface: c_uint, - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct addrinfo { - pub ai_flags: c_int, - pub ai_family: c_int, - pub ai_socktype: c_int, - pub ai_protocol: c_int, - pub ai_addrlen: socklen_t, - pub ai_canonname: *mut c_char, - pub ai_addr: *mut sockaddr, - pub ai_next: *mut addrinfo, - } - #[repr(C)] - #[derive(Copy)] - pub struct sockaddr_un { - pub sun_len: u8, - pub sun_family: sa_family_t, - pub sun_path: [c_char; 104], - } - impl ::core::clone::Clone for sockaddr_un { - fn clone(&self) -> sockaddr_un { - *self - } - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct ifaddrs { - pub ifa_next: *mut ifaddrs, - pub ifa_name: *mut c_char, - pub ifa_flags: c_uint, - pub ifa_addr: *mut sockaddr, - pub ifa_netmask: *mut sockaddr, - pub ifa_dstaddr: *mut sockaddr, - pub ifa_data: *mut c_void, - } - - - } - } - - #[cfg(target_arch = "x86")] - pub mod arch { - pub mod c95 { - pub type c_char = i8; - pub type c_schar = i8; - pub type c_uchar = u8; - pub type c_short = i16; - pub type c_ushort = u16; - pub type c_int = i32; - pub type c_uint = u32; - pub type c_long = i32; - pub type c_ulong = u32; - pub type c_float = f32; - pub type c_double = f64; - pub type size_t = u32; - pub type ptrdiff_t = i32; - pub type clock_t = i32; - pub type time_t = i32; - pub type suseconds_t = i32; - pub type wchar_t = i32; - } - pub mod c99 { - pub type c_longlong = i64; - pub type c_ulonglong = u64; - pub type intptr_t = i32; - pub type uintptr_t = u32; - pub type intmax_t = i64; - pub type uintmax_t = u64; - } - pub mod posix88 { - pub type off_t = i64; - pub type dev_t = u32; - pub type ino_t = u32; - pub type pid_t = i32; - pub type uid_t = u32; - pub type gid_t = u32; - pub type useconds_t = u32; - pub type mode_t = u16; - pub type ssize_t = i32; - } - pub mod posix01 { - use types::common::c95::c_void; - use types::common::c99::{uint32_t, int32_t}; - use types::os::arch::c95::{c_long, time_t}; - use types::os::arch::posix88::{dev_t, gid_t, ino_t}; - use types::os::arch::posix88::{mode_t, off_t}; - use types::os::arch::posix88::uid_t; - - pub type nlink_t = u16; - pub type blksize_t = u32; - pub type blkcnt_t = i64; - pub type fflags_t = u32; - #[repr(C)] - #[derive(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_atime: time_t, - pub st_atime_nsec: c_long, - pub st_mtime: time_t, - pub st_mtime_nsec: c_long, - pub st_ctime: time_t, - pub st_ctime_nsec: c_long, - pub st_size: off_t, - pub st_blocks: blkcnt_t, - pub st_blksize: blksize_t, - pub st_flags: fflags_t, - pub st_gen: uint32_t, - pub st_lspare: int32_t, - pub st_birthtime: time_t, - pub st_birthtime_nsec: c_long, - pub __unused: [u8; 8], - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct utimbuf { - pub actime: time_t, - pub modtime: time_t, - } - - pub type pthread_attr_t = *mut c_void; - } - pub mod posix08 { - } - pub mod bsd44 { - } - pub mod extra { - } - } - - #[cfg(target_arch = "x86_64")] - pub mod arch { - pub mod c95 { - pub type c_char = i8; - pub type c_schar = i8; - pub type c_uchar = u8; - pub type c_short = i16; - pub type c_ushort = u16; - pub type c_int = i32; - pub type c_uint = u32; - pub type c_long = i64; - pub type c_ulong = u64; - pub type c_float = f32; - pub type c_double = f64; - pub type size_t = u64; - pub type ptrdiff_t = i64; - pub type clock_t = i32; - pub type time_t = i64; - pub type suseconds_t = i64; - pub type wchar_t = i32; - } - pub mod c99 { - pub type c_longlong = i64; - pub type c_ulonglong = u64; - pub type intptr_t = i64; - pub type uintptr_t = u64; - pub type intmax_t = i64; - pub type uintmax_t = u64; - } - pub mod posix88 { - pub type off_t = i64; - pub type dev_t = u32; - pub type ino_t = u32; - pub type pid_t = i32; - pub type uid_t = u32; - pub type gid_t = u32; - pub type useconds_t = u32; - pub type mode_t = u16; - pub type ssize_t = i64; - } - pub mod posix01 { - use types::common::c95::c_void; - use types::common::c99::{uint32_t, int32_t}; - use types::os::arch::c95::{c_long, time_t}; - use types::os::arch::posix88::{dev_t, gid_t, ino_t}; - use types::os::arch::posix88::{mode_t, off_t}; - use types::os::arch::posix88::uid_t; - - pub type nlink_t = u16; - pub type blksize_t = u32; - pub type blkcnt_t = i64; - pub type fflags_t = u32; - #[repr(C)] - #[derive(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_atime: time_t, - pub st_atime_nsec: c_long, - pub st_mtime: time_t, - pub st_mtime_nsec: c_long, - pub st_ctime: time_t, - pub st_ctime_nsec: c_long, - pub st_size: off_t, - pub st_blocks: blkcnt_t, - pub st_blksize: blksize_t, - pub st_flags: fflags_t, - pub st_gen: uint32_t, - pub st_lspare: int32_t, - pub st_birthtime: time_t, - pub st_birthtime_nsec: c_long, - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct utimbuf { - pub actime: time_t, - pub modtime: time_t, - } - - pub type pthread_attr_t = *mut c_void; - } - pub mod posix08 { - } - pub mod bsd44 { - } - pub mod extra { - } - } - } - - #[cfg(target_os = "dragonfly")] - pub mod os { - pub mod common { - pub mod posix01 { - use types::common::c95::c_void; - use types::os::arch::c95::{c_char, c_int, size_t, time_t, suseconds_t, c_long}; - use types::os::arch::c99::uintptr_t; - - pub type pthread_t = uintptr_t; - pub type rlim_t = i64; - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct glob_t { - pub gl_pathc: size_t, - pub __unused1: size_t, - pub gl_offs: size_t, - pub __unused2: c_int, - pub gl_pathv: *mut *mut c_char, - - pub __unused3: *mut c_void, - - pub __unused4: *mut c_void, - pub __unused5: *mut c_void, - pub __unused6: *mut c_void, - pub __unused7: *mut c_void, - pub __unused8: *mut c_void, - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct timeval { - pub tv_sec: time_t, - pub tv_usec: suseconds_t, - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct timespec { - pub tv_sec: time_t, - pub tv_nsec: c_long, - } - - pub enum timezone {} - - pub type sighandler_t = size_t; - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct rlimit { - pub rlim_cur: rlim_t, - pub rlim_max: rlim_t, - } - } - - pub mod bsd43 { - use types::os::common::posix01::timeval; - use types::os::arch::c95::c_long; - #[repr(C)] - #[derive(Copy, Clone)] - pub struct rusage { - pub ru_utime: timeval, - pub ru_stime: timeval, - pub ru_maxrss: c_long, - pub ru_ixrss: c_long, - pub ru_idrss: c_long, - pub ru_isrss: c_long, - pub ru_minflt: c_long, - pub ru_majflt: c_long, - pub ru_nswap: c_long, - pub ru_inblock: c_long, - pub ru_oublock: c_long, - pub ru_msgsnd: c_long, - pub ru_msgrcv: c_long, - pub ru_nsignals: c_long, - pub ru_nvcsw: c_long, - pub ru_nivcsw: c_long, - } - } - - pub mod bsd44 { - use types::common::c95::c_void; - use types::os::arch::c95::{c_char, c_int, c_uint}; - - pub type socklen_t = u32; - pub type sa_family_t = u8; - pub type in_port_t = u16; - pub type in_addr_t = u32; - #[repr(C)] - #[derive(Copy, Clone)] - pub struct sockaddr { - pub sa_len: u8, - pub sa_family: sa_family_t, - pub sa_data: [u8; 14], - } - #[repr(C)] - #[derive(Copy)] - pub struct sockaddr_storage { - pub ss_len: u8, - pub ss_family: sa_family_t, - pub __ss_pad1: [u8; 6], - pub __ss_align: i64, - pub __ss_pad2: [u8; 112], - } - impl ::core::clone::Clone for sockaddr_storage { - fn clone(&self) -> sockaddr_storage { - *self - } - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct sockaddr_in { - pub sin_len: u8, - pub sin_family: sa_family_t, - pub sin_port: in_port_t, - pub sin_addr: in_addr, - pub sin_zero: [u8; 8], - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct in_addr { - pub s_addr: in_addr_t, - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct sockaddr_in6 { - pub sin6_len: u8, - pub sin6_family: sa_family_t, - pub sin6_port: in_port_t, - pub sin6_flowinfo: u32, - pub sin6_addr: in6_addr, - pub sin6_scope_id: u32, - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct in6_addr { - pub s6_addr: [u16; 8], - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct ip_mreq { - pub imr_multiaddr: in_addr, - pub imr_interface: in_addr, - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct ip6_mreq { - pub ipv6mr_multiaddr: in6_addr, - pub ipv6mr_interface: c_uint, - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct addrinfo { - pub ai_flags: c_int, - pub ai_family: c_int, - pub ai_socktype: c_int, - pub ai_protocol: c_int, - pub ai_addrlen: socklen_t, - pub ai_canonname: *mut c_char, - pub ai_addr: *mut sockaddr, - pub ai_next: *mut addrinfo, - } - #[repr(C)] - #[derive(Copy)] - pub struct sockaddr_un { - pub sun_len: u8, - pub sun_family: sa_family_t, - pub sun_path: [c_char; 104], - } - impl ::core::clone::Clone for sockaddr_un { - fn clone(&self) -> sockaddr_un { - *self - } - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct ifaddrs { - pub ifa_next: *mut ifaddrs, - pub ifa_name: *mut c_char, - pub ifa_flags: c_uint, - pub ifa_addr: *mut sockaddr, - pub ifa_netmask: *mut sockaddr, - pub ifa_dstaddr: *mut sockaddr, - pub ifa_data: *mut c_void, - } - - } - } - - #[cfg(target_arch = "x86_64")] - pub mod arch { - pub mod c95 { - pub type c_char = i8; - pub type c_schar = i8; - pub type c_uchar = u8; - pub type c_short = i16; - pub type c_ushort = u16; - pub type c_int = i32; - pub type c_uint = u32; - pub type c_long = i64; - pub type c_ulong = u64; - pub type c_float = f32; - pub type c_double = f64; - pub type size_t = u64; - pub type ptrdiff_t = i64; - pub type clock_t = i32; - pub type time_t = i64; - pub type suseconds_t = i64; - pub type wchar_t = i32; - } - pub mod c99 { - pub type c_longlong = i64; - pub type c_ulonglong = u64; - pub type intptr_t = i64; - pub type uintptr_t = u64; - pub type intmax_t = i64; - pub type uintmax_t = u64; - } - pub mod posix88 { - pub type off_t = i64; - pub type dev_t = u32; - pub type pid_t = i32; - pub type uid_t = u32; - pub type gid_t = u32; - pub type useconds_t = u32; - pub type mode_t = u16; - pub type ssize_t = i64; - } - pub mod posix01 { - use types::common::c95::c_void; - use types::common::c99::{uint16_t, uint32_t, int32_t, uint64_t, int64_t}; - use types::os::arch::c95::{c_long, time_t}; - use types::os::arch::posix88::{dev_t, gid_t}; - use types::os::arch::posix88::{mode_t, off_t}; - use types::os::arch::posix88::uid_t; - - pub type nlink_t = u16; - pub type blksize_t = uint32_t; - pub type ino_t = uint64_t; - pub type blkcnt_t = i64; - pub type fflags_t = u32; - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct stat { - pub st_ino: ino_t, - pub st_nlink: nlink_t, - pub st_dev: dev_t, - pub st_mode: mode_t, - pub st_padding1: uint16_t, - pub st_uid: uid_t, - pub st_gid: gid_t, - pub st_rdev: dev_t, - pub st_atime: time_t, - pub st_atime_nsec: c_long, - pub st_mtime: time_t, - pub st_mtime_nsec: c_long, - pub st_ctime: time_t, - pub st_ctime_nsec: c_long, - pub st_size: off_t, - pub st_blocks: blkcnt_t, - pub st_blksize: blksize_t, - pub st_flags: fflags_t, - pub st_gen: uint32_t, - pub st_lspare: int32_t, - pub st_qspare1: int64_t, - pub st_qspare2: int64_t, - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct utimbuf { - pub actime: time_t, - pub modtime: time_t, - } - - pub type pthread_attr_t = *mut c_void; - } - pub mod posix08 { - } - pub mod bsd44 { - } - pub mod extra { - } - } - } - - #[cfg(any(target_os = "bitrig", target_os = "netbsd", target_os ="openbsd"))] - pub mod os { - pub mod common { - pub mod posix01 { - use types::common::c95::c_void; - use types::os::arch::c95::{c_char, c_int, size_t, time_t, suseconds_t, c_long}; - use types::os::arch::c99::uintptr_t; - - pub type pthread_t = uintptr_t; - pub type rlim_t = u64; - - #[cfg(target_os = "bitrig")] - #[repr(C)] - #[derive(Copy, Clone)] - pub struct glob_t { - pub gl_pathc: c_int, - pub gl_matchc: c_int, - pub gl_offs: c_int, - pub gl_flags: c_int, - pub gl_pathv: *mut *mut c_char, - pub __unused1: *mut c_void, - pub __unused2: *mut c_void, - pub __unused3: *mut c_void, - pub __unused4: *mut c_void, - pub __unused5: *mut c_void, - pub __unused6: *mut c_void, - pub __unused7: *mut c_void, - } - - #[cfg(target_os = "netbsd")] - #[repr(C)] - #[derive(Copy, Clone)] - pub struct glob_t { - pub gl_pathc: size_t, - pub gl_matchc: size_t, - pub gl_offs: size_t, - pub gl_flags: c_int, - pub gl_pathv: *mut *mut c_char, - pub __unused1: *mut c_void, - pub __unused2: *mut c_void, - pub __unused3: *mut c_void, - pub __unused4: *mut c_void, - pub __unused5: *mut c_void, - pub __unused6: *mut c_void, - } - - #[cfg(target_os = "openbsd")] - #[repr(C)] - #[derive(Copy, Clone)] - pub struct glob_t { - pub gl_pathc: c_int, - pub __unused1: c_int, - pub gl_offs: c_int, - pub __unused2: c_int, - pub gl_pathv: *mut *mut c_char, - - pub __unused3: *mut c_void, - - pub __unused4: *mut c_void, - pub __unused5: *mut c_void, - pub __unused6: *mut c_void, - pub __unused7: *mut c_void, - pub __unused8: *mut c_void, - pub __unused9: *mut c_void, - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct timeval { - pub tv_sec: time_t, - pub tv_usec: suseconds_t, - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct timespec { - pub tv_sec: time_t, - pub tv_nsec: c_long, - } - - pub enum timezone {} - - pub type sighandler_t = size_t; - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct rlimit { - pub rlim_cur: rlim_t, - pub rlim_max: rlim_t, - } - } - - pub mod bsd43 { - use types::os::common::posix01::timeval; - use types::os::arch::c95::c_long; - #[repr(C)] - #[derive(Copy, Clone)] - pub struct rusage { - pub ru_utime: timeval, - pub ru_stime: timeval, - pub ru_maxrss: c_long, - pub ru_ixrss: c_long, - pub ru_idrss: c_long, - pub ru_isrss: c_long, - pub ru_minflt: c_long, - pub ru_majflt: c_long, - pub ru_nswap: c_long, - pub ru_inblock: c_long, - pub ru_oublock: c_long, - pub ru_msgsnd: c_long, - pub ru_msgrcv: c_long, - pub ru_nsignals: c_long, - pub ru_nvcsw: c_long, - pub ru_nivcsw: c_long, - } - } - - pub mod bsd44 { - use types::common::c95::c_void; - use types::os::arch::c95::{c_char, c_int, c_uint}; - - pub type socklen_t = u32; - pub type sa_family_t = u8; - pub type in_port_t = u16; - pub type in_addr_t = u32; - #[repr(C)] - #[derive(Copy, Clone)] - pub struct sockaddr { - pub sa_len: u8, - pub sa_family: sa_family_t, - pub sa_data: [u8; 14], - } - #[repr(C)] - #[derive(Copy)] - pub struct sockaddr_storage { - pub ss_len: u8, - pub ss_family: sa_family_t, - pub __ss_pad1: [u8; 6], - pub __ss_pad2: i64, - pub __ss_pad3: [u8; 240], - } - impl ::core::clone::Clone for sockaddr_storage { - fn clone(&self) -> sockaddr_storage { - *self - } - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct sockaddr_in { - pub sin_len: u8, - pub sin_family: sa_family_t, - pub sin_port: in_port_t, - pub sin_addr: in_addr, - pub sin_zero: [u8; 8], - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct in_addr { - pub s_addr: in_addr_t, - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct sockaddr_in6 { - pub sin6_len: u8, - pub sin6_family: sa_family_t, - pub sin6_port: in_port_t, - pub sin6_flowinfo: u32, - pub sin6_addr: in6_addr, - pub sin6_scope_id: u32, - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct in6_addr { - pub s6_addr: [u16; 8], - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct ip_mreq { - pub imr_multiaddr: in_addr, - pub imr_interface: in_addr, - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct ip6_mreq { - pub ipv6mr_multiaddr: in6_addr, - pub ipv6mr_interface: c_uint, - } - #[cfg(not(target_os = "netbsd"))] - #[repr(C)] - #[derive(Copy, Clone)] - pub struct addrinfo { - pub ai_flags: c_int, - pub ai_family: c_int, - pub ai_socktype: c_int, - pub ai_protocol: c_int, - pub ai_addrlen: socklen_t, - pub ai_addr: *mut sockaddr, - pub ai_canonname: *mut c_char, - pub ai_next: *mut addrinfo, - } - #[cfg(target_os = "netbsd")] - #[repr(C)] - #[derive(Copy, Clone)] - pub struct addrinfo { - pub ai_flags: c_int, - pub ai_family: c_int, - pub ai_socktype: c_int, - pub ai_protocol: c_int, - pub ai_addrlen: socklen_t, - pub ai_canonname: *mut c_char, - pub ai_addr: *mut sockaddr, - pub ai_next: *mut addrinfo, - } - #[repr(C)] - #[derive(Copy)] - pub struct sockaddr_un { - pub sun_len: u8, - pub sun_family: sa_family_t, - pub sun_path: [c_char; 104], - } - impl ::core::clone::Clone for sockaddr_un { - fn clone(&self) -> sockaddr_un { - *self - } - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct ifaddrs { - pub ifa_next: *mut ifaddrs, - pub ifa_name: *mut c_char, - pub ifa_flags: c_uint, - pub ifa_addr: *mut sockaddr, - pub ifa_netmask: *mut sockaddr, - pub ifa_dstaddr: *mut sockaddr, - pub ifa_data: *mut c_void, - } - } - } - - #[cfg(target_arch = "x86_64")] - pub mod arch { - pub mod c95 { - pub type c_char = i8; - pub type c_schar = i8; - pub type c_uchar = u8; - pub type c_short = i16; - pub type c_ushort = u16; - pub type c_int = i32; - pub type c_uint = u32; - pub type c_long = i64; - pub type c_ulong = u64; - pub type c_float = f32; - pub type c_double = f64; - pub type size_t = u64; - pub type ptrdiff_t = i64; - pub type clock_t = i64; - pub type time_t = i64; - pub type suseconds_t = i64; - pub type wchar_t = i32; - } - pub mod c99 { - pub type c_longlong = i64; - pub type c_ulonglong = u64; - pub type intptr_t = i64; - pub type uintptr_t = u64; - pub type intmax_t = i64; - pub type uintmax_t = u64; - } - pub mod posix88 { - use types::os::arch::c95::c_long; - pub type off_t = i64; - pub type dev_t = i32; - pub type pid_t = i32; - pub type uid_t = u32; - pub type gid_t = u32; - pub type useconds_t = u32; - pub type mode_t = u32; - pub type ssize_t = c_long; - } - pub mod posix01 { - use types::common::c95::c_void; - use types::common::c99::{uint32_t, uint64_t}; - use types::os::arch::c95::{c_long, time_t}; - use types::os::arch::posix88::{dev_t, gid_t}; - use types::os::arch::posix88::{mode_t, off_t}; - use types::os::arch::posix88::uid_t; - #[cfg(target_os = "netbsd")] - use types::os::arch::c95::{c_int, c_uint}; - - pub type nlink_t = uint32_t; - pub type blksize_t = uint32_t; - pub type ino_t = uint64_t; - pub type blkcnt_t = i64; - pub type fflags_t = u32; // type not declared, but struct stat have u_int32_t - - #[cfg(not(target_os = "netbsd"))] - #[repr(C)] - #[derive(Copy, Clone)] - pub struct stat { - pub st_mode: mode_t, - pub st_dev: dev_t, - pub st_ino: ino_t, - pub st_nlink: nlink_t, - pub st_uid: uid_t, - pub st_gid: gid_t, - pub st_rdev: dev_t, - pub st_atime: time_t, - pub st_atime_nsec: c_long, - pub st_mtime: time_t, - pub st_mtime_nsec: c_long, - pub st_ctime: time_t, - pub st_ctime_nsec: c_long, - pub st_size: off_t, - pub st_blocks: blkcnt_t, - pub st_blksize: blksize_t, - pub st_flags: fflags_t, - pub st_gen: uint32_t, - pub st_birthtime: time_t, - pub st_birthtime_nsec: c_long, - } - #[cfg(target_os = "netbsd")] - #[repr(C)] - #[derive(Copy, Clone)] - pub struct stat { - pub st_mode: mode_t, - pub st_dev: dev_t, - pub st_ino: ino_t, - pub st_nlink: nlink_t, - pub st_uid: uid_t, - pub st_gid: gid_t, - pub st_rdev: dev_t, - pub st_atime: time_t, - pub st_atime_nsec: c_long, - pub st_mtime: time_t, - pub st_mtime_nsec: c_long, - pub st_ctime: time_t, - pub st_ctime_nsec: c_long, - pub st_birthtime: time_t, - pub st_birthtime_nsec: c_long, - pub st_size: off_t, - pub st_blocks: blkcnt_t, - pub st_blksize: blksize_t, - pub st_flags: fflags_t, - pub st_gen: uint32_t, - st_spare: [uint32_t; 2], - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct utimbuf { - pub actime: time_t, - pub modtime: time_t, - } - - #[cfg(not(target_os = "netbsd"))] - pub type pthread_attr_t = *mut c_void; - #[cfg(target_os = "netbsd")] - #[repr(C)] - #[derive(Copy, Clone)] - pub struct pthread_attr_t { - pta_magic: c_uint, - pta_flags: c_int, - pta_private: *mut c_void, - } - } - pub mod posix08 { - } - pub mod bsd44 { - } - pub mod extra { - } - } - } - - #[cfg(target_os = "windows")] - pub mod os { - pub mod common { - pub mod posix01 { - use types::os::arch::c95::{c_short, time_t, c_long}; - use types::os::arch::extra::{int64, time64_t}; - use types::os::arch::posix88::{dev_t, ino_t}; - - // pub Note: this is the struct called stat64 in Windows. Not stat, - // nor stati64. - #[repr(C)] - #[derive(Copy, Clone)] - pub struct stat { - pub st_dev: dev_t, - pub st_ino: ino_t, - pub st_mode: u16, - pub st_nlink: c_short, - pub st_uid: c_short, - pub st_gid: c_short, - pub st_rdev: dev_t, - pub st_size: int64, - pub st_atime: time64_t, - pub st_mtime: time64_t, - pub st_ctime: time64_t, - } - - // note that this is called utimbuf64 in Windows - #[repr(C)] - #[derive(Copy, Clone)] - pub struct utimbuf { - pub actime: time64_t, - pub modtime: time64_t, - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct timeval { - pub tv_sec: c_long, - pub tv_usec: c_long, - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct timespec { - pub tv_sec: time_t, - pub tv_nsec: c_long, - } - - pub enum timezone {} - } - - pub mod bsd44 { - use types::os::arch::c95::{c_char, c_int, c_uint, size_t}; - use types::os::arch::c99::uintptr_t; - - pub type SOCKET = uintptr_t; - pub type socklen_t = c_int; - pub type sa_family_t = u16; - pub type in_port_t = u16; - pub type in_addr_t = u32; - #[repr(C)] - #[derive(Copy, Clone)] - pub struct sockaddr { - pub sa_family: sa_family_t, - pub sa_data: [u8; 14], - } - #[repr(C)] - #[derive(Copy)] - pub struct sockaddr_storage { - pub ss_family: sa_family_t, - pub __ss_pad1: [u8; 6], - pub __ss_align: i64, - pub __ss_pad2: [u8; 112], - } - impl ::core::clone::Clone for sockaddr_storage { - fn clone(&self) -> sockaddr_storage { - *self - } - } - #[repr(C)] - #[derive(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; 8], - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct in_addr { - pub s_addr: in_addr_t, - } - #[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, - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct in6_addr { - pub s6_addr: [u16; 8], - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct ip_mreq { - pub imr_multiaddr: in_addr, - pub imr_interface: in_addr, - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct ip6_mreq { - pub ipv6mr_multiaddr: in6_addr, - pub ipv6mr_interface: c_uint, - } - #[repr(C)] - #[derive(Copy, Clone)] - pub struct addrinfo { - pub ai_flags: c_int, - pub ai_family: c_int, - pub ai_socktype: c_int, - pub ai_protocol: c_int, - pub ai_addrlen: size_t, - pub ai_canonname: *mut c_char, - pub ai_addr: *mut sockaddr, - pub ai_next: *mut addrinfo, - } - #[repr(C)] - #[derive(Copy)] - pub struct sockaddr_un { - pub sun_family: sa_family_t, - pub sun_path: [c_char; 108], - } - impl ::core::clone::Clone for sockaddr_un { - fn clone(&self) -> sockaddr_un { - *self - } - } - } - } - - pub mod arch { - pub mod c95 { - pub type c_char = i8; - pub type c_schar = i8; - pub type c_uchar = u8; - pub type c_short = i16; - pub type c_ushort = u16; - pub type c_int = i32; - pub type c_uint = u32; - pub type c_long = i32; - pub type c_ulong = u32; - pub type c_float = f32; - pub type c_double = f64; - - #[cfg(target_arch = "x86")] - pub type size_t = u32; - #[cfg(target_arch = "x86_64")] - pub type size_t = u64; - - #[cfg(target_arch = "x86")] - pub type ptrdiff_t = i32; - #[cfg(target_arch = "x86_64")] - pub type ptrdiff_t = i64; - - pub type clock_t = i32; - - #[cfg(target_arch = "x86")] - pub type time_t = i32; - #[cfg(target_arch = "x86_64")] - pub type time_t = i64; - - #[cfg(target_arch = "x86")] - pub type suseconds_t = i32; - #[cfg(target_arch = "x86_64")] - pub type suseconds_t = i64; - - pub type wchar_t = u16; - } - - pub mod c99 { - pub type c_longlong = i64; - pub type c_ulonglong = u64; - - #[cfg(target_arch = "x86")] - pub type intptr_t = i32; - #[cfg(target_arch = "x86_64")] - pub type intptr_t = i64; - - #[cfg(target_arch = "x86")] - pub type uintptr_t = u32; - #[cfg(target_arch = "x86_64")] - pub type uintptr_t = u64; - - pub type intmax_t = i64; - pub type uintmax_t = u64; - } - - pub mod posix88 { - pub type off_t = i32; - pub type dev_t = u32; - pub type ino_t = u16; - - pub type pid_t = u32; - - pub type useconds_t = u32; - pub type mode_t = u16; - - #[cfg(target_arch = "x86")] - pub type ssize_t = i32; - #[cfg(target_arch = "x86_64")] - pub type ssize_t = i64; - } - - pub mod posix01 { - } - pub mod posix08 { - } - pub mod bsd44 { - } - pub mod extra { - use consts::os::extra::{MAX_PROTOCOL_CHAIN, WSAPROTOCOL_LEN}; - use types::common::c95::c_void; - use types::os::arch::c95::{c_char, c_int, c_uint, size_t}; - use types::os::arch::c95::{c_long, c_ulong}; - use types::os::arch::c95::wchar_t; - use types::os::arch::c99::{c_ulonglong, c_longlong, uintptr_t}; - - pub type BOOL = c_int; - pub type BYTE = u8; - pub type BOOLEAN = BYTE; - pub type CCHAR = c_char; - pub type CHAR = c_char; - - pub type DWORD = c_ulong; - pub type DWORDLONG = c_ulonglong; - - pub type HANDLE = LPVOID; - pub type HINSTANCE = HANDLE; - pub type HMODULE = HINSTANCE; - - pub type LONG = c_long; - pub type PLONG = *mut c_long; - - #[cfg(target_arch = "x86")] - pub type LONG_PTR = c_long; - #[cfg(target_arch = "x86_64")] - pub type LONG_PTR = i64; - - pub type LARGE_INTEGER = c_longlong; - pub type PLARGE_INTEGER = *mut c_longlong; - - pub type LPCWSTR = *const WCHAR; - pub type LPCSTR = *const CHAR; - - pub type LPWSTR = *mut WCHAR; - pub type LPSTR = *mut CHAR; - - pub type LPWCH = *mut WCHAR; - pub type LPCH = *mut CHAR; - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct SECURITY_ATTRIBUTES { - pub nLength: DWORD, - pub lpSecurityDescriptor: LPVOID, - pub bInheritHandle: BOOL, - } - pub type LPSECURITY_ATTRIBUTES = *mut SECURITY_ATTRIBUTES; - - pub type LPVOID = *mut c_void; - pub type LPCVOID = *const c_void; - pub type LPBYTE = *mut BYTE; - pub type LPWORD = *mut WORD; - pub type LPDWORD = *mut DWORD; - pub type LPHANDLE = *mut HANDLE; - - pub type LRESULT = LONG_PTR; - pub type PBOOL = *mut BOOL; - pub type WCHAR = wchar_t; - pub type WORD = u16; - pub type SIZE_T = size_t; - - pub type time64_t = i64; - pub type int64 = i64; - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct STARTUPINFO { - pub cb: DWORD, - pub lpReserved: LPWSTR, - pub lpDesktop: LPWSTR, - pub lpTitle: LPWSTR, - pub dwX: DWORD, - pub dwY: DWORD, - pub dwXSize: DWORD, - pub dwYSize: DWORD, - pub dwXCountChars: DWORD, - pub dwYCountCharts: DWORD, - pub dwFillAttribute: DWORD, - pub dwFlags: DWORD, - pub wShowWindow: WORD, - pub cbReserved2: WORD, - pub lpReserved2: LPBYTE, - pub hStdInput: HANDLE, - pub hStdOutput: HANDLE, - pub hStdError: HANDLE, - } - pub type LPSTARTUPINFO = *mut STARTUPINFO; - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct PROCESS_INFORMATION { - pub hProcess: HANDLE, - pub hThread: HANDLE, - pub dwProcessId: DWORD, - pub dwThreadId: DWORD, - } - pub type LPPROCESS_INFORMATION = *mut PROCESS_INFORMATION; - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct SYSTEM_INFO { - pub wProcessorArchitecture: WORD, - pub wReserved: WORD, - pub dwPageSize: DWORD, - pub lpMinimumApplicationAddress: LPVOID, - pub lpMaximumApplicationAddress: LPVOID, - pub dwActiveProcessorMask: uintptr_t, - pub dwNumberOfProcessors: DWORD, - pub dwProcessorType: DWORD, - pub dwAllocationGranularity: DWORD, - pub wProcessorLevel: WORD, - pub wProcessorRevision: WORD, - } - pub type LPSYSTEM_INFO = *mut SYSTEM_INFO; - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct MEMORY_BASIC_INFORMATION { - pub BaseAddress: LPVOID, - pub AllocationBase: LPVOID, - pub AllocationProtect: DWORD, - pub RegionSize: SIZE_T, - pub State: DWORD, - pub Protect: DWORD, - pub Type: DWORD, - } - pub type LPMEMORY_BASIC_INFORMATION = *mut MEMORY_BASIC_INFORMATION; - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct OVERLAPPED { - pub Internal: *mut c_ulong, - pub InternalHigh: *mut c_ulong, - pub Offset: DWORD, - pub OffsetHigh: DWORD, - pub hEvent: HANDLE, - } - - pub type LPOVERLAPPED = *mut OVERLAPPED; - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct FILETIME { - pub dwLowDateTime: DWORD, - pub dwHighDateTime: DWORD, - } - - pub type LPFILETIME = *mut FILETIME; - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct GUID { - pub Data1: DWORD, - pub Data2: WORD, - pub Data3: WORD, - pub Data4: [BYTE; 8], - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct WSAPROTOCOLCHAIN { - pub ChainLen: c_int, - pub ChainEntries: [DWORD; MAX_PROTOCOL_CHAIN as usize], - } - - pub type LPWSAPROTOCOLCHAIN = *mut WSAPROTOCOLCHAIN; - - #[repr(C)] - #[derive(Copy)] - pub struct WSAPROTOCOL_INFO { - pub dwServiceFlags1: DWORD, - pub dwServiceFlags2: DWORD, - pub dwServiceFlags3: DWORD, - pub dwServiceFlags4: DWORD, - pub dwProviderFlags: DWORD, - pub ProviderId: GUID, - pub dwCatalogEntryId: DWORD, - pub ProtocolChain: WSAPROTOCOLCHAIN, - pub iVersion: c_int, - pub iAddressFamily: c_int, - pub iMaxSockAddr: c_int, - pub iMinSockAddr: c_int, - pub iSocketType: c_int, - pub iProtocol: c_int, - pub iProtocolMaxOffset: c_int, - pub iNetworkByteOrder: c_int, - pub iSecurityScheme: c_int, - pub dwMessageSize: DWORD, - pub dwProviderReserved: DWORD, - pub szProtocol: [u8; (WSAPROTOCOL_LEN as usize) + 1], - } - impl ::core::clone::Clone for WSAPROTOCOL_INFO { - fn clone(&self) -> WSAPROTOCOL_INFO { - *self - } - } - - pub type LPWSAPROTOCOL_INFO = *mut WSAPROTOCOL_INFO; - - pub type GROUP = c_uint; - - #[repr(C)] - #[derive(Copy)] - pub struct WIN32_FIND_DATAW { - pub dwFileAttributes: DWORD, - pub ftCreationTime: FILETIME, - pub ftLastAccessTime: FILETIME, - pub ftLastWriteTime: FILETIME, - pub nFileSizeHigh: DWORD, - pub nFileSizeLow: DWORD, - pub dwReserved0: DWORD, - pub dwReserved1: DWORD, - pub cFileName: [wchar_t; 260], // #define MAX_PATH 260 - pub cAlternateFileName: [wchar_t; 14], - } - impl ::core::clone::Clone for WIN32_FIND_DATAW { - fn clone(&self) -> WIN32_FIND_DATAW { - *self - } - } - - pub type LPWIN32_FIND_DATAW = *mut WIN32_FIND_DATAW; - } - } - } - - #[cfg(any(target_os = "macos", target_os = "ios"))] - pub mod os { - pub mod common { - pub mod posix01 { - use types::common::c95::c_void; - use types::os::arch::c95::{c_char, c_int, size_t, time_t}; - use types::os::arch::c95::{suseconds_t, c_long}; - use types::os::arch::c99::uintptr_t; - - pub type pthread_t = uintptr_t; - pub type rlim_t = u64; - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct glob_t { - pub gl_pathc: size_t, - pub __unused1: c_int, - pub gl_offs: size_t, - pub __unused2: c_int, - pub gl_pathv: *mut *mut c_char, - - pub __unused3: *mut c_void, - - pub __unused4: *mut c_void, - pub __unused5: *mut c_void, - pub __unused6: *mut c_void, - pub __unused7: *mut c_void, - pub __unused8: *mut c_void, - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct timeval { - pub tv_sec: time_t, - pub tv_usec: suseconds_t, - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct timespec { - pub tv_sec: time_t, - pub tv_nsec: c_long, - } - - pub enum timezone {} - - pub type sighandler_t = size_t; - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct rlimit { - pub rlim_cur: rlim_t, - pub rlim_max: rlim_t, - } - } - - pub mod bsd43 { - use types::os::common::posix01::timeval; - use types::os::arch::c95::c_long; - #[repr(C)] - #[derive(Copy, Clone)] - pub struct rusage { - pub ru_utime: timeval, - pub ru_stime: timeval, - pub ru_maxrss: c_long, - pub ru_ixrss: c_long, - pub ru_idrss: c_long, - pub ru_isrss: c_long, - pub ru_minflt: c_long, - pub ru_majflt: c_long, - pub ru_nswap: c_long, - pub ru_inblock: c_long, - pub ru_oublock: c_long, - pub ru_msgsnd: c_long, - pub ru_msgrcv: c_long, - pub ru_nsignals: c_long, - pub ru_nvcsw: c_long, - pub ru_nivcsw: c_long, - } - } - - pub mod bsd44 { - use types::common::c95::c_void; - use types::os::arch::c95::{c_char, c_int, c_uint}; - - pub type socklen_t = u32; - pub type sa_family_t = u8; - pub type in_port_t = u16; - pub type in_addr_t = u32; - #[repr(C)] - #[derive(Copy, Clone)] - pub struct sockaddr { - pub sa_len: u8, - pub sa_family: sa_family_t, - pub sa_data: [u8; 14], - } - - #[repr(C)] - #[derive(Copy)] - pub struct sockaddr_storage { - pub ss_len: u8, - pub ss_family: sa_family_t, - pub __ss_pad1: [u8; 6], - pub __ss_align: i64, - pub __ss_pad2: [u8; 112], - } - impl ::core::clone::Clone for sockaddr_storage { - fn clone(&self) -> sockaddr_storage { - *self - } - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct sockaddr_in { - pub sin_len: u8, - pub sin_family: sa_family_t, - pub sin_port: in_port_t, - pub sin_addr: in_addr, - pub sin_zero: [u8; 8], - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct in_addr { - pub s_addr: in_addr_t, - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct sockaddr_in6 { - pub sin6_len: u8, - pub sin6_family: sa_family_t, - pub sin6_port: in_port_t, - pub sin6_flowinfo: u32, - pub sin6_addr: in6_addr, - pub sin6_scope_id: u32, - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct in6_addr { - pub s6_addr: [u16; 8], - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct ip_mreq { - pub imr_multiaddr: in_addr, - pub imr_interface: in_addr, - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct ip6_mreq { - pub ipv6mr_multiaddr: in6_addr, - pub ipv6mr_interface: c_uint, - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct addrinfo { - pub ai_flags: c_int, - pub ai_family: c_int, - pub ai_socktype: c_int, - pub ai_protocol: c_int, - pub ai_addrlen: socklen_t, - pub ai_canonname: *mut c_char, - pub ai_addr: *mut sockaddr, - pub ai_next: *mut addrinfo, - } - - #[repr(C)] - #[derive(Copy)] - pub struct sockaddr_un { - pub sun_len: u8, - pub sun_family: sa_family_t, - pub sun_path: [c_char; 104], - } - impl ::core::clone::Clone for sockaddr_un { - fn clone(&self) -> sockaddr_un { - *self - } - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct ifaddrs { - pub ifa_next: *mut ifaddrs, - pub ifa_name: *mut c_char, - pub ifa_flags: c_uint, - pub ifa_addr: *mut sockaddr, - pub ifa_netmask: *mut sockaddr, - pub ifa_dstaddr: *mut sockaddr, - pub ifa_data: *mut c_void, - } - } - } - - #[cfg(any(target_arch = "arm", target_arch = "x86"))] - pub mod arch { - pub mod c95 { - pub type c_char = i8; - pub type c_schar = i8; - pub type c_uchar = u8; - pub type c_short = i16; - pub type c_ushort = u16; - pub type c_int = i32; - pub type c_uint = u32; - pub type c_long = i32; - pub type c_ulong = u32; - pub type c_float = f32; - pub type c_double = f64; - pub type size_t = u32; - pub type ptrdiff_t = i32; - pub type clock_t = c_ulong; - pub type time_t = c_long; - pub type suseconds_t = i32; - pub type wchar_t = i32; - } - pub mod c99 { - pub type c_longlong = i64; - pub type c_ulonglong = u64; - pub type intptr_t = i32; - pub type uintptr_t = u32; - pub type intmax_t = i64; - pub type uintmax_t = u64; - } - pub mod posix88 { - use types::os::arch::c95::c_long; - - pub type off_t = i64; - pub type dev_t = i32; - pub type ino_t = u64; - pub type pid_t = i32; - pub type uid_t = u32; - pub type gid_t = u32; - pub type useconds_t = u32; - pub type mode_t = u16; - pub type ssize_t = c_long; - } - pub mod posix01 { - use types::common::c99::{int32_t, int64_t, uint32_t}; - use types::os::arch::c95::{c_char, c_long, time_t}; - use types::os::arch::posix88::{dev_t, gid_t, ino_t, mode_t, off_t, uid_t}; - - pub type nlink_t = u16; - pub type blksize_t = i32; - pub type blkcnt_t = i64; - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct stat { - pub st_dev: dev_t, - pub st_mode: mode_t, - pub st_nlink: nlink_t, - pub st_ino: ino_t, - pub st_uid: uid_t, - pub st_gid: gid_t, - pub st_rdev: dev_t, - pub st_atime: time_t, - pub st_atime_nsec: c_long, - pub st_mtime: time_t, - pub st_mtime_nsec: c_long, - pub st_ctime: time_t, - pub st_ctime_nsec: c_long, - pub st_birthtime: time_t, - pub st_birthtime_nsec: c_long, - pub st_size: off_t, - pub st_blocks: blkcnt_t, - pub st_blksize: blksize_t, - pub st_flags: uint32_t, - pub st_gen: uint32_t, - pub st_lspare: int32_t, - pub st_qspare: [int64_t; 2], - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct utimbuf { - pub actime: time_t, - pub modtime: time_t, - } - - #[repr(C)] - #[derive(Copy)] - pub struct pthread_attr_t { - pub __sig: c_long, - pub __opaque: [c_char; 36], - } - impl ::core::clone::Clone for pthread_attr_t { - fn clone(&self) -> pthread_attr_t { - *self - } - } - } - pub mod posix08 { - } - pub mod bsd44 { - } - pub mod extra { - #[repr(C)] - #[derive(Copy, Clone)] - pub struct mach_timebase_info { - pub numer: u32, - pub denom: u32, - } - - pub type mach_timebase_info_data_t = mach_timebase_info; - } - } - - #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] - pub mod arch { - pub mod c95 { - pub type c_char = i8; - pub type c_schar = i8; - pub type c_uchar = u8; - pub type c_short = i16; - pub type c_ushort = u16; - pub type c_int = i32; - pub type c_uint = u32; - pub type c_long = i64; - pub type c_ulong = u64; - pub type c_float = f32; - pub type c_double = f64; - pub type size_t = u64; - pub type ptrdiff_t = i64; - pub type clock_t = c_ulong; - pub type time_t = c_long; - pub type suseconds_t = i32; - pub type wchar_t = i32; - } - pub mod c99 { - pub type c_longlong = i64; - pub type c_ulonglong = u64; - pub type intptr_t = i64; - pub type uintptr_t = u64; - pub type intmax_t = i64; - pub type uintmax_t = u64; - } - pub mod posix88 { - use types::os::arch::c95::c_long; - - pub type off_t = i64; - pub type dev_t = i32; - pub type ino_t = u64; - pub type pid_t = i32; - pub type uid_t = u32; - pub type gid_t = u32; - pub type useconds_t = u32; - pub type mode_t = u16; - pub type ssize_t = c_long; - } - pub mod posix01 { - use types::common::c99::{int32_t, int64_t}; - use types::common::c99::uint32_t; - use types::os::arch::c95::{c_char, c_long, time_t}; - use types::os::arch::posix88::{dev_t, gid_t, ino_t}; - use types::os::arch::posix88::{mode_t, off_t, uid_t}; - - pub type nlink_t = u16; - pub type blksize_t = i32; - pub type blkcnt_t = i64; - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct stat { - pub st_dev: dev_t, - pub st_mode: mode_t, - pub st_nlink: nlink_t, - pub st_ino: ino_t, - pub st_uid: uid_t, - pub st_gid: gid_t, - pub st_rdev: dev_t, - pub st_atime: time_t, - pub st_atime_nsec: c_long, - pub st_mtime: time_t, - pub st_mtime_nsec: c_long, - pub st_ctime: time_t, - pub st_ctime_nsec: c_long, - pub st_birthtime: time_t, - pub st_birthtime_nsec: c_long, - pub st_size: off_t, - pub st_blocks: blkcnt_t, - pub st_blksize: blksize_t, - pub st_flags: uint32_t, - pub st_gen: uint32_t, - pub st_lspare: int32_t, - pub st_qspare: [int64_t; 2], - } - - #[repr(C)] - #[derive(Copy, Clone)] - pub struct utimbuf { - pub actime: time_t, - pub modtime: time_t, - } - - #[repr(C)] - #[derive(Copy)] - pub struct pthread_attr_t { - pub __sig: c_long, - pub __opaque: [c_char; 56], - } - impl ::core::clone::Clone for pthread_attr_t { - fn clone(&self) -> pthread_attr_t { - *self - } - } - } - pub mod posix08 { - } - pub mod bsd44 { - } - pub mod extra { - #[repr(C)] - #[derive(Copy, Clone)] - pub struct mach_timebase_info { - pub numer: u32, - pub denom: u32, - } - - pub type mach_timebase_info_data_t = mach_timebase_info; - } - } - } -} - -pub mod consts { - // Consts tend to vary per OS so we pull their definitions out - // into this module. - - #[cfg(target_os = "windows")] - pub mod os { - pub mod c95 { - use types::os::arch::c95::{c_int, c_uint}; - - pub const EXIT_FAILURE: c_int = 1; - pub const EXIT_SUCCESS: c_int = 0; - pub const RAND_MAX: c_int = 32767; - pub const EOF: c_int = -1; - pub const SEEK_SET: c_int = 0; - pub const SEEK_CUR: c_int = 1; - pub const SEEK_END: c_int = 2; - pub const _IOFBF: c_int = 0; - pub const _IONBF: c_int = 4; - pub const _IOLBF: c_int = 64; - pub const BUFSIZ: c_uint = 512; - pub const FOPEN_MAX: c_uint = 20; - pub const FILENAME_MAX: c_uint = 260; - pub const L_tmpnam: c_uint = 16; - pub const TMP_MAX: c_uint = 32767; - - pub const WSAEINTR: c_int = 10004; - pub const WSAEBADF: c_int = 10009; - pub const WSAEACCES: c_int = 10013; - pub const WSAEFAULT: c_int = 10014; - pub const WSAEINVAL: c_int = 10022; - pub const WSAEMFILE: c_int = 10024; - pub const WSAEWOULDBLOCK: c_int = 10035; - pub const WSAEINPROGRESS: c_int = 10036; - pub const WSAEALREADY: c_int = 10037; - pub const WSAENOTSOCK: c_int = 10038; - pub const WSAEDESTADDRREQ: c_int = 10039; - pub const WSAEMSGSIZE: c_int = 10040; - pub const WSAEPROTOTYPE: c_int = 10041; - pub const WSAENOPROTOOPT: c_int = 10042; - pub const WSAEPROTONOSUPPORT: c_int = 10043; - pub const WSAESOCKTNOSUPPORT: c_int = 10044; - pub const WSAEOPNOTSUPP: c_int = 10045; - pub const WSAEPFNOSUPPORT: c_int = 10046; - pub const WSAEAFNOSUPPORT: c_int = 10047; - pub const WSAEADDRINUSE: c_int = 10048; - pub const WSAEADDRNOTAVAIL: c_int = 10049; - pub const WSAENETDOWN: c_int = 10050; - pub const WSAENETUNREACH: c_int = 10051; - pub const WSAENETRESET: c_int = 10052; - pub const WSAECONNABORTED: c_int = 10053; - pub const WSAECONNRESET: c_int = 10054; - pub const WSAENOBUFS: c_int = 10055; - pub const WSAEISCONN: c_int = 10056; - pub const WSAENOTCONN: c_int = 10057; - pub const WSAESHUTDOWN: c_int = 10058; - pub const WSAETOOMANYREFS: c_int = 10059; - pub const WSAETIMEDOUT: c_int = 10060; - pub const WSAECONNREFUSED: c_int = 10061; - pub const WSAELOOP: c_int = 10062; - pub const WSAENAMETOOLONG: c_int = 10063; - pub const WSAEHOSTDOWN: c_int = 10064; - pub const WSAEHOSTUNREACH: c_int = 10065; - pub const WSAENOTEMPTY: c_int = 10066; - pub const WSAEPROCLIM: c_int = 10067; - pub const WSAEUSERS: c_int = 10068; - pub const WSAEDQUOT: c_int = 10069; - pub const WSAESTALE: c_int = 10070; - pub const WSAEREMOTE: c_int = 10071; - pub const WSASYSNOTREADY: c_int = 10091; - pub const WSAVERNOTSUPPORTED: c_int = 10092; - pub const WSANOTINITIALISED: c_int = 10093; - pub const WSAEDISCON: c_int = 10101; - pub const WSAENOMORE: c_int = 10102; - pub const WSAECANCELLED: c_int = 10103; - pub const WSAEINVALIDPROCTABLE: c_int = 10104; - pub const WSAEINVALIDPROVIDER: c_int = 10105; - pub const WSAEPROVIDERFAILEDINIT: c_int = 10106; - } - pub mod c99 { - } - pub mod posix88 { - use types::os::arch::c95::c_int; - use types::os::arch::posix88::mode_t; - - pub const O_RDONLY: c_int = 0; - pub const O_WRONLY: c_int = 1; - pub const O_RDWR: c_int = 2; - pub const O_APPEND: c_int = 8; - pub const O_CREAT: c_int = 256; - pub const O_EXCL: c_int = 1024; - pub const O_TRUNC: c_int = 512; - pub const S_IFIFO: c_int = 4096; - pub const S_IFCHR: c_int = 8192; - pub const S_IFBLK: c_int = 12288; - pub const S_IFDIR: c_int = 16384; - pub const S_IFREG: c_int = 32768; - pub const S_IFLNK: c_int = 40960; - pub const S_IFSOCK: mode_t = 49152; - pub const S_IFMT: c_int = 61440; - pub const S_IEXEC: c_int = 64; - pub const S_IWRITE: c_int = 128; - pub const S_IREAD: c_int = 256; - pub const S_IRWXU: c_int = 448; - pub const S_IXUSR: c_int = 64; - pub const S_IWUSR: c_int = 128; - pub const S_IRUSR: c_int = 256; - pub const S_IRWXG: mode_t = 56; - pub const S_IXGRP: mode_t = 8; - pub const S_IWGRP: mode_t = 16; - pub const S_IRGRP: mode_t = 32; - pub const S_IRWXO: mode_t = 7; - pub const S_IXOTH: mode_t = 1; - pub const S_IWOTH: mode_t = 2; - pub const S_IROTH: mode_t = 4; - pub const F_OK: c_int = 0; - pub const R_OK: c_int = 4; - pub const W_OK: c_int = 2; - pub const X_OK: c_int = 1; - pub const STDIN_FILENO: c_int = 0; - pub const STDOUT_FILENO: c_int = 1; - pub const STDERR_FILENO: c_int = 2; - } - pub mod posix01 { - } - pub mod posix08 { - } - pub mod bsd44 { - use types::os::arch::c95::c_int; - - pub const AF_INET: c_int = 2; - pub const AF_INET6: c_int = 23; - pub const SOCK_STREAM: c_int = 1; - pub const SOCK_DGRAM: c_int = 2; - pub const SOCK_RAW: c_int = 3; - pub const IPPROTO_TCP: c_int = 6; - pub const IPPROTO_IP: c_int = 0; - pub const IPPROTO_IPV6: c_int = 41; - pub const IP_MULTICAST_TTL: c_int = 10; - pub const IP_MULTICAST_LOOP: c_int = 11; - pub const IP_ADD_MEMBERSHIP: c_int = 12; - pub const IP_DROP_MEMBERSHIP: c_int = 13; - pub const IPV6_ADD_MEMBERSHIP: c_int = 5; - pub const IPV6_DROP_MEMBERSHIP: c_int = 6; - pub const IP_TTL: c_int = 4; - pub const IP_HDRINCL: c_int = 2; - - pub const TCP_NODELAY: c_int = 0x0001; - pub const SOL_SOCKET: c_int = 0xffff; - - pub const SO_DEBUG: c_int = 0x0001; - pub const SO_ACCEPTCONN: c_int = 0x0002; - pub const SO_REUSEADDR: c_int = 0x0004; - pub const SO_KEEPALIVE: c_int = 0x0008; - pub const SO_DONTROUTE: c_int = 0x0010; - pub const SO_BROADCAST: c_int = 0x0020; - pub const SO_USELOOPBACK: c_int = 0x0040; - pub const SO_LINGER: c_int = 0x0080; - pub const SO_OOBINLINE: c_int = 0x0100; - pub const SO_SNDBUF: c_int = 0x1001; - pub const SO_RCVBUF: c_int = 0x1002; - pub const SO_SNDLOWAT: c_int = 0x1003; - pub const SO_RCVLOWAT: c_int = 0x1004; - pub const SO_SNDTIMEO: c_int = 0x1005; - pub const SO_RCVTIMEO: c_int = 0x1006; - pub const SO_ERROR: c_int = 0x1007; - pub const SO_TYPE: c_int = 0x1008; - - pub const IFF_LOOPBACK: c_int = 4; - - pub const SHUT_RD: c_int = 0; - pub const SHUT_WR: c_int = 1; - pub const SHUT_RDWR: c_int = 2; - } - pub mod extra { - use types::os::common::bsd44::SOCKET; - use types::os::arch::c95::{c_int, c_long}; - use types::os::arch::extra::{WORD, DWORD, BOOL, HANDLE}; - - pub const TRUE: BOOL = 1; - pub const FALSE: BOOL = 0; - - pub const O_TEXT: c_int = 16384; - pub const O_BINARY: c_int = 32768; - pub const O_NOINHERIT: c_int = 128; - - pub const ERROR_SUCCESS: c_int = 0; - pub const ERROR_INVALID_FUNCTION: c_int = 1; - pub const ERROR_FILE_NOT_FOUND: c_int = 2; - pub const ERROR_ACCESS_DENIED: c_int = 5; - pub const ERROR_INVALID_HANDLE: c_int = 6; - pub const ERROR_BROKEN_PIPE: c_int = 109; - pub const ERROR_DISK_FULL: c_int = 112; - pub const ERROR_CALL_NOT_IMPLEMENTED: c_int = 120; - pub const ERROR_INSUFFICIENT_BUFFER: c_int = 122; - pub const ERROR_INVALID_NAME: c_int = 123; - pub const ERROR_ALREADY_EXISTS: c_int = 183; - pub const ERROR_PIPE_BUSY: c_int = 231; - pub const ERROR_NO_DATA: c_int = 232; - pub const ERROR_INVALID_ADDRESS: c_int = 487; - pub const ERROR_PIPE_CONNECTED: c_int = 535; - pub const ERROR_NOTHING_TO_TERMINATE: c_int = 758; - pub const ERROR_OPERATION_ABORTED: c_int = 995; - pub const ERROR_IO_PENDING: c_int = 997; - pub const ERROR_FILE_INVALID: c_int = 1006; - pub const ERROR_NOT_FOUND: c_int = 1168; - pub const INVALID_HANDLE_VALUE: HANDLE = !0 as HANDLE; - - pub const DELETE: DWORD = 0x00010000; - pub const READ_CONTROL: DWORD = 0x00020000; - pub const SYNCHRONIZE: DWORD = 0x00100000; - pub const WRITE_DAC: DWORD = 0x00040000; - pub const WRITE_OWNER: DWORD = 0x00080000; - - pub const PROCESS_CREATE_PROCESS: DWORD = 0x0080; - pub const PROCESS_CREATE_THREAD: DWORD = 0x0002; - pub const PROCESS_DUP_HANDLE: DWORD = 0x0040; - pub const PROCESS_QUERY_INFORMATION: DWORD = 0x0400; - pub const PROCESS_QUERY_LIMITED_INFORMATION: DWORD = 0x1000; - pub const PROCESS_SET_INFORMATION: DWORD = 0x0200; - pub const PROCESS_SET_QUOTA: DWORD = 0x0100; - pub const PROCESS_SUSPEND_RESUME: DWORD = 0x0800; - pub const PROCESS_TERMINATE: DWORD = 0x0001; - pub const PROCESS_VM_OPERATION: DWORD = 0x0008; - pub const PROCESS_VM_READ: DWORD = 0x0010; - pub const PROCESS_VM_WRITE: DWORD = 0x0020; - - pub const STARTF_FORCEONFEEDBACK: DWORD = 0x00000040; - pub const STARTF_FORCEOFFFEEDBACK: DWORD = 0x00000080; - pub const STARTF_PREVENTPINNING: DWORD = 0x00002000; - pub const STARTF_RUNFULLSCREEN: DWORD = 0x00000020; - pub const STARTF_TITLEISAPPID: DWORD = 0x00001000; - pub const STARTF_TITLEISLINKNAME: DWORD = 0x00000800; - pub const STARTF_USECOUNTCHARS: DWORD = 0x00000008; - pub const STARTF_USEFILLATTRIBUTE: DWORD = 0x00000010; - pub const STARTF_USEHOTKEY: DWORD = 0x00000200; - pub const STARTF_USEPOSITION: DWORD = 0x00000004; - pub const STARTF_USESHOWWINDOW: DWORD = 0x00000001; - pub const STARTF_USESIZE: DWORD = 0x00000002; - pub const STARTF_USESTDHANDLES: DWORD = 0x00000100; - - pub const WAIT_ABANDONED: DWORD = 0x00000080; - pub const WAIT_OBJECT_0: DWORD = 0x00000000; - pub const WAIT_TIMEOUT: DWORD = 0x00000102; - pub const WAIT_FAILED: DWORD = !0; - - pub const DUPLICATE_CLOSE_SOURCE: DWORD = 0x00000001; - pub const DUPLICATE_SAME_ACCESS: DWORD = 0x00000002; - - pub const INFINITE: DWORD = !0; - pub const STILL_ACTIVE: DWORD = 259; - - pub const MEM_COMMIT: DWORD = 0x00001000; - pub const MEM_RESERVE: DWORD = 0x00002000; - pub const MEM_DECOMMIT: DWORD = 0x00004000; - pub const MEM_RELEASE: DWORD = 0x00008000; - pub const MEM_RESET: DWORD = 0x00080000; - pub const MEM_RESET_UNDO: DWORD = 0x1000000; - pub const MEM_LARGE_PAGES: DWORD = 0x20000000; - pub const MEM_PHYSICAL: DWORD = 0x00400000; - pub const MEM_TOP_DOWN: DWORD = 0x00100000; - pub const MEM_WRITE_WATCH: DWORD = 0x00200000; - - pub const PAGE_EXECUTE: DWORD = 0x10; - pub const PAGE_EXECUTE_READ: DWORD = 0x20; - pub const PAGE_EXECUTE_READWRITE: DWORD = 0x40; - pub const PAGE_EXECUTE_WRITECOPY: DWORD = 0x80; - pub const PAGE_NOACCESS: DWORD = 0x01; - pub const PAGE_READONLY: DWORD = 0x02; - pub const PAGE_READWRITE: DWORD = 0x04; - pub const PAGE_WRITECOPY: DWORD = 0x08; - pub const PAGE_GUARD: DWORD = 0x100; - pub const PAGE_NOCACHE: DWORD = 0x200; - pub const PAGE_WRITECOMBINE: DWORD = 0x400; - - pub const SEC_COMMIT: DWORD = 0x8000000; - pub const SEC_IMAGE: DWORD = 0x1000000; - pub const SEC_IMAGE_NO_EXECUTE: DWORD = 0x11000000; - pub const SEC_LARGE_PAGES: DWORD = 0x80000000; - pub const SEC_NOCACHE: DWORD = 0x10000000; - pub const SEC_RESERVE: DWORD = 0x4000000; - pub const SEC_WRITECOMBINE: DWORD = 0x40000000; - - pub const FILE_MAP_ALL_ACCESS: DWORD = 0xf001f; - pub const FILE_MAP_READ: DWORD = 0x4; - pub const FILE_MAP_WRITE: DWORD = 0x2; - pub const FILE_MAP_COPY: DWORD = 0x1; - pub const FILE_MAP_EXECUTE: DWORD = 0x20; - - pub const PROCESSOR_ARCHITECTURE_INTEL: WORD = 0; - pub const PROCESSOR_ARCHITECTURE_ARM: WORD = 5; - pub const PROCESSOR_ARCHITECTURE_IA64: WORD = 6; - pub const PROCESSOR_ARCHITECTURE_AMD64: WORD = 9; - pub const PROCESSOR_ARCHITECTURE_UNKNOWN: WORD = 0xffff; - - pub const MOVEFILE_COPY_ALLOWED: DWORD = 2; - pub const MOVEFILE_CREATE_HARDLINK: DWORD = 16; - pub const MOVEFILE_DELAY_UNTIL_REBOOT: DWORD = 4; - pub const MOVEFILE_FAIL_IF_NOT_TRACKABLE: DWORD = 32; - pub const MOVEFILE_REPLACE_EXISTING: DWORD = 1; - pub const MOVEFILE_WRITE_THROUGH: DWORD = 8; - - pub const SYMBOLIC_LINK_FLAG_DIRECTORY: DWORD = 1; - - pub const FILE_SHARE_DELETE: DWORD = 0x4; - pub const FILE_SHARE_READ: DWORD = 0x1; - pub const FILE_SHARE_WRITE: DWORD = 0x2; - - pub const CREATE_ALWAYS: DWORD = 2; - pub const CREATE_NEW: DWORD = 1; - pub const OPEN_ALWAYS: DWORD = 4; - pub const OPEN_EXISTING: DWORD = 3; - pub const TRUNCATE_EXISTING: DWORD = 5; - - pub const FILE_APPEND_DATA: DWORD = 0x00000004; - pub const FILE_READ_DATA: DWORD = 0x00000001; - pub const FILE_WRITE_DATA: DWORD = 0x00000002; - - pub const FILE_ATTRIBUTE_ARCHIVE: DWORD = 0x20; - pub const FILE_ATTRIBUTE_COMPRESSED: DWORD = 0x800; - pub const FILE_ATTRIBUTE_DEVICE: DWORD = 0x40; - pub const FILE_ATTRIBUTE_DIRECTORY: DWORD = 0x10; - pub const FILE_ATTRIBUTE_ENCRYPTED: DWORD = 0x4000; - pub const FILE_ATTRIBUTE_HIDDEN: DWORD = 0x2; - pub const FILE_ATTRIBUTE_INTEGRITY_STREAM: DWORD = 0x8000; - pub const FILE_ATTRIBUTE_NORMAL: DWORD = 0x80; - pub const FILE_ATTRIBUTE_NOT_CONTENT_INDEXED: DWORD = 0x2000; - pub const FILE_ATTRIBUTE_NO_SCRUB_DATA: DWORD = 0x20000; - pub const FILE_ATTRIBUTE_OFFLINE: DWORD = 0x1000; - pub const FILE_ATTRIBUTE_READONLY: DWORD = 0x1; - pub const FILE_ATTRIBUTE_REPARSE_POINT: DWORD = 0x400; - pub const FILE_ATTRIBUTE_SPARSE_FILE: DWORD = 0x200; - pub const FILE_ATTRIBUTE_SYSTEM: DWORD = 0x4; - pub const FILE_ATTRIBUTE_TEMPORARY: DWORD = 0x100; - pub const FILE_ATTRIBUTE_VIRTUAL: DWORD = 0x10000; - - pub const FILE_FLAG_BACKUP_SEMANTICS: DWORD = 0x02000000; - pub const FILE_FLAG_DELETE_ON_CLOSE: DWORD = 0x04000000; - pub const FILE_FLAG_NO_BUFFERING: DWORD = 0x20000000; - pub const FILE_FLAG_OPEN_NO_RECALL: DWORD = 0x00100000; - pub const FILE_FLAG_OPEN_REPARSE_POINT: DWORD = 0x00200000; - pub const FILE_FLAG_OVERLAPPED: DWORD = 0x40000000; - pub const FILE_FLAG_POSIX_SEMANTICS: DWORD = 0x0100000; - pub const FILE_FLAG_RANDOM_ACCESS: DWORD = 0x10000000; - pub const FILE_FLAG_SESSION_AWARE: DWORD = 0x00800000; - pub const FILE_FLAG_SEQUENTIAL_SCAN: DWORD = 0x08000000; - pub const FILE_FLAG_WRITE_THROUGH: DWORD = 0x80000000; - pub const FILE_FLAG_FIRST_PIPE_INSTANCE: DWORD = 0x00080000; - - pub const FILE_NAME_NORMALIZED: DWORD = 0x0; - pub const FILE_NAME_OPENED: DWORD = 0x8; - - pub const VOLUME_NAME_DOS: DWORD = 0x0; - pub const VOLUME_NAME_GUID: DWORD = 0x1; - pub const VOLUME_NAME_NONE: DWORD = 0x4; - pub const VOLUME_NAME_NT: DWORD = 0x2; - - pub const GENERIC_READ: DWORD = 0x80000000; - pub const GENERIC_WRITE: DWORD = 0x40000000; - pub const GENERIC_EXECUTE: DWORD = 0x20000000; - pub const GENERIC_ALL: DWORD = 0x10000000; - pub const FILE_WRITE_ATTRIBUTES: DWORD = 0x00000100; - pub const FILE_READ_ATTRIBUTES: DWORD = 0x00000080; - - pub const STANDARD_RIGHTS_READ: DWORD = 0x20000; - pub const STANDARD_RIGHTS_WRITE: DWORD = 0x20000; - pub const FILE_WRITE_EA: DWORD = 0x00000010; - pub const FILE_READ_EA: DWORD = 0x00000008; - pub const FILE_GENERIC_READ: DWORD = STANDARD_RIGHTS_READ | FILE_READ_DATA | - FILE_READ_ATTRIBUTES | - FILE_READ_EA | - SYNCHRONIZE; - pub const FILE_GENERIC_WRITE: DWORD = STANDARD_RIGHTS_WRITE | FILE_WRITE_DATA | - FILE_WRITE_ATTRIBUTES | - FILE_WRITE_EA | - FILE_APPEND_DATA | - SYNCHRONIZE; - - pub const FILE_BEGIN: DWORD = 0; - pub const FILE_CURRENT: DWORD = 1; - pub const FILE_END: DWORD = 2; - - pub const MAX_PROTOCOL_CHAIN: DWORD = 7; - pub const WSAPROTOCOL_LEN: DWORD = 255; - pub const INVALID_SOCKET: SOCKET = !0; - - pub const DETACHED_PROCESS: DWORD = 0x00000008; - pub const CREATE_NEW_PROCESS_GROUP: DWORD = 0x00000200; - pub const CREATE_UNICODE_ENVIRONMENT: DWORD = 0x00000400; - - pub const PIPE_ACCESS_DUPLEX: DWORD = 0x00000003; - pub const PIPE_ACCESS_INBOUND: DWORD = 0x00000001; - pub const PIPE_ACCESS_OUTBOUND: DWORD = 0x00000002; - pub const PIPE_TYPE_BYTE: DWORD = 0x00000000; - pub const PIPE_TYPE_MESSAGE: DWORD = 0x00000004; - pub const PIPE_READMODE_BYTE: DWORD = 0x00000000; - pub const PIPE_READMODE_MESSAGE: DWORD = 0x00000002; - pub const PIPE_WAIT: DWORD = 0x00000000; - pub const PIPE_NOWAIT: DWORD = 0x00000001; - pub const PIPE_ACCEPT_REMOTE_CLIENTS: DWORD = 0x00000000; - pub const PIPE_REJECT_REMOTE_CLIENTS: DWORD = 0x00000008; - pub const PIPE_UNLIMITED_INSTANCES: DWORD = 255; - - pub const IPPROTO_RAW: c_int = 255; - - pub const FIONBIO: c_long = -0x7FFB9982; - } - pub mod sysconf { - } - } - - - #[cfg(any(target_os = "linux", target_os = "android", target_os = "nacl"))] - pub mod os { - pub mod c95 { - use types::os::arch::c95::{c_int, c_uint}; - - pub const EXIT_FAILURE: c_int = 1; - pub const EXIT_SUCCESS: c_int = 0; - pub const RAND_MAX: c_int = 2147483647; - pub const EOF: c_int = -1; - pub const SEEK_SET: c_int = 0; - pub const SEEK_CUR: c_int = 1; - pub const SEEK_END: c_int = 2; - pub const _IOFBF: c_int = 0; - pub const _IONBF: c_int = 2; - pub const _IOLBF: c_int = 1; - pub const BUFSIZ: c_uint = 8192; - pub const FOPEN_MAX: c_uint = 16; - pub const FILENAME_MAX: c_uint = 4096; - pub const L_tmpnam: c_uint = 20; - pub const TMP_MAX: c_uint = 238328; - } - pub mod c99 { - } - #[cfg(any(target_arch = "x86", - target_arch = "x86_64", - target_arch = "arm", - target_arch = "aarch64", - target_arch = "le32", - target_arch = "powerpc"))] - pub mod posix88 { - use types::os::arch::c95::c_int; - use types::common::c95::c_void; - use types::os::arch::posix88::mode_t; - - pub const O_RDONLY: c_int = 0; - pub const O_WRONLY: c_int = 1; - pub const O_RDWR: c_int = 2; - pub const O_APPEND: c_int = 1024; - pub const O_CREAT: c_int = 64; - pub const O_EXCL: c_int = 128; - pub const O_NOCTTY: c_int = 256; - pub const O_TRUNC: c_int = 512; - pub const S_IFIFO: mode_t = 4096; - pub const S_IFCHR: mode_t = 8192; - pub const S_IFBLK: mode_t = 24576; - pub const S_IFDIR: mode_t = 16384; - pub const S_IFREG: mode_t = 32768; - pub const S_IFLNK: mode_t = 40960; - pub const S_IFSOCK: mode_t = 49152; - pub const S_IFMT: mode_t = 61440; - pub const S_IEXEC: mode_t = 64; - pub const S_IWRITE: mode_t = 128; - pub const S_IREAD: mode_t = 256; - pub const S_IRWXU: mode_t = 448; - pub const S_IXUSR: mode_t = 64; - pub const S_IWUSR: mode_t = 128; - pub const S_IRUSR: mode_t = 256; - pub const S_IRWXG: mode_t = 56; - pub const S_IXGRP: mode_t = 8; - pub const S_IWGRP: mode_t = 16; - pub const S_IRGRP: mode_t = 32; - pub const S_IRWXO: mode_t = 7; - pub const S_IXOTH: mode_t = 1; - pub const S_IWOTH: mode_t = 2; - pub const S_IROTH: mode_t = 4; - pub const F_OK: c_int = 0; - pub const R_OK: c_int = 4; - pub const W_OK: c_int = 2; - pub const X_OK: c_int = 1; - pub const STDIN_FILENO: c_int = 0; - pub const STDOUT_FILENO: c_int = 1; - pub const STDERR_FILENO: c_int = 2; - pub const F_LOCK: c_int = 1; - pub const F_TEST: c_int = 3; - pub const F_TLOCK: c_int = 2; - pub const F_ULOCK: c_int = 0; - pub const SIGHUP: c_int = 1; - pub const SIGINT: c_int = 2; - pub const SIGQUIT: c_int = 3; - pub const SIGILL: c_int = 4; - pub const SIGABRT: c_int = 6; - pub const SIGFPE: c_int = 8; - pub const SIGKILL: c_int = 9; - pub const SIGSEGV: c_int = 11; - pub const SIGPIPE: c_int = 13; - pub const SIGALRM: c_int = 14; - pub const SIGTERM: c_int = 15; - - pub const PROT_NONE: c_int = 0; - pub const PROT_READ: c_int = 1; - pub const PROT_WRITE: c_int = 2; - pub const PROT_EXEC: c_int = 4; - - pub const MAP_FILE: c_int = 0x0000; - pub const MAP_SHARED: c_int = 0x0001; - pub const MAP_PRIVATE: c_int = 0x0002; - pub const MAP_FIXED: c_int = 0x0010; - pub const MAP_ANON: c_int = 0x0020; - - pub const MAP_FAILED: *mut c_void = !0 as *mut c_void; - - pub const MCL_CURRENT: c_int = 0x0001; - pub const MCL_FUTURE: c_int = 0x0002; - - pub const MS_ASYNC: c_int = 0x0001; - pub const MS_INVALIDATE: c_int = 0x0002; - pub const MS_SYNC: c_int = 0x0004; - - pub const EPERM: c_int = 1; - pub const ENOENT: c_int = 2; - pub const ESRCH: c_int = 3; - pub const EINTR: c_int = 4; - pub const EIO: c_int = 5; - pub const ENXIO: c_int = 6; - pub const E2BIG: c_int = 7; - pub const ENOEXEC: c_int = 8; - pub const EBADF: c_int = 9; - pub const ECHILD: c_int = 10; - pub const EAGAIN: c_int = 11; - pub const ENOMEM: c_int = 12; - pub const EACCES: c_int = 13; - pub const EFAULT: c_int = 14; - pub const ENOTBLK: c_int = 15; - pub const EBUSY: c_int = 16; - pub const EEXIST: c_int = 17; - pub const EXDEV: c_int = 18; - pub const ENODEV: c_int = 19; - pub const ENOTDIR: c_int = 20; - pub const EISDIR: c_int = 21; - pub const EINVAL: c_int = 22; - pub const ENFILE: c_int = 23; - pub const EMFILE: c_int = 24; - pub const ENOTTY: c_int = 25; - pub const ETXTBSY: c_int = 26; - pub const EFBIG: c_int = 27; - pub const ENOSPC: c_int = 28; - pub const ESPIPE: c_int = 29; - pub const EROFS: c_int = 30; - pub const EMLINK: c_int = 31; - pub const EPIPE: c_int = 32; - pub const EDOM: c_int = 33; - pub const ERANGE: c_int = 34; - - pub const EDEADLK: c_int = 35; - pub const ENAMETOOLONG: c_int = 36; - pub const ENOLCK: c_int = 37; - pub const ENOSYS: c_int = 38; - pub const ENOTEMPTY: c_int = 39; - pub const ELOOP: c_int = 40; - pub const EWOULDBLOCK: c_int = EAGAIN; - pub const ENOMSG: c_int = 42; - pub const EIDRM: c_int = 43; - pub const ECHRNG: c_int = 44; - pub const EL2NSYNC: c_int = 45; - pub const EL3HLT: c_int = 46; - pub const EL3RST: c_int = 47; - pub const ELNRNG: c_int = 48; - pub const EUNATCH: c_int = 49; - pub const ENOCSI: c_int = 50; - pub const EL2HLT: c_int = 51; - pub const EBADE: c_int = 52; - pub const EBADR: c_int = 53; - pub const EXFULL: c_int = 54; - pub const ENOANO: c_int = 55; - pub const EBADRQC: c_int = 56; - pub const EBADSLT: c_int = 57; - - pub const EDEADLOCK: c_int = EDEADLK; - - pub const EBFONT: c_int = 59; - pub const ENOSTR: c_int = 60; - pub const ENODATA: c_int = 61; - pub const ETIME: c_int = 62; - pub const ENOSR: c_int = 63; - pub const ENONET: c_int = 64; - pub const ENOPKG: c_int = 65; - pub const EREMOTE: c_int = 66; - pub const ENOLINK: c_int = 67; - pub const EADV: c_int = 68; - pub const ESRMNT: c_int = 69; - pub const ECOMM: c_int = 70; - pub const EPROTO: c_int = 71; - pub const EMULTIHOP: c_int = 72; - pub const EDOTDOT: c_int = 73; - pub const EBADMSG: c_int = 74; - pub const EOVERFLOW: c_int = 75; - pub const ENOTUNIQ: c_int = 76; - pub const EBADFD: c_int = 77; - pub const EREMCHG: c_int = 78; - pub const ELIBACC: c_int = 79; - pub const ELIBBAD: c_int = 80; - pub const ELIBSCN: c_int = 81; - pub const ELIBMAX: c_int = 82; - pub const ELIBEXEC: c_int = 83; - pub const EILSEQ: c_int = 84; - pub const ERESTART: c_int = 85; - pub const ESTRPIPE: c_int = 86; - pub const EUSERS: c_int = 87; - pub const ENOTSOCK: c_int = 88; - pub const EDESTADDRREQ: c_int = 89; - pub const EMSGSIZE: c_int = 90; - pub const EPROTOTYPE: c_int = 91; - pub const ENOPROTOOPT: c_int = 92; - pub const EPROTONOSUPPORT: c_int = 93; - pub const ESOCKTNOSUPPORT: c_int = 94; - pub const EOPNOTSUPP: c_int = 95; - pub const EPFNOSUPPORT: c_int = 96; - pub const EAFNOSUPPORT: c_int = 97; - pub const EADDRINUSE: c_int = 98; - pub const EADDRNOTAVAIL: c_int = 99; - pub const ENETDOWN: c_int = 100; - pub const ENETUNREACH: c_int = 101; - pub const ENETRESET: c_int = 102; - pub const ECONNABORTED: c_int = 103; - pub const ECONNRESET: c_int = 104; - pub const ENOBUFS: c_int = 105; - pub const EISCONN: c_int = 106; - pub const ENOTCONN: c_int = 107; - pub const ESHUTDOWN: c_int = 108; - pub const ETOOMANYREFS: c_int = 109; - pub const ETIMEDOUT: c_int = 110; - pub const ECONNREFUSED: c_int = 111; - pub const EHOSTDOWN: c_int = 112; - pub const EHOSTUNREACH: c_int = 113; - pub const EALREADY: c_int = 114; - pub const EINPROGRESS: c_int = 115; - pub const ESTALE: c_int = 116; - pub const EUCLEAN: c_int = 117; - pub const ENOTNAM: c_int = 118; - pub const ENAVAIL: c_int = 119; - pub const EISNAM: c_int = 120; - pub const EREMOTEIO: c_int = 121; - pub const EDQUOT: c_int = 122; - - pub const ENOMEDIUM: c_int = 123; - pub const EMEDIUMTYPE: c_int = 124; - pub const ECANCELED: c_int = 125; - pub const ENOKEY: c_int = 126; - pub const EKEYEXPIRED: c_int = 127; - pub const EKEYREVOKED: c_int = 128; - pub const EKEYREJECTED: c_int = 129; - - pub const EOWNERDEAD: c_int = 130; - pub const ENOTRECOVERABLE: c_int = 131; - - pub const ERFKILL: c_int = 132; - - pub const EHWPOISON: c_int = 133; - } - - #[cfg(any(target_arch = "mips", - target_arch = "mipsel"))] - pub mod posix88 { - use types::os::arch::c95::c_int; - use types::common::c95::c_void; - use types::os::arch::posix88::mode_t; - - pub const O_RDONLY: c_int = 0; - pub const O_WRONLY: c_int = 1; - pub const O_RDWR: c_int = 2; - pub const O_APPEND: c_int = 8; - pub const O_CREAT: c_int = 256; - pub const O_EXCL: c_int = 1024; - pub const O_NOCTTY: c_int = 2048; - pub const O_TRUNC: c_int = 512; - pub const S_IFIFO: mode_t = 4096; - pub const S_IFCHR: mode_t = 8192; - pub const S_IFBLK: mode_t = 24576; - pub const S_IFDIR: mode_t = 16384; - pub const S_IFREG: mode_t = 32768; - pub const S_IFLNK: mode_t = 40960; - pub const S_IFSOCK: mode_t = 49152; - pub const S_IFMT: mode_t = 61440; - pub const S_IEXEC: mode_t = 64; - pub const S_IWRITE: mode_t = 128; - pub const S_IREAD: mode_t = 256; - pub const S_IRWXU: mode_t = 448; - pub const S_IXUSR: mode_t = 64; - pub const S_IWUSR: mode_t = 128; - pub const S_IRUSR: mode_t = 256; - pub const S_IRWXG: mode_t = 56; - pub const S_IXGRP: mode_t = 8; - pub const S_IWGRP: mode_t = 16; - pub const S_IRGRP: mode_t = 32; - pub const S_IRWXO: mode_t = 7; - pub const S_IXOTH: mode_t = 1; - pub const S_IWOTH: mode_t = 2; - pub const S_IROTH: mode_t = 4; - pub const F_OK: c_int = 0; - pub const R_OK: c_int = 4; - pub const W_OK: c_int = 2; - pub const X_OK: c_int = 1; - pub const STDIN_FILENO: c_int = 0; - pub const STDOUT_FILENO: c_int = 1; - pub const STDERR_FILENO: c_int = 2; - pub const F_LOCK: c_int = 1; - pub const F_TEST: c_int = 3; - pub const F_TLOCK: c_int = 2; - pub const F_ULOCK: c_int = 0; - pub const SIGHUP: c_int = 1; - pub const SIGINT: c_int = 2; - pub const SIGQUIT: c_int = 3; - pub const SIGILL: c_int = 4; - pub const SIGABRT: c_int = 6; - pub const SIGFPE: c_int = 8; - pub const SIGKILL: c_int = 9; - pub const SIGSEGV: c_int = 11; - pub const SIGPIPE: c_int = 13; - pub const SIGALRM: c_int = 14; - pub const SIGTERM: c_int = 15; - - pub const PROT_NONE: c_int = 0; - pub const PROT_READ: c_int = 1; - pub const PROT_WRITE: c_int = 2; - pub const PROT_EXEC: c_int = 4; - - pub const MAP_FILE: c_int = 0x0000; - pub const MAP_SHARED: c_int = 0x0001; - pub const MAP_PRIVATE: c_int = 0x0002; - pub const MAP_FIXED: c_int = 0x0010; - pub const MAP_ANON: c_int = 0x0800; - - pub const MAP_FAILED: *mut c_void = !0 as *mut c_void; - - pub const MCL_CURRENT: c_int = 0x0001; - pub const MCL_FUTURE: c_int = 0x0002; - - pub const MS_ASYNC: c_int = 0x0001; - pub const MS_INVALIDATE: c_int = 0x0002; - pub const MS_SYNC: c_int = 0x0004; - - pub const EPERM: c_int = 1; - pub const ENOENT: c_int = 2; - pub const ESRCH: c_int = 3; - pub const EINTR: c_int = 4; - pub const EIO: c_int = 5; - pub const ENXIO: c_int = 6; - pub const E2BIG: c_int = 7; - pub const ENOEXEC: c_int = 8; - pub const EBADF: c_int = 9; - pub const ECHILD: c_int = 10; - pub const EAGAIN: c_int = 11; - pub const ENOMEM: c_int = 12; - pub const EACCES: c_int = 13; - pub const EFAULT: c_int = 14; - pub const ENOTBLK: c_int = 15; - pub const EBUSY: c_int = 16; - pub const EEXIST: c_int = 17; - pub const EXDEV: c_int = 18; - pub const ENODEV: c_int = 19; - pub const ENOTDIR: c_int = 20; - pub const EISDIR: c_int = 21; - pub const EINVAL: c_int = 22; - pub const ENFILE: c_int = 23; - pub const EMFILE: c_int = 24; - pub const ENOTTY: c_int = 25; - pub const ETXTBSY: c_int = 26; - pub const EFBIG: c_int = 27; - pub const ENOSPC: c_int = 28; - pub const ESPIPE: c_int = 29; - pub const EROFS: c_int = 30; - pub const EMLINK: c_int = 31; - pub const EPIPE: c_int = 32; - pub const EDOM: c_int = 33; - pub const ERANGE: c_int = 34; - - pub const ENOMSG: c_int = 35; - pub const EIDRM: c_int = 36; - pub const ECHRNG: c_int = 37; - pub const EL2NSYNC: c_int = 38; - pub const EL3HLT: c_int = 39; - pub const EL3RST: c_int = 40; - pub const ELNRNG: c_int = 41; - pub const EUNATCH: c_int = 42; - pub const ENOCSI: c_int = 43; - pub const EL2HLT: c_int = 44; - pub const EDEADLK: c_int = 45; - pub const ENOLCK: c_int = 46; - pub const EBADE: c_int = 50; - pub const EBADR: c_int = 51; - pub const EXFULL: c_int = 52; - pub const ENOANO: c_int = 53; - pub const EBADRQC: c_int = 54; - pub const EBADSLT: c_int = 55; - pub const EDEADLOCK: c_int = 56; - pub const EBFONT: c_int = 59; - pub const ENOSTR: c_int = 60; - pub const ENODATA: c_int = 61; - pub const ETIME: c_int = 62; - pub const ENOSR: c_int = 63; - pub const ENONET: c_int = 64; - pub const ENOPKG: c_int = 65; - pub const EREMOTE: c_int = 66; - pub const ENOLINK: c_int = 67; - pub const EADV: c_int = 68; - pub const ESRMNT: c_int = 69; - pub const ECOMM: c_int = 70; - pub const EPROTO: c_int = 71; - pub const EDOTDOT: c_int = 73; - pub const EMULTIHOP: c_int = 74; - pub const EBADMSG: c_int = 77; - pub const ENAMETOOLONG: c_int = 78; - pub const EOVERFLOW: c_int = 79; - pub const ENOTUNIQ: c_int = 80; - pub const EBADFD: c_int = 81; - pub const EREMCHG: c_int = 82; - pub const ELIBACC: c_int = 83; - pub const ELIBBAD: c_int = 84; - pub const ELIBSCN: c_int = 95; - pub const ELIBMAX: c_int = 86; - pub const ELIBEXEC: c_int = 87; - pub const EILSEQ: c_int = 88; - pub const ENOSYS: c_int = 89; - pub const ELOOP: c_int = 90; - pub const ERESTART: c_int = 91; - pub const ESTRPIPE: c_int = 92; - pub const ENOTEMPTY: c_int = 93; - pub const EUSERS: c_int = 94; - pub const ENOTSOCK: c_int = 95; - pub const EDESTADDRREQ: c_int = 96; - pub const EMSGSIZE: c_int = 97; - pub const EPROTOTYPE: c_int = 98; - pub const ENOPROTOOPT: c_int = 99; - pub const EPROTONOSUPPORT: c_int = 120; - pub const ESOCKTNOSUPPORT: c_int = 121; - pub const EOPNOTSUPP: c_int = 122; - pub const EPFNOSUPPORT: c_int = 123; - pub const EAFNOSUPPORT: c_int = 124; - pub const EADDRINUSE: c_int = 125; - pub const EADDRNOTAVAIL: c_int = 126; - pub const ENETDOWN: c_int = 127; - pub const ENETUNREACH: c_int = 128; - pub const ENETRESET: c_int = 129; - pub const ECONNABORTED: c_int = 130; - pub const ECONNRESET: c_int = 131; - pub const ENOBUFS: c_int = 132; - pub const EISCONN: c_int = 133; - pub const ENOTCONN: c_int = 134; - pub const EUCLEAN: c_int = 135; - pub const ENOTNAM: c_int = 137; - pub const ENAVAIL: c_int = 138; - pub const EISNAM: c_int = 139; - pub const EREMOTEIO: c_int = 140; - pub const ESHUTDOWN: c_int = 143; - pub const ETOOMANYREFS: c_int = 144; - pub const ETIMEDOUT: c_int = 145; - pub const ECONNREFUSED: c_int = 146; - pub const EHOSTDOWN: c_int = 147; - pub const EHOSTUNREACH: c_int = 148; - pub const EWOULDBLOCK: c_int = EAGAIN; - pub const EALREADY: c_int = 149; - pub const EINPROGRESS: c_int = 150; - pub const ESTALE: c_int = 151; - pub const ECANCELED: c_int = 158; - - pub const ENOMEDIUM: c_int = 159; - pub const EMEDIUMTYPE: c_int = 160; - pub const ENOKEY: c_int = 161; - pub const EKEYEXPIRED: c_int = 162; - pub const EKEYREVOKED: c_int = 163; - pub const EKEYREJECTED: c_int = 164; - - pub const EOWNERDEAD: c_int = 165; - pub const ENOTRECOVERABLE: c_int = 166; - - pub const ERFKILL: c_int = 167; - - pub const EHWPOISON: c_int = 168; - - pub const EDQUOT: c_int = 1133; - } - #[cfg(not(target_os = "nacl"))] - pub mod posix01 { - use types::os::arch::c95::{c_int, size_t}; - use types::os::common::posix01::rlim_t; - - pub const F_DUPFD: c_int = 0; - pub const F_GETFD: c_int = 1; - pub const F_SETFD: c_int = 2; - pub const F_GETFL: c_int = 3; - pub const F_SETFL: c_int = 4; - - pub const O_ACCMODE: c_int = 3; - - pub const SIGTRAP: c_int = 5; - pub const SIG_IGN: size_t = 1; - - pub const GLOB_ERR: c_int = 1 << 0; - pub const GLOB_MARK: c_int = 1 << 1; - pub const GLOB_NOSORT: c_int = 1 << 2; - pub const GLOB_DOOFFS: c_int = 1 << 3; - pub const GLOB_NOCHECK: c_int = 1 << 4; - pub const GLOB_APPEND: c_int = 1 << 5; - pub const GLOB_NOESCAPE: c_int = 1 << 6; - - pub const GLOB_NOSPACE: c_int = 1; - pub const GLOB_ABORTED: c_int = 2; - pub const GLOB_NOMATCH: c_int = 3; - - pub const POSIX_MADV_NORMAL: c_int = 0; - pub const POSIX_MADV_RANDOM: c_int = 1; - pub const POSIX_MADV_SEQUENTIAL: c_int = 2; - pub const POSIX_MADV_WILLNEED: c_int = 3; - pub const POSIX_MADV_DONTNEED: c_int = 4; - - pub const _SC_MQ_PRIO_MAX: c_int = 28; - pub const _SC_IOV_MAX: c_int = 60; - pub const _SC_GETGR_R_SIZE_MAX: c_int = 69; - pub const _SC_GETPW_R_SIZE_MAX: c_int = 70; - pub const _SC_LOGIN_NAME_MAX: c_int = 71; - pub const _SC_TTY_NAME_MAX: c_int = 72; - pub const _SC_THREADS: c_int = 67; - pub const _SC_THREAD_SAFE_FUNCTIONS: c_int = 68; - pub const _SC_THREAD_DESTRUCTOR_ITERATIONS: c_int = 73; - pub const _SC_THREAD_KEYS_MAX: c_int = 74; - pub const _SC_THREAD_STACK_MIN: c_int = 75; - pub const _SC_THREAD_THREADS_MAX: c_int = 76; - pub const _SC_THREAD_ATTR_STACKADDR: c_int = 77; - pub const _SC_THREAD_ATTR_STACKSIZE: c_int = 78; - pub const _SC_THREAD_PRIORITY_SCHEDULING: c_int = 79; - pub const _SC_THREAD_PRIO_INHERIT: c_int = 80; - pub const _SC_THREAD_PRIO_PROTECT: c_int = 81; - pub const _SC_THREAD_PROCESS_SHARED: c_int = 82; - pub const _SC_ATEXIT_MAX: c_int = 87; - pub const _SC_XOPEN_VERSION: c_int = 89; - pub const _SC_XOPEN_XCU_VERSION: c_int = 90; - pub const _SC_XOPEN_UNIX: c_int = 91; - pub const _SC_XOPEN_CRYPT: c_int = 92; - pub const _SC_XOPEN_ENH_I18N: c_int = 93; - pub const _SC_XOPEN_SHM: c_int = 94; - pub const _SC_XOPEN_LEGACY: c_int = 129; - pub const _SC_XOPEN_REALTIME: c_int = 130; - pub const _SC_XOPEN_REALTIME_THREADS: c_int = 131; - - - - pub const PTHREAD_CREATE_JOINABLE: c_int = 0; - pub const PTHREAD_CREATE_DETACHED: c_int = 1; - - #[cfg(target_os = "android")] - pub const PTHREAD_STACK_MIN: size_t = 8192; - - #[cfg(all(target_os = "linux", - any(target_arch = "arm", - target_arch = "x86", - target_arch = "x86_64")))] - pub const PTHREAD_STACK_MIN: size_t = 16384; - - #[cfg(all(target_os = "linux", - any(target_arch = "mips", - target_arch = "mipsel", - target_arch = "aarch64", - target_arch = "powerpc")))] - pub const PTHREAD_STACK_MIN: size_t = 131072; - - pub const CLOCK_REALTIME: c_int = 0; - pub const CLOCK_MONOTONIC: c_int = 1; - - pub const RLIMIT_CPU: c_int = 0; - pub const RLIMIT_FSIZE: c_int = 1; - pub const RLIMIT_DATA: c_int = 2; - pub const RLIMIT_STACK: c_int = 3; - pub const RLIMIT_CORE: c_int = 4; - pub const RLIMIT_RSS: c_int = 5; - pub const RLIMIT_NOFILE: c_int = 7; - pub const RLIMIT_AS: c_int = 9; - pub const RLIMIT_NPROC: c_int = 6; - pub const RLIMIT_MEMLOCK: c_int = 8; - pub const RLIMIT_LOCKS: c_int = 10; - pub const RLIMIT_SIGPENDING: c_int = 11; - pub const RLIMIT_MSGQUEUE: c_int = 12; - pub const RLIMIT_NICE: c_int = 13; - pub const RLIMIT_RTPRIO: c_int = 14; - pub const RLIMIT_RTTIME: c_int = 15; - pub const RLIMIT_NLIMITS: c_int = 16; - pub const RLIM_INFINITY: rlim_t = 0xffff_ffff_ffff_ffff; - pub const RLIM_SAVED_MAX: rlim_t = RLIM_INFINITY; - pub const RLIM_SAVED_CUR: rlim_t = RLIM_INFINITY; - - pub const RUSAGE_SELF: c_int = 0; - pub const RUSAGE_CHILDREN: c_int = -1; - pub const RUSAGE_THREAD: c_int = 1; - } - #[cfg(target_os = "nacl")] - pub mod posix01 { - use types::os::arch::c95::{c_int, size_t}; - use types::os::common::posix01::rlim_t; - - pub const F_DUPFD: c_int = 0; - pub const F_GETFD: c_int = 1; - pub const F_SETFD: c_int = 2; - pub const F_GETFL: c_int = 3; - pub const F_SETFL: c_int = 4; - - pub const SIGTRAP: c_int = 5; - pub const SIG_IGN: size_t = 1; - - pub const GLOB_ERR: c_int = 1 << 0; - pub const GLOB_MARK: c_int = 1 << 1; - pub const GLOB_NOSORT: c_int = 1 << 2; - pub const GLOB_DOOFFS: c_int = 1 << 3; - pub const GLOB_NOCHECK: c_int = 1 << 4; - pub const GLOB_APPEND: c_int = 1 << 5; - pub const GLOB_NOESCAPE: c_int = 1 << 6; - - pub const GLOB_NOSPACE: c_int = 1; - pub const GLOB_ABORTED: c_int = 2; - pub const GLOB_NOMATCH: c_int = 3; - - pub const POSIX_MADV_NORMAL: c_int = 0; - pub const POSIX_MADV_RANDOM: c_int = 1; - pub const POSIX_MADV_SEQUENTIAL: c_int = 2; - pub const POSIX_MADV_WILLNEED: c_int = 3; - pub const POSIX_MADV_DONTNEED: c_int = 4; - - pub const _SC_MQ_PRIO_MAX: c_int = 28; - pub const _SC_IOV_MAX: c_int = 60; - pub const _SC_GETGR_R_SIZE_MAX: c_int = 69; - pub const _SC_GETPW_R_SIZE_MAX: c_int = 70; - pub const _SC_LOGIN_NAME_MAX: c_int = 71; - pub const _SC_TTY_NAME_MAX: c_int = 72; - pub const _SC_THREADS: c_int = 67; - pub const _SC_THREAD_SAFE_FUNCTIONS: c_int = 68; - pub const _SC_THREAD_DESTRUCTOR_ITERATIONS: c_int = 73; - pub const _SC_THREAD_KEYS_MAX: c_int = 74; - pub const _SC_THREAD_STACK_MIN: c_int = 75; - pub const _SC_THREAD_THREADS_MAX: c_int = 76; - pub const _SC_THREAD_ATTR_STACKADDR: c_int = 77; - pub const _SC_THREAD_ATTR_STACKSIZE: c_int = 78; - pub const _SC_THREAD_PRIORITY_SCHEDULING: c_int = 79; - pub const _SC_THREAD_PRIO_INHERIT: c_int = 80; - pub const _SC_THREAD_PRIO_PROTECT: c_int = 81; - pub const _SC_THREAD_PROCESS_SHARED: c_int = 82; - pub const _SC_ATEXIT_MAX: c_int = 87; - pub const _SC_XOPEN_VERSION: c_int = 89; - pub const _SC_XOPEN_XCU_VERSION: c_int = 90; - pub const _SC_XOPEN_UNIX: c_int = 91; - pub const _SC_XOPEN_CRYPT: c_int = 92; - pub const _SC_XOPEN_ENH_I18N: c_int = 93; - pub const _SC_XOPEN_SHM: c_int = 94; - pub const _SC_XOPEN_LEGACY: c_int = 129; - pub const _SC_XOPEN_REALTIME: c_int = 130; - pub const _SC_XOPEN_REALTIME_THREADS: c_int = 131; - - pub const PTHREAD_CREATE_JOINABLE: c_int = 1; - pub const PTHREAD_CREATE_DETACHED: c_int = 0; - - pub const PTHREAD_STACK_MIN: size_t = 1024; - - pub const CLOCK_REALTIME: c_int = 0; - pub const CLOCK_MONOTONIC: c_int = 1; - - pub const RLIMIT_CPU: c_int = 0; - pub const RLIMIT_FSIZE: c_int = 1; - pub const RLIMIT_DATA: c_int = 2; - pub const RLIMIT_STACK: c_int = 3; - pub const RLIMIT_CORE: c_int = 4; - pub const RLIMIT_RSS: c_int = 5; - pub const RLIMIT_NOFILE: c_int = 7; - pub const RLIMIT_AS: c_int = 9; - pub const RLIMIT_NPROC: c_int = 6; - pub const RLIMIT_MEMLOCK: c_int = 8; - pub const RLIMIT_LOCKS: c_int = 10; - pub const RLIMIT_SIGPENDING: c_int = 11; - pub const RLIMIT_MSGQUEUE: c_int = 12; - pub const RLIMIT_NICE: c_int = 13; - pub const RLIMIT_RTPRIO: c_int = 14; - pub const RLIMIT_RTTIME: c_int = 15; - pub const RLIMIT_NLIMITS: c_int = 16; - - pub const RLIM_INFINITY: rlim_t = 0xffff_ffff_ffff_ffff; - pub const RLIM_SAVED_MAX: rlim_t = RLIM_INFINITY; - pub const RLIM_SAVED_CUR: rlim_t = RLIM_INFINITY; - - pub const RUSAGE_SELF: c_int = 0; - pub const RUSAGE_CHILDREN: c_int = -1; - pub const RUSAGE_THREAD: c_int = 1; - } - pub mod posix08 { - use types::os::arch::c95::c_int; - pub const O_CLOEXEC: c_int = 0x80000; - pub const F_DUPFD_CLOEXEC: c_int = 1030; - } - #[cfg(any(target_arch = "arm", - target_arch = "aarch64", - target_arch = "x86", - target_arch = "x86_64", - target_arch = "le32", - target_arch = "powerpc"))] - pub mod bsd44 { - use types::os::arch::c95::c_int; - - pub const MADV_NORMAL: c_int = 0; - pub const MADV_RANDOM: c_int = 1; - pub const MADV_SEQUENTIAL: c_int = 2; - pub const MADV_WILLNEED: c_int = 3; - pub const MADV_DONTNEED: c_int = 4; - pub const MADV_REMOVE: c_int = 9; - pub const MADV_DONTFORK: c_int = 10; - pub const MADV_DOFORK: c_int = 11; - pub const MADV_MERGEABLE: c_int = 12; - pub const MADV_UNMERGEABLE: c_int = 13; - pub const MADV_HWPOISON: c_int = 100; - - pub const IFF_LOOPBACK: c_int = 0x8; - - pub const AF_UNIX: c_int = 1; - pub const AF_INET: c_int = 2; - pub const AF_INET6: c_int = 10; - pub const SOCK_STREAM: c_int = 1; - pub const SOCK_DGRAM: c_int = 2; - pub const SOCK_RAW: c_int = 3; - pub const IPPROTO_TCP: c_int = 6; - pub const IPPROTO_IP: c_int = 0; - pub const IPPROTO_IPV6: c_int = 41; - pub const IP_MULTICAST_TTL: c_int = 33; - pub const IP_MULTICAST_LOOP: c_int = 34; - pub const IP_TTL: c_int = 2; - pub const IP_HDRINCL: c_int = 3; - pub const IP_ADD_MEMBERSHIP: c_int = 35; - pub const IP_DROP_MEMBERSHIP: c_int = 36; - pub const IPV6_ADD_MEMBERSHIP: c_int = 20; - pub const IPV6_DROP_MEMBERSHIP: c_int = 21; - - pub const TCP_NODELAY: c_int = 1; - pub const TCP_MAXSEG: c_int = 2; - pub const TCP_CORK: c_int = 3; - pub const TCP_KEEPIDLE: c_int = 4; - pub const TCP_KEEPINTVL: c_int = 5; - pub const TCP_KEEPCNT: c_int = 6; - pub const TCP_SYNCNT: c_int = 7; - pub const TCP_LINGER2: c_int = 8; - pub const TCP_DEFER_ACCEPT: c_int = 9; - pub const TCP_WINDOW_CLAMP: c_int = 10; - pub const TCP_INFO: c_int = 11; - pub const TCP_QUICKACK: c_int = 12; - pub const TCP_CONGESTION: c_int = 13; - pub const TCP_MD5SIG: c_int = 14; - pub const TCP_COOKIE_TRANSACTIONS: c_int = 15; - pub const TCP_THIN_LINEAR_TIMEOUTS: c_int = 16; - pub const TCP_THIN_DUPACK: c_int = 17; - pub const TCP_USER_TIMEOUT: c_int = 18; - pub const TCP_REPAIR: c_int = 19; - pub const TCP_REPAIR_QUEUE: c_int = 20; - pub const TCP_QUEUE_SEQ: c_int = 21; - pub const TCP_REPAIR_OPTIONS: c_int = 22; - pub const TCP_FASTOPEN: c_int = 23; - pub const TCP_TIMESTAMP: c_int = 24; - - pub const SOL_SOCKET: c_int = 1; - - pub const SO_DEBUG: c_int = 1; - pub const SO_REUSEADDR: c_int = 2; - pub const SO_TYPE: c_int = 3; - pub const SO_ERROR: c_int = 4; - pub const SO_DONTROUTE: c_int = 5; - pub const SO_BROADCAST: c_int = 6; - pub const SO_SNDBUF: c_int = 7; - pub const SO_RCVBUF: c_int = 8; - pub const SO_KEEPALIVE: c_int = 9; - pub const SO_OOBINLINE: c_int = 10; - pub const SO_LINGER: c_int = 13; - pub const SO_REUSEPORT: c_int = 15; - pub const SO_RCVLOWAT: c_int = 18; - pub const SO_SNDLOWAT: c_int = 19; - pub const SO_RCVTIMEO: c_int = 20; - pub const SO_SNDTIMEO: c_int = 21; - pub const SO_ACCEPTCONN: c_int = 30; - - pub const SHUT_RD: c_int = 0; - pub const SHUT_WR: c_int = 1; - pub const SHUT_RDWR: c_int = 2; - - pub const LOCK_SH: c_int = 1; - pub const LOCK_EX: c_int = 2; - pub const LOCK_NB: c_int = 4; - pub const LOCK_UN: c_int = 8; - } - #[cfg(any(target_arch = "mips", - target_arch = "mipsel"))] - pub mod bsd44 { - use types::os::arch::c95::c_int; - - pub const MADV_NORMAL: c_int = 0; - pub const MADV_RANDOM: c_int = 1; - pub const MADV_SEQUENTIAL: c_int = 2; - pub const MADV_WILLNEED: c_int = 3; - pub const MADV_DONTNEED: c_int = 4; - pub const MADV_REMOVE: c_int = 9; - pub const MADV_DONTFORK: c_int = 10; - pub const MADV_DOFORK: c_int = 11; - pub const MADV_MERGEABLE: c_int = 12; - pub const MADV_UNMERGEABLE: c_int = 13; - pub const MADV_HWPOISON: c_int = 100; - - pub const AF_UNIX: c_int = 1; - pub const AF_INET: c_int = 2; - pub const AF_INET6: c_int = 10; - pub const SOCK_STREAM: c_int = 2; - pub const SOCK_DGRAM: c_int = 1; - pub const SOCK_RAW: c_int = 3; - pub const IPPROTO_TCP: c_int = 6; - pub const IPPROTO_IP: c_int = 0; - pub const IPPROTO_IPV6: c_int = 41; - pub const IP_MULTICAST_TTL: c_int = 33; - pub const IP_MULTICAST_LOOP: c_int = 34; - pub const IP_TTL: c_int = 2; - pub const IP_HDRINCL: c_int = 3; - pub const IP_ADD_MEMBERSHIP: c_int = 35; - pub const IP_DROP_MEMBERSHIP: c_int = 36; - pub const IPV6_ADD_MEMBERSHIP: c_int = 20; - pub const IPV6_DROP_MEMBERSHIP: c_int = 21; - - pub const TCP_NODELAY: c_int = 1; - pub const TCP_MAXSEG: c_int = 2; - pub const TCP_CORK: c_int = 3; - pub const TCP_KEEPIDLE: c_int = 4; - pub const TCP_KEEPINTVL: c_int = 5; - pub const TCP_KEEPCNT: c_int = 6; - pub const TCP_SYNCNT: c_int = 7; - pub const TCP_LINGER2: c_int = 8; - pub const TCP_DEFER_ACCEPT: c_int = 9; - pub const TCP_WINDOW_CLAMP: c_int = 10; - pub const TCP_INFO: c_int = 11; - pub const TCP_QUICKACK: c_int = 12; - pub const TCP_CONGESTION: c_int = 13; - pub const TCP_MD5SIG: c_int = 14; - pub const TCP_COOKIE_TRANSACTIONS: c_int = 15; - pub const TCP_THIN_LINEAR_TIMEOUTS: c_int = 16; - pub const TCP_THIN_DUPACK: c_int = 17; - pub const TCP_USER_TIMEOUT: c_int = 18; - pub const TCP_REPAIR: c_int = 19; - pub const TCP_REPAIR_QUEUE: c_int = 20; - pub const TCP_QUEUE_SEQ: c_int = 21; - pub const TCP_REPAIR_OPTIONS: c_int = 22; - pub const TCP_FASTOPEN: c_int = 23; - pub const TCP_TIMESTAMP: c_int = 24; - - pub const SOL_SOCKET: c_int = 65535; - - pub const SO_DEBUG: c_int = 0x0001; - pub const SO_REUSEADDR: c_int = 0x0004; - pub const SO_KEEPALIVE: c_int = 0x0008; - pub const SO_DONTROUTE: c_int = 0x0010; - pub const SO_BROADCAST: c_int = 0x0020; - pub const SO_LINGER: c_int = 0x0080; - pub const SO_OOBINLINE: c_int = 0x100; - pub const SO_REUSEPORT: c_int = 0x0200; - pub const SO_SNDBUF: c_int = 0x1001; - pub const SO_RCVBUF: c_int = 0x1002; - pub const SO_SNDLOWAT: c_int = 0x1003; - pub const SO_RCVLOWAT: c_int = 0x1004; - pub const SO_SNDTIMEO: c_int = 0x1005; - pub const SO_RCVTIMEO: c_int = 0x1006; - pub const SO_ERROR: c_int = 0x1007; - pub const SO_TYPE: c_int = 0x1008; - pub const SO_ACCEPTCONN: c_int = 0x1009; - - pub const SHUT_RD: c_int = 0; - pub const SHUT_WR: c_int = 1; - pub const SHUT_RDWR: c_int = 2; - - pub const LOCK_SH: c_int = 1; - pub const LOCK_EX: c_int = 2; - pub const LOCK_NB: c_int = 4; - pub const LOCK_UN: c_int = 8; - } - #[cfg(any(target_arch = "x86", - target_arch = "x86_64", - target_arch = "arm", - target_arch = "aarch64", - target_arch = "le32", - target_arch = "powerpc"))] - pub mod extra { - use types::os::arch::c95::c_int; - - pub const AF_PACKET: c_int = 17; - pub const IPPROTO_RAW: c_int = 255; - - pub const O_RSYNC: c_int = 1052672; - pub const O_DSYNC: c_int = 4096; - pub const O_NONBLOCK: c_int = 2048; - pub const O_SYNC: c_int = 1052672; - - pub const PROT_GROWSDOWN: c_int = 0x010000000; - pub const PROT_GROWSUP: c_int = 0x020000000; - - pub const MAP_TYPE: c_int = 0x000f; - pub const MAP_ANONYMOUS: c_int = 0x0020; - pub const MAP_32BIT: c_int = 0x0040; - pub const MAP_GROWSDOWN: c_int = 0x0100; - pub const MAP_DENYWRITE: c_int = 0x0800; - pub const MAP_EXECUTABLE: c_int = 0x01000; - pub const MAP_LOCKED: c_int = 0x02000; - pub const MAP_NORESERVE: c_int = 0x04000; - pub const MAP_POPULATE: c_int = 0x08000; - pub const MAP_NONBLOCK: c_int = 0x010000; - pub const MAP_STACK: c_int = 0x020000; - - pub const PATH_MAX: c_int = 4096; - } - #[cfg(any(target_arch = "mips", - target_arch = "mipsel"))] - pub mod extra { - use types::os::arch::c95::c_int; - - pub const AF_PACKET: c_int = 17; - pub const IPPROTO_RAW: c_int = 255; - - pub const O_RSYNC: c_int = 16400; - pub const O_DSYNC: c_int = 16; - pub const O_NONBLOCK: c_int = 128; - pub const O_SYNC: c_int = 16400; - - pub const PROT_GROWSDOWN: c_int = 0x01000000; - pub const PROT_GROWSUP: c_int = 0x02000000; - - pub const MAP_TYPE: c_int = 0x000f; - pub const MAP_ANONYMOUS: c_int = 0x0800; - pub const MAP_GROWSDOWN: c_int = 0x01000; - pub const MAP_DENYWRITE: c_int = 0x02000; - pub const MAP_EXECUTABLE: c_int = 0x04000; - pub const MAP_LOCKED: c_int = 0x08000; - pub const MAP_NORESERVE: c_int = 0x0400; - pub const MAP_POPULATE: c_int = 0x010000; - pub const MAP_NONBLOCK: c_int = 0x020000; - pub const MAP_STACK: c_int = 0x040000; - - pub const PATH_MAX: c_int = 4096; - } - #[cfg(target_os = "linux")] - pub mod sysconf { - use types::os::arch::c95::c_int; - - pub const _SC_ARG_MAX: c_int = 0; - pub const _SC_CHILD_MAX: c_int = 1; - pub const _SC_CLK_TCK: c_int = 2; - pub const _SC_NGROUPS_MAX: c_int = 3; - pub const _SC_OPEN_MAX: c_int = 4; - pub const _SC_STREAM_MAX: c_int = 5; - pub const _SC_TZNAME_MAX: c_int = 6; - pub const _SC_JOB_CONTROL: c_int = 7; - pub const _SC_SAVED_IDS: c_int = 8; - pub const _SC_REALTIME_SIGNALS: c_int = 9; - pub const _SC_PRIORITY_SCHEDULING: c_int = 10; - pub const _SC_TIMERS: c_int = 11; - pub const _SC_ASYNCHRONOUS_IO: c_int = 12; - pub const _SC_PRIORITIZED_IO: c_int = 13; - pub const _SC_SYNCHRONIZED_IO: c_int = 14; - pub const _SC_FSYNC: c_int = 15; - pub const _SC_MAPPED_FILES: c_int = 16; - pub const _SC_MEMLOCK: c_int = 17; - pub const _SC_MEMLOCK_RANGE: c_int = 18; - pub const _SC_MEMORY_PROTECTION: c_int = 19; - pub const _SC_MESSAGE_PASSING: c_int = 20; - pub const _SC_SEMAPHORES: c_int = 21; - pub const _SC_SHARED_MEMORY_OBJECTS: c_int = 22; - pub const _SC_AIO_LISTIO_MAX: c_int = 23; - pub const _SC_AIO_MAX: c_int = 24; - pub const _SC_AIO_PRIO_DELTA_MAX: c_int = 25; - pub const _SC_DELAYTIMER_MAX: c_int = 26; - pub const _SC_MQ_OPEN_MAX: c_int = 27; - pub const _SC_VERSION: c_int = 29; - pub const _SC_PAGESIZE: c_int = 30; - pub const _SC_RTSIG_MAX: c_int = 31; - pub const _SC_SEM_NSEMS_MAX: c_int = 32; - pub const _SC_SEM_VALUE_MAX: c_int = 33; - pub const _SC_SIGQUEUE_MAX: c_int = 34; - pub const _SC_TIMER_MAX: c_int = 35; - pub const _SC_BC_BASE_MAX: c_int = 36; - pub const _SC_BC_DIM_MAX: c_int = 37; - pub const _SC_BC_SCALE_MAX: c_int = 38; - pub const _SC_BC_STRING_MAX: c_int = 39; - pub const _SC_COLL_WEIGHTS_MAX: c_int = 40; - pub const _SC_EXPR_NEST_MAX: c_int = 42; - pub const _SC_LINE_MAX: c_int = 43; - pub const _SC_RE_DUP_MAX: c_int = 44; - pub const _SC_2_VERSION: c_int = 46; - pub const _SC_2_C_BIND: c_int = 47; - pub const _SC_2_C_DEV: c_int = 48; - pub const _SC_2_FORT_DEV: c_int = 49; - pub const _SC_2_FORT_RUN: c_int = 50; - pub const _SC_2_SW_DEV: c_int = 51; - pub const _SC_2_LOCALEDEF: c_int = 52; - pub const _SC_NPROCESSORS_ONLN: c_int = 84; - pub const _SC_2_CHAR_TERM: c_int = 95; - pub const _SC_2_C_VERSION: c_int = 96; - pub const _SC_2_UPE: c_int = 97; - pub const _SC_XBS5_ILP32_OFF32: c_int = 125; - pub const _SC_XBS5_ILP32_OFFBIG: c_int = 126; - pub const _SC_XBS5_LPBIG_OFFBIG: c_int = 128; - - pub const _PC_NAME_MAX: c_int = 3; - pub const _PC_PATH_MAX: c_int = 4; - } - #[cfg(target_os = "nacl")] - pub mod sysconf { - use types::os::arch::c95::c_int; - - pub static _SC_SENDMSG_MAX_SIZE: c_int = 0; - pub static _SC_NPROCESSORS_ONLN: c_int = 1; - pub static _SC_PAGESIZE: c_int = 2; - - pub const _PC_NAME_MAX: c_int = 3; - pub const _PC_PATH_MAX: c_int = 4; - } - - #[cfg(target_os = "android")] - pub mod sysconf { - use types::os::arch::c95::c_int; - - pub const _SC_ARG_MAX: c_int = 0; - pub const _SC_BC_BASE_MAX: c_int = 1; - pub const _SC_BC_DIM_MAX: c_int = 2; - pub const _SC_BC_SCALE_MAX: c_int = 3; - pub const _SC_BC_STRING_MAX: c_int = 4; - pub const _SC_CHILD_MAX: c_int = 5; - pub const _SC_CLK_TCK: c_int = 6; - pub const _SC_COLL_WEIGHTS_MAX: c_int = 7; - pub const _SC_EXPR_NEST_MAX: c_int = 8; - pub const _SC_LINE_MAX: c_int = 9; - pub const _SC_NGROUPS_MAX: c_int = 10; - pub const _SC_OPEN_MAX: c_int = 11; - pub const _SC_2_C_BIND: c_int = 13; - pub const _SC_2_C_DEV: c_int = 14; - pub const _SC_2_C_VERSION: c_int = 15; - pub const _SC_2_CHAR_TERM: c_int = 16; - pub const _SC_2_FORT_DEV: c_int = 17; - pub const _SC_2_FORT_RUN: c_int = 18; - pub const _SC_2_LOCALEDEF: c_int = 19; - pub const _SC_2_SW_DEV: c_int = 20; - pub const _SC_2_UPE: c_int = 21; - pub const _SC_2_VERSION: c_int = 22; - pub const _SC_JOB_CONTROL: c_int = 23; - pub const _SC_SAVED_IDS: c_int = 24; - pub const _SC_VERSION: c_int = 25; - pub const _SC_RE_DUP_MAX: c_int = 26; - pub const _SC_STREAM_MAX: c_int = 27; - pub const _SC_TZNAME_MAX: c_int = 28; - pub const _SC_PAGESIZE: c_int = 39; - - pub const _PC_NAME_MAX: c_int = 4; - pub const _PC_PATH_MAX: c_int = 5; - } - } - - #[cfg(any(target_os = "freebsd", - target_os = "dragonfly"))] - pub mod os { - pub mod c95 { - use types::os::arch::c95::{c_int, c_uint}; - - pub const EXIT_FAILURE: c_int = 1; - pub const EXIT_SUCCESS: c_int = 0; - pub const RAND_MAX: c_int = 2147483647; - pub const EOF: c_int = -1; - pub const SEEK_SET: c_int = 0; - pub const SEEK_CUR: c_int = 1; - pub const SEEK_END: c_int = 2; - pub const _IOFBF: c_int = 0; - pub const _IONBF: c_int = 2; - pub const _IOLBF: c_int = 1; - pub const BUFSIZ: c_uint = 1024; - pub const FOPEN_MAX: c_uint = 20; - pub const FILENAME_MAX: c_uint = 1024; - pub const L_tmpnam: c_uint = 1024; - pub const TMP_MAX: c_uint = 308915776; - } - pub mod c99 { - } - pub mod posix88 { - use types::common::c95::c_void; - use types::os::arch::c95::c_int; - use types::os::arch::posix88::mode_t; - - pub const O_RDONLY: c_int = 0; - pub const O_WRONLY: c_int = 1; - pub const O_RDWR: c_int = 2; - pub const O_APPEND: c_int = 8; - pub const O_CREAT: c_int = 512; - pub const O_EXCL: c_int = 2048; - pub const O_NOCTTY: c_int = 32768; - pub const O_TRUNC: c_int = 1024; - pub const S_IFIFO: mode_t = 4096; - pub const S_IFCHR: mode_t = 8192; - pub const S_IFBLK: mode_t = 24576; - pub const S_IFDIR: mode_t = 16384; - pub const S_IFREG: mode_t = 32768; - pub const S_IFLNK: mode_t = 40960; - pub const S_IFSOCK: mode_t = 49152; - pub const S_IFMT: mode_t = 61440; - pub const S_IEXEC: mode_t = 64; - pub const S_IWRITE: mode_t = 128; - pub const S_IREAD: mode_t = 256; - pub const S_IRWXU: mode_t = 448; - pub const S_IXUSR: mode_t = 64; - pub const S_IWUSR: mode_t = 128; - pub const S_IRUSR: mode_t = 256; - pub const S_IRWXG: mode_t = 56; - pub const S_IXGRP: mode_t = 8; - pub const S_IWGRP: mode_t = 16; - pub const S_IRGRP: mode_t = 32; - pub const S_IRWXO: mode_t = 7; - pub const S_IXOTH: mode_t = 1; - pub const S_IWOTH: mode_t = 2; - pub const S_IROTH: mode_t = 4; - pub const F_OK: c_int = 0; - pub const R_OK: c_int = 4; - pub const W_OK: c_int = 2; - pub const X_OK: c_int = 1; - pub const STDIN_FILENO: c_int = 0; - pub const STDOUT_FILENO: c_int = 1; - pub const STDERR_FILENO: c_int = 2; - pub const F_LOCK: c_int = 1; - pub const F_TEST: c_int = 3; - pub const F_TLOCK: c_int = 2; - pub const F_ULOCK: c_int = 0; - pub const SIGHUP: c_int = 1; - pub const SIGINT: c_int = 2; - pub const SIGQUIT: c_int = 3; - pub const SIGILL: c_int = 4; - pub const SIGABRT: c_int = 6; - pub const SIGFPE: c_int = 8; - pub const SIGKILL: c_int = 9; - pub const SIGSEGV: c_int = 11; - pub const SIGPIPE: c_int = 13; - pub const SIGALRM: c_int = 14; - pub const SIGTERM: c_int = 15; - - pub const PROT_NONE: c_int = 0; - pub const PROT_READ: c_int = 1; - pub const PROT_WRITE: c_int = 2; - pub const PROT_EXEC: c_int = 4; - - pub const MAP_FILE: c_int = 0x0000; - pub const MAP_SHARED: c_int = 0x0001; - pub const MAP_PRIVATE: c_int = 0x0002; - pub const MAP_FIXED: c_int = 0x0010; - pub const MAP_ANON: c_int = 0x1000; - - pub const MAP_FAILED: *mut c_void = !0 as *mut c_void; - - pub const MCL_CURRENT: c_int = 0x0001; - pub const MCL_FUTURE: c_int = 0x0002; - - pub const MS_SYNC: c_int = 0x0000; - pub const MS_ASYNC: c_int = 0x0001; - pub const MS_INVALIDATE: c_int = 0x0002; - - pub const EPERM: c_int = 1; - pub const ENOENT: c_int = 2; - pub const ESRCH: c_int = 3; - pub const EINTR: c_int = 4; - pub const EIO: c_int = 5; - pub const ENXIO: c_int = 6; - pub const E2BIG: c_int = 7; - pub const ENOEXEC: c_int = 8; - pub const EBADF: c_int = 9; - pub const ECHILD: c_int = 10; - pub const EDEADLK: c_int = 11; - pub const ENOMEM: c_int = 12; - pub const EACCES: c_int = 13; - pub const EFAULT: c_int = 14; - pub const ENOTBLK: c_int = 15; - pub const EBUSY: c_int = 16; - pub const EEXIST: c_int = 17; - pub const EXDEV: c_int = 18; - pub const ENODEV: c_int = 19; - pub const ENOTDIR: c_int = 20; - pub const EISDIR: c_int = 21; - pub const EINVAL: c_int = 22; - pub const ENFILE: c_int = 23; - pub const EMFILE: c_int = 24; - pub const ENOTTY: c_int = 25; - pub const ETXTBSY: c_int = 26; - pub const EFBIG: c_int = 27; - pub const ENOSPC: c_int = 28; - pub const ESPIPE: c_int = 29; - pub const EROFS: c_int = 30; - pub const EMLINK: c_int = 31; - pub const EPIPE: c_int = 32; - pub const EDOM: c_int = 33; - pub const ERANGE: c_int = 34; - pub const EAGAIN: c_int = 35; - pub const EWOULDBLOCK: c_int = 35; - pub const EINPROGRESS: c_int = 36; - pub const EALREADY: c_int = 37; - pub const ENOTSOCK: c_int = 38; - pub const EDESTADDRREQ: c_int = 39; - pub const EMSGSIZE: c_int = 40; - pub const EPROTOTYPE: c_int = 41; - pub const ENOPROTOOPT: c_int = 42; - pub const EPROTONOSUPPORT: c_int = 43; - pub const ESOCKTNOSUPPORT: c_int = 44; - pub const EOPNOTSUPP: c_int = 45; - pub const EPFNOSUPPORT: c_int = 46; - pub const EAFNOSUPPORT: c_int = 47; - pub const EADDRINUSE: c_int = 48; - pub const EADDRNOTAVAIL: c_int = 49; - pub const ENETDOWN: c_int = 50; - pub const ENETUNREACH: c_int = 51; - pub const ENETRESET: c_int = 52; - pub const ECONNABORTED: c_int = 53; - pub const ECONNRESET: c_int = 54; - pub const ENOBUFS: c_int = 55; - pub const EISCONN: c_int = 56; - pub const ENOTCONN: c_int = 57; - pub const ESHUTDOWN: c_int = 58; - pub const ETOOMANYREFS: c_int = 59; - pub const ETIMEDOUT: c_int = 60; - pub const ECONNREFUSED: c_int = 61; - pub const ELOOP: c_int = 62; - pub const ENAMETOOLONG: c_int = 63; - pub const EHOSTDOWN: c_int = 64; - pub const EHOSTUNREACH: c_int = 65; - pub const ENOTEMPTY: c_int = 66; - pub const EPROCLIM: c_int = 67; - pub const EUSERS: c_int = 68; - pub const EDQUOT: c_int = 69; - pub const ESTALE: c_int = 70; - pub const EREMOTE: c_int = 71; - pub const EBADRPC: c_int = 72; - pub const ERPCMISMATCH: c_int = 73; - pub const EPROGUNAVAIL: c_int = 74; - pub const EPROGMISMATCH: c_int = 75; - pub const EPROCUNAVAIL: c_int = 76; - pub const ENOLCK: c_int = 77; - pub const ENOSYS: c_int = 78; - pub const EFTYPE: c_int = 79; - pub const EAUTH: c_int = 80; - pub const ENEEDAUTH: c_int = 81; - pub const EIDRM: c_int = 82; - pub const ENOMSG: c_int = 83; - pub const EOVERFLOW: c_int = 84; - pub const ECANCELED: c_int = 85; - pub const EILSEQ: c_int = 86; - pub const ENOATTR: c_int = 87; - pub const EDOOFUS: c_int = 88; - pub const EBADMSG: c_int = 89; - pub const EMULTIHOP: c_int = 90; - pub const ENOLINK: c_int = 91; - pub const EPROTO: c_int = 92; - pub const ENOMEDIUM: c_int = 93; - pub const EUNUSED94: c_int = 94; - pub const EUNUSED95: c_int = 95; - pub const EUNUSED96: c_int = 96; - pub const EUNUSED97: c_int = 97; - pub const EUNUSED98: c_int = 98; - pub const EASYNC: c_int = 99; - pub const ELAST: c_int = 99; - } - pub mod posix01 { - use types::os::arch::c95::{c_int, size_t}; - use types::os::common::posix01::rlim_t; - - pub const F_DUPFD: c_int = 0; - pub const F_GETFD: c_int = 1; - pub const F_SETFD: c_int = 2; - pub const F_GETFL: c_int = 3; - pub const F_SETFL: c_int = 4; - - pub const SIGTRAP: c_int = 5; - pub const SIG_IGN: size_t = 1; - - pub const GLOB_APPEND: c_int = 0x0001; - pub const GLOB_DOOFFS: c_int = 0x0002; - pub const GLOB_ERR: c_int = 0x0004; - pub const GLOB_MARK: c_int = 0x0008; - pub const GLOB_NOCHECK: c_int = 0x0010; - pub const GLOB_NOSORT: c_int = 0x0020; - pub const GLOB_NOESCAPE: c_int = 0x2000; - - pub const GLOB_NOSPACE: c_int = -1; - pub const GLOB_ABORTED: c_int = -2; - pub const GLOB_NOMATCH: c_int = -3; - - pub const POSIX_MADV_NORMAL: c_int = 0; - pub const POSIX_MADV_RANDOM: c_int = 1; - pub const POSIX_MADV_SEQUENTIAL: c_int = 2; - pub const POSIX_MADV_WILLNEED: c_int = 3; - pub const POSIX_MADV_DONTNEED: c_int = 4; - - pub const _SC_IOV_MAX: c_int = 56; - pub const _SC_GETGR_R_SIZE_MAX: c_int = 70; - pub const _SC_GETPW_R_SIZE_MAX: c_int = 71; - pub const _SC_LOGIN_NAME_MAX: c_int = 73; - pub const _SC_MQ_PRIO_MAX: c_int = 75; - pub const _SC_THREAD_ATTR_STACKADDR: c_int = 82; - pub const _SC_THREAD_ATTR_STACKSIZE: c_int = 83; - pub const _SC_THREAD_DESTRUCTOR_ITERATIONS: c_int = 85; - pub const _SC_THREAD_KEYS_MAX: c_int = 86; - pub const _SC_THREAD_PRIO_INHERIT: c_int = 87; - pub const _SC_THREAD_PRIO_PROTECT: c_int = 88; - pub const _SC_THREAD_PRIORITY_SCHEDULING: c_int = 89; - pub const _SC_THREAD_PROCESS_SHARED: c_int = 90; - pub const _SC_THREAD_SAFE_FUNCTIONS: c_int = 91; - pub const _SC_THREAD_STACK_MIN: c_int = 93; - pub const _SC_THREAD_THREADS_MAX: c_int = 94; - pub const _SC_THREADS: c_int = 96; - pub const _SC_TTY_NAME_MAX: c_int = 101; - pub const _SC_ATEXIT_MAX: c_int = 107; - pub const _SC_XOPEN_CRYPT: c_int = 108; - pub const _SC_XOPEN_ENH_I18N: c_int = 109; - pub const _SC_XOPEN_LEGACY: c_int = 110; - pub const _SC_XOPEN_REALTIME: c_int = 111; - pub const _SC_XOPEN_REALTIME_THREADS: c_int = 112; - pub const _SC_XOPEN_SHM: c_int = 113; - pub const _SC_XOPEN_UNIX: c_int = 115; - pub const _SC_XOPEN_VERSION: c_int = 116; - pub const _SC_XOPEN_XCU_VERSION: c_int = 117; - - pub const PTHREAD_CREATE_JOINABLE: c_int = 0; - pub const PTHREAD_CREATE_DETACHED: c_int = 1; - - #[cfg(target_arch = "arm")] - pub const PTHREAD_STACK_MIN: size_t = 4096; - - #[cfg(all(target_os = "freebsd", - any(target_arch = "mips", - target_arch = "mipsel", - target_arch = "x86", - target_arch = "x86_64")))] - pub const PTHREAD_STACK_MIN: size_t = 2048; - - #[cfg(target_os = "dragonfly")] - pub const PTHREAD_STACK_MIN: size_t = 1024; - - pub const CLOCK_REALTIME: c_int = 0; - pub const CLOCK_MONOTONIC: c_int = 4; - - pub const RLIMIT_CPU: c_int = 0; - pub const RLIMIT_FSIZE: c_int = 1; - pub const RLIMIT_DATA: c_int = 2; - pub const RLIMIT_STACK: c_int = 3; - pub const RLIMIT_CORE: c_int = 4; - pub const RLIMIT_RSS: c_int = 5; - pub const RLIMIT_MEMLOCK: c_int = 6; - pub const RLIMIT_NPROC: c_int = 7; - pub const RLIMIT_NOFILE: c_int = 8; - pub const RLIMIT_SBSIZE: c_int = 9; - pub const RLIMIT_VMEM: c_int = 10; - pub const RLIMIT_AS: c_int = RLIMIT_VMEM; - pub const RLIMIT_NPTS: c_int = 11; - pub const RLIMIT_SWAP: c_int = 12; - pub const RLIMIT_KQUEUES: c_int = 13; - - pub const RLIM_NLIMITS: rlim_t = 14; - pub const RLIM_INFINITY: rlim_t = 0x7fff_ffff_ffff_ffff; - - pub const RUSAGE_SELF: c_int = 0; - pub const RUSAGE_CHILDREN: c_int = -1; - pub const RUSAGE_THREAD: c_int = 1; - } - #[cfg(target_os = "freebsd")] - pub mod posix08 { - use types::os::arch::c95::c_int; - pub const O_CLOEXEC: c_int = 0x100000; - pub const F_DUPFD_CLOEXEC: c_int = 17; - } - #[cfg(target_os = "dragonfly")] - pub mod posix08 { - use types::os::arch::c95::c_int; - pub const O_CLOEXEC: c_int = 0x20000; - pub const F_DUPFD_CLOEXEC: c_int = 17; - } - pub mod bsd44 { - use types::os::arch::c95::c_int; - - pub const MADV_NORMAL: c_int = 0; - pub const MADV_RANDOM: c_int = 1; - pub const MADV_SEQUENTIAL: c_int = 2; - pub const MADV_WILLNEED: c_int = 3; - pub const MADV_DONTNEED: c_int = 4; - pub const MADV_FREE: c_int = 5; - pub const MADV_NOSYNC: c_int = 6; - pub const MADV_AUTOSYNC: c_int = 7; - pub const MADV_NOCORE: c_int = 8; - pub const MADV_CORE: c_int = 9; - pub const MADV_PROTECT: c_int = 10; - - pub const MINCORE_INCORE: c_int = 0x1; - pub const MINCORE_REFERENCED: c_int = 0x2; - pub const MINCORE_MODIFIED: c_int = 0x4; - pub const MINCORE_REFERENCED_OTHER: c_int = 0x8; - pub const MINCORE_MODIFIED_OTHER: c_int = 0x10; - pub const MINCORE_SUPER: c_int = 0x20; - - pub const AF_INET: c_int = 2; - pub const AF_INET6: c_int = 28; - pub const AF_UNIX: c_int = 1; - pub const SOCK_STREAM: c_int = 1; - pub const SOCK_DGRAM: c_int = 2; - pub const SOCK_RAW: c_int = 3; - pub const IPPROTO_TCP: c_int = 6; - pub const IPPROTO_IP: c_int = 0; - pub const IPPROTO_IPV6: c_int = 41; - pub const IP_MULTICAST_TTL: c_int = 10; - pub const IP_MULTICAST_LOOP: c_int = 11; - pub const IP_TTL: c_int = 4; - pub const IP_HDRINCL: c_int = 2; - pub const IP_ADD_MEMBERSHIP: c_int = 12; - pub const IP_DROP_MEMBERSHIP: c_int = 13; - pub const IPV6_ADD_MEMBERSHIP: c_int = 12; - pub const IPV6_DROP_MEMBERSHIP: c_int = 13; - - pub const TCP_NODELAY: c_int = 1; - pub const TCP_KEEPIDLE: c_int = 256; - pub const SOL_SOCKET: c_int = 0xffff; - pub const SO_DEBUG: c_int = 0x01; - pub const SO_ACCEPTCONN: c_int = 0x0002; - pub const SO_REUSEADDR: c_int = 0x0004; - pub const SO_KEEPALIVE: c_int = 0x0008; - pub const SO_DONTROUTE: c_int = 0x0010; - pub const SO_BROADCAST: c_int = 0x0020; - pub const SO_USELOOPBACK: c_int = 0x0040; - pub const SO_LINGER: c_int = 0x0080; - pub const SO_OOBINLINE: c_int = 0x0100; - pub const SO_REUSEPORT: c_int = 0x0200; - pub const SO_SNDBUF: c_int = 0x1001; - pub const SO_RCVBUF: c_int = 0x1002; - pub const SO_SNDLOWAT: c_int = 0x1003; - pub const SO_RCVLOWAT: c_int = 0x1004; - pub const SO_SNDTIMEO: c_int = 0x1005; - pub const SO_RCVTIMEO: c_int = 0x1006; - pub const SO_ERROR: c_int = 0x1007; - pub const SO_TYPE: c_int = 0x1008; - - pub const IFF_LOOPBACK: c_int = 0x8; - - pub const SHUT_RD: c_int = 0; - pub const SHUT_WR: c_int = 1; - pub const SHUT_RDWR: c_int = 2; - - pub const LOCK_SH: c_int = 1; - pub const LOCK_EX: c_int = 2; - pub const LOCK_NB: c_int = 4; - pub const LOCK_UN: c_int = 8; - } - pub mod extra { - use types::os::arch::c95::c_int; - - pub const O_SYNC: c_int = 128; - pub const O_NONBLOCK: c_int = 4; - pub const CTL_KERN: c_int = 1; - pub const KERN_PROC: c_int = 14; - #[cfg(target_os = "freebsd")] - pub const KERN_PROC_PATHNAME: c_int = 12; - #[cfg(target_os = "dragonfly")] - pub const KERN_PROC_PATHNAME: c_int = 9; - - pub const MAP_COPY: c_int = 0x0002; - pub const MAP_RENAME: c_int = 0x0020; - pub const MAP_NORESERVE: c_int = 0x0040; - pub const MAP_HASSEMAPHORE: c_int = 0x0200; - pub const MAP_STACK: c_int = 0x0400; - pub const MAP_NOSYNC: c_int = 0x0800; - pub const MAP_NOCORE: c_int = 0x020000; - - pub const IPPROTO_RAW: c_int = 255; - } - pub mod sysconf { - use types::os::arch::c95::c_int; - - pub const _SC_ARG_MAX: c_int = 1; - pub const _SC_CHILD_MAX: c_int = 2; - pub const _SC_CLK_TCK: c_int = 3; - pub const _SC_NGROUPS_MAX: c_int = 4; - pub const _SC_OPEN_MAX: c_int = 5; - pub const _SC_JOB_CONTROL: c_int = 6; - pub const _SC_SAVED_IDS: c_int = 7; - pub const _SC_VERSION: c_int = 8; - pub const _SC_BC_BASE_MAX: c_int = 9; - pub const _SC_BC_DIM_MAX: c_int = 10; - pub const _SC_BC_SCALE_MAX: c_int = 11; - pub const _SC_BC_STRING_MAX: c_int = 12; - pub const _SC_COLL_WEIGHTS_MAX: c_int = 13; - pub const _SC_EXPR_NEST_MAX: c_int = 14; - pub const _SC_LINE_MAX: c_int = 15; - pub const _SC_RE_DUP_MAX: c_int = 16; - pub const _SC_2_VERSION: c_int = 17; - pub const _SC_2_C_BIND: c_int = 18; - pub const _SC_2_C_DEV: c_int = 19; - pub const _SC_2_CHAR_TERM: c_int = 20; - pub const _SC_2_FORT_DEV: c_int = 21; - pub const _SC_2_FORT_RUN: c_int = 22; - pub const _SC_2_LOCALEDEF: c_int = 23; - pub const _SC_2_SW_DEV: c_int = 24; - pub const _SC_2_UPE: c_int = 25; - pub const _SC_STREAM_MAX: c_int = 26; - pub const _SC_TZNAME_MAX: c_int = 27; - pub const _SC_ASYNCHRONOUS_IO: c_int = 28; - pub const _SC_MAPPED_FILES: c_int = 29; - pub const _SC_MEMLOCK: c_int = 30; - pub const _SC_MEMLOCK_RANGE: c_int = 31; - pub const _SC_MEMORY_PROTECTION: c_int = 32; - pub const _SC_MESSAGE_PASSING: c_int = 33; - pub const _SC_PRIORITIZED_IO: c_int = 34; - pub const _SC_PRIORITY_SCHEDULING: c_int = 35; - pub const _SC_REALTIME_SIGNALS: c_int = 36; - pub const _SC_SEMAPHORES: c_int = 37; - pub const _SC_FSYNC: c_int = 38; - pub const _SC_SHARED_MEMORY_OBJECTS: c_int = 39; - pub const _SC_SYNCHRONIZED_IO: c_int = 40; - pub const _SC_TIMERS: c_int = 41; - pub const _SC_AIO_LISTIO_MAX: c_int = 42; - pub const _SC_AIO_MAX: c_int = 43; - pub const _SC_AIO_PRIO_DELTA_MAX: c_int = 44; - pub const _SC_DELAYTIMER_MAX: c_int = 45; - pub const _SC_MQ_OPEN_MAX: c_int = 46; - pub const _SC_PAGESIZE: c_int = 47; - pub const _SC_RTSIG_MAX: c_int = 48; - pub const _SC_SEM_NSEMS_MAX: c_int = 49; - pub const _SC_SEM_VALUE_MAX: c_int = 50; - pub const _SC_SIGQUEUE_MAX: c_int = 51; - pub const _SC_TIMER_MAX: c_int = 52; - - pub const _PC_NAME_MAX: c_int = 4; - pub const _PC_PATH_MAX: c_int = 5; - } - } - - #[cfg(any(target_os = "bitrig", target_os = "openbsd"))] - pub mod os { - pub mod c95 { - use types::os::arch::c95::{c_int, c_uint}; - - pub const EXIT_FAILURE: c_int = 1; - pub const EXIT_SUCCESS: c_int = 0; - pub const RAND_MAX: c_int = 2147483647; - pub const EOF: c_int = -1; - pub const SEEK_SET: c_int = 0; - pub const SEEK_CUR: c_int = 1; - pub const SEEK_END: c_int = 2; - pub const _IOFBF: c_int = 0; - pub const _IONBF: c_int = 2; - pub const _IOLBF: c_int = 1; - pub const BUFSIZ: c_uint = 1024; - pub const FOPEN_MAX: c_uint = 20; - pub const FILENAME_MAX: c_uint = 1024; - pub const L_tmpnam: c_uint = 1024; - pub const TMP_MAX: c_uint = 308915776; - } - pub mod c99 { - } - pub mod posix88 { - use types::common::c95::c_void; - use types::os::arch::c95::c_int; - use types::os::arch::posix88::mode_t; - - pub const O_RDONLY: c_int = 0; - pub const O_WRONLY: c_int = 1; - pub const O_RDWR: c_int = 2; - pub const O_APPEND: c_int = 8; - pub const O_CREAT: c_int = 512; - pub const O_EXCL: c_int = 2048; - pub const O_NOCTTY: c_int = 32768; - pub const O_TRUNC: c_int = 1024; - pub const S_IFIFO: mode_t = 4096; - pub const S_IFCHR: mode_t = 8192; - pub const S_IFBLK: mode_t = 24576; - pub const S_IFDIR: mode_t = 16384; - pub const S_IFREG: mode_t = 32768; - pub const S_IFLNK: mode_t = 40960; - pub const S_IFSOCK: mode_t = 49152; - pub const S_IFMT: mode_t = 61440; - pub const S_IEXEC: mode_t = 64; - pub const S_IWRITE: mode_t = 128; - pub const S_IREAD: mode_t = 256; - pub const S_IRWXU: mode_t = 448; - pub const S_IXUSR: mode_t = 64; - pub const S_IWUSR: mode_t = 128; - pub const S_IRUSR: mode_t = 256; - pub const S_IRWXG: mode_t = 56; - pub const S_IXGRP: mode_t = 8; - pub const S_IWGRP: mode_t = 16; - pub const S_IRGRP: mode_t = 32; - pub const S_IRWXO: mode_t = 7; - pub const S_IXOTH: mode_t = 1; - pub const S_IWOTH: mode_t = 2; - pub const S_IROTH: mode_t = 4; - pub const F_OK: c_int = 0; - pub const R_OK: c_int = 4; - pub const W_OK: c_int = 2; - pub const X_OK: c_int = 1; - pub const STDIN_FILENO: c_int = 0; - pub const STDOUT_FILENO: c_int = 1; - pub const STDERR_FILENO: c_int = 2; - pub const F_LOCK: c_int = 1; - pub const F_TEST: c_int = 3; - pub const F_TLOCK: c_int = 2; - pub const F_ULOCK: c_int = 0; - pub const SIGHUP: c_int = 1; - pub const SIGINT: c_int = 2; - pub const SIGQUIT: c_int = 3; - pub const SIGILL: c_int = 4; - pub const SIGABRT: c_int = 6; - pub const SIGFPE: c_int = 8; - pub const SIGKILL: c_int = 9; - pub const SIGSEGV: c_int = 11; - pub const SIGPIPE: c_int = 13; - pub const SIGALRM: c_int = 14; - pub const SIGTERM: c_int = 15; - - pub const PROT_NONE: c_int = 0; - pub const PROT_READ: c_int = 1; - pub const PROT_WRITE: c_int = 2; - pub const PROT_EXEC: c_int = 4; - - pub const MAP_FILE: c_int = 0x0000; - pub const MAP_SHARED: c_int = 0x0001; - pub const MAP_PRIVATE: c_int = 0x0002; - pub const MAP_FIXED: c_int = 0x0010; - pub const MAP_ANON: c_int = 0x1000; - - pub const MAP_FAILED: *mut c_void = !0 as *mut c_void; - - pub const MCL_CURRENT: c_int = 0x0001; - pub const MCL_FUTURE: c_int = 0x0002; - - pub const MS_ASYNC: c_int = 0x0001; - pub const MS_SYNC: c_int = 0x0002; - pub const MS_INVALIDATE: c_int = 0x0004; - - pub const EPERM: c_int = 1; - pub const ENOENT: c_int = 2; - pub const ESRCH: c_int = 3; - pub const EINTR: c_int = 4; - pub const EIO: c_int = 5; - pub const ENXIO: c_int = 6; - pub const E2BIG: c_int = 7; - pub const ENOEXEC: c_int = 8; - pub const EBADF: c_int = 9; - pub const ECHILD: c_int = 10; - pub const EDEADLK: c_int = 11; - pub const ENOMEM: c_int = 12; - pub const EACCES: c_int = 13; - pub const EFAULT: c_int = 14; - pub const ENOTBLK: c_int = 15; - pub const EBUSY: c_int = 16; - pub const EEXIST: c_int = 17; - pub const EXDEV: c_int = 18; - pub const ENODEV: c_int = 19; - pub const ENOTDIR: c_int = 20; - pub const EISDIR: c_int = 21; - pub const EINVAL: c_int = 22; - pub const ENFILE: c_int = 23; - pub const EMFILE: c_int = 24; - pub const ENOTTY: c_int = 25; - pub const ETXTBSY: c_int = 26; - pub const EFBIG: c_int = 27; - pub const ENOSPC: c_int = 28; - pub const ESPIPE: c_int = 29; - pub const EROFS: c_int = 30; - pub const EMLINK: c_int = 31; - pub const EPIPE: c_int = 32; - pub const EDOM: c_int = 33; - pub const ERANGE: c_int = 34; - pub const EAGAIN: c_int = 35; - pub const EWOULDBLOCK: c_int = 35; - pub const EINPROGRESS: c_int = 36; - pub const EALREADY: c_int = 37; - pub const ENOTSOCK: c_int = 38; - pub const EDESTADDRREQ: c_int = 39; - pub const EMSGSIZE: c_int = 40; - pub const EPROTOTYPE: c_int = 41; - pub const ENOPROTOOPT: c_int = 42; - pub const EPROTONOSUPPORT: c_int = 43; - pub const ESOCKTNOSUPPORT: c_int = 44; - pub const EOPNOTSUPP: c_int = 45; - pub const EPFNOSUPPORT: c_int = 46; - pub const EAFNOSUPPORT: c_int = 47; - pub const EADDRINUSE: c_int = 48; - pub const EADDRNOTAVAIL: c_int = 49; - pub const ENETDOWN: c_int = 50; - pub const ENETUNREACH: c_int = 51; - pub const ENETRESET: c_int = 52; - pub const ECONNABORTED: c_int = 53; - pub const ECONNRESET: c_int = 54; - pub const ENOBUFS: c_int = 55; - pub const EISCONN: c_int = 56; - pub const ENOTCONN: c_int = 57; - pub const ESHUTDOWN: c_int = 58; - pub const ETOOMANYREFS: c_int = 59; - pub const ETIMEDOUT: c_int = 60; - pub const ECONNREFUSED: c_int = 61; - pub const ELOOP: c_int = 62; - pub const ENAMETOOLONG: c_int = 63; - pub const EHOSTDOWN: c_int = 64; - pub const EHOSTUNREACH: c_int = 65; - pub const ENOTEMPTY: c_int = 66; - pub const EPROCLIM: c_int = 67; - pub const EUSERS: c_int = 68; - pub const EDQUOT: c_int = 69; - pub const ESTALE: c_int = 70; - pub const EREMOTE: c_int = 71; - pub const EBADRPC: c_int = 72; - pub const ERPCMISMATCH: c_int = 73; - pub const EPROGUNAVAIL: c_int = 74; - pub const EPROGMISMATCH: c_int = 75; - pub const EPROCUNAVAIL: c_int = 76; - pub const ENOLCK: c_int = 77; - pub const ENOSYS: c_int = 78; - pub const EFTYPE: c_int = 79; - pub const EAUTH: c_int = 80; - pub const ENEEDAUTH: c_int = 81; - pub const EIPSEC: c_int = 82; - pub const ENOATTR: c_int = 83; - pub const EILSEQ: c_int = 84; - pub const ENOMEDIUM: c_int = 85; - pub const EMEDIUMTYPE: c_int = 86; - pub const EOVERFLOW: c_int = 87; - pub const ECANCELED: c_int = 88; - pub const EIDRM: c_int = 89; - pub const ENOMSG: c_int = 90; - pub const ENOTSUP: c_int = 91; - pub const ELAST: c_int = 91; // must be equal to largest errno - } - pub mod posix01 { - use types::os::arch::c95::{c_int, size_t}; - use types::os::common::posix01::rlim_t; - - pub const F_DUPFD: c_int = 0; - pub const F_GETFD: c_int = 1; - pub const F_SETFD: c_int = 2; - pub const F_GETFL: c_int = 3; - pub const F_SETFL: c_int = 4; - pub const F_GETOWN: c_int = 5; - pub const F_SETOWN: c_int = 6; - pub const F_GETLK: c_int = 7; - pub const F_SETLK: c_int = 8; - pub const F_SETLKW: c_int = 9; - - pub const SIGTRAP: c_int = 5; - pub const SIG_IGN: size_t = 1; - - pub const GLOB_APPEND: c_int = 0x0001; - pub const GLOB_DOOFFS: c_int = 0x0002; - pub const GLOB_ERR: c_int = 0x0004; - pub const GLOB_MARK: c_int = 0x0008; - pub const GLOB_NOCHECK: c_int = 0x0010; - pub const GLOB_NOSORT: c_int = 0x0020; - pub const GLOB_NOESCAPE: c_int = 0x1000; - - pub const GLOB_NOSPACE: c_int = -1; - pub const GLOB_ABORTED: c_int = -2; - pub const GLOB_NOMATCH: c_int = -3; - pub const GLOB_NOSYS: c_int = -4; - - pub const POSIX_MADV_NORMAL: c_int = 0; - pub const POSIX_MADV_RANDOM: c_int = 1; - pub const POSIX_MADV_SEQUENTIAL: c_int = 2; - pub const POSIX_MADV_WILLNEED: c_int = 3; - pub const POSIX_MADV_DONTNEED: c_int = 4; - - pub const _SC_IOV_MAX: c_int = 51; - pub const _SC_GETGR_R_SIZE_MAX: c_int = 100; - pub const _SC_GETPW_R_SIZE_MAX: c_int = 101; - pub const _SC_LOGIN_NAME_MAX: c_int = 102; - pub const _SC_MQ_PRIO_MAX: c_int = 59; - pub const _SC_THREAD_ATTR_STACKADDR: c_int = 77; - pub const _SC_THREAD_ATTR_STACKSIZE: c_int = 78; - pub const _SC_THREAD_DESTRUCTOR_ITERATIONS: c_int = 80; - pub const _SC_THREAD_KEYS_MAX: c_int = 81; - pub const _SC_THREAD_PRIO_INHERIT: c_int = 82; - pub const _SC_THREAD_PRIO_PROTECT: c_int = 83; - pub const _SC_THREAD_PRIORITY_SCHEDULING: c_int = 84; - pub const _SC_THREAD_PROCESS_SHARED: c_int = 85; - pub const _SC_THREAD_SAFE_FUNCTIONS: c_int = 103; - pub const _SC_THREAD_STACK_MIN: c_int = 89; - pub const _SC_THREAD_THREADS_MAX: c_int = 90; - pub const _SC_THREADS: c_int = 91; - pub const _SC_TTY_NAME_MAX: c_int = 107; - pub const _SC_ATEXIT_MAX: c_int = 46; - pub const _SC_XOPEN_CRYPT: c_int = 117; - pub const _SC_XOPEN_ENH_I18N: c_int = 118; - pub const _SC_XOPEN_LEGACY: c_int = 119; - pub const _SC_XOPEN_REALTIME: c_int = 120; - pub const _SC_XOPEN_REALTIME_THREADS: c_int = 121; - pub const _SC_XOPEN_SHM: c_int = 30; - pub const _SC_XOPEN_UNIX: c_int = 123; - pub const _SC_XOPEN_VERSION: c_int = 125; - - pub const PTHREAD_CREATE_JOINABLE: c_int = 0; - pub const PTHREAD_CREATE_DETACHED: c_int = 1; - pub const PTHREAD_STACK_MIN: size_t = 2048; - - pub const CLOCK_REALTIME: c_int = 0; - pub const CLOCK_MONOTONIC: c_int = 3; - - pub const RLIMIT_CPU: c_int = 0; - pub const RLIMIT_FSIZE: c_int = 1; - pub const RLIMIT_DATA: c_int = 2; - pub const RLIMIT_STACK: c_int = 3; - pub const RLIMIT_CORE: c_int = 4; - pub const RLIMIT_RSS: c_int = 5; - pub const RLIMIT_MEMLOCK: c_int = 6; - pub const RLIMIT_NPROC: c_int = 7; - pub const RLIMIT_NOFILE: c_int = 8; - pub const RLIM_NLIMITS: c_int = 9; - - pub const RLIM_INFINITY: rlim_t = 0x7fff_ffff_ffff_ffff; - pub const RLIM_SAVED_MAX: rlim_t = RLIM_INFINITY; - pub const RLIM_SAVED_CUR: rlim_t = RLIM_INFINITY; - - pub const RUSAGE_SELF: c_int = 0; - pub const RUSAGE_CHILDREN: c_int = -1; - pub const RUSAGE_THREAD: c_int = 1; - } - pub mod posix08 { - use types::os::arch::c95::c_int; - pub const O_CLOEXEC: c_int = 0x10000; - pub const F_DUPFD_CLOEXEC: c_int = 10; - } - pub mod bsd44 { - use types::os::arch::c95::c_int; - - pub const MADV_NORMAL: c_int = 0; - pub const MADV_RANDOM: c_int = 1; - pub const MADV_SEQUENTIAL: c_int = 2; - pub const MADV_WILLNEED: c_int = 3; - pub const MADV_DONTNEED: c_int = 4; - pub const MADV_FREE: c_int = 6; - - pub const AF_UNIX: c_int = 1; - pub const AF_INET: c_int = 2; - pub const AF_INET6: c_int = 24; - pub const SOCK_STREAM: c_int = 1; - pub const SOCK_DGRAM: c_int = 2; - pub const SOCK_RAW: c_int = 3; - pub const IPPROTO_TCP: c_int = 6; - pub const IPPROTO_IP: c_int = 0; - pub const IPPROTO_IPV6: c_int = 41; - pub const IP_MULTICAST_TTL: c_int = 10; - pub const IP_MULTICAST_LOOP: c_int = 11; - pub const IP_TTL: c_int = 4; - pub const IP_HDRINCL: c_int = 2; - pub const IP_ADD_MEMBERSHIP: c_int = 12; - pub const IP_DROP_MEMBERSHIP: c_int = 13; - pub const IPV6_ADD_MEMBERSHIP: c_int = 12; // don't exist - pub const IPV6_DROP_MEMBERSHIP: c_int = 13; // don't exist - - pub const TCP_NODELAY: c_int = 0x01; - pub const SOL_SOCKET: c_int = 0xffff; - pub const SO_DEBUG: c_int = 0x01; - pub const SO_ACCEPTCONN: c_int = 0x0002; - pub const SO_REUSEADDR: c_int = 0x0004; - pub const SO_KEEPALIVE: c_int = 0x0008; - pub const SO_DONTROUTE: c_int = 0x0010; - pub const SO_BROADCAST: c_int = 0x0020; - pub const SO_USELOOPBACK: c_int = 0x0040; - pub const SO_LINGER: c_int = 0x0080; - pub const SO_OOBINLINE: c_int = 0x0100; - pub const SO_REUSEPORT: c_int = 0x0200; - pub const SO_SNDBUF: c_int = 0x1001; - pub const SO_RCVBUF: c_int = 0x1002; - pub const SO_SNDLOWAT: c_int = 0x1003; - pub const SO_RCVLOWAT: c_int = 0x1004; - pub const SO_SNDTIMEO: c_int = 0x1005; - pub const SO_RCVTIMEO: c_int = 0x1006; - pub const SO_ERROR: c_int = 0x1007; - pub const SO_TYPE: c_int = 0x1008; - - pub const IFF_LOOPBACK: c_int = 0x8; - - pub const SHUT_RD: c_int = 0; - pub const SHUT_WR: c_int = 1; - pub const SHUT_RDWR: c_int = 2; - - pub const LOCK_SH: c_int = 1; - pub const LOCK_EX: c_int = 2; - pub const LOCK_NB: c_int = 4; - pub const LOCK_UN: c_int = 8; - } - pub mod extra { - use types::os::arch::c95::c_int; - - pub const O_DSYNC: c_int = 128; // same as SYNC - pub const O_SYNC: c_int = 128; - pub const O_NONBLOCK: c_int = 4; - pub const CTL_KERN: c_int = 1; - pub const KERN_PROC: c_int = 66; - - pub const MAP_COPY: c_int = 0x0002; - pub const MAP_RENAME: c_int = 0x0000; - pub const MAP_NORESERVE: c_int = 0x0000; - pub const MAP_NOEXTEND: c_int = 0x0000; - pub const MAP_HASSEMAPHORE: c_int = 0x0000; - - pub const IPPROTO_RAW: c_int = 255; - - pub const PATH_MAX: c_int = 1024; - } - pub mod sysconf { - use types::os::arch::c95::c_int; - - pub const _SC_ARG_MAX: c_int = 1; - pub const _SC_CHILD_MAX: c_int = 2; - pub const _SC_CLK_TCK: c_int = 3; - pub const _SC_NGROUPS_MAX: c_int = 4; - pub const _SC_OPEN_MAX: c_int = 5; - pub const _SC_JOB_CONTROL: c_int = 6; - pub const _SC_SAVED_IDS: c_int = 7; - pub const _SC_VERSION: c_int = 8; - pub const _SC_BC_BASE_MAX: c_int = 9; - pub const _SC_BC_DIM_MAX: c_int = 10; - pub const _SC_BC_SCALE_MAX: c_int = 11; - pub const _SC_BC_STRING_MAX: c_int = 12; - pub const _SC_COLL_WEIGHTS_MAX: c_int = 13; - pub const _SC_EXPR_NEST_MAX: c_int = 14; - pub const _SC_LINE_MAX: c_int = 15; - pub const _SC_RE_DUP_MAX: c_int = 16; - pub const _SC_2_VERSION: c_int = 17; - pub const _SC_2_C_BIND: c_int = 18; - pub const _SC_2_C_DEV: c_int = 19; - pub const _SC_2_CHAR_TERM: c_int = 20; - pub const _SC_2_FORT_DEV: c_int = 21; - pub const _SC_2_FORT_RUN: c_int = 22; - pub const _SC_2_LOCALEDEF: c_int = 23; - pub const _SC_2_SW_DEV: c_int = 24; - pub const _SC_2_UPE: c_int = 25; - pub const _SC_STREAM_MAX: c_int = 26; - pub const _SC_TZNAME_MAX: c_int = 27; - pub const _SC_PAGESIZE: c_int = 28; - pub const _SC_FSYNC: c_int = 29; - pub const _SC_SEM_NSEMS_MAX: c_int = 31; - pub const _SC_SEM_VALUE_MAX: c_int = 32; - pub const _SC_AIO_LISTIO_MAX: c_int = 42; - pub const _SC_AIO_MAX: c_int = 43; - pub const _SC_AIO_PRIO_DELTA_MAX: c_int = 44; - pub const _SC_ASYNCHRONOUS_IO: c_int = 45; - pub const _SC_DELAYTIMER_MAX: c_int = 50; - pub const _SC_MAPPED_FILES: c_int = 53; - pub const _SC_MEMLOCK: c_int = 54; - pub const _SC_MEMLOCK_RANGE: c_int = 55; - pub const _SC_MEMORY_PROTECTION: c_int = 56; - pub const _SC_MESSAGE_PASSING: c_int = 57; - pub const _SC_MQ_OPEN_MAX: c_int = 58; - pub const _SC_PRIORITIZED_IO: c_int = 60; - pub const _SC_PRIORITY_SCHEDULING: c_int = 61; - pub const _SC_REALTIME_SIGNALS: c_int = 64; - pub const _SC_RTSIG_MAX: c_int = 66; - pub const _SC_SEMAPHORES: c_int = 67; - pub const _SC_SHARED_MEMORY_OBJECTS: c_int = 68; - pub const _SC_SIGQUEUE_MAX: c_int = 70; - pub const _SC_SYNCHRONIZED_IO: c_int = 75; - pub const _SC_TIMER_MAX: c_int = 93; - pub const _SC_TIMERS: c_int = 94; - - pub const _PC_NAME_MAX: c_int = 4; - pub const _PC_PATH_MAX: c_int = 5; - } - } - - #[cfg(target_os = "netbsd")] - pub mod os { - pub mod c95 { - use types::os::arch::c95::{c_int, c_uint}; - - pub const EXIT_FAILURE: c_int = 1; - pub const EXIT_SUCCESS: c_int = 0; - pub const RAND_MAX: c_int = 2147483647; - pub const EOF: c_int = -1; - pub const SEEK_SET: c_int = 0; - pub const SEEK_CUR: c_int = 1; - pub const SEEK_END: c_int = 2; - pub const _IOFBF: c_int = 0; - pub const _IONBF: c_int = 2; - pub const _IOLBF: c_int = 1; - pub const BUFSIZ: c_uint = 1024; - pub const FOPEN_MAX: c_uint = 20; - pub const FILENAME_MAX: c_uint = 1024; - pub const L_tmpnam: c_uint = 1024; - pub const TMP_MAX: c_uint = 308915776; - } - pub mod c99 { - } - pub mod posix88 { - use types::common::c95::c_void; - use types::os::arch::c95::c_int; - use types::os::arch::posix88::mode_t; - - pub const O_RDONLY: c_int = 0; - pub const O_WRONLY: c_int = 1; - pub const O_RDWR: c_int = 2; - pub const O_APPEND: c_int = 8; - pub const O_CREAT: c_int = 512; - pub const O_EXCL: c_int = 2048; - pub const O_NOCTTY: c_int = 32768; - pub const O_TRUNC: c_int = 1024; - pub const S_IFIFO: mode_t = 4096; - pub const S_IFCHR: mode_t = 8192; - pub const S_IFBLK: mode_t = 24576; - pub const S_IFDIR: mode_t = 16384; - pub const S_IFREG: mode_t = 32768; - pub const S_IFLNK: mode_t = 40960; - pub const S_IFSOCK: mode_t = 49152; - pub const S_IFMT: mode_t = 61440; - pub const S_IEXEC: mode_t = 64; - pub const S_IWRITE: mode_t = 128; - pub const S_IREAD: mode_t = 256; - pub const S_IRWXU: mode_t = 448; - pub const S_IXUSR: mode_t = 64; - pub const S_IWUSR: mode_t = 128; - pub const S_IRUSR: mode_t = 256; - pub const S_IRWXG: mode_t = 56; - pub const S_IXGRP: mode_t = 8; - pub const S_IWGRP: mode_t = 16; - pub const S_IRGRP: mode_t = 32; - pub const S_IRWXO: mode_t = 7; - pub const S_IXOTH: mode_t = 1; - pub const S_IWOTH: mode_t = 2; - pub const S_IROTH: mode_t = 4; - pub const F_OK: c_int = 0; - pub const R_OK: c_int = 4; - pub const W_OK: c_int = 2; - pub const X_OK: c_int = 1; - pub const STDIN_FILENO: c_int = 0; - pub const STDOUT_FILENO: c_int = 1; - pub const STDERR_FILENO: c_int = 2; - pub const F_LOCK: c_int = 1; - pub const F_TEST: c_int = 3; - pub const F_TLOCK: c_int = 2; - pub const F_ULOCK: c_int = 0; - pub const SIGHUP: c_int = 1; - pub const SIGINT: c_int = 2; - pub const SIGQUIT: c_int = 3; - pub const SIGILL: c_int = 4; - pub const SIGABRT: c_int = 6; - pub const SIGFPE: c_int = 8; - pub const SIGKILL: c_int = 9; - pub const SIGSEGV: c_int = 11; - pub const SIGPIPE: c_int = 13; - pub const SIGALRM: c_int = 14; - pub const SIGTERM: c_int = 15; - - pub const PROT_NONE: c_int = 0; - pub const PROT_READ: c_int = 1; - pub const PROT_WRITE: c_int = 2; - pub const PROT_EXEC: c_int = 4; - - pub const MAP_FILE: c_int = 0; - pub const MAP_SHARED: c_int = 1; - pub const MAP_PRIVATE: c_int = 2; - pub const MAP_FIXED: c_int = 16; - pub const MAP_ANON: c_int = 4096; - - pub const MAP_FAILED: *mut c_void = !0 as *mut c_void; - - pub const MCL_CURRENT: c_int = 1; - pub const MCL_FUTURE: c_int = 2; - - pub const MS_ASYNC: c_int = 1; - pub const MS_SYNC: c_int = 4; - pub const MS_INVALIDATE: c_int = 2; - - pub const EPERM: c_int = 1; - pub const ENOENT: c_int = 2; - pub const ESRCH: c_int = 3; - pub const EINTR: c_int = 4; - pub const EIO: c_int = 5; - pub const ENXIO: c_int = 6; - pub const E2BIG: c_int = 7; - pub const ENOEXEC: c_int = 8; - pub const EBADF: c_int = 9; - pub const ECHILD: c_int = 10; - pub const EDEADLK: c_int = 11; - pub const ENOMEM: c_int = 12; - pub const EACCES: c_int = 13; - pub const EFAULT: c_int = 14; - pub const ENOTBLK: c_int = 15; - pub const EBUSY: c_int = 16; - pub const EEXIST: c_int = 17; - pub const EXDEV: c_int = 18; - pub const ENODEV: c_int = 19; - pub const ENOTDIR: c_int = 20; - pub const EISDIR: c_int = 21; - pub const EINVAL: c_int = 22; - pub const ENFILE: c_int = 23; - pub const EMFILE: c_int = 24; - pub const ENOTTY: c_int = 25; - pub const ETXTBSY: c_int = 26; - pub const EFBIG: c_int = 27; - pub const ENOSPC: c_int = 28; - pub const ESPIPE: c_int = 29; - pub const EROFS: c_int = 30; - pub const EMLINK: c_int = 31; - pub const EPIPE: c_int = 32; - pub const EDOM: c_int = 33; - pub const ERANGE: c_int = 34; - pub const EAGAIN: c_int = 35; - pub const EWOULDBLOCK: c_int = 35; - pub const EINPROGRESS: c_int = 36; - pub const EALREADY: c_int = 37; - pub const ENOTSOCK: c_int = 38; - pub const EDESTADDRREQ: c_int = 39; - pub const EMSGSIZE: c_int = 40; - pub const EPROTOTYPE: c_int = 41; - pub const ENOPROTOOPT: c_int = 42; - pub const EPROTONOSUPPORT: c_int = 43; - pub const ESOCKTNOSUPPORT: c_int = 44; - pub const EOPNOTSUPP: c_int = 45; - pub const EPFNOSUPPORT: c_int = 46; - pub const EAFNOSUPPORT: c_int = 47; - pub const EADDRINUSE: c_int = 48; - pub const EADDRNOTAVAIL: c_int = 49; - pub const ENETDOWN: c_int = 50; - pub const ENETUNREACH: c_int = 51; - pub const ENETRESET: c_int = 52; - pub const ECONNABORTED: c_int = 53; - pub const ECONNRESET: c_int = 54; - pub const ENOBUFS: c_int = 55; - pub const EISCONN: c_int = 56; - pub const ENOTCONN: c_int = 57; - pub const ESHUTDOWN: c_int = 58; - pub const ETOOMANYREFS: c_int = 59; - pub const ETIMEDOUT: c_int = 60; - pub const ECONNREFUSED: c_int = 61; - pub const ELOOP: c_int = 62; - pub const ENAMETOOLONG: c_int = 63; - pub const EHOSTDOWN: c_int = 64; - pub const EHOSTUNREACH: c_int = 65; - pub const ENOTEMPTY: c_int = 66; - pub const EPROCLIM: c_int = 67; - pub const EUSERS: c_int = 68; - pub const EDQUOT: c_int = 69; - pub const ESTALE: c_int = 70; - pub const EREMOTE: c_int = 71; - pub const EBADRPC: c_int = 72; - pub const ERPCMISMATCH: c_int = 73; - pub const EPROGUNAVAIL: c_int = 74; - pub const EPROGMISMATCH: c_int = 75; - pub const EPROCUNAVAIL: c_int = 76; - pub const ENOLCK: c_int = 77; - pub const ENOSYS: c_int = 78; - pub const EFTYPE: c_int = 79; - pub const EAUTH: c_int = 80; - pub const ENEEDAUTH: c_int = 81; - pub const ENOATTR: c_int = 93; - pub const EILSEQ: c_int = 85; - pub const EOVERFLOW: c_int = 84; - pub const ECANCELED: c_int = 87; - pub const EIDRM: c_int = 82; - pub const ENOMSG: c_int = 83; - pub const ENOTSUP: c_int = 86; - pub const ELAST: c_int = 96; - } - pub mod posix01 { - use types::os::arch::c95::{c_int, size_t}; - use types::os::common::posix01::rlim_t; - - pub const F_DUPFD: c_int = 0; - pub const F_GETFD: c_int = 1; - pub const F_SETFD: c_int = 2; - pub const F_GETFL: c_int = 3; - pub const F_SETFL: c_int = 4; - pub const F_GETOWN: c_int = 5; - pub const F_SETOWN: c_int = 6; - pub const F_GETLK: c_int = 7; - pub const F_SETLK: c_int = 8; - pub const F_SETLKW: c_int = 9; - - pub const SIGTRAP: c_int = 5; - pub const SIG_IGN: size_t = 1; - - pub const GLOB_APPEND: c_int = 1; - pub const GLOB_DOOFFS: c_int = 2; - pub const GLOB_ERR: c_int = 4; - pub const GLOB_MARK: c_int = 8; - pub const GLOB_NOCHECK: c_int = 16; - pub const GLOB_NOSORT: c_int = 32; - pub const GLOB_NOESCAPE: c_int = 4096; - - pub const GLOB_NOSPACE: c_int = -1; - pub const GLOB_ABORTED: c_int = -2; - pub const GLOB_NOMATCH: c_int = -3; - pub const GLOB_NOSYS: c_int = -4; - - pub const POSIX_MADV_NORMAL: c_int = 0; - pub const POSIX_MADV_RANDOM: c_int = 1; - pub const POSIX_MADV_SEQUENTIAL: c_int = 2; - pub const POSIX_MADV_WILLNEED: c_int = 3; - pub const POSIX_MADV_DONTNEED: c_int = 4; - - pub const _SC_IOV_MAX: c_int = 32; - pub const _SC_GETGR_R_SIZE_MAX: c_int = 47; - pub const _SC_GETPW_R_SIZE_MAX: c_int = 48; - pub const _SC_LOGIN_NAME_MAX: c_int = 37; - pub const _SC_MQ_PRIO_MAX: c_int = 55; - pub const _SC_THREAD_ATTR_STACKADDR: c_int = 61; - pub const _SC_THREAD_ATTR_STACKSIZE: c_int = 62; - pub const _SC_THREAD_DESTRUCTOR_ITERATIONS: c_int = 57; - pub const _SC_THREAD_KEYS_MAX: c_int = 58; - pub const _SC_THREAD_PRIO_INHERIT: c_int = 64; - pub const _SC_THREAD_PRIO_PROTECT: c_int = 65; - pub const _SC_THREAD_PRIORITY_SCHEDULING: c_int = 63; - pub const _SC_THREAD_PROCESS_SHARED: c_int = 66; - pub const _SC_THREAD_SAFE_FUNCTIONS: c_int = 67; - pub const _SC_THREAD_STACK_MIN: c_int = 59; - pub const _SC_THREAD_THREADS_MAX: c_int = 60; - pub const _SC_THREADS: c_int = 41; - pub const _SC_TTY_NAME_MAX: c_int = 68; - pub const _SC_ATEXIT_MAX: c_int = 40; - pub const _SC_XOPEN_SHM: c_int = 30; - - pub const PTHREAD_CREATE_JOINABLE: c_int = 0; - pub const PTHREAD_CREATE_DETACHED: c_int = 1; - pub const PTHREAD_STACK_MIN: size_t = 2048; - - pub const CLOCK_REALTIME: c_int = 0; - pub const CLOCK_MONOTONIC: c_int = 3; - - pub const RLIMIT_CPU: c_int = 0; - pub const RLIMIT_FSIZE: c_int = 1; - pub const RLIMIT_DATA: c_int = 2; - pub const RLIMIT_STACK: c_int = 3; - pub const RLIMIT_CORE: c_int = 4; - pub const RLIMIT_RSS: c_int = 5; - pub const RLIMIT_MEMLOCK: c_int = 6; - pub const RLIMIT_NPROC: c_int = 7; - pub const RLIMIT_NOFILE: c_int = 8; - pub const RLIM_NLIMITS: c_int = 9; - - pub const RLIM_INFINITY: rlim_t = 0x7fff_ffff_ffff_ffff; - pub const RLIM_SAVED_MAX: rlim_t = RLIM_INFINITY; - pub const RLIM_SAVED_CUR: rlim_t = RLIM_INFINITY; - - pub const RUSAGE_SELF: c_int = 0; - pub const RUSAGE_CHILDREN: c_int = -1; - pub const RUSAGE_THREAD: c_int = 1; - } - pub mod posix08 { - use types::os::arch::c95::c_int; - pub const O_CLOEXEC: c_int = 0x400000; - pub const F_DUPFD_CLOEXEC: c_int = 12; - } - pub mod bsd44 { - use types::os::arch::c95::c_int; - - pub const MADV_NORMAL: c_int = 0; - pub const MADV_RANDOM: c_int = 1; - pub const MADV_SEQUENTIAL: c_int = 2; - pub const MADV_WILLNEED: c_int = 3; - pub const MADV_DONTNEED: c_int = 4; - pub const MADV_FREE: c_int = 6; - - pub const AF_UNIX: c_int = 1; - pub const AF_INET: c_int = 2; - pub const AF_INET6: c_int = 24; - pub const SOCK_STREAM: c_int = 1; - pub const SOCK_DGRAM: c_int = 2; - pub const SOCK_RAW: c_int = 3; - pub const IPPROTO_TCP: c_int = 6; - pub const IPPROTO_IP: c_int = 0; - pub const IPPROTO_IPV6: c_int = 41; - pub const IP_MULTICAST_TTL: c_int = 10; - pub const IP_MULTICAST_LOOP: c_int = 11; - pub const IP_TTL: c_int = 4; - pub const IP_HDRINCL: c_int = 2; - pub const IP_ADD_MEMBERSHIP: c_int = 12; - pub const IP_DROP_MEMBERSHIP: c_int = 13; - - pub const TCP_NODELAY: c_int = 1; - pub const SOL_SOCKET: c_int = 65535; - pub const SO_DEBUG: c_int = 1; - pub const SO_ACCEPTCONN: c_int = 2; - pub const SO_REUSEADDR: c_int = 4; - pub const SO_KEEPALIVE: c_int = 8; - pub const SO_DONTROUTE: c_int = 16; - pub const SO_BROADCAST: c_int = 32; - pub const SO_USELOOPBACK: c_int = 64; - pub const SO_LINGER: c_int = 128; - pub const SO_OOBINLINE: c_int = 256; - pub const SO_REUSEPORT: c_int = 512; - pub const SO_SNDBUF: c_int = 4097; - pub const SO_RCVBUF: c_int = 4098; - pub const SO_SNDLOWAT: c_int = 4099; - pub const SO_RCVLOWAT: c_int = 4100; - pub const SO_SNDTIMEO: c_int = 4107; - pub const SO_RCVTIMEO: c_int = 4108; - pub const SO_ERROR: c_int = 4103; - pub const SO_TYPE: c_int = 4104; - - pub const IFF_LOOPBACK: c_int = 0x8; - - pub const SHUT_RD: c_int = 0; - pub const SHUT_WR: c_int = 1; - pub const SHUT_RDWR: c_int = 2; - - pub const LOCK_SH: c_int = 1; - pub const LOCK_EX: c_int = 2; - pub const LOCK_NB: c_int = 4; - pub const LOCK_UN: c_int = 8; - } - pub mod extra { - use types::os::arch::c95::c_int; - - - pub const MAP_RENAME: c_int = 32; - pub const MAP_NORESERVE: c_int = 64; - pub const MAP_HASSEMAPHORE: c_int = 512; - - pub const IPPROTO_RAW: c_int = 255; - - pub const PATH_MAX: c_int = 1024; - } - pub mod sysconf { - use types::os::arch::c95::c_int; - - pub const _SC_ARG_MAX: c_int = 1; - pub const _SC_CHILD_MAX: c_int = 2; - pub const _SC_CLK_TCK: c_int = 39; - pub const _SC_NGROUPS_MAX: c_int = 4; - pub const _SC_OPEN_MAX: c_int = 5; - pub const _SC_JOB_CONTROL: c_int = 6; - pub const _SC_SAVED_IDS: c_int = 7; - pub const _SC_VERSION: c_int = 8; - pub const _SC_BC_BASE_MAX: c_int = 9; - pub const _SC_BC_DIM_MAX: c_int = 10; - pub const _SC_BC_SCALE_MAX: c_int = 11; - pub const _SC_BC_STRING_MAX: c_int = 12; - pub const _SC_COLL_WEIGHTS_MAX: c_int = 13; - pub const _SC_EXPR_NEST_MAX: c_int = 14; - pub const _SC_LINE_MAX: c_int = 15; - pub const _SC_RE_DUP_MAX: c_int = 16; - pub const _SC_2_VERSION: c_int = 17; - pub const _SC_2_C_BIND: c_int = 18; - pub const _SC_2_C_DEV: c_int = 19; - pub const _SC_2_CHAR_TERM: c_int = 20; - pub const _SC_2_FORT_DEV: c_int = 21; - pub const _SC_2_FORT_RUN: c_int = 22; - pub const _SC_2_LOCALEDEF: c_int = 23; - pub const _SC_2_SW_DEV: c_int = 24; - pub const _SC_2_UPE: c_int = 25; - pub const _SC_STREAM_MAX: c_int = 26; - pub const _SC_TZNAME_MAX: c_int = 27; - pub const _SC_PAGESIZE: c_int = 28; - pub const _SC_FSYNC: c_int = 29; - pub const _SC_AIO_LISTIO_MAX: c_int = 51; - pub const _SC_AIO_MAX: c_int = 52; - pub const _SC_ASYNCHRONOUS_IO: c_int = 50; - pub const _SC_MAPPED_FILES: c_int = 33; - pub const _SC_MEMLOCK: c_int = 34; - pub const _SC_MEMLOCK_RANGE: c_int = 35; - pub const _SC_MEMORY_PROTECTION: c_int = 36; - pub const _SC_MESSAGE_PASSING: c_int = 53; - pub const _SC_MQ_OPEN_MAX: c_int = 54; - pub const _SC_PRIORITY_SCHEDULING: c_int = 56; - pub const _SC_SEMAPHORES: c_int = 42; - pub const _SC_SHARED_MEMORY_OBJECTS: c_int = 87; - pub const _SC_SYNCHRONIZED_IO: c_int = 31; - pub const _SC_TIMERS: c_int = 44; - - pub const _PC_NAME_MAX: c_int = 4; - pub const _PC_PATH_MAX: c_int = 5; - } - } - - #[cfg(any(target_os = "macos", target_os = "ios"))] - pub mod os { - pub mod c95 { - use types::os::arch::c95::{c_int, c_uint}; - - pub const EXIT_FAILURE: c_int = 1; - pub const EXIT_SUCCESS: c_int = 0; - pub const RAND_MAX: c_int = 2147483647; - pub const EOF: c_int = -1; - pub const SEEK_SET: c_int = 0; - pub const SEEK_CUR: c_int = 1; - pub const SEEK_END: c_int = 2; - pub const _IOFBF: c_int = 0; - pub const _IONBF: c_int = 2; - pub const _IOLBF: c_int = 1; - pub const BUFSIZ: c_uint = 1024; - pub const FOPEN_MAX: c_uint = 20; - pub const FILENAME_MAX: c_uint = 1024; - pub const L_tmpnam: c_uint = 1024; - pub const TMP_MAX: c_uint = 308915776; - } - pub mod c99 { - } - pub mod posix88 { - use types::common::c95::c_void; - use types::os::arch::c95::c_int; - use types::os::arch::posix88::mode_t; - - pub const O_RDONLY: c_int = 0; - pub const O_WRONLY: c_int = 1; - pub const O_RDWR: c_int = 2; - pub const O_APPEND: c_int = 8; - pub const O_CREAT: c_int = 512; - pub const O_EXCL: c_int = 2048; - pub const O_NOCTTY: c_int = 131072; - pub const O_TRUNC: c_int = 1024; - pub const S_IFIFO: mode_t = 4096; - pub const S_IFCHR: mode_t = 8192; - pub const S_IFBLK: mode_t = 24576; - pub const S_IFDIR: mode_t = 16384; - pub const S_IFREG: mode_t = 32768; - pub const S_IFLNK: mode_t = 40960; - pub const S_IFSOCK: mode_t = 49152; - pub const S_IFMT: mode_t = 61440; - pub const S_IEXEC: mode_t = 64; - pub const S_IWRITE: mode_t = 128; - pub const S_IREAD: mode_t = 256; - pub const S_IRWXU: mode_t = 448; - pub const S_IXUSR: mode_t = 64; - pub const S_IWUSR: mode_t = 128; - pub const S_IRUSR: mode_t = 256; - pub const S_IRWXG: mode_t = 56; - pub const S_IXGRP: mode_t = 8; - pub const S_IWGRP: mode_t = 16; - pub const S_IRGRP: mode_t = 32; - pub const S_IRWXO: mode_t = 7; - pub const S_IXOTH: mode_t = 1; - pub const S_IWOTH: mode_t = 2; - pub const S_IROTH: mode_t = 4; - pub const F_OK: c_int = 0; - pub const R_OK: c_int = 4; - pub const W_OK: c_int = 2; - pub const X_OK: c_int = 1; - pub const STDIN_FILENO: c_int = 0; - pub const STDOUT_FILENO: c_int = 1; - pub const STDERR_FILENO: c_int = 2; - pub const F_LOCK: c_int = 1; - pub const F_TEST: c_int = 3; - pub const F_TLOCK: c_int = 2; - pub const F_ULOCK: c_int = 0; - pub const SIGHUP: c_int = 1; - pub const SIGINT: c_int = 2; - pub const SIGQUIT: c_int = 3; - pub const SIGILL: c_int = 4; - pub const SIGABRT: c_int = 6; - pub const SIGFPE: c_int = 8; - pub const SIGKILL: c_int = 9; - pub const SIGSEGV: c_int = 11; - pub const SIGPIPE: c_int = 13; - pub const SIGALRM: c_int = 14; - pub const SIGTERM: c_int = 15; - - pub const PROT_NONE: c_int = 0; - pub const PROT_READ: c_int = 1; - pub const PROT_WRITE: c_int = 2; - pub const PROT_EXEC: c_int = 4; - - pub const MAP_FILE: c_int = 0x0000; - pub const MAP_SHARED: c_int = 0x0001; - pub const MAP_PRIVATE: c_int = 0x0002; - pub const MAP_FIXED: c_int = 0x0010; - pub const MAP_ANON: c_int = 0x1000; - - pub const MAP_FAILED: *mut c_void = !0 as *mut c_void; - - pub const MCL_CURRENT: c_int = 0x0001; - pub const MCL_FUTURE: c_int = 0x0002; - - pub const MS_ASYNC: c_int = 0x0001; - pub const MS_INVALIDATE: c_int = 0x0002; - pub const MS_SYNC: c_int = 0x0010; - - pub const MS_KILLPAGES: c_int = 0x0004; - pub const MS_DEACTIVATE: c_int = 0x0008; - - pub const EPERM: c_int = 1; - pub const ENOENT: c_int = 2; - pub const ESRCH: c_int = 3; - pub const EINTR: c_int = 4; - pub const EIO: c_int = 5; - pub const ENXIO: c_int = 6; - pub const E2BIG: c_int = 7; - pub const ENOEXEC: c_int = 8; - pub const EBADF: c_int = 9; - pub const ECHILD: c_int = 10; - pub const EDEADLK: c_int = 11; - pub const ENOMEM: c_int = 12; - pub const EACCES: c_int = 13; - pub const EFAULT: c_int = 14; - pub const ENOTBLK: c_int = 15; - pub const EBUSY: c_int = 16; - pub const EEXIST: c_int = 17; - pub const EXDEV: c_int = 18; - pub const ENODEV: c_int = 19; - pub const ENOTDIR: c_int = 20; - pub const EISDIR: c_int = 21; - pub const EINVAL: c_int = 22; - pub const ENFILE: c_int = 23; - pub const EMFILE: c_int = 24; - pub const ENOTTY: c_int = 25; - pub const ETXTBSY: c_int = 26; - pub const EFBIG: c_int = 27; - pub const ENOSPC: c_int = 28; - pub const ESPIPE: c_int = 29; - pub const EROFS: c_int = 30; - pub const EMLINK: c_int = 31; - pub const EPIPE: c_int = 32; - pub const EDOM: c_int = 33; - pub const ERANGE: c_int = 34; - pub const EAGAIN: c_int = 35; - pub const EWOULDBLOCK: c_int = EAGAIN; - pub const EINPROGRESS: c_int = 36; - pub const EALREADY: c_int = 37; - pub const ENOTSOCK: c_int = 38; - pub const EDESTADDRREQ: c_int = 39; - pub const EMSGSIZE: c_int = 40; - pub const EPROTOTYPE: c_int = 41; - pub const ENOPROTOOPT: c_int = 42; - pub const EPROTONOSUPPORT: c_int = 43; - pub const ESOCKTNOSUPPORT: c_int = 44; - pub const ENOTSUP: c_int = 45; - pub const EPFNOSUPPORT: c_int = 46; - pub const EAFNOSUPPORT: c_int = 47; - pub const EADDRINUSE: c_int = 48; - pub const EADDRNOTAVAIL: c_int = 49; - pub const ENETDOWN: c_int = 50; - pub const ENETUNREACH: c_int = 51; - pub const ENETRESET: c_int = 52; - pub const ECONNABORTED: c_int = 53; - pub const ECONNRESET: c_int = 54; - pub const ENOBUFS: c_int = 55; - pub const EISCONN: c_int = 56; - pub const ENOTCONN: c_int = 57; - pub const ESHUTDOWN: c_int = 58; - pub const ETOOMANYREFS: c_int = 59; - pub const ETIMEDOUT: c_int = 60; - pub const ECONNREFUSED: c_int = 61; - pub const ELOOP: c_int = 62; - pub const ENAMETOOLONG: c_int = 63; - pub const EHOSTDOWN: c_int = 64; - pub const EHOSTUNREACH: c_int = 65; - pub const ENOTEMPTY: c_int = 66; - pub const EPROCLIM: c_int = 67; - pub const EUSERS: c_int = 68; - pub const EDQUOT: c_int = 69; - pub const ESTALE: c_int = 70; - pub const EREMOTE: c_int = 71; - pub const EBADRPC: c_int = 72; - pub const ERPCMISMATCH: c_int = 73; - pub const EPROGUNAVAIL: c_int = 74; - pub const EPROGMISMATCH: c_int = 75; - pub const EPROCUNAVAIL: c_int = 76; - pub const ENOLCK: c_int = 77; - pub const ENOSYS: c_int = 78; - pub const EFTYPE: c_int = 79; - pub const EAUTH: c_int = 80; - pub const ENEEDAUTH: c_int = 81; - pub const EPWROFF: c_int = 82; - pub const EDEVERR: c_int = 83; - pub const EOVERFLOW: c_int = 84; - pub const EBADEXEC: c_int = 85; - pub const EBADARCH: c_int = 86; - pub const ESHLIBVERS: c_int = 87; - pub const EBADMACHO: c_int = 88; - pub const ECANCELED: c_int = 89; - pub const EIDRM: c_int = 90; - pub const ENOMSG: c_int = 91; - pub const EILSEQ: c_int = 92; - pub const ENOATTR: c_int = 93; - pub const EBADMSG: c_int = 94; - pub const EMULTIHOP: c_int = 95; - pub const ENODATA: c_int = 96; - pub const ENOLINK: c_int = 97; - pub const ENOSR: c_int = 98; - pub const ENOSTR: c_int = 99; - pub const EPROTO: c_int = 100; - pub const ETIME: c_int = 101; - pub const EOPNOTSUPP: c_int = 102; - pub const ENOPOLICY: c_int = 103; - pub const ENOTRECOVERABLE: c_int = 104; - pub const EOWNERDEAD: c_int = 105; - pub const EQFULL: c_int = 106; - pub const ELAST: c_int = 106; - } - pub mod posix01 { - use types::os::arch::c95::{c_int, size_t}; - use types::os::common::posix01::rlim_t; - - pub const F_DUPFD: c_int = 0; - pub const F_GETFD: c_int = 1; - pub const F_SETFD: c_int = 2; - pub const F_GETFL: c_int = 3; - pub const F_SETFL: c_int = 4; - - pub const O_ACCMODE: c_int = 3; - - pub const SIGTRAP: c_int = 5; - pub const SIG_IGN: size_t = 1; - - pub const GLOB_APPEND: c_int = 0x0001; - pub const GLOB_DOOFFS: c_int = 0x0002; - pub const GLOB_ERR: c_int = 0x0004; - pub const GLOB_MARK: c_int = 0x0008; - pub const GLOB_NOCHECK: c_int = 0x0010; - pub const GLOB_NOSORT: c_int = 0x0020; - pub const GLOB_NOESCAPE: c_int = 0x2000; - - pub const GLOB_NOSPACE: c_int = -1; - pub const GLOB_ABORTED: c_int = -2; - pub const GLOB_NOMATCH: c_int = -3; - - pub const POSIX_MADV_NORMAL: c_int = 0; - pub const POSIX_MADV_RANDOM: c_int = 1; - pub const POSIX_MADV_SEQUENTIAL: c_int = 2; - pub const POSIX_MADV_WILLNEED: c_int = 3; - pub const POSIX_MADV_DONTNEED: c_int = 4; - - pub const _SC_IOV_MAX: c_int = 56; - pub const _SC_GETGR_R_SIZE_MAX: c_int = 70; - pub const _SC_GETPW_R_SIZE_MAX: c_int = 71; - pub const _SC_LOGIN_NAME_MAX: c_int = 73; - pub const _SC_MQ_PRIO_MAX: c_int = 75; - pub const _SC_THREAD_ATTR_STACKADDR: c_int = 82; - pub const _SC_THREAD_ATTR_STACKSIZE: c_int = 83; - pub const _SC_THREAD_DESTRUCTOR_ITERATIONS: c_int = 85; - pub const _SC_THREAD_KEYS_MAX: c_int = 86; - pub const _SC_THREAD_PRIO_INHERIT: c_int = 87; - pub const _SC_THREAD_PRIO_PROTECT: c_int = 88; - pub const _SC_THREAD_PRIORITY_SCHEDULING: c_int = 89; - pub const _SC_THREAD_PROCESS_SHARED: c_int = 90; - pub const _SC_THREAD_SAFE_FUNCTIONS: c_int = 91; - pub const _SC_THREAD_STACK_MIN: c_int = 93; - pub const _SC_THREAD_THREADS_MAX: c_int = 94; - pub const _SC_THREADS: c_int = 96; - pub const _SC_TTY_NAME_MAX: c_int = 101; - pub const _SC_ATEXIT_MAX: c_int = 107; - pub const _SC_XOPEN_CRYPT: c_int = 108; - pub const _SC_XOPEN_ENH_I18N: c_int = 109; - pub const _SC_XOPEN_LEGACY: c_int = 110; - pub const _SC_XOPEN_REALTIME: c_int = 111; - pub const _SC_XOPEN_REALTIME_THREADS: c_int = 112; - pub const _SC_XOPEN_SHM: c_int = 113; - pub const _SC_XOPEN_UNIX: c_int = 115; - pub const _SC_XOPEN_VERSION: c_int = 116; - pub const _SC_XOPEN_XCU_VERSION: c_int = 121; - - pub const PTHREAD_CREATE_JOINABLE: c_int = 1; - pub const PTHREAD_CREATE_DETACHED: c_int = 2; - pub const PTHREAD_STACK_MIN: size_t = 8192; - - pub const RLIMIT_CPU: c_int = 0; - pub const RLIMIT_FSIZE: c_int = 1; - pub const RLIMIT_DATA: c_int = 2; - pub const RLIMIT_STACK: c_int = 3; - pub const RLIMIT_CORE: c_int = 4; - pub const RLIMIT_AS: c_int = 5; - pub const RLIMIT_MEMLOCK: c_int = 6; - pub const RLIMIT_NPROC: c_int = 7; - pub const RLIMIT_NOFILE: c_int = 8; - pub const RLIM_NLIMITS: c_int = 9; - pub const _RLIMIT_POSIX_FLAG: c_int = 0x1000; - - pub const RLIM_INFINITY: rlim_t = 0xffff_ffff_ffff_ffff; - - pub const RUSAGE_SELF: c_int = 0; - pub const RUSAGE_CHILDREN: c_int = -1; - pub const RUSAGE_THREAD: c_int = 1; - } - pub mod posix08 { - use types::os::arch::c95::c_int; - pub const O_CLOEXEC: c_int = 0x1000000; - pub const F_DUPFD_CLOEXEC: c_int = 67; - } - pub mod bsd44 { - use types::os::arch::c95::c_int; - - pub const MADV_NORMAL: c_int = 0; - pub const MADV_RANDOM: c_int = 1; - pub const MADV_SEQUENTIAL: c_int = 2; - pub const MADV_WILLNEED: c_int = 3; - pub const MADV_DONTNEED: c_int = 4; - pub const MADV_FREE: c_int = 5; - pub const MADV_ZERO_WIRED_PAGES: c_int = 6; - pub const MADV_FREE_REUSABLE: c_int = 7; - pub const MADV_FREE_REUSE: c_int = 8; - pub const MADV_CAN_REUSE: c_int = 9; - - pub const MINCORE_INCORE: c_int = 0x1; - pub const MINCORE_REFERENCED: c_int = 0x2; - pub const MINCORE_MODIFIED: c_int = 0x4; - pub const MINCORE_REFERENCED_OTHER: c_int = 0x8; - pub const MINCORE_MODIFIED_OTHER: c_int = 0x10; - - pub const AF_UNIX: c_int = 1; - pub const AF_INET: c_int = 2; - pub const AF_INET6: c_int = 30; - pub const SOCK_STREAM: c_int = 1; - pub const SOCK_DGRAM: c_int = 2; - pub const SOCK_RAW: c_int = 3; - pub const IPPROTO_TCP: c_int = 6; - pub const IPPROTO_IP: c_int = 0; - pub const IPPROTO_IPV6: c_int = 41; - pub const IP_MULTICAST_TTL: c_int = 10; - pub const IP_MULTICAST_LOOP: c_int = 11; - pub const IP_TTL: c_int = 4; - pub const IP_HDRINCL: c_int = 2; - pub const IP_ADD_MEMBERSHIP: c_int = 12; - pub const IP_DROP_MEMBERSHIP: c_int = 13; - pub const IPV6_ADD_MEMBERSHIP: c_int = 12; - pub const IPV6_DROP_MEMBERSHIP: c_int = 13; - - pub const TCP_NODELAY: c_int = 0x01; - pub const TCP_KEEPALIVE: c_int = 0x10; - pub const SOL_SOCKET: c_int = 0xffff; - - pub const SO_DEBUG: c_int = 0x01; - pub const SO_ACCEPTCONN: c_int = 0x0002; - pub const SO_REUSEADDR: c_int = 0x0004; - pub const SO_KEEPALIVE: c_int = 0x0008; - pub const SO_DONTROUTE: c_int = 0x0010; - pub const SO_BROADCAST: c_int = 0x0020; - pub const SO_USELOOPBACK: c_int = 0x0040; - pub const SO_LINGER: c_int = 0x0080; - pub const SO_OOBINLINE: c_int = 0x0100; - pub const SO_REUSEPORT: c_int = 0x0200; - pub const SO_SNDBUF: c_int = 0x1001; - pub const SO_RCVBUF: c_int = 0x1002; - pub const SO_SNDLOWAT: c_int = 0x1003; - pub const SO_RCVLOWAT: c_int = 0x1004; - pub const SO_SNDTIMEO: c_int = 0x1005; - pub const SO_RCVTIMEO: c_int = 0x1006; - pub const SO_ERROR: c_int = 0x1007; - pub const SO_TYPE: c_int = 0x1008; - - pub const IFF_LOOPBACK: c_int = 0x8; - - pub const SHUT_RD: c_int = 0; - pub const SHUT_WR: c_int = 1; - pub const SHUT_RDWR: c_int = 2; - - pub const LOCK_SH: c_int = 1; - pub const LOCK_EX: c_int = 2; - pub const LOCK_NB: c_int = 4; - pub const LOCK_UN: c_int = 8; - } - pub mod extra { - use types::os::arch::c95::c_int; - - pub const O_DSYNC: c_int = 4194304; - pub const O_SYNC: c_int = 128; - pub const O_NONBLOCK: c_int = 4; - pub const F_GETPATH: c_int = 50; - pub const F_FULLFSYNC: c_int = 51; - - pub const MAP_COPY: c_int = 0x0002; - pub const MAP_RENAME: c_int = 0x0020; - pub const MAP_NORESERVE: c_int = 0x0040; - pub const MAP_NOEXTEND: c_int = 0x0100; - pub const MAP_HASSEMAPHORE: c_int = 0x0200; - pub const MAP_NOCACHE: c_int = 0x0400; - pub const MAP_JIT: c_int = 0x0800; - pub const MAP_STACK: c_int = 0; - - pub const IPPROTO_RAW: c_int = 255; - - pub const SO_NREAD: c_int = 0x1020; - pub const SO_NKE: c_int = 0x1021; - pub const SO_NOSIGPIPE: c_int = 0x1022; - pub const SO_NOADDRERR: c_int = 0x1023; - pub const SO_NWRITE: c_int = 0x1024; - pub const SO_DONTTRUNC: c_int = 0x2000; - pub const SO_WANTMORE: c_int = 0x4000; - pub const SO_WANTOOBFLAG: c_int = 0x8000; - - pub const PATH_MAX: c_int = 1024; - } - pub mod sysconf { - use types::os::arch::c95::c_int; - - pub const _SC_ARG_MAX: c_int = 1; - pub const _SC_CHILD_MAX: c_int = 2; - pub const _SC_CLK_TCK: c_int = 3; - pub const _SC_NGROUPS_MAX: c_int = 4; - pub const _SC_OPEN_MAX: c_int = 5; - pub const _SC_JOB_CONTROL: c_int = 6; - pub const _SC_SAVED_IDS: c_int = 7; - pub const _SC_VERSION: c_int = 8; - pub const _SC_BC_BASE_MAX: c_int = 9; - pub const _SC_BC_DIM_MAX: c_int = 10; - pub const _SC_BC_SCALE_MAX: c_int = 11; - pub const _SC_BC_STRING_MAX: c_int = 12; - pub const _SC_COLL_WEIGHTS_MAX: c_int = 13; - pub const _SC_EXPR_NEST_MAX: c_int = 14; - pub const _SC_LINE_MAX: c_int = 15; - pub const _SC_RE_DUP_MAX: c_int = 16; - pub const _SC_2_VERSION: c_int = 17; - pub const _SC_2_C_BIND: c_int = 18; - pub const _SC_2_C_DEV: c_int = 19; - pub const _SC_2_CHAR_TERM: c_int = 20; - pub const _SC_2_FORT_DEV: c_int = 21; - pub const _SC_2_FORT_RUN: c_int = 22; - pub const _SC_2_LOCALEDEF: c_int = 23; - pub const _SC_2_SW_DEV: c_int = 24; - pub const _SC_2_UPE: c_int = 25; - pub const _SC_STREAM_MAX: c_int = 26; - pub const _SC_TZNAME_MAX: c_int = 27; - pub const _SC_ASYNCHRONOUS_IO: c_int = 28; - pub const _SC_PAGESIZE: c_int = 29; - pub const _SC_MEMLOCK: c_int = 30; - pub const _SC_MEMLOCK_RANGE: c_int = 31; - pub const _SC_MEMORY_PROTECTION: c_int = 32; - pub const _SC_MESSAGE_PASSING: c_int = 33; - pub const _SC_PRIORITIZED_IO: c_int = 34; - pub const _SC_PRIORITY_SCHEDULING: c_int = 35; - pub const _SC_REALTIME_SIGNALS: c_int = 36; - pub const _SC_SEMAPHORES: c_int = 37; - pub const _SC_FSYNC: c_int = 38; - pub const _SC_SHARED_MEMORY_OBJECTS: c_int = 39; - pub const _SC_SYNCHRONIZED_IO: c_int = 40; - pub const _SC_TIMERS: c_int = 41; - pub const _SC_AIO_LISTIO_MAX: c_int = 42; - pub const _SC_AIO_MAX: c_int = 43; - pub const _SC_AIO_PRIO_DELTA_MAX: c_int = 44; - pub const _SC_DELAYTIMER_MAX: c_int = 45; - pub const _SC_MQ_OPEN_MAX: c_int = 46; - pub const _SC_MAPPED_FILES: c_int = 47; - pub const _SC_RTSIG_MAX: c_int = 48; - pub const _SC_SEM_NSEMS_MAX: c_int = 49; - pub const _SC_SEM_VALUE_MAX: c_int = 50; - pub const _SC_SIGQUEUE_MAX: c_int = 51; - pub const _SC_TIMER_MAX: c_int = 52; - pub const _SC_NPROCESSORS_CONF: c_int = 57; - pub const _SC_NPROCESSORS_ONLN: c_int = 58; - pub const _SC_2_PBS: c_int = 59; - pub const _SC_2_PBS_ACCOUNTING: c_int = 60; - pub const _SC_2_PBS_CHECKPOINT: c_int = 61; - pub const _SC_2_PBS_LOCATE: c_int = 62; - pub const _SC_2_PBS_MESSAGE: c_int = 63; - pub const _SC_2_PBS_TRACK: c_int = 64; - pub const _SC_ADVISORY_INFO: c_int = 65; - pub const _SC_BARRIERS: c_int = 66; - pub const _SC_CLOCK_SELECTION: c_int = 67; - pub const _SC_CPUTIME: c_int = 68; - pub const _SC_FILE_LOCKING: c_int = 69; - pub const _SC_HOST_NAME_MAX: c_int = 72; - pub const _SC_MONOTONIC_CLOCK: c_int = 74; - pub const _SC_READER_WRITER_LOCKS: c_int = 76; - pub const _SC_REGEXP: c_int = 77; - pub const _SC_SHELL: c_int = 78; - pub const _SC_SPAWN: c_int = 79; - pub const _SC_SPIN_LOCKS: c_int = 80; - pub const _SC_SPORADIC_SERVER: c_int = 81; - pub const _SC_THREAD_CPUTIME: c_int = 84; - pub const _SC_THREAD_SPORADIC_SERVER: c_int = 92; - pub const _SC_TIMEOUTS: c_int = 95; - pub const _SC_TRACE: c_int = 97; - pub const _SC_TRACE_EVENT_FILTER: c_int = 98; - pub const _SC_TRACE_INHERIT: c_int = 99; - pub const _SC_TRACE_LOG: c_int = 100; - pub const _SC_TYPED_MEMORY_OBJECTS: c_int = 102; - pub const _SC_V6_ILP32_OFF32: c_int = 103; - pub const _SC_V6_ILP32_OFFBIG: c_int = 104; - pub const _SC_V6_LP64_OFF64: c_int = 105; - pub const _SC_V6_LPBIG_OFFBIG: c_int = 106; - pub const _SC_IPV6: c_int = 118; - pub const _SC_RAW_SOCKETS: c_int = 119; - pub const _SC_SYMLOOP_MAX: c_int = 120; - pub const _SC_PAGE_SIZE: c_int = _SC_PAGESIZE; - pub const _SC_XOPEN_STREAMS: c_int = 114; - pub const _SC_XBS5_ILP32_OFF32: c_int = 122; - pub const _SC_XBS5_ILP32_OFFBIG: c_int = 123; - pub const _SC_XBS5_LP64_OFF64: c_int = 124; - pub const _SC_XBS5_LPBIG_OFFBIG: c_int = 125; - pub const _SC_SS_REPL_MAX: c_int = 126; - pub const _SC_TRACE_EVENT_NAME_MAX: c_int = 127; - pub const _SC_TRACE_NAME_MAX: c_int = 128; - pub const _SC_TRACE_SYS_MAX: c_int = 129; - pub const _SC_TRACE_USER_EVENT_MAX: c_int = 130; - pub const _SC_PASS_MAX: c_int = 131; - - pub const _PC_NAME_MAX: c_int = 4; - pub const _PC_PATH_MAX: c_int = 5; - } - } -} - - -pub mod funcs { - // Thankfully most of c95 is universally available and does not vary by OS - // or anything. The same is not true of POSIX. - - pub mod c95 { - pub mod ctype { - use types::os::arch::c95::{c_char, c_int}; - - extern { - pub fn isalnum(c: c_int) -> c_int; - pub fn isalpha(c: c_int) -> c_int; - pub fn iscntrl(c: c_int) -> c_int; - pub fn isdigit(c: c_int) -> c_int; - pub fn isgraph(c: c_int) -> c_int; - pub fn islower(c: c_int) -> c_int; - pub fn isprint(c: c_int) -> c_int; - pub fn ispunct(c: c_int) -> c_int; - pub fn isspace(c: c_int) -> c_int; - pub fn isupper(c: c_int) -> c_int; - pub fn isxdigit(c: c_int) -> c_int; - pub fn tolower(c: c_char) -> c_char; - pub fn toupper(c: c_char) -> c_char; - } - } - - pub mod stdio { - use types::common::c95::{FILE, c_void, fpos_t}; - use types::os::arch::c95::{c_char, c_int, c_long, size_t}; - - extern { - pub fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE; - pub fn freopen(filename: *const c_char, - mode: *const c_char, - file: *mut FILE) - -> *mut FILE; - pub fn fflush(file: *mut FILE) -> c_int; - pub fn fclose(file: *mut FILE) -> c_int; - pub fn remove(filename: *const c_char) -> c_int; - pub fn rename(oldname: *const c_char, newname: *const c_char) -> c_int; - pub fn tmpfile() -> *mut FILE; - pub fn setvbuf(stream: *mut FILE, - buffer: *mut c_char, - mode: c_int, - size: size_t) - -> c_int; - pub fn setbuf(stream: *mut FILE, buf: *mut c_char); - // Omitted: printf and scanf variants. - pub fn fgetc(stream: *mut FILE) -> c_int; - pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) -> *mut c_char; - pub fn fputc(c: c_int, stream: *mut FILE) -> c_int; - pub fn fputs(s: *const c_char, stream: *mut FILE) -> c_int; - // Omitted: getc, getchar (might be macros). - - // Omitted: gets, so ridiculously unsafe that it should not - // survive. - - // Omitted: putc, putchar (might be macros). - pub fn puts(s: *const c_char) -> c_int; - pub fn ungetc(c: c_int, stream: *mut FILE) -> c_int; - pub fn fread(ptr: *mut c_void, - size: size_t, - nobj: size_t, - stream: *mut FILE) - -> size_t; - pub fn fwrite(ptr: *const c_void, - size: size_t, - nobj: size_t, - stream: *mut FILE) - -> size_t; - pub fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) -> c_int; - pub fn ftell(stream: *mut FILE) -> c_long; - pub fn rewind(stream: *mut FILE); - pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int; - pub fn fsetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int; - pub fn feof(stream: *mut FILE) -> c_int; - pub fn ferror(stream: *mut FILE) -> c_int; - pub fn perror(s: *const c_char); - } - } - - pub mod stdlib { - use types::common::c95::c_void; - use types::os::arch::c95::{c_char, c_double, c_int}; - use types::os::arch::c95::{c_long, c_uint, c_ulong}; - use types::os::arch::c95::size_t; - - extern { - pub fn abs(i: c_int) -> c_int; - pub fn labs(i: c_long) -> c_long; - // Omitted: div, ldiv (return pub type incomplete). - pub fn atof(s: *const c_char) -> c_double; - pub fn atoi(s: *const c_char) -> c_int; - pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double; - pub fn strtol(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_long; - pub fn strtoul(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_ulong; - pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void; - pub fn malloc(size: size_t) -> *mut c_void; - pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void; - pub fn free(p: *mut c_void); - - /// Exits the running program in a possibly dangerous manner. - /// - /// # Safety - /// - /// While this forces your program to exit, it does so in a way that has - /// consequences. This will skip all unwinding code, which means that anything - /// relying on unwinding for cleanup (such as flushing and closing a buffer to a - /// file) may act in an unexpected way. - /// - /// # Examples - /// - /// ```no_run,ignore - /// extern crate libc; - /// - /// fn main() { - /// unsafe { - /// libc::exit(1); - /// } - /// } - /// ``` - pub fn exit(status: c_int) -> !; - pub fn _exit(status: c_int) -> !; - pub fn atexit(cb: extern "C" fn()) -> c_int; - pub fn system(s: *const c_char) -> c_int; - pub fn getenv(s: *const c_char) -> *mut c_char; - // Omitted: bsearch, qsort - pub fn rand() -> c_int; - pub fn srand(seed: c_uint); - } - } - - pub mod string { - use types::common::c95::c_void; - use types::os::arch::c95::{c_char, c_int, size_t}; - use types::os::arch::c95::wchar_t; - - extern { - pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char; - pub fn strncpy(dst: *mut c_char, src: *const c_char, n: size_t) -> *mut c_char; - pub fn strcat(s: *mut c_char, ct: *const c_char) -> *mut c_char; - pub fn strncat(s: *mut c_char, ct: *const c_char, n: size_t) -> *mut c_char; - pub fn strcmp(cs: *const c_char, ct: *const c_char) -> c_int; - pub fn strncmp(cs: *const c_char, ct: *const c_char, n: size_t) -> c_int; - pub fn strcoll(cs: *const c_char, ct: *const c_char) -> c_int; - pub fn strchr(cs: *const c_char, c: c_int) -> *mut c_char; - pub fn strrchr(cs: *const c_char, c: c_int) -> *mut c_char; - pub fn strspn(cs: *const c_char, ct: *const c_char) -> size_t; - pub fn strcspn(cs: *const c_char, ct: *const c_char) -> size_t; - pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char; - pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char; - pub fn strlen(cs: *const c_char) -> size_t; - pub fn strerror(n: c_int) -> *mut c_char; - pub fn strtok(s: *mut c_char, t: *const c_char) -> *mut c_char; - pub fn strxfrm(s: *mut c_char, ct: *const c_char, n: size_t) -> size_t; - pub fn wcslen(buf: *const wchar_t) -> size_t; - - // Omitted: memcpy, memmove, memset (provided by LLVM) - - // These are fine to execute on the Rust stack. They must be, - // in fact, because LLVM generates calls to them! - pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int; - pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void; - } - } - } - - // Microsoft helpfully underscore-qualifies all of its POSIX-like symbols - // to make sure you don't use them accidentally. It also randomly deviates - // from the exact signatures you might otherwise expect, and omits much, - // so be careful when trying to write portable code; it won't always work - // with the same POSIX functions and types as other platforms. - - #[cfg(target_os = "windows")] - pub mod posix88 { - pub mod stat_ { - use types::os::common::posix01::{stat, utimbuf}; - use types::os::arch::c95::{c_int, c_char, wchar_t}; - - extern { - #[link_name = "_chmod"] - pub fn chmod(path: *const c_char, mode: c_int) -> c_int; - #[link_name = "_wchmod"] - pub fn wchmod(path: *const wchar_t, mode: c_int) -> c_int; - #[link_name = "_mkdir"] - pub fn mkdir(path: *const c_char) -> c_int; - #[link_name = "_wrmdir"] - pub fn wrmdir(path: *const wchar_t) -> c_int; - #[link_name = "_fstat64"] - pub fn fstat(fildes: c_int, buf: *mut stat) -> c_int; - #[link_name = "_stat64"] - pub fn stat(path: *const c_char, buf: *mut stat) -> c_int; - #[link_name = "_wstat64"] - pub fn wstat(path: *const wchar_t, buf: *mut stat) -> c_int; - #[link_name = "_wutime64"] - pub fn wutime(file: *const wchar_t, buf: *mut utimbuf) -> c_int; - } - } - - pub mod stdio { - use types::common::c95::FILE; - use types::os::arch::c95::{c_int, c_char}; - - extern { - #[link_name = "_popen"] - pub fn popen(command: *const c_char, mode: *const c_char) -> *mut FILE; - #[link_name = "_pclose"] - pub fn pclose(stream: *mut FILE) -> c_int; - #[link_name = "_fdopen"] - pub fn fdopen(fd: c_int, mode: *const c_char) -> *mut FILE; - #[link_name = "_fileno"] - pub fn fileno(stream: *mut FILE) -> c_int; - } - } - - pub mod fcntl { - use types::os::arch::c95::{c_int, c_char, wchar_t}; - extern { - #[link_name = "_open"] - pub fn open(path: *const c_char, oflag: c_int, mode: c_int) -> c_int; - #[link_name = "_wopen"] - pub fn wopen(path: *const wchar_t, oflag: c_int, mode: c_int) -> c_int; - #[link_name = "_creat"] - pub fn creat(path: *const c_char, mode: c_int) -> c_int; - } - } - - pub mod dirent { - // Not supplied at all. - } - - pub mod unistd { - use types::common::c95::c_void; - use types::os::arch::c95::{c_int, c_uint, c_char, c_long, size_t}; - use types::os::arch::c99::intptr_t; - - extern { - #[link_name = "_access"] - pub fn access(path: *const c_char, amode: c_int) -> c_int; - #[link_name = "_chdir"] - pub fn chdir(dir: *const c_char) -> c_int; - #[link_name = "_close"] - pub fn close(fd: c_int) -> c_int; - #[link_name = "_dup"] - pub fn dup(fd: c_int) -> c_int; - #[link_name = "_dup2"] - pub fn dup2(src: c_int, dst: c_int) -> c_int; - #[link_name = "_execv"] - pub fn execv(prog: *const c_char, argv: *const *const c_char) -> intptr_t; - #[link_name = "_execve"] - pub fn execve(prog: *const c_char, - argv: *const *const c_char, - envp: *const *const c_char) - -> c_int; - #[link_name = "_execvp"] - pub fn execvp(c: *const c_char, argv: *const *const c_char) -> c_int; - #[link_name = "_execvpe"] - pub fn execvpe(c: *const c_char, - argv: *const *const c_char, - envp: *const *const c_char) - -> c_int; - #[link_name = "_getcwd"] - pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char; - #[link_name = "_getpid"] - pub fn getpid() -> c_int; - #[link_name = "_isatty"] - pub fn isatty(fd: c_int) -> c_int; - #[link_name = "_lseek"] - pub fn lseek(fd: c_int, offset: c_long, origin: c_int) -> c_long; - #[link_name = "_pipe"] - pub fn pipe(fds: *mut c_int, psize: c_uint, textmode: c_int) -> c_int; - #[link_name = "_read"] - pub fn read(fd: c_int, buf: *mut c_void, count: c_uint) -> c_int; - #[link_name = "_rmdir"] - pub fn rmdir(path: *const c_char) -> c_int; - #[link_name = "_unlink"] - pub fn unlink(c: *const c_char) -> c_int; - #[link_name = "_write"] - pub fn write(fd: c_int, buf: *const c_void, count: c_uint) -> c_int; - } - } - - pub mod mman { - } - } - - #[cfg(any(target_os = "linux", - target_os = "android", - target_os = "macos", - target_os = "ios", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "bitrig", - target_os = "netbsd", - target_os = "openbsd", - target_os = "nacl"))] - pub mod posix88 { - pub mod stat_ { - use types::os::arch::c95::{c_char, c_int}; - use types::os::arch::posix01::stat; - use types::os::arch::posix88::mode_t; - - extern { - pub fn chmod(path: *const c_char, mode: mode_t) -> c_int; - pub fn fchmod(fd: c_int, mode: mode_t) -> c_int; - - #[cfg_attr(target_os = "macos", link_name = "fstat64")] - #[cfg_attr(target_os = "netbsd", link_name = "__fstat50")] - pub fn fstat(fildes: c_int, buf: *mut stat) -> c_int; - - pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int; - #[cfg(not(target_os = "nacl"))] - pub fn mkfifo(path: *const c_char, mode: mode_t) -> c_int; - - #[cfg_attr(target_os = "macos", link_name = "stat64")] - #[cfg_attr(target_os = "netbsd", link_name = "__stat50")] - pub fn stat(path: *const c_char, buf: *mut stat) -> c_int; - } - } - - pub mod stdio { - use types::common::c95::FILE; - use types::os::arch::c95::{c_char, c_int}; - - extern { - pub fn popen(command: *const c_char, mode: *const c_char) -> *mut FILE; - pub fn pclose(stream: *mut FILE) -> c_int; - pub fn fdopen(fd: c_int, mode: *const c_char) -> *mut FILE; - pub fn fileno(stream: *mut FILE) -> c_int; - } - } - - pub mod fcntl { - use types::os::arch::c95::{c_char, c_int}; - use types::os::arch::posix88::mode_t; - - mod open_shim { - extern { - #[cfg(any(target_os = "macos", - target_os = "ios"))] - pub fn open(path: *const ::c_char, oflag: ::c_int, ...) -> ::c_int; - - #[cfg(not(any(target_os = "macos", - target_os = "ios")))] - pub fn open(path: *const ::c_char, oflag: ::c_int, mode: ::mode_t) -> ::c_int; - } - } - - #[cfg(any(target_os = "macos", - target_os = "ios"))] - #[inline] - pub unsafe extern "C" fn open(path: *const c_char, - oflag: c_int, - mode: mode_t) - -> c_int { - use types::os::arch::c95::c_uint; - open_shim::open(path, oflag, mode as c_uint) - } - - #[cfg(not(any(target_os = "macos", - target_os = "ios")))] - #[inline] - pub unsafe extern "C" fn open(path: *const c_char, - oflag: c_int, - mode: mode_t) - -> c_int { - open_shim::open(path, oflag, mode) - } - - extern { - pub fn creat(path: *const c_char, mode: mode_t) -> c_int; - pub fn fcntl(fd: c_int, cmd: c_int, ...) -> c_int; - } - } - - pub mod dirent { - use types::common::posix88::{DIR, dirent_t}; - use types::os::arch::c95::{c_char, c_int, c_long}; - - // NB: On OS X opendir and readdir have two versions, - // one for 32-bit kernelspace and one for 64. - // We should be linking to the 64-bit ones, called - // opendir$INODE64, etc. but for some reason rustc - // doesn't link it correctly on i686, so we're going - // through a C function that mysteriously does work. - - extern { - #[link_name="rust_opendir"] - pub fn opendir(dirname: *const c_char) -> *mut DIR; - #[link_name="rust_readdir_r"] - pub fn readdir_r(dirp: *mut DIR, - entry: *mut dirent_t, - result: *mut *mut dirent_t) - -> c_int; - } - - extern { - pub fn closedir(dirp: *mut DIR) -> c_int; - pub fn rewinddir(dirp: *mut DIR); - pub fn seekdir(dirp: *mut DIR, loc: c_long); - pub fn telldir(dirp: *mut DIR) -> c_long; - } - } - - pub mod unistd { - use types::common::c95::c_void; - use types::os::arch::c95::{c_char, c_int, c_long, c_uint}; - use types::os::arch::c95::size_t; - use types::os::common::posix01::timespec; - use types::os::arch::posix01::utimbuf; - use types::os::arch::posix88::{gid_t, off_t, pid_t}; - use types::os::arch::posix88::{ssize_t, uid_t}; - - #[cfg(not(target_os = "nacl"))] - extern { - pub fn access(path: *const c_char, amode: c_int) -> c_int; - pub fn alarm(seconds: c_uint) -> c_uint; - pub fn chdir(dir: *const c_char) -> c_int; - pub fn chown(path: *const c_char, uid: uid_t, gid: gid_t) -> c_int; - pub fn close(fd: c_int) -> c_int; - pub fn dup(fd: c_int) -> c_int; - pub fn dup2(src: c_int, dst: c_int) -> c_int; - pub fn execv(prog: *const c_char, argv: *const *const c_char) -> c_int; - pub fn execve(prog: *const c_char, - argv: *const *const c_char, - envp: *const *const c_char) - -> c_int; - pub fn execvp(c: *const c_char, argv: *const *const c_char) -> c_int; - pub fn fork() -> pid_t; - pub fn fpathconf(filedes: c_int, name: c_int) -> c_long; - pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char; - pub fn getegid() -> gid_t; - pub fn geteuid() -> uid_t; - pub fn getgid() -> gid_t; - pub fn getgroups(ngroups_max: c_int, groups: *mut gid_t) -> c_int; - pub fn getlogin() -> *mut c_char; - // GNU getopt(3) modifies its arguments despite the - // char * const [] prototype; see the manpage. - pub fn getopt(argc: c_int, argv: *mut *mut c_char, optstr: *const c_char) -> c_int; - pub fn getpgrp() -> pid_t; - pub fn getpid() -> pid_t; - pub fn getppid() -> pid_t; - pub fn getuid() -> uid_t; - pub fn getsid(pid: pid_t) -> pid_t; - pub fn isatty(fd: c_int) -> c_int; - pub fn link(src: *const c_char, dst: *const c_char) -> c_int; - pub fn lseek(fd: c_int, offset: off_t, whence: c_int) -> off_t; - pub fn pathconf(path: *mut c_char, name: c_int) -> c_long; - pub fn pause() -> c_int; - pub fn pipe(fds: *mut c_int) -> c_int; - pub fn read(fd: c_int, buf: *mut c_void, count: size_t) -> ssize_t; - pub fn rmdir(path: *const c_char) -> c_int; - pub fn setgid(gid: gid_t) -> c_int; - pub fn setpgid(pid: pid_t, pgid: pid_t) -> c_int; - pub fn setsid() -> pid_t; - pub fn setuid(uid: uid_t) -> c_int; - pub fn sleep(secs: c_uint) -> c_uint; - pub fn usleep(secs: c_uint) -> c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__nanosleep50")] - pub fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int; - pub fn sysconf(name: c_int) -> c_long; - pub fn tcgetpgrp(fd: c_int) -> pid_t; - pub fn ttyname(fd: c_int) -> *mut c_char; - pub fn unlink(c: *const c_char) -> c_int; - pub fn wait(status: *const c_int) -> pid_t; - pub fn waitpid(pid: pid_t, status: *const c_int, options: c_int) -> pid_t; - pub fn write(fd: c_int, buf: *const c_void, count: size_t) -> ssize_t; - pub fn pread(fd: c_int, buf: *mut c_void, count: size_t, offset: off_t) -> ssize_t; - pub fn pwrite(fd: c_int, - buf: *const c_void, - count: size_t, - offset: off_t) - -> ssize_t; - #[cfg_attr(target_os = "netbsd", link_name = "__utime50")] - pub fn utime(file: *const c_char, buf: *const utimbuf) -> c_int; - } - #[cfg(target_os = "nacl")] - extern { - pub fn access(path: *const c_char, amode: c_int) -> c_int; - pub fn chdir(dir: *const c_char) -> c_int; - pub fn chown(path: *const c_char, uid: uid_t, gid: gid_t) -> c_int; - pub fn close(fd: c_int) -> c_int; - pub fn dup(fd: c_int) -> c_int; - pub fn dup2(src: c_int, dst: c_int) -> c_int; - pub fn execv(prog: *const c_char, argv: *const *const c_char) -> c_int; - pub fn execve(prog: *const c_char, - argv: *const *const c_char, - envp: *const *const c_char) - -> c_int; - pub fn execvp(c: *const c_char, argv: *const *const c_char) -> c_int; - pub fn fork() -> pid_t; - pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char; - pub fn getegid() -> gid_t; - pub fn geteuid() -> uid_t; - pub fn getgid() -> gid_t; - pub fn getlogin() -> *mut c_char; - pub fn getopt(argc: c_int, - argv: *const *const c_char, - optstr: *const c_char) - -> c_int; - pub fn getuid() -> uid_t; - pub fn getsid(pid: pid_t) -> pid_t; - pub fn isatty(fd: c_int) -> c_int; - pub fn link(src: *const c_char, dst: *const c_char) -> c_int; - pub fn lseek(fd: c_int, offset: off_t, whence: c_int) -> off_t; - pub fn pipe(fds: *mut c_int) -> c_int; - pub fn read(fd: c_int, buf: *mut c_void, count: size_t) -> ssize_t; - pub fn rmdir(path: *const c_char) -> c_int; - pub fn setgid(gid: gid_t) -> c_int; - pub fn setuid(uid: uid_t) -> c_int; - pub fn sleep(secs: c_uint) -> c_uint; - pub fn usleep(secs: c_uint) -> c_int; - pub fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int; - pub fn sysconf(name: c_int) -> c_long; - pub fn ttyname(fd: c_int) -> *mut c_char; - pub fn unlink(c: *const c_char) -> c_int; - pub fn wait(status: *const c_int) -> pid_t; - pub fn waitpid(pid: pid_t, status: *const c_int, options: c_int) -> pid_t; - pub fn write(fd: c_int, buf: *const c_void, count: size_t) -> ssize_t; - pub fn pread(fd: c_int, buf: *mut c_void, count: size_t, offset: off_t) -> ssize_t; - pub fn pwrite(fd: c_int, - buf: *const c_void, - count: size_t, - offset: off_t) - -> ssize_t; - pub fn utime(file: *const c_char, buf: *const utimbuf) -> c_int; - } - } - - pub mod signal { - use types::os::arch::c95::c_int; - use types::os::arch::posix88::pid_t; - - extern { - pub fn kill(pid: pid_t, sig: c_int) -> c_int; - } - } - - pub mod mman { - use types::common::c95::c_void; - use types::os::arch::c95::{size_t, c_int, c_char}; - use types::os::arch::posix88::{mode_t, off_t}; - - #[cfg(not(target_os = "nacl"))] - extern { - pub fn mlock(addr: *const c_void, len: size_t) -> c_int; - pub fn munlock(addr: *const c_void, len: size_t) -> c_int; - pub fn mlockall(flags: c_int) -> c_int; - pub fn munlockall() -> c_int; - - pub fn mprotect(addr: *mut c_void, len: size_t, prot: c_int) -> c_int; - - #[cfg_attr(target_os = "netbsd", link_name = "__msync13")] - pub fn msync(addr: *mut c_void, len: size_t, flags: c_int) -> c_int; - - pub fn shm_open(name: *const c_char, oflag: c_int, mode: mode_t) -> c_int; - pub fn shm_unlink(name: *const c_char) -> c_int; - } - - extern { - pub fn mmap(addr: *mut c_void, - len: size_t, - prot: c_int, - flags: c_int, - fd: c_int, - offset: off_t) - -> *mut c_void; - pub fn munmap(addr: *mut c_void, len: size_t) -> c_int; - - } - } - - pub mod net { - use types::os::arch::c95::{c_char, c_uint}; - - extern { - pub fn if_nametoindex(ifname: *const c_char) -> c_uint; - } - } - - } - - #[cfg(any(target_os = "linux", - target_os = "android", - target_os = "macos", - target_os = "ios", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "bitrig", - target_os = "netbsd", - target_os = "openbsd", - target_os = "nacl"))] - pub mod posix01 { - pub mod stat_ { - use types::os::arch::c95::{c_char, c_int}; - use types::os::arch::posix01::stat; - - extern { - #[cfg_attr(target_os = "macos", link_name = "lstat64")] - #[cfg_attr(target_os = "netbsd", link_name = "__lstat50")] - pub fn lstat(path: *const c_char, buf: *mut stat) -> c_int; - } - } - - pub mod unistd { - use types::os::arch::c95::{c_char, c_int, size_t}; - use types::os::arch::posix88::{ssize_t, off_t}; - - extern { - pub fn readlink(path: *const c_char, buf: *mut c_char, bufsz: size_t) -> ssize_t; - - pub fn fsync(fd: c_int) -> c_int; - - #[cfg(any(target_os = "linux", target_os = "android"))] - pub fn fdatasync(fd: c_int) -> c_int; - - pub fn setenv(name: *const c_char, val: *const c_char, overwrite: c_int) -> c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__unsetenv13")] - pub fn unsetenv(name: *const c_char) -> c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__putenv50")] - pub fn putenv(string: *mut c_char) -> c_int; - - pub fn symlink(path1: *const c_char, path2: *const c_char) -> c_int; - - pub fn ftruncate(fd: c_int, length: off_t) -> c_int; - } - } - - pub mod signal { - use types::os::arch::c95::c_int; - use types::os::common::posix01::sighandler_t; - - #[cfg(not(all(target_os = "android", any(target_arch = "arm", - target_arch = "x86"))))] - extern { - pub fn signal(signum: c_int, handler: sighandler_t) -> sighandler_t; - } - - #[cfg(all(target_os = "android", any(target_arch = "arm", - target_arch = "x86")))] - extern { - #[link_name = "bsd_signal"] - pub fn signal(signum: c_int, handler: sighandler_t) -> sighandler_t; - } - } - - pub mod glob { - use types::os::arch::c95::{c_char, c_int}; - use types::os::common::posix01::glob_t; - - extern { - #[cfg_attr(target_os = "netbsd", link_name = "__glob30")] - pub fn glob(pattern: *const c_char, - flags: c_int, - errfunc: ::core::option::Option c_int>, - pglob: *mut glob_t); - #[cfg_attr(target_os = "netbsd", link_name = "__globfree30")] - pub fn globfree(pglob: *mut glob_t); - } - } - - pub mod mman { - use types::common::c95::c_void; - use types::os::arch::c95::{c_int, size_t}; - - #[cfg(not(target_os = "nacl"))] - extern { - pub fn posix_madvise(addr: *mut c_void, len: size_t, advice: c_int) -> c_int; - } - } - - pub mod resource { - use types::os::arch::c95::c_int; - use types::os::common::posix01::rlimit; - use types::os::common::bsd43::rusage; - extern { - pub fn getrlimit(resource: c_int, rlim: *mut rlimit) -> c_int; - pub fn setrlimit(resource: c_int, rlim: *const rlimit) -> c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__getrusage50")] - pub fn getrusage(resource: c_int, usage: *mut rusage) -> c_int; - } - } - } - - #[cfg(target_os = "windows")] - pub mod posix01 { - pub mod stat_ { - } - - pub mod unistd { - } - - pub mod glob { - } - - pub mod mman { - } - - pub mod net { - } - } - - - #[cfg(any(target_os = "android", - target_os = "bitrig", - target_os = "dragonfly", - target_os = "ios", - target_os = "freebsd", - target_os = "linux", - target_os = "macos", - target_os = "nacl", - target_os = "netbsd", - target_os = "openbsd", - target_os = "windows"))] - pub mod posix08 { - pub mod unistd { - } - } - - #[cfg(not(windows))] - pub mod bsd43 { - use types::common::c95::c_void; - use types::os::common::bsd44::{socklen_t, sockaddr, ifaddrs}; - use types::os::arch::c95::{c_int, size_t}; - use types::os::arch::posix88::ssize_t; - - extern "system" { - #[cfg_attr(target_os = "netbsd", link_name = "__socket30")] - pub fn socket(domain: c_int, ty: c_int, protocol: c_int) -> c_int; - - pub fn connect(socket: c_int, address: *const sockaddr, len: socklen_t) -> c_int; - pub fn bind(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int; - pub fn listen(socket: c_int, backlog: c_int) -> c_int; - pub fn accept(socket: c_int, - address: *mut sockaddr, - address_len: *mut socklen_t) - -> c_int; - pub fn getpeername(socket: c_int, - address: *mut sockaddr, - address_len: *mut socklen_t) - -> c_int; - pub fn getsockname(socket: c_int, - address: *mut sockaddr, - address_len: *mut socklen_t) - -> c_int; - pub fn setsockopt(socket: c_int, - level: c_int, - name: c_int, - value: *const c_void, - option_len: socklen_t) - -> c_int; - pub fn recv(socket: c_int, buf: *mut c_void, len: size_t, flags: c_int) -> ssize_t; - pub fn send(socket: c_int, buf: *const c_void, len: size_t, flags: c_int) -> ssize_t; - pub fn recvfrom(socket: c_int, - buf: *mut c_void, - len: size_t, - flags: c_int, - addr: *mut sockaddr, - addrlen: *mut socklen_t) - -> ssize_t; - pub fn sendto(socket: c_int, - buf: *const c_void, - len: size_t, - flags: c_int, - addr: *const sockaddr, - addrlen: socklen_t) - -> ssize_t; - pub fn getifaddrs(ifap: *mut *mut ifaddrs) -> c_int; - pub fn freeifaddrs(ifa: *mut ifaddrs); - pub fn shutdown(socket: c_int, how: c_int) -> c_int; - } - } - - #[cfg(windows)] - pub mod bsd43 { - use types::common::c95::c_void; - use types::os::common::bsd44::{socklen_t, sockaddr, SOCKET}; - use types::os::arch::c95::c_int; - - extern "system" { - pub fn socket(domain: c_int, ty: c_int, protocol: c_int) -> SOCKET; - pub fn connect(socket: SOCKET, address: *const sockaddr, len: socklen_t) -> c_int; - pub fn bind(socket: SOCKET, address: *const sockaddr, address_len: socklen_t) -> c_int; - pub fn listen(socket: SOCKET, backlog: c_int) -> c_int; - pub fn accept(socket: SOCKET, - address: *mut sockaddr, - address_len: *mut socklen_t) - -> SOCKET; - pub fn getpeername(socket: SOCKET, - address: *mut sockaddr, - address_len: *mut socklen_t) - -> c_int; - pub fn getsockname(socket: SOCKET, - address: *mut sockaddr, - address_len: *mut socklen_t) - -> c_int; - pub fn setsockopt(socket: SOCKET, - level: c_int, - name: c_int, - value: *const c_void, - option_len: socklen_t) - -> c_int; - pub fn closesocket(socket: SOCKET) -> c_int; - pub fn recv(socket: SOCKET, buf: *mut c_void, len: c_int, flags: c_int) -> c_int; - pub fn send(socket: SOCKET, buf: *const c_void, len: c_int, flags: c_int) -> c_int; - pub fn recvfrom(socket: SOCKET, - buf: *mut c_void, - len: c_int, - flags: c_int, - addr: *mut sockaddr, - addrlen: *mut c_int) - -> c_int; - pub fn sendto(socket: SOCKET, - buf: *const c_void, - len: c_int, - flags: c_int, - addr: *const sockaddr, - addrlen: c_int) - -> c_int; - pub fn shutdown(socket: SOCKET, how: c_int) -> c_int; - } - } - - #[cfg(any(target_os = "macos", - target_os = "ios", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "bitrig", - target_os = "netbsd", - target_os = "openbsd"))] - pub mod bsd44 { - use types::common::c95::c_void; - use types::os::arch::c95::{c_char, c_uchar, c_int, c_uint, c_ulong, size_t}; - - extern { - pub fn ioctl(fd: c_int, request: c_ulong, ...) -> c_int; - pub fn sysctl(name: *mut c_int, - namelen: c_uint, - oldp: *mut c_void, - oldlenp: *mut size_t, - newp: *mut c_void, - newlen: size_t) - -> c_int; - pub fn sysctlbyname(name: *const c_char, - oldp: *mut c_void, - oldlenp: *mut size_t, - newp: *mut c_void, - newlen: size_t) - -> c_int; - pub fn sysctlnametomib(name: *const c_char, - mibp: *mut c_int, - sizep: *mut size_t) - -> c_int; - pub fn getdtablesize() -> c_int; - pub fn madvise(addr: *mut c_void, len: size_t, advice: c_int) -> c_int; - pub fn mincore(addr: *mut c_void, len: size_t, vec: *mut c_uchar) -> c_int; - pub fn realpath(pathname: *const c_char, resolved: *mut c_char) -> *mut c_char; - pub fn flock(fd: c_int, operation: c_int) -> c_int; - } - } - - #[cfg(any(target_os = "linux", target_os = "android"))] - pub mod bsd44 { - use types::common::c95::c_void; - use types::os::arch::c95::{c_uchar, c_int, size_t}; - #[cfg(not(feature = "cargo-build"))] - use types::os::arch::c95::c_ulong; - - extern { - #[cfg(not(all(target_os = "android", target_arch = "aarch64")))] - pub fn getdtablesize() -> c_int; - - // Note that the correct signature of ioctl broke some crates on - // crates.io, so for now we keep the broken signature for crates.io - // but we fix it locally in the main Rust distribution. Once a new - // major version of libc is released on crates.io this #[cfg] should - // go away. - #[cfg(feature = "cargo-build")] - pub fn ioctl(fd: c_int, request: c_int, ...) -> c_int; - #[cfg(not(feature = "cargo-build"))] - pub fn ioctl(fd: c_int, request: c_ulong, ...) -> c_int; - pub fn madvise(addr: *mut c_void, len: size_t, advice: c_int) -> c_int; - pub fn mincore(addr: *mut c_void, len: size_t, vec: *mut c_uchar) -> c_int; - pub fn flock(fd: c_int, operation: c_int) -> c_int; - } - } - - #[cfg(target_os = "nacl")] - pub mod bsd44 { - use types::os::arch::c95::c_int; - extern { - pub fn getdtablesize() -> c_int; - } - } - - #[cfg(target_os = "windows")] - pub mod bsd44 { - } - - #[cfg(any(target_os = "macos", target_os = "ios"))] - pub mod extra { - use types::os::arch::c95::{c_char, c_int}; - - extern { - pub fn _NSGetExecutablePath(buf: *mut c_char, bufsize: *mut u32) -> c_int; - } - } - - #[cfg(any(target_os = "freebsd", - target_os = "dragonfly", - target_os = "bitrig", - target_os = "netbsd", - target_os = "openbsd"))] - pub mod extra { - } - - #[cfg(any(target_os = "linux", target_os = "android", target_os = "nacl"))] - pub mod extra { - } - - - #[cfg(target_os = "windows")] - pub mod extra { - - pub mod kernel32 { - use types::os::arch::c95::c_uint; - use types::os::arch::extra::{BOOL, DWORD, SIZE_T, HMODULE, LPCWSTR, LPWSTR, LPWCH, - LPDWORD, LPVOID, LPCVOID, LPOVERLAPPED, - LPSECURITY_ATTRIBUTES, LPSTARTUPINFO, - LPPROCESS_INFORMATION, LPMEMORY_BASIC_INFORMATION, - LPSYSTEM_INFO, HANDLE, LPHANDLE, LARGE_INTEGER, - PLARGE_INTEGER, LPFILETIME, LPWIN32_FIND_DATAW}; - - extern "system" { - pub fn GetEnvironmentVariableW(n: LPCWSTR, v: LPWSTR, nsize: DWORD) -> DWORD; - pub fn SetEnvironmentVariableW(n: LPCWSTR, v: LPCWSTR) -> BOOL; - pub fn GetEnvironmentStringsW() -> LPWCH; - pub fn FreeEnvironmentStringsW(env_ptr: LPWCH) -> BOOL; - pub fn GetModuleFileNameW(hModule: HMODULE, - lpFilename: LPWSTR, - nSize: DWORD) - -> DWORD; - pub fn CreateDirectoryW(lpPathName: LPCWSTR, - lpSecurityAttributes: LPSECURITY_ATTRIBUTES) - -> BOOL; - pub fn CopyFileW(lpExistingFileName: LPCWSTR, - lpNewFileName: LPCWSTR, - bFailIfExists: BOOL) - -> BOOL; - pub fn DeleteFileW(lpPathName: LPCWSTR) -> BOOL; - pub fn RemoveDirectoryW(lpPathName: LPCWSTR) -> BOOL; - pub fn GetCurrentDirectoryW(nBufferLength: DWORD, lpBuffer: LPWSTR) -> DWORD; - pub fn SetCurrentDirectoryW(lpPathName: LPCWSTR) -> BOOL; - pub fn GetLastError() -> DWORD; - pub fn FindFirstFileW(fileName: LPCWSTR, - findFileData: LPWIN32_FIND_DATAW) - -> HANDLE; - pub fn FindNextFileW(findFile: HANDLE, findFileData: LPWIN32_FIND_DATAW) -> BOOL; - pub fn FindClose(findFile: HANDLE) -> BOOL; - pub fn DuplicateHandle(hSourceProcessHandle: HANDLE, - hSourceHandle: HANDLE, - hTargetProcessHandle: HANDLE, - lpTargetHandle: LPHANDLE, - dwDesiredAccess: DWORD, - bInheritHandle: BOOL, - dwOptions: DWORD) - -> BOOL; - pub fn CloseHandle(hObject: HANDLE) -> BOOL; - pub fn OpenProcess(dwDesiredAccess: DWORD, - bInheritHandle: BOOL, - dwProcessId: DWORD) - -> HANDLE; - pub fn GetCurrentProcess() -> HANDLE; - pub fn CreateProcessW(lpApplicationName: LPCWSTR, - lpCommandLine: LPWSTR, - lpProcessAttributes: LPSECURITY_ATTRIBUTES, - lpThreadAttributes: LPSECURITY_ATTRIBUTES, - bInheritHandles: BOOL, - dwCreationFlags: DWORD, - lpEnvironment: LPVOID, - lpCurrentDirectory: LPCWSTR, - lpStartupInfo: LPSTARTUPINFO, - lpProcessInformation: LPPROCESS_INFORMATION) - -> BOOL; - pub fn WaitForSingleObject(hHandle: HANDLE, dwMilliseconds: DWORD) -> DWORD; - pub fn TerminateProcess(hProcess: HANDLE, uExitCode: c_uint) -> BOOL; - pub fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: LPDWORD) -> BOOL; - pub fn GetSystemInfo(lpSystemInfo: LPSYSTEM_INFO); - pub fn VirtualAlloc(lpAddress: LPVOID, - dwSize: SIZE_T, - flAllocationType: DWORD, - flProtect: DWORD) - -> LPVOID; - pub fn VirtualFree(lpAddress: LPVOID, dwSize: SIZE_T, dwFreeType: DWORD) -> BOOL; - pub fn VirtualLock(lpAddress: LPVOID, dwSize: SIZE_T) -> BOOL; - pub fn VirtualUnlock(lpAddress: LPVOID, dwSize: SIZE_T) -> BOOL; - pub fn VirtualProtect(lpAddress: LPVOID, - dwSize: SIZE_T, - flNewProtect: DWORD, - lpflOldProtect: LPDWORD) - -> BOOL; - pub fn VirtualQuery(lpAddress: LPCVOID, - lpBuffer: LPMEMORY_BASIC_INFORMATION, - dwLength: SIZE_T) - -> SIZE_T; - pub fn CreateFileMappingW(hFile: HANDLE, - lpAttributes: LPSECURITY_ATTRIBUTES, - flProtect: DWORD, - dwMaximumSizeHigh: DWORD, - dwMaximumSizeLow: DWORD, - lpName: LPCWSTR) - -> HANDLE; - pub fn MapViewOfFile(hFileMappingObject: HANDLE, - dwDesiredAccess: DWORD, - dwFileOffsetHigh: DWORD, - dwFileOffsetLow: DWORD, - dwNumberOfBytesToMap: SIZE_T) - -> LPVOID; - pub fn UnmapViewOfFile(lpBaseAddress: LPCVOID) -> BOOL; - pub fn MoveFileExW(lpExistingFileName: LPCWSTR, - lpNewFileName: LPCWSTR, - dwFlags: DWORD) - -> BOOL; - pub fn CreateHardLinkW(lpSymlinkFileName: LPCWSTR, - lpTargetFileName: LPCWSTR, - lpSecurityAttributes: LPSECURITY_ATTRIBUTES) - -> BOOL; - pub fn FlushFileBuffers(hFile: HANDLE) -> BOOL; - pub fn CreateFileW(lpFileName: LPCWSTR, - dwDesiredAccess: DWORD, - dwShareMode: DWORD, - lpSecurityAttributes: LPSECURITY_ATTRIBUTES, - dwCreationDisposition: DWORD, - dwFlagsAndAttributes: DWORD, - hTemplateFile: HANDLE) - -> HANDLE; - pub fn ReadFile(hFile: HANDLE, - lpBuffer: LPVOID, - nNumberOfBytesToRead: DWORD, - lpNumberOfBytesRead: LPDWORD, - lpOverlapped: LPOVERLAPPED) - -> BOOL; - pub fn WriteFile(hFile: HANDLE, - lpBuffer: LPVOID, - nNumberOfBytesToWrite: DWORD, - lpNumberOfBytesWritten: LPDWORD, - lpOverlapped: LPOVERLAPPED) - -> BOOL; - pub fn SetFilePointerEx(hFile: HANDLE, - liDistanceToMove: LARGE_INTEGER, - lpNewFilePointer: PLARGE_INTEGER, - dwMoveMethod: DWORD) - -> BOOL; - pub fn SetEndOfFile(hFile: HANDLE) -> BOOL; - - pub fn GetSystemTimeAsFileTime(lpSystemTimeAsFileTime: LPFILETIME); - - pub fn QueryPerformanceFrequency(lpFrequency: *mut LARGE_INTEGER) -> BOOL; - pub fn QueryPerformanceCounter(lpPerformanceCount: *mut LARGE_INTEGER) -> BOOL; - - pub fn GetCurrentProcessId() -> DWORD; - pub fn CreateNamedPipeW(lpName: LPCWSTR, - dwOpenMode: DWORD, - dwPipeMode: DWORD, - nMaxInstances: DWORD, - nOutBufferSize: DWORD, - nInBufferSize: DWORD, - nDefaultTimeOut: DWORD, - lpSecurityAttributes: LPSECURITY_ATTRIBUTES) - -> HANDLE; - pub fn ConnectNamedPipe(hNamedPipe: HANDLE, lpOverlapped: LPOVERLAPPED) -> BOOL; - pub fn WaitNamedPipeW(lpNamedPipeName: LPCWSTR, nTimeOut: DWORD) -> BOOL; - pub fn SetNamedPipeHandleState(hNamedPipe: HANDLE, - lpMode: LPDWORD, - lpMaxCollectionCount: LPDWORD, - lpCollectDataTimeout: LPDWORD) - -> BOOL; - pub fn CreateEventW(lpEventAttributes: LPSECURITY_ATTRIBUTES, - bManualReset: BOOL, - bInitialState: BOOL, - lpName: LPCWSTR) - -> HANDLE; - pub fn GetOverlappedResult(hFile: HANDLE, - lpOverlapped: LPOVERLAPPED, - lpNumberOfBytesTransferred: LPDWORD, - bWait: BOOL) - -> BOOL; - pub fn DisconnectNamedPipe(hNamedPipe: HANDLE) -> BOOL; - } - } - - pub mod msvcrt { - use types::os::arch::c95::{c_int, c_long}; - use types::os::arch::c99::intptr_t; - - extern { - #[link_name = "_commit"] - pub fn commit(fd: c_int) -> c_int; - - #[link_name = "_get_osfhandle"] - pub fn get_osfhandle(fd: c_int) -> c_long; - - #[link_name = "_open_osfhandle"] - pub fn open_osfhandle(osfhandle: intptr_t, flags: c_int) -> c_int; - } - } - - pub mod winsock { - use types::os::arch::c95::{c_int, c_long, c_ulong}; - use types::os::common::bsd44::SOCKET; - - extern "system" { - pub fn ioctlsocket(s: SOCKET, cmd: c_long, argp: *mut c_ulong) -> c_int; - } - } - } -} - -#[test] -fn work_on_windows() { -} // FIXME #10872 needed for a happy windows diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index a6ca6a45f9568..74b92318f2774 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -96,25 +96,30 @@ fn get_resident() -> Option { } #[cfg(windows)] +#[cfg_attr(stage0, allow(improper_ctypes))] fn get_resident() -> Option { - use libc::{BOOL, DWORD, HANDLE, SIZE_T, GetCurrentProcess}; + type BOOL = i32; + type DWORD = u32; + type HANDLE = *mut u8; + use libc::size_t; use std::mem; #[repr(C)] #[allow(non_snake_case)] struct PROCESS_MEMORY_COUNTERS { cb: DWORD, PageFaultCount: DWORD, - PeakWorkingSetSize: SIZE_T, - WorkingSetSize: SIZE_T, - QuotaPeakPagedPoolUsage: SIZE_T, - QuotaPagedPoolUsage: SIZE_T, - QuotaPeakNonPagedPoolUsage: SIZE_T, - QuotaNonPagedPoolUsage: SIZE_T, - PagefileUsage: SIZE_T, - PeakPagefileUsage: SIZE_T, + PeakWorkingSetSize: size_t, + WorkingSetSize: size_t, + QuotaPeakPagedPoolUsage: size_t, + QuotaPagedPoolUsage: size_t, + QuotaPeakNonPagedPoolUsage: size_t, + QuotaNonPagedPoolUsage: size_t, + PagefileUsage: size_t, + PeakPagefileUsage: size_t, } type PPROCESS_MEMORY_COUNTERS = *mut PROCESS_MEMORY_COUNTERS; #[link(name = "psapi")] extern "system" { + fn GetCurrentProcess() -> HANDLE; fn GetProcessMemoryInfo(Process: HANDLE, ppsmemCounters: PPROCESS_MEMORY_COUNTERS, cb: DWORD) -> BOOL; diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index fe84cffa8c660..9cb5012cf0f81 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -16,6 +16,8 @@ #![allow(dead_code)] #![allow(trivial_casts)] +#![cfg_attr(stage0, allow(improper_ctypes))] + #![crate_name = "rustc_llvm"] #![unstable(feature = "rustc_private", issue = "27812")] #![staged_api] diff --git a/src/librustc_trans/back/msvc/registry.rs b/src/librustc_trans/back/msvc/registry.rs index d178565e18f59..63fb19c9772a8 100644 --- a/src/librustc_trans/back/msvc/registry.rs +++ b/src/librustc_trans/back/msvc/registry.rs @@ -13,8 +13,14 @@ use std::ffi::{OsString, OsStr}; use std::os::windows::prelude::*; use std::ops::RangeFrom; use std::ptr; -use libc::{DWORD, LPCWSTR, LONG, LPDWORD, LPBYTE, ERROR_SUCCESS}; -use libc::c_void; +use libc::{c_void, c_long}; + +type DWORD = u32; +type LPCWSTR = *const u16; +type LONG = c_long; +type LPDWORD = *mut DWORD; +type LPBYTE = *mut u8; + const HKEY_LOCAL_MACHINE: HKEY = 0x80000002 as HKEY; const KEY_WOW64_32KEY: REGSAM = 0x0200; @@ -27,6 +33,7 @@ const KEY_ENUMERATE_SUB_KEYS: REGSAM = 0x0008; const KEY_NOTIFY: REGSAM = 0x0010; const SYNCHRONIZE: REGSAM = 0x00100000; const REG_SZ: DWORD = 1; +const ERROR_SUCCESS: i32 = 0; const ERROR_NO_MORE_ITEMS: DWORD = 259; enum __HKEY__ {} diff --git a/src/librustdoc/flock.rs b/src/librustdoc/flock.rs index 847e28d2bc510..72a5043178baf 100644 --- a/src/librustdoc/flock.rs +++ b/src/librustdoc/flock.rs @@ -121,7 +121,7 @@ mod imp { let buf = CString::new(os.as_bytes()).unwrap(); let fd = unsafe { libc::open(buf.as_ptr(), libc::O_RDWR | libc::O_CREAT, - libc::S_IRWXU) + libc::S_IRWXU as libc::c_int) }; assert!(fd > 0, "failed to open lockfile: {}", io::Error::last_os_error()); @@ -164,77 +164,55 @@ mod imp { } #[cfg(windows)] +#[allow(bad_style)] mod imp { - use libc; use std::io; use std::mem; - use std::ffi::OsStr; use std::os::windows::prelude::*; + use std::os::windows::raw::HANDLE; use std::path::Path; - use std::ptr; - - const LOCKFILE_EXCLUSIVE_LOCK: libc::DWORD = 0x00000002; + use std::fs::{File, OpenOptions}; + + type DWORD = u32; + type LPOVERLAPPED = *mut OVERLAPPED; + type BOOL = i32; + const LOCKFILE_EXCLUSIVE_LOCK: DWORD = 0x00000002; + + #[repr(C)] + struct OVERLAPPED { + Internal: usize, + InternalHigh: usize, + Pointer: *mut u8, + hEvent: *mut u8, + } - #[allow(non_snake_case)] extern "system" { - fn LockFileEx(hFile: libc::HANDLE, - dwFlags: libc::DWORD, - dwReserved: libc::DWORD, - nNumberOfBytesToLockLow: libc::DWORD, - nNumberOfBytesToLockHigh: libc::DWORD, - lpOverlapped: libc::LPOVERLAPPED) -> libc::BOOL; - fn UnlockFileEx(hFile: libc::HANDLE, - dwReserved: libc::DWORD, - nNumberOfBytesToLockLow: libc::DWORD, - nNumberOfBytesToLockHigh: libc::DWORD, - lpOverlapped: libc::LPOVERLAPPED) -> libc::BOOL; + fn LockFileEx(hFile: HANDLE, + dwFlags: DWORD, + dwReserved: DWORD, + nNumberOfBytesToLockLow: DWORD, + nNumberOfBytesToLockHigh: DWORD, + lpOverlapped: LPOVERLAPPED) -> BOOL; } pub struct Lock { - handle: libc::HANDLE, + _file: File, } impl Lock { pub fn new(p: &Path) -> Lock { - let os: &OsStr = p.as_ref(); - let mut p_16: Vec<_> = os.encode_wide().collect(); - p_16.push(0); - let handle = unsafe { - libc::CreateFileW(p_16.as_ptr(), - libc::FILE_GENERIC_READ | - libc::FILE_GENERIC_WRITE, - libc::FILE_SHARE_READ | - libc::FILE_SHARE_DELETE | - libc::FILE_SHARE_WRITE, - ptr::null_mut(), - libc::CREATE_ALWAYS, - libc::FILE_ATTRIBUTE_NORMAL, - ptr::null_mut()) - }; - if handle == libc::INVALID_HANDLE_VALUE { - panic!("create file error: {}", io::Error::last_os_error()); - } - let mut overlapped: libc::OVERLAPPED = unsafe { mem::zeroed() }; + let f = OpenOptions::new().read(true).write(true).create(true) + .open(p).unwrap(); let ret = unsafe { - LockFileEx(handle, LOCKFILE_EXCLUSIVE_LOCK, 0, 100, 0, + let mut overlapped: OVERLAPPED = mem::zeroed(); + LockFileEx(f.as_raw_handle(), LOCKFILE_EXCLUSIVE_LOCK, 0, 100, 0, &mut overlapped) }; if ret == 0 { let err = io::Error::last_os_error(); - unsafe { libc::CloseHandle(handle); } panic!("could not lock `{}`: {}", p.display(), err); } - Lock { handle: handle } - } - } - - impl Drop for Lock { - fn drop(&mut self) { - let mut overlapped: libc::OVERLAPPED = unsafe { mem::zeroed() }; - unsafe { - UnlockFileEx(self.handle, 0, 100, 0, &mut overlapped); - libc::CloseHandle(self.handle); - } + Lock { _file: f } } } } diff --git a/src/libstd/dynamic_lib.rs b/src/libstd/dynamic_lib.rs index 8583631ef58d6..1cb48407f1069 100644 --- a/src/libstd/dynamic_lib.rs +++ b/src/libstd/dynamic_lib.rs @@ -207,11 +207,11 @@ mod dl { unsafe fn open_external(filename: &OsStr) -> *mut u8 { let s = filename.to_cstring().unwrap(); - dlopen(s.as_ptr(), LAZY) as *mut u8 + libc::dlopen(s.as_ptr(), LAZY) as *mut u8 } unsafe fn open_internal() -> *mut u8 { - dlopen(ptr::null(), LAZY) as *mut u8 + libc::dlopen(ptr::null(), LAZY) as *mut u8 } pub fn check_for_errors_in(f: F) -> Result where @@ -223,11 +223,11 @@ mod dl { // dlerror isn't thread safe, so we need to lock around this entire // sequence let _guard = LOCK.lock(); - let _old_error = dlerror(); + let _old_error = libc::dlerror(); let result = f(); - let last_error = dlerror() as *const _; + let last_error = libc::dlerror() as *const _; let ret = if ptr::null() == last_error { Ok(result) } else { @@ -241,19 +241,10 @@ mod dl { pub unsafe fn symbol(handle: *mut u8, symbol: *const libc::c_char) -> *mut u8 { - dlsym(handle as *mut libc::c_void, symbol) as *mut u8 + libc::dlsym(handle as *mut libc::c_void, symbol) as *mut u8 } pub unsafe fn close(handle: *mut u8) { - dlclose(handle as *mut libc::c_void); () - } - - extern { - fn dlopen(filename: *const libc::c_char, - flag: libc::c_int) -> *mut libc::c_void; - fn dlerror() -> *mut libc::c_char; - fn dlsym(handle: *mut libc::c_void, - symbol: *const libc::c_char) -> *mut libc::c_void; - fn dlclose(handle: *mut libc::c_void) -> libc::c_int; + libc::dlclose(handle as *mut libc::c_void); () } } @@ -263,11 +254,10 @@ mod dl { use ffi::OsStr; use libc; - use libc::consts::os::extra::ERROR_CALL_NOT_IMPLEMENTED; - use sys::os; use os::windows::prelude::*; use ptr; - use sys::c::SetThreadErrorMode; + use sys::c; + use sys::os; pub fn open(filename: Option<&OsStr>) -> Result<*mut u8, String> { // disable "dll load failed" error dialog. @@ -277,24 +267,25 @@ mod dl { let new_error_mode = 1; let mut prev_error_mode = 0; // Windows >= 7 supports thread error mode. - let result = SetThreadErrorMode(new_error_mode, &mut prev_error_mode); + let result = c::SetThreadErrorMode(new_error_mode, + &mut prev_error_mode); if result == 0 { let err = os::errno(); - if err as libc::c_int == ERROR_CALL_NOT_IMPLEMENTED { + if err == c::ERROR_CALL_NOT_IMPLEMENTED as i32 { use_thread_mode = false; // SetThreadErrorMode not found. use fallback solution: // SetErrorMode() Note that SetErrorMode is process-wide so // this can cause race condition! However, since even // Windows APIs do not care of such problem (#20650), we // just assume SetErrorMode race is not a great deal. - prev_error_mode = SetErrorMode(new_error_mode); + prev_error_mode = c::SetErrorMode(new_error_mode); } } prev_error_mode }; unsafe { - SetLastError(0); + c::SetLastError(0); } let result = match filename { @@ -302,7 +293,7 @@ mod dl { let filename_str: Vec<_> = filename.encode_wide().chain(Some(0)).collect(); let result = unsafe { - LoadLibraryW(filename_str.as_ptr() as *const libc::c_void) + c::LoadLibraryW(filename_str.as_ptr()) }; // beware: Vec/String may change errno during drop! // so we get error here. @@ -316,9 +307,10 @@ mod dl { None => { let mut handle = ptr::null_mut(); let succeeded = unsafe { - GetModuleHandleExW(0 as libc::DWORD, ptr::null(), &mut handle) + c::GetModuleHandleExW(0 as c::DWORD, ptr::null(), + &mut handle) }; - if succeeded == libc::FALSE { + if succeeded == c::FALSE { let errno = os::errno(); Err(os::error_string(errno)) } else { @@ -329,9 +321,9 @@ mod dl { unsafe { if use_thread_mode { - SetThreadErrorMode(prev_error_mode, ptr::null_mut()); + c::SetThreadErrorMode(prev_error_mode, ptr::null_mut()); } else { - SetErrorMode(prev_error_mode); + c::SetErrorMode(prev_error_mode); } } @@ -342,7 +334,7 @@ mod dl { F: FnOnce() -> T, { unsafe { - SetLastError(0); + c::SetLastError(0); let result = f(); @@ -356,22 +348,10 @@ mod dl { } pub unsafe fn symbol(handle: *mut u8, symbol: *const libc::c_char) -> *mut u8 { - GetProcAddress(handle as *mut libc::c_void, symbol) as *mut u8 + c::GetProcAddress(handle as c::HMODULE, symbol) as *mut u8 } pub unsafe fn close(handle: *mut u8) { - FreeLibrary(handle as *mut libc::c_void); () - } - - #[allow(non_snake_case)] - extern "system" { - fn SetLastError(error: libc::size_t); - fn LoadLibraryW(name: *const libc::c_void) -> *mut libc::c_void; - fn GetModuleHandleExW(dwFlags: libc::DWORD, name: *const u16, - handle: *mut *mut libc::c_void) -> libc::BOOL; - fn GetProcAddress(handle: *mut libc::c_void, - name: *const libc::c_char) -> *mut libc::c_void; - fn FreeLibrary(handle: *mut libc::c_void); - fn SetErrorMode(uMode: libc::c_uint) -> libc::c_uint; + c::FreeLibrary(handle as c::HMODULE); } } diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index d6a9778ced291..985dbdd895f84 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -16,7 +16,6 @@ use cmp; use fmt; use io::lazy::Lazy; use io::{self, BufReader, LineWriter}; -use libc; use sync::{Arc, Mutex, MutexGuard}; use sys::stdio; use sys_common::io::{read_to_end_uninitialized}; @@ -121,9 +120,9 @@ impl io::Read for Maybe { fn handle_ebadf(r: io::Result, default: T) -> io::Result { #[cfg(windows)] - const ERR: libc::c_int = libc::ERROR_INVALID_HANDLE; + const ERR: i32 = ::sys::c::ERROR_INVALID_HANDLE as i32; #[cfg(not(windows))] - const ERR: libc::c_int = libc::EBADF; + const ERR: i32 = ::libc::EBADF as i32; match r { Err(ref e) if e.raw_os_error() == Some(ERR) => Ok(default), diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 01effcadb3aca..a0bb9449806e8 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -213,13 +213,12 @@ test(no_crate_inject, attr(deny(warnings))), test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))))] -// SNAP 1af31d4 -#![allow(unused_features)] -// SNAP 1af31d4 -#![allow(unused_attributes)] +#![cfg_attr(stage0, allow(unused_attributes))] +#![cfg_attr(stage0, allow(improper_ctypes))] #![feature(alloc)] #![feature(allow_internal_unstable)] +#![feature(asm)] #![feature(associated_consts)] #![feature(borrow_state)] #![feature(box_syntax)] @@ -233,49 +232,52 @@ #![feature(core_float)] #![feature(core_intrinsics)] #![feature(core_simd)] +#![feature(decode_utf16)] #![feature(drain)] +#![feature(drop_in_place)] +#![feature(dropck_parametricity)] +#![feature(float_extras)] +#![feature(float_from_str_radix)] #![feature(fnbox)] #![feature(heap_api)] #![feature(int_error_internals)] #![feature(into_cow)] #![feature(lang_items)] #![feature(libc)] -#![feature(linkage, thread_local, asm)] +#![feature(link_args)] +#![feature(linkage)] #![feature(macro_reexport)] -#![feature(slice_concat_ext)] #![feature(no_std)] #![feature(oom)] #![feature(optin_builtin_traits)] #![feature(placement_in_syntax)] #![feature(rand)] +#![feature(range_inclusive)] #![feature(raw)] #![feature(reflect_marker)] #![feature(slice_bytes)] +#![feature(slice_concat_ext)] #![feature(slice_patterns)] #![feature(staged_api)] #![feature(str_char)] #![feature(str_internals)] +#![feature(str_utf16)] +#![feature(test, rustc_private)] +#![feature(thread_local)] #![feature(unboxed_closures)] #![feature(unicode)] #![feature(unique)] -#![feature(dropck_parametricity)] #![feature(unsafe_no_drop_flag, filling_drop)] -#![feature(decode_utf16)] #![feature(unwind_attributes)] #![feature(vec_push_all)] #![feature(wrapping)] #![feature(zero_one)] -#![feature(drop_in_place)] - -#![cfg_attr(windows, feature(str_utf16))] -#![cfg_attr(test, feature(float_from_str_radix, range_inclusive, float_extras))] -#![cfg_attr(test, feature(test, rustc_private))] -#![cfg_attr(target_env = "msvc", feature(link_args))] // Don't link to std. We are std. #![no_std] #![deny(missing_docs)] +#![allow(unused_features)] // std may use features in a platform-specific way #[cfg(test)] extern crate test; #[cfg(test)] #[macro_use] extern crate log; diff --git a/src/libstd/net/addr.rs b/src/libstd/net/addr.rs index cf0ede30dcc7c..66c1ab720b60f 100644 --- a/src/libstd/net/addr.rs +++ b/src/libstd/net/addr.rs @@ -13,10 +13,10 @@ use prelude::v1::*; use fmt; use hash; use io; -use libc::{self, socklen_t, sa_family_t}; use mem; use net::{lookup_host, ntoh, hton, IpAddr, Ipv4Addr, Ipv6Addr}; use option; +use sys::net::netc as c; use sys_common::{FromInner, AsInner, IntoInner}; use vec; @@ -39,12 +39,12 @@ pub enum SocketAddr { /// An IPv4 socket address which is a (ip, port) combination. #[derive(Copy)] #[stable(feature = "rust1", since = "1.0.0")] -pub struct SocketAddrV4 { inner: libc::sockaddr_in } +pub struct SocketAddrV4 { inner: c::sockaddr_in } /// An IPv6 socket address. #[derive(Copy)] #[stable(feature = "rust1", since = "1.0.0")] -pub struct SocketAddrV6 { inner: libc::sockaddr_in6 } +pub struct SocketAddrV6 { inner: c::sockaddr_in6 } impl SocketAddr { /// Creates a new socket address from the (ip, port) pair. @@ -80,8 +80,8 @@ impl SocketAddrV4 { #[stable(feature = "rust1", since = "1.0.0")] pub fn new(ip: Ipv4Addr, port: u16) -> SocketAddrV4 { SocketAddrV4 { - inner: libc::sockaddr_in { - sin_family: libc::AF_INET as sa_family_t, + inner: c::sockaddr_in { + sin_family: c::AF_INET as c::sa_family_t, sin_port: hton(port), sin_addr: *ip.as_inner(), .. unsafe { mem::zeroed() } @@ -93,7 +93,7 @@ impl SocketAddrV4 { #[stable(feature = "rust1", since = "1.0.0")] pub fn ip(&self) -> &Ipv4Addr { unsafe { - &*(&self.inner.sin_addr as *const libc::in_addr as *const Ipv4Addr) + &*(&self.inner.sin_addr as *const c::in_addr as *const Ipv4Addr) } } @@ -109,8 +109,8 @@ impl SocketAddrV6 { pub fn new(ip: Ipv6Addr, port: u16, flowinfo: u32, scope_id: u32) -> SocketAddrV6 { SocketAddrV6 { - inner: libc::sockaddr_in6 { - sin6_family: libc::AF_INET6 as sa_family_t, + inner: c::sockaddr_in6 { + sin6_family: c::AF_INET6 as c::sa_family_t, sin6_port: hton(port), sin6_addr: *ip.as_inner(), sin6_flowinfo: hton(flowinfo), @@ -124,7 +124,7 @@ impl SocketAddrV6 { #[stable(feature = "rust1", since = "1.0.0")] pub fn ip(&self) -> &Ipv6Addr { unsafe { - &*(&self.inner.sin6_addr as *const libc::in6_addr as *const Ipv6Addr) + &*(&self.inner.sin6_addr as *const c::in6_addr as *const Ipv6Addr) } } @@ -143,26 +143,26 @@ impl SocketAddrV6 { pub fn scope_id(&self) -> u32 { ntoh(self.inner.sin6_scope_id) } } -impl FromInner for SocketAddrV4 { - fn from_inner(addr: libc::sockaddr_in) -> SocketAddrV4 { +impl FromInner for SocketAddrV4 { + fn from_inner(addr: c::sockaddr_in) -> SocketAddrV4 { SocketAddrV4 { inner: addr } } } -impl FromInner for SocketAddrV6 { - fn from_inner(addr: libc::sockaddr_in6) -> SocketAddrV6 { +impl FromInner for SocketAddrV6 { + fn from_inner(addr: c::sockaddr_in6) -> SocketAddrV6 { SocketAddrV6 { inner: addr } } } -impl<'a> IntoInner<(*const libc::sockaddr, socklen_t)> for &'a SocketAddr { - fn into_inner(self) -> (*const libc::sockaddr, socklen_t) { +impl<'a> IntoInner<(*const c::sockaddr, c::socklen_t)> for &'a SocketAddr { + fn into_inner(self) -> (*const c::sockaddr, c::socklen_t) { match *self { SocketAddr::V4(ref a) => { - (a as *const _ as *const _, mem::size_of_val(a) as socklen_t) + (a as *const _ as *const _, mem::size_of_val(a) as c::socklen_t) } SocketAddr::V6(ref a) => { - (a as *const _ as *const _, mem::size_of_val(a) as socklen_t) + (a as *const _ as *const _, mem::size_of_val(a) as c::socklen_t) } } } diff --git a/src/libstd/net/ip.rs b/src/libstd/net/ip.rs index 827a3eb9bf600..f3ad148e3da93 100644 --- a/src/libstd/net/ip.rs +++ b/src/libstd/net/ip.rs @@ -16,11 +16,12 @@ use prelude::v1::*; use cmp::Ordering; -use hash; use fmt; -use libc; -use sys_common::{AsInner, FromInner}; +use hash; +use mem; use net::{hton, ntoh}; +use sys::net::netc as c; +use sys_common::{AsInner, FromInner}; /// An IP address, either an IPv4 or IPv6 address. #[unstable(feature = "ip_addr", reason = "recent addition", issue = "27801")] @@ -36,14 +37,14 @@ pub enum IpAddr { #[derive(Copy)] #[stable(feature = "rust1", since = "1.0.0")] pub struct Ipv4Addr { - inner: libc::in_addr, + inner: c::in_addr, } /// Representation of an IPv6 address. #[derive(Copy)] #[stable(feature = "rust1", since = "1.0.0")] pub struct Ipv6Addr { - inner: libc::in6_addr, + inner: c::in6_addr, } #[allow(missing_docs)] @@ -65,7 +66,7 @@ impl Ipv4Addr { #[stable(feature = "rust1", since = "1.0.0")] pub fn new(a: u8, b: u8, c: u8, d: u8) -> Ipv4Addr { Ipv4Addr { - inner: libc::in_addr { + inner: c::in_addr { s_addr: hton(((a as u32) << 24) | ((b as u32) << 16) | ((c as u32) << 8) | @@ -239,11 +240,11 @@ impl Ord for Ipv4Addr { } } -impl AsInner for Ipv4Addr { - fn as_inner(&self) -> &libc::in_addr { &self.inner } +impl AsInner for Ipv4Addr { + fn as_inner(&self) -> &c::in_addr { &self.inner } } -impl FromInner for Ipv4Addr { - fn from_inner(addr: libc::in_addr) -> Ipv4Addr { +impl FromInner for Ipv4Addr { + fn from_inner(addr: c::in_addr) -> Ipv4Addr { Ipv4Addr { inner: addr } } } @@ -270,25 +271,32 @@ impl Ipv6Addr { #[stable(feature = "rust1", since = "1.0.0")] pub fn new(a: u16, b: u16, c: u16, d: u16, e: u16, f: u16, g: u16, h: u16) -> Ipv6Addr { - Ipv6Addr { - inner: libc::in6_addr { - s6_addr: [hton(a), hton(b), hton(c), hton(d), - hton(e), hton(f), hton(g), hton(h)] - } - } + let mut addr: c::in6_addr = unsafe { mem::zeroed() }; + addr.s6_addr = [(a >> 8) as u8, a as u8, + (b >> 8) as u8, b as u8, + (c >> 8) as u8, c as u8, + (d >> 8) as u8, d as u8, + (e >> 8) as u8, e as u8, + (f >> 8) as u8, f as u8, + (g >> 8) as u8, g as u8, + (h >> 8) as u8, h as u8]; + Ipv6Addr { inner: addr } } /// Returns the eight 16-bit segments that make up this address. #[stable(feature = "rust1", since = "1.0.0")] pub fn segments(&self) -> [u16; 8] { - [ntoh(self.inner.s6_addr[0]), - ntoh(self.inner.s6_addr[1]), - ntoh(self.inner.s6_addr[2]), - ntoh(self.inner.s6_addr[3]), - ntoh(self.inner.s6_addr[4]), - ntoh(self.inner.s6_addr[5]), - ntoh(self.inner.s6_addr[6]), - ntoh(self.inner.s6_addr[7])] + let arr = &self.inner.s6_addr; + [ + (arr[0] as u16) << 8 | (arr[1] as u16), + (arr[2] as u16) << 8 | (arr[3] as u16), + (arr[4] as u16) << 8 | (arr[5] as u16), + (arr[6] as u16) << 8 | (arr[7] as u16), + (arr[8] as u16) << 8 | (arr[9] as u16), + (arr[10] as u16) << 8 | (arr[11] as u16), + (arr[12] as u16) << 8 | (arr[13] as u16), + (arr[14] as u16) << 8 | (arr[15] as u16), + ] } /// Returns true for the special 'unspecified' address ::. @@ -502,11 +510,11 @@ impl Ord for Ipv6Addr { } } -impl AsInner for Ipv6Addr { - fn as_inner(&self) -> &libc::in6_addr { &self.inner } +impl AsInner for Ipv6Addr { + fn as_inner(&self) -> &c::in6_addr { &self.inner } } -impl FromInner for Ipv6Addr { - fn from_inner(addr: libc::in6_addr) -> Ipv6Addr { +impl FromInner for Ipv6Addr { + fn from_inner(addr: c::in6_addr) -> Ipv6Addr { Ipv6Addr { inner: addr } } } diff --git a/src/libstd/os/raw.rs b/src/libstd/os/raw.rs index db487d041b7c1..60069cf7bc3ef 100644 --- a/src/libstd/os/raw.rs +++ b/src/libstd/os/raw.rs @@ -12,9 +12,9 @@ #![stable(feature = "raw_os", since = "1.1.0")] -#[cfg(target_arch = "aarch64")] +#[cfg(any(target_arch = "aarch64", target_os = "android"))] #[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = u8; -#[cfg(not(target_arch = "aarch64"))] +#[cfg(not(any(target_arch = "aarch64", target_os = "android")))] #[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = i8; #[stable(feature = "raw_os", since = "1.1.0")] pub type c_schar = i8; #[stable(feature = "raw_os", since = "1.1.0")] pub type c_uchar = u8; diff --git a/src/libstd/rand/os.rs b/src/libstd/rand/os.rs index 1df9642d3bb74..d1bd013e67b79 100644 --- a/src/libstd/rand/os.rs +++ b/src/libstd/rand/os.rs @@ -252,10 +252,7 @@ mod imp { use io; use mem; use rand::Rng; - use libc::types::os::arch::extra::{LONG_PTR}; - use libc::{DWORD, BYTE, LPCSTR, BOOL}; - - type HCRYPTPROV = LONG_PTR; + use sys::c; /// A random number generator that retrieves randomness straight from /// the operating system. Platform sources: @@ -268,25 +265,7 @@ mod imp { /// /// This does not block. pub struct OsRng { - hcryptprov: HCRYPTPROV - } - - const PROV_RSA_FULL: DWORD = 1; - const CRYPT_SILENT: DWORD = 64; - const CRYPT_VERIFYCONTEXT: DWORD = 0xF0000000; - - #[allow(non_snake_case)] - #[link(name = "advapi32")] - extern "system" { - fn CryptAcquireContextA(phProv: *mut HCRYPTPROV, - pszContainer: LPCSTR, - pszProvider: LPCSTR, - dwProvType: DWORD, - dwFlags: DWORD) -> BOOL; - fn CryptGenRandom(hProv: HCRYPTPROV, - dwLen: DWORD, - pbBuffer: *mut BYTE) -> BOOL; - fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) -> BOOL; + hcryptprov: c::HCRYPTPROV } impl OsRng { @@ -294,9 +273,9 @@ mod imp { pub fn new() -> io::Result { let mut hcp = 0; let ret = unsafe { - CryptAcquireContextA(&mut hcp, 0 as LPCSTR, 0 as LPCSTR, - PROV_RSA_FULL, - CRYPT_VERIFYCONTEXT | CRYPT_SILENT) + c::CryptAcquireContextA(&mut hcp, 0 as c::LPCSTR, 0 as c::LPCSTR, + c::PROV_RSA_FULL, + c::CRYPT_VERIFYCONTEXT | c::CRYPT_SILENT) }; if ret == 0 { @@ -320,8 +299,8 @@ mod imp { } fn fill_bytes(&mut self, v: &mut [u8]) { let ret = unsafe { - CryptGenRandom(self.hcryptprov, v.len() as DWORD, - v.as_mut_ptr()) + c::CryptGenRandom(self.hcryptprov, v.len() as c::DWORD, + v.as_mut_ptr()) }; if ret == 0 { panic!("couldn't generate random bytes: {}", @@ -333,7 +312,7 @@ mod imp { impl Drop for OsRng { fn drop(&mut self) { let ret = unsafe { - CryptReleaseContext(self.hcryptprov, 0) + c::CryptReleaseContext(self.hcryptprov, 0) }; if ret == 0 { panic!("couldn't release context: {}", diff --git a/src/libstd/sync/condvar.rs b/src/libstd/sync/condvar.rs index 7a80a202dd9c1..a18370dc68e18 100644 --- a/src/libstd/sync/condvar.rs +++ b/src/libstd/sync/condvar.rs @@ -12,10 +12,10 @@ use prelude::v1::*; use sync::atomic::{AtomicUsize, Ordering}; use sync::{mutex, MutexGuard, PoisonError}; +use sys::time::SteadyTime; use sys_common::condvar as sys; use sys_common::mutex as sys_mutex; use sys_common::poison::{self, LockResult}; -use sys::time::SteadyTime; use time::Duration; /// A type indicating whether a timed wait on a condition variable returned diff --git a/src/libstd/sys/common/net.rs b/src/libstd/sys/common/net.rs index 37379596251de..449cd9d8c97a1 100644 --- a/src/libstd/sys/common/net.rs +++ b/src/libstd/sys/common/net.rs @@ -13,13 +13,13 @@ use prelude::v1::*; use ffi::{CStr, CString}; use fmt; use io::{self, Error, ErrorKind}; -use libc::{self, c_int, c_char, c_void, socklen_t}; +use libc::{c_int, c_char, c_void}; use mem; use net::{SocketAddr, Shutdown, IpAddr}; use ptr; use str::from_utf8; -use sys::c; use sys::net::{cvt, cvt_r, cvt_gai, Socket, init, wrlen_t}; +use sys::net::netc as c; use sys_common::{AsInner, FromInner, IntoInner}; use time::Duration; @@ -31,8 +31,8 @@ pub fn setsockopt(sock: &Socket, opt: c_int, val: c_int, payload: T) -> io::Result<()> { unsafe { let payload = &payload as *const T as *const c_void; - try!(cvt(libc::setsockopt(*sock.as_inner(), opt, val, payload, - mem::size_of::() as socklen_t))); + try!(cvt(c::setsockopt(*sock.as_inner(), opt, val, payload, + mem::size_of::() as c::socklen_t))); Ok(()) } } @@ -41,7 +41,7 @@ pub fn getsockopt(sock: &Socket, opt: c_int, val: c_int) -> io::Result { unsafe { let mut slot: T = mem::zeroed(); - let mut len = mem::size_of::() as socklen_t; + let mut len = mem::size_of::() as c::socklen_t; try!(cvt(c::getsockopt(*sock.as_inner(), opt, val, &mut slot as *mut _ as *mut _, &mut len))); @@ -51,29 +51,29 @@ pub fn getsockopt(sock: &Socket, opt: c_int, } fn sockname(f: F) -> io::Result - where F: FnOnce(*mut libc::sockaddr, *mut socklen_t) -> c_int + where F: FnOnce(*mut c::sockaddr, *mut c::socklen_t) -> c_int { unsafe { - let mut storage: libc::sockaddr_storage = mem::zeroed(); - let mut len = mem::size_of_val(&storage) as socklen_t; + let mut storage: c::sockaddr_storage = mem::zeroed(); + let mut len = mem::size_of_val(&storage) as c::socklen_t; try!(cvt(f(&mut storage as *mut _ as *mut _, &mut len))); sockaddr_to_addr(&storage, len as usize) } } -fn sockaddr_to_addr(storage: &libc::sockaddr_storage, +fn sockaddr_to_addr(storage: &c::sockaddr_storage, len: usize) -> io::Result { - match storage.ss_family as libc::c_int { - libc::AF_INET => { - assert!(len as usize >= mem::size_of::()); + match storage.ss_family as c_int { + c::AF_INET => { + assert!(len as usize >= mem::size_of::()); Ok(SocketAddr::V4(FromInner::from_inner(unsafe { - *(storage as *const _ as *const libc::sockaddr_in) + *(storage as *const _ as *const c::sockaddr_in) }))) } - libc::AF_INET6 => { - assert!(len as usize >= mem::size_of::()); + c::AF_INET6 => { + assert!(len as usize >= mem::size_of::()); Ok(SocketAddr::V6(FromInner::from_inner(unsafe { - *(storage as *const _ as *const libc::sockaddr_in6) + *(storage as *const _ as *const c::sockaddr_in6) }))) } _ => { @@ -86,16 +86,9 @@ fn sockaddr_to_addr(storage: &libc::sockaddr_storage, // get_host_addresses //////////////////////////////////////////////////////////////////////////////// -extern "system" { - fn getaddrinfo(node: *const c_char, service: *const c_char, - hints: *const libc::addrinfo, - res: *mut *mut libc::addrinfo) -> c_int; - fn freeaddrinfo(res: *mut libc::addrinfo); -} - pub struct LookupHost { - original: *mut libc::addrinfo, - cur: *mut libc::addrinfo, + original: *mut c::addrinfo, + cur: *mut c::addrinfo, } impl Iterator for LookupHost { @@ -105,7 +98,7 @@ impl Iterator for LookupHost { if self.cur.is_null() { return None } let ret = sockaddr_to_addr(mem::transmute((*self.cur).ai_addr), (*self.cur).ai_addrlen as usize); - self.cur = (*self.cur).ai_next as *mut libc::addrinfo; + self.cur = (*self.cur).ai_next as *mut c::addrinfo; Some(ret) } } @@ -116,7 +109,7 @@ unsafe impl Send for LookupHost {} impl Drop for LookupHost { fn drop(&mut self) { - unsafe { freeaddrinfo(self.original) } + unsafe { c::freeaddrinfo(self.original) } } } @@ -126,8 +119,8 @@ pub fn lookup_host(host: &str) -> io::Result { let c_host = try!(CString::new(host)); let mut res = ptr::null_mut(); unsafe { - try!(cvt_gai(getaddrinfo(c_host.as_ptr(), ptr::null(), ptr::null(), - &mut res))); + try!(cvt_gai(c::getaddrinfo(c_host.as_ptr(), ptr::null(), ptr::null(), + &mut res))); Ok(LookupHost { original: res, cur: res }) } } @@ -136,26 +129,18 @@ pub fn lookup_host(host: &str) -> io::Result { // lookup_addr //////////////////////////////////////////////////////////////////////////////// -extern "system" { - fn getnameinfo(sa: *const libc::sockaddr, salen: socklen_t, - host: *mut c_char, hostlen: libc::size_t, - serv: *mut c_char, servlen: libc::size_t, - flags: c_int) -> c_int; -} - -const NI_MAXHOST: usize = 1025; - pub fn lookup_addr(addr: &IpAddr) -> io::Result { init(); let saddr = SocketAddr::new(*addr, 0); let (inner, len) = saddr.into_inner(); - let mut hostbuf = [0 as c_char; NI_MAXHOST]; + let mut hostbuf = [0 as c_char; c::NI_MAXHOST as usize]; let data = unsafe { - try!(cvt_gai(getnameinfo(inner, len, - hostbuf.as_mut_ptr(), NI_MAXHOST as libc::size_t, - ptr::null_mut(), 0, 0))); + try!(cvt_gai(c::getnameinfo(inner, len, + hostbuf.as_mut_ptr(), + c::NI_MAXHOST, + ptr::null_mut(), 0, 0))); CStr::from_ptr(hostbuf.as_ptr()) }; @@ -179,10 +164,10 @@ impl TcpStream { pub fn connect(addr: &SocketAddr) -> io::Result { init(); - let sock = try!(Socket::new(addr, libc::SOCK_STREAM)); + let sock = try!(Socket::new(addr, c::SOCK_STREAM)); let (addrp, len) = addr.into_inner(); - try!(cvt_r(|| unsafe { libc::connect(*sock.as_inner(), addrp, len) })); + try!(cvt_r(|| unsafe { c::connect(*sock.as_inner(), addrp, len) })); Ok(TcpStream { inner: sock }) } @@ -191,19 +176,19 @@ impl TcpStream { pub fn into_socket(self) -> Socket { self.inner } pub fn set_read_timeout(&self, dur: Option) -> io::Result<()> { - self.inner.set_timeout(dur, libc::SO_RCVTIMEO) + self.inner.set_timeout(dur, c::SO_RCVTIMEO) } pub fn set_write_timeout(&self, dur: Option) -> io::Result<()> { - self.inner.set_timeout(dur, libc::SO_SNDTIMEO) + self.inner.set_timeout(dur, c::SO_SNDTIMEO) } pub fn read_timeout(&self) -> io::Result> { - self.inner.timeout(libc::SO_RCVTIMEO) + self.inner.timeout(c::SO_RCVTIMEO) } pub fn write_timeout(&self) -> io::Result> { - self.inner.timeout(libc::SO_SNDTIMEO) + self.inner.timeout(c::SO_SNDTIMEO) } pub fn read(&self, buf: &mut [u8]) -> io::Result { @@ -212,36 +197,28 @@ impl TcpStream { pub fn write(&self, buf: &[u8]) -> io::Result { let ret = try!(cvt(unsafe { - libc::send(*self.inner.as_inner(), - buf.as_ptr() as *const c_void, - buf.len() as wrlen_t, - 0) + c::send(*self.inner.as_inner(), + buf.as_ptr() as *const c_void, + buf.len() as wrlen_t, + 0) })); Ok(ret as usize) } pub fn peer_addr(&self) -> io::Result { sockname(|buf, len| unsafe { - libc::getpeername(*self.inner.as_inner(), buf, len) + c::getpeername(*self.inner.as_inner(), buf, len) }) } pub fn socket_addr(&self) -> io::Result { sockname(|buf, len| unsafe { - libc::getsockname(*self.inner.as_inner(), buf, len) + c::getsockname(*self.inner.as_inner(), buf, len) }) } pub fn shutdown(&self, how: Shutdown) -> io::Result<()> { - use libc::consts::os::bsd44::SHUT_RDWR; - - let how = match how { - Shutdown::Write => libc::SHUT_WR, - Shutdown::Read => libc::SHUT_RD, - Shutdown::Both => SHUT_RDWR, - }; - try!(cvt(unsafe { libc::shutdown(*self.inner.as_inner(), how) })); - Ok(()) + self.inner.shutdown(how) } pub fn duplicate(&self) -> io::Result { @@ -285,22 +262,22 @@ impl TcpListener { pub fn bind(addr: &SocketAddr) -> io::Result { init(); - let sock = try!(Socket::new(addr, libc::SOCK_STREAM)); + let sock = try!(Socket::new(addr, c::SOCK_STREAM)); // On platforms with Berkeley-derived sockets, this allows // to quickly rebind a socket, without needing to wait for // the OS to clean up the previous one. if !cfg!(windows) { - try!(setsockopt(&sock, libc::SOL_SOCKET, libc::SO_REUSEADDR, + try!(setsockopt(&sock, c::SOL_SOCKET, c::SO_REUSEADDR, 1 as c_int)); } // Bind our new socket let (addrp, len) = addr.into_inner(); - try!(cvt(unsafe { libc::bind(*sock.as_inner(), addrp, len) })); + try!(cvt(unsafe { c::bind(*sock.as_inner(), addrp, len) })); // Start listening - try!(cvt(unsafe { libc::listen(*sock.as_inner(), 128) })); + try!(cvt(unsafe { c::listen(*sock.as_inner(), 128) })); Ok(TcpListener { inner: sock }) } @@ -310,13 +287,13 @@ impl TcpListener { pub fn socket_addr(&self) -> io::Result { sockname(|buf, len| unsafe { - libc::getsockname(*self.inner.as_inner(), buf, len) + c::getsockname(*self.inner.as_inner(), buf, len) }) } pub fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> { - let mut storage: libc::sockaddr_storage = unsafe { mem::zeroed() }; - let mut len = mem::size_of_val(&storage) as socklen_t; + let mut storage: c::sockaddr_storage = unsafe { mem::zeroed() }; + let mut len = mem::size_of_val(&storage) as c::socklen_t; let sock = try!(self.inner.accept(&mut storage as *mut _ as *mut _, &mut len)); let addr = try!(sockaddr_to_addr(&storage, len as usize)); @@ -360,9 +337,9 @@ impl UdpSocket { pub fn bind(addr: &SocketAddr) -> io::Result { init(); - let sock = try!(Socket::new(addr, libc::SOCK_DGRAM)); + let sock = try!(Socket::new(addr, c::SOCK_DGRAM)); let (addrp, len) = addr.into_inner(); - try!(cvt(unsafe { libc::bind(*sock.as_inner(), addrp, len) })); + try!(cvt(unsafe { c::bind(*sock.as_inner(), addrp, len) })); Ok(UdpSocket { inner: sock }) } @@ -372,19 +349,19 @@ impl UdpSocket { pub fn socket_addr(&self) -> io::Result { sockname(|buf, len| unsafe { - libc::getsockname(*self.inner.as_inner(), buf, len) + c::getsockname(*self.inner.as_inner(), buf, len) }) } pub fn recv_from(&self, buf: &mut [u8]) -> io::Result<(usize, SocketAddr)> { - let mut storage: libc::sockaddr_storage = unsafe { mem::zeroed() }; - let mut addrlen = mem::size_of_val(&storage) as socklen_t; + let mut storage: c::sockaddr_storage = unsafe { mem::zeroed() }; + let mut addrlen = mem::size_of_val(&storage) as c::socklen_t; let n = try!(cvt(unsafe { - libc::recvfrom(*self.inner.as_inner(), - buf.as_mut_ptr() as *mut c_void, - buf.len() as wrlen_t, 0, - &mut storage as *mut _ as *mut _, &mut addrlen) + c::recvfrom(*self.inner.as_inner(), + buf.as_mut_ptr() as *mut c_void, + buf.len() as wrlen_t, 0, + &mut storage as *mut _ as *mut _, &mut addrlen) })); Ok((n as usize, try!(sockaddr_to_addr(&storage, addrlen as usize)))) } @@ -392,9 +369,9 @@ impl UdpSocket { pub fn send_to(&self, buf: &[u8], dst: &SocketAddr) -> io::Result { let (dstp, dstlen) = dst.into_inner(); let ret = try!(cvt(unsafe { - libc::sendto(*self.inner.as_inner(), - buf.as_ptr() as *const c_void, buf.len() as wrlen_t, - 0, dstp, dstlen) + c::sendto(*self.inner.as_inner(), + buf.as_ptr() as *const c_void, buf.len() as wrlen_t, + 0, dstp, dstlen) })); Ok(ret as usize) } @@ -404,19 +381,19 @@ impl UdpSocket { } pub fn set_read_timeout(&self, dur: Option) -> io::Result<()> { - self.inner.set_timeout(dur, libc::SO_RCVTIMEO) + self.inner.set_timeout(dur, c::SO_RCVTIMEO) } pub fn set_write_timeout(&self, dur: Option) -> io::Result<()> { - self.inner.set_timeout(dur, libc::SO_SNDTIMEO) + self.inner.set_timeout(dur, c::SO_SNDTIMEO) } pub fn read_timeout(&self) -> io::Result> { - self.inner.timeout(libc::SO_RCVTIMEO) + self.inner.timeout(c::SO_RCVTIMEO) } pub fn write_timeout(&self) -> io::Result> { - self.inner.timeout(libc::SO_SNDTIMEO) + self.inner.timeout(c::SO_SNDTIMEO) } } diff --git a/src/libstd/sys/common/unwind/seh.rs b/src/libstd/sys/common/unwind/seh.rs index a89e8b499acce..7296194efda5e 100644 --- a/src/libstd/sys/common/unwind/seh.rs +++ b/src/libstd/sys/common/unwind/seh.rs @@ -52,45 +52,14 @@ use prelude::v1::*; use any::Any; -use libc::{c_ulong, DWORD, c_void}; use ptr; use sys_common::thread_local::StaticKey; +use sys::c; -// 0x R U S T -const RUST_PANIC: DWORD = 0x52555354; +// 0x R U S T +const RUST_PANIC: c::DWORD = 0x52555354; static PANIC_DATA: StaticKey = StaticKey::new(None); -// This function is provided by kernel32.dll -extern "system" { - #[unwind] - fn RaiseException(dwExceptionCode: DWORD, - dwExceptionFlags: DWORD, - nNumberOfArguments: DWORD, - lpArguments: *const c_ulong); -} - -#[repr(C)] -pub struct EXCEPTION_POINTERS { - ExceptionRecord: *mut EXCEPTION_RECORD, - ContextRecord: *mut CONTEXT, -} - -enum CONTEXT {} - -#[repr(C)] -struct EXCEPTION_RECORD { - ExceptionCode: DWORD, - ExceptionFlags: DWORD, - ExceptionRecord: *mut _EXCEPTION_RECORD, - ExceptionAddress: *mut c_void, - NumberParameters: DWORD, - ExceptionInformation: [*mut c_ulong; EXCEPTION_MAXIMUM_PARAMETERS], -} - -enum _EXCEPTION_RECORD {} - -const EXCEPTION_MAXIMUM_PARAMETERS: usize = 15; - pub unsafe fn panic(data: Box) -> ! { // See module docs above for an explanation of why `data` is stored in a // thread local instead of being passed as an argument to the @@ -100,14 +69,14 @@ pub unsafe fn panic(data: Box) -> ! { rtassert!(PANIC_DATA.get().is_null()); PANIC_DATA.set(Box::into_raw(exception) as *mut u8); - RaiseException(RUST_PANIC, 0, 0, ptr::null()); + c::RaiseException(RUST_PANIC, 0, 0, ptr::null()); rtabort!("could not unwind stack"); } pub unsafe fn cleanup(ptr: *mut u8) -> Box { // The `ptr` here actually corresponds to the code of the exception, and our // real data is stored in our thread local. - rtassert!(ptr as DWORD == RUST_PANIC); + rtassert!(ptr as c::DWORD == RUST_PANIC); let data = PANIC_DATA.get() as *mut Box; PANIC_DATA.set(ptr::null_mut()); @@ -139,7 +108,7 @@ fn rust_eh_personality() { #[lang = "msvc_try_filter"] #[linkage = "external"] #[allow(private_no_mangle_fns)] -extern fn __rust_try_filter(eh_ptrs: *mut EXCEPTION_POINTERS, +extern fn __rust_try_filter(eh_ptrs: *mut c::EXCEPTION_POINTERS, _rbp: *mut u8) -> i32 { unsafe { ((*(*eh_ptrs).ExceptionRecord).ExceptionCode == RUST_PANIC) as i32 diff --git a/src/libstd/sys/common/unwind/seh64_gnu.rs b/src/libstd/sys/common/unwind/seh64_gnu.rs index 92f059d68e1a3..26c2cee9222db 100644 --- a/src/libstd/sys/common/unwind/seh64_gnu.rs +++ b/src/libstd/sys/common/unwind/seh64_gnu.rs @@ -17,12 +17,10 @@ use prelude::v1::*; use any::Any; -use self::EXCEPTION_DISPOSITION::*; use sys_common::dwarf::eh; use core::mem; use core::ptr; -use libc::{c_void, c_ulonglong, DWORD, LPVOID}; -type ULONG_PTR = c_ulonglong; +use sys::c; // Define our exception codes: // according to http://msdn.microsoft.com/en-us/library/het71c37(v=VS.80).aspx, @@ -32,80 +30,10 @@ type ULONG_PTR = c_ulonglong; // we define bits: // [24:27] = type // [0:23] = magic -const ETYPE: DWORD = 0b1110_u32 << 28; -const MAGIC: DWORD = 0x525354; // "RST" +const ETYPE: c::DWORD = 0b1110_u32 << 28; +const MAGIC: c::DWORD = 0x525354; // "RST" -const RUST_PANIC: DWORD = ETYPE | (1 << 24) | MAGIC; - -const EXCEPTION_NONCONTINUABLE: DWORD = 0x1; // Noncontinuable exception -const EXCEPTION_UNWINDING: DWORD = 0x2; // Unwind is in progress -const EXCEPTION_EXIT_UNWIND: DWORD = 0x4; // Exit unwind is in progress -const EXCEPTION_STACK_INVALID: DWORD = 0x8; // Stack out of limits or unaligned -const EXCEPTION_NESTED_CALL: DWORD = 0x10; // Nested exception handler call -const EXCEPTION_TARGET_UNWIND: DWORD = 0x20; // Target unwind in progress -const EXCEPTION_COLLIDED_UNWIND: DWORD = 0x40; // Collided exception handler call -const EXCEPTION_UNWIND: DWORD = EXCEPTION_UNWINDING | - EXCEPTION_EXIT_UNWIND | - EXCEPTION_TARGET_UNWIND | - EXCEPTION_COLLIDED_UNWIND; - -#[repr(C)] -pub struct EXCEPTION_RECORD { - ExceptionCode: DWORD, - ExceptionFlags: DWORD, - ExceptionRecord: *const EXCEPTION_RECORD, - ExceptionAddress: LPVOID, - NumberParameters: DWORD, - ExceptionInformation: [ULONG_PTR; 15], -} - -pub enum CONTEXT {} -pub enum UNWIND_HISTORY_TABLE {} - -#[repr(C)] -pub struct RUNTIME_FUNCTION { - BeginAddress: DWORD, - EndAddress: DWORD, - UnwindData: DWORD, -} - -#[repr(C)] -pub struct DISPATCHER_CONTEXT { - ControlPc: LPVOID, - ImageBase: LPVOID, - FunctionEntry: *const RUNTIME_FUNCTION, - EstablisherFrame: LPVOID, - TargetIp: LPVOID, - ContextRecord: *const CONTEXT, - LanguageHandler: LPVOID, - HandlerData: *const u8, - HistoryTable: *const UNWIND_HISTORY_TABLE, -} - -#[repr(C)] -#[derive(Copy, Clone)] -pub enum EXCEPTION_DISPOSITION { - ExceptionContinueExecution, - ExceptionContinueSearch, - ExceptionNestedException, - ExceptionCollidedUnwind -} - -// From kernel32.dll -extern "system" { - #[unwind] - fn RaiseException(dwExceptionCode: DWORD, - dwExceptionFlags: DWORD, - nNumberOfArguments: DWORD, - lpArguments: *const ULONG_PTR); - - fn RtlUnwindEx(TargetFrame: LPVOID, - TargetIp: LPVOID, - ExceptionRecord: *const EXCEPTION_RECORD, - ReturnValue: LPVOID, - OriginalContext: *const CONTEXT, - HistoryTable: *const UNWIND_HISTORY_TABLE); -} +const RUST_PANIC: c::DWORD = ETYPE | (1 << 24) | MAGIC; #[repr(C)] struct PanicData { @@ -114,11 +42,11 @@ struct PanicData { pub unsafe fn panic(data: Box) -> ! { let panic_ctx = Box::new(PanicData { data: data }); - let params = [Box::into_raw(panic_ctx) as ULONG_PTR]; - RaiseException(RUST_PANIC, - EXCEPTION_NONCONTINUABLE, - params.len() as DWORD, - ¶ms as *const ULONG_PTR); + let params = [Box::into_raw(panic_ctx) as c::ULONG_PTR]; + c::RaiseException(RUST_PANIC, + c::EXCEPTION_NONCONTINUABLE, + params.len() as c::DWORD, + ¶ms as *const c::ULONG_PTR); rtabort!("could not unwind stack"); } @@ -152,11 +80,11 @@ pub unsafe fn cleanup(ptr: *mut u8) -> Box { #[lang = "eh_personality_catch"] #[cfg(not(test))] unsafe extern fn rust_eh_personality_catch( - exceptionRecord: *mut EXCEPTION_RECORD, - establisherFrame: LPVOID, - contextRecord: *mut CONTEXT, - dispatcherContext: *mut DISPATCHER_CONTEXT -) -> EXCEPTION_DISPOSITION + exceptionRecord: *mut c::EXCEPTION_RECORD, + establisherFrame: c::LPVOID, + contextRecord: *mut c::CONTEXT, + dispatcherContext: *mut c::DISPATCHER_CONTEXT +) -> c::EXCEPTION_DISPOSITION { rust_eh_personality(exceptionRecord, establisherFrame, contextRecord, dispatcherContext) @@ -165,44 +93,44 @@ unsafe extern fn rust_eh_personality_catch( #[lang = "eh_personality"] #[cfg(not(test))] unsafe extern fn rust_eh_personality( - exceptionRecord: *mut EXCEPTION_RECORD, - establisherFrame: LPVOID, - contextRecord: *mut CONTEXT, - dispatcherContext: *mut DISPATCHER_CONTEXT -) -> EXCEPTION_DISPOSITION + exceptionRecord: *mut c::EXCEPTION_RECORD, + establisherFrame: c::LPVOID, + contextRecord: *mut c::CONTEXT, + dispatcherContext: *mut c::DISPATCHER_CONTEXT +) -> c::EXCEPTION_DISPOSITION { let er = &*exceptionRecord; let dc = &*dispatcherContext; - if er.ExceptionFlags & EXCEPTION_UNWIND == 0 { // we are in the dispatch phase + if er.ExceptionFlags & c::EXCEPTION_UNWIND == 0 { // we are in the dispatch phase if er.ExceptionCode == RUST_PANIC { if let Some(lpad) = find_landing_pad(dc) { - RtlUnwindEx(establisherFrame, - lpad as LPVOID, - exceptionRecord, - er.ExceptionInformation[0] as LPVOID, // pointer to PanicData - contextRecord, - dc.HistoryTable); + c::RtlUnwindEx(establisherFrame, + lpad as c::LPVOID, + exceptionRecord, + er.ExceptionInformation[0] as c::LPVOID, // pointer to PanicData + contextRecord, + dc.HistoryTable); rtabort!("could not unwind"); } } } - ExceptionContinueSearch + c::ExceptionContinueSearch } #[cfg(not(test))] #[lang = "eh_unwind_resume"] #[unwind] -unsafe extern fn rust_eh_unwind_resume(panic_ctx: LPVOID) -> ! { - let params = [panic_ctx as ULONG_PTR]; - RaiseException(RUST_PANIC, - EXCEPTION_NONCONTINUABLE, - params.len() as DWORD, - ¶ms as *const ULONG_PTR); +unsafe extern fn rust_eh_unwind_resume(panic_ctx: c::LPVOID) -> ! { + let params = [panic_ctx as c::ULONG_PTR]; + c::RaiseException(RUST_PANIC, + c::EXCEPTION_NONCONTINUABLE, + params.len() as c::DWORD, + ¶ms as *const c::ULONG_PTR); rtabort!("could not resume unwind"); } -unsafe fn find_landing_pad(dc: &DISPATCHER_CONTEXT) -> Option { +unsafe fn find_landing_pad(dc: &c::DISPATCHER_CONTEXT) -> Option { let eh_ctx = eh::EHContext { ip: dc.ControlPc as usize, func_start: dc.ImageBase as usize + (*dc.FunctionEntry).BeginAddress as usize, diff --git a/src/libstd/sys/unix/c.rs b/src/libstd/sys/unix/c.rs deleted file mode 100644 index fc6af6447d2fd..0000000000000 --- a/src/libstd/sys/unix/c.rs +++ /dev/null @@ -1,452 +0,0 @@ -// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! C definitions used by std::sys that don't belong in liblibc - -// These are definitions sufficient for the users in this directory. -// This is not a general-purpose binding to this functionality, and in -// some cases (notably the definition of siginfo_t), we intentionally -// have incomplete bindings so that we don't need to fight with unions. -// -// Note that these types need to match the definitions from the platform -// libc (currently glibc on Linux), not the kernel definitions / the -// syscall interface. This has a few weirdnesses, like glibc's sigset_t -// being 1024 bits on all platforms. If you're adding a new GNU/Linux -// port, check glibc's sysdeps/unix/sysv/linux, not the kernel headers. - -#![allow(dead_code)] -#![allow(non_camel_case_types)] - -pub use self::signal_os::*; -use libc; - -#[cfg(any(target_os = "macos", - target_os = "ios", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "bitrig", - target_os = "netbsd", - target_os = "openbsd"))] -pub const FIOCLEX: libc::c_ulong = 0x20006601; - -#[cfg(any(all(target_os = "linux", - any(target_arch = "x86", - target_arch = "x86_64", - target_arch = "arm", - target_arch = "aarch64")), - target_os = "android"))] -pub const FIOCLEX: libc::c_ulong = 0x5451; - -#[cfg(all(target_os = "linux", - any(target_arch = "mips", - target_arch = "mipsel", - target_arch = "powerpc")))] -pub const FIOCLEX: libc::c_ulong = 0x6601; - -#[cfg(target_env = "newlib")] -pub const FD_CLOEXEC: libc::c_int = 1; -#[cfg(target_env = "newlib")] -pub const F_GETFD: libc::c_int = 1; -#[cfg(target_env = "newlib")] -pub const F_SETFD: libc::c_int = 2; - -pub const WNOHANG: libc::c_int = 1; - -#[cfg(target_os = "linux")] -pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 70; -#[cfg(any(target_os = "macos", - target_os = "freebsd", - target_os = "dragonfly"))] -pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 71; -#[cfg(any(target_os = "bitrig", - target_os = "openbsd"))] -pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 101; -#[cfg(target_os = "netbsd")] -pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 48; -#[cfg(target_os = "android")] -pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 0x0048; - -#[repr(C)] -#[cfg(target_os = "linux")] -pub struct passwd { - pub pw_name: *mut libc::c_char, - pub pw_passwd: *mut libc::c_char, - pub pw_uid: libc::uid_t, - pub pw_gid: libc::gid_t, - pub pw_gecos: *mut libc::c_char, - pub pw_dir: *mut libc::c_char, - pub pw_shell: *mut libc::c_char, -} -#[repr(C)] -#[cfg(target_env = "newlib")] -pub struct passwd { - pub pw_name: *mut libc::c_char, - pub pw_passwd: *mut libc::c_char, - pub pw_uid: libc::uid_t, - pub pw_gid: libc::gid_t, - pub pw_comment: *mut libc::c_char, - pub pw_gecos: *mut libc::c_char, - pub pw_dir: *mut libc::c_char, - pub pw_shell: *mut libc::c_char, -} - -#[repr(C)] -#[cfg(any(target_os = "macos", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "bitrig", - target_os = "netbsd", - target_os = "openbsd"))] -pub struct passwd { - pub pw_name: *mut libc::c_char, - pub pw_passwd: *mut libc::c_char, - pub pw_uid: libc::uid_t, - pub pw_gid: libc::gid_t, - pub pw_change: libc::time_t, - pub pw_class: *mut libc::c_char, - pub pw_gecos: *mut libc::c_char, - pub pw_dir: *mut libc::c_char, - pub pw_shell: *mut libc::c_char, - pub pw_expire: libc::time_t, -} - -#[repr(C)] -#[cfg(target_os = "android")] -pub struct passwd { - pub pw_name: *mut libc::c_char, - pub pw_passwd: *mut libc::c_char, - pub pw_uid: libc::uid_t, - pub pw_gid: libc::gid_t, - pub pw_dir: *mut libc::c_char, - pub pw_shell: *mut libc::c_char, -} - -// This is really a function pointer (or a union of multiple function -// pointers), except for constants like SIG_DFL. -pub type sighandler_t = *mut libc::c_void; - -pub const SIG_DFL: sighandler_t = 0 as sighandler_t; -pub const SIG_ERR: sighandler_t = !0 as sighandler_t; - -extern { - pub fn getsockopt(sockfd: libc::c_int, - level: libc::c_int, - optname: libc::c_int, - optval: *mut libc::c_void, - optlen: *mut libc::socklen_t) -> libc::c_int; - #[cfg(not(target_env = "newlib"))] - pub fn ioctl(fd: libc::c_int, req: libc::c_ulong, ...) -> libc::c_int; - #[cfg(target_env = "newlib")] - pub fn fnctl(fd: libc::c_int, req: libc::c_int, ...) -> libc::c_int; - - - pub fn waitpid(pid: libc::pid_t, status: *mut libc::c_int, - options: libc::c_int) -> libc::pid_t; - - pub fn raise(signum: libc::c_int) -> libc::c_int; - - #[cfg_attr(target_os = "netbsd", link_name = "__sigaction14")] - pub fn sigaction(signum: libc::c_int, - act: *const sigaction, - oldact: *mut sigaction) -> libc::c_int; - - #[cfg_attr(target_os = "netbsd", link_name = "__sigaltstack14")] - #[cfg(not(target_env = "newlib"))] - pub fn sigaltstack(ss: *const sigaltstack, - oss: *mut sigaltstack) -> libc::c_int; - - #[cfg(not(target_os = "android"))] - #[cfg_attr(target_os = "netbsd", link_name = "__sigemptyset14")] - pub fn sigemptyset(set: *mut sigset_t) -> libc::c_int; - - pub fn pthread_sigmask(how: libc::c_int, set: *const sigset_t, - oldset: *mut sigset_t) -> libc::c_int; - - #[cfg(not(target_os = "ios"))] - #[cfg_attr(target_os = "netbsd", link_name = "__getpwuid_r50")] - pub fn getpwuid_r(uid: libc::uid_t, - pwd: *mut passwd, - buf: *mut libc::c_char, - buflen: libc::size_t, - result: *mut *mut passwd) -> libc::c_int; - - #[cfg_attr(target_os = "netbsd", link_name = "__utimes50")] - pub fn utimes(filename: *const libc::c_char, - times: *const libc::timeval) -> libc::c_int; - pub fn gai_strerror(errcode: libc::c_int) -> *const libc::c_char; - /// Newlib has this, but only for Cygwin. - #[cfg(not(target_os = "nacl"))] - pub fn setgroups(ngroups: libc::c_int, - ptr: *const libc::c_void) -> libc::c_int; - pub fn realpath(pathname: *const libc::c_char, resolved: *mut libc::c_char) - -> *mut libc::c_char; -} - -// Ugh. This is only available as an inline until Android API 21. -#[cfg(target_os = "android")] -pub unsafe fn sigemptyset(set: *mut sigset_t) -> libc::c_int { - use intrinsics; - intrinsics::write_bytes(set, 0, 1); - return 0; -} - -#[cfg(any(target_os = "linux", - target_os = "android"))] -mod signal_os { - pub use self::arch::{SA_ONSTACK, SA_SIGINFO, SIGBUS, SIG_SETMASK, - sigaction, sigaltstack}; - use libc; - - #[cfg(any(target_arch = "x86", - target_arch = "x86_64", - target_arch = "arm", - target_arch = "mips", - target_arch = "mipsel"))] - pub const SIGSTKSZ: libc::size_t = 8192; - - // This is smaller on musl and Android, but no harm in being generous. - #[cfg(any(target_arch = "aarch64", - target_arch = "powerpc"))] - pub const SIGSTKSZ: libc::size_t = 16384; - - // This definition is intentionally a subset of the C structure: the - // fields after si_code are actually a giant union. We're only - // interested in si_addr for this module, though. - #[repr(C)] - pub struct siginfo { - _signo: libc::c_int, - _errno: libc::c_int, - _code: libc::c_int, - // This structure will need extra padding here for MIPS64. - pub si_addr: *mut libc::c_void - } - - #[cfg(all(target_os = "linux", target_pointer_width = "32"))] - #[repr(C)] - pub struct sigset_t { - __val: [libc::c_ulong; 32], - } - - #[cfg(all(target_os = "linux", target_pointer_width = "64"))] - #[repr(C)] - pub struct sigset_t { - __val: [libc::c_ulong; 16], - } - - // Android for MIPS has a 128-bit sigset_t, but we don't currently - // support it. Android for AArch64 technically has a structure of a - // single ulong. - #[cfg(target_os = "android")] - pub type sigset_t = libc::c_ulong; - - #[cfg(any(target_arch = "x86", - target_arch = "x86_64", - target_arch = "powerpc", - target_arch = "arm", - target_arch = "aarch64"))] - mod arch { - use libc; - use super::super::sighandler_t; - use super::sigset_t; - - pub const SA_ONSTACK: libc::c_ulong = 0x08000000; - pub const SA_SIGINFO: libc::c_ulong = 0x00000004; - - pub const SIGBUS: libc::c_int = 7; - - pub const SIG_SETMASK: libc::c_int = 2; - - #[cfg(target_os = "linux")] - #[repr(C)] - pub struct sigaction { - pub sa_sigaction: sighandler_t, - pub sa_mask: sigset_t, - pub sa_flags: libc::c_ulong, - _restorer: *mut libc::c_void, - } - - #[cfg(all(target_os = "android", target_pointer_width = "32"))] - #[repr(C)] - pub struct sigaction { - pub sa_sigaction: sighandler_t, - pub sa_flags: libc::c_ulong, - _restorer: *mut libc::c_void, - pub sa_mask: sigset_t, - } - - #[cfg(all(target_os = "android", target_pointer_width = "64"))] - #[repr(C)] - pub struct sigaction { - pub sa_flags: libc::c_uint, - pub sa_sigaction: sighandler_t, - pub sa_mask: sigset_t, - _restorer: *mut libc::c_void, - } - - #[repr(C)] - pub struct sigaltstack { - pub ss_sp: *mut libc::c_void, - pub ss_flags: libc::c_int, - pub ss_size: libc::size_t - } - } - - #[cfg(any(target_arch = "mips", - target_arch = "mipsel"))] - mod arch { - use libc; - use super::super::sighandler_t; - use super::sigset_t; - - pub const SA_ONSTACK: libc::c_ulong = 0x08000000; - pub const SA_SIGINFO: libc::c_ulong = 0x00000008; - - pub const SIGBUS: libc::c_int = 10; - - pub const SIG_SETMASK: libc::c_int = 3; - - #[cfg(all(target_os = "linux", not(target_env = "musl")))] - #[repr(C)] - pub struct sigaction { - pub sa_flags: libc::c_uint, - pub sa_sigaction: sighandler_t, - pub sa_mask: sigset_t, - _restorer: *mut libc::c_void, - _resv: [libc::c_int; 1], - } - - #[cfg(target_env = "musl")] - #[repr(C)] - pub struct sigaction { - pub sa_sigaction: sighandler_t, - pub sa_mask: sigset_t, - pub sa_flags: libc::c_ulong, - _restorer: *mut libc::c_void, - } - - #[cfg(target_os = "android")] - #[repr(C)] - pub struct sigaction { - pub sa_flags: libc::c_uint, - pub sa_sigaction: sighandler_t, - pub sa_mask: sigset_t, - } - - #[repr(C)] - pub struct sigaltstack { - pub ss_sp: *mut libc::c_void, - pub ss_size: libc::size_t, - pub ss_flags: libc::c_int, - } - } -} - -/// Note: Although the signal functions are defined on NaCl, they always fail. -/// Also, this could be cfg-ed on newlib instead of nacl, but these structures -/// can differ depending on the platform, so I've played it safe here. -#[cfg(target_os = "nacl")] -mod signal_os { - use libc; - - pub static SA_NOCLDSTOP: libc::c_ulong = 1; - pub static SA_SIGINFO: libc::c_ulong = 2; - - pub type sigset_t = libc::c_ulong; - #[repr(C)] - pub struct sigaction { - pub sa_flags: libc::c_int, - pub sa_mask: sigset_t, - pub handler: extern fn(libc::c_int), - } -} - -#[cfg(any(target_os = "macos", - target_os = "ios", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "bitrig", - target_os = "netbsd", - target_os = "openbsd"))] -mod signal_os { - use libc; - use super::sighandler_t; - - pub const SA_ONSTACK: libc::c_int = 0x0001; - pub const SA_SIGINFO: libc::c_int = 0x0040; - - pub const SIGBUS: libc::c_int = 10; - - #[cfg(any(target_os = "macos", target_os = "ios"))] - pub const SIGSTKSZ: libc::size_t = 131072; - // FreeBSD's is actually arch-dependent, but never more than 40960. - // No harm in being generous. - #[cfg(not(any(target_os = "macos", target_os = "ios")))] - pub const SIGSTKSZ: libc::size_t = 40960; - - pub const SIG_SETMASK: libc::c_int = 3; - - #[cfg(any(target_os = "macos", - target_os = "ios"))] - pub type sigset_t = u32; - #[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "netbsd"))] - #[repr(C)] - pub struct sigset_t { - bits: [u32; 4], - } - #[cfg(any(target_os = "bitrig", target_os = "openbsd"))] - pub type sigset_t = libc::c_uint; - - // This structure has more fields, but we're not all that interested in - // them. - #[cfg(any(target_os = "macos", target_os = "ios", - target_os = "freebsd", target_os = "dragonfly"))] - #[repr(C)] - pub struct siginfo { - pub _signo: libc::c_int, - pub _errno: libc::c_int, - pub _code: libc::c_int, - pub _pid: libc::pid_t, - pub _uid: libc::uid_t, - pub _status: libc::c_int, - pub si_addr: *mut libc::c_void - } - #[cfg(any(target_os = "bitrig", target_os = "netbsd", target_os = "openbsd"))] - #[repr(C)] - pub struct siginfo { - pub si_signo: libc::c_int, - pub si_code: libc::c_int, - pub si_errno: libc::c_int, - pub si_addr: *mut libc::c_void - } - - #[cfg(any(target_os = "macos", target_os = "ios", - target_os = "bitrig", target_os = "netbsd", target_os = "openbsd"))] - #[repr(C)] - pub struct sigaction { - pub sa_sigaction: sighandler_t, - pub sa_mask: sigset_t, - pub sa_flags: libc::c_int, - } - - #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] - #[repr(C)] - pub struct sigaction { - pub sa_sigaction: sighandler_t, - pub sa_flags: libc::c_int, - pub sa_mask: sigset_t, - } - - #[repr(C)] - pub struct sigaltstack { - pub ss_sp: *mut libc::c_void, - pub ss_size: libc::size_t, - pub ss_flags: libc::c_int, - } -} diff --git a/src/libstd/sys/unix/condvar.rs b/src/libstd/sys/unix/condvar.rs index b9538867b252d..3e0f41933e641 100644 --- a/src/libstd/sys/unix/condvar.rs +++ b/src/libstd/sys/unix/condvar.rs @@ -13,10 +13,9 @@ use libc; use ptr; use sys::mutex::{self, Mutex}; use sys::time; -use sys::sync as ffi; use time::Duration; -pub struct Condvar { inner: UnsafeCell } +pub struct Condvar { inner: UnsafeCell } unsafe impl Send for Condvar {} unsafe impl Sync for Condvar {} @@ -25,24 +24,24 @@ impl Condvar { pub const fn new() -> Condvar { // Might be moved and address is changing it is better to avoid // initialization of potentially opaque OS data before it landed - Condvar { inner: UnsafeCell::new(ffi::PTHREAD_COND_INITIALIZER) } + Condvar { inner: UnsafeCell::new(libc::PTHREAD_COND_INITIALIZER) } } #[inline] pub unsafe fn notify_one(&self) { - let r = ffi::pthread_cond_signal(self.inner.get()); + let r = libc::pthread_cond_signal(self.inner.get()); debug_assert_eq!(r, 0); } #[inline] pub unsafe fn notify_all(&self) { - let r = ffi::pthread_cond_broadcast(self.inner.get()); + let r = libc::pthread_cond_broadcast(self.inner.get()); debug_assert_eq!(r, 0); } #[inline] pub unsafe fn wait(&self, mutex: &Mutex) { - let r = ffi::pthread_cond_wait(self.inner.get(), mutex::raw(mutex)); + let r = libc::pthread_cond_wait(self.inner.get(), mutex::raw(mutex)); debug_assert_eq!(r, 0); } @@ -55,7 +54,7 @@ impl Condvar { // report timeout based on stable time. let mut sys_now = libc::timeval { tv_sec: 0, tv_usec: 0 }; let stable_now = time::SteadyTime::now(); - let r = ffi::gettimeofday(&mut sys_now, ptr::null_mut()); + let r = libc::gettimeofday(&mut sys_now, ptr::null_mut()); debug_assert_eq!(r, 0); let nsec = dur.subsec_nanos() as libc::c_long + @@ -76,7 +75,7 @@ impl Condvar { }); // And wait! - let r = ffi::pthread_cond_timedwait(self.inner.get(), mutex::raw(mutex), + let r = libc::pthread_cond_timedwait(self.inner.get(), mutex::raw(mutex), &timeout); debug_assert!(r == libc::ETIMEDOUT || r == 0); @@ -88,17 +87,17 @@ impl Condvar { #[inline] #[cfg(not(target_os = "dragonfly"))] pub unsafe fn destroy(&self) { - let r = ffi::pthread_cond_destroy(self.inner.get()); + let r = libc::pthread_cond_destroy(self.inner.get()); debug_assert_eq!(r, 0); } #[inline] #[cfg(target_os = "dragonfly")] pub unsafe fn destroy(&self) { - let r = ffi::pthread_cond_destroy(self.inner.get()); + let r = libc::pthread_cond_destroy(self.inner.get()); // On DragonFly pthread_cond_destroy() returns EINVAL if called on // a condvar that was just initialized with - // ffi::PTHREAD_COND_INITIALIZER. Once it is used or + // libc::PTHREAD_COND_INITIALIZER. Once it is used or // pthread_cond_init() is called, this behaviour no longer occurs. debug_assert!(r == 0 || r == libc::EINVAL); } diff --git a/src/libstd/sys/unix/fd.rs b/src/libstd/sys/unix/fd.rs index e9f442a22ccee..d42c15a97ac8c 100644 --- a/src/libstd/sys/unix/fd.rs +++ b/src/libstd/sys/unix/fd.rs @@ -11,7 +11,6 @@ use io; use libc::{self, c_int, size_t, c_void}; use mem; -use sys::c; use sys::cvt; use sys_common::AsInner; @@ -54,15 +53,15 @@ impl FileDesc { #[cfg(not(target_env = "newlib"))] pub fn set_cloexec(&self) { unsafe { - let ret = c::ioctl(self.fd, c::FIOCLEX); + let ret = libc::ioctl(self.fd, libc::FIOCLEX); debug_assert_eq!(ret, 0); } } #[cfg(target_env = "newlib")] pub fn set_cloexec(&self) { unsafe { - let previous = c::fnctl(self.fd, c::F_GETFD); - let ret = c::fnctl(self.fd, c::F_SETFD, previous | c::FD_CLOEXEC); + let previous = libc::fnctl(self.fd, libc::F_GETFD); + let ret = libc::fnctl(self.fd, libc::F_SETFD, previous | libc::FD_CLOEXEC); debug_assert_eq!(ret, 0); } } diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index c2145ac875ac3..018c91002880f 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -21,7 +21,7 @@ use ptr; use sync::Arc; use sys::fd::FileDesc; use sys::platform::raw; -use sys::{c, cvt, cvt_r}; +use sys::{cvt, cvt_r}; use sys_common::{AsInner, FromInner}; use vec::Vec; @@ -43,7 +43,7 @@ unsafe impl Send for Dir {} unsafe impl Sync for Dir {} pub struct DirEntry { - buf: Vec, // actually *mut libc::dirent_t + buf: Vec, // actually *mut libc::dirent root: Arc, } @@ -133,7 +133,7 @@ impl Iterator for ReadDir { let mut buf: Vec = Vec::with_capacity(unsafe { rust_dirent_t_size() as usize }); - let ptr = buf.as_mut_ptr() as *mut libc::dirent_t; + let ptr = buf.as_mut_ptr() as *mut libc::dirent; let mut entry_ptr = ptr::null_mut(); loop { @@ -179,7 +179,7 @@ impl DirEntry { pub fn file_type(&self) -> io::Result { extern { - fn rust_dir_get_mode(ptr: *mut libc::dirent_t) -> c_int; + fn rust_dir_get_mode(ptr: *mut libc::dirent) -> c_int; } unsafe { match rust_dir_get_mode(self.dirent()) { @@ -191,21 +191,21 @@ impl DirEntry { pub fn ino(&self) -> raw::ino_t { extern { - fn rust_dir_get_ino(ptr: *mut libc::dirent_t) -> raw::ino_t; + fn rust_dir_get_ino(ptr: *mut libc::dirent) -> raw::ino_t; } unsafe { rust_dir_get_ino(self.dirent()) } } fn name_bytes(&self) -> &[u8] { extern { - fn rust_list_dir_val(ptr: *mut libc::dirent_t) -> *const c_char; + fn rust_list_dir_val(ptr: *mut libc::dirent) -> *const c_char; } unsafe { CStr::from_ptr(rust_list_dir_val(self.dirent())).to_bytes() } } - fn dirent(&self) -> *mut libc::dirent_t { + fn dirent(&self) -> *mut libc::dirent { self.buf.as_ptr() as *mut _ } } @@ -267,7 +267,7 @@ impl File { (false, false) => libc::O_RDONLY, }; let fd = try!(cvt_r(|| unsafe { - libc::open(path.as_ptr(), flags, opts.mode) + libc::open(path.as_ptr(), flags, opts.mode as c_int) })); let fd = FileDesc::new(fd); // Even though we open with the O_CLOEXEC flag, still set CLOEXEC here, @@ -532,7 +532,7 @@ pub fn canonicalize(p: &Path) -> io::Result { let path = try!(CString::new(p.as_os_str().as_bytes())); let buf; unsafe { - let r = c::realpath(path.as_ptr(), ptr::null_mut()); + let r = libc::realpath(path.as_ptr(), ptr::null_mut()); if r.is_null() { return Err(io::Error::last_os_error()) } diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs index 26b6b17cbe41a..68b0c3d6b0ee7 100644 --- a/src/libstd/sys/unix/mod.rs +++ b/src/libstd/sys/unix/mod.rs @@ -28,7 +28,6 @@ use ops::Neg; #[cfg(target_os = "openbsd")] pub use os::openbsd as platform; pub mod backtrace; -pub mod c; pub mod condvar; pub mod ext; pub mod fd; @@ -41,7 +40,6 @@ pub mod pipe; pub mod process; pub mod rwlock; pub mod stack_overflow; -pub mod sync; pub mod thread; pub mod thread_local; pub mod time; @@ -49,7 +47,7 @@ pub mod stdio; #[cfg(not(target_os = "nacl"))] pub fn init() { - use libc::funcs::posix01::signal::signal; + use libc::signal; // By default, some platforms will send a *signal* when an EPIPE error // would otherwise be delivered. This runtime doesn't install a SIGPIPE // handler, causing it to kill the program, which isn't exactly what we @@ -78,7 +76,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { libc::EINTR => ErrorKind::Interrupted, libc::EINVAL => ErrorKind::InvalidInput, libc::ETIMEDOUT => ErrorKind::TimedOut, - libc::consts::os::posix88::EEXIST => ErrorKind::AlreadyExists, + libc::EEXIST => ErrorKind::AlreadyExists, // These two constants can have the same value on some systems, // but different values on others, so we can't use a match diff --git a/src/libstd/sys/unix/mutex.rs b/src/libstd/sys/unix/mutex.rs index e4c231ff971d3..4e4abcfbeee4d 100644 --- a/src/libstd/sys/unix/mutex.rs +++ b/src/libstd/sys/unix/mutex.rs @@ -9,13 +9,13 @@ // except according to those terms. use cell::UnsafeCell; -use sys::sync as ffi; +use libc; use mem; -pub struct Mutex { inner: UnsafeCell } +pub struct Mutex { inner: UnsafeCell } #[inline] -pub unsafe fn raw(m: &Mutex) -> *mut ffi::pthread_mutex_t { +pub unsafe fn raw(m: &Mutex) -> *mut libc::pthread_mutex_t { m.inner.get() } @@ -27,42 +27,42 @@ impl Mutex { pub const fn new() -> Mutex { // Might be moved and address is changing it is better to avoid // initialization of potentially opaque OS data before it landed - Mutex { inner: UnsafeCell::new(ffi::PTHREAD_MUTEX_INITIALIZER) } + Mutex { inner: UnsafeCell::new(libc::PTHREAD_MUTEX_INITIALIZER) } } #[inline] pub unsafe fn lock(&self) { - let r = ffi::pthread_mutex_lock(self.inner.get()); + let r = libc::pthread_mutex_lock(self.inner.get()); debug_assert_eq!(r, 0); } #[inline] pub unsafe fn unlock(&self) { - let r = ffi::pthread_mutex_unlock(self.inner.get()); + let r = libc::pthread_mutex_unlock(self.inner.get()); debug_assert_eq!(r, 0); } #[inline] pub unsafe fn try_lock(&self) -> bool { - ffi::pthread_mutex_trylock(self.inner.get()) == 0 + libc::pthread_mutex_trylock(self.inner.get()) == 0 } #[inline] #[cfg(not(target_os = "dragonfly"))] pub unsafe fn destroy(&self) { - let r = ffi::pthread_mutex_destroy(self.inner.get()); + let r = libc::pthread_mutex_destroy(self.inner.get()); debug_assert_eq!(r, 0); } #[inline] #[cfg(target_os = "dragonfly")] pub unsafe fn destroy(&self) { use libc; - let r = ffi::pthread_mutex_destroy(self.inner.get()); + let r = libc::pthread_mutex_destroy(self.inner.get()); // On DragonFly pthread_mutex_destroy() returns EINVAL if called on a - // mutex that was just initialized with ffi::PTHREAD_MUTEX_INITIALIZER. + // mutex that was just initialized with libc::PTHREAD_MUTEX_INITIALIZER. // Once it is used (locked/unlocked) or pthread_mutex_init() is called, // this behaviour no longer occurs. debug_assert!(r == 0 || r == libc::EINVAL); } } -pub struct ReentrantMutex { inner: UnsafeCell } +pub struct ReentrantMutex { inner: UnsafeCell } unsafe impl Send for ReentrantMutex {} unsafe impl Sync for ReentrantMutex {} @@ -73,35 +73,35 @@ impl ReentrantMutex { } pub unsafe fn init(&mut self) { - let mut attr: ffi::pthread_mutexattr_t = mem::uninitialized(); - let result = ffi::pthread_mutexattr_init(&mut attr as *mut _); + let mut attr: libc::pthread_mutexattr_t = mem::uninitialized(); + let result = libc::pthread_mutexattr_init(&mut attr as *mut _); debug_assert_eq!(result, 0); - let result = ffi::pthread_mutexattr_settype(&mut attr as *mut _, - ffi::PTHREAD_MUTEX_RECURSIVE); + let result = libc::pthread_mutexattr_settype(&mut attr as *mut _, + libc::PTHREAD_MUTEX_RECURSIVE); debug_assert_eq!(result, 0); - let result = ffi::pthread_mutex_init(self.inner.get(), &attr as *const _); + let result = libc::pthread_mutex_init(self.inner.get(), &attr as *const _); debug_assert_eq!(result, 0); - let result = ffi::pthread_mutexattr_destroy(&mut attr as *mut _); + let result = libc::pthread_mutexattr_destroy(&mut attr as *mut _); debug_assert_eq!(result, 0); } pub unsafe fn lock(&self) { - let result = ffi::pthread_mutex_lock(self.inner.get()); + let result = libc::pthread_mutex_lock(self.inner.get()); debug_assert_eq!(result, 0); } #[inline] pub unsafe fn try_lock(&self) -> bool { - ffi::pthread_mutex_trylock(self.inner.get()) == 0 + libc::pthread_mutex_trylock(self.inner.get()) == 0 } pub unsafe fn unlock(&self) { - let result = ffi::pthread_mutex_unlock(self.inner.get()); + let result = libc::pthread_mutex_unlock(self.inner.get()); debug_assert_eq!(result, 0); } pub unsafe fn destroy(&self) { - let result = ffi::pthread_mutex_destroy(self.inner.get()); + let result = libc::pthread_mutex_destroy(self.inner.get()); debug_assert_eq!(result, 0); } } diff --git a/src/libstd/sys/unix/net.rs b/src/libstd/sys/unix/net.rs index 6d65cb838f67a..bcda1d651d69d 100644 --- a/src/libstd/sys/unix/net.rs +++ b/src/libstd/sys/unix/net.rs @@ -13,16 +13,16 @@ use prelude::v1::*; use ffi::CStr; use io; use libc::{self, c_int, size_t}; -use net::SocketAddr; +use net::{SocketAddr, Shutdown}; use str; -use sync::atomic::{self, AtomicBool}; -use sys::c; +use sync::atomic::{AtomicBool, Ordering}; use sys::fd::FileDesc; use sys_common::{AsInner, FromInner, IntoInner}; use sys_common::net::{getsockopt, setsockopt}; use time::Duration; pub use sys::{cvt, cvt_r}; +pub use libc as netc; pub type wrlen_t = size_t; @@ -34,7 +34,7 @@ pub fn cvt_gai(err: c_int) -> io::Result<()> { if err == 0 { return Ok(()) } let detail = unsafe { - str::from_utf8(CStr::from_ptr(c::gai_strerror(err)).to_bytes()).unwrap() + str::from_utf8(CStr::from_ptr(libc::gai_strerror(err)).to_bytes()).unwrap() .to_owned() }; Err(io::Error::new(io::ErrorKind::Other, @@ -67,29 +67,44 @@ impl Socket { } pub fn duplicate(&self) -> io::Result { - use libc::funcs::posix88::fcntl::fcntl; + // We want to atomically duplicate this file descriptor and set the + // CLOEXEC flag, and currently that's done via F_DUPFD_CLOEXEC. This + // flag, however, isn't supported on older Linux kernels (earlier than + // 2.6.24). + // + // To detect this and ensure that CLOEXEC is still set, we + // follow a strategy similar to musl [1] where if passing + // F_DUPFD_CLOEXEC causes `fcntl` to return EINVAL it means it's not + // supported (the third parameter, 0, is always valid), so we stop + // trying that. We also *still* call the `set_cloexec` method as + // apparently some kernel at some point stopped setting CLOEXEC even + // though it reported doing so on F_DUPFD_CLOEXEC. + // + // Also note that Android doesn't have F_DUPFD_CLOEXEC, but get it to + // resolve so we at least compile this. + // + // [1]: http://comments.gmane.org/gmane.linux.lib.musl.general/2963 + #[cfg(target_os = "android")] + use libc::F_DUPFD as F_DUPFD_CLOEXEC; + #[cfg(not(target_os = "android"))] + use libc::F_DUPFD_CLOEXEC; + let make_socket = |fd| { let fd = FileDesc::new(fd); fd.set_cloexec(); Socket(fd) }; - static EMULATE_F_DUPFD_CLOEXEC: AtomicBool = AtomicBool::new(false); - if !EMULATE_F_DUPFD_CLOEXEC.load(atomic::Ordering::Relaxed) { - match cvt(unsafe { fcntl(self.0.raw(), libc::F_DUPFD_CLOEXEC, 0) }) { - // `EINVAL` can only be returned on two occasions: Invalid - // command (second parameter) or invalid third parameter. 0 is - // always a valid third parameter, so it must be the second - // parameter. - // - // Store the result in a global variable so we don't try each - // syscall twice. + static TRY_CLOEXEC: AtomicBool = AtomicBool::new(true); + let fd = self.0.raw(); + if !cfg!(target_os = "android") && TRY_CLOEXEC.load(Ordering::Relaxed) { + match cvt(unsafe { libc::fcntl(fd, F_DUPFD_CLOEXEC, 0) }) { Err(ref e) if e.raw_os_error() == Some(libc::EINVAL) => { - EMULATE_F_DUPFD_CLOEXEC.store(true, atomic::Ordering::Relaxed); + TRY_CLOEXEC.store(false, Ordering::Relaxed); } res => return res.map(make_socket), } } - cvt(unsafe { fcntl(self.0.raw(), libc::F_DUPFD, 0) }).map(make_socket) + cvt(unsafe { libc::fcntl(fd, libc::F_DUPFD, 0) }).map(make_socket) } pub fn read(&self, buf: &mut [u8]) -> io::Result { @@ -138,6 +153,16 @@ impl Socket { Ok(Some(Duration::new(sec, nsec))) } } + + pub fn shutdown(&self, how: Shutdown) -> io::Result<()> { + let how = match how { + Shutdown::Write => libc::SHUT_WR, + Shutdown::Read => libc::SHUT_RD, + Shutdown::Both => libc::SHUT_RDWR, + }; + try!(cvt(unsafe { libc::shutdown(self.0.raw(), how) })); + Ok(()) + } } impl AsInner for Socket { diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 4e7058d06879e..3c53db53f85f1 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -27,9 +27,8 @@ use ptr; use slice; use str; use sync::StaticMutex; -use sys::c; -use sys::fd; use sys::cvt; +use sys::fd; use vec; const TMPBUF_SZ: usize = 128; @@ -230,8 +229,11 @@ pub fn current_exe() -> io::Result { #[cfg(any(target_os = "macos", target_os = "ios"))] pub fn current_exe() -> io::Result { + extern { + fn _NSGetExecutablePath(buf: *mut libc::c_char, + bufsize: *mut u32) -> libc::c_int; + } unsafe { - use libc::funcs::extra::_NSGetExecutablePath; let mut sz: u32 = 0; _NSGetExecutablePath(ptr::null_mut(), &mut sz); if sz == 0 { return Err(io::Error::last_os_error()); } @@ -425,7 +427,7 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { let v = try!(CString::new(v.as_bytes())); let _g = ENV_LOCK.lock(); cvt(unsafe { - libc::funcs::posix01::unistd::setenv(k.as_ptr(), v.as_ptr(), 1) + libc::setenv(k.as_ptr(), v.as_ptr(), 1) }).map(|_| ()) } @@ -433,7 +435,7 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> { let nbuf = try!(CString::new(n.as_bytes())); let _g = ENV_LOCK.lock(); cvt(unsafe { - libc::funcs::posix01::unistd::unsetenv(nbuf.as_ptr()) + libc::unsetenv(nbuf.as_ptr()) }).map(|_| ()) } @@ -466,18 +468,18 @@ pub fn home_dir() -> Option { target_os = "ios", target_os = "nacl")))] unsafe fn fallback() -> Option { - let amt = match libc::sysconf(c::_SC_GETPW_R_SIZE_MAX) { + let amt = match libc::sysconf(libc::_SC_GETPW_R_SIZE_MAX) { n if n < 0 => 512 as usize, n => n as usize, }; let me = libc::getuid(); loop { let mut buf = Vec::with_capacity(amt); - let mut passwd: c::passwd = mem::zeroed(); + let mut passwd: libc::passwd = mem::zeroed(); let mut result = ptr::null_mut(); - match c::getpwuid_r(me, &mut passwd, buf.as_mut_ptr(), - buf.capacity() as libc::size_t, - &mut result) { + match libc::getpwuid_r(me, &mut passwd, buf.as_mut_ptr(), + buf.capacity() as libc::size_t, + &mut result) { 0 if !result.is_null() => {} _ => return None } diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs index 7e37238c23b56..8d80296ab035a 100644 --- a/src/libstd/sys/unix/process.rs +++ b/src/libstd/sys/unix/process.rs @@ -23,7 +23,7 @@ use ptr; use sys::fd::FileDesc; use sys::fs::{File, OpenOptions}; use sys::pipe::AnonPipe; -use sys::{self, c, cvt, cvt_r}; +use sys::{self, cvt, cvt_r}; //////////////////////////////////////////////////////////////////////////////// // Command @@ -163,7 +163,7 @@ const CLOEXEC_MSG_FOOTER: &'static [u8] = b"NOEX"; impl Process { pub unsafe fn kill(&self) -> io::Result<()> { - try!(cvt(libc::funcs::posix88::signal::kill(self.pid, libc::SIGKILL))); + try!(cvt(libc::kill(self.pid, libc::SIGKILL))); Ok(()) } @@ -326,7 +326,7 @@ impl Process { // fail if we aren't root, so don't bother checking the // return value, this is just done as an optimistic // privilege dropping function. - let _ = c::setgroups(0, ptr::null()); + let _ = libc::setgroups(0, ptr::null()); if libc::setuid(u as libc::uid_t) != 0 { fail(&mut output); @@ -355,12 +355,12 @@ impl Process { // UNIX programs do not reset these things on their own, so we // need to clean things up now to avoid confusing the program // we're about to run. - let mut set: c::sigset_t = mem::uninitialized(); - if c::sigemptyset(&mut set) != 0 || - c::pthread_sigmask(c::SIG_SETMASK, &set, ptr::null_mut()) != 0 || - libc::funcs::posix01::signal::signal( - libc::SIGPIPE, mem::transmute(c::SIG_DFL) - ) == mem::transmute(c::SIG_ERR) + let mut set: libc::sigset_t = mem::uninitialized(); + if libc::sigemptyset(&mut set) != 0 || + libc::pthread_sigmask(libc::SIG_SETMASK, &set, ptr::null_mut()) != 0 || + libc::signal( + libc::SIGPIPE, mem::transmute(libc::SIG_DFL) + ) == mem::transmute(libc::SIG_ERR) { fail(output); } @@ -381,14 +381,14 @@ impl Process { pub fn wait(&self) -> io::Result { let mut status = 0 as c_int; - try!(cvt_r(|| unsafe { c::waitpid(self.pid, &mut status, 0) })); + try!(cvt_r(|| unsafe { libc::waitpid(self.pid, &mut status, 0) })); Ok(ExitStatus(status)) } pub fn try_wait(&self) -> Option { let mut status = 0 as c_int; match cvt_r(|| unsafe { - c::waitpid(self.pid, &mut status, c::WNOHANG) + libc::waitpid(self.pid, &mut status, libc::WNOHANG) }) { Ok(0) => None, Ok(n) if n == self.pid => Some(ExitStatus(status)), @@ -459,7 +459,7 @@ mod tests { use ptr; use libc; use slice; - use sys::{self, c, cvt, pipe}; + use sys::{self, cvt, pipe}; macro_rules! t { ($e:expr) => { @@ -473,12 +473,12 @@ mod tests { #[cfg(not(target_os = "android"))] extern { #[cfg_attr(target_os = "netbsd", link_name = "__sigaddset14")] - fn sigaddset(set: *mut c::sigset_t, signum: libc::c_int) -> libc::c_int; + fn sigaddset(set: *mut libc::sigset_t, signum: libc::c_int) -> libc::c_int; } #[cfg(target_os = "android")] - unsafe fn sigaddset(set: *mut c::sigset_t, signum: libc::c_int) -> libc::c_int { - let raw = slice::from_raw_parts_mut(set as *mut u8, mem::size_of::()); + unsafe fn sigaddset(set: *mut libc::sigset_t, signum: libc::c_int) -> libc::c_int { + let raw = slice::from_raw_parts_mut(set as *mut u8, mem::size_of::()); let bit = (signum - 1) as usize; raw[bit / 8] |= 1 << (bit % 8); return 0; @@ -497,11 +497,11 @@ mod tests { let (stdin_read, stdin_write) = t!(sys::pipe::anon_pipe()); let (stdout_read, stdout_write) = t!(sys::pipe::anon_pipe()); - let mut set: c::sigset_t = mem::uninitialized(); - let mut old_set: c::sigset_t = mem::uninitialized(); - t!(cvt(c::sigemptyset(&mut set))); + let mut set: libc::sigset_t = mem::uninitialized(); + let mut old_set: libc::sigset_t = mem::uninitialized(); + t!(cvt(libc::sigemptyset(&mut set))); t!(cvt(sigaddset(&mut set, libc::SIGINT))); - t!(cvt(c::pthread_sigmask(c::SIG_SETMASK, &set, &mut old_set))); + t!(cvt(libc::pthread_sigmask(libc::SIG_SETMASK, &set, &mut old_set))); let cat = t!(Process::spawn(&cmd, Stdio::Raw(stdin_read.raw()), Stdio::Raw(stdout_write.raw()), @@ -509,11 +509,10 @@ mod tests { drop(stdin_read); drop(stdout_write); - t!(cvt(c::pthread_sigmask(c::SIG_SETMASK, &old_set, - ptr::null_mut()))); + t!(cvt(libc::pthread_sigmask(libc::SIG_SETMASK, &old_set, + ptr::null_mut()))); - t!(cvt(libc::funcs::posix88::signal::kill(cat.id() as libc::pid_t, - libc::SIGINT))); + t!(cvt(libc::kill(cat.id() as libc::pid_t, libc::SIGINT))); // We need to wait until SIGINT is definitely delivered. The // easiest way is to write something to cat, and try to read it // back: if SIGINT is unmasked, it'll get delivered when cat is diff --git a/src/libstd/sys/unix/rwlock.rs b/src/libstd/sys/unix/rwlock.rs index 788bff6243018..44bd5d895f2e4 100644 --- a/src/libstd/sys/unix/rwlock.rs +++ b/src/libstd/sys/unix/rwlock.rs @@ -10,20 +10,19 @@ use libc; use cell::UnsafeCell; -use sys::sync as ffi; -pub struct RWLock { inner: UnsafeCell } +pub struct RWLock { inner: UnsafeCell } unsafe impl Send for RWLock {} unsafe impl Sync for RWLock {} impl RWLock { pub const fn new() -> RWLock { - RWLock { inner: UnsafeCell::new(ffi::PTHREAD_RWLOCK_INITIALIZER) } + RWLock { inner: UnsafeCell::new(libc::PTHREAD_RWLOCK_INITIALIZER) } } #[inline] pub unsafe fn read(&self) { - let r = ffi::pthread_rwlock_rdlock(self.inner.get()); + let r = libc::pthread_rwlock_rdlock(self.inner.get()); // According to the pthread_rwlock_rdlock spec, this function **may** // fail with EDEADLK if a deadlock is detected. On the other hand @@ -44,11 +43,11 @@ impl RWLock { } #[inline] pub unsafe fn try_read(&self) -> bool { - ffi::pthread_rwlock_tryrdlock(self.inner.get()) == 0 + libc::pthread_rwlock_tryrdlock(self.inner.get()) == 0 } #[inline] pub unsafe fn write(&self) { - let r = ffi::pthread_rwlock_wrlock(self.inner.get()); + let r = libc::pthread_rwlock_wrlock(self.inner.get()); // see comments above for why we check for EDEADLK if r == libc::EDEADLK { panic!("rwlock write lock would result in deadlock"); @@ -58,21 +57,21 @@ impl RWLock { } #[inline] pub unsafe fn try_write(&self) -> bool { - ffi::pthread_rwlock_trywrlock(self.inner.get()) == 0 + libc::pthread_rwlock_trywrlock(self.inner.get()) == 0 } #[inline] pub unsafe fn read_unlock(&self) { - let r = ffi::pthread_rwlock_unlock(self.inner.get()); + let r = libc::pthread_rwlock_unlock(self.inner.get()); debug_assert_eq!(r, 0); } #[inline] pub unsafe fn write_unlock(&self) { self.read_unlock() } #[inline] pub unsafe fn destroy(&self) { - let r = ffi::pthread_rwlock_destroy(self.inner.get()); + let r = libc::pthread_rwlock_destroy(self.inner.get()); // On DragonFly pthread_rwlock_destroy() returns EINVAL if called on a // rwlock that was just initialized with - // ffi::PTHREAD_RWLOCK_INITIALIZER. Once it is used (locked/unlocked) + // libc::PTHREAD_RWLOCK_INITIALIZER. Once it is used (locked/unlocked) // or pthread_rwlock_init() is called, this behaviour no longer occurs. if cfg!(target_os = "dragonfly") { debug_assert!(r == 0 || r == libc::EINVAL); diff --git a/src/libstd/sys/unix/stack_overflow.rs b/src/libstd/sys/unix/stack_overflow.rs index 5f624bc76b3e8..9a7f98d24cd5d 100644 --- a/src/libstd/sys/unix/stack_overflow.rs +++ b/src/libstd/sys/unix/stack_overflow.rs @@ -43,11 +43,11 @@ mod imp { use sys_common::util::report_overflow; use mem; use ptr; - use sys::c::{siginfo, sigaction, SIGBUS, SIG_DFL, - SA_SIGINFO, SA_ONSTACK, sigaltstack, - SIGSTKSZ, sighandler_t}; + use libc::{sigaction, SIGBUS, SIG_DFL, + SA_SIGINFO, SA_ONSTACK, sigaltstack, + SIGSTKSZ, sighandler_t}; use libc; - use libc::funcs::posix88::mman::{mmap, munmap}; + use libc::{mmap, munmap}; use libc::{SIGSEGV, PROT_READ, PROT_WRITE, MAP_PRIVATE, MAP_ANON}; use libc::MAP_FAILED; @@ -57,6 +57,22 @@ mod imp { // This is initialized in init() and only read from after static mut PAGE_SIZE: usize = 0; + #[cfg(any(target_os = "linux", target_os = "android"))] + unsafe fn siginfo_si_addr(info: *mut libc::siginfo_t) -> *mut libc::c_void { + #[repr(C)] + struct siginfo_t { + a: [libc::c_int; 3], // si_signo, si_code, si_errno, + si_addr: *mut libc::c_void, + } + + (*(info as *const siginfo_t)).si_addr + } + + #[cfg(not(any(target_os = "linux", target_os = "android")))] + unsafe fn siginfo_si_addr(info: *mut libc::siginfo_t) -> *mut libc::c_void { + (*info).si_addr + } + // Signal handler for the SIGSEGV and SIGBUS handlers. We've got guard pages // (unmapped pages) at the end of every thread's stack, so if a thread ends // up running into the guard page it'll trigger this handler. We want to @@ -76,10 +92,10 @@ mod imp { // handler to work. For a more detailed explanation see the comments on // #26458. unsafe extern fn signal_handler(signum: libc::c_int, - info: *mut siginfo, + info: *mut libc::siginfo_t, _data: *mut libc::c_void) { let guard = thread_info::stack_guard().unwrap_or(0); - let addr = (*info).si_addr as usize; + let addr = siginfo_si_addr(info) as usize; // If the faulting address is within the guard page, then we print a // message saying so. @@ -126,7 +142,7 @@ mod imp { panic!("failed to allocate an alternative stack"); } - let mut stack: sigaltstack = mem::zeroed(); + let mut stack: libc::stack_t = mem::zeroed(); stack.ss_sp = alt_stack; stack.ss_flags = 0; diff --git a/src/libstd/sys/unix/sync.rs b/src/libstd/sys/unix/sync.rs deleted file mode 100644 index 6f6acc2560e0c..0000000000000 --- a/src/libstd/sys/unix/sync.rs +++ /dev/null @@ -1,374 +0,0 @@ -// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![allow(bad_style)] - -use libc; - -pub use self::os::{PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_RECURSIVE, pthread_mutex_t, - pthread_mutexattr_t}; -pub use self::os::{PTHREAD_COND_INITIALIZER, pthread_cond_t}; -pub use self::os::{PTHREAD_RWLOCK_INITIALIZER, pthread_rwlock_t}; - -extern { - // mutexes - pub fn pthread_mutex_init(lock: *mut pthread_mutex_t, attr: *const pthread_mutexattr_t) - -> libc::c_int; - pub fn pthread_mutex_destroy(lock: *mut pthread_mutex_t) -> libc::c_int; - pub fn pthread_mutex_lock(lock: *mut pthread_mutex_t) -> libc::c_int; - pub fn pthread_mutex_trylock(lock: *mut pthread_mutex_t) -> libc::c_int; - pub fn pthread_mutex_unlock(lock: *mut pthread_mutex_t) -> libc::c_int; - - pub fn pthread_mutexattr_init(attr: *mut pthread_mutexattr_t) -> libc::c_int; - pub fn pthread_mutexattr_destroy(attr: *mut pthread_mutexattr_t) -> libc::c_int; - pub fn pthread_mutexattr_settype(attr: *mut pthread_mutexattr_t, _type: libc::c_int) - -> libc::c_int; - - // cvars - pub fn pthread_cond_wait(cond: *mut pthread_cond_t, - lock: *mut pthread_mutex_t) -> libc::c_int; - #[cfg_attr(target_os = "nacl", link_name = "pthread_cond_timedwait_abs")] - pub fn pthread_cond_timedwait(cond: *mut pthread_cond_t, - lock: *mut pthread_mutex_t, - abstime: *const libc::timespec) -> libc::c_int; - pub fn pthread_cond_signal(cond: *mut pthread_cond_t) -> libc::c_int; - pub fn pthread_cond_broadcast(cond: *mut pthread_cond_t) -> libc::c_int; - pub fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> libc::c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__gettimeofday50")] - pub fn gettimeofday(tp: *mut libc::timeval, - tz: *mut libc::c_void) -> libc::c_int; - - // rwlocks - pub fn pthread_rwlock_destroy(lock: *mut pthread_rwlock_t) -> libc::c_int; - pub fn pthread_rwlock_rdlock(lock: *mut pthread_rwlock_t) -> libc::c_int; - pub fn pthread_rwlock_tryrdlock(lock: *mut pthread_rwlock_t) -> libc::c_int; - pub fn pthread_rwlock_wrlock(lock: *mut pthread_rwlock_t) -> libc::c_int; - pub fn pthread_rwlock_trywrlock(lock: *mut pthread_rwlock_t) -> libc::c_int; - pub fn pthread_rwlock_unlock(lock: *mut pthread_rwlock_t) -> libc::c_int; -} - -#[cfg(any(target_os = "freebsd", - target_os = "dragonfly", - target_os = "bitrig", - target_os = "openbsd"))] -mod os { - use libc; - use ptr; - - pub type pthread_mutex_t = *mut libc::c_void; - pub type pthread_mutexattr_t = *mut libc::c_void; - pub type pthread_cond_t = *mut libc::c_void; - pub type pthread_rwlock_t = *mut libc::c_void; - - pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = ptr::null_mut(); - pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = ptr::null_mut(); - pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = ptr::null_mut(); - pub const PTHREAD_MUTEX_RECURSIVE: libc::c_int = 2; -} - -#[cfg(any(target_os = "macos", target_os = "ios"))] -mod os { - use libc; - - #[cfg(any(target_arch = "x86_64", - target_arch = "aarch64"))] - const __PTHREAD_MUTEX_SIZE__: usize = 56; - #[cfg(any(target_arch = "x86", - target_arch = "arm"))] - const __PTHREAD_MUTEX_SIZE__: usize = 40; - - #[cfg(any(target_arch = "x86_64", - target_arch = "aarch64"))] - const __PTHREAD_COND_SIZE__: usize = 40; - #[cfg(any(target_arch = "x86", - target_arch = "arm"))] - const __PTHREAD_COND_SIZE__: usize = 24; - - #[cfg(any(target_arch = "x86_64", - target_arch = "aarch64"))] - const __PTHREAD_RWLOCK_SIZE__: usize = 192; - #[cfg(any(target_arch = "x86", - target_arch = "arm"))] - const __PTHREAD_RWLOCK_SIZE__: usize = 124; - - const _PTHREAD_MUTEX_SIG_INIT: libc::c_long = 0x32AAABA7; - const _PTHREAD_COND_SIG_INIT: libc::c_long = 0x3CB0B1BB; - const _PTHREAD_RWLOCK_SIG_INIT: libc::c_long = 0x2DA8B3B4; - - #[repr(C)] - pub struct pthread_mutex_t { - __sig: libc::c_long, - __opaque: [u8; __PTHREAD_MUTEX_SIZE__], - } - #[repr(C)] - pub struct pthread_mutexattr_t { - __sig: libc::c_long, - // note, that this is 16 bytes just to be safe, the actual struct might be smaller. - __opaque: [u8; 16], - } - #[repr(C)] - pub struct pthread_cond_t { - __sig: libc::c_long, - __opaque: [u8; __PTHREAD_COND_SIZE__], - } - #[repr(C)] - pub struct pthread_rwlock_t { - __sig: libc::c_long, - __opaque: [u8; __PTHREAD_RWLOCK_SIZE__], - } - - pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { - __sig: _PTHREAD_MUTEX_SIG_INIT, - __opaque: [0; __PTHREAD_MUTEX_SIZE__], - }; - pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { - __sig: _PTHREAD_COND_SIG_INIT, - __opaque: [0; __PTHREAD_COND_SIZE__], - }; - pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { - __sig: _PTHREAD_RWLOCK_SIG_INIT, - __opaque: [0; __PTHREAD_RWLOCK_SIZE__], - }; - - pub const PTHREAD_MUTEX_RECURSIVE: libc::c_int = 2; -} - -#[cfg(target_os = "linux")] -mod os { - use libc; - - // minus 8 because we have an 'align' field - #[cfg(target_arch = "x86_64")] - const __SIZEOF_PTHREAD_MUTEX_T: usize = 40 - 8; - #[cfg(any(target_arch = "x86", - target_arch = "arm", - target_arch = "mips", - target_arch = "mipsel", - target_arch = "powerpc"))] - const __SIZEOF_PTHREAD_MUTEX_T: usize = 24 - 8; - #[cfg(target_arch = "aarch64")] - const __SIZEOF_PTHREAD_MUTEX_T: usize = 48 - 8; - - #[cfg(any(target_arch = "x86_64", - target_arch = "x86", - target_arch = "arm", - target_arch = "aarch64", - target_arch = "mips", - target_arch = "mipsel", - target_arch = "powerpc"))] - const __SIZEOF_PTHREAD_COND_T: usize = 48 - 8; - - #[cfg(any(target_arch = "x86_64", - target_arch = "aarch64"))] - const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56 - 8; - - #[cfg(any(target_arch = "x86", - target_arch = "arm", - target_arch = "mips", - target_arch = "mipsel", - target_arch = "powerpc"))] - const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32 - 8; - - #[repr(C)] - pub struct pthread_mutex_t { - __align: libc::c_longlong, - size: [u8; __SIZEOF_PTHREAD_MUTEX_T], - } - #[repr(C)] - pub struct pthread_mutexattr_t { - __align: libc::c_longlong, - // note, that this is 16 bytes just to be safe, the actual struct might be smaller. - size: [u8; 16], - } - #[repr(C)] - pub struct pthread_cond_t { - __align: libc::c_longlong, - size: [u8; __SIZEOF_PTHREAD_COND_T], - } - #[repr(C)] - pub struct pthread_rwlock_t { - __align: libc::c_longlong, - size: [u8; __SIZEOF_PTHREAD_RWLOCK_T], - } - - pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { - __align: 0, - size: [0; __SIZEOF_PTHREAD_MUTEX_T], - }; - pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { - __align: 0, - size: [0; __SIZEOF_PTHREAD_COND_T], - }; - pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { - __align: 0, - size: [0; __SIZEOF_PTHREAD_RWLOCK_T], - }; - pub const PTHREAD_MUTEX_RECURSIVE: libc::c_int = 1; -} -#[cfg(target_os = "android")] -mod os { - use libc; - use ptr; - - #[repr(C)] - pub struct pthread_mutex_t { value: libc::c_int } - pub type pthread_mutexattr_t = libc::c_long; - #[repr(C)] - pub struct pthread_cond_t { value: libc::c_int } - #[repr(C)] - pub struct pthread_rwlock_t { - lock: pthread_mutex_t, - cond: pthread_cond_t, - numLocks: libc::c_int, - writerThreadId: libc::c_int, - pendingReaders: libc::c_int, - pendingWriters: libc::c_int, - reserved: [*mut libc::c_void; 4], - } - - pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { - value: 0, - }; - pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { - value: 0, - }; - pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { - lock: PTHREAD_MUTEX_INITIALIZER, - cond: PTHREAD_COND_INITIALIZER, - numLocks: 0, - writerThreadId: 0, - pendingReaders: 0, - pendingWriters: 0, - reserved: [ptr::null_mut(); 4], - }; - pub const PTHREAD_MUTEX_RECURSIVE: libc::c_int = 1; -} - -#[cfg(target_os = "netbsd")] -mod os { - use libc; - - // size of the type minus width of the magic and alignment field - #[cfg(target_arch = "x86_64")] - const __PTHREAD_MUTEX_SIZE__: usize = 48 - 4 - 8; - - #[cfg(target_arch = "x86_64")] - const __PTHREAD_MUTEXATTR_SIZE__: usize = 16 - 8; // no magic field - - #[cfg(target_arch = "x86_64")] - const __PTHREAD_COND_SIZE__: usize = 40 - 4 - 8; - - #[cfg(target_arch = "x86_64")] - const __PTHREAD_RWLOCK_SIZE__: usize = 64 - 4 - 8; - - const _PTHREAD_MUTEX_MAGIC_INIT: libc::c_uint = 0x33330003; - const _PTHREAD_COND_MAGIC_INIT: libc::c_uint = 0x55550005; - const _PTHREAD_RWLOCK_MAGIC_INIT: libc::c_uint = 0x99990009; - - #[repr(C)] - pub struct pthread_mutex_t { - __magic: libc::c_uint, - __opaque: [u8; __PTHREAD_MUTEX_SIZE__], - __align: libc::c_longlong, - } - #[repr(C)] - pub struct pthread_mutexattr_t { - __opaque: [u8; __PTHREAD_MUTEXATTR_SIZE__], - __align: libc::c_longlong, - } - #[repr(C)] - pub struct pthread_cond_t { - __magic: libc::c_uint, - __opaque: [u8; __PTHREAD_COND_SIZE__], - __align: libc::c_longlong, - } - #[repr(C)] - pub struct pthread_rwlock_t { - __magic: libc::c_uint, - __opaque: [u8; __PTHREAD_RWLOCK_SIZE__], - __align: libc::c_longlong, - } - - pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { - __magic: _PTHREAD_MUTEX_MAGIC_INIT, - __opaque: [0; __PTHREAD_MUTEX_SIZE__], - __align: 0, - }; - pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { - __magic: _PTHREAD_COND_MAGIC_INIT, - __opaque: [0; __PTHREAD_COND_SIZE__], - __align: 0, - }; - pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { - __magic: _PTHREAD_RWLOCK_MAGIC_INIT, - __opaque: [0; __PTHREAD_RWLOCK_SIZE__], - __align: 0, - }; - - pub const PTHREAD_MUTEX_RECURSIVE: libc::c_int = 2; -} -#[cfg(target_os = "nacl")] -mod os { - use libc; - - pub type __nc_basic_thread_data = libc::c_void; - - #[repr(C)] - pub struct pthread_mutex_t { - mutex_state: libc::c_int, - mutex_type: libc::c_int, - owner_thread_id: *mut __nc_basic_thread_data, - recursion_counter: libc::uint32_t, - _unused: libc::c_int, - } - #[repr(C)] - pub struct pthread_mutexattr_t { - kind: libc::c_int, - } - #[repr(C)] - pub struct pthread_cond_t { - sequence_number: libc::c_int, - _unused: libc::c_int, - } - #[repr(C)] - pub struct pthread_rwlock_t { - mutex: pthread_mutex_t, - reader_count: libc::c_int, - writers_waiting: libc::c_int, - writer_thread_id: *mut __nc_basic_thread_data, - read_possible: pthread_cond_t, - write_possible: pthread_cond_t, - } - - const NC_INVALID_HANDLE: libc::c_int = -1; - const NACL_PTHREAD_ILLEGAL_THREAD_ID: *mut __nc_basic_thread_data - = 0 as *mut __nc_basic_thread_data; - - pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { - mutex_state: 0, - mutex_type: 0, - owner_thread_id: NACL_PTHREAD_ILLEGAL_THREAD_ID, - recursion_counter: 0, - _unused: NC_INVALID_HANDLE, - }; - pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { - sequence_number: 0, - _unused: NC_INVALID_HANDLE, - }; - pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { - mutex: PTHREAD_MUTEX_INITIALIZER, - reader_count: 0, - writers_waiting: 0, - writer_thread_id: NACL_PTHREAD_ILLEGAL_THREAD_ID, - read_possible: PTHREAD_COND_INITIALIZER, - write_possible: PTHREAD_COND_INITIALIZER, - }; - pub const PTHREAD_MUTEX_RECURSIVE: libc::c_int = 1; -} diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index 3eedb76c21b72..f111f97be60a0 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -17,7 +17,7 @@ use cmp; #[cfg(not(target_env = "newlib"))] use ffi::CString; use io; -use libc::consts::os::posix01::PTHREAD_STACK_MIN; +use libc::PTHREAD_STACK_MIN; use libc; use mem; use ptr; @@ -41,10 +41,11 @@ impl Thread { let p = box p; let mut native: libc::pthread_t = mem::zeroed(); let mut attr: libc::pthread_attr_t = mem::zeroed(); - assert_eq!(pthread_attr_init(&mut attr), 0); + assert_eq!(libc::pthread_attr_init(&mut attr), 0); let stack_size = cmp::max(stack, min_stack_size(&attr)); - match pthread_attr_setstacksize(&mut attr, stack_size as libc::size_t) { + match libc::pthread_attr_setstacksize(&mut attr, + stack_size as libc::size_t) { 0 => {} n => { assert_eq!(n, libc::EINVAL); @@ -56,13 +57,14 @@ impl Thread { let stack_size = (stack_size + page_size - 1) & (-(page_size as isize - 1) as usize - 1); let stack_size = stack_size as libc::size_t; - assert_eq!(pthread_attr_setstacksize(&mut attr, stack_size), 0); + assert_eq!(libc::pthread_attr_setstacksize(&mut attr, + stack_size), 0); } }; - let ret = pthread_create(&mut native, &attr, thread_start, - &*p as *const _ as *mut _); - assert_eq!(pthread_attr_destroy(&mut attr), 0); + let ret = libc::pthread_create(&mut native, &attr, thread_start, + &*p as *const _ as *mut _); + assert_eq!(libc::pthread_attr_destroy(&mut attr), 0); return if ret != 0 { Err(io::Error::from_raw_os_error(ret)) @@ -78,25 +80,20 @@ impl Thread { } pub fn yield_now() { - let ret = unsafe { sched_yield() }; + let ret = unsafe { libc::sched_yield() }; debug_assert_eq!(ret, 0); } #[cfg(any(target_os = "linux", target_os = "android"))] pub fn set_name(name: &str) { - // pthread wrapper only appeared in glibc 2.12, so we use syscall - // directly. - extern { - fn prctl(option: libc::c_int, arg2: libc::c_ulong, - arg3: libc::c_ulong, arg4: libc::c_ulong, - arg5: libc::c_ulong) -> libc::c_int; - } const PR_SET_NAME: libc::c_int = 15; let cname = CString::new(name).unwrap_or_else(|_| { panic!("thread name may not contain interior null bytes") }); + // pthread wrapper only appeared in glibc 2.12, so we use syscall + // directly. unsafe { - prctl(PR_SET_NAME, cname.as_ptr() as libc::c_ulong, 0, 0, 0); + libc::prctl(PR_SET_NAME, cname.as_ptr() as libc::c_ulong, 0, 0, 0); } } @@ -105,39 +102,27 @@ impl Thread { target_os = "bitrig", target_os = "openbsd"))] pub fn set_name(name: &str) { - extern { - fn pthread_set_name_np(tid: libc::pthread_t, - name: *const libc::c_char); - } let cname = CString::new(name).unwrap(); unsafe { - pthread_set_name_np(pthread_self(), cname.as_ptr()); + libc::pthread_set_name_np(libc::pthread_self(), cname.as_ptr()); } } #[cfg(any(target_os = "macos", target_os = "ios"))] pub fn set_name(name: &str) { - extern { - fn pthread_setname_np(name: *const libc::c_char) -> libc::c_int; - } let cname = CString::new(name).unwrap(); unsafe { - pthread_setname_np(cname.as_ptr()); + libc::pthread_setname_np(cname.as_ptr()); } } #[cfg(target_os = "netbsd")] pub fn set_name(name: &str) { - extern { - fn pthread_setname_np(thread: libc::pthread_t, - name: *const libc::c_char, - arg: *mut libc::c_void) -> libc::c_int; - } let cname = CString::new(&b"%s"[..]).unwrap(); let carg = CString::new(name).unwrap(); unsafe { - pthread_setname_np(pthread_self(), cname.as_ptr(), - carg.as_ptr() as *mut libc::c_void); + libc::pthread_setname_np(libc::pthread_self(), cname.as_ptr(), + carg.as_ptr() as *mut libc::c_void); } } #[cfg(target_env = "newlib")] @@ -162,7 +147,7 @@ impl Thread { pub fn join(self) { unsafe { - let ret = pthread_join(self.id, ptr::null_mut()); + let ret = libc::pthread_join(self.id, ptr::null_mut()); mem::forget(self); debug_assert_eq!(ret, 0); } @@ -171,7 +156,7 @@ impl Thread { impl Drop for Thread { fn drop(&mut self) { - let ret = unsafe { pthread_detach(self.id) }; + let ret = unsafe { libc::pthread_detach(self.id) }; debug_assert_eq!(ret, 0); } } @@ -197,15 +182,10 @@ pub mod guard { use prelude::v1::*; use libc::{self, pthread_t}; - use libc::funcs::posix88::mman::mmap; - use libc::consts::os::posix88::{PROT_NONE, - MAP_PRIVATE, - MAP_ANON, - MAP_FAILED, - MAP_FIXED}; + use libc::mmap; + use libc::{PROT_NONE, MAP_PRIVATE, MAP_ANON, MAP_FAILED, MAP_FIXED}; use mem; use ptr; - use super::{pthread_self, pthread_attr_destroy}; use sys::os; #[cfg(any(target_os = "macos", @@ -217,19 +197,17 @@ pub mod guard { #[cfg(any(target_os = "linux", target_os = "android", target_os = "netbsd"))] unsafe fn get_stack_start() -> Option<*mut libc::c_void> { - use super::pthread_attr_init; - let mut ret = None; let mut attr: libc::pthread_attr_t = mem::zeroed(); - assert_eq!(pthread_attr_init(&mut attr), 0); - if pthread_getattr_np(pthread_self(), &mut attr) == 0 { + assert_eq!(libc::pthread_attr_init(&mut attr), 0); + if libc::pthread_getattr_np(libc::pthread_self(), &mut attr) == 0 { let mut stackaddr = ptr::null_mut(); let mut stacksize = 0; - assert_eq!(pthread_attr_getstack(&attr, &mut stackaddr, - &mut stacksize), 0); + assert_eq!(libc::pthread_attr_getstack(&attr, &mut stackaddr, + &mut stacksize), 0); ret = Some(stackaddr); } - assert_eq!(pthread_attr_destroy(&mut attr), 0); + assert_eq!(libc::pthread_attr_destroy(&mut attr), 0); ret } @@ -273,33 +251,18 @@ pub mod guard { #[cfg(target_os = "macos")] pub unsafe fn current() -> Option { - extern { - fn pthread_get_stackaddr_np(thread: pthread_t) -> *mut libc::c_void; - fn pthread_get_stacksize_np(thread: pthread_t) -> libc::size_t; - } - Some((pthread_get_stackaddr_np(pthread_self()) as libc::size_t - - pthread_get_stacksize_np(pthread_self())) as usize) + Some((libc::pthread_get_stackaddr_np(libc::pthread_self()) as libc::size_t - + libc::pthread_get_stacksize_np(libc::pthread_self())) as usize) } #[cfg(any(target_os = "openbsd", target_os = "bitrig"))] pub unsafe fn current() -> Option { - #[repr(C)] - struct stack_t { - ss_sp: *mut libc::c_void, - ss_size: libc::size_t, - ss_flags: libc::c_int, - } - extern { - fn pthread_main_np() -> libc::c_uint; - fn pthread_stackseg_np(thread: pthread_t, - sinfo: *mut stack_t) -> libc::c_uint; - } - - let mut current_stack: stack_t = mem::zeroed(); - assert_eq!(pthread_stackseg_np(pthread_self(), &mut current_stack), 0); + let mut current_stack: libc::stack_t = mem::zeroed(); + assert_eq!(libc::pthread_stackseg_np(libc::pthread_self(), + &mut current_stack), 0); let extra = if cfg!(target_os = "bitrig") {3} else {1} * os::page_size(); - Some(if pthread_main_np() == 1 { + Some(if libc::pthread_main_np() == 1 { // main thread current_stack.ss_sp as usize - current_stack.ss_size as usize + extra } else { @@ -310,20 +273,19 @@ pub mod guard { #[cfg(any(target_os = "linux", target_os = "android", target_os = "netbsd"))] pub unsafe fn current() -> Option { - use super::pthread_attr_init; - let mut ret = None; let mut attr: libc::pthread_attr_t = mem::zeroed(); - assert_eq!(pthread_attr_init(&mut attr), 0); - if pthread_getattr_np(pthread_self(), &mut attr) == 0 { + assert_eq!(libc::pthread_attr_init(&mut attr), 0); + if libc::pthread_getattr_np(libc::pthread_self(), &mut attr) == 0 { let mut guardsize = 0; - assert_eq!(pthread_attr_getguardsize(&attr, &mut guardsize), 0); + assert_eq!(libc::pthread_attr_getguardsize(&attr, &mut guardsize), 0); if guardsize == 0 { panic!("there is no guard page"); } let mut stackaddr = ptr::null_mut(); let mut size = 0; - assert_eq!(pthread_attr_getstack(&attr, &mut stackaddr, &mut size), 0); + assert_eq!(libc::pthread_attr_getstack(&attr, &mut stackaddr, + &mut size), 0); ret = if cfg!(target_os = "netbsd") { Some(stackaddr as usize) @@ -331,20 +293,9 @@ pub mod guard { Some(stackaddr as usize + guardsize as usize) }; } - assert_eq!(pthread_attr_destroy(&mut attr), 0); + assert_eq!(libc::pthread_attr_destroy(&mut attr), 0); ret } - - #[cfg(any(target_os = "linux", target_os = "android", target_os = "netbsd"))] - extern { - fn pthread_getattr_np(native: libc::pthread_t, - attr: *mut libc::pthread_attr_t) -> libc::c_int; - fn pthread_attr_getguardsize(attr: *const libc::pthread_attr_t, - guardsize: *mut libc::size_t) -> libc::c_int; - fn pthread_attr_getstack(attr: *const libc::pthread_attr_t, - stackaddr: *mut *mut libc::c_void, - stacksize: *mut libc::size_t) -> libc::c_int; - } } // glibc >= 2.15 has a __pthread_get_minstack() function that returns @@ -394,21 +345,3 @@ fn min_stack_size(attr: *const libc::pthread_attr_t) -> usize { fn min_stack_size(_: *const libc::pthread_attr_t) -> usize { PTHREAD_STACK_MIN as usize } - -extern { - fn pthread_self() -> libc::pthread_t; - fn pthread_create(native: *mut libc::pthread_t, - attr: *const libc::pthread_attr_t, - f: extern fn(*mut libc::c_void) -> *mut libc::c_void, - value: *mut libc::c_void) -> libc::c_int; - fn pthread_join(native: libc::pthread_t, - value: *mut *mut libc::c_void) -> libc::c_int; - fn pthread_attr_init(attr: *mut libc::pthread_attr_t) -> libc::c_int; - fn pthread_attr_destroy(attr: *mut libc::pthread_attr_t) -> libc::c_int; - fn pthread_attr_setstacksize(attr: *mut libc::pthread_attr_t, - stack_size: libc::size_t) -> libc::c_int; - fn pthread_attr_setdetachstate(attr: *mut libc::pthread_attr_t, - state: libc::c_int) -> libc::c_int; - fn pthread_detach(thread: libc::pthread_t) -> libc::c_int; - fn sched_yield() -> libc::c_int; -} diff --git a/src/libstd/sys/unix/thread_local.rs b/src/libstd/sys/unix/thread_local.rs index e9bf214e8161c..d22118d4d793e 100644 --- a/src/libstd/sys/unix/thread_local.rs +++ b/src/libstd/sys/unix/thread_local.rs @@ -8,62 +8,33 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(dead_code)] // sys isn't exported yet +#![allow(dead_code)] // not used on all platforms -use libc::c_int; +use mem; +use libc; -pub type Key = pthread_key_t; +pub type Key = libc::pthread_key_t; #[inline] pub unsafe fn create(dtor: Option) -> Key { let mut key = 0; - assert_eq!(pthread_key_create(&mut key, dtor), 0); + assert_eq!(libc::pthread_key_create(&mut key, mem::transmute(dtor)), 0); key } #[inline] pub unsafe fn set(key: Key, value: *mut u8) { - let r = pthread_setspecific(key, value); + let r = libc::pthread_setspecific(key, value as *mut _); debug_assert_eq!(r, 0); } #[inline] pub unsafe fn get(key: Key) -> *mut u8 { - pthread_getspecific(key) + libc::pthread_getspecific(key) as *mut u8 } #[inline] pub unsafe fn destroy(key: Key) { - let r = pthread_key_delete(key); + let r = libc::pthread_key_delete(key); debug_assert_eq!(r, 0); } - -#[cfg(any(target_os = "macos", - target_os = "ios"))] -type pthread_key_t = ::libc::c_ulong; - -#[cfg(any(target_os = "freebsd", - target_os = "dragonfly", - target_os = "bitrig", - target_os = "netbsd", - target_os = "openbsd", - target_os = "nacl"))] -type pthread_key_t = ::libc::c_int; - -#[cfg(not(any(target_os = "macos", - target_os = "ios", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "bitrig", - target_os = "netbsd", - target_os = "openbsd", - target_os = "nacl")))] -type pthread_key_t = ::libc::c_uint; - -extern { - fn pthread_key_create(key: *mut pthread_key_t, - dtor: Option) -> c_int; - fn pthread_key_delete(key: pthread_key_t) -> c_int; - fn pthread_getspecific(key: pthread_key_t) -> *mut u8; - fn pthread_setspecific(key: pthread_key_t, value: *mut u8) -> c_int; -} diff --git a/src/libstd/sys/unix/time.rs b/src/libstd/sys/unix/time.rs index 35d55902f9c8b..5192f01269d0c 100644 --- a/src/libstd/sys/unix/time.rs +++ b/src/libstd/sys/unix/time.rs @@ -24,15 +24,10 @@ mod inner { t: u64 } - extern { - pub fn mach_absolute_time() -> u64; - pub fn mach_timebase_info(info: *mut libc::mach_timebase_info) -> libc::c_int; - } - impl SteadyTime { pub fn now() -> SteadyTime { SteadyTime { - t: unsafe { mach_absolute_time() }, + t: unsafe { libc::mach_absolute_time() }, } } } @@ -46,7 +41,7 @@ mod inner { unsafe { ONCE.call_once(|| { - mach_timebase_info(&mut INFO); + libc::mach_timebase_info(&mut INFO); }); &INFO } @@ -87,11 +82,6 @@ mod inner { #[link(name = "rt")] extern {} - extern { - #[cfg_attr(target_os = "netbsd", link_name = "__clock_gettime50")] - fn clock_gettime(clk_id: libc::c_int, tp: *mut libc::timespec) -> libc::c_int; - } - impl SteadyTime { pub fn now() -> SteadyTime { let mut t = SteadyTime { @@ -101,7 +91,8 @@ mod inner { } }; unsafe { - assert_eq!(0, clock_gettime(libc::CLOCK_MONOTONIC, &mut t.t)); + assert_eq!(0, libc::clock_gettime(libc::CLOCK_MONOTONIC, + &mut t.t)); } t } diff --git a/src/libstd/sys/windows/backtrace.rs b/src/libstd/sys/windows/backtrace.rs index b562e772b9c2c..d106bc3285cb1 100644 --- a/src/libstd/sys/windows/backtrace.rs +++ b/src/libstd/sys/windows/backtrace.rs @@ -27,12 +27,13 @@ use io::prelude::*; use dynamic_lib::DynamicLibrary; -use intrinsics; use io; -use libc; +use libc::c_void; +use mem; use path::Path; use ptr; use sync::StaticMutex; +use sys::c; macro_rules! sym{ ($lib:expr, $e:expr, $t:ident) => (unsafe { let lib = $lib; @@ -50,264 +51,50 @@ mod printing; #[path = "printing/gnu.rs"] mod printing; -#[allow(non_snake_case)] -extern "system" { - fn GetCurrentProcess() -> libc::HANDLE; - fn GetCurrentThread() -> libc::HANDLE; - fn RtlCaptureContext(ctx: *mut arch::CONTEXT); -} - type SymFromAddrFn = - extern "system" fn(libc::HANDLE, u64, *mut u64, - *mut SYMBOL_INFO) -> libc::BOOL; + extern "system" fn(c::HANDLE, u64, *mut u64, + *mut c::SYMBOL_INFO) -> c::BOOL; type SymGetLineFromAddr64Fn = - extern "system" fn(libc::HANDLE, u64, *mut u32, - *mut IMAGEHLP_LINE64) -> libc::BOOL; + extern "system" fn(c::HANDLE, u64, *mut u32, + *mut c::IMAGEHLP_LINE64) -> c::BOOL; type SymInitializeFn = - extern "system" fn(libc::HANDLE, *mut libc::c_void, - libc::BOOL) -> libc::BOOL; + extern "system" fn(c::HANDLE, *mut c_void, + c::BOOL) -> c::BOOL; type SymCleanupFn = - extern "system" fn(libc::HANDLE) -> libc::BOOL; + extern "system" fn(c::HANDLE) -> c::BOOL; type StackWalk64Fn = - extern "system" fn(libc::DWORD, libc::HANDLE, libc::HANDLE, - *mut STACKFRAME64, *mut arch::CONTEXT, - *mut libc::c_void, *mut libc::c_void, - *mut libc::c_void, *mut libc::c_void) -> libc::BOOL; - -const MAX_SYM_NAME: usize = 2000; -const IMAGE_FILE_MACHINE_I386: libc::DWORD = 0x014c; -const IMAGE_FILE_MACHINE_IA64: libc::DWORD = 0x0200; -const IMAGE_FILE_MACHINE_AMD64: libc::DWORD = 0x8664; - -#[repr(C)] -struct SYMBOL_INFO { - SizeOfStruct: libc::c_ulong, - TypeIndex: libc::c_ulong, - Reserved: [u64; 2], - Index: libc::c_ulong, - Size: libc::c_ulong, - ModBase: u64, - Flags: libc::c_ulong, - Value: u64, - Address: u64, - Register: libc::c_ulong, - Scope: libc::c_ulong, - Tag: libc::c_ulong, - NameLen: libc::c_ulong, - MaxNameLen: libc::c_ulong, - // note that windows has this as 1, but it basically just means that - // the name is inline at the end of the struct. For us, we just bump - // the struct size up to MAX_SYM_NAME. - Name: [libc::c_char; MAX_SYM_NAME], -} - -#[repr(C)] -struct IMAGEHLP_LINE64 { - SizeOfStruct: u32, - Key: *const libc::c_void, - LineNumber: u32, - Filename: *const libc::c_char, - Address: u64, -} - -#[repr(C)] -enum ADDRESS_MODE { - AddrMode1616, - AddrMode1632, - AddrModeReal, - AddrModeFlat, -} - -struct ADDRESS64 { - Offset: u64, - Segment: u16, - Mode: ADDRESS_MODE, -} - -pub struct STACKFRAME64 { - AddrPC: ADDRESS64, - AddrReturn: ADDRESS64, - AddrFrame: ADDRESS64, - AddrStack: ADDRESS64, - AddrBStore: ADDRESS64, - FuncTableEntry: *mut libc::c_void, - Params: [u64; 4], - Far: libc::BOOL, - Virtual: libc::BOOL, - Reserved: [u64; 3], - KdHelp: KDHELP64, -} - -struct KDHELP64 { - Thread: u64, - ThCallbackStack: libc::DWORD, - ThCallbackBStore: libc::DWORD, - NextCallback: libc::DWORD, - FramePointer: libc::DWORD, - KiCallUserMode: u64, - KeUserCallbackDispatcher: u64, - SystemRangeStart: u64, - KiUserExceptionDispatcher: u64, - StackBase: u64, - StackLimit: u64, - Reserved: [u64; 5], -} + extern "system" fn(c::DWORD, c::HANDLE, c::HANDLE, + *mut c::STACKFRAME64, *mut c::CONTEXT, + *mut c_void, *mut c_void, + *mut c_void, *mut c_void) -> c::BOOL; #[cfg(target_arch = "x86")] -mod arch { - use libc; - - const MAXIMUM_SUPPORTED_EXTENSION: usize = 512; - - #[repr(C)] - pub struct CONTEXT { - ContextFlags: libc::DWORD, - Dr0: libc::DWORD, - Dr1: libc::DWORD, - Dr2: libc::DWORD, - Dr3: libc::DWORD, - Dr6: libc::DWORD, - Dr7: libc::DWORD, - FloatSave: FLOATING_SAVE_AREA, - SegGs: libc::DWORD, - SegFs: libc::DWORD, - SegEs: libc::DWORD, - SegDs: libc::DWORD, - Edi: libc::DWORD, - Esi: libc::DWORD, - Ebx: libc::DWORD, - Edx: libc::DWORD, - Ecx: libc::DWORD, - Eax: libc::DWORD, - Ebp: libc::DWORD, - Eip: libc::DWORD, - SegCs: libc::DWORD, - EFlags: libc::DWORD, - Esp: libc::DWORD, - SegSs: libc::DWORD, - ExtendedRegisters: [u8; MAXIMUM_SUPPORTED_EXTENSION], - } - - #[repr(C)] - pub struct FLOATING_SAVE_AREA { - ControlWord: libc::DWORD, - StatusWord: libc::DWORD, - TagWord: libc::DWORD, - ErrorOffset: libc::DWORD, - ErrorSelector: libc::DWORD, - DataOffset: libc::DWORD, - DataSelector: libc::DWORD, - RegisterArea: [u8; 80], - Cr0NpxState: libc::DWORD, - } - - pub fn init_frame(frame: &mut super::STACKFRAME64, - ctx: &CONTEXT) -> libc::DWORD { - frame.AddrPC.Offset = ctx.Eip as u64; - frame.AddrPC.Mode = super::ADDRESS_MODE::AddrModeFlat; - frame.AddrStack.Offset = ctx.Esp as u64; - frame.AddrStack.Mode = super::ADDRESS_MODE::AddrModeFlat; - frame.AddrFrame.Offset = ctx.Ebp as u64; - frame.AddrFrame.Mode = super::ADDRESS_MODE::AddrModeFlat; - super::IMAGE_FILE_MACHINE_I386 - } +pub fn init_frame(frame: &mut c::STACKFRAME64, + ctx: &c::CONTEXT) -> c::DWORD { + frame.AddrPC.Offset = ctx.Eip as u64; + frame.AddrPC.Mode = c::ADDRESS_MODE::AddrModeFlat; + frame.AddrStack.Offset = ctx.Esp as u64; + frame.AddrStack.Mode = c::ADDRESS_MODE::AddrModeFlat; + frame.AddrFrame.Offset = ctx.Ebp as u64; + frame.AddrFrame.Mode = c::ADDRESS_MODE::AddrModeFlat; + c::IMAGE_FILE_MACHINE_I386 } #[cfg(target_arch = "x86_64")] -mod arch { - #![allow(deprecated)] - - use libc::{c_longlong, c_ulonglong}; - use libc::types::os::arch::extra::{WORD, DWORD, DWORDLONG}; - use simd; - - #[repr(C)] - pub struct CONTEXT { - _align_hack: [simd::u64x2; 0], // FIXME align on 16-byte - P1Home: DWORDLONG, - P2Home: DWORDLONG, - P3Home: DWORDLONG, - P4Home: DWORDLONG, - P5Home: DWORDLONG, - P6Home: DWORDLONG, - - ContextFlags: DWORD, - MxCsr: DWORD, - - SegCs: WORD, - SegDs: WORD, - SegEs: WORD, - SegFs: WORD, - SegGs: WORD, - SegSs: WORD, - EFlags: DWORD, - - Dr0: DWORDLONG, - Dr1: DWORDLONG, - Dr2: DWORDLONG, - Dr3: DWORDLONG, - Dr6: DWORDLONG, - Dr7: DWORDLONG, - - Rax: DWORDLONG, - Rcx: DWORDLONG, - Rdx: DWORDLONG, - Rbx: DWORDLONG, - Rsp: DWORDLONG, - Rbp: DWORDLONG, - Rsi: DWORDLONG, - Rdi: DWORDLONG, - R8: DWORDLONG, - R9: DWORDLONG, - R10: DWORDLONG, - R11: DWORDLONG, - R12: DWORDLONG, - R13: DWORDLONG, - R14: DWORDLONG, - R15: DWORDLONG, - - Rip: DWORDLONG, - - FltSave: FLOATING_SAVE_AREA, - - VectorRegister: [M128A; 26], - VectorControl: DWORDLONG, - - DebugControl: DWORDLONG, - LastBranchToRip: DWORDLONG, - LastBranchFromRip: DWORDLONG, - LastExceptionToRip: DWORDLONG, - LastExceptionFromRip: DWORDLONG, - } - - #[repr(C)] - pub struct M128A { - _align_hack: [simd::u64x2; 0], // FIXME align on 16-byte - Low: c_ulonglong, - High: c_longlong - } - - #[repr(C)] - pub struct FLOATING_SAVE_AREA { - _align_hack: [simd::u64x2; 0], // FIXME align on 16-byte - _Dummy: [u8; 512] // FIXME: Fill this out - } - - pub fn init_frame(frame: &mut super::STACKFRAME64, - ctx: &CONTEXT) -> DWORD { - frame.AddrPC.Offset = ctx.Rip as u64; - frame.AddrPC.Mode = super::ADDRESS_MODE::AddrModeFlat; - frame.AddrStack.Offset = ctx.Rsp as u64; - frame.AddrStack.Mode = super::ADDRESS_MODE::AddrModeFlat; - frame.AddrFrame.Offset = ctx.Rbp as u64; - frame.AddrFrame.Mode = super::ADDRESS_MODE::AddrModeFlat; - super::IMAGE_FILE_MACHINE_AMD64 - } +pub fn init_frame(frame: &mut c::STACKFRAME64, + ctx: &c::CONTEXT) -> c::DWORD { + frame.AddrPC.Offset = ctx.Rip as u64; + frame.AddrPC.Mode = c::ADDRESS_MODE::AddrModeFlat; + frame.AddrStack.Offset = ctx.Rsp as u64; + frame.AddrStack.Mode = c::ADDRESS_MODE::AddrModeFlat; + frame.AddrFrame.Offset = ctx.Rbp as u64; + frame.AddrFrame.Mode = c::ADDRESS_MODE::AddrModeFlat; + c::IMAGE_FILE_MACHINE_AMD64 } struct Cleanup { - handle: libc::HANDLE, + handle: c::HANDLE, SymCleanup: SymCleanupFn, } @@ -335,16 +122,16 @@ pub fn write(w: &mut Write) -> io::Result<()> { let StackWalk64 = sym!(&dbghelp, "StackWalk64", StackWalk64Fn); // Allocate necessary structures for doing the stack walk - let process = unsafe { GetCurrentProcess() }; - let thread = unsafe { GetCurrentThread() }; - let mut context: arch::CONTEXT = unsafe { intrinsics::init() }; - unsafe { RtlCaptureContext(&mut context); } - let mut frame: STACKFRAME64 = unsafe { intrinsics::init() }; - let image = arch::init_frame(&mut frame, &context); + let process = unsafe { c::GetCurrentProcess() }; + let thread = unsafe { c::GetCurrentThread() }; + let mut context: c::CONTEXT = unsafe { mem::zeroed() }; + unsafe { c::RtlCaptureContext(&mut context); } + let mut frame: c::STACKFRAME64 = unsafe { mem::zeroed() }; + let image = init_frame(&mut frame, &context); // Initialize this process's symbols - let ret = SymInitialize(process, ptr::null_mut(), libc::TRUE); - if ret != libc::TRUE { return Ok(()) } + let ret = SymInitialize(process, ptr::null_mut(), c::TRUE); + if ret != c::TRUE { return Ok(()) } let _c = Cleanup { handle: process, SymCleanup: SymCleanup }; // And now that we're done with all the setup, do the stack walking! @@ -356,7 +143,7 @@ pub fn write(w: &mut Write) -> io::Result<()> { ptr::null_mut(), ptr::null_mut(), ptr::null_mut(), - ptr::null_mut()) == libc::TRUE{ + ptr::null_mut()) == c::TRUE { let addr = frame.AddrPC.Offset; if addr == frame.AddrReturn.Offset || addr == 0 || frame.AddrReturn.Offset == 0 { break } diff --git a/src/libstd/sys/windows/c.rs b/src/libstd/sys/windows/c.rs index 270e260d504db..42f182eb01066 100644 --- a/src/libstd/sys/windows/c.rs +++ b/src/libstd/sys/windows/c.rs @@ -10,87 +10,336 @@ //! C definitions used by libnative that don't belong in liblibc -#![allow(bad_style, dead_code, overflowing_literals)] +#![allow(bad_style, overflowing_literals, dead_code, deprecated, unused_imports)] -use libc; -use libc::{c_uint, c_ulong}; -use libc::{DWORD, BOOL, BOOLEAN, ERROR_CALL_NOT_IMPLEMENTED, LPVOID, HANDLE}; -use libc::{LPCWSTR, LONG}; +use os::raw::{c_int, c_uint, c_ulong, c_long, c_longlong, c_ushort}; +use os::raw::{c_char, c_short, c_ulonglong}; +use libc::{wchar_t, size_t, c_void}; use ptr; +use simd; pub use self::GET_FILEEX_INFO_LEVELS::*; pub use self::FILE_INFO_BY_HANDLE_CLASS::*; -pub use libc::consts::os::extra::{ - FILE_ATTRIBUTE_READONLY, - FILE_ATTRIBUTE_DIRECTORY, - WSAPROTOCOL_LEN, -}; -pub use libc::types::os::arch::extra::{GROUP, GUID, WSAPROTOCOLCHAIN}; +pub use self::EXCEPTION_DISPOSITION::*; -pub const WSADESCRIPTION_LEN: usize = 256; -pub const WSASYS_STATUS_LEN: usize = 128; -pub const FIONBIO: libc::c_long = 0x8004667e; +pub type DWORD = c_ulong; +pub type HANDLE = LPVOID; +pub type HINSTANCE = HANDLE; +pub type HMODULE = HINSTANCE; +pub type BOOL = c_int; +pub type BYTE = u8; +pub type BOOLEAN = BYTE; +pub type GROUP = c_uint; +pub type LONG_PTR = isize; +pub type LARGE_INTEGER = c_longlong; +pub type LONG = c_long; +pub type UINT = c_uint; +pub type WCHAR = u16; +pub type USHORT = c_ushort; +pub type SIZE_T = usize; +pub type WORD = u16; +pub type CHAR = c_char; +pub type HCRYPTPROV = LONG_PTR; +pub type ULONG_PTR = c_ulonglong; +pub type ULONG = c_ulong; +pub type ULONGLONG = u64; +pub type DWORDLONG = ULONGLONG; + +pub type LPBOOL = *mut BOOL; +pub type LPBYTE = *mut BYTE; +pub type LPBY_HANDLE_FILE_INFORMATION = *mut BY_HANDLE_FILE_INFORMATION; +pub type LPCSTR = *const CHAR; +pub type LPCVOID = *const c_void; +pub type LPCWSTR = *const WCHAR; +pub type LPDWORD = *mut DWORD; +pub type LPHANDLE = *mut HANDLE; +pub type LPOVERLAPPED = *mut OVERLAPPED; +pub type LPPROCESS_INFORMATION = *mut PROCESS_INFORMATION; +pub type LPSECURITY_ATTRIBUTES = *mut SECURITY_ATTRIBUTES; +pub type LPSTARTUPINFO = *mut STARTUPINFO; +pub type LPVOID = *mut c_void; +pub type LPWCH = *mut WCHAR; +pub type LPWIN32_FIND_DATAW = *mut WIN32_FIND_DATAW; +pub type LPWSADATA = *mut WSADATA; +pub type LPWSANETWORKEVENTS = *mut WSANETWORKEVENTS; +pub type LPWSAPROTOCOLCHAIN = *mut WSAPROTOCOLCHAIN; +pub type LPWSAPROTOCOL_INFO = *mut WSAPROTOCOL_INFO; +pub type LPWSTR = *mut WCHAR; + +pub type PCONDITION_VARIABLE = *mut CONDITION_VARIABLE; +pub type PLARGE_INTEGER = *mut c_longlong; +pub type PSRWLOCK = *mut SRWLOCK; + +pub type SOCKET = ::os::windows::raw::SOCKET; +pub type socklen_t = c_int; +pub type ADDRESS_FAMILY = USHORT; + +pub const TRUE: BOOL = 1; +pub const FALSE: BOOL = 0; + +pub const FILE_ATTRIBUTE_READONLY: DWORD = 0x1; +pub const FILE_ATTRIBUTE_DIRECTORY: DWORD = 0x10; +pub const FILE_ATTRIBUTE_NORMAL: DWORD = 0x80; +pub const FILE_ATTRIBUTE_REPARSE_POINT: DWORD = 0x400; +pub const FILE_SHARE_DELETE: DWORD = 0x4; +pub const FILE_SHARE_READ: DWORD = 0x1; +pub const FILE_SHARE_WRITE: DWORD = 0x2; +pub const CREATE_ALWAYS: DWORD = 2; +pub const CREATE_NEW: DWORD = 1; +pub const OPEN_ALWAYS: DWORD = 4; +pub const OPEN_EXISTING: DWORD = 3; +pub const TRUNCATE_EXISTING: DWORD = 5; +pub const FILE_APPEND_DATA: DWORD = 0x00000004; +pub const FILE_READ_DATA: DWORD = 0x00000001; +pub const FILE_WRITE_DATA: DWORD = 0x00000002; +pub const STANDARD_RIGHTS_READ: DWORD = 0x20000; +pub const STANDARD_RIGHTS_WRITE: DWORD = 0x20000; +pub const FILE_WRITE_EA: DWORD = 0x00000010; +pub const FILE_READ_EA: DWORD = 0x00000008; +pub const SYNCHRONIZE: DWORD = 0x00100000; +pub const FILE_WRITE_ATTRIBUTES: DWORD = 0x00000100; +pub const FILE_READ_ATTRIBUTES: DWORD = 0x00000080; +pub const FILE_GENERIC_READ: DWORD = STANDARD_RIGHTS_READ | FILE_READ_DATA | + FILE_READ_ATTRIBUTES | + FILE_READ_EA | + SYNCHRONIZE; +pub const FILE_GENERIC_WRITE: DWORD = STANDARD_RIGHTS_WRITE | FILE_WRITE_DATA | + FILE_WRITE_ATTRIBUTES | + FILE_WRITE_EA | + FILE_APPEND_DATA | + SYNCHRONIZE; + +#[repr(C)] +#[derive(Copy)] +pub struct WIN32_FIND_DATAW { + pub dwFileAttributes: DWORD, + pub ftCreationTime: FILETIME, + pub ftLastAccessTime: FILETIME, + pub ftLastWriteTime: FILETIME, + pub nFileSizeHigh: DWORD, + pub nFileSizeLow: DWORD, + pub dwReserved0: DWORD, + pub dwReserved1: DWORD, + pub cFileName: [wchar_t; 260], // #define MAX_PATH 260 + pub cAlternateFileName: [wchar_t; 14], +} +impl Clone for WIN32_FIND_DATAW { + fn clone(&self) -> Self { *self } +} + +pub const FIONBIO: c_long = 0x8004667e; pub const FD_SETSIZE: usize = 64; -pub const MSG_DONTWAIT: libc::c_int = 0; -pub const ERROR_ENVVAR_NOT_FOUND: libc::c_int = 203; -pub const ERROR_ILLEGAL_CHARACTER: libc::c_int = 582; -pub const ENABLE_ECHO_INPUT: libc::DWORD = 0x4; -pub const ENABLE_EXTENDED_FLAGS: libc::DWORD = 0x80; -pub const ENABLE_INSERT_MODE: libc::DWORD = 0x20; -pub const ENABLE_LINE_INPUT: libc::DWORD = 0x2; -pub const ENABLE_PROCESSED_INPUT: libc::DWORD = 0x1; -pub const ENABLE_QUICK_EDIT_MODE: libc::DWORD = 0x40; -pub const WSA_INVALID_EVENT: WSAEVENT = 0 as WSAEVENT; +pub const MSG_DONTWAIT: c_int = 0; +pub const ENABLE_ECHO_INPUT: DWORD = 0x4; +pub const ENABLE_EXTENDED_FLAGS: DWORD = 0x80; +pub const ENABLE_INSERT_MODE: DWORD = 0x20; +pub const ENABLE_LINE_INPUT: DWORD = 0x2; +pub const ENABLE_PROCESSED_INPUT: DWORD = 0x1; +pub const ENABLE_QUICK_EDIT_MODE: DWORD = 0x40; -pub const FD_ACCEPT: libc::c_long = 0x08; +pub const FD_ACCEPT: c_long = 0x08; pub const FD_MAX_EVENTS: usize = 10; -pub const WSA_INFINITE: libc::DWORD = libc::INFINITE; -pub const WSA_WAIT_TIMEOUT: libc::DWORD = libc::consts::os::extra::WAIT_TIMEOUT; -pub const WSA_WAIT_EVENT_0: libc::DWORD = libc::consts::os::extra::WAIT_OBJECT_0; -pub const WSA_WAIT_FAILED: libc::DWORD = libc::consts::os::extra::WAIT_FAILED; -pub const WSAESHUTDOWN: libc::c_int = 10058; -pub const WSA_FLAG_OVERLAPPED: libc::DWORD = 0x01; -pub const WSA_FLAG_NO_HANDLE_INHERIT: libc::DWORD = 0x80; - -pub const ERROR_NO_MORE_FILES: libc::DWORD = 18; -pub const TOKEN_READ: libc::DWORD = 0x20008; -pub const FILE_FLAG_OPEN_REPARSE_POINT: libc::DWORD = 0x00200000; -pub const FILE_FLAG_BACKUP_SEMANTICS: libc::DWORD = 0x02000000; + +pub const WSA_INVALID_EVENT: WSAEVENT = 0 as WSAEVENT; +pub const WSA_INFINITE: DWORD = INFINITE; +pub const WSA_WAIT_TIMEOUT: DWORD = WAIT_TIMEOUT; +pub const WSA_WAIT_EVENT_0: DWORD = WAIT_OBJECT_0; +pub const WSA_WAIT_FAILED: DWORD = WAIT_FAILED; +pub const WSA_FLAG_OVERLAPPED: DWORD = 0x01; +pub const WSA_FLAG_NO_HANDLE_INHERIT: DWORD = 0x80; + +pub const WSADESCRIPTION_LEN: usize = 256; +pub const WSASYS_STATUS_LEN: usize = 128; +pub const WSAPROTOCOL_LEN: DWORD = 255; +pub const INVALID_SOCKET: SOCKET = !0; + +pub const WSAEINTR: c_int = 10004; +pub const WSAEBADF: c_int = 10009; +pub const WSAEACCES: c_int = 10013; +pub const WSAEFAULT: c_int = 10014; +pub const WSAEINVAL: c_int = 10022; +pub const WSAEMFILE: c_int = 10024; +pub const WSAEWOULDBLOCK: c_int = 10035; +pub const WSAEINPROGRESS: c_int = 10036; +pub const WSAEALREADY: c_int = 10037; +pub const WSAENOTSOCK: c_int = 10038; +pub const WSAEDESTADDRREQ: c_int = 10039; +pub const WSAEMSGSIZE: c_int = 10040; +pub const WSAEPROTOTYPE: c_int = 10041; +pub const WSAENOPROTOOPT: c_int = 10042; +pub const WSAEPROTONOSUPPORT: c_int = 10043; +pub const WSAESOCKTNOSUPPORT: c_int = 10044; +pub const WSAEOPNOTSUPP: c_int = 10045; +pub const WSAEPFNOSUPPORT: c_int = 10046; +pub const WSAEAFNOSUPPORT: c_int = 10047; +pub const WSAEADDRINUSE: c_int = 10048; +pub const WSAEADDRNOTAVAIL: c_int = 10049; +pub const WSAENETDOWN: c_int = 10050; +pub const WSAENETUNREACH: c_int = 10051; +pub const WSAENETRESET: c_int = 10052; +pub const WSAECONNABORTED: c_int = 10053; +pub const WSAECONNRESET: c_int = 10054; +pub const WSAENOBUFS: c_int = 10055; +pub const WSAEISCONN: c_int = 10056; +pub const WSAENOTCONN: c_int = 10057; +pub const WSAESHUTDOWN: c_int = 10058; +pub const WSAETOOMANYREFS: c_int = 10059; +pub const WSAETIMEDOUT: c_int = 10060; +pub const WSAECONNREFUSED: c_int = 10061; +pub const WSAELOOP: c_int = 10062; +pub const WSAENAMETOOLONG: c_int = 10063; +pub const WSAEHOSTDOWN: c_int = 10064; +pub const WSAEHOSTUNREACH: c_int = 10065; +pub const WSAENOTEMPTY: c_int = 10066; +pub const WSAEPROCLIM: c_int = 10067; +pub const WSAEUSERS: c_int = 10068; +pub const WSAEDQUOT: c_int = 10069; +pub const WSAESTALE: c_int = 10070; +pub const WSAEREMOTE: c_int = 10071; +pub const WSASYSNOTREADY: c_int = 10091; +pub const WSAVERNOTSUPPORTED: c_int = 10092; +pub const WSANOTINITIALISED: c_int = 10093; +pub const WSAEDISCON: c_int = 10101; +pub const WSAENOMORE: c_int = 10102; +pub const WSAECANCELLED: c_int = 10103; +pub const WSAEINVALIDPROCTABLE: c_int = 10104; +pub const NI_MAXHOST: DWORD = 1025; + +pub const MAX_PROTOCOL_CHAIN: DWORD = 7; + +pub const TOKEN_READ: DWORD = 0x20008; +pub const FILE_FLAG_OPEN_REPARSE_POINT: DWORD = 0x00200000; +pub const FILE_FLAG_BACKUP_SEMANTICS: DWORD = 0x02000000; pub const MAXIMUM_REPARSE_DATA_BUFFER_SIZE: usize = 16 * 1024; -pub const FSCTL_GET_REPARSE_POINT: libc::DWORD = 0x900a8; -pub const IO_REPARSE_TAG_SYMLINK: libc::DWORD = 0xa000000c; -pub const IO_REPARSE_TAG_MOUNT_POINT: libc::DWORD = 0xa0000003; -pub const FSCTL_SET_REPARSE_POINT: libc::DWORD = 0x900a4; -pub const FSCTL_DELETE_REPARSE_POINT: libc::DWORD = 0x900ac; +pub const FSCTL_GET_REPARSE_POINT: DWORD = 0x900a8; +pub const IO_REPARSE_TAG_SYMLINK: DWORD = 0xa000000c; +pub const IO_REPARSE_TAG_MOUNT_POINT: DWORD = 0xa0000003; +pub const FSCTL_SET_REPARSE_POINT: DWORD = 0x900a4; +pub const FSCTL_DELETE_REPARSE_POINT: DWORD = 0x900ac; -pub const SYMBOLIC_LINK_FLAG_DIRECTORY: libc::DWORD = 0x1; +pub const SYMBOLIC_LINK_FLAG_DIRECTORY: DWORD = 0x1; // Note that these are not actually HANDLEs, just values to pass to GetStdHandle -pub const STD_INPUT_HANDLE: libc::DWORD = -10i32 as libc::DWORD; -pub const STD_OUTPUT_HANDLE: libc::DWORD = -11i32 as libc::DWORD; -pub const STD_ERROR_HANDLE: libc::DWORD = -12i32 as libc::DWORD; +pub const STD_INPUT_HANDLE: DWORD = -10i32 as DWORD; +pub const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD; +pub const STD_ERROR_HANDLE: DWORD = -12i32 as DWORD; + +pub const HANDLE_FLAG_INHERIT: DWORD = 0x00000001; + +pub const PROGRESS_CONTINUE: DWORD = 0; +pub const PROGRESS_CANCEL: DWORD = 1; +pub const PROGRESS_STOP: DWORD = 2; +pub const PROGRESS_QUIET: DWORD = 3; + +pub const TOKEN_ADJUST_PRIVILEGES: DWORD = 0x0020; +pub const SE_PRIVILEGE_ENABLED: DWORD = 2; + -pub const HANDLE_FLAG_INHERIT: libc::DWORD = 0x00000001; +pub const ERROR_SUCCESS: DWORD = 0; +pub const ERROR_INVALID_FUNCTION: DWORD = 1; +pub const ERROR_FILE_NOT_FOUND: DWORD = 2; +pub const ERROR_PATH_NOT_FOUND: DWORD = 3; +pub const ERROR_ACCESS_DENIED: DWORD = 5; +pub const ERROR_INVALID_HANDLE: DWORD = 6; +pub const ERROR_NO_MORE_FILES: DWORD = 18; +pub const ERROR_BROKEN_PIPE: DWORD = 109; +pub const ERROR_DISK_FULL: DWORD = 112; +pub const ERROR_CALL_NOT_IMPLEMENTED: DWORD = 120; +pub const ERROR_INSUFFICIENT_BUFFER: DWORD = 122; +pub const ERROR_INVALID_NAME: DWORD = 123; +pub const ERROR_ALREADY_EXISTS: DWORD = 183; +pub const ERROR_PIPE_BUSY: DWORD = 231; +pub const ERROR_NO_DATA: DWORD = 232; +pub const ERROR_INVALID_ADDRESS: DWORD = 487; +pub const ERROR_PIPE_CONNECTED: DWORD = 535; +pub const ERROR_ILLEGAL_CHARACTER: DWORD = 582; +pub const ERROR_ENVVAR_NOT_FOUND: DWORD = 203; +pub const ERROR_NOTHING_TO_TERMINATE: DWORD = 758; +pub const ERROR_OPERATION_ABORTED: DWORD = 995; +pub const ERROR_IO_PENDING: DWORD = 997; +pub const ERROR_FILE_INVALID: DWORD = 1006; +pub const ERROR_NOT_FOUND: DWORD = 1168; +pub const ERROR_TIMEOUT: DWORD = 0x5B4; + +pub const INVALID_HANDLE_VALUE: HANDLE = !0 as HANDLE; + +pub const FORMAT_MESSAGE_FROM_SYSTEM: DWORD = 0x00001000; +pub const FORMAT_MESSAGE_IGNORE_INSERTS: DWORD = 0x00000200; + +pub const TLS_OUT_OF_INDEXES: DWORD = 0xFFFFFFFF; + +pub const DLL_THREAD_DETACH: DWORD = 3; +pub const DLL_PROCESS_DETACH: DWORD = 0; + +pub const INFINITE: DWORD = !0; + +pub const DUPLICATE_SAME_ACCESS: DWORD = 0x00000002; + +pub const CONDITION_VARIABLE_INIT: CONDITION_VARIABLE = CONDITION_VARIABLE { + ptr: ptr::null_mut(), +}; +pub const SRWLOCK_INIT: SRWLOCK = SRWLOCK { ptr: ptr::null_mut() }; -pub const PROGRESS_CONTINUE: libc::DWORD = 0; -pub const PROGRESS_CANCEL: libc::DWORD = 1; -pub const PROGRESS_STOP: libc::DWORD = 2; -pub const PROGRESS_QUIET: libc::DWORD = 3; +pub const STILL_ACTIVE: DWORD = 259; -pub const TOKEN_ADJUST_PRIVILEGES: libc::DWORD = 0x0020; -pub const SE_PRIVILEGE_ENABLED: libc::DWORD = 2; +pub const DETACHED_PROCESS: DWORD = 0x00000008; +pub const CREATE_NEW_PROCESS_GROUP: DWORD = 0x00000200; +pub const CREATE_UNICODE_ENVIRONMENT: DWORD = 0x00000400; +pub const STARTF_USESTDHANDLES: DWORD = 0x00000100; + +pub const AF_INET: c_int = 2; +pub const AF_INET6: c_int = 23; +pub const SD_BOTH: c_int = 2; +pub const SD_RECEIVE: c_int = 0; +pub const SD_SEND: c_int = 1; +pub const SOCK_DGRAM: c_int = 2; +pub const SOCK_STREAM: c_int = 1; +pub const SOL_SOCKET: c_int = 0xffff; +pub const SO_RCVTIMEO: c_int = 0x1006; +pub const SO_SNDTIMEO: c_int = 0x1005; +pub const SO_REUSEADDR: c_int = 0x0004; + +pub const VOLUME_NAME_DOS: DWORD = 0x0; +pub const MOVEFILE_REPLACE_EXISTING: DWORD = 1; + +pub const FILE_BEGIN: DWORD = 0; +pub const FILE_CURRENT: DWORD = 1; +pub const FILE_END: DWORD = 2; + +pub const WAIT_ABANDONED: DWORD = 0x00000080; +pub const WAIT_OBJECT_0: DWORD = 0x00000000; +pub const WAIT_TIMEOUT: DWORD = 0x00000102; +pub const WAIT_FAILED: DWORD = !0; + +pub const MAX_SYM_NAME: usize = 2000; +pub const IMAGE_FILE_MACHINE_I386: DWORD = 0x014c; +pub const IMAGE_FILE_MACHINE_IA64: DWORD = 0x0200; +pub const IMAGE_FILE_MACHINE_AMD64: DWORD = 0x8664; + +pub const PROV_RSA_FULL: DWORD = 1; +pub const CRYPT_SILENT: DWORD = 64; +pub const CRYPT_VERIFYCONTEXT: DWORD = 0xF0000000; pub const EXCEPTION_CONTINUE_SEARCH: LONG = 0; -pub const EXCEPTION_MAXIMUM_PARAMETERS: usize = 15; pub const EXCEPTION_STACK_OVERFLOW: DWORD = 0xc00000fd; - -pub const ERROR_PATH_NOT_FOUND: libc::c_int = 3; +pub const EXCEPTION_MAXIMUM_PARAMETERS: usize = 15; +pub const EXCEPTION_NONCONTINUABLE: DWORD = 0x1; // Noncontinuable exception +pub const EXCEPTION_UNWINDING: DWORD = 0x2; // Unwind is in progress +pub const EXCEPTION_EXIT_UNWIND: DWORD = 0x4; // Exit unwind is in progress +pub const EXCEPTION_STACK_INVALID: DWORD = 0x8; // Stack out of limits or unaligned +pub const EXCEPTION_NESTED_CALL: DWORD = 0x10; // Nested exception handler call +pub const EXCEPTION_TARGET_UNWIND: DWORD = 0x20; // Target unwind in progress +pub const EXCEPTION_COLLIDED_UNWIND: DWORD = 0x40; // Collided exception handler call +pub const EXCEPTION_UNWIND: DWORD = EXCEPTION_UNWINDING | + EXCEPTION_EXIT_UNWIND | + EXCEPTION_TARGET_UNWIND | + EXCEPTION_COLLIDED_UNWIND; #[repr(C)] #[cfg(target_arch = "x86")] pub struct WSADATA { - pub wVersion: libc::WORD, - pub wHighVersion: libc::WORD, + pub wVersion: WORD, + pub wHighVersion: WORD, pub szDescription: [u8; WSADESCRIPTION_LEN + 1], pub szSystemStatus: [u8; WSASYS_STATUS_LEN + 1], pub iMaxSockets: u16, @@ -100,8 +349,8 @@ pub struct WSADATA { #[repr(C)] #[cfg(target_arch = "x86_64")] pub struct WSADATA { - pub wVersion: libc::WORD, - pub wHighVersion: libc::WORD, + pub wVersion: WORD, + pub wHighVersion: WORD, pub iMaxSockets: u16, pub iMaxUdpDg: u16, pub lpVendorInfo: *mut u8, @@ -109,56 +358,50 @@ pub struct WSADATA { pub szSystemStatus: [u8; WSASYS_STATUS_LEN + 1], } -pub type LPWSADATA = *mut WSADATA; - #[repr(C)] pub struct WSANETWORKEVENTS { - pub lNetworkEvents: libc::c_long, - pub iErrorCode: [libc::c_int; FD_MAX_EVENTS], + pub lNetworkEvents: c_long, + pub iErrorCode: [c_int; FD_MAX_EVENTS], } -pub type LPWSANETWORKEVENTS = *mut WSANETWORKEVENTS; - -pub type WSAEVENT = libc::HANDLE; +pub type WSAEVENT = HANDLE; #[repr(C)] pub struct WSAPROTOCOL_INFO { - pub dwServiceFlags1: libc::DWORD, - pub dwServiceFlags2: libc::DWORD, - pub dwServiceFlags3: libc::DWORD, - pub dwServiceFlags4: libc::DWORD, - pub dwProviderFlags: libc::DWORD, + pub dwServiceFlags1: DWORD, + pub dwServiceFlags2: DWORD, + pub dwServiceFlags3: DWORD, + pub dwServiceFlags4: DWORD, + pub dwProviderFlags: DWORD, pub ProviderId: GUID, - pub dwCatalogEntryId: libc::DWORD, + pub dwCatalogEntryId: DWORD, pub ProtocolChain: WSAPROTOCOLCHAIN, - pub iVersion: libc::c_int, - pub iAddressFamily: libc::c_int, - pub iMaxSockAddr: libc::c_int, - pub iMinSockAddr: libc::c_int, - pub iSocketType: libc::c_int, - pub iProtocol: libc::c_int, - pub iProtocolMaxOffset: libc::c_int, - pub iNetworkByteOrder: libc::c_int, - pub iSecurityScheme: libc::c_int, - pub dwMessageSize: libc::DWORD, - pub dwProviderReserved: libc::DWORD, + pub iVersion: c_int, + pub iAddressFamily: c_int, + pub iMaxSockAddr: c_int, + pub iMinSockAddr: c_int, + pub iSocketType: c_int, + pub iProtocol: c_int, + pub iProtocolMaxOffset: c_int, + pub iNetworkByteOrder: c_int, + pub iSecurityScheme: c_int, + pub dwMessageSize: DWORD, + pub dwProviderReserved: DWORD, pub szProtocol: [u16; (WSAPROTOCOL_LEN as usize) + 1], } -pub type LPWSAPROTOCOL_INFO = *mut WSAPROTOCOL_INFO; - #[repr(C)] pub struct fd_set { - fd_count: libc::c_uint, - fd_array: [libc::SOCKET; FD_SETSIZE], + fd_count: c_uint, + fd_array: [SOCKET; FD_SETSIZE], } -pub fn fd_set(set: &mut fd_set, s: libc::SOCKET) { +pub fn fd_set(set: &mut fd_set, s: SOCKET) { set.fd_array[set.fd_count as usize] = s; set.fd_count += 1; } -pub type SHORT = libc::c_short; +pub type SHORT = c_short; #[repr(C)] pub struct COORD { @@ -178,39 +421,37 @@ pub struct SMALL_RECT { pub struct CONSOLE_SCREEN_BUFFER_INFO { pub dwSize: COORD, pub dwCursorPosition: COORD, - pub wAttributes: libc::WORD, + pub wAttributes: WORD, pub srWindow: SMALL_RECT, pub dwMaximumWindowSize: COORD, } pub type PCONSOLE_SCREEN_BUFFER_INFO = *mut CONSOLE_SCREEN_BUFFER_INFO; #[repr(C)] -#[derive(Clone)] +#[derive(Copy, Clone)] pub struct WIN32_FILE_ATTRIBUTE_DATA { - pub dwFileAttributes: libc::DWORD, - pub ftCreationTime: libc::FILETIME, - pub ftLastAccessTime: libc::FILETIME, - pub ftLastWriteTime: libc::FILETIME, - pub nFileSizeHigh: libc::DWORD, - pub nFileSizeLow: libc::DWORD, + pub dwFileAttributes: DWORD, + pub ftCreationTime: FILETIME, + pub ftLastAccessTime: FILETIME, + pub ftLastWriteTime: FILETIME, + pub nFileSizeHigh: DWORD, + pub nFileSizeLow: DWORD, } #[repr(C)] pub struct BY_HANDLE_FILE_INFORMATION { - pub dwFileAttributes: libc::DWORD, - pub ftCreationTime: libc::FILETIME, - pub ftLastAccessTime: libc::FILETIME, - pub ftLastWriteTime: libc::FILETIME, - pub dwVolumeSerialNumber: libc::DWORD, - pub nFileSizeHigh: libc::DWORD, - pub nFileSizeLow: libc::DWORD, - pub nNumberOfLinks: libc::DWORD, - pub nFileIndexHigh: libc::DWORD, - pub nFileIndexLow: libc::DWORD, + pub dwFileAttributes: DWORD, + pub ftCreationTime: FILETIME, + pub ftLastAccessTime: FILETIME, + pub ftLastWriteTime: FILETIME, + pub dwVolumeSerialNumber: DWORD, + pub nFileSizeHigh: DWORD, + pub nFileSizeLow: DWORD, + pub nNumberOfLinks: DWORD, + pub nFileIndexHigh: DWORD, + pub nFileIndexLow: DWORD, } -pub type LPBY_HANDLE_FILE_INFORMATION = *mut BY_HANDLE_FILE_INFORMATION; - #[repr(C)] pub enum GET_FILEEX_INFO_LEVELS { GetFileExInfoStandard, @@ -245,38 +486,32 @@ pub enum FILE_INFO_BY_HANDLE_CLASS { #[repr(C)] pub struct FILE_END_OF_FILE_INFO { - pub EndOfFile: libc::LARGE_INTEGER, + pub EndOfFile: LARGE_INTEGER, } #[repr(C)] pub struct REPARSE_DATA_BUFFER { - pub ReparseTag: libc::c_uint, - pub ReparseDataLength: libc::c_ushort, - pub Reserved: libc::c_ushort, + pub ReparseTag: c_uint, + pub ReparseDataLength: c_ushort, + pub Reserved: c_ushort, pub rest: (), } #[repr(C)] pub struct SYMBOLIC_LINK_REPARSE_BUFFER { - pub SubstituteNameOffset: libc::c_ushort, - pub SubstituteNameLength: libc::c_ushort, - pub PrintNameOffset: libc::c_ushort, - pub PrintNameLength: libc::c_ushort, - pub Flags: libc::c_ulong, - pub PathBuffer: libc::WCHAR, + pub SubstituteNameOffset: c_ushort, + pub SubstituteNameLength: c_ushort, + pub PrintNameOffset: c_ushort, + pub PrintNameLength: c_ushort, + pub Flags: c_ulong, + pub PathBuffer: WCHAR, } -pub type PCONDITION_VARIABLE = *mut CONDITION_VARIABLE; -pub type PSRWLOCK = *mut SRWLOCK; -pub type ULONG = c_ulong; -pub type ULONG_PTR = c_ulong; -pub type LPBOOL = *mut BOOL; - pub type LPPROGRESS_ROUTINE = ::option::Option LONG; +#[repr(C)] +pub struct GUID { + pub Data1: DWORD, + pub Data2: WORD, + pub Data3: WORD, + pub Data4: [BYTE; 8], +} + +#[repr(C)] +pub struct WSAPROTOCOLCHAIN { + pub ChainLen: c_int, + pub ChainEntries: [DWORD; MAX_PROTOCOL_CHAIN as usize], +} + +#[repr(C)] +pub struct SECURITY_ATTRIBUTES { + pub nLength: DWORD, + pub lpSecurityDescriptor: LPVOID, + pub bInheritHandle: BOOL, +} + +#[repr(C)] +pub struct PROCESS_INFORMATION { + pub hProcess: HANDLE, + pub hThread: HANDLE, + pub dwProcessId: DWORD, + pub dwThreadId: DWORD, +} + +#[repr(C)] +pub struct STARTUPINFO { + pub cb: DWORD, + pub lpReserved: LPWSTR, + pub lpDesktop: LPWSTR, + pub lpTitle: LPWSTR, + pub dwX: DWORD, + pub dwY: DWORD, + pub dwXSize: DWORD, + pub dwYSize: DWORD, + pub dwXCountChars: DWORD, + pub dwYCountCharts: DWORD, + pub dwFillAttribute: DWORD, + pub dwFlags: DWORD, + pub wShowWindow: WORD, + pub cbReserved2: WORD, + pub lpReserved2: LPBYTE, + pub hStdInput: HANDLE, + pub hStdOutput: HANDLE, + pub hStdError: HANDLE, +} + +#[repr(C)] +pub struct SOCKADDR { + pub sa_family: ADDRESS_FAMILY, + pub sa_data: [CHAR; 14], +} + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct FILETIME { + pub dwLowDateTime: DWORD, + pub dwHighDateTime: DWORD, +} + +#[repr(C)] +pub struct OVERLAPPED { + pub Internal: *mut c_ulong, + pub InternalHigh: *mut c_ulong, + pub Offset: DWORD, + pub OffsetHigh: DWORD, + pub hEvent: HANDLE, +} + +#[repr(C)] +pub struct SYMBOL_INFO { + pub SizeOfStruct: c_ulong, + pub TypeIndex: c_ulong, + pub Reserved: [u64; 2], + pub Index: c_ulong, + pub Size: c_ulong, + pub ModBase: u64, + pub Flags: c_ulong, + pub Value: u64, + pub Address: u64, + pub Register: c_ulong, + pub Scope: c_ulong, + pub Tag: c_ulong, + pub NameLen: c_ulong, + pub MaxNameLen: c_ulong, + // note that windows has this as 1, but it basically just means that + // the name is inline at the end of the struct. For us, we just bump + // the struct size up to MAX_SYM_NAME. + pub Name: [c_char; MAX_SYM_NAME], +} + +#[repr(C)] +pub struct IMAGEHLP_LINE64 { + pub SizeOfStruct: u32, + pub Key: *const c_void, + pub LineNumber: u32, + pub Filename: *const c_char, + pub Address: u64, +} + +#[repr(C)] +pub enum ADDRESS_MODE { + AddrMode1616, + AddrMode1632, + AddrModeReal, + AddrModeFlat, +} + +#[repr(C)] +pub struct ADDRESS64 { + pub Offset: u64, + pub Segment: u16, + pub Mode: ADDRESS_MODE, +} + +#[repr(C)] +pub struct STACKFRAME64 { + pub AddrPC: ADDRESS64, + pub AddrReturn: ADDRESS64, + pub AddrFrame: ADDRESS64, + pub AddrStack: ADDRESS64, + pub AddrBStore: ADDRESS64, + pub FuncTableEntry: *mut c_void, + pub Params: [u64; 4], + pub Far: BOOL, + pub Virtual: BOOL, + pub Reserved: [u64; 3], + pub KdHelp: KDHELP64, +} + +#[repr(C)] +pub struct KDHELP64 { + pub Thread: u64, + pub ThCallbackStack: DWORD, + pub ThCallbackBStore: DWORD, + pub NextCallback: DWORD, + pub FramePointer: DWORD, + pub KiCallUserMode: u64, + pub KeUserCallbackDispatcher: u64, + pub SystemRangeStart: u64, + pub KiUserExceptionDispatcher: u64, + pub StackBase: u64, + pub StackLimit: u64, + pub Reserved: [u64; 5], +} + +#[cfg(target_arch = "x86")] +#[repr(C)] +pub struct CONTEXT { + pub ContextFlags: DWORD, + pub Dr0: DWORD, + pub Dr1: DWORD, + pub Dr2: DWORD, + pub Dr3: DWORD, + pub Dr6: DWORD, + pub Dr7: DWORD, + pub FloatSave: FLOATING_SAVE_AREA, + pub SegGs: DWORD, + pub SegFs: DWORD, + pub SegEs: DWORD, + pub SegDs: DWORD, + pub Edi: DWORD, + pub Esi: DWORD, + pub Ebx: DWORD, + pub Edx: DWORD, + pub Ecx: DWORD, + pub Eax: DWORD, + pub Ebp: DWORD, + pub Eip: DWORD, + pub SegCs: DWORD, + pub EFlags: DWORD, + pub Esp: DWORD, + pub SegSs: DWORD, + pub ExtendedRegisters: [u8; 512], +} + +#[cfg(target_arch = "x86")] +#[repr(C)] +pub struct FLOATING_SAVE_AREA { + pub ControlWord: DWORD, + pub StatusWord: DWORD, + pub TagWord: DWORD, + pub ErrorOffset: DWORD, + pub ErrorSelector: DWORD, + pub DataOffset: DWORD, + pub DataSelector: DWORD, + pub RegisterArea: [u8; 80], + pub Cr0NpxState: DWORD, +} + +#[cfg(target_arch = "x86_64")] +#[repr(C)] +pub struct CONTEXT { + _align_hack: [simd::u64x2; 0], // FIXME align on 16-byte + pub P1Home: DWORDLONG, + pub P2Home: DWORDLONG, + pub P3Home: DWORDLONG, + pub P4Home: DWORDLONG, + pub P5Home: DWORDLONG, + pub P6Home: DWORDLONG, + + pub ContextFlags: DWORD, + pub MxCsr: DWORD, + + pub SegCs: WORD, + pub SegDs: WORD, + pub SegEs: WORD, + pub SegFs: WORD, + pub SegGs: WORD, + pub SegSs: WORD, + pub EFlags: DWORD, + + pub Dr0: DWORDLONG, + pub Dr1: DWORDLONG, + pub Dr2: DWORDLONG, + pub Dr3: DWORDLONG, + pub Dr6: DWORDLONG, + pub Dr7: DWORDLONG, + + pub Rax: DWORDLONG, + pub Rcx: DWORDLONG, + pub Rdx: DWORDLONG, + pub Rbx: DWORDLONG, + pub Rsp: DWORDLONG, + pub Rbp: DWORDLONG, + pub Rsi: DWORDLONG, + pub Rdi: DWORDLONG, + pub R8: DWORDLONG, + pub R9: DWORDLONG, + pub R10: DWORDLONG, + pub R11: DWORDLONG, + pub R12: DWORDLONG, + pub R13: DWORDLONG, + pub R14: DWORDLONG, + pub R15: DWORDLONG, + + pub Rip: DWORDLONG, + + pub FltSave: FLOATING_SAVE_AREA, + + pub VectorRegister: [M128A; 26], + pub VectorControl: DWORDLONG, + + pub DebugControl: DWORDLONG, + pub LastBranchToRip: DWORDLONG, + pub LastBranchFromRip: DWORDLONG, + pub LastExceptionToRip: DWORDLONG, + pub LastExceptionFromRip: DWORDLONG, +} + +#[cfg(target_arch = "x86_64")] +#[repr(C)] +pub struct M128A { + _align_hack: [simd::u64x2; 0], // FIXME align on 16-byte + pub Low: c_ulonglong, + pub High: c_longlong +} + +#[cfg(target_arch = "x86_64")] +#[repr(C)] +pub struct FLOATING_SAVE_AREA { + _align_hack: [simd::u64x2; 0], // FIXME align on 16-byte + _Dummy: [u8; 512] // FIXME: Fill this out +} + +#[repr(C)] +pub struct SOCKADDR_STORAGE_LH { + pub ss_family: ADDRESS_FAMILY, + pub __ss_pad1: [CHAR; 6], + pub __ss_align: i64, + pub __ss_pad2: [CHAR; 112], +} + +#[repr(C)] +pub struct ADDRINFOA { + pub ai_flags: c_int, + pub ai_family: c_int, + pub ai_socktype: c_int, + pub ai_protocol: c_int, + pub ai_addrlen: size_t, + pub ai_canonname: *mut c_char, + pub ai_addr: *mut SOCKADDR, + pub ai_next: *mut ADDRINFOA, +} + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct sockaddr_in { + pub sin_family: ADDRESS_FAMILY, + pub sin_port: USHORT, + pub sin_addr: in_addr, + pub sin_zero: [CHAR; 8], +} + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct sockaddr_in6 { + pub sin6_family: ADDRESS_FAMILY, + pub sin6_port: USHORT, + pub sin6_flowinfo: c_ulong, + pub sin6_addr: in6_addr, + pub sin6_scope_id: c_ulong, +} + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct in_addr { + pub s_addr: u32, +} + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct in6_addr { + pub s6_addr: [u8; 16], +} + +pub enum UNWIND_HISTORY_TABLE {} + +#[repr(C)] +pub struct RUNTIME_FUNCTION { + pub BeginAddress: DWORD, + pub EndAddress: DWORD, + pub UnwindData: DWORD, +} + +#[repr(C)] +pub struct DISPATCHER_CONTEXT { + pub ControlPc: LPVOID, + pub ImageBase: LPVOID, + pub FunctionEntry: *const RUNTIME_FUNCTION, + pub EstablisherFrame: LPVOID, + pub TargetIp: LPVOID, + pub ContextRecord: *const CONTEXT, + pub LanguageHandler: LPVOID, + pub HandlerData: *const u8, + pub HistoryTable: *const UNWIND_HISTORY_TABLE, +} + +#[repr(C)] +#[derive(Copy, Clone)] +pub enum EXCEPTION_DISPOSITION { + ExceptionContinueExecution, + ExceptionContinueSearch, + ExceptionNestedException, + ExceptionCollidedUnwind +} + #[link(name = "ws2_32")] #[link(name = "userenv")] #[link(name = "shell32")] +#[link(name = "advapi32")] extern "system" { - pub fn WSAStartup(wVersionRequested: libc::WORD, - lpWSAData: LPWSADATA) -> libc::c_int; - pub fn WSACleanup() -> libc::c_int; - pub fn WSAGetLastError() -> libc::c_int; - pub fn WSACloseEvent(hEvent: WSAEVENT) -> libc::BOOL; - pub fn WSACreateEvent() -> WSAEVENT; - pub fn WSAEventSelect(s: libc::SOCKET, - hEventObject: WSAEVENT, - lNetworkEvents: libc::c_long) -> libc::c_int; - pub fn WSASetEvent(hEvent: WSAEVENT) -> libc::BOOL; - pub fn WSAWaitForMultipleEvents(cEvents: libc::DWORD, - lphEvents: *const WSAEVENT, - fWaitAll: libc::BOOL, - dwTimeout: libc::DWORD, - fAltertable: libc::BOOL) -> libc::DWORD; - pub fn WSAEnumNetworkEvents(s: libc::SOCKET, - hEventObject: WSAEVENT, - lpNetworkEvents: LPWSANETWORKEVENTS) - -> libc::c_int; - pub fn WSADuplicateSocketW(s: libc::SOCKET, - dwProcessId: libc::DWORD, + pub fn WSAStartup(wVersionRequested: WORD, + lpWSAData: LPWSADATA) -> c_int; + pub fn WSACleanup() -> c_int; + pub fn WSAGetLastError() -> c_int; + pub fn WSADuplicateSocketW(s: SOCKET, + dwProcessId: DWORD, lpProtocolInfo: LPWSAPROTOCOL_INFO) - -> libc::c_int; - pub fn GetCurrentProcessId() -> libc::DWORD; - pub fn WSASocketW(af: libc::c_int, - kind: libc::c_int, - protocol: libc::c_int, + -> c_int; + pub fn GetCurrentProcessId() -> DWORD; + pub fn WSASocketW(af: c_int, + kind: c_int, + protocol: c_int, lpProtocolInfo: LPWSAPROTOCOL_INFO, g: GROUP, - dwFlags: libc::DWORD) -> libc::SOCKET; - - pub fn ioctlsocket(s: libc::SOCKET, cmd: libc::c_long, - argp: *mut libc::c_ulong) -> libc::c_int; - pub fn select(nfds: libc::c_int, - readfds: *mut fd_set, - writefds: *mut fd_set, - exceptfds: *mut fd_set, - timeout: *mut libc::timeval) -> libc::c_int; - pub fn getsockopt(sockfd: libc::SOCKET, - level: libc::c_int, - optname: libc::c_int, - optval: *mut libc::c_char, - optlen: *mut libc::c_int) -> libc::c_int; - - pub fn SetEvent(hEvent: libc::HANDLE) -> libc::BOOL; - pub fn WaitForMultipleObjects(nCount: libc::DWORD, - lpHandles: *const libc::HANDLE, - bWaitAll: libc::BOOL, - dwMilliseconds: libc::DWORD) -> libc::DWORD; - - pub fn CancelIo(hFile: libc::HANDLE) -> libc::BOOL; - pub fn CancelIoEx(hFile: libc::HANDLE, - lpOverlapped: libc::LPOVERLAPPED) -> libc::BOOL; - + dwFlags: DWORD) -> SOCKET; pub fn InitializeCriticalSection(CriticalSection: *mut CRITICAL_SECTION); pub fn EnterCriticalSection(CriticalSection: *mut CRITICAL_SECTION); pub fn TryEnterCriticalSection(CriticalSection: *mut CRITICAL_SECTION) -> BOOLEAN; @@ -420,104 +963,274 @@ extern "system" { pub fn DeleteCriticalSection(CriticalSection: *mut CRITICAL_SECTION); // FIXME - pInputControl should be PCONSOLE_READCONSOLE_CONTROL - pub fn ReadConsoleW(hConsoleInput: libc::HANDLE, - lpBuffer: libc::LPVOID, - nNumberOfCharsToRead: libc::DWORD, - lpNumberOfCharsRead: libc::LPDWORD, - pInputControl: libc::LPVOID) -> libc::BOOL; - - pub fn WriteConsoleW(hConsoleOutput: libc::HANDLE, - lpBuffer: libc::types::os::arch::extra::LPCVOID, - nNumberOfCharsToWrite: libc::DWORD, - lpNumberOfCharsWritten: libc::LPDWORD, - lpReserved: libc::LPVOID) -> libc::BOOL; - - pub fn GetConsoleMode(hConsoleHandle: libc::HANDLE, - lpMode: libc::LPDWORD) -> libc::BOOL; - - pub fn SetConsoleMode(hConsoleHandle: libc::HANDLE, - lpMode: libc::DWORD) -> libc::BOOL; - pub fn GetConsoleScreenBufferInfo( - hConsoleOutput: libc::HANDLE, - lpConsoleScreenBufferInfo: PCONSOLE_SCREEN_BUFFER_INFO, - ) -> libc::BOOL; - - pub fn GetFileAttributesExW(lpFileName: libc::LPCWSTR, + pub fn ReadConsoleW(hConsoleInput: HANDLE, + lpBuffer: LPVOID, + nNumberOfCharsToRead: DWORD, + lpNumberOfCharsRead: LPDWORD, + pInputControl: LPVOID) -> BOOL; + + pub fn WriteConsoleW(hConsoleOutput: HANDLE, + lpBuffer: LPCVOID, + nNumberOfCharsToWrite: DWORD, + lpNumberOfCharsWritten: LPDWORD, + lpReserved: LPVOID) -> BOOL; + + pub fn GetConsoleMode(hConsoleHandle: HANDLE, + lpMode: LPDWORD) -> BOOL; + pub fn GetFileAttributesExW(lpFileName: LPCWSTR, fInfoLevelId: GET_FILEEX_INFO_LEVELS, - lpFileInformation: libc::LPVOID) -> libc::BOOL; - pub fn RemoveDirectoryW(lpPathName: libc::LPCWSTR) -> libc::BOOL; - pub fn SetFileAttributesW(lpFileName: libc::LPCWSTR, - dwFileAttributes: libc::DWORD) -> libc::BOOL; - pub fn GetFileAttributesW(lpFileName: libc::LPCWSTR) -> libc::DWORD; - pub fn GetFileInformationByHandle(hFile: libc::HANDLE, + lpFileInformation: LPVOID) -> BOOL; + pub fn RemoveDirectoryW(lpPathName: LPCWSTR) -> BOOL; + pub fn SetFileAttributesW(lpFileName: LPCWSTR, + dwFileAttributes: DWORD) -> BOOL; + pub fn GetFileInformationByHandle(hFile: HANDLE, lpFileInformation: LPBY_HANDLE_FILE_INFORMATION) - -> libc::BOOL; - - pub fn SetLastError(dwErrCode: libc::DWORD); - pub fn GetCommandLineW() -> *mut libc::LPCWSTR; - pub fn LocalFree(ptr: *mut libc::c_void); - pub fn CommandLineToArgvW(lpCmdLine: *mut libc::LPCWSTR, - pNumArgs: *mut libc::c_int) -> *mut *mut u16; - pub fn SetFileTime(hFile: libc::HANDLE, - lpCreationTime: *const libc::FILETIME, - lpLastAccessTime: *const libc::FILETIME, - lpLastWriteTime: *const libc::FILETIME) -> libc::BOOL; - pub fn GetTempPathW(nBufferLength: libc::DWORD, - lpBuffer: libc::LPCWSTR) -> libc::DWORD; - pub fn OpenProcessToken(ProcessHandle: libc::HANDLE, - DesiredAccess: libc::DWORD, - TokenHandle: *mut libc::HANDLE) -> libc::BOOL; - pub fn GetCurrentProcess() -> libc::HANDLE; - pub fn GetStdHandle(which: libc::DWORD) -> libc::HANDLE; - pub fn ExitProcess(uExitCode: libc::c_uint) -> !; - pub fn DeviceIoControl(hDevice: libc::HANDLE, - dwIoControlCode: libc::DWORD, - lpInBuffer: libc::LPVOID, - nInBufferSize: libc::DWORD, - lpOutBuffer: libc::LPVOID, - nOutBufferSize: libc::DWORD, - lpBytesReturned: libc::LPDWORD, - lpOverlapped: libc::LPOVERLAPPED) -> libc::BOOL; - pub fn CreatePipe(hReadPipe: libc::LPHANDLE, - hWritePipe: libc::LPHANDLE, - lpPipeAttributes: libc::LPSECURITY_ATTRIBUTES, - nSize: libc::DWORD) -> libc::BOOL; - pub fn CreateThread(lpThreadAttributes: libc::LPSECURITY_ATTRIBUTES, - dwStackSize: libc::SIZE_T, - lpStartAddress: extern "system" fn(*mut libc::c_void) - -> libc::DWORD, - lpParameter: libc::LPVOID, - dwCreationFlags: libc::DWORD, - lpThreadId: libc::LPDWORD) -> libc::HANDLE; - pub fn WaitForSingleObject(hHandle: libc::HANDLE, - dwMilliseconds: libc::DWORD) -> libc::DWORD; - pub fn SwitchToThread() -> libc::BOOL; - pub fn Sleep(dwMilliseconds: libc::DWORD); - pub fn GetProcessId(handle: libc::HANDLE) -> libc::DWORD; - pub fn GetUserProfileDirectoryW(hToken: libc::HANDLE, - lpProfileDir: libc::LPCWSTR, - lpcchSize: *mut libc::DWORD) -> libc::BOOL; - pub fn SetHandleInformation(hObject: libc::HANDLE, - dwMask: libc::DWORD, - dwFlags: libc::DWORD) -> libc::BOOL; - pub fn CopyFileExW(lpExistingFileName: libc::LPCWSTR, - lpNewFileName: libc::LPCWSTR, + -> BOOL; + + pub fn SetLastError(dwErrCode: DWORD); + pub fn GetCommandLineW() -> *mut LPCWSTR; + pub fn LocalFree(ptr: *mut c_void); + pub fn CommandLineToArgvW(lpCmdLine: *mut LPCWSTR, + pNumArgs: *mut c_int) -> *mut *mut u16; + pub fn GetTempPathW(nBufferLength: DWORD, + lpBuffer: LPCWSTR) -> DWORD; + pub fn OpenProcessToken(ProcessHandle: HANDLE, + DesiredAccess: DWORD, + TokenHandle: *mut HANDLE) -> BOOL; + pub fn GetCurrentProcess() -> HANDLE; + pub fn GetCurrentThread() -> HANDLE; + pub fn GetStdHandle(which: DWORD) -> HANDLE; + pub fn ExitProcess(uExitCode: c_uint) -> !; + pub fn DeviceIoControl(hDevice: HANDLE, + dwIoControlCode: DWORD, + lpInBuffer: LPVOID, + nInBufferSize: DWORD, + lpOutBuffer: LPVOID, + nOutBufferSize: DWORD, + lpBytesReturned: LPDWORD, + lpOverlapped: LPOVERLAPPED) -> BOOL; + pub fn CreatePipe(hReadPipe: LPHANDLE, + hWritePipe: LPHANDLE, + lpPipeAttributes: LPSECURITY_ATTRIBUTES, + nSize: DWORD) -> BOOL; + pub fn CreateThread(lpThreadAttributes: LPSECURITY_ATTRIBUTES, + dwStackSize: SIZE_T, + lpStartAddress: extern "system" fn(*mut c_void) + -> DWORD, + lpParameter: LPVOID, + dwCreationFlags: DWORD, + lpThreadId: LPDWORD) -> HANDLE; + pub fn WaitForSingleObject(hHandle: HANDLE, + dwMilliseconds: DWORD) -> DWORD; + pub fn SwitchToThread() -> BOOL; + pub fn Sleep(dwMilliseconds: DWORD); + pub fn GetProcessId(handle: HANDLE) -> DWORD; + pub fn GetUserProfileDirectoryW(hToken: HANDLE, + lpProfileDir: LPCWSTR, + lpcchSize: *mut DWORD) -> BOOL; + pub fn SetHandleInformation(hObject: HANDLE, + dwMask: DWORD, + dwFlags: DWORD) -> BOOL; + pub fn CopyFileExW(lpExistingFileName: LPCWSTR, + lpNewFileName: LPCWSTR, lpProgressRoutine: LPPROGRESS_ROUTINE, - lpData: libc::LPVOID, + lpData: LPVOID, pbCancel: LPBOOL, - dwCopyFlags: libc::DWORD) -> libc::BOOL; - pub fn LookupPrivilegeValueW(lpSystemName: libc::LPCWSTR, - lpName: libc::LPCWSTR, - lpLuid: PLUID) -> libc::BOOL; - pub fn AdjustTokenPrivileges(TokenHandle: libc::HANDLE, - DisableAllPrivileges: libc::BOOL, + dwCopyFlags: DWORD) -> BOOL; + pub fn LookupPrivilegeValueW(lpSystemName: LPCWSTR, + lpName: LPCWSTR, + lpLuid: PLUID) -> BOOL; + pub fn AdjustTokenPrivileges(TokenHandle: HANDLE, + DisableAllPrivileges: BOOL, NewState: PTOKEN_PRIVILEGES, - BufferLength: libc::DWORD, + BufferLength: DWORD, PreviousState: PTOKEN_PRIVILEGES, - ReturnLength: *mut libc::DWORD) -> libc::BOOL; + ReturnLength: *mut DWORD) -> BOOL; pub fn AddVectoredExceptionHandler(FirstHandler: ULONG, VectoredHandler: PVECTORED_EXCEPTION_HANDLER) -> LPVOID; + pub fn FormatMessageW(flags: DWORD, + lpSrc: LPVOID, + msgId: DWORD, + langId: DWORD, + buf: LPWSTR, + nsize: DWORD, + args: *const c_void) + -> DWORD; + pub fn TlsAlloc() -> DWORD; + pub fn TlsFree(dwTlsIndex: DWORD) -> BOOL; + pub fn TlsGetValue(dwTlsIndex: DWORD) -> LPVOID; + pub fn TlsSetValue(dwTlsIndex: DWORD, lpTlsvalue: LPVOID) -> BOOL; + pub fn GetLastError() -> DWORD; + pub fn QueryPerformanceFrequency(lpFrequency: *mut LARGE_INTEGER) -> BOOL; + pub fn QueryPerformanceCounter(lpPerformanceCount: *mut LARGE_INTEGER) + -> BOOL; + pub fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: LPDWORD) -> BOOL; + pub fn TerminateProcess(hProcess: HANDLE, uExitCode: UINT) -> BOOL; + pub fn CreateProcessW(lpApplicationName: LPCWSTR, + lpCommandLine: LPWSTR, + lpProcessAttributes: LPSECURITY_ATTRIBUTES, + lpThreadAttributes: LPSECURITY_ATTRIBUTES, + bInheritHandles: BOOL, + dwCreationFlags: DWORD, + lpEnvironment: LPVOID, + lpCurrentDirectory: LPCWSTR, + lpStartupInfo: LPSTARTUPINFO, + lpProcessInformation: LPPROCESS_INFORMATION) + -> BOOL; + pub fn GetEnvironmentVariableW(n: LPCWSTR, v: LPWSTR, nsize: DWORD) -> DWORD; + pub fn SetEnvironmentVariableW(n: LPCWSTR, v: LPCWSTR) -> BOOL; + pub fn GetEnvironmentStringsW() -> LPWCH; + pub fn FreeEnvironmentStringsW(env_ptr: LPWCH) -> BOOL; + pub fn GetModuleFileNameW(hModule: HMODULE, + lpFilename: LPWSTR, + nSize: DWORD) + -> DWORD; + pub fn CreateDirectoryW(lpPathName: LPCWSTR, + lpSecurityAttributes: LPSECURITY_ATTRIBUTES) + -> BOOL; + pub fn DeleteFileW(lpPathName: LPCWSTR) -> BOOL; + pub fn GetCurrentDirectoryW(nBufferLength: DWORD, lpBuffer: LPWSTR) -> DWORD; + pub fn SetCurrentDirectoryW(lpPathName: LPCWSTR) -> BOOL; + + pub fn closesocket(socket: SOCKET) -> c_int; + pub fn recv(socket: SOCKET, buf: *mut c_void, len: c_int, + flags: c_int) -> c_int; + pub fn send(socket: SOCKET, buf: *const c_void, len: c_int, + flags: c_int) -> c_int; + pub fn recvfrom(socket: SOCKET, + buf: *mut c_void, + len: c_int, + flags: c_int, + addr: *mut SOCKADDR, + addrlen: *mut c_int) + -> c_int; + pub fn sendto(socket: SOCKET, + buf: *const c_void, + len: c_int, + flags: c_int, + addr: *const SOCKADDR, + addrlen: c_int) + -> c_int; + pub fn shutdown(socket: SOCKET, how: c_int) -> c_int; + pub fn accept(socket: SOCKET, + address: *mut SOCKADDR, + address_len: *mut c_int) + -> SOCKET; + pub fn DuplicateHandle(hSourceProcessHandle: HANDLE, + hSourceHandle: HANDLE, + hTargetProcessHandle: HANDLE, + lpTargetHandle: LPHANDLE, + dwDesiredAccess: DWORD, + bInheritHandle: BOOL, + dwOptions: DWORD) + -> BOOL; + pub fn ReadFile(hFile: HANDLE, + lpBuffer: LPVOID, + nNumberOfBytesToRead: DWORD, + lpNumberOfBytesRead: LPDWORD, + lpOverlapped: LPOVERLAPPED) + -> BOOL; + pub fn WriteFile(hFile: HANDLE, + lpBuffer: LPVOID, + nNumberOfBytesToWrite: DWORD, + lpNumberOfBytesWritten: LPDWORD, + lpOverlapped: LPOVERLAPPED) + -> BOOL; + pub fn CloseHandle(hObject: HANDLE) -> BOOL; + pub fn CreateHardLinkW(lpSymlinkFileName: LPCWSTR, + lpTargetFileName: LPCWSTR, + lpSecurityAttributes: LPSECURITY_ATTRIBUTES) + -> BOOL; + pub fn MoveFileExW(lpExistingFileName: LPCWSTR, + lpNewFileName: LPCWSTR, + dwFlags: DWORD) + -> BOOL; + pub fn SetFilePointerEx(hFile: HANDLE, + liDistanceToMove: LARGE_INTEGER, + lpNewFilePointer: PLARGE_INTEGER, + dwMoveMethod: DWORD) + -> BOOL; + pub fn FlushFileBuffers(hFile: HANDLE) -> BOOL; + pub fn CreateFileW(lpFileName: LPCWSTR, + dwDesiredAccess: DWORD, + dwShareMode: DWORD, + lpSecurityAttributes: LPSECURITY_ATTRIBUTES, + dwCreationDisposition: DWORD, + dwFlagsAndAttributes: DWORD, + hTemplateFile: HANDLE) + -> HANDLE; + + pub fn FindFirstFileW(fileName: LPCWSTR, + findFileData: LPWIN32_FIND_DATAW) + -> HANDLE; + pub fn FindNextFileW(findFile: HANDLE, findFileData: LPWIN32_FIND_DATAW) + -> BOOL; + pub fn FindClose(findFile: HANDLE) -> BOOL; + pub fn RtlCaptureContext(ctx: *mut CONTEXT); + pub fn getsockopt(s: SOCKET, + level: c_int, + optname: c_int, + optval: *mut c_char, + optlen: *mut c_int) + -> c_int; + pub fn setsockopt(s: SOCKET, + level: c_int, + optname: c_int, + optval: *const c_void, + optlen: c_int) + -> c_int; + pub fn getsockname(socket: SOCKET, + address: *mut SOCKADDR, + address_len: *mut c_int) + -> c_int; + pub fn getpeername(socket: SOCKET, + address: *mut SOCKADDR, + address_len: *mut c_int) + -> c_int; + pub fn bind(socket: SOCKET, address: *const SOCKADDR, + address_len: socklen_t) -> c_int; + pub fn listen(socket: SOCKET, backlog: c_int) -> c_int; + pub fn connect(socket: SOCKET, address: *const SOCKADDR, len: c_int) + -> c_int; + pub fn getaddrinfo(node: *const c_char, service: *const c_char, + hints: *const ADDRINFOA, + res: *mut *mut ADDRINFOA) -> c_int; + pub fn freeaddrinfo(res: *mut ADDRINFOA); + pub fn getnameinfo(sa: *const SOCKADDR, salen: c_int, + host: *mut c_char, hostlen: DWORD, + serv: *mut c_char, servlen: DWORD, + flags: c_int) -> c_int; + + pub fn LoadLibraryW(name: LPCWSTR) -> HMODULE; + pub fn GetModuleHandleExW(dwFlags: DWORD, name: LPCWSTR, + handle: *mut HMODULE) -> BOOL; + pub fn GetProcAddress(handle: HMODULE, + name: LPCSTR) -> *mut c_void; + pub fn FreeLibrary(handle: HMODULE) -> BOOL; + pub fn SetErrorMode(uMode: c_uint) -> c_uint; + pub fn GetModuleHandleW(lpModuleName: LPCWSTR) -> HMODULE; + pub fn CryptAcquireContextA(phProv: *mut HCRYPTPROV, + pszContainer: LPCSTR, + pszProvider: LPCSTR, + dwProvType: DWORD, + dwFlags: DWORD) -> BOOL; + pub fn CryptGenRandom(hProv: HCRYPTPROV, + dwLen: DWORD, + pbBuffer: *mut BYTE) -> BOOL; + pub fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) -> BOOL; + + #[unwind] + pub fn RaiseException(dwExceptionCode: DWORD, + dwExceptionFlags: DWORD, + nNumberOfArguments: DWORD, + lpArguments: *const ULONG_PTR); + pub fn RtlUnwindEx(TargetFrame: LPVOID, + TargetIp: LPVOID, + ExceptionRecord: *const EXCEPTION_RECORD, + ReturnValue: LPVOID, + OriginalContext: *const CONTEXT, + HistoryTable: *const UNWIND_HISTORY_TABLE); } // Functions that aren't available on Windows XP, but we still use them and just diff --git a/src/libstd/sys/windows/compat.rs b/src/libstd/sys/windows/compat.rs index 3a03b91f24ed3..780a0d9427d59 100644 --- a/src/libstd/sys/windows/compat.rs +++ b/src/libstd/sys/windows/compat.rs @@ -24,21 +24,16 @@ use prelude::v1::*; use ffi::CString; -use libc::{LPVOID, LPCWSTR, HMODULE, LPCSTR}; use sync::atomic::{AtomicUsize, Ordering}; - -extern "system" { - fn GetModuleHandleW(lpModuleName: LPCWSTR) -> HMODULE; - fn GetProcAddress(hModule: HMODULE, lpProcName: LPCSTR) -> LPVOID; -} +use sys::c; pub fn lookup(module: &str, symbol: &str) -> Option { let mut module: Vec = module.utf16_units().collect(); module.push(0); let symbol = CString::new(symbol).unwrap(); unsafe { - let handle = GetModuleHandleW(module.as_ptr()); - match GetProcAddress(handle, symbol.as_ptr()) as usize { + let handle = c::GetModuleHandleW(module.as_ptr()); + match c::GetProcAddress(handle, symbol.as_ptr()) as usize { 0 => None, n => Some(n), } diff --git a/src/libstd/sys/windows/condvar.rs b/src/libstd/sys/windows/condvar.rs index ac76479d7dbd0..8075374d42bdd 100644 --- a/src/libstd/sys/windows/condvar.rs +++ b/src/libstd/sys/windows/condvar.rs @@ -9,7 +9,6 @@ // except according to those terms. use cell::UnsafeCell; -use libc::{self, DWORD}; use sys::c; use sys::mutex::{self, Mutex}; use sys::os; @@ -29,7 +28,7 @@ impl Condvar { pub unsafe fn wait(&self, mutex: &Mutex) { let r = c::SleepConditionVariableSRW(self.inner.get(), mutex::raw(mutex), - libc::INFINITE, + c::INFINITE, 0); debug_assert!(r != 0); } @@ -40,8 +39,7 @@ impl Condvar { super::dur2timeout(dur), 0); if r == 0 { - const ERROR_TIMEOUT: DWORD = 0x5B4; - debug_assert_eq!(os::errno() as usize, ERROR_TIMEOUT as usize); + debug_assert_eq!(os::errno() as usize, c::ERROR_TIMEOUT as usize); false } else { true diff --git a/src/libstd/sys/windows/ext/io.rs b/src/libstd/sys/windows/ext/io.rs index 9f10b0e856370..2ddb6c65fd357 100644 --- a/src/libstd/sys/windows/ext/io.rs +++ b/src/libstd/sys/windows/ext/io.rs @@ -15,6 +15,7 @@ use os::windows::raw; use net; use sys_common::{self, AsInner, FromInner, IntoInner}; use sys; +use sys::c; /// Raw HANDLEs. #[stable(feature = "rust1", since = "1.0.0")] @@ -73,7 +74,7 @@ impl AsRawHandle for fs::File { #[stable(feature = "from_raw_os", since = "1.1.0")] impl FromRawHandle for fs::File { unsafe fn from_raw_handle(handle: RawHandle) -> fs::File { - let handle = handle as ::libc::HANDLE; + let handle = handle as c::HANDLE; fs::File::from_inner(sys::fs::File::from_inner(handle)) } } diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs index fb2456564eb8d..0b0e1a1ece70c 100644 --- a/src/libstd/sys/windows/fs.rs +++ b/src/libstd/sys/windows/fs.rs @@ -14,7 +14,6 @@ use os::windows::prelude::*; use ffi::OsString; use fmt; use io::{self, Error, SeekFrom}; -use libc::{self, HANDLE}; use mem; use path::{Path, PathBuf}; use ptr; @@ -30,7 +29,7 @@ pub struct File { handle: Handle } #[derive(Clone)] pub struct FileAttr { data: c::WIN32_FILE_ATTRIBUTE_DATA, - reparse_tag: libc::DWORD, + reparse_tag: c::DWORD, } #[derive(Copy, Clone, PartialEq, Eq, Hash)] @@ -41,17 +40,17 @@ pub enum FileType { pub struct ReadDir { handle: FindNextFileHandle, root: Arc, - first: Option, + first: Option, } -struct FindNextFileHandle(libc::HANDLE); +struct FindNextFileHandle(c::HANDLE); unsafe impl Send for FindNextFileHandle {} unsafe impl Sync for FindNextFileHandle {} pub struct DirEntry { root: Arc, - data: libc::WIN32_FIND_DATAW, + data: c::WIN32_FIND_DATAW, } #[derive(Clone, Default)] @@ -61,15 +60,15 @@ pub struct OpenOptions { read: bool, write: bool, truncate: bool, - desired_access: Option, - share_mode: Option, - creation_disposition: Option, - flags_and_attributes: Option, + desired_access: Option, + share_mode: Option, + creation_disposition: Option, + flags_and_attributes: Option, security_attributes: usize, // *mut T doesn't have a Default impl } #[derive(Clone, PartialEq, Eq, Debug)] -pub struct FilePermissions { attrs: libc::DWORD } +pub struct FilePermissions { attrs: c::DWORD } pub struct DirBuilder; @@ -84,9 +83,8 @@ impl Iterator for ReadDir { unsafe { let mut wfd = mem::zeroed(); loop { - if libc::FindNextFileW(self.handle.0, &mut wfd) == 0 { - if libc::GetLastError() == - c::ERROR_NO_MORE_FILES as libc::DWORD { + if c::FindNextFileW(self.handle.0, &mut wfd) == 0 { + if c::GetLastError() == c::ERROR_NO_MORE_FILES { return None } else { return Some(Err(Error::last_os_error())) @@ -102,13 +100,13 @@ impl Iterator for ReadDir { impl Drop for FindNextFileHandle { fn drop(&mut self) { - let r = unsafe { libc::FindClose(self.0) }; + let r = unsafe { c::FindClose(self.0) }; debug_assert!(r != 0); } } impl DirEntry { - fn new(root: &Arc, wfd: &libc::WIN32_FIND_DATAW) -> Option { + fn new(root: &Arc, wfd: &c::WIN32_FIND_DATAW) -> Option { match &wfd.cFileName[0..3] { // check for '.' and '..' [46, 0, ..] | @@ -170,50 +168,50 @@ impl OpenOptions { pub fn share_mode(&mut self, val: u32) { self.share_mode = Some(val); } - pub fn security_attributes(&mut self, attrs: libc::LPSECURITY_ATTRIBUTES) { + pub fn security_attributes(&mut self, attrs: c::LPSECURITY_ATTRIBUTES) { self.security_attributes = attrs as usize; } - fn get_desired_access(&self) -> libc::DWORD { + fn get_desired_access(&self) -> c::DWORD { self.desired_access.unwrap_or({ - let mut base = if self.read {libc::FILE_GENERIC_READ} else {0} | - if self.write {libc::FILE_GENERIC_WRITE} else {0}; + let mut base = if self.read {c::FILE_GENERIC_READ} else {0} | + if self.write {c::FILE_GENERIC_WRITE} else {0}; if self.append { - base &= !libc::FILE_WRITE_DATA; - base |= libc::FILE_APPEND_DATA; + base &= !c::FILE_WRITE_DATA; + base |= c::FILE_APPEND_DATA; } base }) } - fn get_share_mode(&self) -> libc::DWORD { + fn get_share_mode(&self) -> c::DWORD { // libuv has a good comment about this, but the basic idea is that // we try to emulate unix semantics by enabling all sharing by // allowing things such as deleting a file while it's still open. - self.share_mode.unwrap_or(libc::FILE_SHARE_READ | - libc::FILE_SHARE_WRITE | - libc::FILE_SHARE_DELETE) + self.share_mode.unwrap_or(c::FILE_SHARE_READ | + c::FILE_SHARE_WRITE | + c::FILE_SHARE_DELETE) } - fn get_creation_disposition(&self) -> libc::DWORD { + fn get_creation_disposition(&self) -> c::DWORD { self.creation_disposition.unwrap_or({ match (self.create, self.truncate) { - (true, true) => libc::CREATE_ALWAYS, - (true, false) => libc::OPEN_ALWAYS, - (false, false) => libc::OPEN_EXISTING, + (true, true) => c::CREATE_ALWAYS, + (true, false) => c::OPEN_ALWAYS, + (false, false) => c::OPEN_EXISTING, (false, true) => { if self.write && !self.append { - libc::CREATE_ALWAYS + c::CREATE_ALWAYS } else { - libc::TRUNCATE_EXISTING + c::TRUNCATE_EXISTING } } } }) } - fn get_flags_and_attributes(&self) -> libc::DWORD { - self.flags_and_attributes.unwrap_or(libc::FILE_ATTRIBUTE_NORMAL) + fn get_flags_and_attributes(&self) -> c::DWORD { + self.flags_and_attributes.unwrap_or(c::FILE_ATTRIBUTE_NORMAL) } } @@ -230,15 +228,15 @@ impl File { pub fn open(path: &Path, opts: &OpenOptions) -> io::Result { let path = to_utf16(path); let handle = unsafe { - libc::CreateFileW(path.as_ptr(), - opts.get_desired_access(), - opts.get_share_mode(), - opts.security_attributes as *mut _, - opts.get_creation_disposition(), - opts.get_flags_and_attributes(), - ptr::null_mut()) + c::CreateFileW(path.as_ptr(), + opts.get_desired_access(), + opts.get_share_mode(), + opts.security_attributes as *mut _, + opts.get_creation_disposition(), + opts.get_flags_and_attributes(), + ptr::null_mut()) }; - if handle == libc::INVALID_HANDLE_VALUE { + if handle == c::INVALID_HANDLE_VALUE { Err(Error::last_os_error()) } else { Ok(File { handle: Handle::new(handle) }) @@ -246,7 +244,7 @@ impl File { } pub fn fsync(&self) -> io::Result<()> { - try!(cvt(unsafe { libc::FlushFileBuffers(self.handle.raw()) })); + try!(cvt(unsafe { c::FlushFileBuffers(self.handle.raw()) })); Ok(()) } @@ -254,14 +252,14 @@ impl File { pub fn truncate(&self, size: u64) -> io::Result<()> { let mut info = c::FILE_END_OF_FILE_INFO { - EndOfFile: size as libc::LARGE_INTEGER, + EndOfFile: size as c::LARGE_INTEGER, }; let size = mem::size_of_val(&info); try!(cvt(unsafe { c::SetFileInformationByHandle(self.handle.raw(), c::FileEndOfFileInfo, &mut info as *mut _ as *mut _, - size as libc::DWORD) + size as c::DWORD) })); Ok(()) } @@ -304,15 +302,15 @@ impl File { pub fn seek(&self, pos: SeekFrom) -> io::Result { let (whence, pos) = match pos { - SeekFrom::Start(n) => (libc::FILE_BEGIN, n as i64), - SeekFrom::End(n) => (libc::FILE_END, n), - SeekFrom::Current(n) => (libc::FILE_CURRENT, n), + SeekFrom::Start(n) => (c::FILE_BEGIN, n as i64), + SeekFrom::End(n) => (c::FILE_END, n), + SeekFrom::Current(n) => (c::FILE_CURRENT, n), }; - let pos = pos as libc::LARGE_INTEGER; + let pos = pos as c::LARGE_INTEGER; let mut newpos = 0; try!(cvt(unsafe { - libc::SetFilePointerEx(self.handle.raw(), pos, - &mut newpos, whence) + c::SetFilePointerEx(self.handle.raw(), pos, + &mut newpos, whence) })); Ok(newpos as u64) } @@ -323,7 +321,7 @@ impl File { fn reparse_point<'a>(&self, space: &'a mut [u8; c::MAXIMUM_REPARSE_DATA_BUFFER_SIZE]) - -> io::Result<(libc::DWORD, &'a c::REPARSE_DATA_BUFFER)> { + -> io::Result<(c::DWORD, &'a c::REPARSE_DATA_BUFFER)> { unsafe { let mut bytes = 0; try!(cvt({ @@ -332,7 +330,7 @@ impl File { ptr::null_mut(), 0, space.as_mut_ptr() as *mut _, - space.len() as libc::DWORD, + space.len() as c::DWORD, &mut bytes, ptr::null_mut()) })); @@ -361,8 +359,8 @@ impl File { } } -impl FromInner for File { - fn from_inner(handle: libc::HANDLE) -> File { +impl FromInner for File { + fn from_inner(handle: c::HANDLE) -> File { File { handle: Handle::new(handle) } } } @@ -402,12 +400,12 @@ impl FileAttr { pub fn accessed(&self) -> u64 { self.to_u64(&self.data.ftLastAccessTime) } pub fn modified(&self) -> u64 { self.to_u64(&self.data.ftLastWriteTime) } - fn to_u64(&self, ft: &libc::FILETIME) -> u64 { + fn to_u64(&self, ft: &c::FILETIME) -> u64 { (ft.dwLowDateTime as u64) | ((ft.dwHighDateTime as u64) << 32) } fn is_reparse_point(&self) -> bool { - self.data.dwFileAttributes & libc::FILE_ATTRIBUTE_REPARSE_POINT != 0 + self.data.dwFileAttributes & c::FILE_ATTRIBUTE_REPARSE_POINT != 0 } } @@ -426,8 +424,8 @@ impl FilePermissions { } impl FileType { - fn new(attrs: libc::DWORD, reparse_tag: libc::DWORD) -> FileType { - if attrs & libc::FILE_ATTRIBUTE_REPARSE_POINT != 0 { + fn new(attrs: c::DWORD, reparse_tag: c::DWORD) -> FileType { + if attrs & c::FILE_ATTRIBUTE_REPARSE_POINT != 0 { match reparse_tag { c::IO_REPARSE_TAG_SYMLINK => FileType::Symlink, c::IO_REPARSE_TAG_MOUNT_POINT => FileType::MountPoint, @@ -453,7 +451,7 @@ impl DirBuilder { pub fn mkdir(&self, p: &Path) -> io::Result<()> { let p = to_utf16(p); try!(cvt(unsafe { - libc::CreateDirectoryW(p.as_ptr(), ptr::null_mut()) + c::CreateDirectoryW(p.as_ptr(), ptr::null_mut()) })); Ok(()) } @@ -466,8 +464,8 @@ pub fn readdir(p: &Path) -> io::Result { unsafe { let mut wfd = mem::zeroed(); - let find_handle = libc::FindFirstFileW(path.as_ptr(), &mut wfd); - if find_handle != libc::INVALID_HANDLE_VALUE { + let find_handle = c::FindFirstFileW(path.as_ptr(), &mut wfd); + if find_handle != c::INVALID_HANDLE_VALUE { Ok(ReadDir { handle: FindNextFileHandle(find_handle), root: Arc::new(root), @@ -481,7 +479,7 @@ pub fn readdir(p: &Path) -> io::Result { pub fn unlink(p: &Path) -> io::Result<()> { let p_utf16 = to_utf16(p); - try!(cvt(unsafe { libc::DeleteFileW(p_utf16.as_ptr()) })); + try!(cvt(unsafe { c::DeleteFileW(p_utf16.as_ptr()) })); Ok(()) } @@ -489,8 +487,7 @@ pub fn rename(old: &Path, new: &Path) -> io::Result<()> { let old = to_utf16(old); let new = to_utf16(new); try!(cvt(unsafe { - libc::MoveFileExW(old.as_ptr(), new.as_ptr(), - libc::MOVEFILE_REPLACE_EXISTING) + c::MoveFileExW(old.as_ptr(), new.as_ptr(), c::MOVEFILE_REPLACE_EXISTING) })); Ok(()) } @@ -515,7 +512,7 @@ pub fn symlink_inner(src: &Path, dst: &Path, dir: bool) -> io::Result<()> { let dst = to_utf16(dst); let flags = if dir { c::SYMBOLIC_LINK_FLAG_DIRECTORY } else { 0 }; try!(cvt(unsafe { - c::CreateSymbolicLinkW(dst.as_ptr(), src.as_ptr(), flags) as libc::BOOL + c::CreateSymbolicLinkW(dst.as_ptr(), src.as_ptr(), flags) as c::BOOL })); Ok(()) } @@ -524,7 +521,7 @@ pub fn link(src: &Path, dst: &Path) -> io::Result<()> { let src = to_utf16(src); let dst = to_utf16(dst); try!(cvt(unsafe { - libc::CreateHardLinkW(dst.as_ptr(), src.as_ptr(), ptr::null_mut()) + c::CreateHardLinkW(dst.as_ptr(), src.as_ptr(), ptr::null_mut()) })); Ok(()) } @@ -575,7 +572,7 @@ pub fn set_perm(p: &Path, perm: FilePermissions) -> io::Result<()> { fn get_path(f: &File) -> io::Result { super::fill_utf16_buf(|buf, sz| unsafe { c::GetFinalPathNameByHandleW(f.handle.raw(), buf, sz, - libc::VOLUME_NAME_DOS) + c::VOLUME_NAME_DOS) }, |buf| { PathBuf::from(OsString::from_wide(buf)) }) @@ -592,16 +589,16 @@ pub fn canonicalize(p: &Path) -> io::Result { pub fn copy(from: &Path, to: &Path) -> io::Result { unsafe extern "system" fn callback( - _TotalFileSize: libc::LARGE_INTEGER, - TotalBytesTransferred: libc::LARGE_INTEGER, - _StreamSize: libc::LARGE_INTEGER, - _StreamBytesTransferred: libc::LARGE_INTEGER, - _dwStreamNumber: libc::DWORD, - _dwCallbackReason: libc::DWORD, - _hSourceFile: HANDLE, - _hDestinationFile: HANDLE, - lpData: libc::LPVOID, - ) -> libc::DWORD { + _TotalFileSize: c::LARGE_INTEGER, + TotalBytesTransferred: c::LARGE_INTEGER, + _StreamSize: c::LARGE_INTEGER, + _StreamBytesTransferred: c::LARGE_INTEGER, + _dwStreamNumber: c::DWORD, + _dwCallbackReason: c::DWORD, + _hSourceFile: c::HANDLE, + _hDestinationFile: c::HANDLE, + lpData: c::LPVOID, + ) -> c::DWORD { *(lpData as *mut i64) = TotalBytesTransferred; c::PROGRESS_CONTINUE } @@ -673,10 +670,10 @@ fn directory_junctions_are_directories() { *buf.offset(i) = 0; i += 1; (*db).ReparseTag = c::IO_REPARSE_TAG_MOUNT_POINT; - (*db).ReparseTargetMaximumLength = (i * 2) as libc::WORD; - (*db).ReparseTargetLength = ((i - 1) * 2) as libc::WORD; + (*db).ReparseTargetMaximumLength = (i * 2) as c::WORD; + (*db).ReparseTargetLength = ((i - 1) * 2) as c::WORD; (*db).ReparseDataLength = - (*db).ReparseTargetLength as libc::DWORD + 12; + (*db).ReparseTargetLength as c::DWORD + 12; let mut ret = 0; cvt(c::DeviceIoControl(h as *mut _, @@ -707,10 +704,10 @@ fn directory_junctions_are_directories() { &mut tp.Privileges[0].Luid))); tp.PrivilegeCount = 1; tp.Privileges[0].Attributes = c::SE_PRIVILEGE_ENABLED; - let size = mem::size_of::() as libc::DWORD; - try!(cvt(c::AdjustTokenPrivileges(token, libc::FALSE, &mut tp, size, + let size = mem::size_of::() as c::DWORD; + try!(cvt(c::AdjustTokenPrivileges(token, c::FALSE, &mut tp, size, ptr::null_mut(), ptr::null_mut()))); - try!(cvt(libc::CloseHandle(token))); + try!(cvt(c::CloseHandle(token))); File::open_reparse_point(p, write) } diff --git a/src/libstd/sys/windows/handle.rs b/src/libstd/sys/windows/handle.rs index a9e9b0e252077..cb41b05daaea2 100644 --- a/src/libstd/sys/windows/handle.rs +++ b/src/libstd/sys/windows/handle.rs @@ -10,11 +10,10 @@ use io::ErrorKind; use io; -use libc::funcs::extra::kernel32::{GetCurrentProcess, DuplicateHandle}; -use libc::{self, HANDLE}; use mem; use ops::Deref; use ptr; +use sys::c; use sys::cvt; /// An owned container for `HANDLE` object, closing them on Drop. @@ -28,17 +27,17 @@ pub struct Handle(RawHandle); /// This does **not** drop the handle when it goes out of scope, use `Handle` /// instead for that. #[derive(Copy, Clone)] -pub struct RawHandle(HANDLE); +pub struct RawHandle(c::HANDLE); unsafe impl Send for RawHandle {} unsafe impl Sync for RawHandle {} impl Handle { - pub fn new(handle: HANDLE) -> Handle { + pub fn new(handle: c::HANDLE) -> Handle { Handle(RawHandle::new(handle)) } - pub fn into_raw(self) -> HANDLE { + pub fn into_raw(self) -> c::HANDLE { let ret = self.raw(); mem::forget(self); return ret; @@ -52,22 +51,22 @@ impl Deref for Handle { impl Drop for Handle { fn drop(&mut self) { - unsafe { let _ = libc::CloseHandle(self.raw()); } + unsafe { let _ = c::CloseHandle(self.raw()); } } } impl RawHandle { - pub fn new(handle: HANDLE) -> RawHandle { + pub fn new(handle: c::HANDLE) -> RawHandle { RawHandle(handle) } - pub fn raw(&self) -> HANDLE { self.0 } + pub fn raw(&self) -> c::HANDLE { self.0 } pub fn read(&self, buf: &mut [u8]) -> io::Result { let mut read = 0; let res = cvt(unsafe { - libc::ReadFile(self.0, buf.as_ptr() as libc::LPVOID, - buf.len() as libc::DWORD, &mut read, + c::ReadFile(self.0, buf.as_ptr() as c::LPVOID, + buf.len() as c::DWORD, &mut read, ptr::null_mut()) }); @@ -87,20 +86,20 @@ impl RawHandle { pub fn write(&self, buf: &[u8]) -> io::Result { let mut amt = 0; try!(cvt(unsafe { - libc::WriteFile(self.0, buf.as_ptr() as libc::LPVOID, - buf.len() as libc::DWORD, &mut amt, + c::WriteFile(self.0, buf.as_ptr() as c::LPVOID, + buf.len() as c::DWORD, &mut amt, ptr::null_mut()) })); Ok(amt as usize) } - pub fn duplicate(&self, access: libc::DWORD, inherit: bool, - options: libc::DWORD) -> io::Result { - let mut ret = 0 as libc::HANDLE; + pub fn duplicate(&self, access: c::DWORD, inherit: bool, + options: c::DWORD) -> io::Result { + let mut ret = 0 as c::HANDLE; try!(cvt(unsafe { - let cur_proc = GetCurrentProcess(); - DuplicateHandle(cur_proc, self.0, cur_proc, &mut ret, - access, inherit as libc::BOOL, + let cur_proc = c::GetCurrentProcess(); + c::DuplicateHandle(cur_proc, self.0, cur_proc, &mut ret, + access, inherit as c::BOOL, options) })); Ok(Handle::new(ret)) diff --git a/src/libstd/sys/windows/mod.rs b/src/libstd/sys/windows/mod.rs index 4df3c561ab1c3..3f76218eafee6 100644 --- a/src/libstd/sys/windows/mod.rs +++ b/src/libstd/sys/windows/mod.rs @@ -16,7 +16,6 @@ use prelude::v1::*; use ffi::{OsStr, OsString}; use io::{self, ErrorKind}; -use libc; use num::Zero; use os::windows::ffi::{OsStrExt, OsStringExt}; use path::PathBuf; @@ -46,25 +45,28 @@ pub mod stdio; pub fn init() {} pub fn decode_error_kind(errno: i32) -> ErrorKind { - match errno as libc::c_int { - libc::ERROR_ACCESS_DENIED => ErrorKind::PermissionDenied, - libc::ERROR_ALREADY_EXISTS => ErrorKind::AlreadyExists, - libc::ERROR_BROKEN_PIPE => ErrorKind::BrokenPipe, - libc::ERROR_FILE_NOT_FOUND => ErrorKind::NotFound, - c::ERROR_PATH_NOT_FOUND => ErrorKind::NotFound, - libc::ERROR_NO_DATA => ErrorKind::BrokenPipe, - libc::ERROR_OPERATION_ABORTED => ErrorKind::TimedOut, - - libc::WSAEACCES => ErrorKind::PermissionDenied, - libc::WSAEADDRINUSE => ErrorKind::AddrInUse, - libc::WSAEADDRNOTAVAIL => ErrorKind::AddrNotAvailable, - libc::WSAECONNABORTED => ErrorKind::ConnectionAborted, - libc::WSAECONNREFUSED => ErrorKind::ConnectionRefused, - libc::WSAECONNRESET => ErrorKind::ConnectionReset, - libc::WSAEINVAL => ErrorKind::InvalidInput, - libc::WSAENOTCONN => ErrorKind::NotConnected, - libc::WSAEWOULDBLOCK => ErrorKind::WouldBlock, - libc::WSAETIMEDOUT => ErrorKind::TimedOut, + match errno as c::DWORD { + c::ERROR_ACCESS_DENIED => return ErrorKind::PermissionDenied, + c::ERROR_ALREADY_EXISTS => return ErrorKind::AlreadyExists, + c::ERROR_BROKEN_PIPE => return ErrorKind::BrokenPipe, + c::ERROR_FILE_NOT_FOUND => return ErrorKind::NotFound, + c::ERROR_PATH_NOT_FOUND => return ErrorKind::NotFound, + c::ERROR_NO_DATA => return ErrorKind::BrokenPipe, + c::ERROR_OPERATION_ABORTED => return ErrorKind::TimedOut, + _ => {} + } + + match errno { + c::WSAEACCES => ErrorKind::PermissionDenied, + c::WSAEADDRINUSE => ErrorKind::AddrInUse, + c::WSAEADDRNOTAVAIL => ErrorKind::AddrNotAvailable, + c::WSAECONNABORTED => ErrorKind::ConnectionAborted, + c::WSAECONNREFUSED => ErrorKind::ConnectionRefused, + c::WSAECONNRESET => ErrorKind::ConnectionReset, + c::WSAEINVAL => ErrorKind::InvalidInput, + c::WSAENOTCONN => ErrorKind::NotConnected, + c::WSAEWOULDBLOCK => ErrorKind::WouldBlock, + c::WSAETIMEDOUT => ErrorKind::TimedOut, _ => ErrorKind::Other, } @@ -91,7 +93,7 @@ fn to_utf16_os(s: &OsStr) -> Vec { // yielded the data which has been read from the syscall. The return value // from this closure is then the return value of the function. fn fill_utf16_buf(mut f1: F1, f2: F2) -> io::Result - where F1: FnMut(*mut u16, libc::DWORD) -> libc::DWORD, + where F1: FnMut(*mut u16, c::DWORD) -> c::DWORD, F2: FnOnce(&[u16]) -> T { // Start off with a stack buf but then spill over to the heap if we end up @@ -120,13 +122,12 @@ fn fill_utf16_buf(mut f1: F1, f2: F2) -> io::Result // error" is still 0 then we interpret it as a 0 length buffer and // not an actual error. c::SetLastError(0); - let k = match f1(buf.as_mut_ptr(), n as libc::DWORD) { - 0 if libc::GetLastError() == 0 => 0, + let k = match f1(buf.as_mut_ptr(), n as c::DWORD) { + 0 if c::GetLastError() == 0 => 0, 0 => return Err(io::Error::last_os_error()), n => n, } as usize; - if k == n && libc::GetLastError() == - libc::ERROR_INSUFFICIENT_BUFFER as libc::DWORD { + if k == n && c::GetLastError() == c::ERROR_INSUFFICIENT_BUFFER { n *= 2; } else if k >= n { n = k; @@ -157,7 +158,7 @@ fn cvt(i: I) -> io::Result { } } -fn dur2timeout(dur: Duration) -> libc::DWORD { +fn dur2timeout(dur: Duration) -> c::DWORD { // Note that a duration is a (u64, u32) (seconds, nanoseconds) pair, and the // timeouts in windows APIs are typically u32 milliseconds. To translate, we // have two pieces to take care of: @@ -170,10 +171,10 @@ fn dur2timeout(dur: Duration) -> libc::DWORD { }).and_then(|ms| { ms.checked_add(if dur.subsec_nanos() % 1_000_000 > 0 {1} else {0}) }).map(|ms| { - if ms > ::max_value() as u64 { - libc::INFINITE + if ms > ::max_value() as u64 { + c::INFINITE } else { - ms as libc::DWORD + ms as c::DWORD } - }).unwrap_or(libc::INFINITE) + }).unwrap_or(c::INFINITE) } diff --git a/src/libstd/sys/windows/net.rs b/src/libstd/sys/windows/net.rs index 998b4fcb1a121..3e69902dcb6bd 100644 --- a/src/libstd/sys/windows/net.rs +++ b/src/libstd/sys/windows/net.rs @@ -9,23 +9,30 @@ // except according to those terms. use io; -use libc::consts::os::extra::INVALID_SOCKET; -use libc::{self, c_int, c_void}; +use libc::{c_int, c_void}; use mem; -use net::SocketAddr; +use net::{SocketAddr, Shutdown}; use num::One; use ops::Neg; use ptr; use sync::Once; -use sys; use sys::c; +use sys; use sys_common::{self, AsInner, FromInner, IntoInner}; -use sys_common::net::{setsockopt, getsockopt}; +use sys_common::net; use time::Duration; pub type wrlen_t = i32; -pub struct Socket(libc::SOCKET); +pub mod netc { + pub use sys::c::*; + pub use sys::c::SOCKADDR as sockaddr; + pub use sys::c::SOCKADDR_STORAGE_LH as sockaddr_storage; + pub use sys::c::ADDRINFOA as addrinfo; + pub use sys::c::ADDRESS_FAMILY as sa_family_t; +} + +pub struct Socket(c::SOCKET); /// Checks whether the Windows socket interface has been started already, and /// if not, starts it. @@ -76,13 +83,13 @@ pub fn cvt_r(mut f: F) -> io::Result impl Socket { pub fn new(addr: &SocketAddr, ty: c_int) -> io::Result { let fam = match *addr { - SocketAddr::V4(..) => libc::AF_INET, - SocketAddr::V6(..) => libc::AF_INET6, + SocketAddr::V4(..) => c::AF_INET, + SocketAddr::V6(..) => c::AF_INET6, }; let socket = try!(unsafe { match c::WSASocketW(fam, ty, 0, ptr::null_mut(), 0, c::WSA_FLAG_OVERLAPPED) { - INVALID_SOCKET => Err(last_error()), + c::INVALID_SOCKET => Err(last_error()), n => Ok(Socket(n)), } }); @@ -90,11 +97,11 @@ impl Socket { Ok(socket) } - pub fn accept(&self, storage: *mut libc::sockaddr, - len: *mut libc::socklen_t) -> io::Result { + pub fn accept(&self, storage: *mut c::SOCKADDR, + len: *mut c_int) -> io::Result { let socket = try!(unsafe { - match libc::accept(self.0, storage, len) { - INVALID_SOCKET => Err(last_error()), + match c::accept(self.0, storage, len) { + c::INVALID_SOCKET => Err(last_error()), n => Ok(Socket(n)), } }); @@ -113,7 +120,7 @@ impl Socket { info.iProtocol, &mut info, 0, c::WSA_FLAG_OVERLAPPED) { - INVALID_SOCKET => Err(last_error()), + c::INVALID_SOCKET => Err(last_error()), n => Ok(Socket(n)), } }); @@ -125,7 +132,7 @@ impl Socket { // On unix when a socket is shut down all further reads return 0, so we // do the same on windows to map a shut down socket to returning EOF. unsafe { - match libc::recv(self.0, buf.as_mut_ptr() as *mut c_void, + match c::recv(self.0, buf.as_mut_ptr() as *mut c_void, buf.len() as i32, 0) { -1 if c::WSAGetLastError() == c::WSAESHUTDOWN => Ok(0), -1 => Err(last_error()), @@ -134,7 +141,8 @@ impl Socket { } } - pub fn set_timeout(&self, dur: Option, kind: libc::c_int) -> io::Result<()> { + pub fn set_timeout(&self, dur: Option, + kind: c_int) -> io::Result<()> { let timeout = match dur { Some(dur) => { let timeout = sys::dur2timeout(dur); @@ -146,11 +154,11 @@ impl Socket { } None => 0 }; - setsockopt(self, libc::SOL_SOCKET, kind, timeout) + net::setsockopt(self, c::SOL_SOCKET, kind, timeout) } - pub fn timeout(&self, kind: libc::c_int) -> io::Result> { - let raw: libc::DWORD = try!(getsockopt(self, libc::SOL_SOCKET, kind)); + pub fn timeout(&self, kind: c_int) -> io::Result> { + let raw: c::DWORD = try!(net::getsockopt(self, c::SOL_SOCKET, kind)); if raw == 0 { Ok(None) } else { @@ -162,28 +170,38 @@ impl Socket { fn set_no_inherit(&self) -> io::Result<()> { sys::cvt(unsafe { - c::SetHandleInformation(self.0 as libc::HANDLE, + c::SetHandleInformation(self.0 as c::HANDLE, c::HANDLE_FLAG_INHERIT, 0) }).map(|_| ()) } + + pub fn shutdown(&self, how: Shutdown) -> io::Result<()> { + let how = match how { + Shutdown::Write => c::SD_SEND, + Shutdown::Read => c::SD_RECEIVE, + Shutdown::Both => c::SD_BOTH, + }; + try!(cvt(unsafe { c::shutdown(self.0, how) })); + Ok(()) + } } impl Drop for Socket { fn drop(&mut self) { - let _ = unsafe { libc::closesocket(self.0) }; + let _ = unsafe { c::closesocket(self.0) }; } } -impl AsInner for Socket { - fn as_inner(&self) -> &libc::SOCKET { &self.0 } +impl AsInner for Socket { + fn as_inner(&self) -> &c::SOCKET { &self.0 } } -impl FromInner for Socket { - fn from_inner(sock: libc::SOCKET) -> Socket { Socket(sock) } +impl FromInner for Socket { + fn from_inner(sock: c::SOCKET) -> Socket { Socket(sock) } } -impl IntoInner for Socket { - fn into_inner(self) -> libc::SOCKET { +impl IntoInner for Socket { + fn into_inner(self) -> c::SOCKET { let ret = self.0; mem::forget(self); ret diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index ba4bce38014a4..52740b2cad4f0 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -19,8 +19,7 @@ use error::Error as StdError; use ffi::{OsString, OsStr}; use fmt; use io; -use libc::types::os::arch::extra::LPWCH; -use libc::{self, c_int, c_void}; +use libc::{c_int, c_void}; use ops::Range; use os::windows::ffi::EncodeWide; use path::{self, PathBuf}; @@ -29,52 +28,27 @@ use slice; use sys::{c, cvt}; use sys::handle::Handle; -use libc::funcs::extra::kernel32::{ - GetEnvironmentStringsW, - FreeEnvironmentStringsW -}; - pub fn errno() -> i32 { - unsafe { libc::GetLastError() as i32 } + unsafe { c::GetLastError() as i32 } } /// Gets a detailed string description for the given error number. pub fn error_string(errnum: i32) -> String { - use libc::types::os::arch::extra::DWORD; - use libc::types::os::arch::extra::LPWSTR; - use libc::types::os::arch::extra::LPVOID; - use libc::types::os::arch::extra::WCHAR; - - #[link_name = "kernel32"] - extern "system" { - fn FormatMessageW(flags: DWORD, - lpSrc: LPVOID, - msgId: DWORD, - langId: DWORD, - buf: LPWSTR, - nsize: DWORD, - args: *const c_void) - -> DWORD; - } - - const FORMAT_MESSAGE_FROM_SYSTEM: DWORD = 0x00001000; - const FORMAT_MESSAGE_IGNORE_INSERTS: DWORD = 0x00000200; - // This value is calculated from the macro // MAKELANGID(LANG_SYSTEM_DEFAULT, SUBLANG_SYS_DEFAULT) - let langId = 0x0800 as DWORD; + let langId = 0x0800 as c::DWORD; - let mut buf = [0 as WCHAR; 2048]; + let mut buf = [0 as c::WCHAR; 2048]; unsafe { - let res = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - ptr::null_mut(), - errnum as DWORD, - langId, - buf.as_mut_ptr(), - buf.len() as DWORD, - ptr::null()) as usize; + let res = c::FormatMessageW(c::FORMAT_MESSAGE_FROM_SYSTEM | + c::FORMAT_MESSAGE_IGNORE_INSERTS, + ptr::null_mut(), + errnum as c::DWORD, + langId, + buf.as_mut_ptr(), + buf.len() as c::DWORD, + ptr::null()) as usize; if res == 0 { // Sometimes FormatMessageW can fail e.g. system doesn't like langId, let fm_err = errno(); @@ -96,8 +70,8 @@ pub fn error_string(errnum: i32) -> String { } pub struct Env { - base: LPWCH, - cur: LPWCH, + base: c::LPWCH, + cur: c::LPWCH, } impl Iterator for Env { @@ -126,13 +100,13 @@ impl Iterator for Env { impl Drop for Env { fn drop(&mut self) { - unsafe { FreeEnvironmentStringsW(self.base); } + unsafe { c::FreeEnvironmentStringsW(self.base); } } } pub fn env() -> Env { unsafe { - let ch = GetEnvironmentStringsW(); + let ch = c::GetEnvironmentStringsW(); if ch as usize == 0 { panic!("failure getting env string from OS: {}", io::Error::last_os_error()); @@ -233,13 +207,13 @@ impl StdError for JoinPathsError { pub fn current_exe() -> io::Result { super::fill_utf16_buf(|buf, sz| unsafe { - libc::GetModuleFileNameW(ptr::null_mut(), buf, sz) + c::GetModuleFileNameW(ptr::null_mut(), buf, sz) }, super::os2path) } pub fn getcwd() -> io::Result { super::fill_utf16_buf(|buf, sz| unsafe { - libc::GetCurrentDirectoryW(sz, buf) + c::GetCurrentDirectoryW(sz, buf) }, super::os2path) } @@ -249,23 +223,26 @@ pub fn chdir(p: &path::Path) -> io::Result<()> { p.push(0); cvt(unsafe { - libc::SetCurrentDirectoryW(p.as_ptr()) + c::SetCurrentDirectoryW(p.as_ptr()) }).map(|_| ()) } pub fn getenv(k: &OsStr) -> io::Result> { let k = super::to_utf16_os(k); let res = super::fill_utf16_buf(|buf, sz| unsafe { - libc::GetEnvironmentVariableW(k.as_ptr(), buf, sz) + c::GetEnvironmentVariableW(k.as_ptr(), buf, sz) }, |buf| { OsStringExt::from_wide(buf) }); match res { Ok(value) => Ok(Some(value)), - Err(ref e) if e.raw_os_error() == Some(c::ERROR_ENVVAR_NOT_FOUND) => { - Ok(None) + Err(e) => { + if e.raw_os_error() == Some(c::ERROR_ENVVAR_NOT_FOUND as i32) { + Ok(None) + } else { + Err(e) + } } - Err(e) => Err(e) } } @@ -274,14 +251,14 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { let v = super::to_utf16_os(v); cvt(unsafe { - libc::SetEnvironmentVariableW(k.as_ptr(), v.as_ptr()) + c::SetEnvironmentVariableW(k.as_ptr(), v.as_ptr()) }).map(|_| ()) } pub fn unsetenv(n: &OsStr) -> io::Result<()> { let v = super::to_utf16_os(n); cvt(unsafe { - libc::SetEnvironmentVariableW(v.as_ptr(), ptr::null()) + c::SetEnvironmentVariableW(v.as_ptr(), ptr::null()) }).map(|_| ()) } @@ -350,14 +327,14 @@ pub fn home_dir() -> Option { let _handle = Handle::new(token); super::fill_utf16_buf(|buf, mut sz| { match c::GetUserProfileDirectoryW(token, buf, &mut sz) { - 0 if libc::GetLastError() != 0 => 0, + 0 if c::GetLastError() != 0 => 0, 0 => sz, - n => n as libc::DWORD, + n => n as c::DWORD, } }, super::os2path).ok() }) } pub fn exit(code: i32) -> ! { - unsafe { c::ExitProcess(code as libc::c_uint) } + unsafe { c::ExitProcess(code as c::UINT) } } diff --git a/src/libstd/sys/windows/pipe.rs b/src/libstd/sys/windows/pipe.rs index 3e2f442f073f6..a6e69c789d098 100644 --- a/src/libstd/sys/windows/pipe.rs +++ b/src/libstd/sys/windows/pipe.rs @@ -9,7 +9,6 @@ // except according to those terms. use io; -use libc; use ptr; use sys::cvt; use sys::c; @@ -24,8 +23,8 @@ pub struct AnonPipe { } pub fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> { - let mut reader = libc::INVALID_HANDLE_VALUE; - let mut writer = libc::INVALID_HANDLE_VALUE; + let mut reader = c::INVALID_HANDLE_VALUE; + let mut writer = c::INVALID_HANDLE_VALUE; try!(cvt(unsafe { c::CreatePipe(&mut reader, &mut writer, ptr::null_mut(), 0) })); @@ -38,7 +37,7 @@ impl AnonPipe { pub fn handle(&self) -> &Handle { &self.inner } pub fn into_handle(self) -> Handle { self.inner } - pub fn raw(&self) -> libc::HANDLE { self.inner.raw() } + pub fn raw(&self) -> c::HANDLE { self.inner.raw() } pub fn read(&self, buf: &mut [u8]) -> io::Result { self.inner.read(buf) diff --git a/src/libstd/sys/windows/printing/gnu.rs b/src/libstd/sys/windows/printing/gnu.rs index e27bef0b1e989..c1367d5381da1 100644 --- a/src/libstd/sys/windows/printing/gnu.rs +++ b/src/libstd/sys/windows/printing/gnu.rs @@ -11,14 +11,15 @@ #![allow(deprecated)] use dynamic_lib::DynamicLibrary; -use io; use io::prelude::*; -use libc; +use io; +use sys::c; +use libc::c_void; use sys_common::gnu::libbacktrace; -pub fn print(w: &mut Write, i: isize, addr: u64, _: &DynamicLibrary, _: libc::HANDLE) +pub fn print(w: &mut Write, i: isize, addr: u64, _: &DynamicLibrary, _: c::HANDLE) -> io::Result<()> { - let addr = addr as usize as *mut libc::c_void; + let addr = addr as usize as *mut c_void; libbacktrace::print(w, i, addr, addr) } diff --git a/src/libstd/sys/windows/printing/msvc.rs b/src/libstd/sys/windows/printing/msvc.rs index 6f1db5df7db2a..d04691a6a4783 100644 --- a/src/libstd/sys/windows/printing/msvc.rs +++ b/src/libstd/sys/windows/printing/msvc.rs @@ -10,22 +10,23 @@ #![allow(deprecated)] -use sys_common::backtrace::{output, output_fileline}; -use ffi::CStr; use dynamic_lib::DynamicLibrary; -use super::{SymFromAddrFn, SymGetLineFromAddr64Fn, SYMBOL_INFO, MAX_SYM_NAME, IMAGEHLP_LINE64}; -use io; +use ffi::CStr; use io::prelude::*; -use intrinsics; -use libc; +use io; +use libc::{c_ulong, c_int, c_char, c_void}; +use mem; +use super::{SymFromAddrFn, SymGetLineFromAddr64Fn}; +use sys::c; +use sys_common::backtrace::{output, output_fileline}; -pub fn print(w: &mut Write, i: isize, addr: u64, dbghelp: &DynamicLibrary, process: libc::HANDLE) - -> io::Result<()> { +pub fn print(w: &mut Write, i: isize, addr: u64, dbghelp: &DynamicLibrary, + process: c::HANDLE) -> io::Result<()> { let SymFromAddr = sym!(dbghelp, "SymFromAddr", SymFromAddrFn); let SymGetLineFromAddr64 = sym!(dbghelp, "SymGetLineFromAddr64", SymGetLineFromAddr64Fn); - let mut info: SYMBOL_INFO = unsafe { intrinsics::init() }; - info.MaxNameLen = MAX_SYM_NAME as libc::c_ulong; + let mut info: c::SYMBOL_INFO = unsafe { mem::zeroed() }; + info.MaxNameLen = c::MAX_SYM_NAME as c_ulong; // the struct size in C. the value is different to // `size_of::() - MAX_SYM_NAME + 1` (== 81) // due to struct alignment. @@ -34,25 +35,25 @@ pub fn print(w: &mut Write, i: isize, addr: u64, dbghelp: &DynamicLibrary, proce let mut displacement = 0u64; let ret = SymFromAddr(process, addr, &mut displacement, &mut info); - let name = if ret == libc::TRUE { - let ptr = info.Name.as_ptr() as *const libc::c_char; + let name = if ret == c::TRUE { + let ptr = info.Name.as_ptr() as *const c_char; Some(unsafe { CStr::from_ptr(ptr).to_bytes() }) } else { None }; - try!(output(w, i, addr as usize as *mut libc::c_void, name)); + try!(output(w, i, addr as usize as *mut c_void, name)); // Now find out the filename and line number - let mut line: IMAGEHLP_LINE64 = unsafe { intrinsics::init() }; - line.SizeOfStruct = ::mem::size_of::() as u32; + let mut line: c::IMAGEHLP_LINE64 = unsafe { mem::zeroed() }; + line.SizeOfStruct = ::mem::size_of::() as u32; let mut displacement = 0u32; let ret = SymGetLineFromAddr64(process, addr, &mut displacement, &mut line); - if ret == libc::TRUE { + if ret == c::TRUE { output_fileline(w, unsafe { CStr::from_ptr(line.Filename).to_bytes() }, - line.LineNumber as libc::c_int, + line.LineNumber as c_int, false) } else { Ok(()) diff --git a/src/libstd/sys/windows/process.rs b/src/libstd/sys/windows/process.rs index e8cc160fde77b..e0f8d6f9df963 100644 --- a/src/libstd/sys/windows/process.rs +++ b/src/libstd/sys/windows/process.rs @@ -19,13 +19,14 @@ use ffi::{OsString, OsStr}; use fmt; use fs; use io::{self, Error}; -use libc::{self, c_void}; +use libc::c_void; use mem; use os::windows::ffi::OsStrExt; use path::Path; use ptr; use sync::StaticMutex; use sys::c; + use sys::fs::{OpenOptions, File}; use sys::handle::{Handle, RawHandle}; use sys::stdio; @@ -107,7 +108,7 @@ pub struct Process { pub enum Stdio { Inherit, None, - Raw(libc::HANDLE), + Raw(c::HANDLE), } pub type RawStdio = Handle; @@ -118,9 +119,6 @@ impl Process { out_handle: Stdio, err_handle: Stdio) -> io::Result { - use libc::{TRUE, STARTF_USESTDHANDLES}; - use libc::{DWORD, STARTUPINFO, CreateProcessW}; - // To have the spawning semantics of unix/windows stay the same, we need // to read the *child's* PATH if one is provided. See #15149 for more // details. @@ -143,8 +141,8 @@ impl Process { }); let mut si = zeroed_startupinfo(); - si.cb = mem::size_of::() as DWORD; - si.dwFlags = STARTF_USESTDHANDLES; + si.cb = mem::size_of::() as c::DWORD; + si.dwFlags = c::STARTF_USESTDHANDLES; let stdin = try!(in_handle.to_handle(c::STD_INPUT_HANDLE)); let stdout = try!(out_handle.to_handle(c::STD_OUTPUT_HANDLE)); @@ -159,9 +157,9 @@ impl Process { cmd_str.push(0); // add null terminator // stolen from the libuv code. - let mut flags = libc::CREATE_UNICODE_ENVIRONMENT; + let mut flags = c::CREATE_UNICODE_ENVIRONMENT; if cfg.detach { - flags |= libc::DETACHED_PROCESS | libc::CREATE_NEW_PROCESS_GROUP; + flags |= c::DETACHED_PROCESS | c::CREATE_NEW_PROCESS_GROUP; } let (envp, _data) = make_envp(cfg.env.as_ref()); @@ -173,12 +171,12 @@ impl Process { static CREATE_PROCESS_LOCK: StaticMutex = StaticMutex::new(); let _lock = CREATE_PROCESS_LOCK.lock(); - cvt(CreateProcessW(ptr::null(), - cmd_str.as_mut_ptr(), - ptr::null_mut(), - ptr::null_mut(), - TRUE, flags, envp, dirp, - &mut si, &mut pi)) + cvt(c::CreateProcessW(ptr::null(), + cmd_str.as_mut_ptr(), + ptr::null_mut(), + ptr::null_mut(), + c::TRUE, flags, envp, dirp, + &mut si, &mut pi)) }); // We close the thread handle because we don't care about keeping @@ -190,7 +188,7 @@ impl Process { } pub unsafe fn kill(&self) -> io::Result<()> { - try!(cvt(libc::TerminateProcess(self.handle.raw(), 1))); + try!(cvt(c::TerminateProcess(self.handle.raw(), 1))); Ok(()) } @@ -201,15 +199,13 @@ impl Process { } pub fn wait(&self) -> io::Result { - use libc::{INFINITE, WAIT_OBJECT_0}; - use libc::{GetExitCodeProcess, WaitForSingleObject}; - unsafe { - if WaitForSingleObject(self.handle.raw(), INFINITE) != WAIT_OBJECT_0 { + let res = c::WaitForSingleObject(self.handle.raw(), c::INFINITE); + if res != c::WAIT_OBJECT_0 { return Err(Error::last_os_error()) } let mut status = 0; - try!(cvt(GetExitCodeProcess(self.handle.raw(), &mut status))); + try!(cvt(c::GetExitCodeProcess(self.handle.raw(), &mut status))); Ok(ExitStatus(status)) } } @@ -220,7 +216,7 @@ impl Process { } #[derive(PartialEq, Eq, Clone, Copy, Debug)] -pub struct ExitStatus(libc::DWORD); +pub struct ExitStatus(c::DWORD); impl ExitStatus { pub fn success(&self) -> bool { @@ -237,8 +233,8 @@ impl fmt::Display for ExitStatus { } } -fn zeroed_startupinfo() -> libc::types::os::arch::extra::STARTUPINFO { - libc::types::os::arch::extra::STARTUPINFO { +fn zeroed_startupinfo() -> c::STARTUPINFO { + c::STARTUPINFO { cb: 0, lpReserved: ptr::null_mut(), lpDesktop: ptr::null_mut(), @@ -254,14 +250,14 @@ fn zeroed_startupinfo() -> libc::types::os::arch::extra::STARTUPINFO { wShowWindow: 0, cbReserved2: 0, lpReserved2: ptr::null_mut(), - hStdInput: libc::INVALID_HANDLE_VALUE, - hStdOutput: libc::INVALID_HANDLE_VALUE, - hStdError: libc::INVALID_HANDLE_VALUE, + hStdInput: c::INVALID_HANDLE_VALUE, + hStdOutput: c::INVALID_HANDLE_VALUE, + hStdError: c::INVALID_HANDLE_VALUE, } } -fn zeroed_process_information() -> libc::types::os::arch::extra::PROCESS_INFORMATION { - libc::types::os::arch::extra::PROCESS_INFORMATION { +fn zeroed_process_information() -> c::PROCESS_INFORMATION { + c::PROCESS_INFORMATION { hProcess: ptr::null_mut(), hThread: ptr::null_mut(), dwProcessId: 0, @@ -353,17 +349,15 @@ fn make_dirp(d: Option<&OsString>) -> (*const u16, Vec) { } impl Stdio { - fn to_handle(&self, stdio_id: libc::DWORD) -> io::Result { - use libc::DUPLICATE_SAME_ACCESS; - + fn to_handle(&self, stdio_id: c::DWORD) -> io::Result { match *self { Stdio::Inherit => { stdio::get(stdio_id).and_then(|io| { - io.handle().duplicate(0, true, DUPLICATE_SAME_ACCESS) + io.handle().duplicate(0, true, c::DUPLICATE_SAME_ACCESS) }) } Stdio::Raw(handle) => { - RawHandle::new(handle).duplicate(0, true, DUPLICATE_SAME_ACCESS) + RawHandle::new(handle).duplicate(0, true, c::DUPLICATE_SAME_ACCESS) } // Similarly to unix, we don't actually leave holes for the @@ -371,9 +365,9 @@ impl Stdio { // equivalents. These equivalents are drawn from libuv's // windows process spawning. Stdio::None => { - let size = mem::size_of::(); - let mut sa = libc::SECURITY_ATTRIBUTES { - nLength: size as libc::DWORD, + let size = mem::size_of::(); + let mut sa = c::SECURITY_ATTRIBUTES { + nLength: size as c::DWORD, lpSecurityDescriptor: ptr::null_mut(), bInheritHandle: 1, }; diff --git a/src/libstd/sys/windows/stack_overflow.rs b/src/libstd/sys/windows/stack_overflow.rs index d1c2144ef0d78..01317bec0de88 100644 --- a/src/libstd/sys/windows/stack_overflow.rs +++ b/src/libstd/sys/windows/stack_overflow.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use libc::{self, LONG}; use sys_common::util::report_overflow; use sys::c; @@ -19,7 +18,7 @@ impl Handler { // This API isn't available on XP, so don't panic in that case and just // pray it works out ok. if c::SetThreadStackGuarantee(&mut 0x5000) == 0 { - if libc::GetLastError() as u32 != libc::ERROR_CALL_NOT_IMPLEMENTED as u32 { + if c::GetLastError() as u32 != c::ERROR_CALL_NOT_IMPLEMENTED as u32 { panic!("failed to reserve stack space for exception handling"); } } @@ -28,7 +27,7 @@ impl Handler { } extern "system" fn vectored_handler(ExceptionInfo: *mut c::EXCEPTION_POINTERS) - -> LONG { + -> c::LONG { unsafe { let rec = &(*(*ExceptionInfo).ExceptionRecord); let code = rec.ExceptionCode; diff --git a/src/libstd/sys/windows/stdio.rs b/src/libstd/sys/windows/stdio.rs index 356787d5bf01a..8f37dc02e87af 100644 --- a/src/libstd/sys/windows/stdio.rs +++ b/src/libstd/sys/windows/stdio.rs @@ -12,7 +12,6 @@ use prelude::v1::*; use io::prelude::*; use io::{self, Cursor}; -use libc; use ptr; use str; use sync::Mutex; @@ -34,9 +33,9 @@ pub struct Stdin { pub struct Stdout(Output); pub struct Stderr(Output); -pub fn get(handle: libc::DWORD) -> io::Result { +pub fn get(handle: c::DWORD) -> io::Result { let handle = unsafe { c::GetStdHandle(handle) }; - if handle == libc::INVALID_HANDLE_VALUE { + if handle == c::INVALID_HANDLE_VALUE { Err(io::Error::last_os_error()) } else if handle.is_null() { Err(io::Error::new(io::ErrorKind::Other, @@ -63,7 +62,7 @@ fn write(out: &Output, data: &[u8]) -> io::Result { let mut written = 0; try!(cvt(unsafe { c::WriteConsoleW(handle, - utf16.as_ptr() as libc::LPCVOID, + utf16.as_ptr() as c::LPCVOID, utf16.len() as u32, &mut written, ptr::null_mut()) @@ -97,7 +96,7 @@ impl Stdin { let mut num = 0; try!(cvt(unsafe { c::ReadConsoleW(handle, - utf16.as_mut_ptr() as libc::LPVOID, + utf16.as_mut_ptr() as c::LPVOID, utf16.len() as u32, &mut num, ptr::null_mut()) @@ -147,7 +146,7 @@ impl io::Write for Stderr { } impl NoClose { - fn new(handle: libc::HANDLE) -> NoClose { + fn new(handle: c::HANDLE) -> NoClose { NoClose(Some(Handle::new(handle))) } diff --git a/src/libstd/sys/windows/thread.rs b/src/libstd/sys/windows/thread.rs index cf1b3ebddb97b..a6e6cc94b7679 100644 --- a/src/libstd/sys/windows/thread.rs +++ b/src/libstd/sys/windows/thread.rs @@ -12,8 +12,8 @@ use prelude::v1::*; use alloc::boxed::FnBox; use io; -use libc::{self, c_void, DWORD}; use mem; +use libc::c_void; use ptr; use sys::c; use sys::handle::Handle; @@ -37,7 +37,7 @@ impl Thread { // Round up to the next 64 kB because that's what the NT kernel does, // might as well make it explicit. let stack_size = (stack + 0xfffe) & (!0xfffe); - let ret = c::CreateThread(ptr::null_mut(), stack_size as libc::size_t, + let ret = c::CreateThread(ptr::null_mut(), stack_size, thread_start, &*p as *const _ as *mut _, 0, ptr::null_mut()); @@ -48,7 +48,7 @@ impl Thread { Ok(Thread { handle: Handle::new(ret) }) }; - extern "system" fn thread_start(main: *mut libc::c_void) -> DWORD { + extern "system" fn thread_start(main: *mut c_void) -> c::DWORD { unsafe { start_thread(main); } 0 } @@ -62,8 +62,7 @@ impl Thread { } pub fn join(self) { - use libc::consts::os::extra::INFINITE; - unsafe { c::WaitForSingleObject(self.handle.raw(), INFINITE); } + unsafe { c::WaitForSingleObject(self.handle.raw(), c::INFINITE); } } pub fn yield_now() { diff --git a/src/libstd/sys/windows/thread_local.rs b/src/libstd/sys/windows/thread_local.rs index c544eec7fce85..db2ad1d89c4d8 100644 --- a/src/libstd/sys/windows/thread_local.rs +++ b/src/libstd/sys/windows/thread_local.rs @@ -10,13 +10,12 @@ use prelude::v1::*; -use libc::types::os::arch::extra::{DWORD, LPVOID, BOOL}; - use ptr; -use sys_common; +use sys::c; use sys_common::mutex::Mutex; +use sys_common; -pub type Key = DWORD; +pub type Key = c::DWORD; pub type Dtor = unsafe extern fn(*mut u8); // Turns out, like pretty much everything, Windows is pretty close the @@ -68,9 +67,8 @@ static mut DTORS: *mut Vec<(Key, Dtor)> = ptr::null_mut(); #[inline] pub unsafe fn create(dtor: Option) -> Key { - const TLS_OUT_OF_INDEXES: DWORD = 0xFFFFFFFF; - let key = TlsAlloc(); - assert!(key != TLS_OUT_OF_INDEXES); + let key = c::TlsAlloc(); + assert!(key != c::TLS_OUT_OF_INDEXES); match dtor { Some(f) => register_dtor(key, f), None => {} @@ -80,13 +78,13 @@ pub unsafe fn create(dtor: Option) -> Key { #[inline] pub unsafe fn set(key: Key, value: *mut u8) { - let r = TlsSetValue(key, value as LPVOID); + let r = c::TlsSetValue(key, value as c::LPVOID); debug_assert!(r != 0); } #[inline] pub unsafe fn get(key: Key) -> *mut u8 { - TlsGetValue(key) as *mut u8 + c::TlsGetValue(key) as *mut u8 } #[inline] @@ -107,18 +105,11 @@ pub unsafe fn destroy(key: Key) { // Note that source [2] above shows precedent for this sort // of strategy. } else { - let r = TlsFree(key); + let r = c::TlsFree(key); debug_assert!(r != 0); } } -extern "system" { - fn TlsAlloc() -> DWORD; - fn TlsFree(dwTlsIndex: DWORD) -> BOOL; - fn TlsGetValue(dwTlsIndex: DWORD) -> LPVOID; - fn TlsSetValue(dwTlsIndex: DWORD, lpTlsvalue: LPVOID) -> BOOL; -} - // ------------------------------------------------------------------------- // Dtor registration // @@ -243,17 +234,15 @@ unsafe fn unregister_dtor(key: Key) -> bool { #[link_section = ".CRT$XLB"] #[linkage = "external"] #[allow(warnings)] -pub static p_thread_callback: unsafe extern "system" fn(LPVOID, DWORD, - LPVOID) = +pub static p_thread_callback: unsafe extern "system" fn(c::LPVOID, c::DWORD, + c::LPVOID) = on_tls_callback; #[allow(warnings)] -unsafe extern "system" fn on_tls_callback(h: LPVOID, - dwReason: DWORD, - pv: LPVOID) { - const DLL_THREAD_DETACH: DWORD = 3; - const DLL_PROCESS_DETACH: DWORD = 0; - if dwReason == DLL_THREAD_DETACH || dwReason == DLL_PROCESS_DETACH { +unsafe extern "system" fn on_tls_callback(h: c::LPVOID, + dwReason: c::DWORD, + pv: c::LPVOID) { + if dwReason == c::DLL_THREAD_DETACH || dwReason == c::DLL_PROCESS_DETACH { run_dtors(); } @@ -286,9 +275,9 @@ unsafe fn run_dtors() { ret }; for &(key, dtor) in &dtors { - let ptr = TlsGetValue(key); + let ptr = c::TlsGetValue(key); if !ptr.is_null() { - TlsSetValue(key, ptr::null_mut()); + c::TlsSetValue(key, ptr::null_mut()); dtor(ptr as *mut _); any_run = true; } diff --git a/src/libstd/sys/windows/time.rs b/src/libstd/sys/windows/time.rs index f5a70ccc90743..4dc7997d22e85 100644 --- a/src/libstd/sys/windows/time.rs +++ b/src/libstd/sys/windows/time.rs @@ -7,32 +7,33 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -use libc; + use ops::Sub; -use time::Duration; use sync::Once; +use sys::c; +use time::Duration; const NANOS_PER_SEC: u64 = 1_000_000_000; pub struct SteadyTime { - t: libc::LARGE_INTEGER, + t: c::LARGE_INTEGER, } impl SteadyTime { pub fn now() -> SteadyTime { let mut t = SteadyTime { t: 0 }; - unsafe { libc::QueryPerformanceCounter(&mut t.t); } + unsafe { c::QueryPerformanceCounter(&mut t.t); } t } } -fn frequency() -> libc::LARGE_INTEGER { - static mut FREQUENCY: libc::LARGE_INTEGER = 0; +fn frequency() -> c::LARGE_INTEGER { + static mut FREQUENCY: c::LARGE_INTEGER = 0; static ONCE: Once = Once::new(); unsafe { ONCE.call_once(|| { - libc::QueryPerformanceFrequency(&mut FREQUENCY); + c::QueryPerformanceFrequency(&mut FREQUENCY); }); FREQUENCY } diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index 2b34db3f6eafb..f1fd8be472830 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -21,7 +21,6 @@ use std::{cmp, error, fmt}; use std::io::prelude::*; use std::io; use term::{self, WriterWrapper}; -use libc; /// maximum number of lines we will print for each error; arbitrary. const MAX_LINES: usize = 6; @@ -767,15 +766,19 @@ impl EmitterWriter { #[cfg(unix)] fn stderr_isatty() -> bool { + use libc; unsafe { libc::isatty(libc::STDERR_FILENO) != 0 } } #[cfg(windows)] fn stderr_isatty() -> bool { - const STD_ERROR_HANDLE: libc::DWORD = -12i32 as libc::DWORD; + type DWORD = u32; + type BOOL = i32; + type HANDLE = *mut u8; + const STD_ERROR_HANDLE: DWORD = -12i32 as DWORD; extern "system" { - fn GetStdHandle(which: libc::DWORD) -> libc::HANDLE; - fn GetConsoleMode(hConsoleHandle: libc::HANDLE, - lpMode: libc::LPDWORD) -> libc::BOOL; + fn GetStdHandle(which: DWORD) -> HANDLE; + fn GetConsoleMode(hConsoleHandle: HANDLE, + lpMode: *mut DWORD) -> BOOL; } unsafe { let handle = GetStdHandle(STD_ERROR_HANDLE); diff --git a/src/libterm/win.rs b/src/libterm/win.rs index 66ef5e8661797..28ddc56793832 100644 --- a/src/libterm/win.rs +++ b/src/libterm/win.rs @@ -30,12 +30,17 @@ pub struct WinConsole { background: color::Color, } +type WORD = u16; +type DWORD = u32; +type BOOL = i32; +type HANDLE = *mut u8; + #[allow(non_snake_case)] #[repr(C)] struct CONSOLE_SCREEN_BUFFER_INFO { dwSize: [libc::c_short; 2], dwCursorPosition: [libc::c_short; 2], - wAttributes: libc::WORD, + wAttributes: WORD, srWindow: [libc::c_short; 4], dwMaximumWindowSize: [libc::c_short; 2], } @@ -43,10 +48,10 @@ struct CONSOLE_SCREEN_BUFFER_INFO { #[allow(non_snake_case)] #[link(name = "kernel32")] extern "system" { - fn SetConsoleTextAttribute(handle: libc::HANDLE, attr: libc::WORD) -> libc::BOOL; - fn GetStdHandle(which: libc::DWORD) -> libc::HANDLE; - fn GetConsoleScreenBufferInfo(handle: libc::HANDLE, - info: *mut CONSOLE_SCREEN_BUFFER_INFO) -> libc::BOOL; + fn SetConsoleTextAttribute(handle: HANDLE, attr: WORD) -> BOOL; + fn GetStdHandle(which: DWORD) -> HANDLE; + fn GetConsoleScreenBufferInfo(handle: HANDLE, + info: *mut CONSOLE_SCREEN_BUFFER_INFO) -> BOOL; } fn color_to_bits(color: color::Color) -> u16 { @@ -90,7 +95,7 @@ fn bits_to_color(bits: u16) -> color::Color { impl WinConsole { fn apply(&mut self) { let _unused = self.buf.flush(); - let mut accum: libc::WORD = 0; + let mut accum: WORD = 0; accum |= color_to_bits(self.foreground); accum |= color_to_bits(self.background) << 4; @@ -104,7 +109,7 @@ impl WinConsole { // terminal! Admittedly, this is fragile, since stderr could be // redirected to a different console. This is good enough for // rustc though. See #13400. - let out = GetStdHandle(-11i32 as libc::DWORD); + let out = GetStdHandle(-11i32 as DWORD); SetConsoleTextAttribute(out, accum); } } @@ -116,7 +121,7 @@ impl WinConsole { let bg; unsafe { let mut buffer_info = ::std::mem::uninitialized(); - if GetConsoleScreenBufferInfo(GetStdHandle(-11i32 as libc::DWORD), + if GetConsoleScreenBufferInfo(GetStdHandle(-11i32 as DWORD), &mut buffer_info) != 0 { fg = bits_to_color(buffer_info.wAttributes); bg = bits_to_color(buffer_info.wAttributes >> 4); diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 12541dc010bcf..69b1d37bfc4ee 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -777,11 +777,14 @@ fn stdout_isatty() -> bool { } #[cfg(windows)] fn stdout_isatty() -> bool { - const STD_OUTPUT_HANDLE: libc::DWORD = -11i32 as libc::DWORD; + type DWORD = u32; + type BOOL = i32; + type HANDLE = *mut u8; + type LPDWORD = *mut u32; + const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD; extern "system" { - fn GetStdHandle(which: libc::DWORD) -> libc::HANDLE; - fn GetConsoleMode(hConsoleHandle: libc::HANDLE, - lpMode: libc::LPDWORD) -> libc::BOOL; + fn GetStdHandle(which: DWORD) -> HANDLE; + fn GetConsoleMode(hConsoleHandle: HANDLE, lpMode: LPDWORD) -> BOOL; } unsafe { let handle = GetStdHandle(STD_OUTPUT_HANDLE); @@ -882,10 +885,28 @@ fn get_concurrency() -> usize { }; #[cfg(windows)] + #[allow(bad_style)] fn num_cpus() -> usize { + #[repr(C)] + struct SYSTEM_INFO { + wProcessorArchitecture: u16, + wReserved: u16, + dwPageSize: u32, + lpMinimumApplicationAddress: *mut u8, + lpMaximumApplicationAddress: *mut u8, + dwActiveProcessorMask: *mut u8, + dwNumberOfProcessors: u32, + dwProcessorType: u32, + dwAllocationGranularity: u32, + wProcessorLevel: u16, + wProcessorRevision: u16, + } + extern "system" { + fn GetSystemInfo(info: *mut SYSTEM_INFO) -> i32; + } unsafe { let mut sysinfo = std::mem::zeroed(); - libc::GetSystemInfo(&mut sysinfo); + GetSystemInfo(&mut sysinfo); sysinfo.dwNumberOfProcessors as usize } } diff --git a/src/test/run-pass/issue-13259-windows-tcb-trash.rs b/src/test/run-pass/issue-13259-windows-tcb-trash.rs index 2e03a9a724420..cca27aebfa44f 100644 --- a/src/test/run-pass/issue-13259-windows-tcb-trash.rs +++ b/src/test/run-pass/issue-13259-windows-tcb-trash.rs @@ -14,8 +14,9 @@ extern crate libc; #[cfg(windows)] mod imp { - use libc::{c_void, LPVOID, DWORD}; - use libc::types::os::arch::extra::LPWSTR; + type LPVOID = *mut u8; + type DWORD = u32; + type LPWSTR = *mut u16; extern "system" { fn FormatMessageW(flags: DWORD, @@ -24,15 +25,15 @@ mod imp { langId: DWORD, buf: LPWSTR, nsize: DWORD, - args: *const c_void) + args: *const u8) -> DWORD; } pub fn test() { let mut buf: [u16; 50] = [0; 50]; let ret = unsafe { - FormatMessageW(0x1000, 0 as *mut c_void, 1, 0x400, - buf.as_mut_ptr(), buf.len() as u32, 0 as *const c_void) + FormatMessageW(0x1000, 0 as *mut _, 1, 0x400, + buf.as_mut_ptr(), buf.len() as u32, 0 as *const _) }; // On some 32-bit Windowses (Win7-8 at least) this will panic with segmented // stacks taking control of pvArbitrary diff --git a/src/test/run-pass/rfc-1014-2.rs b/src/test/run-pass/rfc-1014-2.rs index ad76daaace49b..7cdaf278a08f5 100644 --- a/src/test/run-pass/rfc-1014-2.rs +++ b/src/test/run-pass/rfc-1014-2.rs @@ -11,15 +11,19 @@ extern crate libc; +type DWORD = u32; +type HANDLE = *mut u8; +type BOOL = i32; + #[cfg(windows)] extern "system" { - fn SetStdHandle(nStdHandle: libc::DWORD, nHandle: libc::HANDLE) -> libc::BOOL; + fn SetStdHandle(nStdHandle: DWORD, nHandle: HANDLE) -> BOOL; } #[cfg(windows)] fn close_stdout() { - const STD_OUTPUT_HANDLE: libc::DWORD = -11i32 as libc::DWORD; - unsafe { SetStdHandle(STD_OUTPUT_HANDLE, 0 as libc::HANDLE); } + const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD; + unsafe { SetStdHandle(STD_OUTPUT_HANDLE, 0 as HANDLE); } } #[cfg(windows)] diff --git a/src/test/run-pass/rfc-1014.rs b/src/test/run-pass/rfc-1014.rs index 98cad4efab71a..df969070a2ad4 100644 --- a/src/test/run-pass/rfc-1014.rs +++ b/src/test/run-pass/rfc-1014.rs @@ -11,20 +11,24 @@ extern crate libc; +type DWORD = u32; +type HANDLE = *mut u8; + #[cfg(windows)] extern "system" { - pub fn GetStdHandle(which: libc::DWORD) -> libc::HANDLE; + fn GetStdHandle(which: DWORD) -> HANDLE; + fn CloseHandle(handle: HANDLE) -> i32; } #[cfg(windows)] fn close_stdout() { - const STD_OUTPUT_HANDLE: libc::DWORD = -11i32 as libc::DWORD; - unsafe { libc::CloseHandle(GetStdHandle(STD_OUTPUT_HANDLE)); } + const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD; + unsafe { CloseHandle(GetStdHandle(STD_OUTPUT_HANDLE)); } } #[cfg(not(windows))] fn close_stdout() { - unsafe { libc::close(libc::STDOUT_FILENO); } + unsafe { libc::close(1); } } fn main() { diff --git a/src/test/run-pass/wait-forked-but-failed-child.rs b/src/test/run-pass/wait-forked-but-failed-child.rs index 1d0004bafa356..795c3f46f7579 100644 --- a/src/test/run-pass/wait-forked-but-failed-child.rs +++ b/src/test/run-pass/wait-forked-but-failed-child.rs @@ -15,8 +15,6 @@ extern crate libc; use std::process::Command; -use libc::funcs::posix88::unistd; - // The output from "ps -A -o pid,ppid,args" should look like this: // PID PPID COMMAND // 1 0 /sbin/init @@ -34,7 +32,7 @@ use libc::funcs::posix88::unistd; #[cfg(unix)] fn find_zombies() { - let my_pid = unsafe { unistd::getpid() }; + let my_pid = unsafe { libc::getpid() }; // http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ps.html let ps_cmd_output = Command::new("ps").args(&["-A", "-o", "pid,ppid,args"]).output().unwrap();