fatal: Rename functions/types to match official names more closely

This commit is contained in:
fincs 2019-10-24 23:25:07 +02:00
parent a808c53efc
commit 4ab2384449
No known key found for this signature in database
GPG Key ID: 62C7609ADA219C60
14 changed files with 80 additions and 79 deletions

View File

@ -9,10 +9,10 @@
/// Type of thrown fatal error. /// Type of thrown fatal error.
typedef enum { typedef enum {
FatalType_ErrorReportAndErrorScreen = 0, FatalPolicy_ErrorReportAndErrorScreen = 0,
FatalType_ErrorReport = 1, FatalPolicy_ErrorReport = 1,
FatalType_ErrorScreen = 2 ///< Only available with [3.0.0+]. If specified, FatalType_ErrorReportAndErrorScreen will be used instead on pre-3.0.0. FatalPolicy_ErrorScreen = 2 ///< Only available with [3.0.0+]. If specified, FatalPolicy_ErrorReportAndErrorScreen will be used instead on pre-3.0.0.
} FatalType; } FatalPolicy;
/// Struct for fatal Cpu context, 64-bit. /// Struct for fatal Cpu context, 64-bit.
typedef struct { typedef struct {
@ -71,29 +71,29 @@ typedef struct {
bool is_aarch32; bool is_aarch32;
u32 type; u32 type;
} FatalContext; } FatalCpuContext;
/** /**
* @brief Triggers a system fatal error. * @brief Triggers a system fatal error.
* @param[in] err Result code to throw. * @param[in] err Result code to throw.
* @note This function does not return. * @note This function does not return.
* @note This uses \ref fatalWithType with \ref FatalType_ErrorScreen internally. * @note This uses \ref fatalThrowWithPolicy with \ref FatalPolicy_ErrorScreen internally.
*/ */
void NORETURN fatalSimple(Result err); void NORETURN fatalThrow(Result err);
/** /**
* @brief Triggers a system fatal error with a custom \ref FatalType. * @brief Triggers a system fatal error with a custom \ref FatalPolicy.
* @param[in] err Result code to throw. * @param[in] err Result code to throw.
* @param[in] type Type of fatal error to throw. * @param[in] type Type of fatal error to throw.
* @note This function may not return, depending on \ref FatalType. * @note This function may not return, depending on \ref FatalPolicy.
*/ */
void fatalWithType(Result err, FatalType type); void fatalThrowWithPolicy(Result err, FatalPolicy type);
/** /**
* @brief Triggers a system fatal error with a custom \ref FatalType and \ref FatalContext. * @brief Triggers a system fatal error with a custom \ref FatalPolicy and \ref FatalCpuContext.
* @param[in] err Result code to throw. * @param[in] err Result code to throw.
* @param[in] type Type of fatal error to throw. * @param[in] type Type of fatal error to throw.
* @param[in] ctx Cpu context for fatal error to throw. * @param[in] ctx Cpu context for fatal error to throw.
* @note This function may not return, depending on \ref FatalType. * @note This function may not return, depending on \ref FatalPolicy.
*/ */
void fatalWithContext(Result err, FatalType type, FatalContext *ctx); void fatalThrowWithContext(Result err, FatalPolicy type, FatalCpuContext *ctx);

View File

@ -42,7 +42,7 @@ void __nx_win_init(void)
viExit(); viExit();
} }
if (R_FAILED(rc)) if (R_FAILED(rc))
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadGfxInit)); fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadGfxInit));
} }
void __nx_win_exit(void) void __nx_win_exit(void)

View File

