From 6d110ef0cb7845fd6869201e6a2d80bd2803951d Mon Sep 17 00:00:00 2001 From: Dan Robertson Date: Thu, 15 Mar 2018 00:46:16 +0000 Subject: [PATCH] Use a sys module for OS specific information Update cbindgen to parse modules with a path attribute and revert the following commits: - 996fad709238e5c4e24395f1c4ff8c90dfb984e5. - cfe98ab3b2ef0d211e092c846a80b969fad82f92. --- cbindgen | 2 +- src/fcntl/src/lib.rs | 52 ++--------- src/fcntl/src/linux.rs | 8 ++ src/fcntl/src/redox.rs | 20 +++++ src/signal/src/lib.rs | 186 +++------------------------------------- src/signal/src/linux.rs | 48 +++++++++++ src/signal/src/redox.rs | 44 ++++++++++ 7 files changed, 137 insertions(+), 223 deletions(-) create mode 100644 src/fcntl/src/linux.rs create mode 100644 src/fcntl/src/redox.rs create mode 100644 src/signal/src/linux.rs create mode 100644 src/signal/src/redox.rs diff --git a/cbindgen b/cbindgen index d14295f3ca..95821b3bbe 160000 --- a/cbindgen +++ b/cbindgen @@ -1 +1 @@ -Subproject commit d14295f3ca588f1d1752ea0a579f0597dd2ce248 +Subproject commit 95821b3bbe857354e3fb1efa96ed5252ecc3ec3e diff --git a/src/fcntl/src/lib.rs b/src/fcntl/src/lib.rs index 0e5048277a..0c0fa43ce2 100644 --- a/src/fcntl/src/lib.rs +++ b/src/fcntl/src/lib.rs @@ -6,55 +6,15 @@ extern crate platform; use platform::types::*; +pub use sys::*; + #[cfg(target_os = "linux")] -pub const O_RDONLY: c_int = 0x0000; -#[cfg(target_os = "linux")] -pub const O_WRONLY: c_int = 0x0001; -#[cfg(target_os = "linux")] -pub const O_RDWR: c_int = 0x0002; -#[cfg(target_os = "linux")] -pub const O_CREAT: c_int = 0x0040; -#[cfg(target_os = "linux")] -pub const O_TRUNC: c_int = 0x0200; -#[cfg(target_os = "linux")] -pub const O_ACCMODE: c_int = O_RDONLY | O_WRONLY | O_RDWR; +#[path = "linux.rs"] +pub mod sys; #[cfg(target_os = "redox")] -pub const O_RDONLY: c_int = 0x0001_0000; -#[cfg(target_os = "redox")] -pub const O_WRONLY: c_int = 0x0002_0000; -#[cfg(target_os = "redox")] -pub const O_RDWR: c_int = 0x0003_0000; -#[cfg(target_os = "redox")] -pub const O_NONBLOCK: c_int = 0x0004_0000; -#[cfg(target_os = "redox")] -pub const O_APPEND: c_int = 0x0008_0000; -#[cfg(target_os = "redox")] -pub const O_SHLOCK: c_int = 0x0010_0000; -#[cfg(target_os = "redox")] -pub const O_EXLOCK: c_int = 0x0020_0000; -#[cfg(target_os = "redox")] -pub const O_ASYNC: c_int = 0x0040_0000; -#[cfg(target_os = "redox")] -pub const O_FSYNC: c_int = 0x0080_0000; -#[cfg(target_os = "redox")] -pub const O_CLOEXEC: c_int = 0x0100_0000; -#[cfg(target_os = "redox")] -pub const O_CREAT: c_int = 0x0200_0000; -#[cfg(target_os = "redox")] -pub const O_TRUNC: c_int = 0x0400_0000; -#[cfg(target_os = "redox")] -pub const O_EXCL: c_int = 0x0800_0000; -#[cfg(target_os = "redox")] -pub const O_DIRECTORY: c_int = 0x1000_0000; -#[cfg(target_os = "redox")] -pub const O_STAT: c_int = 0x2000_0000; -#[cfg(target_os = "redox")] -pub const O_SYMLINK: c_int = 0x4000_0000; -#[cfg(target_os = "redox")] -pub const O_NOFOLLOW: c_int = 0x8000_0000; -#[cfg(target_os = "redox")] -pub const O_ACCMODE: c_int = O_RDONLY | O_WRONLY | O_RDWR; +#[path = "redox.rs"] +pub mod sys; pub const F_DUPFD: c_int = 0; pub const F_GETFD: c_int = 1; diff --git a/src/fcntl/src/linux.rs b/src/fcntl/src/linux.rs new file mode 100644 index 0000000000..fd68ffcf14 --- /dev/null +++ b/src/fcntl/src/linux.rs @@ -0,0 +1,8 @@ +use platform::types::*; + +pub const O_RDONLY: c_int = 0x0000; +pub const O_WRONLY: c_int = 0x0001; +pub const O_RDWR: c_int = 0x0002; +pub const O_CREAT: c_int = 0x0040; +pub const O_TRUNC: c_int = 0x0200; +pub const O_ACCMODE: c_int = O_RDONLY | O_WRONLY | O_RDWR; diff --git a/src/fcntl/src/redox.rs b/src/fcntl/src/redox.rs new file mode 100644 index 0000000000..1ea3ca45de --- /dev/null +++ b/src/fcntl/src/redox.rs @@ -0,0 +1,20 @@ +use platform::types::*; + +pub const O_RDONLY: c_int = 0x0001_0000; +pub const O_WRONLY: c_int = 0x0002_0000; +pub const O_RDWR: c_int = 0x0003_0000; +pub const O_NONBLOCK: c_int = 0x0004_0000; +pub const O_APPEND: c_int = 0x0008_0000; +pub const O_SHLOCK: c_int = 0x0010_0000; +pub const O_EXLOCK: c_int = 0x0020_0000; +pub const O_ASYNC: c_int = 0x0040_0000; +pub const O_FSYNC: c_int = 0x0080_0000; +pub const O_CLOEXEC: c_int = 0x0100_0000; +pub const O_CREAT: c_int = 0x0200_0000; +pub const O_TRUNC: c_int = 0x0400_0000; +pub const O_EXCL: c_int = 0x0800_0000; +pub const O_DIRECTORY: c_int = 0x1000_0000; +pub const O_STAT: c_int = 0x2000_0000; +pub const O_SYMLINK: c_int = 0x4000_0000; +pub const O_NOFOLLOW: c_int = 0x8000_0000; +pub const O_ACCMODE: c_int = O_RDONLY | O_WRONLY | O_RDWR; diff --git a/src/signal/src/lib.rs b/src/signal/src/lib.rs index 9a4e781785..80ec786e33 100644 --- a/src/signal/src/lib.rs +++ b/src/signal/src/lib.rs @@ -4,184 +4,18 @@ extern crate platform; +#[cfg(target_os = "linux")] +#[path = "linux.rs"] +pub mod sys; + +#[cfg(target_os = "redox")] +#[path = "redox.rs"] +pub mod sys; + +pub use sys::*; + use platform::types::*; -#[cfg(target_os = "linux")] -#[repr(C)] -pub struct sigset_t { - pub bits: [u64; 16], -} - -#[cfg(target_os = "linux")] -pub const SIGHUP: usize = 1; -#[cfg(target_os = "linux")] -pub const SIGINT: usize = 2; -#[cfg(target_os = "linux")] -pub const SIGQUIT: usize = 3; -#[cfg(target_os = "linux")] -pub const SIGILL: usize = 4; -#[cfg(target_os = "linux")] -pub const SIGTRAP: usize = 5; -#[cfg(target_os = "linux")] -pub const SIGABRT: usize = 6; -#[cfg(target_os = "linux")] -pub const SIGIOT: usize = SIGABRT; -#[cfg(target_os = "linux")] -pub const SIGBUS: usize = 7; -#[cfg(target_os = "linux")] -pub const SIGFPE: usize = 8; -#[cfg(target_os = "linux")] -pub const SIGKILL: usize = 9; -#[cfg(target_os = "linux")] -pub const SIGUSR1: usize = 10; -#[cfg(target_os = "linux")] -pub const SIGSEGV: usize = 11; -#[cfg(target_os = "linux")] -pub const SIGUSR2: usize = 12; -#[cfg(target_os = "linux")] -pub const SIGPIPE: usize = 13; -#[cfg(target_os = "linux")] -pub const SIGALRM: usize = 14; -#[cfg(target_os = "linux")] -pub const SIGTERM: usize = 15; -#[cfg(target_os = "linux")] -pub const SIGSTKFLT: usize = 16; -#[cfg(target_os = "linux")] -pub const SIGCHLD: usize = 17; -#[cfg(target_os = "linux")] -pub const SIGCONT: usize = 18; -#[cfg(target_os = "linux")] -pub const SIGSTOP: usize = 19; -#[cfg(target_os = "linux")] -pub const SIGTSTP: usize = 20; -#[cfg(target_os = "linux")] -pub const SIGTTIN: usize = 21; -#[cfg(target_os = "linux")] -pub const SIGTTOU: usize = 22; -#[cfg(target_os = "linux")] -pub const SIGURG: usize = 23; -#[cfg(target_os = "linux")] -pub const SIGXCPU: usize = 24; -#[cfg(target_os = "linux")] -pub const SIGXFSZ: usize = 25; -#[cfg(target_os = "linux")] -pub const SIGVTALRM: usize = 26; -#[cfg(target_os = "linux")] -pub const SIGPROF: usize = 27; -#[cfg(target_os = "linux")] -pub const SIGWINCH: usize = 28; -#[cfg(target_os = "linux")] -pub const SIGIO: usize = 29; -#[cfg(target_os = "linux")] -pub const SIGPOLL: usize = 29; -#[cfg(target_os = "linux")] -pub const SIGPWR: usize = 30; -#[cfg(target_os = "linux")] -pub const SIGSYS: usize = 31; -#[cfg(target_os = "linux")] -pub const SIGUNUSED: usize = SIGSYS; - -#[cfg(target_os = "linux")] -pub const SA_NOCLDSTOP: usize = 1; -#[cfg(target_os = "linux")] -pub const SA_NOCLDWAIT: usize = 2; -#[cfg(target_os = "linux")] -pub const SA_SIGINFO: usize = 4; -#[cfg(target_os = "linux")] -pub const SA_ONSTACK: usize = 0x08000000; -#[cfg(target_os = "linux")] -pub const SA_RESTART: usize = 0x10000000; -#[cfg(target_os = "linux")] -pub const SA_NODEFER: usize = 0x40000000; -#[cfg(target_os = "linux")] -pub const SA_RESETHAND: usize = 0x80000000; -#[cfg(target_os = "linux")] -pub const SA_RESTORER: usize = 0x04000000; - -#[cfg(target_os = "redox")] -#[repr(C)] -pub struct sigset_t { - pub bits: [u64; 2], -} - -#[cfg(target_os = "redox")] -pub const SIGHUP: usize = 1; -#[cfg(target_os = "redox")] -pub const SIGINT: usize = 2; -#[cfg(target_os = "redox")] -pub const SIGQUIT: usize = 3; -#[cfg(target_os = "redox")] -pub const SIGILL: usize = 4; -#[cfg(target_os = "redox")] -pub const SIGTRAP: usize = 5; -#[cfg(target_os = "redox")] -pub const SIGBUS: usize = 7; -#[cfg(target_os = "redox")] -pub const SIGFPE: usize = 8; -#[cfg(target_os = "redox")] -pub const SIGKILL: usize = 9; -#[cfg(target_os = "redox")] -pub const SIGUSR1: usize = 10; -#[cfg(target_os = "redox")] -pub const SIGSEGV: usize = 11; -#[cfg(target_os = "redox")] -pub const SIGUSR2: usize = 12; -#[cfg(target_os = "redox")] -pub const SIGPIPE: usize = 13; -#[cfg(target_os = "redox")] -pub const SIGALRM: usize = 14; -#[cfg(target_os = "redox")] -pub const SIGTERM: usize = 15; -#[cfg(target_os = "redox")] -pub const SIGSTKFLT: usize = 16; -#[cfg(target_os = "redox")] -pub const SIGCHLD: usize = 17; -#[cfg(target_os = "redox")] -pub const SIGCONT: usize = 18; -#[cfg(target_os = "redox")] -pub const SIGSTOP: usize = 19; -#[cfg(target_os = "redox")] -pub const SIGTSTP: usize = 20; -#[cfg(target_os = "redox")] -pub const SIGTTIN: usize = 21; -#[cfg(target_os = "redox")] -pub const SIGTTOU: usize = 22; -#[cfg(target_os = "redox")] -pub const SIGURG: usize = 23; -#[cfg(target_os = "redox")] -pub const SIGXCPU: usize = 24; -#[cfg(target_os = "redox")] -pub const SIGXFSZ: usize = 25; -#[cfg(target_os = "redox")] -pub const SIGVTALRM: usize = 26; -#[cfg(target_os = "redox")] -pub const SIGPROF: usize = 27; -#[cfg(target_os = "redox")] -pub const SIGWINCH: usize = 28; -#[cfg(target_os = "redox")] -pub const SIGIO: usize = 29; -#[cfg(target_os = "redox")] -pub const SIGPWR: usize = 30; -#[cfg(target_os = "redox")] -pub const SIGSYS: usize = 31; - -#[cfg(target_os = "redox")] -pub const SA_NOCLDSTOP: usize = 0x00000001; -#[cfg(target_os = "redox")] -pub const SA_NOCLDWAIT: usize = 0x00000002; -#[cfg(target_os = "redox")] -pub const SA_SIGINFO: usize = 0x00000004; -#[cfg(target_os = "redox")] -pub const SA_RESTORER: usize = 0x04000000; -#[cfg(target_os = "redox")] -pub const SA_ONSTACK: usize = 0x08000000; -#[cfg(target_os = "redox")] -pub const SA_RESTART: usize = 0x10000000; -#[cfg(target_os = "redox")] -pub const SA_NODEFER: usize = 0x40000000; -#[cfg(target_os = "redox")] -pub const SA_RESETHAND: usize = 0x80000000; - #[repr(C)] pub struct sigaction { pub sa_handler: extern "C" fn(usize), diff --git a/src/signal/src/linux.rs b/src/signal/src/linux.rs new file mode 100644 index 0000000000..63eff1c144 --- /dev/null +++ b/src/signal/src/linux.rs @@ -0,0 +1,48 @@ +#[repr(C)] +pub struct sigset_t { + pub bits: [u64; 16], +} + +pub const SIGHUP: usize = 1; +pub const SIGINT: usize = 2; +pub const SIGQUIT: usize = 3; +pub const SIGILL: usize = 4; +pub const SIGTRAP: usize = 5; +pub const SIGABRT: usize = 6; +pub const SIGIOT: usize = SIGABRT; +pub const SIGBUS: usize = 7; +pub const SIGFPE: usize = 8; +pub const SIGKILL: usize = 9; +pub const SIGUSR1: usize = 10; +pub const SIGSEGV: usize = 11; +pub const SIGUSR2: usize = 12; +pub const SIGPIPE: usize = 13; +pub const SIGALRM: usize = 14; +pub const SIGTERM: usize = 15; +pub const SIGSTKFLT: usize = 16; +pub const SIGCHLD: usize = 17; +pub const SIGCONT: usize = 18; +pub const SIGSTOP: usize = 19; +pub const SIGTSTP: usize = 20; +pub const SIGTTIN: usize = 21; +pub const SIGTTOU: usize = 22; +pub const SIGURG: usize = 23; +pub const SIGXCPU: usize = 24; +pub const SIGXFSZ: usize = 25; +pub const SIGVTALRM: usize = 26; +pub const SIGPROF: usize = 27; +pub const SIGWINCH: usize = 28; +pub const SIGIO: usize = 29; +pub const SIGPOLL: usize = 29; +pub const SIGPWR: usize = 30; +pub const SIGSYS: usize = 31; +pub const SIGUNUSED: usize = SIGSYS; + +pub const SA_NOCLDSTOP: usize = 1; +pub const SA_NOCLDWAIT: usize = 2; +pub const SA_SIGINFO: usize = 4; +pub const SA_ONSTACK: usize = 0x08000000; +pub const SA_RESTART: usize = 0x10000000; +pub const SA_NODEFER: usize = 0x40000000; +pub const SA_RESETHAND: usize = 0x80000000; +pub const SA_RESTORER: usize = 0x04000000; diff --git a/src/signal/src/redox.rs b/src/signal/src/redox.rs new file mode 100644 index 0000000000..54cb42adc5 --- /dev/null +++ b/src/signal/src/redox.rs @@ -0,0 +1,44 @@ +#[repr(C)] +pub struct sigset_t { + pub bits: [u64; 2], +} + +pub const SIGHUP: usize = 1; +pub const SIGINT: usize = 2; +pub const SIGQUIT: usize = 3; +pub const SIGILL: usize = 4; +pub const SIGTRAP: usize = 5; +pub const SIGBUS: usize = 7; +pub const SIGFPE: usize = 8; +pub const SIGKILL: usize = 9; +pub const SIGUSR1: usize = 10; +pub const SIGSEGV: usize = 11; +pub const SIGUSR2: usize = 12; +pub const SIGPIPE: usize = 13; +pub const SIGALRM: usize = 14; +pub const SIGTERM: usize = 15; +pub const SIGSTKFLT: usize = 16; +pub const SIGCHLD: usize = 17; +pub const SIGCONT: usize = 18; +pub const SIGSTOP: usize = 19; +pub const SIGTSTP: usize = 20; +pub const SIGTTIN: usize = 21; +pub const SIGTTOU: usize = 22; +pub const SIGURG: usize = 23; +pub const SIGXCPU: usize = 24; +pub const SIGXFSZ: usize = 25; +pub const SIGVTALRM: usize = 26; +pub const SIGPROF: usize = 27; +pub const SIGWINCH: usize = 28; +pub const SIGIO: usize = 29; +pub const SIGPWR: usize = 30; +pub const SIGSYS: usize = 31; + +pub const SA_NOCLDSTOP: usize = 0x00000001; +pub const SA_NOCLDWAIT: usize = 0x00000002; +pub const SA_SIGINFO: usize = 0x00000004; +pub const SA_RESTORER: usize = 0x04000000; +pub const SA_ONSTACK: usize = 0x08000000; +pub const SA_RESTART: usize = 0x10000000; +pub const SA_NODEFER: usize = 0x40000000; +pub const SA_RESETHAND: usize = 0x80000000;