1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-28 21:26:14 +00:00

Merge branch 'master' into emunand_dev

This commit is contained in:
hexkyz 2019-06-03 20:14:22 +01:00
commit 4c328b6c50
10 changed files with 407 additions and 169 deletions

View file

@ -19,6 +19,16 @@ Atmosphère consists of multiple components, each of which replaces/modifies a d
* Stratosphère: Custom Sysmodule(s), both Rosalina style to extend the kernel/provide new features, and of the loader reimplementation style to hook important system actions * Stratosphère: Custom Sysmodule(s), both Rosalina style to extend the kernel/provide new features, and of the loader reimplementation style to hook important system actions
* Troposphère: Application-level Horizon OS patches, used to implement desirable CFW features * Troposphère: Application-level Horizon OS patches, used to implement desirable CFW features
Licensing
=====
This software is licensed under the terms of the GPLv2, with exemptions for specific projects noted below.
You can find a copy of the license in the [LICENSE file](LICENSE).
Exemptions:
* The [yuzu emulator project](https://github.com/yuzu-emu/yuzu) is exempt from GPLv2 licensing and may (at its option) instead license any source code authored for the Atmosphère project as GPLv2 or later.
Credits Credits
===== =====

View file

@ -17,9 +17,15 @@
#pragma once #pragma once
#include <switch.h> #include <switch.h>
struct StackFrame { union StackFrame {
u64 fp; struct {
u64 lr; u64 fp;
u64 lr;
} frame_64;
struct {
u32 fp;
u32 lr;
} frame_32;
}; };
struct AttachProcessInfo { struct AttachProcessInfo {

View file

@ -75,9 +75,11 @@ bool ThreadInfo::ReadFromProcess(std::map<u64, u64> &tls_map, Handle debug_handl
return false; return false;
} }
/* Don't try to parse stack frames if 32-bit. */ /* In AArch32 mode the LR, FP, and SP registers aren't set correctly in the ThreadContext by svcGetDebugThreadParam... */
if (!is_64_bit) { if (!is_64_bit) {
return true; this->context.fp = this->context.cpu_gprs[11].x;
this->context.sp = this->context.cpu_gprs[13].x;
this->context.lr = this->context.cpu_gprs[14].x;
} }
/* Parse information from TLS if present. */ /* Parse information from TLS if present. */
@ -104,21 +106,41 @@ bool ThreadInfo::ReadFromProcess(std::map<u64, u64> &tls_map, Handle debug_handl
TryGetStackInfo(debug_handle); TryGetStackInfo(debug_handle);
u64 cur_fp = this->context.fp; u64 cur_fp = this->context.fp;
for (unsigned int i = 0; i < sizeof(this->stack_trace)/sizeof(u64); i++) {
/* Validate the current frame. */
if (cur_fp == 0 || (cur_fp & 0xF)) {
break;
}
/* Read a new frame. */ if (is_64_bit) {
StackFrame cur_frame; for (unsigned int i = 0; i < sizeof(this->stack_trace)/sizeof(u64); i++) {
if (R_FAILED(svcReadDebugProcessMemory(&cur_frame, debug_handle, cur_fp, sizeof(StackFrame)))) { /* Validate the current frame. */
break; if (cur_fp == 0 || (cur_fp & 0xF)) {
} break;
}
/* Advance to the next frame. */ /* Read a new frame. */
this->stack_trace[this->stack_trace_size++] = cur_frame.lr; StackFrame cur_frame;
cur_fp = cur_frame.fp; if (R_FAILED(svcReadDebugProcessMemory(&cur_frame, debug_handle, cur_fp, sizeof(cur_frame.frame_64)))) {
break;
}
/* Advance to the next frame. */
this->stack_trace[this->stack_trace_size++] = cur_frame.frame_64.lr;
cur_fp = cur_frame.frame_64.fp;
}
} else {
for (unsigned int i = 0; i < sizeof(this->stack_trace)/sizeof(u64); i++) {
/* Validate the current frame. */
if (cur_fp == 0 || (cur_fp & 0x7)) {
break;
}
/* Read a new frame. */
StackFrame cur_frame;
if (R_FAILED(svcReadDebugProcessMemory(&cur_frame, debug_handle, cur_fp, sizeof(cur_frame.frame_32)))) {
break;
}
/* Advance to the next frame. */
this->stack_trace[this->stack_trace_size++] = cur_frame.frame_32.lr;
cur_fp = cur_frame.frame_32.fp;
}
} }
return true; return true;

View file

@ -14,12 +14,27 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <sys/stat.h>
#include <switch.h> #include <switch.h>
#include "dmnt_cheat_types.hpp" #include "dmnt_cheat_types.hpp"
#include "dmnt_cheat_vm.hpp" #include "dmnt_cheat_vm.hpp"
#include "dmnt_cheat_manager.hpp" #include "dmnt_cheat_manager.hpp"
#include "dmnt_hid.hpp" #include "dmnt_hid.hpp"
void DmntCheatVm::DebugLog(u32 log_id, u64 value) {
/* Just unconditionally try to create the log folder. */
mkdir("/atmosphere/cheat_vm_logs", 0777);
FILE *f_log = NULL;
{
char log_path[FS_MAX_PATH];
snprintf(log_path, sizeof(log_path), "/atmosphere/cheat_vm_logs/%x.log", log_id);
f_log = fopen(log_path, "ab");
}
if (f_log != NULL) {
ON_SCOPE_EXIT { fclose(f_log); };
fprintf(f_log, "%016lx\n", value);
}
}
void DmntCheatVm::OpenDebugLogFile() { void DmntCheatVm::OpenDebugLogFile() {
#ifdef DMNT_CHEAT_VM_DEBUG_LOG #ifdef DMNT_CHEAT_VM_DEBUG_LOG
@ -157,36 +172,36 @@ void DmntCheatVm::LogOpcode(const CheatVmOpcode *opcode) {
this->LogToDebugFile("Bit Width: %x\n", opcode->begin_reg_cond.bit_width); this->LogToDebugFile("Bit Width: %x\n", opcode->begin_reg_cond.bit_width);
this->LogToDebugFile("Cond Type: %x\n", opcode->begin_reg_cond.cond_type); this->LogToDebugFile("Cond Type: %x\n", opcode->begin_reg_cond.cond_type);
this->LogToDebugFile("V Reg Idx: %x\n", opcode->begin_reg_cond.val_reg_index); this->LogToDebugFile("V Reg Idx: %x\n", opcode->begin_reg_cond.val_reg_index);
switch (opcode->begin_reg_cond.comp_type) { switch (opcode->begin_reg_cond.comp_type) {
case CompareRegisterValueType_StaticValue: case CompareRegisterValueType_StaticValue:
this->LogToDebugFile("Comp Type: Static Value\n"); this->LogToDebugFile("Comp Type: Static Value\n");
this->LogToDebugFile("Value: %lx\n", opcode->begin_reg_cond.value.bit64); this->LogToDebugFile("Value: %lx\n", opcode->begin_reg_cond.value.bit64);
break; break;
case CompareRegisterValueType_OtherRegister: case CompareRegisterValueType_OtherRegister:
this->LogToDebugFile("Comp Type: Other Register\n"); this->LogToDebugFile("Comp Type: Other Register\n");
this->LogToDebugFile("X Reg Idx: %x\n", opcode->begin_reg_cond.other_reg_index); this->LogToDebugFile("X Reg Idx: %x\n", opcode->begin_reg_cond.other_reg_index);
break; break;
case CompareRegisterValueType_MemoryRelAddr: case CompareRegisterValueType_MemoryRelAddr:
this->LogToDebugFile("Comp Type: Memory Relative Address\n"); this->LogToDebugFile("Comp Type: Memory Relative Address\n");
this->LogToDebugFile("Mem Type: %x\n", opcode->begin_reg_cond.mem_type); this->LogToDebugFile("Mem Type: %x\n", opcode->begin_reg_cond.mem_type);
this->LogToDebugFile("Rel Addr: %lx\n", opcode->begin_reg_cond.rel_address); this->LogToDebugFile("Rel Addr: %lx\n", opcode->begin_reg_cond.rel_address);
break; break;
case CompareRegisterValueType_MemoryOfsReg: case CompareRegisterValueType_MemoryOfsReg:
this->LogToDebugFile("Comp Type: Memory Offset Register\n"); this->LogToDebugFile("Comp Type: Memory Offset Register\n");
this->LogToDebugFile("Mem Type: %x\n", opcode->begin_reg_cond.mem_type); this->LogToDebugFile("Mem Type: %x\n", opcode->begin_reg_cond.mem_type);
this->LogToDebugFile("O Reg Idx: %x\n", opcode->begin_reg_cond.ofs_reg_index); this->LogToDebugFile("O Reg Idx: %x\n", opcode->begin_reg_cond.ofs_reg_index);
break; break;
case CompareRegisterValueType_RegisterRelAddr: case CompareRegisterValueType_RegisterRelAddr:
this->LogToDebugFile("Comp Type: Register Relative Address\n"); this->LogToDebugFile("Comp Type: Register Relative Address\n");
this->LogToDebugFile("A Reg Idx: %x\n", opcode->begin_reg_cond.addr_reg_index); this->LogToDebugFile("A Reg Idx: %x\n", opcode->begin_reg_cond.addr_reg_index);
this->LogToDebugFile("Rel Addr: %lx\n", opcode->begin_reg_cond.rel_address); this->LogToDebugFile("Rel Addr: %lx\n", opcode->begin_reg_cond.rel_address);
break; break;
case CompareRegisterValueType_RegisterOfsReg: case CompareRegisterValueType_RegisterOfsReg:
this->LogToDebugFile("Comp Type: Register Offset Register\n"); this->LogToDebugFile("Comp Type: Register Offset Register\n");
this->LogToDebugFile("A Reg Idx: %x\n", opcode->begin_reg_cond.addr_reg_index); this->LogToDebugFile("A Reg Idx: %x\n", opcode->begin_reg_cond.addr_reg_index);
this->LogToDebugFile("O Reg Idx: %x\n", opcode->begin_reg_cond.ofs_reg_index); this->LogToDebugFile("O Reg Idx: %x\n", opcode->begin_reg_cond.ofs_reg_index);
break; break;
} }
break; break;
case CheatVmOpcodeType_SaveRestoreRegister: case CheatVmOpcodeType_SaveRestoreRegister:
this->LogToDebugFile("Opcode: Save or Restore Register\n"); this->LogToDebugFile("Opcode: Save or Restore Register\n");
@ -201,6 +216,37 @@ void DmntCheatVm::LogOpcode(const CheatVmOpcode *opcode) {
this->LogToDebugFile("Act[%02x]: %d\n", i, opcode->save_restore_regmask.should_operate[i]); this->LogToDebugFile("Act[%02x]: %d\n", i, opcode->save_restore_regmask.should_operate[i]);
} }
break; break;
case CheatVmOpcodeType_DebugLog:
this->LogToDebugFile("Opcode: Debug Log\n");
this->LogToDebugFile("Bit Width: %x\n", opcode->debug_log.bit_width);
this->LogToDebugFile("Log ID: %x\n", opcode->debug_log.log_id);
this->LogToDebugFile("Val Type: %x\n", opcode->debug_log.val_type);
switch (opcode->debug_log.val_type) {
case DebugLogValueType_RegisterValue:
this->LogToDebugFile("Val Type: Register Value\n");
this->LogToDebugFile("X Reg Idx: %x\n", opcode->debug_log.val_reg_index);
break;
case DebugLogValueType_MemoryRelAddr:
this->LogToDebugFile("Val Type: Memory Relative Address\n");
this->LogToDebugFile("Mem Type: %x\n", opcode->debug_log.mem_type);
this->LogToDebugFile("Rel Addr: %lx\n", opcode->debug_log.rel_address);
break;
case DebugLogValueType_MemoryOfsReg:
this->LogToDebugFile("Val Type: Memory Offset Register\n");
this->LogToDebugFile("Mem Type: %x\n", opcode->debug_log.mem_type);
this->LogToDebugFile("O Reg Idx: %x\n", opcode->debug_log.ofs_reg_index);
break;
case DebugLogValueType_RegisterRelAddr:
this->LogToDebugFile("Val Type: Register Relative Address\n");
this->LogToDebugFile("A Reg Idx: %x\n", opcode->debug_log.addr_reg_index);
this->LogToDebugFile("Rel Addr: %lx\n", opcode->debug_log.rel_address);
break;
case DebugLogValueType_RegisterOfsReg:
this->LogToDebugFile("Val Type: Register Offset Register\n");
this->LogToDebugFile("A Reg Idx: %x\n", opcode->debug_log.addr_reg_index);
this->LogToDebugFile("O Reg Idx: %x\n", opcode->debug_log.ofs_reg_index);
break;
}
default: default:
this->LogToDebugFile("Unknown opcode: %x\n", opcode->opcode); this->LogToDebugFile("Unknown opcode: %x\n", opcode->opcode);
break; break;
@ -260,6 +306,9 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode *out) {
if (opcode.opcode >= CheatVmOpcodeType_ExtendedWidth) { if (opcode.opcode >= CheatVmOpcodeType_ExtendedWidth) {
opcode.opcode = (CheatVmOpcodeType)((((u32)opcode.opcode) << 4) | ((first_dword >> 24) & 0xF)); opcode.opcode = (CheatVmOpcodeType)((((u32)opcode.opcode) << 4) | ((first_dword >> 24) & 0xF));
} }
if (opcode.opcode >= CheatVmOpcodeType_DoubleExtendedWidth) {
opcode.opcode = (CheatVmOpcodeType)((((u32)opcode.opcode) << 4) | ((first_dword >> 20) & 0xF));
}
/* detect condition start. */ /* detect condition start. */
switch (opcode.opcode) { switch (opcode.opcode) {
@ -500,7 +549,53 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode *out) {
} }
} }
break; break;
case CheatVmOpcodeType_DebugLog:
{
/* FFFTIX## */
/* FFFTI0Ma aaaaaaaa */
/* FFFTI1Mr */
/* FFFTI2Ra aaaaaaaa */
/* FFFTI3Rr */
/* FFFTI4X0 */
/* FFF = opcode 0xFFF */
/* T = bit width. */
/* I = log id. */
/* X = value operand type, 0 = main/heap with relative offset, 1 = main/heap with offset register, */
/* 2 = register with relative offset, 3 = register with offset register, 4 = register value. */
/* M = memory type. */
/* R = address register. */
/* a = relative address. */
/* r = offset register. */
/* X = value register. */
opcode.debug_log.bit_width = (first_dword >> 16) & 0xF;
opcode.debug_log.log_id = ((first_dword >> 12) & 0xF);
opcode.debug_log.val_type = (DebugLogValueType)((first_dword >> 8) & 0xF);
switch (opcode.debug_log.val_type) {
case DebugLogValueType_RegisterValue:
opcode.debug_log.val_reg_index = ((first_dword >> 4) & 0xF);
break;
case DebugLogValueType_MemoryRelAddr:
opcode.debug_log.mem_type = (MemoryAccessType)((first_dword >> 4) & 0xF);
opcode.debug_log.rel_address = (((u64)(first_dword & 0xF) << 32ul) | ((u64)GetNextDword()));
break;
case DebugLogValueType_MemoryOfsReg:
opcode.debug_log.mem_type = (MemoryAccessType)((first_dword >> 4) & 0xF);
opcode.debug_log.ofs_reg_index = (first_dword & 0xF);
break;
case DebugLogValueType_RegisterRelAddr:
opcode.debug_log.addr_reg_index = ((first_dword >> 4) & 0xF);
opcode.debug_log.rel_address = (((u64)(first_dword & 0xF) << 32ul) | ((u64)GetNextDword()));
break;
case DebugLogValueType_RegisterOfsReg:
opcode.debug_log.addr_reg_index = ((first_dword >> 4) & 0xF);
opcode.debug_log.ofs_reg_index = (first_dword & 0xF);
break;
}
}
break;
case CheatVmOpcodeType_ExtendedWidth: case CheatVmOpcodeType_ExtendedWidth:
case CheatVmOpcodeType_DoubleExtendedWidth:
default: default:
/* Unrecognized instruction cannot be decoded. */ /* Unrecognized instruction cannot be decoded. */
valid = false; valid = false;
@ -1058,6 +1153,57 @@ void DmntCheatVm::Execute(const CheatProcessMetadata *metadata) {
} }
} }
break; break;
case CheatVmOpcodeType_DebugLog:
{
/* Read value from memory. */
u64 log_value = 0;
if (cur_opcode.debug_log.val_type == DebugLogValueType_RegisterValue) {
switch (cur_opcode.debug_log.bit_width) {
case 1:
log_value = static_cast<u8>(this->registers[cur_opcode.debug_log.val_reg_index] & 0xFFul);
break;
case 2:
log_value = static_cast<u16>(this->registers[cur_opcode.debug_log.val_reg_index] & 0xFFFFul);
break;
case 4:
log_value = static_cast<u32>(this->registers[cur_opcode.debug_log.val_reg_index] & 0xFFFFFFFFul);
break;
case 8:
log_value = static_cast<u64>(this->registers[cur_opcode.debug_log.val_reg_index] & 0xFFFFFFFFFFFFFFFFul);
break;
}
} else {
u64 val_address = 0;
switch (cur_opcode.debug_log.val_type) {
case DebugLogValueType_MemoryRelAddr:
val_address = GetCheatProcessAddress(metadata, cur_opcode.debug_log.mem_type, cur_opcode.debug_log.rel_address);
break;
case DebugLogValueType_MemoryOfsReg:
val_address = GetCheatProcessAddress(metadata, cur_opcode.debug_log.mem_type, this->registers[cur_opcode.debug_log.ofs_reg_index]);
break;
case DebugLogValueType_RegisterRelAddr:
val_address = this->registers[cur_opcode.debug_log.addr_reg_index] + cur_opcode.debug_log.rel_address;
break;
case DebugLogValueType_RegisterOfsReg:
val_address = this->registers[cur_opcode.debug_log.addr_reg_index] + this->registers[cur_opcode.debug_log.ofs_reg_index];
break;
default:
break;
}
switch (cur_opcode.debug_log.bit_width) {
case 1:
case 2:
case 4:
case 8:
DmntCheatManager::ReadCheatProcessMemoryForVm(val_address, &log_value, cur_opcode.debug_log.bit_width);
break;
}
}
/* Log value. */
this->DebugLog(cur_opcode.debug_log.log_id, log_value);
}
break;
default: default:
/* By default, we do a no-op. */ /* By default, we do a no-op. */
break; break;

