Implement shm_ functions and add MAP_FIXED

This commit is contained in:
Jeremy Soller
2019-01-13 09:31:04 -07:00
parent 5b779448ab
commit cea5101cba
3 changed files with 51 additions and 24 deletions
+4 -9
View File
@@ -1,11 +1,6 @@
use platform::types::*;
pub const PROT_READ: c_int = 0x1;
pub const PROT_WRITE: c_int = 0x2;
pub const PROT_EXEC: c_int = 0x4;
pub const PROT_NONE: c_int = 0x0;
pub const MAP_SHARED: c_int = 0x1;
pub const MAP_PRIVATE: c_int = 0x2;
pub const MAP_ANON: c_int = 0x20;
pub const MAP_ANONYMOUS: c_int = MAP_ANON;
pub const PROT_READ: c_int = 0x0001;
pub const PROT_WRITE: c_int = 0x0002;
pub const PROT_EXEC: c_int = 0x0004;
pub const PROT_NONE: c_int = 0x0000;
+43 -6
View File
@@ -1,3 +1,5 @@
use c_str::{CStr, CString};
use header::{fcntl, unistd};
use platform::types::*;
use platform::{Pal, Sys};
@@ -11,6 +13,13 @@ pub mod sys;
#[path = "redox.rs"]
pub mod sys;
pub const MAP_SHARED: c_int = 0x0001;
pub const MAP_PRIVATE: c_int = 0x0002;
pub const MAP_TYPE: c_int = 0x000F;
pub const MAP_FIXED: c_int = 0x0010;
pub const MAP_ANON: c_int = 0x0020;
pub const MAP_ANONYMOUS: c_int = MAP_ANON;
// #[no_mangle]
pub extern "C" fn mlock(addr: *const c_void, len: usize) -> c_int {
unimplemented!();
@@ -58,12 +67,40 @@ pub unsafe extern "C" fn munmap(addr: *mut c_void, len: size_t) -> c_int {
Sys::munmap(addr, len)
}
// #[no_mangle]
pub extern "C" fn shm_open(name: *const c_char, oflag: c_int, mode: mode_t) -> c_int {
unimplemented!();
#[cfg(target_os = "linux")]
static SHM_PATH: &'static [u8] = b"/dev/shm/";
#[cfg(target_os = "redox")]
static SHM_PATH: &'static [u8] = b"shm:";
unsafe fn shm_path(name: *const c_char) -> CString {
let name_c = CStr::from_ptr(name);
let mut path = SHM_PATH.to_vec();
let mut skip_slash = true;
for &b in name_c.to_bytes() {
if skip_slash {
if b == b'/' {
continue;
} else {
skip_slash = false;
}
}
path.push(b);
}
CString::from_vec_unchecked(path)
}
// #[no_mangle]
pub extern "C" fn shm_unlink(name: *const c_char) -> c_int {
unimplemented!();
#[no_mangle]
pub unsafe extern "C" fn shm_open(name: *const c_char, oflag: c_int, mode: mode_t) -> c_int {
let path = shm_path(name);
fcntl::sys_open(path.as_ptr(), oflag, mode)
}
#[no_mangle]
pub unsafe extern "C" fn shm_unlink(name: *const c_char) -> c_int {
let path = shm_path(name);
unistd::unlink(path.as_ptr())
}
+4 -9
View File
@@ -1,11 +1,6 @@
use platform::types::*;
pub const PROT_NONE: c_int = 0;
pub const PROT_EXEC: c_int = 1;
pub const PROT_WRITE: c_int = 2;
pub const PROT_READ: c_int = 4;
pub const MAP_SHARED: c_int = 1;
pub const MAP_PRIVATE: c_int = 2;
pub const MAP_ANON: c_int = 4;
pub const MAP_ANONYMOUS: c_int = MAP_ANON;
pub const PROT_NONE: c_int = 0x0000;
pub const PROT_EXEC: c_int = 0x0001;
pub const PROT_WRITE: c_int = 0x0002;
pub const PROT_READ: c_int = 0x0004;