@ -154,7 +154,7 @@ void* framebufferBegin(Framebuffer* fb, u32* out_stride)
s32 slot; s32 slot;
Result rc = nwindowDequeueBuffer(fb->win, &slot, NULL); Result rc = nwindowDequeueBuffer(fb->win, &slot, NULL);
if (R_FAILED(rc)) if (R_FAILED(rc))
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadGfxDequeueBuffer)); fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadGfxDequeueBuffer));
if (out_stride) if (out_stride)
*out_stride = fb->stride; *out_stride = fb->stride;
@ -223,5 +223,5 @@ void framebufferEnd(Framebuffer* fb)
Result rc = nwindowQueueBuffer(fb->win, fb->win->cur_slot, NULL); Result rc = nwindowQueueBuffer(fb->win, fb->win->cur_slot, NULL);
if (R_FAILED(rc)) if (R_FAILED(rc))
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadGfxQueueBuffer)); fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadGfxQueueBuffer));
} }

View File

@ -137,7 +137,7 @@ static void _randomInit(void)
{ {
// Get process TRNG seeds from kernel. // Get process TRNG seeds from kernel.
if (R_FAILED(svcGetInfo(&seed[i], InfoType_RandomEntropy, INVALID_HANDLE, i))) if (R_FAILED(svcGetInfo(&seed[i], InfoType_RandomEntropy, INVALID_HANDLE, i)))
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadGetInfo_Rng)); fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadGetInfo_Rng));
} }
if (envHasRandomSeed()) if (envHasRandomSeed())

View File

@ -161,7 +161,7 @@ Result threadCreate(
void threadExit(void) { void threadExit(void) {
Thread* t = getThreadVars()->thread_ptr; Thread* t = getThreadVars()->thread_ptr;
if (!t) if (!t)
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_NotInitialized)); fatalThrow(MAKERESULT(Module_Libnx, LibnxError_NotInitialized));
u64 tls_mask = __atomic_load_n(&g_tlsUsageMask, __ATOMIC_SEQ_CST); u64 tls_mask = __atomic_load_n(&g_tlsUsageMask, __ATOMIC_SEQ_CST);
for (s32 i = 0; i < NUM_TLS_SLOTS; i ++) { for (s32 i = 0; i < NUM_TLS_SLOTS; i ++) {

View File

@ -71,16 +71,16 @@ void virtmemSetup(void) {
} }
else { else {
// Wat. // Wat.
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_WeirdKernel)); fatalThrow(MAKERESULT(Module_Libnx, LibnxError_WeirdKernel));
} }
} else { } else {
if (R_FAILED(_GetRegionFromInfo(&g_Region[REGION_STACK], InfoType_StackRegionAddress, InfoType_StackRegionSize))) { if (R_FAILED(_GetRegionFromInfo(&g_Region[REGION_STACK], InfoType_StackRegionAddress, InfoType_StackRegionSize))) {
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadGetInfo_Stack)); fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadGetInfo_Stack));
} }
} }
if (R_FAILED(_GetRegionFromInfo(&g_Region[REGION_HEAP], InfoType_HeapRegionAddress, InfoType_HeapRegionSize))) { if (R_FAILED(_GetRegionFromInfo(&g_Region[REGION_HEAP], InfoType_HeapRegionAddress, InfoType_HeapRegionSize))) {
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadGetInfo_Heap)); fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadGetInfo_Heap));
} }
_GetRegionFromInfo(&g_Region[REGION_LEGACY_ALIAS], InfoType_AliasRegionAddress, InfoType_AliasRegionSize); _GetRegionFromInfo(&g_Region[REGION_LEGACY_ALIAS], InfoType_AliasRegionAddress, InfoType_AliasRegionSize);
@ -110,7 +110,7 @@ void* virtmemReserve(size_t size) {
rc = svcQueryMemory(&meminfo, &pageinfo, addr); rc = svcQueryMemory(&meminfo, &pageinfo, addr);
if (R_FAILED(rc)) { if (R_FAILED(rc)) {
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadQueryMemory)); fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadQueryMemory));
} }
if (meminfo.type != 0) { if (meminfo.type != 0) {
@ -181,7 +181,7 @@ void* virtmemReserveStack(size_t size)
rc = svcQueryMemory(&meminfo, &pageinfo, addr); rc = svcQueryMemory(&meminfo, &pageinfo, addr);
if (R_FAILED(rc)) { if (R_FAILED(rc)) {
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadQueryMemory)); fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadQueryMemory));
} }
if (meminfo.type != 0) { if (meminfo.type != 0) {

View File

@ -553,7 +553,7 @@ size_t usbCommsReadEx(void* buffer, size_t size, u32 interface)
rwlockWriteUnlock(&inter->lock_out); rwlockWriteUnlock(&inter->lock_out);
} }
} }
if (R_FAILED(rc) && g_usbCommsErrorHandling) fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadUsbCommsRead)); if (R_FAILED(rc) && g_usbCommsErrorHandling) fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadUsbCommsRead));
} }
return transferredSize; return transferredSize;
} }
@ -590,7 +590,7 @@ size_t usbCommsWriteEx(const void* buffer, size_t size, u32 interface)
rwlockWriteUnlock(&inter->lock_in); rwlockWriteUnlock(&inter->lock_in);
} }
} }
if (R_FAILED(rc) && g_usbCommsErrorHandling) fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadUsbCommsWrite)); if (R_FAILED(rc) && g_usbCommsErrorHandling) fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadUsbCommsWrite));
} }
return transferredSize; return transferredSize;
} }

