Skip to content

Split up Solaris and illumos targets #1716

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

Merged
merged 2 commits into from
Apr 11, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
118 changes: 110 additions & 8 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ use std::env;

fn do_cc() {
let target = env::var("TARGET").unwrap();
if cfg!(unix) && !target.contains("wasi") {
cc::Build::new().file("src/cmsg.c").compile("cmsg");
if cfg!(unix) {
let exclude = ["wasi", "solaris", "illumos"];
if !exclude.iter().any(|x| target.contains(x)) {
cc::Build::new().file("src/cmsg.c").compile("cmsg");
}
}
if target.contains("android") || target.contains("linux") {
cc::Build::new().file("src/errqueue.c").compile("errqueue");
Expand All @@ -27,7 +30,8 @@ fn do_ctest() {
t if t.contains("netbsd") => return test_netbsd(t),
t if t.contains("openbsd") => return test_openbsd(t),
t if t.contains("redox") => return test_redox(t),
t if t.contains("solaris") => return test_solaris(t),
t if t.contains("solaris") => return test_solarish(t),
t if t.contains("illumos") => return test_solarish(t),
t if t.contains("wasi") => return test_wasi(t),
t if t.contains("windows") => return test_windows(t),
t if t.contains("vxworks") => return test_vxworks(t),
Expand Down Expand Up @@ -649,9 +653,13 @@ fn test_cloudabi(target: &str) {
cfg.generate("../src/lib.rs", "main.rs");
}

fn test_solaris(target: &str) {
assert!(target.contains("solaris"));
fn test_solarish(target: &str) {
let is_solaris = target.contains("solaris");
let is_illumos = target.contains("illumos");
assert!(is_solaris || is_illumos);

// ctest generates arguments supported only by clang, so make sure to run with CC=clang.
// While debugging, "CFLAGS=-ferror-limit=<large num>" is useful to get more error output.
let mut cfg = ctest_cfg();
cfg.flag("-Wno-deprecated-declarations");

Expand All @@ -664,6 +672,7 @@ fn test_solaris(target: &str) {
"ctype.h",
"dirent.h",
"dlfcn.h",
"door.h",
"errno.h",
"execinfo.h",
"fcntl.h",
Expand All @@ -673,6 +682,7 @@ fn test_solaris(target: &str) {
"langinfo.h",
"limits.h",
"locale.h",
"mqueue.h",
"net/if.h",
"net/if_arp.h",
"net/route.h",
Expand Down Expand Up @@ -705,6 +715,7 @@ fn test_solaris(target: &str) {
"sys/socket.h",
"sys/stat.h",
"sys/statvfs.h",
"sys/shm.h",
"sys/time.h",
"sys/times.h",
"sys/timex.h",
Expand All @@ -723,15 +734,100 @@ fn test_solaris(target: &str) {
"wchar.h",
}

cfg.skip_type(move |ty| {
match ty {
// sighandler_t is not present here
"sighandler_t" => true,
_ => false,
}
});

cfg.type_name(move |ty, is_struct, is_union| {
match ty {
"FILE" => "__FILE".to_string(),
"DIR" | "Dl_info" => ty.to_string(),
t if t.ends_with("_t") => t.to_string(),
t if is_struct => format!("struct {}", t),
t if is_union => format!("union {}", t),
t => t.to_string(),
}
});

cfg.field_name(move |struct_, field| {
match struct_ {
// rust struct uses raw u64, rather than union
"epoll_event" if field == "u64" => "data.u64".to_string(),
// rust struct was committed with typo for Solaris
"door_arg_t" if field == "dec_num" => "desc_num".to_string(),
"stat" if field.ends_with("_nsec") => {
// expose stat.Xtim.tv_nsec fields
field.trim_end_matches("e_nsec").to_string() + ".tv_nsec"
},
_ => field.to_string()
}
});

cfg.skip_const(move |name| match name {
"DT_FIFO" | "DT_CHR" | "DT_DIR" | "DT_BLK" | "DT_REG" | "DT_LNK"
| "DT_SOCK" | "USRQUOTA" | "GRPQUOTA" | "PRIO_MIN" | "PRIO_MAX" => {
true
}

// skip sighandler_t assignments
"SIG_DFL" | "SIG_ERR" | "SIG_IGN" => true,

"DT_UNKNOWN" => true,

"_UTX_LINESIZE" | "_UTX_USERSIZE" |
"_UTX_PADSIZE" | "_UTX_IDSIZE" | "_UTX_HOSTSIZE" => true,

"EADI" | "EXTPROC" | "IPC_SEAT" => true,

// This evaluates to a sysconf() call rather than a constant
"PTHREAD_STACK_MIN" => true,

_ => false,
});



cfg.skip_struct(move |ty| {
// the union handling is a mess
if ty.contains("door_desc_t_") {
return true
}
match ty {
// union, not a struct
"sigval" => true,
// a bunch of solaris-only fields
"utmpx" if is_illumos => true,
_ => false,
}
});

cfg.skip_field(move |s, field| {
match s {
// C99 sizing on this is tough
"dirent" if field == "d_name" => true,
// the union/macro makes this rough
"sigaction" if field == "sa_sigaction" => true,
// Missing in illumos
"sigevent" if field == "ss_sp" => true,
// Avoid sigval union issues
"sigevent" if field == "sigev_value" => true,
// const issues
"sigevent" if field == "sigev_notify_attributes" => true,

// Avoid const and union issues
"door_arg" if field == "desc_ptr" => true,
"door_desc_t" if field == "d_data" => true,
"door_arg_t" if field.ends_with("_ptr") => true,
"door_arg_t" if field.ends_with("rbuf") => true,

_ => false
}
});

cfg.skip_fn(move |name| {
// skip those that are manually verified
match name {
Expand All @@ -746,13 +842,19 @@ fn test_solaris(target: &str) {
// FIXME: unskip these for next major release
"setpriority" | "personality" => true,

// signal is defined with sighandler_t, so ignore
// signal is defined in terms of sighandler_t, so ignore
"signal" => true,

// Currently missing
"cfmakeraw" | "cfsetspeed" => true,

// FIXME: mincore is defined with caddr_t on Solaris.
"mincore" => true,
// const-ness issues
"execv" | "execve" | "execvp" | "settimeofday" | "sethostname" => true,

// Solaris-different
"getpwent_r" | "getgrent_r" | "updwtmpx" if is_illumos => true,
"madvise" | "mprotect" if is_illumos => true,
"door_call" | "door_return" | "door_create" if is_illumos => true,

_ => false,
}
Expand Down
1 change: 1 addition & 0 deletions libc-test/test/cmsg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
extern crate libc;

#[cfg(unix)]
#[cfg(not(any(target_os = "solaris", target_os = "illumos")))]
mod t {

use libc::{self, c_uchar, c_uint, c_void, cmsghdr, msghdr};
Expand Down
12 changes: 9 additions & 3 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,12 @@ pub const S_ISUID: ::mode_t = 0x800;
pub const S_ISGID: ::mode_t = 0x400;
pub const S_ISVTX: ::mode_t = 0x200;

pub const IF_NAMESIZE: ::size_t = 16;
pub const IFNAMSIZ: ::size_t = IF_NAMESIZE;
cfg_if! {
if #[cfg(not(any(target_os = "illumos", target_os = "solaris")))] {
pub const IF_NAMESIZE: ::size_t = 16;
pub const IFNAMSIZ: ::size_t = IF_NAMESIZE;
}
}

pub const LOG_EMERG: ::c_int = 0;
pub const LOG_ALERT: ::c_int = 1;
Expand Down Expand Up @@ -611,7 +615,6 @@ extern "C" {
all(target_os = "macos", target_arch = "x86"),
link_name = "listen$UNIX2003"
)]
#[cfg_attr(target_os = "illumos", link_name = "__xnet_listen")]
pub fn listen(socket: ::c_int, backlog: ::c_int) -> ::c_int;
#[cfg_attr(
all(target_os = "macos", target_arch = "x86"),
Expand Down Expand Up @@ -854,6 +857,7 @@ extern "C" {
pub fn geteuid() -> uid_t;
pub fn getgid() -> gid_t;
pub fn getgroups(ngroups_max: ::c_int, groups: *mut gid_t) -> ::c_int;
#[cfg_attr(target_os = "illumos", link_name = "getloginx")]
pub fn getlogin() -> *mut c_char;
#[cfg_attr(
all(target_os = "macos", target_arch = "x86"),
Expand Down Expand Up @@ -910,6 +914,7 @@ extern "C" {
all(target_os = "macos", target_arch = "x86"),
link_name = "ttyname_r$UNIX2003"
)]
#[cfg_attr(target_os = "illumos", link_name = "__posix_ttyname_r")]
pub fn ttyname_r(
fd: ::c_int,
buf: *mut c_char,
Expand Down Expand Up @@ -1216,6 +1221,7 @@ extern "C" {
pub fn dlclose(handle: *mut ::c_void) -> ::c_int;
pub fn dladdr(addr: *const ::c_void, info: *mut Dl_info) -> ::c_int;

#[cfg_attr(target_os = "illumos", link_name = "__xnet_getaddrinfo")]
pub fn getaddrinfo(
node: *const c_char,
service: *const c_char,
Expand Down
27 changes: 27 additions & 0 deletions src/unix/solarish/illumos.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
s! {
pub struct shmid_ds {
pub shm_perm: ::ipc_perm,
pub shm_segsz: ::size_t,
pub shm_amp: *mut ::c_void,
pub shm_lkcnt: ::c_ushort,
pub shm_lpid: ::pid_t,
pub shm_cpid: ::pid_t,
pub shm_nattch: ::shmatt_t,
pub shm_cnattch: ::c_ulong,
pub shm_atime: ::time_t,
pub shm_dtime: ::time_t,
pub shm_ctime: ::time_t,
pub shm_pad4: [i64; 4],
}
}

pub const AF_LOCAL: ::c_int = 1; // AF_UNIX
pub const AF_FILE: ::c_int = 1; // AF_UNIX

extern "C" {
pub fn mincore(
addr: ::caddr_t,
len: ::size_t,
vec: *mut ::c_char,
) -> ::c_int;
}
Loading