Add mprotect
This commit is contained in:
10
Cargo.lock
generated
10
Cargo.lock
generated
@@ -65,7 +65,7 @@ dependencies = [
|
||||
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -178,7 +178,7 @@ dependencies = [
|
||||
"goblin 0.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"linked_list_allocator 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"raw-cpuid 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"redox_syscall 0.1.49",
|
||||
"redox_syscall 0.1.50",
|
||||
"slab_allocator 0.3.1",
|
||||
"spin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"x86 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -279,7 +279,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.1.49"
|
||||
version = "0.1.50"
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
@@ -358,7 +358,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.33"
|
||||
version = "1.0.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -526,7 +526,7 @@ dependencies = [
|
||||
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||
"checksum serde 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)" = "157e12af46859e968da75dea9845530e13d03bcab2009a41b9b7bb3cf4eb3ec2"
|
||||
"checksum serde_derive 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)" = "9469829702497daf2daf3c190e130c3fa72f719920f73c86160d43e8f8d76951"
|
||||
"checksum serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)" = "c37ccd6be3ed1fdf419ee848f7c758eb31b054d7cd3ae3600e3bae0adf569811"
|
||||
"checksum serde_json 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)" = "bdf540260cfee6da923831f4776ddc495ada940c30117977c70f1313a6130545"
|
||||
"checksum spin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ceac490aa12c567115b40b7b7fceca03a6c9d53d5defea066123debc83c5dc1f"
|
||||
"checksum syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)" = "9545a6a093a3f0bd59adb472700acc08cad3776f860f16a897dfce8c88721cbc"
|
||||
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
|
||||
|
||||
@@ -106,6 +106,7 @@ pub fn syscall(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, bp: u
|
||||
SYS_GETGID => getgid(),
|
||||
SYS_GETNS => getns(),
|
||||
SYS_GETUID => getuid(),
|
||||
SYS_MPROTECT => mprotect(b, c, d),
|
||||
SYS_MKNS => mkns(validate_slice(b as *const [usize; 2], c)?),
|
||||
SYS_SETPGID => setpgid(ContextId::from(b), ContextId::from(c)),
|
||||
SYS_SETREUID => setreuid(b as u32, c as u32),
|
||||
|
||||
@@ -9,6 +9,7 @@ use spin::Mutex;
|
||||
use memory::allocate_frames;
|
||||
use paging::{ActivePageTable, InactivePageTable, Page, VirtualAddress};
|
||||
use paging::entry::EntryFlags;
|
||||
use paging::mapper::MapperFlushAll;
|
||||
use paging::temporary_page::TemporaryPage;
|
||||
use start::usermode;
|
||||
use interrupt;
|
||||
@@ -22,7 +23,9 @@ use scheme::FileHandle;
|
||||
use syscall;
|
||||
use syscall::data::{SigAction, Stat};
|
||||
use syscall::error::*;
|
||||
use syscall::flag::{CLONE_VFORK, CLONE_VM, CLONE_FS, CLONE_FILES, CLONE_SIGHAND, SIG_DFL, SIGCONT, SIGTERM, WCONTINUED, WNOHANG, WUNTRACED, wifcontinued, wifstopped};
|
||||
use syscall::flag::{CLONE_VFORK, CLONE_VM, CLONE_FS, CLONE_FILES, CLONE_SIGHAND,
|
||||
PROT_EXEC, PROT_READ, PROT_WRITE, SIG_DFL, SIGCONT, SIGTERM,
|
||||
WCONTINUED, WNOHANG, WUNTRACED, wifcontinued, wifstopped};
|
||||
use syscall::validate::{validate_slice, validate_slice_mut};
|
||||
|
||||
pub fn brk(address: usize) -> Result<usize> {
|
||||
@@ -1127,6 +1130,50 @@ pub fn kill(pid: ContextId, sig: usize) -> Result<usize> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mprotect(address: usize, size: usize, flags: usize) -> Result<usize> {
|
||||
println!("mprotect {:#X}, {}, {:#X}", address, size, flags);
|
||||
|
||||
let end_offset = size.checked_sub(1).ok_or(Error::new(EFAULT))?;
|
||||
let end_address = address.checked_add(end_offset).ok_or(Error::new(EFAULT))?;
|
||||
|
||||
let mut active_table = unsafe { ActivePageTable::new() };
|
||||
|
||||
let mut flush_all = MapperFlushAll::new();
|
||||
|
||||
let start_page = Page::containing_address(VirtualAddress::new(address));
|
||||
let end_page = Page::containing_address(VirtualAddress::new(end_address));
|
||||
for page in Page::range_inclusive(start_page, end_page) {
|
||||
if let Some(mut page_flags) = active_table.translate_page_flags(page) {
|
||||
if flags & PROT_EXEC > 0 {
|
||||
page_flags.remove(EntryFlags::NO_EXECUTE);
|
||||
} else {
|
||||
page_flags.insert(EntryFlags::NO_EXECUTE);
|
||||
}
|
||||
|
||||
if flags & PROT_WRITE > 0 {
|
||||
//TODO: Not allowing gain of write privileges
|
||||
} else {
|
||||
page_flags.remove(EntryFlags::WRITABLE);
|
||||
}
|
||||
|
||||
if flags & PROT_READ > 0 {
|
||||
//TODO: No flags for readable pages
|
||||
} else {
|
||||
//TODO: No flags for readable pages
|
||||
}
|
||||
|
||||
let flush = active_table.remap(page, page_flags);
|
||||
flush_all.consume(flush);
|
||||
} else {
|
||||
return Err(Error::new(EFAULT));
|
||||
}
|
||||
}
|
||||
|
||||
flush_all.flush(&mut active_table);
|
||||
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
pub fn setpgid(pid: ContextId, pgid: ContextId) -> Result<usize> {
|
||||
let contexts = context::contexts();
|
||||
|
||||
|
||||
2
syscall
2
syscall
Submodule syscall updated: 6909fb1c32...9a3734c41a
Reference in New Issue
Block a user