Result srvSysInit() { Result rc = 0; if (!initLockinit) { RecursiveLock_Init(&initLock); } RecursiveLock_Lock(&initLock); if (srvRefCount > 0) { RecursiveLock_Unlock(&initLock); return MAKERESULT(RL_INFO, RS_NOP, 25, RD_ALREADY_INITIALIZED); } while (1) { rc = svcConnectToPort(&srvHandle, "srv:"); if (R_LEVEL(rc) != RL_PERMANENT || R_SUMMARY(rc) != RS_NOTFOUND || R_DESCRIPTION(rc) != RD_NOT_FOUND) break; svcSleepThread(500000); } if (R_SUCCEEDED(rc)) { rc = srvSysRegisterClient(); srvRefCount++; } RecursiveLock_Unlock(&initLock); return rc; }
bool hidTryWaitForEvent(HID_Event id, s64 nanoseconds){ if(R_DESCRIPTION(svcWaitSynchronization(hidEvents[id], nanoseconds))==RD_TIMEOUT){ return false; } else{ svcClearEvent(hidEvents[id]); return true; } }
static int installCia(Handle ciaFile){ Result failed; Handle outputHandle; u64 fileSize; u64 fileOffset = 0; u32 bytesRead; u32 bytesWritten; u8 transferBuffer[FILE_CHUNK_SIZE]; failed = AM_StartCiaInstall(MEDIATYPE_SD, &outputHandle); if(R_FAILED(failed)) return -1; failed = FSFILE_GetSize(ciaFile, &fileSize); if(R_FAILED(failed)) return -1; while(fileOffset < fileSize){ u64 bytesRemaining = fileSize - fileOffset; failed = FSFILE_Read(ciaFile, &bytesRead, fileOffset, transferBuffer, bytesRemaining < FILE_CHUNK_SIZE ? bytesRemaining : FILE_CHUNK_SIZE); if(R_FAILED(failed)){ AM_CancelCIAInstall(outputHandle); return -1; } failed = FSFILE_Write(outputHandle, &bytesWritten, fileOffset, transferBuffer, bytesRead, 0); if(R_FAILED(failed)){ AM_CancelCIAInstall(outputHandle); if(R_DESCRIPTION(failed) == RD_ALREADY_EXISTS) return 1; return -1; } if(bytesWritten != bytesRead){ AM_CancelCIAInstall(outputHandle); return -1; } fileOffset += bytesWritten; } failed = AM_FinishCiaInstall(outputHandle); if(R_FAILED(failed)) return -1; return 1; }
static inline void initPXI(void) { Result res; Handle handles[2] = {0}; PXIReset(); if(PXISyncInterrupt != 0) svcBreak(USERBREAK_PANIC); //0xE0A0183B assertSuccess(svcCreateEvent(&PXISyncInterrupt, RESET_ONESHOT)); if(PXITransferMutex != 0) svcBreak(USERBREAK_PANIC); //0xE0A0183B assertSuccess(svcCreateMutex(&PXITransferMutex, false)); assertSuccess(svcCreateEvent(&handles[0], RESET_ONESHOT)); //receive FIFO not empty assertSuccess(svcCreateEvent(&handles[1], RESET_ONESHOT)); //send FIFO empty assertSuccess(bindPXIInterrupts(&PXISyncInterrupt, &handles[0], &handles[1])); s32 handleIndex; do { while(!PXIIsSendFIFOFull()) PXISendWord(0); res = assertSuccess(svcWaitSynchronization(handles[0], 0LL)); if(R_DESCRIPTION(res) == RD_TIMEOUT) assertSuccess(svcWaitSynchronizationN(&handleIndex, handles, 2, false, -1LL)); else handleIndex = 0; } while(handleIndex != 0); unbindPXIInterrupts(NULL, &handles[0], &handles[1]); PXISendByte(1); while(PXIReceiveByte() < 1); while (!PXIIsReceiveFIFOEmpty()) PXIReceiveWord(); PXISendByte(2); while(PXIReceiveByte() < 2); svcCloseHandle(handles[0]); svcCloseHandle(handles[1]); }
void error_display_res(void* data, void (*drawTop)(ui_view* view, void* data, float x1, float y1, float x2, float y2), Result result, const char* text, ...) { error_data* errorData = (error_data*) calloc(1, sizeof(error_data)); errorData->data = data; errorData->drawTop = drawTop; char textBuf[1024]; va_list list; va_start(list, text); vsnprintf(textBuf, 1024, text, list); va_end(list); int level = R_LEVEL(result); int summary = R_SUMMARY(result); int module = R_MODULE(result); int description = R_DESCRIPTION(result); snprintf(errorData->fullText, 4096, "%s\nResult code: 0x%08lX\nLevel: %s (%d)\nSummary: %s (%d)\nModule: %s (%d)\nDesc: %s (%d)", textBuf, result, level_to_string(result), level, summary_to_string(result), summary, module_to_string(result), module, description_to_string(result), description); ui_push(prompt_create("Error", errorData->fullText, COLOR_TEXT, false, errorData, NULL, error_draw_top, error_onresponse)); }
static const char* description_to_string(Result res) { int module = R_MODULE(res); int description = R_DESCRIPTION(res); switch(module) { case RM_KERNEL: switch(description) { case 2: return "Invalid DMA buffer memory permissions"; default: break; } break; case RM_OS: switch(description) { case 1: return "Out of synchronization object"; case 2: return "Out of shared memory objects"; case 9: return "Out of session objects"; case 10: return "Not enough memory for allocation"; case 20: return "Wrong permissions for unprivileged access"; case 26: return "Session closed by remote process"; case 47: return "Invalid command header"; case 52: return "Max port connections exceeded"; default: break; } break; case RM_FS: switch(description) { case 101: return "Archive not mounted"; case 120: return "Doesn't exist / Failed to open"; case 141: return "Game card not inserted"; case 171: return "Bus: Busy / Underrun"; case 172: return "Bus: Illegal function"; case 190: return "Already exists / Failed to create"; case 210: return "Partition full"; case 230: return "Illegal operation / File in use"; case 231: return "Resource locked"; case 265: return "Bus: Timeout"; case 331: return "Bus error / TWL partition invalid"; case 332: return "Bus: Stop bit error"; case 391: return "Hash verification failure"; case 392: return "RSA/Hash verification failure"; case 395: return "Invalid RomFS or save data block hash"; case 630: return "Archive permission denied"; case 702: return "Invalid path / Inaccessible archive"; case 705: return "Offset out of bounds"; case 721: return "Reached file size limit"; case 760: return "Unsupported operation"; case 761: return "ExeFS read size mismatch"; default: break; } break; case RM_SRV: switch(description) { case 5: return "Invalid service name length"; case 6: return "Service access denied"; case 7: return "String size mismatch"; default: break; } break; case RM_AM: switch(description) { case 4: return "Wrong installation state"; case 37: return "Invalid NCCH"; case 39: return "Invalid or outdated title version"; case 41: return "Error type 1"; case 43: return "Database does not exist"; case 44: return "Attempted to delete system title"; case 101: return "Error type -1"; case 102: return "Error type -2"; case 103: return "Error type -3"; case 104: return "Error type -4"; case 105: return "Error type -5"; case 106: return "Cert signature or hash check failed"; case 107: return "Error type -7"; case 108: return "Error type -8"; case 109: return "Error type -9"; case 110: return "Error type -10"; case 111: return "Error type -11"; case 112: return "Error type -12"; case 113: return "Error type -13"; case 114: return "Error type -14"; case 393: return "Invalid database"; default: break; } break; case RM_HTTP: switch(description) { case 60: return "Failed to verify TLS certificate"; case 70: return "Network unavailable"; case 102: return "Wrong context handle"; case 105: return "Request timed out"; default: break; } break; case RM_SSL: switch(description) { case 20: return "Untrusted RootCA"; case 54: return "RootCertChain handle not found"; default: break; } break; case RM_SDMC: switch(description) { case 1: return "Bus: Bit23 error"; case 2: return "Bus: RX ready error"; case 3: return "Bus: Bit28 error"; case 4: return "Bus: Bit27 error"; default: break; } break; case RM_MVD: switch(description) { case 271: return "Invalid configuration"; default: break; } break; case RM_NFC: switch(description) { case 512: return "Invalid NFC state"; default: break; } break; case RM_QTM: switch(description) { case 8: return "Camera busy"; default: break; } break; default: break; } switch(description) { case RD_SUCCESS: return "Success"; case RD_TIMEOUT: return "Timeout"; case RD_OUT_OF_RANGE: return "Out of range"; case RD_ALREADY_EXISTS: return "Already exists"; case RD_CANCEL_REQUESTED: return "Cancel requested"; case RD_NOT_FOUND: return "Not found"; case RD_ALREADY_INITIALIZED: return "Already initialized"; case RD_NOT_INITIALIZED: return "Not initialized"; case RD_INVALID_HANDLE: return "Invalid handle"; case RD_INVALID_POINTER: return "Invalid pointer"; case RD_INVALID_ADDRESS: return "Invalid address"; case RD_NOT_IMPLEMENTED: return "Not implemented"; case RD_OUT_OF_MEMORY: return "Out of memory"; case RD_MISALIGNED_SIZE: return "Misaligned size"; case RD_MISALIGNED_ADDRESS: return "Misaligned address"; case RD_BUSY: return "Busy"; case RD_NO_DATA: return "No data"; case RD_INVALID_COMBINATION: return "Invalid combination"; case RD_INVALID_ENUM_VALUE: return "Invalid enum value"; case RD_INVALID_SIZE: return "Invalid size"; case RD_ALREADY_DONE: return "Already done"; case RD_NOT_AUTHORIZED: return "Not authorized"; case RD_TOO_LARGE: return "Too large"; case RD_INVALID_SELECTION: return "Invalid selection"; default: return "<unknown>"; } }