aldostools / Mamba

Mamba is a payload for PS3 apps that adds support for ISO, netiso, plugins, PS3MAPI, etc. It's derived from Cobra.
GNU General Public License v3.0
35 stars 8 forks source link

PS3MAPI - Checking availability of a syscall twice #1

Open PHTNCx64 opened 3 years ago

PHTNCx64 commented 3 years ago

I'm not quite sure if this was done on purpose, or by accident, but I've noticed that in ps3mapi_core.c in the function int ps3mapi_check_syscall(int num) that MAMBA (and also Cobra) does check the availability for the specified syscall twice... I don't know what purpose it serves to do the same task twice, so my suggestion is changing it from:

int ps3mapi_check_syscall(int num)
{
    uint64_t sc_null = *(uint64_t *)MKA(syscall_table_symbol);
    if (*(uint64_t *)MKA(syscall_table_symbol + (8 * num)) != sc_null)
    {
        uint64_t syscall_not_impl = *(uint64_t *)sc_null;
        if ((*(uint64_t *)MKA(syscall_table_symbol + (8 * num))) != syscall_not_impl)
            return SUCCEEDED;
    }
    return ENOSYS;
}

to:

int ps3mapi_check_syscall(int num)
{
    uint64_t sc_null = *(uint64_t *)MKA(syscall_table_symbol);
    return *(uint64_t*)MKA(syscall_table_symbol + (8 * num)) != sc_null ? SUCCEEDED : ENOSYS;
}
aldostools commented 3 years ago

Thank you for your feedback. I thought the same when I checked the code. That double check was implemented by NzV (the developer that introduced PS3MAPI in Cobra/Mamba payload).

I agree with you that your code is more efficent. However, that double check is working and I don't want to break it in case there is some condition that NzV considered that we are not taking in count.

Anyway that code does not affect the performance. And the code overhead is minimal.

PHTNCx64 commented 3 years ago

While I do agree that the correction does not really affect performance, it makes the code look much cleaner than the original form. I'll try compiling Mamba with my correction and see how it affects the function. Since it's basic LV2 Peek Poke, I don't think there's gonna be a difference between my and his code. I'll also check if any other Mamba/Cobra function that makes usage of this check, is behaving differently than it should.

Have you tried contacting NzV and asked him about the double check of the function? I'd like to do it, but can't find any contact to him, he also hasn't been online since 5 years on PSX-Place.. :/

aldostools commented 3 years ago

No, I haven't contacted NzV. He is retired from PS3 scene. He also removed his repository from github long time ago.

If you have good results in your test, please report back here.

PHTNCx64 commented 3 years ago

I've tested this now and I haven't noticed any differences while checking through activated and deactivated syscalls on Rebug 4.84 D-REX Mamba (Cobra was deactivated). PRX Loader beeped once which indicates that everything executed and installed flawlessly. In my opinion, it's safe to change the code.

aldostools commented 3 years ago

Thank you for your feedback. I just implemented the change in the repository.