2014-04-18 20:23:56 +00:00
|
|
|
// Copyright 2014 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 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
//! C definitions used by libnative that don't belong in liblibc
|
|
|
|
|
2014-05-05 23:58:42 +00:00
|
|
|
#![allow(dead_code)]
|
2014-10-01 00:03:56 +00:00
|
|
|
#![allow(non_camel_case_types)]
|
2014-05-05 23:58:42 +00:00
|
|
|
|
2014-04-18 20:23:56 +00:00
|
|
|
pub use self::select::fd_set;
|
2014-05-05 23:58:42 +00:00
|
|
|
pub use self::signal::{sigaction, siginfo, sigset_t};
|
|
|
|
pub use self::signal::{SA_ONSTACK, SA_RESTART, SA_RESETHAND, SA_NOCLDSTOP};
|
|
|
|
pub use self::signal::{SA_NODEFER, SA_NOCLDWAIT, SA_SIGINFO, SIGCHLD};
|
2014-04-18 20:23:56 +00:00
|
|
|
|
|
|
|
use libc;
|
|
|
|
|
2014-09-29 07:28:50 +00:00
|
|
|
#[cfg(any(target_os = "macos",
|
|
|
|
target_os = "ios",
|
|
|
|
target_os = "freebsd",
|
|
|
|
target_os = "dragonfly"))]
|
2014-10-06 23:33:29 +00:00
|
|
|
pub const FIONBIO: libc::c_ulong = 0x8004667e;
|
2014-09-29 07:28:50 +00:00
|
|
|
#[cfg(any(all(target_os = "linux",
|
|
|
|
any(target_arch = "x86",
|
|
|
|
target_arch = "x86_64",
|
|
|
|
target_arch = "arm")),
|
|
|
|
target_os = "android"))]
|
2014-10-06 23:33:29 +00:00
|
|
|
pub const FIONBIO: libc::c_ulong = 0x5421;
|
2014-09-29 07:28:50 +00:00
|
|
|
#[cfg(all(target_os = "linux",
|
|
|
|
any(target_arch = "mips", target_arch = "mipsel")))]
|
2014-10-06 23:33:29 +00:00
|
|
|
pub const FIONBIO: libc::c_ulong = 0x667e;
|
2014-05-27 09:00:50 +00:00
|
|
|
|
2014-09-29 07:28:50 +00:00
|
|
|
#[cfg(any(target_os = "macos",
|
|
|
|
target_os = "ios",
|
|
|
|
target_os = "freebsd",
|
|
|
|
target_os = "dragonfly"))]
|
2014-10-06 23:33:29 +00:00
|
|
|
pub const FIOCLEX: libc::c_ulong = 0x20006601;
|
2014-09-29 07:28:50 +00:00
|
|
|
#[cfg(any(all(target_os = "linux",
|
|
|
|
any(target_arch = "x86",
|
|
|
|
target_arch = "x86_64",
|
|
|
|
target_arch = "arm")),
|
|
|
|
target_os = "android"))]
|
2014-10-06 23:33:29 +00:00
|
|
|
pub const FIOCLEX: libc::c_ulong = 0x5451;
|
2014-09-29 07:28:50 +00:00
|
|
|
#[cfg(all(target_os = "linux",
|
|
|
|
any(target_arch = "mips", target_arch = "mipsel")))]
|
2014-10-06 23:33:29 +00:00
|
|
|
pub const FIOCLEX: libc::c_ulong = 0x6601;
|
2014-04-18 20:23:56 +00:00
|
|
|
|
2014-09-29 07:28:50 +00:00
|
|
|
#[cfg(any(target_os = "macos",
|
|
|
|
target_os = "ios",
|
|
|
|
target_os = "freebsd",
|
|
|
|
target_os = "dragonfly"))]
|
2014-10-06 23:33:29 +00:00
|
|
|
pub const MSG_DONTWAIT: libc::c_int = 0x80;
|
2014-09-29 07:28:50 +00:00
|
|
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
2014-10-06 23:33:29 +00:00
|
|
|
pub const MSG_DONTWAIT: libc::c_int = 0x40;
|
2014-04-26 03:50:22 +00:00
|
|
|
|
2014-10-06 23:33:29 +00:00
|
|
|
pub const WNOHANG: libc::c_int = 1;
|
2014-05-05 23:58:42 +00:00
|
|
|
|
2014-04-18 20:23:56 +00:00
|
|
|
extern {
|
|
|
|
pub fn gettimeofday(timeval: *mut libc::timeval,
|
2014-06-25 19:47:34 +00:00
|
|
|
tzp: *mut libc::c_void) -> libc::c_int;
|
2014-04-18 20:23:56 +00:00
|
|
|
pub fn select(nfds: libc::c_int,
|
2014-06-25 19:47:34 +00:00
|
|
|
readfds: *mut fd_set,
|
|
|
|
writefds: *mut fd_set,
|
|
|
|
errorfds: *mut fd_set,
|
|
|
|
timeout: *mut libc::timeval) -> libc::c_int;
|
2014-04-18 20:23:56 +00:00
|
|
|
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;
|
|
|
|
pub fn ioctl(fd: libc::c_int, req: libc::c_ulong, ...) -> libc::c_int;
|
|
|
|
|
2014-05-05 23:58:42 +00:00
|
|
|
|
|
|
|
pub fn waitpid(pid: libc::pid_t, status: *mut libc::c_int,
|
|
|
|
options: libc::c_int) -> libc::pid_t;
|
|
|
|
|
|
|
|
pub fn sigaction(signum: libc::c_int,
|
2014-06-25 19:47:34 +00:00
|
|
|
act: *const sigaction,
|
2014-05-05 23:58:42 +00:00
|
|
|
oldact: *mut sigaction) -> libc::c_int;
|
|
|
|
|
|
|
|
pub fn sigaddset(set: *mut sigset_t, signum: libc::c_int) -> libc::c_int;
|
|
|
|
pub fn sigdelset(set: *mut sigset_t, signum: libc::c_int) -> libc::c_int;
|
|
|
|
pub fn sigemptyset(set: *mut sigset_t) -> libc::c_int;
|
2014-04-18 20:23:56 +00:00
|
|
|
}
|
|
|
|
|
2014-09-29 07:28:50 +00:00
|
|
|
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
2014-04-18 20:23:56 +00:00
|
|
|
mod select {
|
2014-10-06 23:33:29 +00:00
|
|
|
pub const FD_SETSIZE: uint = 1024;
|
2014-04-18 20:23:56 +00:00
|
|
|
|
2014-05-28 01:37:49 +00:00
|
|
|
#[repr(C)]
|
2014-04-18 20:23:56 +00:00
|
|
|
pub struct fd_set {
|
|
|
|
fds_bits: [i32, ..(FD_SETSIZE / 32)]
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn fd_set(set: &mut fd_set, fd: i32) {
|
2014-04-21 21:58:52 +00:00
|
|
|
set.fds_bits[(fd / 32) as uint] |= 1 << ((fd % 32) as uint);
|
2014-04-18 20:23:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 07:28:50 +00:00
|
|
|
#[cfg(any(target_os = "android",
|
|
|
|
target_os = "freebsd",
|
|
|
|
target_os = "dragonfly",
|
|
|
|
target_os = "linux"))]
|
2014-04-18 20:23:56 +00:00
|
|
|
mod select {
|
2014-10-01 00:03:56 +00:00
|
|
|
use uint;
|
2014-08-14 19:49:26 +00:00
|
|
|
use libc;
|
2014-04-18 20:23:56 +00:00
|
|
|
|
2014-10-06 23:33:29 +00:00
|
|
|
pub const FD_SETSIZE: uint = 1024;
|
2014-04-18 20:23:56 +00:00
|
|
|
|
2014-05-28 01:37:49 +00:00
|
|
|
#[repr(C)]
|
2014-04-18 20:23:56 +00:00
|
|
|
pub struct fd_set {
|
2014-07-29 14:44:39 +00:00
|
|
|
// FIXME: shouldn't this be a c_ulong?
|
2014-08-14 19:49:26 +00:00
|
|
|
fds_bits: [libc::uintptr_t, ..(FD_SETSIZE / uint::BITS)]
|
2014-04-18 20:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn fd_set(set: &mut fd_set, fd: i32) {
|
|
|
|
let fd = fd as uint;
|
|
|
|
set.fds_bits[fd / uint::BITS] |= 1 << (fd % uint::BITS);
|
|
|
|
}
|
|
|
|
}
|
2014-05-05 23:58:42 +00:00
|
|
|
|
2014-09-29 07:28:50 +00:00
|
|
|
#[cfg(any(all(target_os = "linux",
|
|
|
|
any(target_arch = "x86",
|
|
|
|
target_arch = "x86_64",
|
|
|
|
target_arch = "arm")),
|
|
|
|
target_os = "android"))]
|
2014-05-05 23:58:42 +00:00
|
|
|
mod signal {
|
|
|
|
use libc;
|
|
|
|
|
2014-10-06 23:33:29 +00:00
|
|
|
pub const SA_NOCLDSTOP: libc::c_ulong = 0x00000001;
|
|
|
|
pub const SA_NOCLDWAIT: libc::c_ulong = 0x00000002;
|
|
|
|
pub const SA_NODEFER: libc::c_ulong = 0x40000000;
|
|
|
|
pub const SA_ONSTACK: libc::c_ulong = 0x08000000;
|
|
|
|
pub const SA_RESETHAND: libc::c_ulong = 0x80000000;
|
|
|
|
pub const SA_RESTART: libc::c_ulong = 0x10000000;
|
|
|
|
pub const SA_SIGINFO: libc::c_ulong = 0x00000004;
|
|
|
|
pub const SIGCHLD: libc::c_int = 17;
|
2014-05-05 23:58:42 +00:00
|
|
|
|
|
|
|
// This definition is not as accurate as it could be, {pid, uid, status} is
|
|
|
|
// actually a giant union. Currently we're only interested in these fields,
|
|
|
|
// however.
|
2014-05-28 01:37:49 +00:00
|
|
|
#[repr(C)]
|
2014-05-05 23:58:42 +00:00
|
|
|
pub struct siginfo {
|
|
|
|
si_signo: libc::c_int,
|
|
|
|
si_errno: libc::c_int,
|
|
|
|
si_code: libc::c_int,
|
|
|
|
pub pid: libc::pid_t,
|
|
|
|
pub uid: libc::uid_t,
|
|
|
|
pub status: libc::c_int,
|
|
|
|
}
|
|
|
|
|
2014-05-28 01:37:49 +00:00
|
|
|
#[repr(C)]
|
2014-05-05 23:58:42 +00:00
|
|
|
pub struct sigaction {
|
|
|
|
pub sa_handler: extern fn(libc::c_int),
|
|
|
|
pub sa_mask: sigset_t,
|
|
|
|
pub sa_flags: libc::c_ulong,
|
|
|
|
sa_restorer: *mut libc::c_void,
|
|
|
|
}
|
|
|
|
|
2014-12-21 23:49:42 +00:00
|
|
|
unsafe impl ::kinds::Send for sigaction { }
|
|
|
|
unsafe impl ::kinds::Sync for sigaction { }
|
2014-12-06 16:39:25 +00:00
|
|
|
|
2014-05-28 01:37:49 +00:00
|
|
|
#[repr(C)]
|
2014-05-05 23:58:42 +00:00
|
|
|
#[cfg(target_word_size = "32")]
|
|
|
|
pub struct sigset_t {
|
|
|
|
__val: [libc::c_ulong, ..32],
|
|
|
|
}
|
2014-05-28 01:37:49 +00:00
|
|
|
|
|
|
|
#[repr(C)]
|
2014-05-05 23:58:42 +00:00
|
|
|
#[cfg(target_word_size = "64")]
|
|
|
|
pub struct sigset_t {
|
|
|
|
__val: [libc::c_ulong, ..16],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 07:28:50 +00:00
|
|
|
#[cfg(all(target_os = "linux",
|
|
|
|
any(target_arch = "mips", target_arch = "mipsel")))]
|
2014-05-27 09:00:50 +00:00
|
|
|
mod signal {
|
|
|
|
use libc;
|
|
|
|
|
2014-10-06 23:33:29 +00:00
|
|
|
pub const SA_NOCLDSTOP: libc::c_ulong = 0x00000001;
|
|
|
|
pub const SA_NOCLDWAIT: libc::c_ulong = 0x00010000;
|
|
|
|
pub const SA_NODEFER: libc::c_ulong = 0x40000000;
|
|
|
|
pub const SA_ONSTACK: libc::c_ulong = 0x08000000;
|
|
|
|
pub const SA_RESETHAND: libc::c_ulong = 0x80000000;
|
|
|
|
pub const SA_RESTART: libc::c_ulong = 0x10000000;
|
|
|
|
pub const SA_SIGINFO: libc::c_ulong = 0x00000008;
|
|
|
|
pub const SIGCHLD: libc::c_int = 18;
|
2014-05-27 09:00:50 +00:00
|
|
|
|
|
|
|
// This definition is not as accurate as it could be, {pid, uid, status} is
|
|
|
|
// actually a giant union. Currently we're only interested in these fields,
|
|
|
|
// however.
|
2014-05-28 01:37:49 +00:00
|
|
|
#[repr(C)]
|
2014-05-27 09:00:50 +00:00
|
|
|
pub struct siginfo {
|
|
|
|
si_signo: libc::c_int,
|
|
|
|
si_code: libc::c_int,
|
|
|
|
si_errno: libc::c_int,
|
|
|
|
pub pid: libc::pid_t,
|
|
|
|
pub uid: libc::uid_t,
|
|
|
|
pub status: libc::c_int,
|
|
|
|
}
|
|
|
|
|
2014-05-28 01:37:49 +00:00
|
|
|
#[repr(C)]
|
2014-05-27 09:00:50 +00:00
|
|
|
pub struct sigaction {
|
|
|
|
pub sa_flags: libc::c_uint,
|
|
|
|
pub sa_handler: extern fn(libc::c_int),
|
|
|
|
pub sa_mask: sigset_t,
|
|
|
|
sa_restorer: *mut libc::c_void,
|
|
|
|
sa_resv: [libc::c_int, ..1],
|
|
|
|
}
|
|
|
|
|
2014-12-30 03:16:53 +00:00
|
|
|
unsafe impl ::kinds::Send for sigaction { }
|
|
|
|
unsafe impl ::kinds::Sync for sigaction { }
|
2014-12-06 16:39:25 +00:00
|
|
|
|
2014-05-28 01:37:49 +00:00
|
|
|
#[repr(C)]
|
2014-05-27 09:00:50 +00:00
|
|
|
pub struct sigset_t {
|
|
|
|
__val: [libc::c_ulong, ..32],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 07:28:50 +00:00
|
|
|
#[cfg(any(target_os = "macos",
|
|
|
|
target_os = "ios",
|
|
|
|
target_os = "freebsd",
|
|
|
|
target_os = "dragonfly"))]
|
2014-05-05 23:58:42 +00:00
|
|
|
mod signal {
|
|
|
|
use libc;
|
|
|
|
|
2014-10-06 23:33:29 +00:00
|
|
|
pub const SA_ONSTACK: libc::c_int = 0x0001;
|
|
|
|
pub const SA_RESTART: libc::c_int = 0x0002;
|
|
|
|
pub const SA_RESETHAND: libc::c_int = 0x0004;
|
|
|
|
pub const SA_NOCLDSTOP: libc::c_int = 0x0008;
|
|
|
|
pub const SA_NODEFER: libc::c_int = 0x0010;
|
|
|
|
pub const SA_NOCLDWAIT: libc::c_int = 0x0020;
|
|
|
|
pub const SA_SIGINFO: libc::c_int = 0x0040;
|
|
|
|
pub const SIGCHLD: libc::c_int = 20;
|
2014-05-05 23:58:42 +00:00
|
|
|
|
2014-10-05 16:30:04 +00:00
|
|
|
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
2014-05-05 23:58:42 +00:00
|
|
|
pub type sigset_t = u32;
|
2014-10-05 16:30:04 +00:00
|
|
|
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
|
2014-08-14 19:18:14 +00:00
|
|
|
#[repr(C)]
|
2014-05-05 23:58:42 +00:00
|
|
|
pub struct sigset_t {
|
|
|
|
bits: [u32, ..4],
|
|
|
|
}
|
|
|
|
|
|
|
|
// This structure has more fields, but we're not all that interested in
|
|
|
|
// them.
|
2014-05-28 01:37:49 +00:00
|
|
|
#[repr(C)]
|
2014-05-05 23:58:42 +00:00
|
|
|
pub struct siginfo {
|
|
|
|
pub si_signo: libc::c_int,
|
|
|
|
pub si_errno: libc::c_int,
|
|
|
|
pub si_code: libc::c_int,
|
|
|
|
pub pid: libc::pid_t,
|
|
|
|
pub uid: libc::uid_t,
|
|
|
|
pub status: libc::c_int,
|
|
|
|
}
|
|
|
|
|
2014-05-28 01:37:49 +00:00
|
|
|
#[repr(C)]
|
2014-05-05 23:58:42 +00:00
|
|
|
pub struct sigaction {
|
|
|
|
pub sa_handler: extern fn(libc::c_int),
|
|
|
|
pub sa_flags: libc::c_int,
|
|
|
|
pub sa_mask: sigset_t,
|
|
|
|
}
|
|
|
|
}
|