Skip to content

Commit

Permalink
Merge #747
Browse files Browse the repository at this point in the history
747: Use libc types for sched and syscall FFI r=Susurrus a=Susurrus
  • Loading branch information
bors[bot] committed Aug 28, 2017
2 parents 28c5b4a + d322aa9 commit 202f30e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 121 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 2 additions & 21 deletions src/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/sys/memfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ bitflags!(
);

pub fn memfd_create(name: &CStr, flags: MemFdCreateFlag) -> Result<RawFd> {
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)
}
3 changes: 0 additions & 3 deletions src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
91 changes: 0 additions & 91 deletions src/sys/syscall.rs

This file was deleted.

8 changes: 4 additions & 4 deletions src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down Expand Up @@ -1647,16 +1647,16 @@ pub fn sysconf(var: SysconfVar) -> Result<Option<c_long>> {
}

#[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<P1: ?Sized + NixPath, P2: ?Sized + NixPath>(
new_root: &P1, put_old: &P2) -> Result<()> {
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())
}
})
})));
Expand Down

0 comments on commit 202f30e

Please sign in to comment.