mirror of
https://github.com/switchbrew/libnx.git
synced 2025-08-05 16:09:24 +02:00
fatal: Rename functions/types to match official names more closely
This commit is contained in:
parent
a808c53efc
commit
4ab2384449
@ -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 {
|
||||||
@ -68,32 +68,32 @@ typedef struct {
|
|||||||
FatalAarch64Context aarch64_ctx;
|
FatalAarch64Context aarch64_ctx;
|
||||||
FatalAarch32Context aarch32_ctx;
|
FatalAarch32Context aarch32_ctx;
|
||||||
};
|
};
|
||||||
|
|
||||||
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);
|
||||||
|
@ -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)
|
||||||
|
@ -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));
|
||||||
}
|
}
|
||||||
|
@ -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())
|
||||||
|
@ -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 ++) {
|
||||||
|
@ -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) {
|
||||||
|
@ -47,14 +47,14 @@ Result usbCommsInitializeEx(u32 num_interfaces, const UsbCommsInterfaceInfo *inf
|
|||||||
{
|
{
|
||||||
Result rc = 0;
|
Result rc = 0;
|
||||||
rwlockWriteLock(&g_usbCommsLock);
|
rwlockWriteLock(&g_usbCommsLock);
|
||||||
|
|
||||||
if (g_usbCommsInitialized) {
|
if (g_usbCommsInitialized) {
|
||||||
rc = MAKERESULT(Module_Libnx, LibnxError_AlreadyInitialized);
|
rc = MAKERESULT(Module_Libnx, LibnxError_AlreadyInitialized);
|
||||||
} else if (num_interfaces > TOTAL_INTERFACES) {
|
} else if (num_interfaces > TOTAL_INTERFACES) {
|
||||||
rc = MAKERESULT(Module_Libnx, LibnxError_OutOfMemory);
|
rc = MAKERESULT(Module_Libnx, LibnxError_OutOfMemory);
|
||||||
} else {
|
} else {
|
||||||
rc = usbDsInitialize();
|
rc = usbDsInitialize();
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) {
|
if (R_SUCCEEDED(rc)) {
|
||||||
if (hosversionAtLeast(5,0,0)) {
|
if (hosversionAtLeast(5,0,0)) {
|
||||||
u8 iManufacturer, iProduct, iSerialNumber;
|
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");
|
if (R_SUCCEEDED(rc)) rc = usbDsAddUsbStringDescriptor(&iProduct, "Nintendo Switch");
|
||||||
// Send serial number
|
// Send serial number
|
||||||
if (R_SUCCEEDED(rc)) rc = usbDsAddUsbStringDescriptor(&iSerialNumber, "SerialNumber");
|
if (R_SUCCEEDED(rc)) rc = usbDsAddUsbStringDescriptor(&iSerialNumber, "SerialNumber");
|
||||||
|
|
||||||
// Send device descriptors
|
// Send device descriptors
|
||||||
struct usb_device_descriptor device_descriptor = {
|
struct usb_device_descriptor device_descriptor = {
|
||||||
.bLength = USB_DT_DEVICE_SIZE,
|
.bLength = USB_DT_DEVICE_SIZE,
|
||||||
@ -87,30 +87,30 @@ Result usbCommsInitializeEx(u32 num_interfaces, const UsbCommsInterfaceInfo *inf
|
|||||||
};
|
};
|
||||||
// Full Speed is USB 1.1
|
// Full Speed is USB 1.1
|
||||||
if (R_SUCCEEDED(rc)) rc = usbDsSetUsbDeviceDescriptor(UsbDeviceSpeed_Full, &device_descriptor);
|
if (R_SUCCEEDED(rc)) rc = usbDsSetUsbDeviceDescriptor(UsbDeviceSpeed_Full, &device_descriptor);
|
||||||
|
|
||||||
// High Speed is USB 2.0
|
// High Speed is USB 2.0
|
||||||
device_descriptor.bcdUSB = 0x0200;
|
device_descriptor.bcdUSB = 0x0200;
|
||||||
if (R_SUCCEEDED(rc)) rc = usbDsSetUsbDeviceDescriptor(UsbDeviceSpeed_High, &device_descriptor);
|
if (R_SUCCEEDED(rc)) rc = usbDsSetUsbDeviceDescriptor(UsbDeviceSpeed_High, &device_descriptor);
|
||||||
|
|
||||||
// Super Speed is USB 3.0
|
// Super Speed is USB 3.0
|
||||||
device_descriptor.bcdUSB = 0x0300;
|
device_descriptor.bcdUSB = 0x0300;
|
||||||
// Upgrade packet size to 512
|
// Upgrade packet size to 512
|
||||||
device_descriptor.bMaxPacketSize0 = 0x09;
|
device_descriptor.bMaxPacketSize0 = 0x09;
|
||||||
if (R_SUCCEEDED(rc)) rc = usbDsSetUsbDeviceDescriptor(UsbDeviceSpeed_Super, &device_descriptor);
|
if (R_SUCCEEDED(rc)) rc = usbDsSetUsbDeviceDescriptor(UsbDeviceSpeed_Super, &device_descriptor);
|
||||||
|
|
||||||
// Define Binary Object Store
|
// Define Binary Object Store
|
||||||
u8 bos[0x16] = {
|
u8 bos[0x16] = {
|
||||||
0x05, // .bLength
|
0x05, // .bLength
|
||||||
USB_DT_BOS, // .bDescriptorType
|
USB_DT_BOS, // .bDescriptorType
|
||||||
0x16, 0x00, // .wTotalLength
|
0x16, 0x00, // .wTotalLength
|
||||||
0x02, // .bNumDeviceCaps
|
0x02, // .bNumDeviceCaps
|
||||||
|
|
||||||
// USB 2.0
|
// USB 2.0
|
||||||
0x07, // .bLength
|
0x07, // .bLength
|
||||||
USB_DT_DEVICE_CAPABILITY, // .bDescriptorType
|
USB_DT_DEVICE_CAPABILITY, // .bDescriptorType
|
||||||
0x02, // .bDevCapabilityType
|
0x02, // .bDevCapabilityType
|
||||||
0x02, 0x00, 0x00, 0x00, // dev_capability_data
|
0x02, 0x00, 0x00, 0x00, // dev_capability_data
|
||||||
|
|
||||||
// USB 3.0
|
// USB 3.0
|
||||||
0x0A, // .bLength
|
0x0A, // .bLength
|
||||||
USB_DT_DEVICE_CAPABILITY, // .bDescriptorType
|
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)) rc = usbDsSetBinaryObjectStore(bos, sizeof(bos));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) {
|
if (R_SUCCEEDED(rc)) {
|
||||||
for (u32 i = 0; i < num_interfaces; i++) {
|
for (u32 i = 0; i < num_interfaces; i++) {
|
||||||
usbCommsInterface *intf = &g_usbCommsInterfaces[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)) {
|
if (R_SUCCEEDED(rc) && hosversionAtLeast(5,0,0)) {
|
||||||
rc = usbDsEnable();
|
rc = usbDsEnable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) {
|
if (R_SUCCEEDED(rc)) {
|
||||||
g_usbCommsInitialized = true;
|
g_usbCommsInitialized = true;
|
||||||
g_usbCommsErrorHandling = false;
|
g_usbCommsErrorHandling = false;
|
||||||
@ -220,7 +220,7 @@ static Result _usbCommsInterfaceInit5x(u32 intf_ind, const UsbCommsInterfaceInfo
|
|||||||
{
|
{
|
||||||
Result rc = 0;
|
Result rc = 0;
|
||||||
usbCommsInterface *interface = &g_usbCommsInterfaces[intf_ind];
|
usbCommsInterface *interface = &g_usbCommsInterfaces[intf_ind];
|
||||||
|
|
||||||
struct usb_interface_descriptor interface_descriptor = {
|
struct usb_interface_descriptor interface_descriptor = {
|
||||||
.bLength = USB_DT_INTERFACE_SIZE,
|
.bLength = USB_DT_INTERFACE_SIZE,
|
||||||
.bDescriptorType = USB_DT_INTERFACE,
|
.bDescriptorType = USB_DT_INTERFACE,
|
||||||
@ -247,7 +247,7 @@ static Result _usbCommsInterfaceInit5x(u32 intf_ind, const UsbCommsInterfaceInfo
|
|||||||
.bmAttributes = USB_TRANSFER_TYPE_BULK,
|
.bmAttributes = USB_TRANSFER_TYPE_BULK,
|
||||||
.wMaxPacketSize = 0x40,
|
.wMaxPacketSize = 0x40,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct usb_ss_endpoint_companion_descriptor endpoint_companion = {
|
struct usb_ss_endpoint_companion_descriptor endpoint_companion = {
|
||||||
.bLength = sizeof(struct usb_ss_endpoint_companion_descriptor),
|
.bLength = sizeof(struct usb_ss_endpoint_companion_descriptor),
|
||||||
.bDescriptorType = USB_DT_SS_ENDPOINT_COMPANION,
|
.bDescriptorType = USB_DT_SS_ENDPOINT_COMPANION,
|
||||||
@ -273,14 +273,14 @@ static Result _usbCommsInterfaceInit5x(u32 intf_ind, const UsbCommsInterfaceInfo
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (R_FAILED(rc)) return rc;
|
if (R_FAILED(rc)) return rc;
|
||||||
|
|
||||||
rc = usbDsRegisterInterface(&interface->interface);
|
rc = usbDsRegisterInterface(&interface->interface);
|
||||||
if (R_FAILED(rc)) return rc;
|
if (R_FAILED(rc)) return rc;
|
||||||
|
|
||||||
interface_descriptor.bInterfaceNumber = interface->interface->interface_index;
|
interface_descriptor.bInterfaceNumber = interface->interface->interface_index;
|
||||||
endpoint_descriptor_in.bEndpointAddress += interface_descriptor.bInterfaceNumber + 1;
|
endpoint_descriptor_in.bEndpointAddress += interface_descriptor.bInterfaceNumber + 1;
|
||||||
endpoint_descriptor_out.bEndpointAddress += interface_descriptor.bInterfaceNumber + 1;
|
endpoint_descriptor_out.bEndpointAddress += interface_descriptor.bInterfaceNumber + 1;
|
||||||
|
|
||||||
// Full Speed Config
|
// Full Speed Config
|
||||||
rc = usbDsInterface_AppendConfigurationData(interface->interface, UsbDeviceSpeed_Full, &interface_descriptor, USB_DT_INTERFACE_SIZE);
|
rc = usbDsInterface_AppendConfigurationData(interface->interface, UsbDeviceSpeed_Full, &interface_descriptor, USB_DT_INTERFACE_SIZE);
|
||||||
if (R_FAILED(rc)) return rc;
|
if (R_FAILED(rc)) return rc;
|
||||||
@ -288,7 +288,7 @@ static Result _usbCommsInterfaceInit5x(u32 intf_ind, const UsbCommsInterfaceInfo
|
|||||||
if (R_FAILED(rc)) return rc;
|
if (R_FAILED(rc)) return rc;
|
||||||
rc = usbDsInterface_AppendConfigurationData(interface->interface, UsbDeviceSpeed_Full, &endpoint_descriptor_out, USB_DT_ENDPOINT_SIZE);
|
rc = usbDsInterface_AppendConfigurationData(interface->interface, UsbDeviceSpeed_Full, &endpoint_descriptor_out, USB_DT_ENDPOINT_SIZE);
|
||||||
if (R_FAILED(rc)) return rc;
|
if (R_FAILED(rc)) return rc;
|
||||||
|
|
||||||
// High Speed Config
|
// High Speed Config
|
||||||
endpoint_descriptor_in.wMaxPacketSize = 0x200;
|
endpoint_descriptor_in.wMaxPacketSize = 0x200;
|
||||||
endpoint_descriptor_out.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;
|
if (R_FAILED(rc)) return rc;
|
||||||
rc = usbDsInterface_AppendConfigurationData(interface->interface, UsbDeviceSpeed_High, &endpoint_descriptor_out, USB_DT_ENDPOINT_SIZE);
|
rc = usbDsInterface_AppendConfigurationData(interface->interface, UsbDeviceSpeed_High, &endpoint_descriptor_out, USB_DT_ENDPOINT_SIZE);
|
||||||
if (R_FAILED(rc)) return rc;
|
if (R_FAILED(rc)) return rc;
|
||||||
|
|
||||||
// Super Speed Config
|
// Super Speed Config
|
||||||
endpoint_descriptor_in.wMaxPacketSize = 0x400;
|
endpoint_descriptor_in.wMaxPacketSize = 0x400;
|
||||||
endpoint_descriptor_out.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;
|
if (R_FAILED(rc)) return rc;
|
||||||
rc = usbDsInterface_AppendConfigurationData(interface->interface, UsbDeviceSpeed_Super, &endpoint_companion, USB_DT_SS_ENDPOINT_COMPANION_SIZE);
|
rc = usbDsInterface_AppendConfigurationData(interface->interface, UsbDeviceSpeed_Super, &endpoint_companion, USB_DT_SS_ENDPOINT_COMPANION_SIZE);
|
||||||
if (R_FAILED(rc)) return rc;
|
if (R_FAILED(rc)) return rc;
|
||||||
|
|
||||||
//Setup endpoints.
|
//Setup endpoints.
|
||||||
rc = usbDsInterface_RegisterEndpoint(interface->interface, &interface->endpoint_in, endpoint_descriptor_in.bEndpointAddress);
|
rc = usbDsInterface_RegisterEndpoint(interface->interface, &interface->endpoint_in, endpoint_descriptor_in.bEndpointAddress);
|
||||||
if (R_FAILED(rc)) return rc;
|
if (R_FAILED(rc)) return rc;
|
||||||
|
|
||||||
rc = usbDsInterface_RegisterEndpoint(interface->interface, &interface->endpoint_out, endpoint_descriptor_out.bEndpointAddress);
|
rc = usbDsInterface_RegisterEndpoint(interface->interface, &interface->endpoint_out, endpoint_descriptor_out.bEndpointAddress);
|
||||||
if (R_FAILED(rc)) return rc;
|
if (R_FAILED(rc)) return rc;
|
||||||
|
|
||||||
rc = usbDsInterface_EnableInterface(interface->interface);
|
rc = usbDsInterface_EnableInterface(interface->interface);
|
||||||
if (R_FAILED(rc)) return rc;
|
if (R_FAILED(rc)) return rc;
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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++)
|
||||||
{
|
{
|
||||||
|
@ -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) {
|
||||||
|
@ -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();
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
@ -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")));
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user