View file

@ -45,6 +45,13 @@ enum CheatVmOpcodeType : u32 {
CheatVmOpcodeType_BeginRegisterConditionalBlock = 0xC0, CheatVmOpcodeType_BeginRegisterConditionalBlock = 0xC0,
CheatVmOpcodeType_SaveRestoreRegister = 0xC1, CheatVmOpcodeType_SaveRestoreRegister = 0xC1,
CheatVmOpcodeType_SaveRestoreRegisterMask = 0xC2, CheatVmOpcodeType_SaveRestoreRegisterMask = 0xC2,
/* This is a meta entry, and not a real opcode. */
/* This is to facilitate multi-nybble instruction decoding. */
CheatVmOpcodeType_DoubleExtendedWidth = 0xF0,
/* Double-extended width opcodes. */
CheatVmOpcodeType_DebugLog = 0xFFF,
}; };
enum MemoryAccessType : u32 { enum MemoryAccessType : u32 {
@ -102,6 +109,14 @@ enum SaveRestoreRegisterOpType : u32 {
SaveRestoreRegisterOpType_ClearRegs = 3, SaveRestoreRegisterOpType_ClearRegs = 3,
}; };
enum DebugLogValueType : u32 {
DebugLogValueType_MemoryRelAddr = 0,
DebugLogValueType_MemoryOfsReg = 1,
DebugLogValueType_RegisterRelAddr = 2,
DebugLogValueType_RegisterOfsReg = 3,
DebugLogValueType_RegisterValue = 4,
};
union VmInt { union VmInt {
u8 bit8; u8 bit8;
u16 bit16; u16 bit16;
@ -211,6 +226,17 @@ struct SaveRestoreRegisterMaskOpcode {
bool should_operate[0x10]; bool should_operate[0x10];
}; };
struct DebugLogOpcode {
u32 bit_width;
u32 log_id;
DebugLogValueType val_type;
MemoryAccessType mem_type;
u32 addr_reg_index;
u32 val_reg_index;
u32 ofs_reg_index;
u64 rel_address;
};
struct CheatVmOpcode { struct CheatVmOpcode {
CheatVmOpcodeType opcode; CheatVmOpcodeType opcode;
bool begin_conditional_block; bool begin_conditional_block;
@ -229,6 +255,7 @@ struct CheatVmOpcode {
BeginRegisterConditionalOpcode begin_reg_cond; BeginRegisterConditionalOpcode begin_reg_cond;
SaveRestoreRegisterOpcode save_restore_reg; SaveRestoreRegisterOpcode save_restore_reg;
SaveRestoreRegisterMaskOpcode save_restore_regmask; SaveRestoreRegisterMaskOpcode save_restore_regmask;
DebugLogOpcode debug_log;
}; };
}; };
@ -250,6 +277,9 @@ class DmntCheatVm {
void SkipConditionalBlock(); void SkipConditionalBlock();
void ResetState(); void ResetState();
/* For implementing the DebugLog opcode. */
void DebugLog(u32 log_id, u64 value);
/* For debugging. These will be IFDEF'd out normally. */ /* For debugging. These will be IFDEF'd out normally. */
void OpenDebugLogFile(); void OpenDebugLogFile();
void CloseDebugLogFile(); void CloseDebugLogFile();

View file

@ -35,6 +35,7 @@ static std::atomic<u64> g_debug_on_launch_tid(0);
static IEvent *g_process_event = nullptr; static IEvent *g_process_event = nullptr;
static IEvent *g_debug_title_event = nullptr; static IEvent *g_debug_title_event = nullptr;
static IEvent *g_debug_application_event = nullptr; static IEvent *g_debug_application_event = nullptr;
static IEvent *g_boot_finished_event = nullptr;
static u8 g_ac_buf[4 * sizeof(LoaderProgramInfo)]; static u8 g_ac_buf[4 * sizeof(LoaderProgramInfo)];
@ -46,6 +47,7 @@ void Registration::InitializeSystemResources() {
g_process_event = CreateWriteOnlySystemEvent(); g_process_event = CreateWriteOnlySystemEvent();
g_debug_title_event = CreateWriteOnlySystemEvent(); g_debug_title_event = CreateWriteOnlySystemEvent();
g_debug_application_event = CreateWriteOnlySystemEvent(); g_debug_application_event = CreateWriteOnlySystemEvent();
g_boot_finished_event = CreateWriteOnlySystemEvent();
/* Auto-clear non-system event. */ /* Auto-clear non-system event. */
g_process_launch_start_event = CreateHosEvent(&Registration::ProcessLaunchStartCallback); g_process_launch_start_event = CreateHosEvent(&Registration::ProcessLaunchStartCallback);
@ -501,3 +503,19 @@ Result Registration::DisableDebug(u32 which) {
} }
return ResultSuccess; return ResultSuccess;
} }
Handle Registration::GetDebugTitleEventHandle() {
return g_debug_title_event->GetHandle();
}
Handle Registration::GetDebugApplicationEventHandle() {
return g_debug_application_event->GetHandle();
}
Handle Registration::GetBootFinishedEventHandle() {
return g_boot_finished_event->GetHandle();
}
void Registration::SignalBootFinished() {
g_boot_finished_event->Signal();
}

