diff --git a/include/stratosphere.hpp b/include/stratosphere.hpp index 04ddaa2e..000656cb 100644 --- a/include/stratosphere.hpp +++ b/include/stratosphere.hpp @@ -43,6 +43,7 @@ #include "stratosphere/on_crash.hpp" +#include "stratosphere/svc.hpp" #include "stratosphere/cfg.hpp" #include "stratosphere/hid.hpp" #include "stratosphere/ncm.hpp" diff --git a/include/stratosphere/ldr/ldr_types.hpp b/include/stratosphere/ldr/ldr_types.hpp index 3efc5726..6139cff4 100644 --- a/include/stratosphere/ldr/ldr_types.hpp +++ b/include/stratosphere/ldr/ldr_types.hpp @@ -18,6 +18,7 @@ #include #include +#include "../svc/svc_types.hpp" #include "../ncm/ncm_types.hpp" namespace sts::ldr { @@ -176,10 +177,10 @@ namespace sts::ldr { }; enum PoolPartition { - PoolPartition_Application = 0, - PoolPartition_Applet = 1, - PoolPartition_System = 2, - PoolPartition_SystemNonSecure = 3, + PoolPartition_Application = (svc::CreateProcessFlag_PoolPartitionApplication >> svc::CreateProcessFlag_PoolPartitionShift), + PoolPartition_Applet = (svc::CreateProcessFlag_PoolPartitionApplet >> svc::CreateProcessFlag_PoolPartitionShift), + PoolPartition_System = (svc::CreateProcessFlag_PoolPartitionSystem >> svc::CreateProcessFlag_PoolPartitionShift), + PoolPartition_SystemNonSecure = (svc::CreateProcessFlag_PoolPartitionSystemNonSecure >> svc::CreateProcessFlag_PoolPartitionShift), }; u8 signature[0x100]; @@ -214,10 +215,10 @@ namespace sts::ldr { }; enum AddressSpaceType { - AddressSpaceType_32Bit = 0, - AddressSpaceType_64BitDeprecated = 1, - AddressSpaceType_32BitWithoutAlias = 2, - AddressSpaceType_64Bit = 3, + AddressSpaceType_32Bit = (svc::CreateProcessFlag_AddressSpace32Bit >> svc::CreateProcessFlag_AddressSpaceShift), + AddressSpaceType_64BitDeprecated = (svc::CreateProcessFlag_AddressSpace64BitDeprecated >> svc::CreateProcessFlag_AddressSpaceShift), + AddressSpaceType_32BitWithoutAlias = (svc::CreateProcessFlag_AddressSpace32BitWithoutAlias >> svc::CreateProcessFlag_AddressSpaceShift), + AddressSpaceType_64Bit = (svc::CreateProcessFlag_AddressSpace64Bit >> svc::CreateProcessFlag_AddressSpaceShift), }; u32 magic; diff --git a/include/stratosphere/results/creport_results.hpp b/include/stratosphere/results/creport_results.hpp index 905fe3eb..2ac115ca 100644 --- a/include/stratosphere/results/creport_results.hpp +++ b/include/stratosphere/results/creport_results.hpp @@ -27,7 +27,7 @@ static constexpr Result ResultCreportDebuggerAttached = MAKERESULT(Module_Cr static constexpr Result ResultCreportBreakPoint = MAKERESULT(Module_Creport, 5); static constexpr Result ResultCreportUserBreak = MAKERESULT(Module_Creport, 6); static constexpr Result ResultCreportDebuggerBreak = MAKERESULT(Module_Creport, 7); -static constexpr Result ResultCreportBadSvc = MAKERESULT(Module_Creport, 8); +static constexpr Result ResultCreportUndefinedSystemCall = MAKERESULT(Module_Creport, 8); static constexpr Result ResultCreportSystemMemoryError = MAKERESULT(Module_Creport, 9); static constexpr Result ResultCreportIncompleteReport = MAKERESULT(Module_Creport, 99); diff --git a/include/stratosphere/svc.hpp b/include/stratosphere/svc.hpp new file mode 100644 index 00000000..dad85159 --- /dev/null +++ b/include/stratosphere/svc.hpp @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2018-2019 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include + +#include "svc/svc_types.hpp" diff --git a/include/stratosphere/svc/svc_types.hpp b/include/stratosphere/svc/svc_types.hpp new file mode 100644 index 00000000..98855abd --- /dev/null +++ b/include/stratosphere/svc/svc_types.hpp @@ -0,0 +1,205 @@ +/* + * Copyright (c) 2018-2019 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include +#include "../defines.hpp" +#include "../results.hpp" + +namespace sts::svc { + + /* Debug event types. */ + enum class DebugEventType : u32 { + AttachProcess = 0, + AttachThread = 1, + ExitProcess = 2, + ExitThread = 3, + Exception = 4, + }; + + struct DebugInfoAttachProcess { + u64 title_id; + u64 process_id; + char name[0xC]; + u32 flags; + u64 user_exception_context_address; /* 5.0.0+ */ + }; + + struct DebugInfoAttachThread { + u64 thread_id; + u64 tls_address; + u64 entrypoint; + }; + + enum class ExitProcessReason : u32 { + ExitProcess = 0, + TerminateProcess = 1, + Exception = 2, + }; + + struct DebugInfoExitProcess { + ExitProcessReason reason; + }; + + enum class ExitThreadReason : u32 { + ExitThread = 0, + TerminateThread = 1, + ExitProcess = 2, + TerminateProcess = 3, + }; + + struct DebugInfoExitThread { + ExitThreadReason reason; + }; + + enum class DebugExceptionType : u32 { + UndefinedInstruction = 0, + InstructionAbort = 1, + DataAbort = 2, + AlignmentFault = 3, + DebuggerAttached = 4, + BreakPoint = 5, + UserBreak = 6, + DebuggerBreak = 7, + UndefinedSystemCall = 8, + SystemMemoryError = 9, + }; + + struct DebugInfoUndefinedInstructionException { + u32 insn; + }; + + struct DebugInfoDataAbortException { + u64 address; + }; + + struct DebugInfoAligntmentFaultException { + u64 address; + }; + + enum class BreakPointType : u32 { + BreakPoint = 0, + WatchPoint = 1, + }; + + struct DebugInfoBreakPointException { + BreakPointType type; + u64 address; + }; + + struct DebugInfoUserBreakException { + u32 break_reason; /* TODO: enum? */ + u64 address; + u64 size; + }; + + struct DebugInfoDebuggerBreakException { + u64 active_thread_ids[4]; + }; + + struct DebugInfoUndefinedSystemCallException { + u32 id; + }; + + union DebugInfoSpecificException { + DebugInfoUndefinedInstructionException undefined_instruction; + DebugInfoDataAbortException data_abort; + DebugInfoAligntmentFaultException alignment_fault; + DebugInfoBreakPointException break_point; + DebugInfoUserBreakException user_break; + DebugInfoDebuggerBreakException debugger_break; + DebugInfoUndefinedSystemCallException undefined_system_call; + u64 raw; + }; + + struct DebugInfoException { + DebugExceptionType type; + u64 address; + DebugInfoSpecificException specific; + }; + + union DebugInfo { + DebugInfoAttachProcess attach_process; + DebugInfoAttachThread attach_thread; + DebugInfoExitProcess exit_process; + DebugInfoExitThread exit_thread; + DebugInfoException exception; + }; + + struct DebugEventInfo { + DebugEventType type; + u32 flags; + u64 thread_id; + DebugInfo info; + }; + static_assert(sizeof(DebugEventInfo) >= 0x40, "DebugEventInfo definition!"); + + /* Thread State, for svcGetDebugThreadParam. */ + enum class ThreadState : u32 { + Waiting = 0, + Running = 1, + Terminated = 4, + Initializing = 5, + }; + + enum ThreadContextFlag : u32 { + ThreadContextFlag_General = (1 << 0), + ThreadContextFlag_Control = (1 << 1), + ThreadContextFlag_Fpu = (1 << 2), + ThreadContextFlag_FpuControl = (1 << 3), + + ThreadContextFlag_All = (ThreadContextFlag_General | ThreadContextFlag_Control | ThreadContextFlag_Fpu | ThreadContextFlag_FpuControl), + }; + + /* Flags for svcCreateProcess. */ + enum CreateProcessFlag : u32 { + /* Is 64 bit? */ + CreateProcessFlag_Is64Bit = (1 << 0), + + /* What kind of address space? */ + CreateProcessFlag_AddressSpaceShift = 1, + CreateProcessFlag_AddressSpaceMask = (7 << CreateProcessFlag_AddressSpaceShift), + CreateProcessFlag_AddressSpace32Bit = (0 << CreateProcessFlag_AddressSpaceShift), + CreateProcessFlag_AddressSpace64BitDeprecated = (1 << CreateProcessFlag_AddressSpaceShift), + CreateProcessFlag_AddressSpace32BitWithoutAlias = (2 << CreateProcessFlag_AddressSpaceShift), + CreateProcessFlag_AddressSpace64Bit = (3 << CreateProcessFlag_AddressSpaceShift), + + /* Should JIT debug be done on crash? */ + CreateProcessFlag_EnableDebug = (1 << 4), + + /* Should ASLR be enabled for the process? */ + CreateProcessFlag_EnableAslr = (1 << 5), + + /* Is the process an application? */ + CreateProcessFlag_IsApplication = (1 << 6), + + /* 4.x deprecated: Should use secure memory? */ + CreateProcessFlag_DeprecatedUseSecureMemory = (1 << 7), + + /* 5.x+ Pool partition type. */ + CreateProcessFlag_PoolPartitionShift = 7, + CreateProcessFlag_PoolPartitionMask = (0xF << CreateProcessFlag_PoolPartitionShift), + CreateProcessFlag_PoolPartitionApplication = (0 << CreateProcessFlag_PoolPartitionShift), + CreateProcessFlag_PoolPartitionApplet = (1 << CreateProcessFlag_PoolPartitionShift), + CreateProcessFlag_PoolPartitionSystem = (2 << CreateProcessFlag_PoolPartitionShift), + CreateProcessFlag_PoolPartitionSystemNonSecure = (3 << CreateProcessFlag_PoolPartitionShift), + + /* 7.x+ Should memory allocation be optimized? This requires IsApplication. */ + CreateProcessFlag_OptimizeMemoryAllocation = (1 << 11), + }; + +}