Просмотр исходного кода

Add msync function and stub for Redox

Jeremy Soller 5 лет назад
Родитель
Сommit
2ac349d2d2
4 измененных файлов с 26 добавлено и 4 удалено
  1. 8 4
      src/header/sys_mman/mod.rs
  2. 4 0
      src/platform/linux/mod.rs
  3. 2 0
      src/platform/pal/mod.rs
  4. 12 0
      src/platform/redox/mod.rs

+ 8 - 4
src/header/sys_mman/mod.rs

@@ -21,6 +21,10 @@ pub const MAP_FIXED: c_int = 0x0010;
 pub const MAP_ANON: c_int = 0x0020;
 pub const MAP_ANONYMOUS: c_int = MAP_ANON;
 
+pub const MS_ASYNC: c_int = 0x0001;
+pub const MS_INVALIDATE: c_int = 0x0002;
+pub const MS_SYNC: c_int = 0x0004;
+
 // #[no_mangle]
 pub extern "C" fn mlock(addr: *const c_void, len: usize) -> c_int {
     unimplemented!();
@@ -44,13 +48,13 @@ pub unsafe extern "C" fn mmap(
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn mprotect(addr: *mut c_void, len: usize, prot: c_int) -> c_int {
+pub unsafe extern "C" fn mprotect(addr: *mut c_void, len: size_t, prot: c_int) -> c_int {
     Sys::mprotect(addr, len, prot)
 }
 
-// #[no_mangle]
-pub extern "C" fn msync(addr: *mut c_void, len: usize, flags: c_int) -> c_int {
-    unimplemented!();
+#[no_mangle]
+pub unsafe extern "C" fn msync(addr: *mut c_void, len: size_t, flags: c_int) -> c_int {
+    Sys::msync(addr, len, flags)
 }
 
 // #[no_mangle]

+ 4 - 0
src/platform/linux/mod.rs

@@ -310,6 +310,10 @@ impl Pal for Sys {
         e(syscall!(MPROTECT, addr, len, prot)) as c_int
     }
 
+    unsafe fn msync(addr: *mut c_void, len: usize, flags: c_int) -> c_int {
+        e(syscall!(MSYNC, addr, len, flags)) as c_int
+    }
+
     unsafe fn munmap(addr: *mut c_void, len: usize) -> c_int {
         e(syscall!(MUNMAP, addr, len)) as c_int
     }

+ 2 - 0
src/platform/pal/mod.rs

@@ -118,6 +118,8 @@ pub trait Pal {
 
     unsafe fn mprotect(addr: *mut c_void, len: usize, prot: c_int) -> c_int;
 
+    unsafe fn msync(addr: *mut c_void, len: usize, flags: c_int) -> c_int;
+
     unsafe fn munmap(addr: *mut c_void, len: usize) -> c_int;
 
     fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int;

+ 12 - 0
src/platform/redox/mod.rs

@@ -675,6 +675,18 @@ impl Pal for Sys {
         )) as c_int
     }
 
+    unsafe fn msync(addr: *mut c_void, len: usize, flags: c_int) -> c_int {
+        eprintln!("msync {:p} {:x} {:x}", addr, len, flags);
+        e(Err(syscall::Error::new(syscall::ENOSYS))) as c_int
+        /* TODO
+        e(syscall::msync(
+            addr as usize,
+            len,
+            flags
+        )) as c_int
+        */
+    }
+
     unsafe fn munmap(addr: *mut c_void, _len: usize) -> c_int {
         if e(syscall::funmap(addr as usize)) == !0 {
             return !0;