Skip to content

Commit 202f30e

Browse files
committed
Merge #747
747: Use libc types for sched and syscall FFI r=Susurrus a=Susurrus
2 parents 28c5b4a + d322aa9 commit 202f30e

File tree

6 files changed

+14
-121
lines changed

6 files changed

+14
-121
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
5252
- Fix compilation and tests for OpenBSD targets
5353
([#688](https://github.com/nix-rust/nix/pull/688))
5454

55+
# Removed
56+
- The syscall module has been removed. This only exposed enough functionality for
57+
`memfd_create()` and `pivot_root()`, which are still exposed as separate functions.
58+
([#747](https://github.com/nix-rust/nix/pull/747))
59+
5560
## [0.9.0] 2017-07-23
5661

5762
### Added

src/sched.rs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,6 @@ impl CpuSet {
7373
}
7474
}
7575

76-
mod ffi {
77-
use libc::{c_void, c_int};
78-
79-
pub type CloneCb = extern "C" fn(data: *const super::CloneCb) -> c_int;
80-
81-
// We cannot give a proper #[repr(C)] to super::CloneCb
82-
#[allow(improper_ctypes)]
83-
extern "C" {
84-
// create a child process
85-
// doc: http://man7.org/linux/man-pages/man2/clone.2.html
86-
pub fn clone(cb: *const CloneCb,
87-
child_stack: *mut c_void,
88-
flags: c_int,
89-
arg: *mut super::CloneCb,
90-
...)
91-
-> c_int;
92-
}
93-
}
94-
9576
pub fn sched_setaffinity(pid: Pid, cpuset: &CpuSet) -> Result<()> {
9677
let res = unsafe {
9778
libc::sched_setaffinity(pid.into(),
@@ -116,10 +97,10 @@ pub fn clone(mut cb: CloneCb,
11697
let combined = flags.bits() | signal.unwrap_or(0);
11798
let ptr = stack.as_mut_ptr().offset(stack.len() as isize);
11899
let ptr_aligned = ptr.offset((ptr as usize % 16) as isize * -1);
119-
ffi::clone(mem::transmute(callback as extern "C" fn(*mut Box<::std::ops::FnMut() -> isize>) -> i32),
100+
libc::clone(mem::transmute(callback as extern "C" fn(*mut Box<::std::ops::FnMut() -> isize>) -> i32),
120101
ptr_aligned as *mut c_void,
121102
combined,
122-
&mut cb)
103+
&mut cb as *mut _ as *mut c_void)
123104
};
124105

125106
Errno::result(res).map(Pid::from_raw)

src/sys/memfd.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ bitflags!(
1111
);
1212

1313
pub fn memfd_create(name: &CStr, flags: MemFdCreateFlag) -> Result<RawFd> {
14-
use sys::syscall::{syscall, MEMFD_CREATE};
15-
let res = unsafe { syscall(MEMFD_CREATE, name.as_ptr(), flags.bits()) };
14+
let res = unsafe {
15+
libc::syscall(libc::SYS_memfd_create, name.as_ptr(), flags.bits())
16+
};
1617

1718
Errno::result(res).map(|r| r as RawFd)
1819
}

src/sys/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ pub mod socket;
3131

3232
pub mod stat;
3333

34-
#[cfg(any(target_os = "linux", target_os = "android"))]
35-
pub mod syscall;
36-
3734
#[cfg(any(target_os = "linux"))]
3835
pub mod reboot;
3936

src/sys/syscall.rs

Lines changed: 0 additions & 91 deletions
This file was deleted.

src/unistd.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use sys::stat::Mode;
1616
use std::fmt;
1717

1818
#[cfg(any(target_os = "android", target_os = "linux"))]
19-
pub use self::linux::*;
19+
pub use self::pivot_root::*;
2020

2121
#[cfg(any(target_os = "android", target_os = "freebsd",
2222
target_os = "linux", target_os = "openbsd"))]
@@ -1647,16 +1647,16 @@ pub fn sysconf(var: SysconfVar) -> Result<Option<c_long>> {
16471647
}
16481648

16491649
#[cfg(any(target_os = "android", target_os = "linux"))]
1650-
mod linux {
1651-
use sys::syscall::{syscall, SYSPIVOTROOT};
1650+
mod pivot_root {
1651+
use libc;
16521652
use {Errno, Result, NixPath};
16531653

16541654
pub fn pivot_root<P1: ?Sized + NixPath, P2: ?Sized + NixPath>(
16551655
new_root: &P1, put_old: &P2) -> Result<()> {
16561656
let res = try!(try!(new_root.with_nix_path(|new_root| {
16571657
put_old.with_nix_path(|put_old| {
16581658
unsafe {
1659-
syscall(SYSPIVOTROOT, new_root.as_ptr(), put_old.as_ptr())
1659+
libc::syscall(libc::SYS_pivot_root, new_root.as_ptr(), put_old.as_ptr())
16601660
}
16611661
})
16621662
})));

0 commit comments

Comments
 (0)