openbsd support
This commit is contained in:
parent
f1f9cb705d
commit
fcb30a0b67
43 changed files with 1036 additions and 72 deletions
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// 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.
|
||||
//
|
||||
|
|
@ -31,7 +31,9 @@ pub extern fn thread_start(main: *mut libc::c_void) -> rust_thread_return {
|
|||
return start_thread(main);
|
||||
}
|
||||
|
||||
#[cfg(all(not(target_os = "linux"), not(target_os = "macos")))]
|
||||
#[cfg(all(not(target_os = "linux"),
|
||||
not(target_os = "macos"),
|
||||
not(target_os = "openbsd")))]
|
||||
pub mod guard {
|
||||
pub unsafe fn current() -> uint {
|
||||
0
|
||||
|
|
@ -45,10 +47,15 @@ pub mod guard {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
|
||||
#[cfg(any(target_os = "linux",
|
||||
target_os = "macos",
|
||||
target_os = "openbsd"))]
|
||||
pub mod guard {
|
||||
use super::*;
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
#[cfg(any(target_os = "linux",
|
||||
target_os = "android",
|
||||
target_os = "openbsd"))]
|
||||
use mem;
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
use ptr;
|
||||
|
|
@ -64,7 +71,7 @@ pub mod guard {
|
|||
static mut PAGE_SIZE: uint = 0;
|
||||
static mut GUARD_PAGE: uint = 0;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
#[cfg(any(target_os = "macos", target_os = "openbsd"))]
|
||||
unsafe fn get_stack_start() -> *mut libc::c_void {
|
||||
current() as *mut libc::c_void
|
||||
}
|
||||
|
|
@ -141,6 +148,23 @@ pub mod guard {
|
|||
pthread_get_stacksize_np(pthread_self())) as uint
|
||||
}
|
||||
|
||||
#[cfg(target_os = "openbsd")]
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
pub unsafe fn current() -> uint {
|
||||
let mut attr: libc::pthread_attr_t = mem::zeroed();
|
||||
|
|
@ -304,6 +328,22 @@ extern {
|
|||
fn pthread_setname_np(name: *const libc::c_char) -> libc::c_int;
|
||||
}
|
||||
|
||||
#[cfg(target_os = "openbsd")]
|
||||
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;
|
||||
}
|
||||
|
||||
#[cfg(target_os = "openbsd")]
|
||||
#[repr(C)]
|
||||
pub struct stack_t {
|
||||
pub ss_sp: *mut libc::c_void,
|
||||
pub ss_size: libc::size_t,
|
||||
pub ss_flags: libc::c_int,
|
||||
}
|
||||
|
||||
extern {
|
||||
fn pthread_create(native: *mut libc::pthread_t,
|
||||
attr: *const libc::pthread_attr_t,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue