Skip to content

Commit 9782b7f

Browse files
authored
Merge pull request #1716 from pfmooney/illumos-target
Split up Solaris and illumos targets
2 parents 035a480 + 48594dc commit 9782b7f

File tree

6 files changed

+273
-109
lines changed

6 files changed

+273
-109
lines changed

libc-test/build.rs

Lines changed: 110 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ use std::env;
77

88
fn do_cc() {
99
let target = env::var("TARGET").unwrap();
10-
if cfg!(unix) && !target.contains("wasi") {
11-
cc::Build::new().file("src/cmsg.c").compile("cmsg");
10+
if cfg!(unix) {
11+
let exclude = ["wasi", "solaris", "illumos"];
12+
if !exclude.iter().any(|x| target.contains(x)) {
13+
cc::Build::new().file("src/cmsg.c").compile("cmsg");
14+
}
1215
}
1316
if target.contains("android") || target.contains("linux") {
1417
cc::Build::new().file("src/errqueue.c").compile("errqueue");
@@ -27,7 +30,8 @@ fn do_ctest() {
2730
t if t.contains("netbsd") => return test_netbsd(t),
2831
t if t.contains("openbsd") => return test_openbsd(t),
2932
t if t.contains("redox") => return test_redox(t),
30-
t if t.contains("solaris") => return test_solaris(t),
33+
t if t.contains("solaris") => return test_solarish(t),
34+
t if t.contains("illumos") => return test_solarish(t),
3135
t if t.contains("wasi") => return test_wasi(t),
3236
t if t.contains("windows") => return test_windows(t),
3337
t if t.contains("vxworks") => return test_vxworks(t),
@@ -649,9 +653,13 @@ fn test_cloudabi(target: &str) {
649653
cfg.generate("../src/lib.rs", "main.rs");
650654
}
651655

652-
fn test_solaris(target: &str) {
653-
assert!(target.contains("solaris"));
656+
fn test_solarish(target: &str) {
657+
let is_solaris = target.contains("solaris");
658+
let is_illumos = target.contains("illumos");
659+
assert!(is_solaris || is_illumos);
654660

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

@@ -664,6 +672,7 @@ fn test_solaris(target: &str) {
664672
"ctype.h",
665673
"dirent.h",
666674
"dlfcn.h",
675+
"door.h",
667676
"errno.h",
668677
"execinfo.h",
669678
"fcntl.h",
@@ -673,6 +682,7 @@ fn test_solaris(target: &str) {
673682
"langinfo.h",
674683
"limits.h",
675684
"locale.h",
685+
"mqueue.h",
676686
"net/if.h",
677687
"net/if_arp.h",
678688
"net/route.h",
@@ -705,6 +715,7 @@ fn test_solaris(target: &str) {
705715
"sys/socket.h",
706716
"sys/stat.h",
707717
"sys/statvfs.h",
718+
"sys/shm.h",
708719
"sys/time.h",
709720
"sys/times.h",
710721
"sys/timex.h",
@@ -723,15 +734,100 @@ fn test_solaris(target: &str) {
723734
"wchar.h",
724735
}
725736

737+
cfg.skip_type(move |ty| {
738+
match ty {
739+
// sighandler_t is not present here
740+
"sighandler_t" => true,
741+
_ => false,
742+
}
743+
});
744+
745+
cfg.type_name(move |ty, is_struct, is_union| {
746+
match ty {
747+
"FILE" => "__FILE".to_string(),
748+
"DIR" | "Dl_info" => ty.to_string(),
749+
t if t.ends_with("_t") => t.to_string(),
750+
t if is_struct => format!("struct {}", t),
751+
t if is_union => format!("union {}", t),
752+
t => t.to_string(),
753+
}
754+
});
755+
756+
cfg.field_name(move |struct_, field| {
757+
match struct_ {
758+
// rust struct uses raw u64, rather than union
759+
"epoll_event" if field == "u64" => "data.u64".to_string(),
760+
// rust struct was committed with typo for Solaris
761+
"door_arg_t" if field == "dec_num" => "desc_num".to_string(),
762+
"stat" if field.ends_with("_nsec") => {
763+
// expose stat.Xtim.tv_nsec fields
764+
field.trim_end_matches("e_nsec").to_string() + ".tv_nsec"
765+
},
766+
_ => field.to_string()
767+
}
768+
});
769+
726770
cfg.skip_const(move |name| match name {
727771
"DT_FIFO" | "DT_CHR" | "DT_DIR" | "DT_BLK" | "DT_REG" | "DT_LNK"
728772
| "DT_SOCK" | "USRQUOTA" | "GRPQUOTA" | "PRIO_MIN" | "PRIO_MAX" => {
729773
true
730774
}
731775

776+
// skip sighandler_t assignments
777+
"SIG_DFL" | "SIG_ERR" | "SIG_IGN" => true,
778+
779+
"DT_UNKNOWN" => true,
780+
781+
"_UTX_LINESIZE" | "_UTX_USERSIZE" |
782+
"_UTX_PADSIZE" | "_UTX_IDSIZE" | "_UTX_HOSTSIZE" => true,
783+
784+
"EADI" | "EXTPROC" | "IPC_SEAT" => true,
785+
786+
// This evaluates to a sysconf() call rather than a constant
787+
"PTHREAD_STACK_MIN" => true,
788+
732789
_ => false,
733790
});
734791

792+
793+
794+
cfg.skip_struct(move |ty| {
795+
// the union handling is a mess
796+
if ty.contains("door_desc_t_") {
797+
return true
798+
}
799+
match ty {
800+
// union, not a struct
801+
"sigval" => true,
802+
// a bunch of solaris-only fields
803+
"utmpx" if is_illumos => true,
804+
_ => false,
805+
}
806+
});
807+
808+
cfg.skip_field(move |s, field| {
809+
match s {
810+
// C99 sizing on this is tough
811+
"dirent" if field == "d_name" => true,
812+
// the union/macro makes this rough
813+
"sigaction" if field == "sa_sigaction" => true,
814+
// Missing in illumos
815+
"sigevent" if field == "ss_sp" => true,
816+
// Avoid sigval union issues
817+
"sigevent" if field == "sigev_value" => true,
818+
// const issues
819+
"sigevent" if field == "sigev_notify_attributes" => true,
820+
821+
// Avoid const and union issues
822+
"door_arg" if field == "desc_ptr" => true,
823+
"door_desc_t" if field == "d_data" => true,
824+
"door_arg_t" if field.ends_with("_ptr") => true,
825+
"door_arg_t" if field.ends_with("rbuf") => true,
826+
827+
_ => false
828+
}
829+
});
830+
735831
cfg.skip_fn(move |name| {
736832
// skip those that are manually verified
737833
match name {
@@ -746,13 +842,19 @@ fn test_solaris(target: &str) {
746842
// FIXME: unskip these for next major release
747843
"setpriority" | "personality" => true,
748844

749-
// signal is defined with sighandler_t, so ignore
845+
// signal is defined in terms of sighandler_t, so ignore
750846
"signal" => true,
751847

848+
// Currently missing
752849
"cfmakeraw" | "cfsetspeed" => true,
753850

754-
// FIXME: mincore is defined with caddr_t on Solaris.
755-
"mincore" => true,
851+
// const-ness issues
852+
"execv" | "execve" | "execvp" | "settimeofday" | "sethostname" => true,
853+
854+
// Solaris-different
855+
"getpwent_r" | "getgrent_r" | "updwtmpx" if is_illumos => true,
856+
"madvise" | "mprotect" if is_illumos => true,
857+
"door_call" | "door_return" | "door_create" if is_illumos => true,
756858

757859
_ => false,
758860
}

libc-test/test/cmsg.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
extern crate libc;
55

66
#[cfg(unix)]
7+
#[cfg(not(any(target_os = "solaris", target_os = "illumos")))]
78
mod t {
89

910
use libc::{self, c_uchar, c_uint, c_void, cmsghdr, msghdr};

src/unix/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,12 @@ pub const S_ISUID: ::mode_t = 0x800;
226226
pub const S_ISGID: ::mode_t = 0x400;
227227
pub const S_ISVTX: ::mode_t = 0x200;
228228

229-
pub const IF_NAMESIZE: ::size_t = 16;
230-
pub const IFNAMSIZ: ::size_t = IF_NAMESIZE;
229+
cfg_if! {
230+
if #[cfg(not(any(target_os = "illumos", target_os = "solaris")))] {
231+
pub const IF_NAMESIZE: ::size_t = 16;
232+
pub const IFNAMSIZ: ::size_t = IF_NAMESIZE;
233+
}
234+
}
231235

232236
pub const LOG_EMERG: ::c_int = 0;
233237
pub const LOG_ALERT: ::c_int = 1;
@@ -612,7 +616,6 @@ extern "C" {
612616
all(target_os = "macos", target_arch = "x86"),
613617
link_name = "listen$UNIX2003"
614618
)]
615-
#[cfg_attr(target_os = "illumos", link_name = "__xnet_listen")]
616619
pub fn listen(socket: ::c_int, backlog: ::c_int) -> ::c_int;
617620
#[cfg_attr(
618621
all(target_os = "macos", target_arch = "x86"),
@@ -855,6 +858,7 @@ extern "C" {
855858
pub fn geteuid() -> uid_t;
856859
pub fn getgid() -> gid_t;
857860
pub fn getgroups(ngroups_max: ::c_int, groups: *mut gid_t) -> ::c_int;
861+
#[cfg_attr(target_os = "illumos", link_name = "getloginx")]
858862
pub fn getlogin() -> *mut c_char;
859863
#[cfg_attr(
860864
all(target_os = "macos", target_arch = "x86"),
@@ -911,6 +915,7 @@ extern "C" {
911915
all(target_os = "macos", target_arch = "x86"),
912916
link_name = "ttyname_r$UNIX2003"
913917
)]
918+
#[cfg_attr(target_os = "illumos", link_name = "__posix_ttyname_r")]
914919
pub fn ttyname_r(
915920
fd: ::c_int,
916921
buf: *mut c_char,
@@ -1217,6 +1222,7 @@ extern "C" {
12171222
pub fn dlclose(handle: *mut ::c_void) -> ::c_int;
12181223
pub fn dladdr(addr: *const ::c_void, info: *mut Dl_info) -> ::c_int;
12191224

1225+
#[cfg_attr(target_os = "illumos", link_name = "__xnet_getaddrinfo")]
12201226
pub fn getaddrinfo(
12211227
node: *const c_char,
12221228
service: *const c_char,

src/unix/solarish/illumos.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
s! {
2+
pub struct shmid_ds {
3+
pub shm_perm: ::ipc_perm,
4+
pub shm_segsz: ::size_t,
5+
pub shm_amp: *mut ::c_void,
6+
pub shm_lkcnt: ::c_ushort,
7+
pub shm_lpid: ::pid_t,
8+
pub shm_cpid: ::pid_t,
9+
pub shm_nattch: ::shmatt_t,
10+
pub shm_cnattch: ::c_ulong,
11+
pub shm_atime: ::time_t,
12+
pub shm_dtime: ::time_t,
13+
pub shm_ctime: ::time_t,
14+
pub shm_pad4: [i64; 4],
15+
}
16+
}
17+
18+
pub const AF_LOCAL: ::c_int = 1; // AF_UNIX
19+
pub const AF_FILE: ::c_int = 1; // AF_UNIX
20+
21+
extern "C" {
22+
pub fn mincore(
23+
addr: ::caddr_t,
24+
len: ::size_t,
25+
vec: *mut ::c_char,
26+
) -> ::c_int;
27+
}

0 commit comments

Comments
 (0)