0.3.0: converge relibc to upstream 0.6.0 + Red Bear patches
This commit is contained in:
@@ -1,14 +1,21 @@
|
||||
sys_includes = ["stdint.h", "sys/types.h"]
|
||||
include_guard = "_SYS_MMAN_H"
|
||||
trailer = "#include <bits/sys/mman.h>"
|
||||
# POSIX header spec: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_mman.h.html
|
||||
#
|
||||
# Spec quotations relating to includes:
|
||||
# - "The <sys/mman.h> header shall define the mode_t, off_t, and size_t types as described in <sys/types.h>."
|
||||
# - "The <sys/mman.h> header shall define the following symbolic constants as described in <fcntl.h>"
|
||||
# - "Inclusion of the <sys/mman.h> header may make visible all symbols from the <fcntl.h> header."
|
||||
sys_includes = ["sys/types.h", "fcntl.h"]
|
||||
include_guard = "_RELIBC_SYS_MMAN_H"
|
||||
after_includes = """
|
||||
|
||||
#define MAP_FAILED ((void *) -1)
|
||||
"""
|
||||
language = "C"
|
||||
style = "Tag"
|
||||
no_includes = true
|
||||
no_includes = false
|
||||
cpp_compat = true
|
||||
|
||||
[defines]
|
||||
"target_os=linux" = "__linux__"
|
||||
"target_os=redox" = "__redox__"
|
||||
# make size_t actually size_t instead of uintptr_t (which would require stdint.h)
|
||||
usize_is_size_t = true
|
||||
|
||||
[enum]
|
||||
prefix_with_name = true
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::platform::types::*;
|
||||
use crate::platform::types::c_int;
|
||||
|
||||
pub const PROT_READ: c_int = 0x0001;
|
||||
pub const PROT_WRITE: c_int = 0x0002;
|
||||
@@ -7,3 +7,11 @@ pub const PROT_NONE: c_int = 0x0000;
|
||||
|
||||
pub const MAP_FIXED: c_int = 0x0010;
|
||||
pub const MAP_FIXED_NOREPLACE: c_int = 0x100000;
|
||||
pub const MAP_POPULATE: c_int = 0x008000;
|
||||
pub const MAP_HUGETLB: c_int = 0x40000;
|
||||
pub const MAP_NORESERVE: c_int = 0x4000;
|
||||
|
||||
pub const MADV_HUGEPAGE: c_int = 14;
|
||||
pub const MADV_NOHUGEPAGE: c_int = 15;
|
||||
pub const MADV_DONTDUMP: c_int = 16;
|
||||
pub const MADV_DODUMP: c_int = 17;
|
||||
|
||||
+116
-31
@@ -1,7 +1,15 @@
|
||||
//! `sys/mman.h` implementation.
|
||||
//!
|
||||
//! See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_mman.h.html>.
|
||||
|
||||
use crate::{
|
||||
c_str::{CStr, CString},
|
||||
error::{Errno, ResultExt},
|
||||
header::{fcntl, unistd},
|
||||
platform::{types::*, Pal, Sys},
|
||||
platform::{
|
||||
ERRNO, Pal, Sys,
|
||||
types::{c_char, c_int, c_void, mode_t, off_t, size_t},
|
||||
},
|
||||
};
|
||||
|
||||
pub use self::sys::*;
|
||||
@@ -14,27 +22,62 @@ pub mod sys;
|
||||
#[path = "redox.rs"]
|
||||
pub mod sys;
|
||||
|
||||
pub const MADV_NORMAL: c_int = 0;
|
||||
pub const MADV_RANDOM: c_int = 1;
|
||||
pub const MADV_SEQUENTIAL: c_int = 2;
|
||||
pub const MADV_WILLNEED: c_int = 3;
|
||||
pub const MADV_DONTNEED: c_int = 4;
|
||||
|
||||
pub const MAP_SHARED: c_int = 0x0001;
|
||||
pub const MAP_PRIVATE: c_int = 0x0002;
|
||||
pub const MAP_TYPE: c_int = 0x000F;
|
||||
pub const MAP_ANON: c_int = 0x0020;
|
||||
pub const MAP_ANONYMOUS: c_int = MAP_ANON;
|
||||
pub const MAP_STACK: c_int = 0x20000;
|
||||
/// cbindgen:ignore
|
||||
pub const MAP_FAILED: *mut c_void = usize::wrapping_neg(1) as *mut c_void;
|
||||
|
||||
pub const MREMAP_MAYMOVE: c_int = 1;
|
||||
|
||||
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!();
|
||||
pub const MCL_CURRENT: c_int = 1;
|
||||
pub const MCL_FUTURE: c_int = 2;
|
||||
|
||||
pub const POSIX_MADV_NORMAL: c_int = 0;
|
||||
pub const POSIX_MADV_RANDOM: c_int = 1;
|
||||
pub const POSIX_MADV_SEQUENTIAL: c_int = 2;
|
||||
pub const POSIX_MADV_WILLNEED: c_int = 3;
|
||||
pub const POSIX_MADV_WONTNEED: c_int = 4;
|
||||
|
||||
/// Non-POSIX, see <https://www.man7.org/linux/man-pages/man2/madvise.2.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn madvise(addr: *mut c_void, len: size_t, flags: c_int) -> c_int {
|
||||
unsafe { Sys::madvise(addr, len, flags) }
|
||||
.map(|()| 0)
|
||||
.or_minus_one_errno()
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
pub extern "C" fn mlockall(flags: c_int) -> c_int {
|
||||
unimplemented!();
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mlock.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn mlock(addr: *const c_void, len: size_t) -> c_int {
|
||||
unsafe { Sys::mlock(addr, len) }
|
||||
.map(|()| 0)
|
||||
.or_minus_one_errno()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mlockall.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn mlockall(flags: c_int) -> c_int {
|
||||
unsafe { Sys::mlockall(flags) }
|
||||
.map(|()| 0)
|
||||
.or_minus_one_errno()
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mmap.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn mmap(
|
||||
addr: *mut c_void,
|
||||
len: size_t,
|
||||
@@ -43,42 +86,82 @@ pub unsafe extern "C" fn mmap(
|
||||
fildes: c_int,
|
||||
off: off_t,
|
||||
) -> *mut c_void {
|
||||
Sys::mmap(addr, len, prot, flags, fildes, off)
|
||||
match unsafe { Sys::mmap(addr, len, prot, flags, fildes, off) } {
|
||||
Ok(ptr) => ptr,
|
||||
Err(Errno(errno)) => {
|
||||
ERRNO.set(errno);
|
||||
MAP_FAILED
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mprotect.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn mprotect(addr: *mut c_void, len: size_t, prot: c_int) -> c_int {
|
||||
Sys::mprotect(addr, len, prot)
|
||||
unsafe { Sys::mprotect(addr, len, prot) }
|
||||
.map(|()| 0)
|
||||
.or_minus_one_errno()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
/// Non-POSIX, see <https://www.man7.org/linux/man-pages/man2/mremap.2.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn mremap(
|
||||
old_address: *mut c_void,
|
||||
old_size: size_t,
|
||||
new_size: size_t,
|
||||
flags: c_int,
|
||||
mut __valist: ...
|
||||
) -> *mut c_void {
|
||||
let new_address = unsafe { __valist.next_arg::<*mut c_void>() };
|
||||
match unsafe { Sys::mremap(old_address, old_size, new_size, flags, new_address) } {
|
||||
Ok(ptr) => ptr,
|
||||
Err(Errno(errno)) => {
|
||||
ERRNO.set(errno);
|
||||
MAP_FAILED
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/msync.html>.
|
||||
#[unsafe(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)
|
||||
unsafe { Sys::msync(addr, len, flags) }
|
||||
.map(|()| 0)
|
||||
.or_minus_one_errno()
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
pub extern "C" fn munlock(addr: *const c_void, len: usize) -> c_int {
|
||||
unimplemented!();
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mlock.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn munlock(addr: *const c_void, len: size_t) -> c_int {
|
||||
unsafe { Sys::munlock(addr, len) }
|
||||
.map(|()| 0)
|
||||
.or_minus_one_errno()
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
pub extern "C" fn munlockall() -> c_int {
|
||||
unimplemented!();
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mlockall.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn munlockall() -> c_int {
|
||||
unsafe { Sys::munlockall() }
|
||||
.map(|()| 0)
|
||||
.or_minus_one_errno()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/munmap.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn munmap(addr: *mut c_void, len: size_t) -> c_int {
|
||||
Sys::munmap(addr, len)
|
||||
unsafe { Sys::munmap(addr, len) }
|
||||
.map(|()| 0)
|
||||
.or_minus_one_errno()
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
static SHM_PATH: &'static [u8] = b"/dev/shm/";
|
||||
static SHM_PATH: &[u8] = b"/dev/shm/";
|
||||
|
||||
#[cfg(target_os = "redox")]
|
||||
static SHM_PATH: &'static [u8] = b"shm:";
|
||||
static SHM_PATH: &[u8] = b"/scheme/shm/";
|
||||
|
||||
unsafe fn shm_path(name: *const c_char) -> CString {
|
||||
let name_c = CStr::from_ptr(name);
|
||||
let name_c = unsafe { CStr::from_ptr(name) };
|
||||
|
||||
let mut path = SHM_PATH.to_vec();
|
||||
|
||||
@@ -94,17 +177,19 @@ unsafe fn shm_path(name: *const c_char) -> CString {
|
||||
path.push(b);
|
||||
}
|
||||
|
||||
CString::from_vec_unchecked(path)
|
||||
unsafe { CString::from_vec_unchecked(path) }
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/shm_open.html>.
|
||||
#[unsafe(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)
|
||||
let path = unsafe { shm_path(name) };
|
||||
unsafe { fcntl::open(path.as_ptr(), oflag, mode) }
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/shm_unlink.html>.
|
||||
#[unsafe(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())
|
||||
let path = unsafe { shm_path(name) };
|
||||
unsafe { unistd::unlink(path.as_ptr()) }
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::platform::types::*;
|
||||
use crate::platform::types::c_int;
|
||||
|
||||
pub const PROT_NONE: c_int = 0x0000;
|
||||
pub const PROT_EXEC: c_int = 0x0001;
|
||||
@@ -7,3 +7,8 @@ pub const PROT_READ: c_int = 0x0004;
|
||||
|
||||
pub const MAP_FIXED: c_int = 0x0004;
|
||||
pub const MAP_FIXED_NOREPLACE: c_int = 0x000C;
|
||||
pub const MAP_POPULATE: c_int = 0x0001F;
|
||||
pub const MAP_HUGETLB: c_int = 0x2E;
|
||||
|
||||
pub const MADV_DONTDUMP: c_int = 5;
|
||||
pub const MADV_DODUMP: c_int = 6;
|
||||
|
||||
Reference in New Issue
Block a user