userspace/target/operating_system/linux/syscall/
mprotect.rs1use crate::target::arch::{Arch, traits::Callable};
2
3pub use super::mmap::{Prot, prot};
4
5hooking!(MPROTECT);
6
7#[inline(always)]
8pub fn mprotect(addr: *mut u8, len: usize, prot: i32) -> crate::Result {
9 let arch_result = Arch::syscall3(NUMBER, addr as usize, len, prot as usize);
10 handle_result(arch_result)
11}
12
13pub mod ok {
14
15 ample::result!( Ok; "MUnMap Ok"; usize; [
16 [0; OK; Default; usize; "Ok"; "All good"],
17 ]);
18
19 impl Ok {
20 pub fn from_no(no: usize) -> Self {
21 Ok::Default(no)
22 }
23 }
24}
25
26pub mod error {
27 ample::result!(Error; "MUnMap error"; usize; [
28 [1; ERROR; Default; usize; "Error"; "Something wicked this way comes"],
29 ]);
30
31 impl Error {
32 pub fn from_no(no: usize) -> Self {
33 Error::Default(no)
34 }
35 }
36}
37
38pub use error::Error;
39pub use ok::Ok;
40
41pub type Result = core::result::Result<Ok, Error>;
42
43pub fn handle_result(result: crate::Result) -> crate::Result {
44 match result {
46 crate::Result::Ok(crate::Ok::Target(crate::target::Ok::Arch(
47 crate::target::arch::Ok::X86_64Syscall(
48 crate::target::arch::syscall::Ok::X86_64Syscall3(
49 crate::target::arch::syscall::syscall3::Ok::Default(m),
50 ),
51 ),
52 ))) => core::result::Result::Ok(crate::Ok::Target(crate::target::Ok::Os(
53 crate::target::os::Ok::Syscall(crate::target::os::syscall::Ok::MProtect(
54 crate::target::os::syscall::mprotect::Ok::Default(m),
55 )),
56 ))),
57 _ => core::result::Result::Err(crate::Error::Target(crate::target::Error::Os(
58 crate::target::os::Error::Syscall(crate::target::os::syscall::Error::MProtect(
59 Error::Default(3),
60 )),
61 ))),
62 }
63}