Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make svc api more rusty #12

Open
roblabla opened this issue Mar 10, 2018 · 2 comments
Open

Make svc api more rusty #12

roblabla opened this issue Mar 10, 2018 · 2 comments

Comments

@roblabla
Copy link
Member

the current svcs are basically a copy paste from libt, and are very C-like. I would love to turn them into something closer to rust, and would probably be possible without too much trouble.

We coudl use naked functions and inline asm to recode them. This gives us additional flexibility if we want to make the API more rusty.

Related to #11

@roblabla
Copy link
Member Author

Moved SVC api to naked functions. API is still not very rusty though.

@roblabla
Copy link
Member Author

roblabla commented Mar 30, 2018

The new svc functions have a big problem: they don't mark the clobbers/input/output. This is UB, and is causing big problems in release mode. I had hoped that marking them "extern" would be enough, but alas, rust eagerly optimizes everything.

I have a new svc macro, I'm in the process of porting everything to it:

macro_rules! define_svcs {
    ($($(#[$meta:meta])* $name:ident ( $id:expr, ($($svc_name:tt($svc_id:tt)),*), ($($svc_in:tt)*), $($args:tt)* ) -> $return_type:ty;)*) => {
        $(
            $(#[$meta])*
            pub unsafe fn $name($($args)*) -> $return_type {
                let mut ret: $return_type = ::std::mem::uninitialized();
                asm!("svc $0" : $($svc_name(ret.$svc_id)),* : "i"($id), $($svc_in)* : : "volatile");
                ret
            }
        )*
    };
}

define_svc! {
    /// Sets the size of the heap. Equivalent to a brk syscall on unix.
    ///
    /// Note that you should almost never use this method! Use the system
    /// allocator instead, like Box, to allocate heap memory!
    /// @brief Sets the size of the heap
    ///
    /// @param outAddr Output for address of the heap
    /// @param size Size of the heap
    set_heap_size(0x01, ("={x0}"(0), "={x1}"(1)), ("{x1}"(size)), size: u32) -> (Result, *mut cty::c_void);

    /// Sets memory permissions. Takes the address of the region to reprotect,
    /// its size, and the new permission of that region.
    ///
    /// Address and size must be page-aligned, and execute bit is not allowed.
    set_memory_permission(0x02, (), ("x0"(addr), "x1"(size), "x2"(permission)), addr: *mut cty::c_void, size: u64, permission: u32) -> Result;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant