Skip to content
Permalink
Browse files

Porting mremap().

  • Loading branch information...
anp committed May 10, 2016
1 parent 669a250 commit deb822aa93586206ed3b33661d2bd0231dc2daac
Showing with 41 additions and 41 deletions.
  1. +1 −0 Cargo.toml
  2. +0 −33 musl/src/mman/mremap.c
  3. +4 −8 src/lib.rs
  4. +35 −0 src/mmap.rs
  5. +1 −0 src/platform/linux-x86_64/mman.rs
@@ -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

This file was deleted.

@@ -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;
@@ -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() {}
}
}*/
@@ -1,5 +1,7 @@
use core::isize;

use va_list::VaList;

use c_types::*;
use errno::{set_errno, EINVAL, ENOMEM};
use platform::mman::*;
@@ -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
@@ -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)
}
@@ -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.
You can’t perform that action at this time.