View File

@ -21,7 +21,7 @@ void __nx_dynamic(uintptr_t base, const Elf64_Dyn* dyn)
} }
if (rela == NULL) if (rela == NULL)
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadReloc)); fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadReloc));
for (; relasz--; rela++) for (; relasz--; rela++)
{ {

View File

@ -145,7 +145,7 @@ Handle envGetMainThreadHandle(void) {
return g_mainThreadHandle; return g_mainThreadHandle;
} }
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_HandleTooEarly)); fatalThrow(MAKERESULT(Module_Libnx, LibnxError_HandleTooEarly));
} }
bool envIsNso(void) { bool envIsNso(void) {

View File

@ -87,7 +87,7 @@ void __attribute__((weak)) __libnx_initheap(void)
Result rc = svcSetHeapSize(&addr, size); Result rc = svcSetHeapSize(&addr, size);
if (R_FAILED(rc)) if (R_FAILED(rc))
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_HeapAllocFailed)); fatalThrow(MAKERESULT(Module_Libnx, LibnxError_HeapAllocFailed));
} }
// Newlib // Newlib
@ -108,7 +108,7 @@ void __attribute__((weak)) __appInit(void)
// Initialize default services. // Initialize default services.
rc = smInitialize(); rc = smInitialize();
if (R_FAILED(rc)) if (R_FAILED(rc))
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_SM)); fatalThrow(MAKERESULT(Module_Libnx, LibnxError_InitFail_SM));
if (hosversionGet() == 0) { if (hosversionGet() == 0) {
rc = setsysInitialize(); rc = setsysInitialize();
@ -123,23 +123,23 @@ void __attribute__((weak)) __appInit(void)
rc = appletInitialize(); rc = appletInitialize();
if (R_FAILED(rc)) if (R_FAILED(rc))
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_AM)); fatalThrow(MAKERESULT(Module_Libnx, LibnxError_InitFail_AM));
if (__nx_applet_type != AppletType_None) { if (__nx_applet_type != AppletType_None) {
rc = hidInitialize(); rc = hidInitialize();
if (R_FAILED(rc)) if (R_FAILED(rc))
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_HID)); fatalThrow(MAKERESULT(Module_Libnx, LibnxError_InitFail_HID));
} }
rc = timeInitialize(); rc = timeInitialize();
if (R_FAILED(rc)) if (R_FAILED(rc))
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_Time)); fatalThrow(MAKERESULT(Module_Libnx, LibnxError_InitFail_Time));
__libnx_init_time(); __libnx_init_time();
rc = fsInitialize(); rc = fsInitialize();
if (R_FAILED(rc)) if (R_FAILED(rc))
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_FS)); fatalThrow(MAKERESULT(Module_Libnx, LibnxError_InitFail_FS));
fsdevMountSdmc(); fsdevMountSdmc();
__libnx_init_cwd(); __libnx_init_cwd();

