Ejemplo n.º 1
0
u32 services_SyncRequest(handleinfo* h, bool *locked)
{
    u32 i;

    // Lookup which requested service in table.
    for(i=0; i<ARRAY_SIZE(services); i++) {
        if(services[i].subtype == h->subtype)
            return services[i].fnSyncRequest();
    }

    if (h->subtype == SERVICE_DIRECT) {
        if (h->misc[0] & HANDLE_SERV_STAT_ACKING) {
            mem_Write(h->misc_ptr[0], arm11_ServiceBufferAddress() + 0x80, 0x200);
            h->misc[0] &= ~(HANDLE_SERV_STAT_ACKING | HANDLE_SERV_STAT_SYNCING);
            *locked = false;
            return 0;
        } else {
            if (!(h->misc[0] & HANDLE_SERV_STAT_SYNCING)) mem_Read(h->misc_ptr[0], arm11_ServiceBufferAddress() + 0x80, 0x200);
            h->misc[0] |= HANDLE_SERV_STAT_SYNCING;
            *locked = true;
            return 0;
        }
    }

    ERROR("invalid handle.\n");
    arm11_Dump();
    PAUSE();
    return 0;
}
Ejemplo n.º 2
0
archive* sharedextd_OpenArchive(file_path path)
{
    // Extdata needs a binary path with a 12-byte id.
    if(path.type != PATH_BINARY || path.size != 12) {
        ERROR("Unknown SharedExtData path.\n");
        return NULL;
    }

    archive* arch = calloc(sizeof(archive), 1);

    if(arch == NULL) {
        ERROR("malloc failed.\n");
        return NULL;
    }

    // Setup function pointers
    arch->fnFileExists   = &sharedextd_FileExists;
    arch->fnOpenFile     = &sharedextd_OpenFile;
    arch->fnDeinitialize = &sharedextd_Deinitialize;

    u8 buf[12];

    if(mem_Read(buf, path.ptr, 12) != 0) {
        ERROR("Failed to read path.\n");
        free(arch);
        return NULL;
    }

    snprintf(arch->type_specific.sharedextd.path,
             sizeof(arch->type_specific.sharedextd.path),
             "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
             buf[0], buf[1], buf[2], buf[3], buf[ 4], buf[ 5],
             buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]);
    return arch;
}
Ejemplo n.º 3
0
u32 wrapWaitSynchronizationN(u32 nanoseconds1,u32 handles_ptr,u32 handles_count,u32 wait_all,u32 nanoseconds2,u32 out) // TODO: timeouts
{
    bool all_unlocked = true;

    for (u32 i = 0; i < handles_count; i++) {
        u32 handle = mem_Read32(handles_ptr + i * 4);
        handleinfo* hi = handle_Get(handle);

        if (hi == NULL) {
            arm11_SetR(1, i);
            ERROR("handle %08x not found.\n", handle);
            PAUSE();
#ifdef EXIT_ON_ERROR
            exit(1);
#endif
            return -1;
        }

        if (hi->type >= NUM_HANDLE_TYPES) {
            // This should never happen.
            ERROR("handle %08x has non-defined type.\n", handle);
            PAUSE();
            exit(1);
        }

        // Lookup actual callback in table.
        if (handle_types[hi->type].fnWaitSynchronization != NULL) {
            bool locked = false;

            handle_types[hi->type].fnWaitSynchronization(hi, &locked);

            if (!locked && !wait_all) {
                arm11_SetR(1, i);
                return 0;
            } else
                all_unlocked = false;

        } else {
            ERROR("WaitSynchronization undefined for handle-type \"%s\".\n",
                  handle_types[hi->type].name);
            PAUSE();
            arm11_SetR(1, i); //we just say this one is open
            return 0;
        }
    }

    if(wait_all && all_unlocked) {
        arm11_SetR(1, handles_count);
        return 0;
    }

    // Put thread in WAITING state if not all handles were unlocked.
    u32* wait_list = malloc(handles_count*4);
    mem_Read((u8 *) wait_list, handles_ptr, handles_count * 4);

    threads_SetCurrentThreadWaitList(wait_list, wait_all, handles_count);
    return 0;

}
Ejemplo n.º 4
0
const char* fs_PathToString(u32 type, u32 ptr, u32 size,
                            char* buf_out, size_t size_out)
{
    static const char* hex_digits = "0123456789abcdef";
    u32 i;

    switch(type) {
    case PATH_BINARY:
        if(size >= size_out/2)
            return "<couldn't fit it>";

        // Dump binary paths in hex.
        for(i=0; i<size; i++) {
            u8 b = mem_Read8(ptr + i);
            buf_out[2*i] = hex_digits[(b>>4) & 0xF];
            buf_out[2*i+1] = hex_digits[b & 0xF];
        }

        buf_out[2*i] = '\0';
        return buf_out;

    case PATH_CHAR:
        if(size >= size_out)
            return "<couldn't fit it>";

        // Dump ascii paths normally.
        mem_Read(buf_out, ptr, size);
        buf_out[size] = '\0';
        return buf_out;

    case PATH_WCHAR:
        if(size/2 >= size_out)
            return "<couldn't fit it>";

        for(i=0; i<size; i++) {
            u16 b = mem_Read16(ptr + 2*i);

            // Convert unicode -> ascii.
            // If it fails, use question marks.
            if(b >> 8)
                buf_out[i] = '?';
            else
                buf_out[i] = b & 0xFF;
        }

        buf_out[i] = '\0';
        return buf_out;

    default:
        return "";
    }
Ejemplo n.º 5
0
u32 srv_SyncRequest()
{
    u32 cid = mem_Read32(arm11_ServiceBufferAddress() + 0x80);

    // Read command-id.
    switch(cid) {

    case 0x10002:
        DEBUG("srv_Initialize\n");

        // XXX: check +4, flags?
        mem_Write32(arm11_ServiceBufferAddress() + 0x84, 0); //no error
        PAUSE();
        return 0;

    case 0x20000:
        DEBUG("srv_GetProcSemaphore");

        mem_Write32(arm11_ServiceBufferAddress() + 0x84, 0); //no error
        mem_Write32(arm11_ServiceBufferAddress() + 0x88, 0); //done in sm 4.4
        mem_Write32(arm11_ServiceBufferAddress() + 0x8C, eventhandle);
        return 0;

        char names[9];
    case 0x000400C0:
        DEBUG("srv_UnRegisterService --todo--\n");

        // Read rest of command header
        mem_Read((u8*)&req, arm11_ServiceBufferAddress() + 0x84, sizeof(req));

        memcpy(names, req.name, 8);
        names[8] = '\0';

        DEBUG("name=%s, namelen=%u\n", names, req.name_len);

        return 0;

    case 0x00030100:
        DEBUG("srv_registerService\n");

        // Read rest of command header
        mem_Read((u8*)&req, arm11_ServiceBufferAddress() + 0x84, sizeof(req));

        memcpy(names, req.name, 8);
        names[8] = '\0';

        DEBUG("name=%s, namelen=%u, unk=0x%x\n", names, req.name_len,
            req.unk2);


        ownservice[ownservice_num].name = malloc(9);
        memcpy(ownservice[ownservice_num].name, req.name, 9);

        ownservice[ownservice_num].handle = handle_New(HANDLE_TYPE_SERVICE, SERVICE_DIRECT);

        handleinfo* hi = handle_Get(ownservice[ownservice_num].handle);
        if (hi == NULL) {
            ERROR("getting handle.\n");
            return 0x0;
        }
        hi->misc[0] = HANDLE_SERV_STAT_TAKEN; //init

        hi->misc_ptr[0] = malloc(0x200);

        mem_Write32(arm11_ServiceBufferAddress() + 0x84, 0); //no error
        mem_Write32(arm11_ServiceBufferAddress() + 0x8C, ownservice[ownservice_num].handle); //return handle
        ownservice_num++;
        return 0;

    case 0x50100:
        DEBUG("srv_GetServiceHandle\n");

        // Read rest of command header
        mem_Read((u8*)&req, arm11_ServiceBufferAddress() + 0x84, sizeof(req));

        memcpy(names, req.name, 8);
        names[8] = '\0';

        DEBUG("name=%s, namelen=%u, unk=0x%x\n", names, req.name_len,
              req.unk2);
        PAUSE();

        u32 i;

        bool overdr = false;
        for (u32 i = 0; i < overdrivnum; i++) {
            if (memcmp(req.name, *(overdrivnames + i), strnlen(*(overdrivnames + i), 8)) == 0)overdr = true;
        }
        if (!overdr) {
            for (u32 i = 0; i < ownservice_num; i++) {
                if (memcmp(req.name, ownservice[i].name, strnlen(ownservice[i].name, 8)) == 0) {

                    // Write result.
                    mem_Write32(arm11_ServiceBufferAddress() + 0x84, 0);

                    // Write handle_out.
                    mem_Write32(arm11_ServiceBufferAddress() + 0x8C, ownservice[i].handle);

                    return 0;
                }
            }
        }
        for(i=0; i<ARRAY_SIZE(services); i++) {
            // Find service in list.
            if(memcmp(req.name, services[i].name, strnlen(services[i].name, 8)) == 0) {

                // Write result.
                mem_Write32(arm11_ServiceBufferAddress() + 0x84, 0);

                // Write handle_out.
                mem_Write32(arm11_ServiceBufferAddress() + 0x8C, services[i].handle);

                return 0;
            }
        }

        ERROR("Unimplemented service: %s\n", req.name);
        arm11_Dump();
        exit(1);

    case 0x90040: // EnableNotificationType
        DEBUG("srv_EnableNotificationType\n");

        u32 type = mem_Read32(arm11_ServiceBufferAddress() + 0x84);
        DEBUG("STUBBED, type=%x\n", type);

        mem_Write32(arm11_ServiceBufferAddress() + 0x84, 0);
        return 0;

    case 0xa0040: // DisableNotificationType
        DEBUG("srv_DisableNotificationType\n");

        type = mem_Read32(arm11_ServiceBufferAddress() + 0x84);
        DEBUG("STUBBED, type=%x\n", type);

        mem_Write32(arm11_ServiceBufferAddress() + 0x84, 0); //no error
        return 0;

    case 0xB0000: // GetNotificationType
        DEBUG("srv_GetNotificationType\n");
        //mem_Dbugdump();
        mem_Write32(arm11_ServiceBufferAddress() + 0x84, 0); //worked
        mem_Write32(arm11_ServiceBufferAddress() + 0x88, 0); //type
        return 0;

    default:
        ERROR("Unimplemented command %08x in \"srv:\"\n", cid);
        arm11_Dump();
        mem_Write32(arm11_ServiceBufferAddress() + 0x84, 0xFFFFFFFF); //worked
        return 0;
        //exit(1);
    }

    return 0;
}
Ejemplo n.º 6
0
u32 svcWaitSynchronizationN() //todo timeout
{
    u32 *handelist;
    u32 nanoseconds1 = arm11_R(0);
    u32 handles = arm11_R(1);
    u32 handlecount = arm11_R(2);
    u32 waitAll = arm11_R(3);
    u32 nanoseconds2 = arm11_R(4);
    bool allunlockde = true;
    for (u32 i = 0; i < handlecount; i++)
    {
        u32 curhandel = mem_Read32(handles + i * 4);
        handleinfo* hi = handle_Get(curhandel);

        if (hi == NULL) {
            ERROR("handle %08x not found.\n", curhandel);
            PAUSE();
#ifdef exitonerror
            exit(1);
#else
            return 0;
#endif
        }

        if (hi->type >= NUM_HANDLE_TYPES) {
            // This should never happen.
            ERROR("handle %08x has non-defined type.\n", curhandel);
            PAUSE();
            exit(1);
        }

        u32 temp;
        bool locked = false;
        // Lookup actual callback in table.
        if (handle_types[hi->type].fnWaitSynchronization != NULL)
        {
            temp = handle_types[hi->type].fnWaitSynchronization(hi, &locked);
            if (!locked && waitAll == 0)
            {
                arm11_SetR(1,i);
                return 0;
            }
            else
            {
                allunlockde = false;
            }
        }
        else
        {
            ERROR("svcCloseHandle undefined for handle-type \"%s\".\n",
                handle_types[hi->type].name);
            PAUSE();
            return 0;
        }
    }
    if (waitAll && allunlockde)return 0;
    handelist = malloc(handlecount*4);
    mem_Read((u8*)handelist, handles, handlecount * 4);
    lockcpu(handelist, waitAll, handlecount);
    return 0;
}
Ejemplo n.º 7
0
Archivo: srv.c Proyecto: 20150/3dmoo
u32 svcReplyAndReceive()
{

    s32 index = arm11_R(0);
    u32 handles = arm11_R(1);
    u32 handleCount = arm11_R(2);
    u32 replyTarget = arm11_R(3);
    DEBUG("svcReplyAndReceive %08x %08x %08x %08x\n", index, handles, handleCount, replyTarget);

    if (replyTarget) //respond
    {
        IPC_debugprint(arm11_ServiceBufferAddress() + 0x80);
        handleinfo* h2 = handle_Get(replyTarget);
        if (h2 == NULL) {
            ERROR("handle not there");
        }
        eventhandle = h2->misc[0];
        h2 = handle_Get(eventhandle);
        if (h2 == NULL) {
            ERROR("handle not there");
        }
        if (h2->misc[0] & HANDLE_SERV_STAT_SYNCING) {
            mem_Read(h2->misc_ptr[0], arm11_ServiceBufferAddress() + 0x80, 0x80); //todo 
            h2->misc[0] |= HANDLE_SERV_STAT_ACKING;
        }
    }

    for (u32 i = 0; i < handleCount; i++) {
        DEBUG("%08x\n", mem_Read32(handles + i * 4));
    }
    /*wrapWaitSynchronizationN(0xFFFFFFFF, handles, handleCount, 0, 0xFFFFFFFF,0);



    //feed module data here
    switch (times) {
    case 0:
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
        RESP(0, 0x00160042);
        RESP(1, 0x0);
        RESP(2, 0x0);
        RESP(3, 0x12345);
        break;
    case 7:
        RESP(0, 0x00130042);
        RESP(1, 0x0);
        RESP(2, 0x0);
        RESP(3, handle_New(HANDLE_TYPE_EVENT, 0));
        break;
    default:
        RESP(0, 0x000C0000);
        break;
    }*/

    //RESP(0, 0x00010800);

    //feed end

    times++;

    arm11_SetR(1, 0);

    return 0;
}