Skip to content

Commit

Permalink
Porting mremap().
Browse files Browse the repository at this point in the history
  • Loading branch information
anp committed May 10, 2016
1 parent 669a250 commit deb822a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 41 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ crate-type = ["staticlib", "dylib"]
lazy_static = { version = "0.2.1", features = ["spin_no_std"] }
rlibc = "1.0.0"
syscall = "0.2.1"
va_list = "0.0.3"

[profile.release]
debug = true
33 changes: 0 additions & 33 deletions musl/src/mman/mremap.c

This file was deleted.

12 changes: 4 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#![no_std]
#![feature(asm, lang_items, linkage)]
//#![needs_panic_runtime]

#![allow(non_camel_case_types)]

#[macro_use]
extern crate lazy_static;
extern crate syscall;
extern crate va_list;

#[macro_use]
pub mod syscall_mgt;
Expand Down Expand Up @@ -65,16 +67,10 @@ pub mod signal {
pub use platform::signal::*;
}

#[lang = "eh_personality"]
/*#[lang = "eh_personality"]
extern "C" fn eh_personality() {}
#[lang = "panic_fmt"]
fn panic_fmt() -> ! {
loop {}
}

#[cfg(test)]
mod test {
#[test]
fn it_works() {}
}
}*/
35 changes: 35 additions & 0 deletions src/mmap.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use core::isize;

use va_list::VaList;

use c_types::*;
use errno::{set_errno, EINVAL, ENOMEM};
use platform::mman::*;
Expand Down Expand Up @@ -37,6 +39,29 @@ pub unsafe extern "C" fn __mmap(start: *mut c_void,
syscall!(MMAP, start, len, prot, flags, fd, off) as *mut c_void
}

#[no_mangle]
pub unsafe extern "C" fn __mremap(old_address: *mut c_void,
old_len: size_t,
new_len: size_t,
flags: c_int,
mut args: VaList)
-> *mut c_void {

let mut new_address = 0 as *mut c_void;

if new_len >= isize::MAX as usize {
set_errno(ENOMEM);
return MAP_FAILED;
}

if flags & MREMAP_FIXED != 0 {
__vm_wait();
new_address = args.get::<usize>() as *mut c_void;
}

syscall!(MREMAP, old_address, old_len, new_len, flags, new_address) as *mut c_void
}

#[no_mangle]
pub unsafe extern "C" fn madvise(address: *mut c_void, len: usize, advice: c_int) -> c_int {
syscall!(MADVISE, address, len, advice) as c_int
Expand Down Expand Up @@ -86,3 +111,13 @@ pub unsafe extern "C" fn mmap64(start: *mut c_void,
-> *mut c_void {
__mmap(start, len, prot, flags, fd, off)
}

#[no_mangle]
pub unsafe extern "C" fn mremap(old_address: *mut c_void,
old_len: size_t,
new_len: size_t,
flags: c_int,
args: VaList)
-> *mut c_void {
__mremap(old_address, old_len, new_len, flags, args)
}
1 change: 1 addition & 0 deletions src/platform/linux-x86_64/mman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ pub const PAGE_SIZE: off_t = 4096;
pub const MAP_FAILED: *mut c_void = 0xffffffffffffffff as *mut c_void;

pub const MAP_FIXED: c_int = 0x10;
pub const MREMAP_FIXED: c_int = 2;

0 comments on commit deb822a

Please sign in to comment.