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
View
@@ -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
View
@@ -1,33 +0,0 @@
-#define _GNU_SOURCE
-#include <unistd.h>
-#include <sys/mman.h>
-#include <errno.h>
-#include <stdint.h>
-#include <stdarg.h>
-#include "syscall.h"
-#include "libc.h"
-
-static void dummy(void) { }
-weak_alias(dummy, __vm_wait);
-
-void *__mremap(void *old_addr, size_t old_len, size_t new_len, int flags, ...)
-{
- va_list ap;
- void *new_addr = 0;
-
- if (new_len >= PTRDIFF_MAX) {
- errno = ENOMEM;
- return MAP_FAILED;
- }
-
- if (flags & MREMAP_FIXED) {
- __vm_wait();
- va_start(ap, flags);
- new_addr = va_arg(ap, void *);
- va_end(ap);
- }
-
- return (void *)syscall(SYS_mremap, old_addr, old_len, new_len, flags, new_addr);
-}
-
-weak_alias(__mremap, mremap);
View
@@ -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() {}
-}
+}*/
View
@@ -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.