View File

@ -59,7 +59,7 @@ struct _reent* __syscall_getreent(void)
{ {
ThreadVars* tv = getThreadVars(); ThreadVars* tv = getThreadVars();
if (tv->magic != THREADVARS_MAGIC) if (tv->magic != THREADVARS_MAGIC)
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadReent)); fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadReent));
return tv->reent; return tv->reent;
} }

View File

@ -168,7 +168,7 @@ Result _appletInitialize(void) {
case AppletType_OverlayApplet: cmd_id = 300; break; case AppletType_OverlayApplet: cmd_id = 300; break;
case AppletType_SystemApplication: cmd_id = 350; break; case AppletType_SystemApplication: cmd_id = 350; break;
// TODO: Replace error code // TODO: Replace error code
default: fatalSimple(MAKERESULT(Module_Libnx, LibnxError_AppletCmdidNotFound)); default: fatalThrow(MAKERESULT(Module_Libnx, LibnxError_AppletCmdidNotFound));
} }
if (__nx_applet_type == AppletType_LibraryApplet && hosversionAtLeast(3,0,0)) { if (__nx_applet_type == AppletType_LibraryApplet && hosversionAtLeast(3,0,0)) {
@ -1980,7 +1980,7 @@ void appletNotifyRunning(bool *out) {
Result rc = _appletCmdNoInOutBool(&g_appletIFunctions, out, 40); Result rc = _appletCmdNoInOutBool(&g_appletIFunctions, out, 40);
if (R_FAILED(rc)) fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadAppletNotifyRunning)); if (R_FAILED(rc)) fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadAppletNotifyRunning));
} }
Result appletGetPseudoDeviceId(u128 *out) { Result appletGetPseudoDeviceId(u128 *out) {
@ -2714,7 +2714,7 @@ Result appletGetMessage(u32 *msg) {
if (R_VALUE(rc) == MAKERESULT(128, 3)) if (R_VALUE(rc) == MAKERESULT(128, 3))
return rc; return rc;
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadAppletReceiveMessage)); fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadAppletReceiveMessage));
} }
return 0; return 0;
@ -2732,7 +2732,7 @@ bool appletProcessMessage(u32 msg) {
case AppletMessage_FocusStateChanged: case AppletMessage_FocusStateChanged:
rc = _appletGetCurrentFocusState(&g_appletFocusState); rc = _appletGetCurrentFocusState(&g_appletFocusState);
if (R_FAILED(rc)) if (R_FAILED(rc))
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadAppletGetCurrentFocusState)); fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadAppletGetCurrentFocusState));
appletCallHook(AppletHookType_OnFocusState); appletCallHook(AppletHookType_OnFocusState);
break; break;
@ -2744,7 +2744,7 @@ bool appletProcessMessage(u32 msg) {
case AppletMessage_OperationModeChanged: case AppletMessage_OperationModeChanged:
rc = _appletGetOperationMode(&g_appletOperationMode); rc = _appletGetOperationMode(&g_appletOperationMode);
if (R_FAILED(rc)) if (R_FAILED(rc))
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadAppletGetOperationMode)); fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadAppletGetOperationMode));
appletCallHook(AppletHookType_OnOperationMode); appletCallHook(AppletHookType_OnOperationMode);
break; break;
@ -2752,7 +2752,7 @@ bool appletProcessMessage(u32 msg) {
case AppletMessage_PerformanceModeChanged: case AppletMessage_PerformanceModeChanged:
rc = _appletGetPerformanceMode(&g_appletPerformanceMode); rc = _appletGetPerformanceMode(&g_appletPerformanceMode);
if (R_FAILED(rc)) if (R_FAILED(rc))
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadAppletGetPerformanceMode)); fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadAppletGetPerformanceMode));
appletCallHook(AppletHookType_OnPerformanceMode); appletCallHook(AppletHookType_OnPerformanceMode);
break; break;

