Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Openbsd cleanup #110

Merged
merged 17 commits into from
Jan 11, 2016
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ fn main() {
let freebsd = target.contains("freebsd");
let mips = target.contains("mips");
let netbsd = target.contains("netbsd");
let openbsd = target.contains("openbsd");
let rumprun = target.contains("rumprun");
let bsdlike = freebsd || apple || netbsd;
let bsdlike = freebsd || apple || netbsd || openbsd;
let mut cfg = ctest::TestGenerator::new();

// Pull in extra goodies on linux/mingw
Expand Down Expand Up @@ -61,6 +62,9 @@ fn main() {
} else {
cfg.header("ctype.h");
cfg.header("dirent.h");
if openbsd {
cfg.header("sys/socket.h");
}
cfg.header("net/if.h");
cfg.header("netdb.h");
cfg.header("netinet/in.h");
Expand Down Expand Up @@ -96,13 +100,15 @@ fn main() {
} else if !windows {
cfg.header("glob.h");
cfg.header("ifaddrs.h");
cfg.header("sys/quota.h");
if !openbsd {
cfg.header("sys/quota.h");
}
cfg.header("sys/statvfs.h");

if !musl {
cfg.header("sys/sysctl.h");

if !netbsd {
if !netbsd && !openbsd {
cfg.header("execinfo.h");
}
}
Expand Down Expand Up @@ -161,6 +167,13 @@ fn main() {
cfg.header("sys/ioctl_compat.h");
}

if openbsd {
cfg.header("ufs/ufs/quota.h");
cfg.header("rpcsvc/rex.h");
cfg.header("pthread_np.h");
cfg.header("sys/syscall.h");
}

cfg.type_name(move |ty, is_struct| {
match ty {
// Just pass all these through, no need for a "struct" prefix
Expand Down Expand Up @@ -200,6 +213,9 @@ fn main() {
let target2 = target.clone();
cfg.field_name(move |struct_, field| {
match field {
"d_namelen" if openbsd && struct_ == "dirent" => "d_namlen".to_string(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this struct field be updated on openbsd to match the name in C? For renamings like this Rust shouldn't differ much

"st_birthtime" if openbsd && struct_ == "stat" => "__st_birthtime".to_string(),
"st_birthtime_nsec" if openbsd && struct_ == "stat" => "__st_birthtimensec".to_string(),
// Our stat *_nsec fields normally don't actually exist but are part
// of a timeval struct
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
Expand Down Expand Up @@ -303,7 +319,7 @@ fn main() {
"strerror_r" if linux => true, // actually xpg-something-or-other

// typed 2nd arg on linux and android
"gettimeofday" if linux || android || freebsd => true,
"gettimeofday" if linux || android || freebsd || openbsd => true,

// not declared in newer android toolchains
"getdtablesize" if android => true,
Expand Down
9 changes: 9 additions & 0 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,16 @@ pub const VT1: ::c_int = 0x00010000;
pub const IUTF8: ::tcflag_t = 0x00004000;
pub const CRTSCTS: ::tcflag_t = 0x00030000;

pub const NI_MAXHOST: ::socklen_t = 1025;

extern {
pub fn getnameinfo(sa: *const ::sockaddr,
salen: ::socklen_t,
host: *mut ::c_char,
hostlen: ::socklen_t,
serv: *mut ::c_char,
sevlen: ::socklen_t,
flags: ::c_int) -> ::c_int;
pub fn mincore(addr: *const ::c_void, len: ::size_t,
vec: *mut ::c_char) -> ::c_int;
pub fn sysctlnametomib(name: *const ::c_char,
Expand Down
9 changes: 9 additions & 0 deletions src/unix/bsd/freebsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,16 @@ pub const ST_NOSUID: ::c_ulong = 2;

pub const HW_AVAILCPU: ::c_int = 25;

pub const NI_MAXHOST: ::size_t = 1025;

extern {
pub fn getnameinfo(sa: *const ::sockaddr,
salen: ::socklen_t,
host: *mut ::c_char,
hostlen: ::size_t,
serv: *mut ::c_char,
servlen: ::size_t,
flags: ::c_int) -> ::c_int;
pub fn mincore(addr: *const ::c_void, len: ::size_t,
vec: *mut ::c_char) -> ::c_int;
pub fn sysctlnametomib(name: *const ::c_char,
Expand Down
12 changes: 2 additions & 10 deletions src/unix/bsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ s! {

#[cfg(not(any(target_os = "macos",
target_os = "ios",
target_os = "netbsd")))]
target_os = "netbsd",
target_os = "openbsd")))]
pub pw_fields: ::c_int,
}

Expand Down Expand Up @@ -146,8 +147,6 @@ pub const IPV6_V6ONLY: ::c_int = 27;

pub const ST_RDONLY: ::c_ulong = 1;

pub const NI_MAXHOST: ::socklen_t = 1025;

pub const CTL_HW: ::c_int = 6;
pub const HW_NCPU: ::c_int = 3;

Expand Down Expand Up @@ -321,13 +320,6 @@ extern {
pub fn setgroups(ngroups: ::c_int,
ptr: *const ::gid_t) -> ::c_int;
pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int;
pub fn getnameinfo(sa: *const ::sockaddr,
salen: ::socklen_t,
host: *mut ::c_char,
hostlen: ::socklen_t,
serv: *mut ::c_char,
sevlen: ::socklen_t,
flags: ::c_int) -> ::c_int;
pub fn kqueue() -> ::c_int;
pub fn unmount(target: *const ::c_char, arg: ::c_int) -> ::c_int;
pub fn syscall(num: ::c_int, ...) -> ::c_int;
Expand Down
18 changes: 18 additions & 0 deletions src/unix/bsd/openbsdlike/bitrig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ s! {
pub si_errno: ::c_int,
pub si_addr: *mut ::c_void
}

pub struct Dl_info {
pub dli_fname: *const ::c_char,
pub dli_fbase: *mut ::c_void,
pub dli_sname: *const ::c_char,
pub dli_saddr: *mut ::c_void,
}
}

pub const O_CLOEXEC: ::c_int = 0x10000;
Expand Down Expand Up @@ -208,7 +215,18 @@ pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 2;
pub const HW_AVAILCPU: ::c_int = 25;
pub const KERN_PROC_ARGS: ::c_int = 55;

pub const TMP_MAX : ::c_uint = 0x7fffffff;

pub const NI_MAXHOST: ::size_t = 256;

extern {
pub fn getnameinfo(sa: *const ::sockaddr,
salen: ::socklen_t,
host: *mut ::c_char,
hostlen: ::size_t,
serv: *mut ::c_char,
servlen: ::size_t,
flags: ::c_int) -> ::c_int;
pub fn mprotect(addr: *const ::c_void, len: ::size_t, prot: ::c_int)
-> ::c_int;
pub fn sysctl(name: *mut ::c_int,
Expand Down
13 changes: 2 additions & 11 deletions src/unix/bsd/openbsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ s! {
pub ss_flags: ::c_int,
}

pub struct Dl_info {
pub dli_fname: *const ::c_char,
pub dli_fbase: *mut ::c_void,
pub dli_sname: *const ::c_char,
pub dli_saddr: *const ::c_void,
}

pub struct sockaddr_in {
pub sin_len: u8,
pub sin_family: ::sa_family_t,
Expand Down Expand Up @@ -64,7 +57,6 @@ 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 const O_RDONLY : ::c_int = 0;
pub const O_WRONLY : ::c_int = 1;
pub const O_RDWR : ::c_int = 2;
Expand Down Expand Up @@ -368,13 +360,12 @@ extern {
#[cfg_attr(target_os = "netbsd", link_name = "__clock_gettime50")]
pub fn clock_gettime(clk_id: ::c_int, tp: *mut ::timespec) -> ::c_int;
pub fn __errno() -> *mut ::c_int;
pub fn backtrace(buf: *mut *mut ::c_void, sz: ::size_t) -> ::size_t;
pub fn shm_open(name: *const ::c_char, oflag: ::c_int, mode: ::mode_t)
-> ::c_int;
pub fn pthread_main_np() -> ::c_uint;
pub fn pthread_main_np() -> ::c_int;
pub fn pthread_set_name_np(tid: ::pthread_t, name: *const ::c_char);
pub fn pthread_stackseg_np(thread: ::pthread_t,
sinfo: *mut ::stack_t) -> ::c_uint;
sinfo: *mut ::stack_t) -> ::c_int;
pub fn memrchr(cx: *const ::c_void, c: ::c_int, n: ::size_t) -> *mut ::c_void;
}

Expand Down
18 changes: 18 additions & 0 deletions src/unix/bsd/openbsdlike/netbsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ s! {
pub dqb_btime: ::int32_t,
pub dqb_itime: ::int32_t,
}

pub struct Dl_info {
pub dli_fname: *const ::c_char,
pub dli_fbase: *mut ::c_void,
pub dli_sname: *const ::c_char,
pub dli_saddr: *const ::c_void,
}
}

pub const O_CLOEXEC: ::c_int = 0x400000;
Expand Down Expand Up @@ -313,7 +320,18 @@ pub const NOTE_PCTRLMASK: ::uint32_t = 0xf0000000;

pub const CRTSCTS: ::tcflag_t = 0x00010000;

pub const TMP_MAX : ::c_uint = 308915776;

pub const NI_MAXHOST: ::socklen_t = 1025;

extern {
pub fn getnameinfo(sa: *const ::sockaddr,
salen: ::socklen_t,
host: *mut ::c_char,
hostlen: ::socklen_t,
serv: *mut ::c_char,
sevlen: ::socklen_t,
flags: ::c_int) -> ::c_int;
pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int)
-> ::c_int;
pub fn sysctl(name: *const ::c_int,
Expand Down
46 changes: 26 additions & 20 deletions src/unix/bsd/openbsdlike/openbsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ pub type clock_t = i64;
pub type suseconds_t = i64;
pub type dev_t = i32;
pub type sigset_t = ::c_uint;
pub type blksize_t = ::uint32_t;
pub type fsblkcnt_t = ::c_uint;
pub type fsfilcnt_t = ::c_uint;
pub type blksize_t = ::int32_t;
pub type fsblkcnt_t = ::uint64_t;
pub type fsfilcnt_t = ::uint64_t;
pub type pthread_attr_t = *mut ::c_void;
pub type pthread_mutex_t = *mut ::c_void;
pub type pthread_mutexattr_t = *mut ::c_void;
Expand Down Expand Up @@ -99,8 +99,15 @@ s! {
pub si_signo: ::c_int,
pub si_code: ::c_int,
pub si_errno: ::c_int,
pub si_addr: *mut ::c_void,
__pad: [u8; 116],
pub si_addr: *mut ::c_char,
__pad: [u8; 108],
}

pub struct Dl_info {
pub dli_fname: *const ::c_char,
pub dli_fbase: *mut ::c_void,
pub dli_sname: *const ::c_char,
pub dli_saddr: *mut ::c_void,
}
}

Expand Down Expand Up @@ -140,9 +147,6 @@ pub const EMEDIUMTYPE : ::c_int = 86;

pub const RUSAGE_THREAD: ::c_int = 1;

pub const IPV6_ADD_MEMBERSHIP: ::c_int = 12;
pub const IPV6_DROP_MEMBERSHIP: ::c_int = 13;

pub const MAP_COPY : ::c_int = 0x0002;
pub const MAP_NOEXTEND : ::c_int = 0x0000;

Expand Down Expand Up @@ -197,7 +201,7 @@ pub const _SC_RTSIG_MAX : ::c_int = 66;
pub const _SC_SIGQUEUE_MAX : ::c_int = 70;
pub const _SC_TIMER_MAX : ::c_int = 93;

pub const SIGSTKSZ: ::size_t = 131072;
pub const SIGSTKSZ: ::size_t = 40960;

pub const FD_SETSIZE: usize = 1024;

Expand All @@ -208,26 +212,28 @@ pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = 0 as *mut _;
pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = 0 as *mut _;
pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 2;

pub const HW_AVAILCPU: ::c_int = 25;
pub const KERN_PROC_ARGS: ::c_int = 55;

// syscall numbers
pub const NR_GETENTROPY: ::c_int = 7;
pub const TMP_MAX : ::c_uint = 0x7fffffff;

pub const NI_MAXHOST: ::size_t = 256;

extern {
pub fn mprotect(addr: *const ::c_void, len: ::size_t, prot: ::c_int)
pub fn getnameinfo(sa: *const ::sockaddr,
salen: ::socklen_t,
host: *mut ::c_char,
hostlen: ::size_t,
serv: *mut ::c_char,
servlen: ::size_t,
flags: ::c_int) -> ::c_int;
pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int)
-> ::c_int;
pub fn sysctl(name: *mut ::c_int,
pub fn sysctl(name: *const ::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 getentropy(buf: *mut ::c_void, buflen: ::size_t) -> ::c_int;
}