View file

@ -193,6 +193,7 @@ class Registration {
static Result DisableDebug(u32 which); static Result DisableDebug(u32 which);
static Handle GetDebugTitleEventHandle(); static Handle GetDebugTitleEventHandle();
static Handle GetDebugApplicationEventHandle(); static Handle GetDebugApplicationEventHandle();
static Handle GetBootFinishedEventHandle();
static void HandleProcessLaunch(); static void HandleProcessLaunch();
static Result LaunchDebugProcess(u64 pid); static Result LaunchDebugProcess(u64 pid);
@ -200,6 +201,8 @@ class Registration {
static Result LaunchProcess(u64 title_id, FsStorageId storage_id, u64 launch_flags, u64 *out_pid); static Result LaunchProcess(u64 title_id, FsStorageId storage_id, u64 launch_flags, u64 *out_pid);
static Result LaunchProcessByTidSid(TidSid tid_sid, u64 launch_flags, u64 *out_pid); static Result LaunchProcessByTidSid(TidSid tid_sid, u64 launch_flags, u64 *out_pid);
static void SignalBootFinished();
static bool HasApplicationProcess(std::shared_ptr<Process> *out); static bool HasApplicationProcess(std::shared_ptr<Process> *out);
}; };

View file

@ -86,6 +86,7 @@ Result ShellService::ClearProcessNotificationFlag(u64 pid) {
void ShellService::NotifyBootFinished() { void ShellService::NotifyBootFinished() {
if (!g_has_boot_finished) { if (!g_has_boot_finished) {
g_has_boot_finished = true; g_has_boot_finished = true;
Registration::SignalBootFinished();
EmbeddedBoot2::Main(); EmbeddedBoot2::Main();
} }
} }
@ -113,13 +114,15 @@ Result ShellService::BoostSystemThreadsResourceLimit() {
} }
Result ShellService::GetUnimplementedEventHandle(Out<CopiedHandle> event) { void ShellService::GetBootFinishedEvent(Out<CopiedHandle> event) {
/* In 8.0.0, Nintendo added this command which should return an event handle. */ /* In 8.0.0, Nintendo added this command, which signals that the boot sysmodule has finished. */
/* In addition, they also added code to create a new event in the global PM constructor. */ /* Nintendo only signals it in safe mode FIRM, and this function aborts on normal FIRM. */
/* However, nothing signals this event, and this command currently does std::abort();. */ /* We will signal it always, but only allow this function to succeed on safe mode. */
/* We will oblige. */ {
std::abort(); u64 is_recovery_boot = 0;
if (R_FAILED(SmcGetConfig(SplConfigItem_IsRecoveryBoot, &is_recovery_boot)) || !is_recovery_boot) {
/* TODO: Return an event handle, once N makes this command a real thing in the future. */ std::abort();
/* TODO: return ResultSuccess; */ }
}
event.SetValue(Registration::GetBootFinishedEventHandle());
} }

