userspace/target/operating_system/linux/syscall/
lseek.rs

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