bitrig integration
This commit is contained in:
parent
e29f420255
commit
cd8f31759f
50 changed files with 1116 additions and 77 deletions
|
|
@ -689,7 +689,8 @@ impl TcpStream {
|
|||
setsockopt(self.fd(), libc::IPPROTO_TCP, libc::TCP_KEEPALIVE,
|
||||
seconds as libc::c_int)
|
||||
}
|
||||
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
|
||||
#[cfg(any(target_os = "freebsd",
|
||||
target_os = "dragonfly"))]
|
||||
fn set_tcp_keepalive(&mut self, seconds: uint) -> IoResult<()> {
|
||||
setsockopt(self.fd(), libc::IPPROTO_TCP, libc::TCP_KEEPIDLE,
|
||||
seconds as libc::c_int)
|
||||
|
|
|
|||
|
|
@ -189,11 +189,18 @@ pub unsafe fn record_sp_limit(limit: uint) {
|
|||
unsafe fn target_record_sp_limit(limit: uint) {
|
||||
asm!("movq $0, %fs:24" :: "r"(limit) :: "volatile")
|
||||
}
|
||||
#[cfg(all(target_arch = "x86_64", target_os = "dragonfly"))] #[inline(always)]
|
||||
#[cfg(all(target_arch = "x86_64", target_os = "dragonfly"))]
|
||||
#[inline(always)]
|
||||
unsafe fn target_record_sp_limit(limit: uint) {
|
||||
asm!("movq $0, %fs:32" :: "r"(limit) :: "volatile")
|
||||
}
|
||||
|
||||
#[cfg(target_os = "bitrig")]
|
||||
#[inline(always)]
|
||||
unsafe fn target_record_sp_limit(_: uint) {
|
||||
// segmented stacks are disabled
|
||||
}
|
||||
|
||||
// x86
|
||||
#[cfg(all(target_arch = "x86",
|
||||
any(target_os = "macos", target_os = "ios")))]
|
||||
|
|
@ -276,12 +283,18 @@ pub unsafe fn get_sp_limit() -> uint {
|
|||
asm!("movq %fs:24, $0" : "=r"(limit) ::: "volatile");
|
||||
return limit;
|
||||
}
|
||||
#[cfg(all(target_arch = "x86_64", target_os = "dragonfly"))] #[inline(always)]
|
||||
#[cfg(all(target_arch = "x86_64", target_os = "dragonfly"))]
|
||||
#[inline(always)]
|
||||
unsafe fn target_get_sp_limit() -> uint {
|
||||
let limit;
|
||||
asm!("movq %fs:32, $0" : "=r"(limit) ::: "volatile");
|
||||
return limit;
|
||||
}
|
||||
#[cfg(target_os = "bitrig")]
|
||||
#[inline(always)]
|
||||
unsafe fn target_get_sp_limit() -> uint {
|
||||
return 2048;
|
||||
}
|
||||
|
||||
|
||||
// x86
|
||||
|
|
|
|||
|
|
@ -319,6 +319,7 @@ fn print(w: &mut Writer, idx: int, addr: *mut libc::c_void) -> IoResult<()> {
|
|||
if !STATE.is_null() { return STATE }
|
||||
let selfname = if cfg!(target_os = "freebsd") ||
|
||||
cfg!(target_os = "dragonfly") ||
|
||||
cfg!(target_os = "bitrig") ||
|
||||
cfg!(target_os = "openbsd") {
|
||||
env::current_exe().ok()
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ use libc;
|
|||
target_os = "ios",
|
||||
target_os = "freebsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "bitrig",
|
||||
target_os = "openbsd"))]
|
||||
pub const FIONBIO: libc::c_ulong = 0x8004667e;
|
||||
#[cfg(any(all(target_os = "linux",
|
||||
|
|
@ -43,6 +44,7 @@ pub const FIONBIO: libc::c_ulong = 0x667e;
|
|||
target_os = "ios",
|
||||
target_os = "freebsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "bitrig",
|
||||
target_os = "openbsd"))]
|
||||
pub const FIOCLEX: libc::c_ulong = 0x20006601;
|
||||
#[cfg(any(all(target_os = "linux",
|
||||
|
|
@ -62,6 +64,7 @@ pub const FIOCLEX: libc::c_ulong = 0x6601;
|
|||
target_os = "ios",
|
||||
target_os = "freebsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "bitrig",
|
||||
target_os = "openbsd"))]
|
||||
pub const MSG_DONTWAIT: libc::c_int = 0x80;
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
|
|
@ -75,7 +78,8 @@ pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 70;
|
|||
target_os = "freebsd",
|
||||
target_os = "dragonfly"))]
|
||||
pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 71;
|
||||
#[cfg(target_os = "openbsd")]
|
||||
#[cfg(any(target_os = "bitrig",
|
||||
target_os = "openbsd"))]
|
||||
pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 101;
|
||||
#[cfg(target_os = "android")]
|
||||
pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 0x0048;
|
||||
|
|
@ -96,6 +100,7 @@ pub struct passwd {
|
|||
#[cfg(any(target_os = "macos",
|
||||
target_os = "freebsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "bitrig",
|
||||
target_os = "openbsd"))]
|
||||
pub struct passwd {
|
||||
pub pw_name: *mut libc::c_char,
|
||||
|
|
@ -176,6 +181,7 @@ mod select {
|
|||
#[cfg(any(target_os = "android",
|
||||
target_os = "freebsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "bitrig",
|
||||
target_os = "openbsd",
|
||||
target_os = "linux"))]
|
||||
mod select {
|
||||
|
|
@ -344,3 +350,41 @@ mod signal {
|
|||
pub sa_mask: sigset_t,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "bitrig")]
|
||||
mod signal {
|
||||
use libc;
|
||||
|
||||
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;
|
||||
|
||||
pub type sigset_t = libc::c_uint;
|
||||
|
||||
// This structure has more fields, but we're not all that interested in
|
||||
// them.
|
||||
#[repr(C)]
|
||||
pub struct siginfo {
|
||||
pub si_signo: libc::c_int,
|
||||
pub si_code: libc::c_int,
|
||||
pub si_errno: libc::c_int,
|
||||
// FIXME: Bitrig has a crazy union here in the siginfo, I think this
|
||||
// layout will still work tho. The status might be off by the size of
|
||||
// a clock_t by my reading, but we can fix this later.
|
||||
pub pid: libc::pid_t,
|
||||
pub uid: libc::uid_t,
|
||||
pub status: libc::c_int,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct sigaction {
|
||||
pub sa_handler: extern fn(libc::c_int),
|
||||
pub sa_mask: sigset_t,
|
||||
pub sa_flags: libc::c_int,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -291,6 +291,33 @@ fn mkstat(stat: &libc::stat) -> FileStat {
|
|||
// FileStat times are in milliseconds
|
||||
fn mktime(secs: u64, nsecs: u64) -> u64 { secs * 1000 + nsecs / 1000000 }
|
||||
|
||||
#[cfg(target_os = "bitrig")]
|
||||
fn ctime(stat: &libc::stat) -> u64 {
|
||||
mktime(stat.st_ctim.tv_sec as u64, stat.st_ctim.tv_nsec as u64)
|
||||
}
|
||||
#[cfg(not(target_os = "bitrig"))]
|
||||
fn ctime(stat: &libc::stat) -> u64 {
|
||||
mktime(stat.st_ctime as u64, stat.st_ctime_nsec as u64)
|
||||
}
|
||||
|
||||
#[cfg(target_os = "bitrig")]
|
||||
fn atime(stat: &libc::stat) -> u64 {
|
||||
mktime(stat.st_atim.tv_sec as u64, stat.st_atim.tv_nsec as u64)
|
||||
}
|
||||
#[cfg(not(target_os = "bitrig"))]
|
||||
fn atime(stat: &libc::stat) -> u64 {
|
||||
mktime(stat.st_atime as u64, stat.st_atime_nsec as u64)
|
||||
}
|
||||
|
||||
#[cfg(target_os = "bitrig")]
|
||||
fn mtime(stat: &libc::stat) -> u64 {
|
||||
mktime(stat.st_mtim.tv_sec as u64, stat.st_mtim.tv_nsec as u64)
|
||||
}
|
||||
#[cfg(not(target_os = "bitrig"))]
|
||||
fn mtime(stat: &libc::stat) -> u64 {
|
||||
mktime(stat.st_mtime as u64, stat.st_mtime_nsec as u64)
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "linux", target_os = "android")))]
|
||||
fn flags(stat: &libc::stat) -> u64 { stat.st_flags as u64 }
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
|
|
@ -312,9 +339,9 @@ fn mkstat(stat: &libc::stat) -> FileStat {
|
|||
_ => old_io::FileType::Unknown,
|
||||
},
|
||||
perm: FilePermission::from_bits_truncate(stat.st_mode as u32),
|
||||
created: mktime(stat.st_ctime as u64, stat.st_ctime_nsec as u64),
|
||||
modified: mktime(stat.st_mtime as u64, stat.st_mtime_nsec as u64),
|
||||
accessed: mktime(stat.st_atime as u64, stat.st_atime_nsec as u64),
|
||||
created: ctime(stat),
|
||||
modified: mtime(stat),
|
||||
accessed: atime(stat),
|
||||
unstable: UnstableFileStat {
|
||||
device: stat.st_dev as u64,
|
||||
inode: stat.st_ino as u64,
|
||||
|
|
|
|||
|
|
@ -40,6 +40,16 @@ pub fn errno() -> i32 {
|
|||
__error()
|
||||
}
|
||||
|
||||
#[cfg(target_os = "bitrig")]
|
||||
fn errno_location() -> *const c_int {
|
||||
extern {
|
||||
fn __errno() -> *const c_int;
|
||||
}
|
||||
unsafe {
|
||||
__errno()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "dragonfly")]
|
||||
unsafe fn errno_location() -> *const c_int {
|
||||
extern { fn __dfly_error() -> *const c_int; }
|
||||
|
|
@ -192,10 +202,9 @@ pub fn current_exe() -> IoResult<Path> {
|
|||
fs::readlink(&Path::new("/proc/curproc/file"))
|
||||
}
|
||||
|
||||
#[cfg(target_os = "openbsd")]
|
||||
#[cfg(any(target_os = "bitrig", target_os = "openbsd"))]
|
||||
pub fn current_exe() -> IoResult<Path> {
|
||||
use sync::{StaticMutex, MUTEX_INIT};
|
||||
|
||||
static LOCK: StaticMutex = MUTEX_INIT;
|
||||
|
||||
extern {
|
||||
|
|
@ -330,6 +339,7 @@ pub fn args() -> Args {
|
|||
target_os = "android",
|
||||
target_os = "freebsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "bitrig",
|
||||
target_os = "openbsd"))]
|
||||
pub fn args() -> Args {
|
||||
use rt;
|
||||
|
|
|
|||
|
|
@ -593,6 +593,7 @@ fn translate_status(status: c_int) -> ProcessExit {
|
|||
target_os = "ios",
|
||||
target_os = "freebsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "bitrig",
|
||||
target_os = "openbsd"))]
|
||||
mod imp {
|
||||
pub fn WIFEXITED(status: i32) -> bool { (status & 0x7f) == 0 }
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ impl Drop for Handler {
|
|||
|
||||
#[cfg(any(target_os = "linux",
|
||||
target_os = "macos",
|
||||
target_os = "bitrig",
|
||||
target_os = "openbsd"))]
|
||||
mod imp {
|
||||
use core::prelude::*;
|
||||
|
|
@ -205,7 +206,9 @@ mod imp {
|
|||
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "macos", target_os = "openbsd"))]
|
||||
#[cfg(any(target_os = "macos",
|
||||
target_os = "bitrig",
|
||||
target_os = "openbsd"))]
|
||||
mod signal {
|
||||
use libc;
|
||||
use super::sighandler_t;
|
||||
|
|
@ -219,6 +222,9 @@ mod imp {
|
|||
#[cfg(target_os = "openbsd")]
|
||||
pub const SIGSTKSZ: libc::size_t = 40960;
|
||||
|
||||
#[cfg(target_os = "bitrig")]
|
||||
pub const SIGSTKSZ: libc::size_t = 40960;
|
||||
|
||||
pub const SIG_DFL: sighandler_t = 0 as sighandler_t;
|
||||
|
||||
pub type sigset_t = u32;
|
||||
|
|
@ -237,14 +243,14 @@ mod imp {
|
|||
pub si_addr: *mut libc::c_void
|
||||
}
|
||||
|
||||
#[cfg(target_os = "openbsd")]
|
||||
#[cfg(any(target_os = "bitrig", 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,
|
||||
// union
|
||||
pub si_addr: *mut libc::c_void,
|
||||
//union
|
||||
pub si_addr: *mut libc::c_void
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
|
|
@ -277,6 +283,7 @@ mod imp {
|
|||
|
||||
#[cfg(not(any(target_os = "linux",
|
||||
target_os = "macos",
|
||||
target_os = "bitrig",
|
||||
target_os = "openbsd")))]
|
||||
mod imp {
|
||||
use libc;
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ extern {
|
|||
|
||||
#[cfg(any(target_os = "freebsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "bitrig",
|
||||
target_os = "openbsd"))]
|
||||
mod os {
|
||||
use libc;
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ pub extern fn thread_start(main: *mut libc::c_void) -> rust_thread_return {
|
|||
|
||||
#[cfg(all(not(target_os = "linux"),
|
||||
not(target_os = "macos"),
|
||||
not(target_os = "bitrig"),
|
||||
not(target_os = "openbsd")))]
|
||||
pub mod guard {
|
||||
pub unsafe fn current() -> uint {
|
||||
|
|
@ -50,11 +51,13 @@ pub mod guard {
|
|||
|
||||
#[cfg(any(target_os = "linux",
|
||||
target_os = "macos",
|
||||
target_os = "bitrig",
|
||||
target_os = "openbsd"))]
|
||||
pub mod guard {
|
||||
use super::*;
|
||||
#[cfg(any(target_os = "linux",
|
||||
target_os = "android",
|
||||
target_os = "bitrig",
|
||||
target_os = "openbsd"))]
|
||||
use mem;
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
|
|
@ -71,7 +74,9 @@ pub mod guard {
|
|||
static mut PAGE_SIZE: uint = 0;
|
||||
static mut GUARD_PAGE: uint = 0;
|
||||
|
||||
#[cfg(any(target_os = "macos", target_os = "openbsd"))]
|
||||
#[cfg(any(target_os = "macos",
|
||||
target_os = "bitrig",
|
||||
target_os = "openbsd"))]
|
||||
unsafe fn get_stack_start() -> *mut libc::c_void {
|
||||
current() as *mut libc::c_void
|
||||
}
|
||||
|
|
@ -189,6 +194,22 @@ pub mod guard {
|
|||
|
||||
stackaddr as uint + guardsize as uint
|
||||
}
|
||||
|
||||
#[cfg(target_os = "bitrig")]
|
||||
pub unsafe fn current() -> uint {
|
||||
let mut current_stack: stack_t = mem::zeroed();
|
||||
if pthread_stackseg_np(pthread_self(), &mut current_stack) != 0 {
|
||||
panic!("failed to get current stack: pthread_stackseg_np")
|
||||
}
|
||||
|
||||
if pthread_main_np() == 1 {
|
||||
// main thread
|
||||
current_stack.ss_sp as uint - current_stack.ss_size as uint + 3 * PAGE_SIZE as uint
|
||||
} else {
|
||||
// new thread
|
||||
current_stack.ss_sp as uint - current_stack.ss_size as uint
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn create(stack: uint, p: Thunk) -> rust_thread {
|
||||
|
|
@ -250,6 +271,7 @@ pub unsafe fn set_name(name: &str) {
|
|||
|
||||
#[cfg(any(target_os = "freebsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "bitrig",
|
||||
target_os = "openbsd"))]
|
||||
pub unsafe fn set_name(name: &str) {
|
||||
// pthread_set_name_np() since almost forever on all BSDs
|
||||
|
|
@ -332,6 +354,15 @@ extern {
|
|||
fn pthread_setname_np(name: *const libc::c_char) -> libc::c_int;
|
||||
}
|
||||
|
||||
#[cfg(target_os = "bitrig")]
|
||||
extern {
|
||||
pub fn pthread_self() -> libc::pthread_t;
|
||||
pub fn pthread_stackseg_np(thread: libc::pthread_t,
|
||||
sinfo: *mut stack_t) -> libc::c_uint;
|
||||
pub fn pthread_main_np() -> libc::c_uint;
|
||||
fn pthread_set_name_np(tid: libc::pthread_t, name: *const libc::c_char);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "openbsd")]
|
||||
extern {
|
||||
pub fn pthread_stackseg_np(thread: libc::pthread_t,
|
||||
|
|
@ -339,7 +370,7 @@ extern {
|
|||
pub fn pthread_main_np() -> libc::c_uint;
|
||||
}
|
||||
|
||||
#[cfg(target_os = "openbsd")]
|
||||
#[cfg(any(target_os = "bitrig", target_os = "openbsd"))]
|
||||
#[repr(C)]
|
||||
pub struct stack_t {
|
||||
pub ss_sp: *mut libc::c_void,
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ type pthread_key_t = ::libc::c_ulong;
|
|||
|
||||
#[cfg(any(target_os = "freebsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "bitrig",
|
||||
target_os = "openbsd"))]
|
||||
type pthread_key_t = ::libc::c_int;
|
||||
|
||||
|
|
@ -50,6 +51,7 @@ type pthread_key_t = ::libc::c_int;
|
|||
target_os = "ios",
|
||||
target_os = "freebsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "bitrig",
|
||||
target_os = "openbsd")))]
|
||||
type pthread_key_t = ::libc::c_uint;
|
||||
|
||||
|
|
|
|||
|
|
@ -80,8 +80,11 @@ mod inner {
|
|||
}
|
||||
|
||||
// Apparently android provides this in some other library?
|
||||
// Bitrig's RT extensions are in the C library, not a separate librt
|
||||
// OpenBSD provide it via libc
|
||||
#[cfg(not(any(target_os = "android", target_os = "openbsd")))]
|
||||
#[cfg(not(any(target_os = "android",
|
||||
target_os = "bitrig",
|
||||
target_os = "openbsd")))]
|
||||
#[link(name = "rt")]
|
||||
extern {}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ pub struct TTY {
|
|||
|
||||
#[cfg(any(target_os = "macos",
|
||||
target_os = "freebsd",
|
||||
target_os = "bitrig",
|
||||
target_os = "openbsd"))]
|
||||
const TIOCGWINSZ: c_ulong = 0x40087468;
|
||||
|
||||
|
|
@ -55,6 +56,7 @@ impl TTY {
|
|||
target_os = "android",
|
||||
target_os = "macos",
|
||||
target_os = "freebsd",
|
||||
target_os = "bitrig",
|
||||
target_os = "openbsd"))]
|
||||
pub fn get_winsize(&mut self) -> IoResult<(int, int)> {
|
||||
unsafe {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue