From a1067a2ffbd92030fd82525c8dca501e7f5945fb Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Sat, 26 Aug 2017 10:43:29 -0700 Subject: Use libc types for sched FFI --- src/sched.rs | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/src/sched.rs b/src/sched.rs index 943b432b..74c23072 100644 --- a/src/sched.rs +++ b/src/sched.rs @@ -73,25 +73,6 @@ impl CpuSet { } } -mod ffi { - use libc::{c_void, c_int}; - - pub type CloneCb = extern "C" fn(data: *const super::CloneCb) -> c_int; - - // We cannot give a proper #[repr(C)] to super::CloneCb - #[allow(improper_ctypes)] - extern "C" { - // create a child process - // doc: http://man7.org/linux/man-pages/man2/clone.2.html - pub fn clone(cb: *const CloneCb, - child_stack: *mut c_void, - flags: c_int, - arg: *mut super::CloneCb, - ...) - -> c_int; - } -} - pub fn sched_setaffinity(pid: Pid, cpuset: &CpuSet) -> Result<()> { let res = unsafe { libc::sched_setaffinity(pid.into(), @@ -116,10 +97,10 @@ pub fn clone(mut cb: CloneCb, let combined = flags.bits() | signal.unwrap_or(0); let ptr = stack.as_mut_ptr().offset(stack.len() as isize); let ptr_aligned = ptr.offset((ptr as usize % 16) as isize * -1); - ffi::clone(mem::transmute(callback as extern "C" fn(*mut Box<::std::ops::FnMut() -> isize>) -> i32), + libc::clone(mem::transmute(callback as extern "C" fn(*mut Box<::std::ops::FnMut() -> isize>) -> i32), ptr_aligned as *mut c_void, combined, - &mut cb) + &mut cb as *mut _ as *mut c_void) }; Errno::result(res).map(Pid::from_raw) -- cgit v1.2.3 From d322aa9a3f8e685eb6f48843f22ec12127f6251d Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Sat, 26 Aug 2017 21:03:52 -0700 Subject: Remove syscall module. This module merely contained FFI declarations, and only enough to implement memfd_create() and pivot_root() wrapper functions in nix. Since these declarations are redundant with equivalent FFI declarations in libc, we'll remove them here. In the future, any syscall-related wrapper function will be implemented directly and utilize libc for FFI declarations as we cannot generically expose a type-safe `syscall()` because of its variadic argument list. --- CHANGELOG.md | 5 +++ src/sys/memfd.rs | 5 +-- src/sys/mod.rs | 3 -- src/sys/syscall.rs | 91 ------------------------------------------------------ src/unistd.rs | 8 ++--- 5 files changed, 12 insertions(+), 100 deletions(-) delete mode 100644 src/sys/syscall.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 148f0c6d..9214b7e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,11 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Fix compilation and tests for OpenBSD targets ([#688](https://github.com/nix-rust/nix/pull/688)) +# Removed +- The syscall module has been removed. This only exposed enough functionality for + `memfd_create()` and `pivot_root()`, which are still exposed as separate functions. + ([#747](https://github.com/nix-rust/nix/pull/747)) + ## [0.9.0] 2017-07-23 ### Added diff --git a/src/sys/memfd.rs b/src/sys/memfd.rs index b9812943..056e9e43 100644 --- a/src/sys/memfd.rs +++ b/src/sys/memfd.rs @@ -11,8 +11,9 @@ bitflags!( ); pub fn memfd_create(name: &CStr, flags: MemFdCreateFlag) -> Result { - use sys::syscall::{syscall, MEMFD_CREATE}; - let res = unsafe { syscall(MEMFD_CREATE, name.as_ptr(), flags.bits()) }; + let res = unsafe { + libc::syscall(libc::SYS_memfd_create, name.as_ptr(), flags.bits()) + }; Errno::result(res).map(|r| r as RawFd) } diff --git a/src/sys/mod.rs b/src/sys/mod.rs index c73a09cd..7326a2cf 100644 --- a/src/sys/mod.rs +++ b/src/sys/mod.rs @@ -31,9 +31,6 @@ pub mod socket; pub mod stat; -#[cfg(any(target_os = "linux", target_os = "android"))] -pub mod syscall; - #[cfg(any(target_os = "linux"))] pub mod reboot; diff --git a/src/sys/syscall.rs b/src/sys/syscall.rs deleted file mode 100644 index 50866ca7..00000000 --- a/src/sys/syscall.rs +++ /dev/null @@ -1,91 +0,0 @@ -//! Indirect system call -//! -use libc::c_int; - -pub use self::arch::*; - -#[cfg(target_arch = "x86_64")] -mod arch { - use libc::c_long; - - pub type Syscall = c_long; - - pub static SYSPIVOTROOT: Syscall = 155; - pub static MEMFD_CREATE: Syscall = 319; -} - -#[cfg(target_arch = "x86")] -mod arch { - use libc::c_long; - - pub type Syscall = c_long; - - pub static SYSPIVOTROOT: Syscall = 217; - pub static MEMFD_CREATE: Syscall = 356; -} - -#[cfg(target_arch = "aarch64")] -mod arch { - use libc::c_long; - - pub type Syscall = c_long; - - pub static SYSPIVOTROOT: Syscall = 41; - pub static MEMFD_CREATE: Syscall = 279; -} - -#[cfg(target_arch = "arm")] -mod arch { - use libc::c_long; - - pub type Syscall = c_long; - - pub static SYSPIVOTROOT: Syscall = 218; - pub static MEMFD_CREATE: Syscall = 385; -} - -// Rust on mips uses the N32 ABI -#[cfg(target_arch = "mips")] -mod arch { - use libc::c_long; - - pub type Syscall = c_long; - - pub static SYSPIVOTROOT: Syscall = 216; - pub static MEMFD_CREATE: Syscall = 354; -} - -// Rust on mips64 uses the N64 ABI -#[cfg(target_arch = "mips64")] -mod arch { - use libc::c_long; - - pub type Syscall = c_long; - - pub static SYSPIVOTROOT: Syscall = 151; - pub static MEMFD_CREATE: Syscall = 314; -} - -#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))] -mod arch { - use libc::c_long; - - pub type Syscall = c_long; - - pub static SYSPIVOTROOT: Syscall = 203; - pub static MEMFD_CREATE: Syscall = 360; -} - -#[cfg(target_arch = "s390x")] -mod arch { - use libc::c_long; - - pub type Syscall = c_long; - - pub static SYSPIVOTROOT: Syscall = 217; - pub static MEMFD_CREATE: Syscall = 350; -} - -extern { - pub fn syscall(num: Syscall, ...) -> c_int; -} diff --git a/src/unistd.rs b/src/unistd.rs index af38cf2d..fad51272 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -16,7 +16,7 @@ use sys::stat::Mode; use std::fmt; #[cfg(any(target_os = "android", target_os = "linux"))] -pub use self::linux::*; +pub use self::pivot_root::*; #[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux", target_os = "openbsd"))] @@ -1647,8 +1647,8 @@ pub fn sysconf(var: SysconfVar) -> Result> { } #[cfg(any(target_os = "android", target_os = "linux"))] -mod linux { - use sys::syscall::{syscall, SYSPIVOTROOT}; +mod pivot_root { + use libc; use {Errno, Result, NixPath}; pub fn pivot_root( @@ -1656,7 +1656,7 @@ mod linux { let res = try!(try!(new_root.with_nix_path(|new_root| { put_old.with_nix_path(|put_old| { unsafe { - syscall(SYSPIVOTROOT, new_root.as_ptr(), put_old.as_ptr()) + libc::syscall(libc::SYS_pivot_root, new_root.as_ptr(), put_old.as_ptr()) } }) }))); -- cgit v1.2.3