View file

@ -44,7 +44,7 @@ enum ShellCmd_5X {
Shell_Cmd_5X_BoostSystemMemoryResourceLimit = 7, Shell_Cmd_5X_BoostSystemMemoryResourceLimit = 7,
Shell_Cmd_BoostSystemThreadsResourceLimit = 8, Shell_Cmd_BoostSystemThreadsResourceLimit = 8,
Shell_Cmd_GetUnimplementedEventHandle = 9 /* TODO: Rename when Nintendo implements this. */ Shell_Cmd_GetBootFinishedEvent = 9,
}; };
class ShellService final : public IServiceObject { class ShellService final : public IServiceObject {
@ -61,7 +61,7 @@ class ShellService final : public IServiceObject {
Result GetApplicationProcessId(Out<u64> pid); Result GetApplicationProcessId(Out<u64> pid);
Result BoostSystemMemoryResourceLimit(u64 sysmem_size); Result BoostSystemMemoryResourceLimit(u64 sysmem_size);
Result BoostSystemThreadsResourceLimit(); Result BoostSystemThreadsResourceLimit();
Result GetUnimplementedEventHandle(Out<CopiedHandle> event); void GetBootFinishedEvent(Out<CopiedHandle> event);
public: public:
DEFINE_SERVICE_DISPATCH_TABLE { DEFINE_SERVICE_DISPATCH_TABLE {
/* 1.0.0-4.0.0 */ /* 1.0.0-4.0.0 */
@ -92,6 +92,6 @@ class ShellService final : public IServiceObject {
MakeServiceCommandMeta<Shell_Cmd_BoostSystemThreadsResourceLimit, &ShellService::BoostSystemThreadsResourceLimit, FirmwareVersion_700>(), MakeServiceCommandMeta<Shell_Cmd_BoostSystemThreadsResourceLimit, &ShellService::BoostSystemThreadsResourceLimit, FirmwareVersion_700>(),
/* 8.0.0-* */ /* 8.0.0-* */
MakeServiceCommandMeta<Shell_Cmd_GetUnimplementedEventHandle, &ShellService::GetUnimplementedEventHandle, FirmwareVersion_800>(), MakeServiceCommandMeta<Shell_Cmd_GetBootFinishedEvent, &ShellService::GetBootFinishedEvent, FirmwareVersion_800>(),
}; };
}; };