瀏覽代碼

Add mlock and friends

Jeremy Soller 3 年之前
父節點
當前提交
f63d9cefad
共有 4 個文件被更改,包括 54 次插入10 次删除
  1. 10 10
      src/header/sys_mman/mod.rs
  2. 16 0
      src/platform/linux/mod.rs
  3. 8 0
      src/platform/pal/mod.rs
  4. 20 0
      src/platform/redox/mod.rs

+ 10 - 10
src/header/sys_mman/mod.rs

@@ -24,14 +24,14 @@ 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!();
+#[no_mangle]
+pub unsafe extern "C" fn mlock(addr: *const c_void, len: usize) -> c_int {
+    Sys::mlock(addr, len)
 }
 
-// #[no_mangle]
+#[no_mangle]
 pub extern "C" fn mlockall(flags: c_int) -> c_int {
-    unimplemented!();
+    Sys::mlockall(flags)
 }
 
 #[no_mangle]
@@ -56,14 +56,14 @@ pub unsafe extern "C" fn msync(addr: *mut c_void, len: size_t, flags: c_int) ->
     Sys::msync(addr, len, flags)
 }
 
-// #[no_mangle]
-pub extern "C" fn munlock(addr: *const c_void, len: usize) -> c_int {
-    unimplemented!();
+#[no_mangle]
+pub unsafe extern "C" fn munlock(addr: *const c_void, len: usize) -> c_int {
+    Sys::munlock(addr, len)
 }
 
-// #[no_mangle]
+#[no_mangle]
 pub extern "C" fn munlockall() -> c_int {
-    unimplemented!();
+    Sys::munlockall()
 }
 
 #[no_mangle]

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

@@ -304,6 +304,14 @@ impl Pal for Sys {
         e(unsafe { syscall!(MKNODAT, AT_FDCWD, path.as_ptr(), mode | S_IFIFO, 0) }) as c_int
     }
 
+    unsafe fn mlock(addr: *const c_void, len: usize) -> c_int {
+        e(syscall!(MLOCK, addr, len)) as c_int
+    }
+
+    fn mlockall(flags: c_int) -> c_int {
+        e(unsafe { syscall!(MLOCKALL, flags) }) as c_int
+    }
+
     unsafe fn mmap(
         addr: *mut c_void,
         len: usize,
@@ -323,6 +331,14 @@ impl Pal for Sys {
         e(syscall!(MSYNC, addr, len, flags)) as c_int
     }
 
+    unsafe fn munlock(addr: *const c_void, len: usize) -> c_int {
+        e(syscall!(MUNLOCK, addr, len)) as c_int
+    }
+
+    fn munlockall() -> c_int {
+        e(unsafe { syscall!(MUNLOCKALL) }) as c_int
+    }
+
     unsafe fn munmap(addr: *mut c_void, len: usize) -> c_int {
         e(syscall!(MUNMAP, addr, len)) as c_int
     }

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

@@ -114,6 +114,10 @@ pub trait Pal {
 
     fn mkfifo(path: &CStr, mode: mode_t) -> c_int;
 
+    unsafe fn mlock(addr: *const c_void, len: usize) -> c_int;
+
+    fn mlockall(flags: c_int) -> c_int;
+
     unsafe fn mmap(
         addr: *mut c_void,
         len: usize,
@@ -127,6 +131,10 @@ pub trait Pal {
 
     unsafe fn msync(addr: *mut c_void, len: usize, flags: c_int) -> c_int;
 
+    unsafe fn munlock(addr: *const c_void, len: usize) -> c_int;
+
+    fn munlockall() -> c_int;
+
     unsafe fn munmap(addr: *mut c_void, len: usize) -> c_int;
 
     fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int;

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

@@ -721,6 +721,16 @@ impl Pal for Sys {
         }
     }
 
+    unsafe fn mlock(addr: *const c_void, len: usize) -> c_int {
+        // Redox never swaps
+        0
+    }
+
+    fn mlockall(flags: c_int) -> c_int {
+        // Redox never swaps
+        0
+    }
+
     unsafe fn mmap(
         addr: *mut c_void,
         len: usize,
@@ -766,6 +776,16 @@ impl Pal for Sys {
         */
     }
 
+    unsafe fn munlock(addr: *const c_void, len: usize) -> c_int {
+        // Redox never swaps
+        0
+    }
+
+    fn munlockall() -> c_int {
+        // Redox never swaps
+        0
+    }
+
     unsafe fn munmap(addr: *mut c_void, len: usize) -> c_int {
         if e(syscall::funmap(addr as usize, len)) == !0 {
             return !0;