Homebrew svcReplyAndReceive Invalid Handle?

gudenau

Largely ignored
OP
Member
Joined
Jul 7, 2010
Messages
3,882
Trophies
2
Location
/dev/random
Website
www.gudenau.net
XP
5,312
Country
United States
I am attempting to create a module for the 3DS, I am using the custom loader as a very basic framework and stripping almost all of the code out and attempting to just get a command to return a version number. In the module svcReplyAndReceive is returning 0xD8E007F7 when the userland program calls srvGetServiceHandle.

Userland method:
Code:
Result gudModuleInit(void){
    Result ret;
 
    if(AtomicPostIncrement(&gudModuleRefCount)){
        return 0;
    }
 
    ret = srvGetServiceHandle(&gudModuleHandle, "gud:mod");
    if(R_FAILED(ret)){
        AtomicDecrement(&gudModuleRefCount);
    }
 
    return ret;
}

Module code:
Code:
int main(){
    Handle *notificationHandle = &handles[0];
    Handle *serviceHandle = &handles[1];
 
    if(R_FAILED(srvSysRegisterService(serviceHandle, "gud:mod", MAX_SESSIONS))){
        SETR10();
        svcBreak(USERBREAK_ASSERT);
    }
 
    if(R_FAILED(srvSysEnableNotification(notificationHandle))){
        SETR10();
        svcBreak(USERBREAK_ASSERT);
    }
 
    activeHandles = 2;
    s32 index = 1;
    int terminateRequest = 0;
    Handle replyTarget = 0;
    u32* commandBuffer;
    Result result;
    int i;
    Handle handle;
 
    do{
        if(replyTarget == 0){
            commandBuffer = getThreadCommandBuffer();
            commandBuffer[0] = 0xFFFF0000;
        }
    
        result = svcReplyAndReceive(&index, handles, activeHandles, replyTarget);
    
        if(R_FAILED(result)){
            // Check if any handles have been closed
            if(result == (int)0xC920181A){
                if(index == -1){
                    for(i = 2; i < MAX_SESSIONS + 2; i++){
                        if(handles[i] == replyTarget){
                            index = i;
                            break;
                        }
                    }
                }
                svcCloseHandle(handles[index]);
                handles[index] = handles[activeHandles - 1];
                activeHandles--;
                replyTarget = 0;
            }else{
                __asm__ volatile(
                    "MOV R10, %[marker]; PUSH {r10};"
                    "MOV R10, %[index]; PUSH {r10};"
                    "MOV R10, %[handles]; PUSH {r10};"
                    "MOV R10, %[handleCount]; PUSH {r10};"
                    "MOV R10, %[reply]; PUSH {r10};"
                    "MOV R10, %[line]; PUSH {r10};"
                    "MOV R10, %[res]; PUSH {r10};"
                    "MOV R10, %[level]; PUSH {r10};"
                    "MOV R10, %[summary]; PUSH {r10};"
                    "MOV R10, %[module]; PUSH {r10};"
                    "MOV R10, %[description]; PUSH {r10};"
                    ::
                    [marker] "r" (3735929054),
                    [index] "r" ((u32)index),
                    [handles] "r" ((u32)handles),
                    [handleCount] "r" (activeHandles),
                    [reply] "r" (replyTarget),
                    [line] "r" (__LINE__),
                    [res] "r" (result),
                    [level] "r" (R_LEVEL(result)),
                    [summary] "r" (R_SUMMARY(result)),
                    [module] "r" (R_MODULE(result)),
                    [description] "r" (R_DESCRIPTION(result))
                
                );
                svcBreak(USERBREAK_ASSERT);
            }
        }else{
            // Process responses
            replyTarget = 0;
            switch(index){
                case 0:{ // Notification
                    if(R_FAILED(shouldTerminate(&terminateRequest))){
                        SETR10();
                        svcBreak(USERBREAK_ASSERT);
                    }
                    break;
                }
            
                case 1:{ // New session
                    if(R_FAILED(svcAcceptSession(&handle, *serviceHandle))){
                        SETR10();
                        svcBreak(USERBREAK_ASSERT);
                    }
                    if(activeHandles < MAX_SESSIONS + 2){
                        handles[activeHandles] = handle;
                        activeHandles++;
                    }else{
                        svcCloseHandle(handle);
                    }
                }
            
                default:{ // Session
                    handleCommands();
                    replyTarget = handles[index];
                    break;
                }
            }
        }
    }while(!terminateRequest || activeHandles != 2);
 
    srvSysUnregisterService("gud:mod");
    svcCloseHandle(*serviceHandle);
    svcCloseHandle(*notificationHandle);
 
    return 0;
}

There is also an issue with the banner, the banner image does not render on the top screen. This is not a huge issue, but I am not sure what I messed up with that either.

Here is the entire project directory.


Edit:
I saw the pointer errors and fixed them in the module, the archive does not reflect these changes.
 
Last edited by gudenau,

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • BakerMan @ BakerMan:
    @LeoTCK is your partner the sascrotch or smth?
  • Xdqwerty @ Xdqwerty:
    Good morning
  • Xdqwerty @ Xdqwerty:
    Out of nowhere I got several scars on my forearm and part of my arm and it really itches.
  • AdRoz78 @ AdRoz78:
    Hey, I bought a modchip today and it says "New 2040plus" in the top left corner. Is this a legit chip or was I scammed?
  • Veho @ Veho:
    @AdRoz78 start a thread and post a photo of the chip.
    +2
  • Xdqwerty @ Xdqwerty:
    Yawn
  • S @ salazarcosplay:
    and good morning everyone
    +1
  • K3Nv2 @ K3Nv2:
    @BakerMan, his partner is Luke
  • Sicklyboy @ Sicklyboy:
    Sup nerds
    +1
  • Flame @ Flame:
    oh hi, Sickly
  • K3Nv2 @ K3Nv2:
    Oh hi flame
  • S @ salazarcosplay:
    @K3Nv2 what was your ps4 situation
  • S @ salazarcosplay:
    did you always have a ps4 you never updated
  • S @ salazarcosplay:
    or were you able to get new ps4 tracking it \
    as soon as the hack was announced
  • S @ salazarcosplay:
    or did you have to find a used one with the lower firm ware that was not updated
  • K3Nv2 @ K3Nv2:
    I got this ps4 at launch and never updated since 9.0
  • K3Nv2 @ K3Nv2:
    You got a good chance of buying a used one and asking the seller how often they used or even ask for a Pic of fw and telling them not to update
  • RedColoredStars @ RedColoredStars:
    Speaking of PLaystation. I see Evilnat put out a beta for PS3 CFW 4.91.2 on the 22nd.
  • K3Nv2 @ K3Nv2:
    Don't really see the point in updating it tbh
  • BigOnYa @ BigOnYa:
    Yea you right, I thought about updating my PS3 CFW to 4.91, but why really, everything plays fine now. I guess for people that have already updated past 4.9 it would be helpful.
  • K3Nv2 @ K3Nv2:
    Idk if online servers are still active that would be my only thought
    +1
  • BigOnYa @ BigOnYa:
    Thats true, personally I don't play it online at all, in fact, I deleted all wifi details on it once I installed CFW, so it won't connect and auto-update itself
  • BigOnYa @ BigOnYa:
    I play most games that are on both PS3/360 strickly on the 360, but PS3 exclusives are really only games I play on the PS3 (You know me, I'm more of a Xbox junkie)
    BigOnYa @ BigOnYa: I play most games that are on both PS3/360 strickly on the 360, but PS3 exclusives are really...