Merge branch 'libredox' into 'master'

Switch almost fully to libredox.

See merge request redox-os/redoxfs!71
This commit is contained in:
Jeremy Soller
2024-03-18 20:37:13 +00:00
5 changed files with 53 additions and 43 deletions
Generated
+13 -1
View File
@@ -213,6 +213,17 @@ dependencies = [
"redox_syscall 0.4.1",
]
[[package]]
name = "libredox"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
dependencies = [
"bitflags 2.4.2",
"libc",
"redox_syscall 0.5.0",
]
[[package]]
name = "log"
version = "0.4.21"
@@ -324,6 +335,7 @@ dependencies = [
"fuser",
"getrandom",
"libc",
"libredox 0.1.3",
"log",
"range-tree",
"redox-path",
@@ -409,7 +421,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4648c7def6f2043b2568617b9f9b75eae88ca185dbc1f1fda30e95a85d49d7d"
dependencies = [
"libc",
"libredox",
"libredox 0.0.2",
"numtoa",
"redox_termios",
]
+1
View File
@@ -44,6 +44,7 @@ seahash = { version = "4.1.0", default-features = false }
termion = { version = "2", optional = true }
uuid = { version = "1.4", default-features = false }
redox-path = "0.3.0"
libredox = "0.1.3"
# https://github.com/rexlunae/simple-endian-rs/pull/5
[dependencies.redox_simple_endian]
+13 -16
View File
@@ -69,11 +69,12 @@ fn bootloader_password() -> Option<Vec<u8>> {
#[cfg(target_os = "redox")]
fn capability_mode() {
syscall::setrens(0, 0).expect("redoxfs: failed to enter null namespace");
libredox::call::setrens(0, 0).expect("redoxfs: failed to enter null namespace");
}
#[cfg(target_os = "redox")]
fn bootloader_password() -> Option<Vec<u8>> {
use libredox::call::MmapArgs;
use syscall::MapFlags;
let addr_env = env::var_os("REDOXFS_PASSWORD_ADDR")?;
@@ -95,27 +96,23 @@ fn bootloader_password() -> Option<Vec<u8>> {
unsafe {
let aligned_size = size.next_multiple_of(syscall::PAGE_SIZE);
let fd = syscall::open("memory:physical", syscall::O_CLOEXEC)
let fd = libredox::Fd::open("memory:physical", libredox::flag::O_CLOEXEC, 0)
.expect("failed to open physical memory file");
let password_map = syscall::fmap(
fd,
&syscall::Map {
offset: addr,
size: aligned_size,
flags: MapFlags::PROT_READ | MapFlags::MAP_SHARED,
address: 0, // ignored
},
)
.expect("failed to map REDOXFS_PASSWORD");
let _ = syscall::close(fd);
let password_map = libredox::call::mmap(MmapArgs {
addr: core::ptr::null_mut(),
length: aligned_size,
prot: libredox::flag::PROT_READ,
flags: libredox::flag::MAP_SHARED,
fd: fd.raw(),
offset: addr as u64,
}).expect("failed to map REDOXFS_PASSWORD").cast::<u8>();
for i in 0..size {
password.push(*((password_map + i) as *const u8));
password.push(password_map.add(i).read());
}
let _ = syscall::funmap(password_map, aligned_size);
let _ = libredox::call::munmap(password_map.cast(), aligned_size);
}
Some(password)
}
+13 -13
View File
@@ -3,6 +3,7 @@ use std::slice;
use std::time::{SystemTime, UNIX_EPOCH};
use alloc::collections::BTreeMap;
use libredox::call::MmapArgs;
use range_tree::RangeTree;
use syscall::data::{Map, Stat, TimeSpec};
@@ -293,7 +294,7 @@ impl Fmap {
{
Ok(ok) => ok,
Err(err) => {
let _ = syscall::funmap(address as usize, aligned_size);
let _ = libredox::call::munmap(address.cast(), aligned_size);
return Err(err);
}
};
@@ -487,19 +488,18 @@ impl<D: Disk> Resource<D> for FileResource {
if new_size > fmap_info.size {
fmap_info.base = if fmap_info.base.is_null() {
unsafe {
syscall::fmap(
!0,
&Map {
size: new_size,
// PRIVATE/SHARED doesn't matter once the pages are passed in the fmap
// handler.
flags: MapFlags::PROT_READ
| MapFlags::PROT_WRITE
| MapFlags::MAP_PRIVATE,
libredox::call::mmap(MmapArgs {
length: new_size,
// PRIVATE/SHARED doesn't matter once the pages are passed in the fmap
// handler.
prot: libredox::flag::PROT_READ
| libredox::flag::PROT_WRITE,
flags: libredox::flag::MAP_PRIVATE,
offset: 0,
address: 0,
},
offset: 0,
fd: !0,
addr: core::ptr::null_mut(),
}
)? as *mut u8
}
} else {
+13 -13
View File
@@ -84,30 +84,30 @@ fn mmap() {
let path = dbg!(path.join("test"));
let mmap_inner = |write: bool| {
let fd = dbg!(syscall::open(
let fd = dbg!(libredox::call::open(
path.to_str().unwrap(),
syscall::O_CREAT | syscall::O_RDWR | syscall::O_CLOEXEC
libredox::flag::O_CREAT | libredox::flag::O_RDWR | libredox::flag::O_CLOEXEC,
0,
))
.unwrap();
let map = unsafe {
slice::from_raw_parts_mut(
dbg!(syscall::fmap(
dbg!(libredox::call::mmap(libredox::call::MmapArgs {
fd,
&syscall::Map {
offset: 0,
size: 128,
flags: syscall::PROT_READ | syscall::PROT_WRITE,
address: 0,
}
))
offset: 0,
length: 128,
prot: libredox::flag::PROT_READ | libredox::flag::PROT_WRITE,
flags: libredox::flag::MAP_SHARED,
addr: core::ptr::null_mut(),
}))
.unwrap() as *mut u8,
128,
)
};
// Maps should be available after closing
assert_eq!(dbg!(syscall::close(fd)), Ok(0));
assert_eq!(dbg!(libredox::call::close(fd)), Ok(()));
for i in 0..128 {
if write {
@@ -119,8 +119,8 @@ fn mmap() {
//TODO: add msync
unsafe {
assert_eq!(
dbg!(syscall::funmap(map.as_mut_ptr() as usize, map.len())),
Ok(0)
dbg!(libredox::call::munmap(map.as_mut_ptr().cast(), map.len())),
Ok(())
);
}
};