From 4ab23844497c3864d9ad0a493c7ad434dd840c1b Mon Sep 17 00:00:00 2001 From: fincs Date: Thu, 24 Oct 2019 23:25:07 +0200 Subject: [PATCH] fatal: Rename functions/types to match official names more closely --- nx/include/switch/services/fatal.h | 28 +++++++-------- nx/source/display/default_window.c | 2 +- nx/source/display/framebuffer.c | 4 +-- nx/source/kernel/random.c | 2 +- nx/source/kernel/thread.c | 2 +- nx/source/kernel/virtmem.c | 10 +++--- nx/source/runtime/devices/usb_comms.c | 50 +++++++++++++-------------- nx/source/runtime/dynamic.c | 2 +- nx/source/runtime/env.c | 2 +- nx/source/runtime/init.c | 12 +++---- nx/source/runtime/newlib.c | 2 +- nx/source/services/applet.c | 12 +++---- nx/source/services/fatal.c | 29 ++++++++-------- nx/source/services/sm.c | 2 +- 14 files changed, 80 insertions(+), 79 deletions(-) diff --git a/nx/include/switch/services/fatal.h b/nx/include/switch/services/fatal.h index 5b294108..80d1f6bf 100644 --- a/nx/include/switch/services/fatal.h +++ b/nx/include/switch/services/fatal.h @@ -9,10 +9,10 @@ /// Type of thrown fatal error. typedef enum { - FatalType_ErrorReportAndErrorScreen = 0, - FatalType_ErrorReport = 1, - FatalType_ErrorScreen = 2 ///< Only available with [3.0.0+]. If specified, FatalType_ErrorReportAndErrorScreen will be used instead on pre-3.0.0. -} FatalType; + FatalPolicy_ErrorReportAndErrorScreen = 0, + FatalPolicy_ErrorReport = 1, + FatalPolicy_ErrorScreen = 2 ///< Only available with [3.0.0+]. If specified, FatalPolicy_ErrorReportAndErrorScreen will be used instead on pre-3.0.0. +} FatalPolicy; /// Struct for fatal Cpu context, 64-bit. typedef struct { @@ -68,32 +68,32 @@ typedef struct { FatalAarch64Context aarch64_ctx; FatalAarch32Context aarch32_ctx; }; - + bool is_aarch32; u32 type; -} FatalContext; +} FatalCpuContext; /** * @brief Triggers a system fatal error. * @param[in] err Result code to throw. * @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] 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] type Type of 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); diff --git a/nx/source/display/default_window.c b/nx/source/display/default_window.c index 0855009c..9e0e859a 100644 --- a/nx/source/display/default_window.c +++ b/nx/source/display/default_window.c @@ -42,7 +42,7 @@ void __nx_win_init(void) viExit(); } if (R_FAILED(rc)) - fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadGfxInit)); + fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadGfxInit)); } void __nx_win_exit(void) diff --git a/nx/source/display/framebuffer.c b/nx/source/display/framebuffer.c index d6a3dc23..9a24e6a2 100644 --- a/nx/source/display/framebuffer.c +++ b/nx/source/display/framebuffer.c @@ -154,7 +154,7 @@ void* framebufferBegin(Framebuffer* fb, u32* out_stride) s32 slot; Result rc = nwindowDequeueBuffer(fb->win, &slot, NULL); if (R_FAILED(rc)) - fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadGfxDequeueBuffer)); + fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadGfxDequeueBuffer)); if (out_stride) *out_stride = fb->stride; @@ -223,5 +223,5 @@ void framebufferEnd(Framebuffer* fb) Result rc = nwindowQueueBuffer(fb->win, fb->win->cur_slot, NULL); if (R_FAILED(rc)) - fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadGfxQueueBuffer)); + fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadGfxQueueBuffer)); } diff --git a/nx/source/kernel/random.c b/nx/source/kernel/random.c index d908a753..49335da5 100644 --- a/nx/source/kernel/random.c +++ b/nx/source/kernel/random.c @@ -137,7 +137,7 @@ static void _randomInit(void) { // Get process TRNG seeds from kernel. 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()) diff --git a/nx/source/kernel/thread.c b/nx/source/kernel/thread.c index 770ca5ab..768a95b2 100644 --- a/nx/source/kernel/thread.c +++ b/nx/source/kernel/thread.c @@ -161,7 +161,7 @@ Result threadCreate( void threadExit(void) { Thread* t = getThreadVars()->thread_ptr; 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); for (s32 i = 0; i < NUM_TLS_SLOTS; i ++) { diff --git a/nx/source/kernel/virtmem.c b/nx/source/kernel/virtmem.c index 8a2b9947..7de1ee7b 100644 --- a/nx/source/kernel/virtmem.c +++ b/nx/source/kernel/virtmem.c @@ -71,16 +71,16 @@ void virtmemSetup(void) { } else { // Wat. - fatalSimple(MAKERESULT(Module_Libnx, LibnxError_WeirdKernel)); + fatalThrow(MAKERESULT(Module_Libnx, LibnxError_WeirdKernel)); } } else { 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))) { - fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadGetInfo_Heap)); + fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadGetInfo_Heap)); } _GetRegionFromInfo(&g_Region[REGION_LEGACY_ALIAS], InfoType_AliasRegionAddress, InfoType_AliasRegionSize); @@ -110,7 +110,7 @@ void* virtmemReserve(size_t size) { rc = svcQueryMemory(&meminfo, &pageinfo, addr); if (R_FAILED(rc)) { - fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadQueryMemory)); + fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadQueryMemory)); } if (meminfo.type != 0) { @@ -181,7 +181,7 @@ void* virtmemReserveStack(size_t size) rc = svcQueryMemory(&meminfo, &pageinfo, addr); if (R_FAILED(rc)) { - fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadQueryMemory)); + fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadQueryMemory)); } if (meminfo.type != 0) { diff --git a/nx/source/runtime/devices/usb_comms.c b/nx/source/runtime/devices/usb_comms.c index fab3441a..01bb2f27 100644 --- a/nx/source/runtime/devices/usb_comms.c +++ b/nx/source/runtime/devices/usb_comms.c @@ -47,14 +47,14 @@ Result usbCommsInitializeEx(u32 num_interfaces, const UsbCommsInterfaceInfo *inf { Result rc = 0; rwlockWriteLock(&g_usbCommsLock); - + if (g_usbCommsInitialized) { - rc = MAKERESULT(Module_Libnx, LibnxError_AlreadyInitialized); + rc = MAKERESULT(Module_Libnx, LibnxError_AlreadyInitialized); } else if (num_interfaces > TOTAL_INTERFACES) { rc = MAKERESULT(Module_Libnx, LibnxError_OutOfMemory); } else { rc = usbDsInitialize(); - + if (R_SUCCEEDED(rc)) { if (hosversionAtLeast(5,0,0)) { u8 iManufacturer, iProduct, iSerialNumber; @@ -67,7 +67,7 @@ Result usbCommsInitializeEx(u32 num_interfaces, const UsbCommsInterfaceInfo *inf if (R_SUCCEEDED(rc)) rc = usbDsAddUsbStringDescriptor(&iProduct, "Nintendo Switch"); // Send serial number if (R_SUCCEEDED(rc)) rc = usbDsAddUsbStringDescriptor(&iSerialNumber, "SerialNumber"); - + // Send device descriptors struct usb_device_descriptor device_descriptor = { .bLength = USB_DT_DEVICE_SIZE, @@ -87,30 +87,30 @@ Result usbCommsInitializeEx(u32 num_interfaces, const UsbCommsInterfaceInfo *inf }; // Full Speed is USB 1.1 if (R_SUCCEEDED(rc)) rc = usbDsSetUsbDeviceDescriptor(UsbDeviceSpeed_Full, &device_descriptor); - + // High Speed is USB 2.0 device_descriptor.bcdUSB = 0x0200; if (R_SUCCEEDED(rc)) rc = usbDsSetUsbDeviceDescriptor(UsbDeviceSpeed_High, &device_descriptor); - + // Super Speed is USB 3.0 device_descriptor.bcdUSB = 0x0300; // Upgrade packet size to 512 device_descriptor.bMaxPacketSize0 = 0x09; if (R_SUCCEEDED(rc)) rc = usbDsSetUsbDeviceDescriptor(UsbDeviceSpeed_Super, &device_descriptor); - + // Define Binary Object Store u8 bos[0x16] = { 0x05, // .bLength USB_DT_BOS, // .bDescriptorType 0x16, 0x00, // .wTotalLength 0x02, // .bNumDeviceCaps - + // USB 2.0 0x07, // .bLength USB_DT_DEVICE_CAPABILITY, // .bDescriptorType 0x02, // .bDevCapabilityType 0x02, 0x00, 0x00, 0x00, // dev_capability_data - + // USB 3.0 0x0A, // .bLength USB_DT_DEVICE_CAPABILITY, // .bDescriptorType @@ -119,7 +119,7 @@ Result usbCommsInitializeEx(u32 num_interfaces, const UsbCommsInterfaceInfo *inf }; if (R_SUCCEEDED(rc)) rc = usbDsSetBinaryObjectStore(bos, sizeof(bos)); } - + if (R_SUCCEEDED(rc)) { for (u32 i = 0; i < num_interfaces; i++) { usbCommsInterface *intf = &g_usbCommsInterfaces[i]; @@ -136,12 +136,12 @@ Result usbCommsInitializeEx(u32 num_interfaces, const UsbCommsInterfaceInfo *inf } } } - + if (R_SUCCEEDED(rc) && hosversionAtLeast(5,0,0)) { rc = usbDsEnable(); } } - + if (R_SUCCEEDED(rc)) { g_usbCommsInitialized = true; g_usbCommsErrorHandling = false; @@ -220,7 +220,7 @@ static Result _usbCommsInterfaceInit5x(u32 intf_ind, const UsbCommsInterfaceInfo { Result rc = 0; usbCommsInterface *interface = &g_usbCommsInterfaces[intf_ind]; - + struct usb_interface_descriptor interface_descriptor = { .bLength = USB_DT_INTERFACE_SIZE, .bDescriptorType = USB_DT_INTERFACE, @@ -247,7 +247,7 @@ static Result _usbCommsInterfaceInit5x(u32 intf_ind, const UsbCommsInterfaceInfo .bmAttributes = USB_TRANSFER_TYPE_BULK, .wMaxPacketSize = 0x40, }; - + struct usb_ss_endpoint_companion_descriptor endpoint_companion = { .bLength = sizeof(struct usb_ss_endpoint_companion_descriptor), .bDescriptorType = USB_DT_SS_ENDPOINT_COMPANION, @@ -273,14 +273,14 @@ static Result _usbCommsInterfaceInit5x(u32 intf_ind, const UsbCommsInterfaceInfo } if (R_FAILED(rc)) return rc; - + rc = usbDsRegisterInterface(&interface->interface); if (R_FAILED(rc)) return rc; - + interface_descriptor.bInterfaceNumber = interface->interface->interface_index; endpoint_descriptor_in.bEndpointAddress += interface_descriptor.bInterfaceNumber + 1; endpoint_descriptor_out.bEndpointAddress += interface_descriptor.bInterfaceNumber + 1; - + // Full Speed Config rc = usbDsInterface_AppendConfigurationData(interface->interface, UsbDeviceSpeed_Full, &interface_descriptor, USB_DT_INTERFACE_SIZE); if (R_FAILED(rc)) return rc; @@ -288,7 +288,7 @@ static Result _usbCommsInterfaceInit5x(u32 intf_ind, const UsbCommsInterfaceInfo if (R_FAILED(rc)) return rc; rc = usbDsInterface_AppendConfigurationData(interface->interface, UsbDeviceSpeed_Full, &endpoint_descriptor_out, USB_DT_ENDPOINT_SIZE); if (R_FAILED(rc)) return rc; - + // High Speed Config endpoint_descriptor_in.wMaxPacketSize = 0x200; endpoint_descriptor_out.wMaxPacketSize = 0x200; @@ -298,7 +298,7 @@ static Result _usbCommsInterfaceInit5x(u32 intf_ind, const UsbCommsInterfaceInfo if (R_FAILED(rc)) return rc; rc = usbDsInterface_AppendConfigurationData(interface->interface, UsbDeviceSpeed_High, &endpoint_descriptor_out, USB_DT_ENDPOINT_SIZE); if (R_FAILED(rc)) return rc; - + // Super Speed Config endpoint_descriptor_in.wMaxPacketSize = 0x400; endpoint_descriptor_out.wMaxPacketSize = 0x400; @@ -312,17 +312,17 @@ static Result _usbCommsInterfaceInit5x(u32 intf_ind, const UsbCommsInterfaceInfo if (R_FAILED(rc)) return rc; rc = usbDsInterface_AppendConfigurationData(interface->interface, UsbDeviceSpeed_Super, &endpoint_companion, USB_DT_SS_ENDPOINT_COMPANION_SIZE); if (R_FAILED(rc)) return rc; - - //Setup endpoints. + + //Setup endpoints. rc = usbDsInterface_RegisterEndpoint(interface->interface, &interface->endpoint_in, endpoint_descriptor_in.bEndpointAddress); if (R_FAILED(rc)) return rc; - + rc = usbDsInterface_RegisterEndpoint(interface->interface, &interface->endpoint_out, endpoint_descriptor_out.bEndpointAddress); if (R_FAILED(rc)) return rc; rc = usbDsInterface_EnableInterface(interface->interface); if (R_FAILED(rc)) return rc; - + return rc; } @@ -553,7 +553,7 @@ size_t usbCommsReadEx(void* buffer, size_t size, u32 interface) 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; } @@ -590,7 +590,7 @@ size_t usbCommsWriteEx(const void* buffer, size_t size, u32 interface) 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; } diff --git a/nx/source/runtime/dynamic.c b/nx/source/runtime/dynamic.c index f0b4794b..56b119a1 100644 --- a/nx/source/runtime/dynamic.c +++ b/nx/source/runtime/dynamic.c @@ -21,7 +21,7 @@ void __nx_dynamic(uintptr_t base, const Elf64_Dyn* dyn) } if (rela == NULL) - fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadReloc)); + fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadReloc)); for (; relasz--; rela++) { diff --git a/nx/source/runtime/env.c b/nx/source/runtime/env.c index 7d146c16..a4a4fd09 100644 --- a/nx/source/runtime/env.c +++ b/nx/source/runtime/env.c @@ -145,7 +145,7 @@ Handle envGetMainThreadHandle(void) { return g_mainThreadHandle; } - fatalSimple(MAKERESULT(Module_Libnx, LibnxError_HandleTooEarly)); + fatalThrow(MAKERESULT(Module_Libnx, LibnxError_HandleTooEarly)); } bool envIsNso(void) { diff --git a/nx/source/runtime/init.c b/nx/source/runtime/init.c index 4f7bbada..3aff48fc 100644 --- a/nx/source/runtime/init.c +++ b/nx/source/runtime/init.c @@ -87,7 +87,7 @@ void __attribute__((weak)) __libnx_initheap(void) Result rc = svcSetHeapSize(&addr, size); if (R_FAILED(rc)) - fatalSimple(MAKERESULT(Module_Libnx, LibnxError_HeapAllocFailed)); + fatalThrow(MAKERESULT(Module_Libnx, LibnxError_HeapAllocFailed)); } // Newlib @@ -108,7 +108,7 @@ void __attribute__((weak)) __appInit(void) // Initialize default services. rc = smInitialize(); if (R_FAILED(rc)) - fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_SM)); + fatalThrow(MAKERESULT(Module_Libnx, LibnxError_InitFail_SM)); if (hosversionGet() == 0) { rc = setsysInitialize(); @@ -123,23 +123,23 @@ void __attribute__((weak)) __appInit(void) rc = appletInitialize(); if (R_FAILED(rc)) - fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_AM)); + fatalThrow(MAKERESULT(Module_Libnx, LibnxError_InitFail_AM)); if (__nx_applet_type != AppletType_None) { rc = hidInitialize(); if (R_FAILED(rc)) - fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_HID)); + fatalThrow(MAKERESULT(Module_Libnx, LibnxError_InitFail_HID)); } rc = timeInitialize(); if (R_FAILED(rc)) - fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_Time)); + fatalThrow(MAKERESULT(Module_Libnx, LibnxError_InitFail_Time)); __libnx_init_time(); rc = fsInitialize(); if (R_FAILED(rc)) - fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_FS)); + fatalThrow(MAKERESULT(Module_Libnx, LibnxError_InitFail_FS)); fsdevMountSdmc(); __libnx_init_cwd(); diff --git a/nx/source/runtime/newlib.c b/nx/source/runtime/newlib.c index d3dea4e0..7f8f4a4d 100644 --- a/nx/source/runtime/newlib.c +++ b/nx/source/runtime/newlib.c @@ -59,7 +59,7 @@ struct _reent* __syscall_getreent(void) { ThreadVars* tv = getThreadVars(); if (tv->magic != THREADVARS_MAGIC) - fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadReent)); + fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadReent)); return tv->reent; } diff --git a/nx/source/services/applet.c b/nx/source/services/applet.c index 09a08ceb..b417cec0 100644 --- a/nx/source/services/applet.c +++ b/nx/source/services/applet.c @@ -168,7 +168,7 @@ Result _appletInitialize(void) { case AppletType_OverlayApplet: cmd_id = 300; break; case AppletType_SystemApplication: cmd_id = 350; break; // 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)) { @@ -1980,7 +1980,7 @@ void appletNotifyRunning(bool *out) { 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) { @@ -2714,7 +2714,7 @@ Result appletGetMessage(u32 *msg) { if (R_VALUE(rc) == MAKERESULT(128, 3)) return rc; - fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadAppletReceiveMessage)); + fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadAppletReceiveMessage)); } return 0; @@ -2732,7 +2732,7 @@ bool appletProcessMessage(u32 msg) { case AppletMessage_FocusStateChanged: rc = _appletGetCurrentFocusState(&g_appletFocusState); if (R_FAILED(rc)) - fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadAppletGetCurrentFocusState)); + fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadAppletGetCurrentFocusState)); appletCallHook(AppletHookType_OnFocusState); break; @@ -2744,7 +2744,7 @@ bool appletProcessMessage(u32 msg) { case AppletMessage_OperationModeChanged: rc = _appletGetOperationMode(&g_appletOperationMode); if (R_FAILED(rc)) - fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadAppletGetOperationMode)); + fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadAppletGetOperationMode)); appletCallHook(AppletHookType_OnOperationMode); break; @@ -2752,7 +2752,7 @@ bool appletProcessMessage(u32 msg) { case AppletMessage_PerformanceModeChanged: rc = _appletGetPerformanceMode(&g_appletPerformanceMode); if (R_FAILED(rc)) - fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadAppletGetPerformanceMode)); + fatalThrow(MAKERESULT(Module_Libnx, LibnxError_BadAppletGetPerformanceMode)); appletCallHook(AppletHookType_OnPerformanceMode); break; diff --git a/nx/source/services/fatal.c b/nx/source/services/fatal.c index e4d8ccc7..bcfa33cd 100644 --- a/nx/source/services/fatal.c +++ b/nx/source/services/fatal.c @@ -1,4 +1,3 @@ -// Copyright 2017 plutoo #define NX_SERVICE_ASSUME_NON_DOMAIN #include "types.h" #include "result.h" @@ -8,11 +7,11 @@ #include "services/fatal.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; - //Only [3.0.0+] supports FatalType_ErrorScreen, when specified on pre-3.0.0 use FatalType_ErrorReportAndErrorScreen instead. - if (type == FatalType_ErrorScreen && !kernelAbove300()) type = FatalType_ErrorReportAndErrorScreen; + //Only [3.0.0+] supports FatalPolicy_ErrorScreen, when specified on pre-3.0.0 use FatalPolicy_ErrorReportAndErrorScreen instead. + if (type == FatalPolicy_ErrorScreen && !kernelAbove300()) type = FatalPolicy_ErrorReportAndErrorScreen; if (detectDebugger()) { svcBreak(0x80000000, err, 0); @@ -43,27 +42,29 @@ static void _fatalImpl(u32 cmd_id, Result err, FatalType type, FatalContext *ctx } switch (type) { - case FatalType_ErrorReport: + case FatalPolicy_ErrorReport: break; - case FatalType_ErrorReportAndErrorScreen: - case FatalType_ErrorScreen: + case FatalPolicy_ErrorReportAndErrorScreen: + case FatalPolicy_ErrorScreen: default: svcExitProcess(); __builtin_unreachable(); } } -void NORETURN fatalSimple(Result err) { - /* By default, do not generate an error report. */ - fatalWithType(err, FatalType_ErrorScreen); +void NORETURN fatalThrow(Result err) { + // By default, do not generate an error report. + fatalThrowWithPolicy(err, FatalPolicy_ErrorScreen); svcExitProcess(); __builtin_unreachable(); } -void fatalWithType(Result err, FatalType type) { - _fatalImpl(1, err, type, NULL); +void fatalThrowWithPolicy(Result err, FatalPolicy type) { + _fatalCmd(err, type, NULL, 1); } -void fatalWithContext(Result err, FatalType type, FatalContext *ctx) { - _fatalImpl(2, err, type, ctx); +void fatalThrowWithContext(Result err, FatalPolicy type, FatalCpuContext *ctx) { + _fatalCmd(err, type, ctx, 2); } + +void NORETURN fatalSimple(Result) __attribute__((alias("fatalThrow"))); diff --git a/nx/source/services/sm.c b/nx/source/services/sm.c index e0fcca54..a2352ff4 100644 --- a/nx/source/services/sm.c +++ b/nx/source/services/sm.c @@ -15,7 +15,7 @@ static size_t g_smOverridesNum = 0; void smAddOverrideHandle(SmServiceName name, Handle handle) { if (g_smOverridesNum == MAX_OVERRIDES) - fatalSimple(MAKERESULT(Module_Libnx, LibnxError_TooManyOverrides)); + fatalThrow(MAKERESULT(Module_Libnx, LibnxError_TooManyOverrides)); size_t i = g_smOverridesNum;