Skip to content
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

Use libc types for sched and syscall FFI #747

Merged
merged 2 commits into from
Aug 28, 2017
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
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