overdrivenpotato / rust-psp

Rust on PSP. Panic and allocation support. Access PSP system libraries.
Other
588 stars 31 forks source link

`sys::sceNetInetRecv` return type #176

Open lorenzofelletti opened 1 month ago

lorenzofelletti commented 1 month ago

sys::sceNetInetRecv return type is set to usize, as pspsdk sets it to size_t. However, the Linux manual for the recv functions sets its return type to ssize_t (isize in Rust), which actually makes more sense as it gives you a way to intercept an error from the returned value.

Do we know if the correct return type is indeed usize and not isize?

sajattack commented 1 month ago

There's no difference to a compiled binary between usize and isize afaik. So we don't have a way to know which is more correct. But the idea of error codes makes sense.

lorenzofelletti commented 1 month ago

Mmh ok. I never really did that stuff, so I'm not an expert on the matter, but I'm wondering then why there is a different between these two functions signatures:

#[psp(0xCDA85C99)]
    pub fn sceNetInetRecv(
        s: i32,
        buf: *mut c_void,
        len: usize,
        flags: i32,
    ) -> usize;

    #[psp(0xC91142E4, i6)]
    pub fn sceNetInetRecvfrom(
        s: i32,
        buf: *mut c_void,
        len: usize,
        flags: i32,
        from: *mut sockaddr,
        from_len: *mut socklen_t,
    ) -> i32;

Why does one return usize and the other one i32?

sajattack commented 1 month ago

Yeah ultimately I think you're right because sceNetInetRecv has the possibility to return an error code. I was just mentioning you can't tell from decompilation directly.