mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-21 04:22:50 +02:00
Introducing fatal
This commit is contained in:
parent
5ef41f9e07
commit
6e84dee135
@ -18,6 +18,7 @@ extern "C" {
|
||||
|
||||
#include <switch/services/sm.h>
|
||||
#include <switch/services/bsd.h>
|
||||
#include <switch/services/fatal.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -17,3 +17,6 @@
|
||||
/// Builds a result code from its constituent components.
|
||||
#define MAKERESULT(module,description) \
|
||||
((((module)&0x1FF)) | ((description)&0x1FFF)<<9)
|
||||
|
||||
#define MODULE_LIBNX 345
|
||||
#define MODULE_BADRELOC 1
|
||||
|
1
nx/include/switch/services/fatal.h
Normal file
1
nx/include/switch/services/fatal.h
Normal file
@ -0,0 +1 @@
|
||||
void fatalSimple(Result err);
|
@ -1,2 +1,3 @@
|
||||
bool smHasInitialized();
|
||||
Result smInitialize();
|
||||
Result smGetService(Handle* handle_out, const char* name);
|
||||
|
39
nx/source/services/fatal.c
Normal file
39
nx/source/services/fatal.c
Normal file
@ -0,0 +1,39 @@
|
||||
// Copyright 2017 plutoo
|
||||
#include <switch.h>
|
||||
|
||||
void fatalSimple(Result err) {
|
||||
Result rc = 0;
|
||||
|
||||
if (!smHasInitialized()) {
|
||||
rc = smInitialize();
|
||||
}
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
Handle srv;
|
||||
rc = smGetService(&srv, "fatal:u");
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
ipcSendPid(&c);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
u64 result;
|
||||
u64 unknown;
|
||||
} *raw;
|
||||
|
||||
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 1;
|
||||
raw->result = err;
|
||||
raw->unknown = 0;
|
||||
|
||||
ipcDispatch(srv);
|
||||
}
|
||||
}
|
||||
|
||||
((void(*)())0xBADC0DE)();
|
||||
}
|
@ -3,6 +3,10 @@
|
||||
|
||||
static Handle g_smHandle = -1;
|
||||
|
||||
bool smHasInitialized() {
|
||||
return g_smHandle != -1;
|
||||
}
|
||||
|
||||
Result smInitialize() {
|
||||
Result rc = svcConnectToNamedPort(&g_smHandle, "sm:");
|
||||
Handle tmp;
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include <switch/types.h>
|
||||
#include <switch.h>
|
||||
#include <elf.h>
|
||||
|
||||
void __nx_dynamic(uintptr_t base, const Elf64_Dyn* dyn)
|
||||
@ -20,7 +20,7 @@ void __nx_dynamic(uintptr_t base, const Elf64_Dyn* dyn)
|
||||
}
|
||||
|
||||
if (rela == NULL)
|
||||
for (;;); // Panic
|
||||
fatalSimple(MAKERESULT(MODULE_LIBNX, MODULE_BADRELOC));
|
||||
|
||||
for (; relasz--; rela++)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user