View File

@ -1,4 +1,3 @@
// Copyright 2017 plutoo
#define NX_SERVICE_ASSUME_NON_DOMAIN #define NX_SERVICE_ASSUME_NON_DOMAIN
#include "types.h" #include "types.h"
#include "result.h" #include "result.h"
@ -8,11 +7,11 @@
#include "services/fatal.h" #include "services/fatal.h"
#include "services/sm.h" #include "services/sm.h"
static void _fatalImpl(u32 cmd_id, Result err, FatalType type, FatalContext *ctx) { static void _fatalCmd(Result err, FatalPolicy type, FatalCpuContext *ctx, u32 cmd_id) {
Result rc = 0; Result rc = 0;
//Only [3.0.0+] supports FatalType_ErrorScreen, when specified on pre-3.0.0 use FatalType_ErrorReportAndErrorScreen instead. //Only [3.0.0+] supports FatalPolicy_ErrorScreen, when specified on pre-3.0.0 use FatalPolicy_ErrorReportAndErrorScreen instead.
if (type == FatalType_ErrorScreen && !kernelAbove300()) type = FatalType_ErrorReportAndErrorScreen; if (type == FatalPolicy_ErrorScreen && !kernelAbove300()) type = FatalPolicy_ErrorReportAndErrorScreen;
if (detectDebugger()) { if (detectDebugger()) {
svcBreak(0x80000000, err, 0); svcBreak(0x80000000, err, 0);
@ -43,27 +42,29 @@ static void _fatalImpl(u32 cmd_id, Result err, FatalType type, FatalContext *ctx
} }
switch (type) { switch (type) {
case FatalType_ErrorReport: case FatalPolicy_ErrorReport:
break; break;
case FatalType_ErrorReportAndErrorScreen: case FatalPolicy_ErrorReportAndErrorScreen:
case FatalType_ErrorScreen: case FatalPolicy_ErrorScreen:
default: default:
svcExitProcess(); svcExitProcess();
__builtin_unreachable(); __builtin_unreachable();
} }
} }
void NORETURN fatalSimple(Result err) { void NORETURN fatalThrow(Result err) {
/* By default, do not generate an error report. */ // By default, do not generate an error report.
fatalWithType(err, FatalType_ErrorScreen); fatalThrowWithPolicy(err, FatalPolicy_ErrorScreen);
svcExitProcess(); svcExitProcess();
__builtin_unreachable(); __builtin_unreachable();
} }
void fatalWithType(Result err, FatalType type) { void fatalThrowWithPolicy(Result err, FatalPolicy type) {
_fatalImpl(1, err, type, NULL); _fatalCmd(err, type, NULL, 1);
} }
void fatalWithContext(Result err, FatalType type, FatalContext *ctx) { void fatalThrowWithContext(Result err, FatalPolicy type, FatalCpuContext *ctx) {
_fatalImpl(2, err, type, ctx); _fatalCmd(err, type, ctx, 2);
} }
void NORETURN fatalSimple(Result) __attribute__((alias("fatalThrow")));

View File

@ -15,7 +15,7 @@ static size_t g_smOverridesNum = 0;
void smAddOverrideHandle(SmServiceName name, Handle handle) { void smAddOverrideHandle(SmServiceName name, Handle handle) {
if (g_smOverridesNum == MAX_OVERRIDES) if (g_smOverridesNum == MAX_OVERRIDES)
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_TooManyOverrides)); fatalThrow(MAKERESULT(Module_Libnx, LibnxError_TooManyOverrides));
size_t i = g_smOverridesNum; size_t i = g_smOverridesNum;