From 7c03711d45041a30a812113d6dd61bda271751cc Mon Sep 17 00:00:00 2001 From: Ryan Moeller Date: Tue, 21 Feb 2017 00:41:12 +0000 Subject: [PATCH 1/4] Add jail functions and constants for FreeBSD --- libc-test/build.rs | 1 + src/unix/bsd/freebsdlike/freebsd/mod.rs | 30 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index fc4db1e9..37a237a5 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -195,6 +195,7 @@ fn main() { cfg.header("pthread_np.h"); cfg.header("sched.h"); cfg.header("ufs/ufs/quota.h"); + cfg.header("sys/jail.h"); } if netbsd { diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index b02e9a77..f0cbaf11 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -47,6 +47,17 @@ s! { pub d_name: [::c_char; 256], } + pub struct jail { + pub version: u32, + pub path: *mut ::c_char, + pub hostname: *mut ::c_char, + pub jailname: *mut ::c_char, + pub ip4s: ::c_uint, + pub ip6s: ::c_uint, + pub ip4: *mut ::in_addr, + pub ip6: *mut ::in6_addr, + } + pub struct sigevent { pub sigev_notify: ::c_int, pub sigev_signo: ::c_int, @@ -322,6 +333,17 @@ pub const TIOCSIG: ::c_uint = 0x2004745f; pub const TIOCM_DCD: ::c_int = 0x40; pub const H4DISC: ::c_int = 0x7; +pub const JAIL_API_VERSION: u32 = 2; +pub const JAIL_CREATE: ::c_int = 0x01; +pub const JAIL_UPDATE: ::c_int = 0x02; +pub const JAIL_ATTACH: ::c_int = 0x04; +pub const JAIL_DYING: ::c_int = 0x08; +pub const JAIL_SET_MASK: ::c_int = 0x0f; +pub const JAIL_GET_MASK: ::c_int = 0x08; +pub const JAIL_SYS_DISABLE: ::c_int = 0; +pub const JAIL_SYS_NEW: ::c_int = 1; +pub const JAIL_SYS_INHERIT: ::c_int = 2; + // The *_MAXID constants never should've been used outside of the // FreeBSD base system. And with the exception of CTL_P1003_1B_MAXID, // they were all removed in svn r262489. They remain here for backwards @@ -385,6 +407,14 @@ extern { pub fn clock_gettime(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int; pub fn clock_settime(clk_id: clockid_t, tp: *const ::timespec) -> ::c_int; + pub fn jail(jail: *mut ::jail) -> ::c_int; + pub fn jail_attach(jid: ::c_int) -> ::c_int; + pub fn jail_remove(jid: ::c_int) -> ::c_int; + pub fn jail_get(iov: *mut ::iovec, niov: ::c_uint, flags: ::c_int) + -> ::c_int; + pub fn jail_set(iov: *mut ::iovec, niov: ::c_uint, flags: ::c_int) + -> ::c_int; + pub fn posix_fallocate(fd: ::c_int, offset: ::off_t, len: ::off_t) -> ::c_int; pub fn posix_fadvise(fd: ::c_int, offset: ::off_t, len: ::off_t, From bad80ba4d767f11247c25073088ae06acd040365 Mon Sep 17 00:00:00 2001 From: Marco A L Barbosa Date: Tue, 21 Feb 2017 16:58:03 -0300 Subject: [PATCH 2/4] Add definitions to Android to allow fs2 crate compile --- libc-test/build.rs | 2 +- src/unix/mod.rs | 4 ++-- src/unix/notbsd/android/mod.rs | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index fc4db1e9..9ad44f42 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -101,6 +101,7 @@ fn main() { cfg.header("poll.h"); cfg.header("syslog.h"); cfg.header("semaphore.h"); + cfg.header("sys/statvfs.h"); } if android { @@ -111,7 +112,6 @@ fn main() { } else if !windows { cfg.header("glob.h"); cfg.header("ifaddrs.h"); - cfg.header("sys/statvfs.h"); cfg.header("langinfo.h"); if !openbsd && !freebsd && !dragonfly { diff --git a/src/unix/mod.rs b/src/unix/mod.rs index b2c64a88..4e0ec4d1 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -745,6 +745,8 @@ extern { pshared: ::c_int, value: ::c_uint) -> ::c_int; + pub fn statvfs(path: *const c_char, buf: *mut statvfs) -> ::c_int; + pub fn fstatvfs(fd: ::c_int, buf: *mut statvfs) -> ::c_int; } // TODO: get rid of this cfg(not(...)) @@ -824,8 +826,6 @@ extern { pub fn ftello(stream: *mut ::FILE) -> ::off_t; #[cfg_attr(target_os = "netbsd", link_name = "__timegm50")] pub fn timegm(tm: *mut ::tm) -> time_t; - pub fn statvfs(path: *const c_char, buf: *mut statvfs) -> ::c_int; - pub fn fstatvfs(fd: ::c_int, buf: *mut statvfs) -> ::c_int; #[cfg_attr(all(target_os = "macos", target_arch = "x86"), link_name = "tcdrain$UNIX2003")] pub fn tcdrain(fd: ::c_int) -> ::c_int; diff --git a/src/unix/notbsd/android/mod.rs b/src/unix/notbsd/android/mod.rs index 4b4e2622..ec6aa90e 100644 --- a/src/unix/notbsd/android/mod.rs +++ b/src/unix/notbsd/android/mod.rs @@ -136,6 +136,20 @@ s! { pub ut_addr_v6: [::int32_t; 4], unused: [::c_char; 20], } + + pub struct statvfs { + pub f_bsize: ::c_ulong, + pub f_frsize: ::c_ulong, + pub f_blocks: ::fsblkcnt_t, + pub f_bfree: ::fsblkcnt_t, + pub f_bavail: ::fsblkcnt_t, + pub f_files: ::fsfilcnt_t, + pub f_ffree: ::fsfilcnt_t, + pub f_favail: ::fsfilcnt_t, + pub f_fsid: ::c_ulong, + pub f_flag: ::c_ulong, + pub f_namemax: ::c_ulong, + } } pub const O_TRUNC: ::c_int = 512; @@ -801,6 +815,9 @@ extern { pub fn utmpname(name: *const ::c_char) -> ::c_int; pub fn setutent(); pub fn getutent() -> *mut utmp; + + pub fn posix_fallocate(fd: ::c_int, offset: ::off_t, + len: ::off_t) -> ::c_int; } cfg_if! { From e0100781277b2ca6e69975405f95195e28b19797 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Tue, 21 Feb 2017 15:07:03 -0800 Subject: [PATCH 3/4] Make readdir available on all unix targets The readdir_r call has problems, and we'll probably want to move to readdir on many, if not most, unix targets. This patch makes readdir available in unix, rather than just solaris as before. See https://github.com/rust-lang/rust/issues/40021 --- src/unix/mod.rs | 3 +++ src/unix/solaris/mod.rs | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 427553d1..224061c8 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -350,6 +350,9 @@ extern { link_name = "opendir$INODE64$UNIX2003")] #[cfg_attr(target_os = "netbsd", link_name = "__opendir30")] pub fn opendir(dirname: *const c_char) -> *mut ::DIR; + #[cfg_attr(target_os = "macos", link_name = "readdir$INODE64")] + #[cfg_attr(target_os = "netbsd", link_name = "__readdir30")] + pub fn readdir(dirp: *mut ::DIR) -> *const ::dirent; #[cfg_attr(target_os = "macos", link_name = "readdir_r$INODE64")] #[cfg_attr(target_os = "netbsd", link_name = "__readdir_r30")] pub fn readdir_r(dirp: *mut ::DIR, entry: *mut ::dirent, diff --git a/src/unix/solaris/mod.rs b/src/unix/solaris/mod.rs index 5a15f812..1247917b 100644 --- a/src/unix/solaris/mod.rs +++ b/src/unix/solaris/mod.rs @@ -1017,7 +1017,6 @@ extern { buflen: ::c_int) -> *const passwd; pub fn setpwent(); pub fn getpwent() -> *mut passwd; - pub fn readdir(dirp: *mut ::DIR) -> *const ::dirent; pub fn fdatasync(fd: ::c_int) -> ::c_int; pub fn nl_langinfo_l(item: ::nl_item, locale: ::locale_t) -> *mut ::c_char; pub fn duplocale(base: ::locale_t) -> ::locale_t; From 02990f2fd2801908e0f8e2022270b504c4359829 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Tue, 21 Feb 2017 19:13:16 -0800 Subject: [PATCH 4/4] Change return type of readdir to *mut ::dirent Apparently a lot of libc's don't put "const" on the return type for readdir, which causes type mismatch. --- src/unix/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 224061c8..4ff759c0 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -352,7 +352,7 @@ extern { pub fn opendir(dirname: *const c_char) -> *mut ::DIR; #[cfg_attr(target_os = "macos", link_name = "readdir$INODE64")] #[cfg_attr(target_os = "netbsd", link_name = "__readdir30")] - pub fn readdir(dirp: *mut ::DIR) -> *const ::dirent; + pub fn readdir(dirp: *mut ::DIR) -> *mut ::dirent; #[cfg_attr(target_os = "macos", link_name = "readdir_r$INODE64")] #[cfg_attr(target_os = "netbsd", link_name = "__readdir_r30")] pub fn readdir_r(dirp: *mut ::DIR, entry: *mut ::dirent,