From 78f210887474964bebc16c25caa6b8d94d3b5431 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Fri, 17 Jan 2020 20:11:03 -0800 Subject: [PATCH] svc: populate namespace --- .../sf/cmif/sf_cmif_domain_service_object.hpp | 2 - .../sf/hipc/sf_hipc_server_manager.hpp | 1 - .../vapours/results/creport_results.hpp | 2 +- libvapours/include/vapours/svc.hpp | 1 + .../board/nintendo/switch/svc_device_name.hpp | 65 +++ libvapours/include/vapours/svc/svc_common.hpp | 61 +++ .../include/vapours/svc/svc_definitions.hpp | 185 +++++++ libvapours/include/vapours/svc/svc_types.hpp | 197 +------ .../include/vapours/svc/svc_types_base.hpp | 65 +++ .../include/vapours/svc/svc_types_common.hpp | 506 ++++++++++++++++++ .../include/vapours/svc/svc_types_dd.hpp | 51 ++ .../include/vapours/svc/svc_types_dmnt.hpp | 200 +++++++ .../include/vapours/svc/svc_types_priv.hpp | 53 ++ libvapours/include/vapours/types.hpp | 4 +- 14 files changed, 1196 insertions(+), 197 deletions(-) create mode 100644 libvapours/include/vapours/svc/board/nintendo/switch/svc_device_name.hpp create mode 100644 libvapours/include/vapours/svc/svc_common.hpp create mode 100644 libvapours/include/vapours/svc/svc_definitions.hpp create mode 100644 libvapours/include/vapours/svc/svc_types_base.hpp create mode 100644 libvapours/include/vapours/svc/svc_types_common.hpp create mode 100644 libvapours/include/vapours/svc/svc_types_dd.hpp create mode 100644 libvapours/include/vapours/svc/svc_types_dmnt.hpp create mode 100644 libvapours/include/vapours/svc/svc_types_priv.hpp diff --git a/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_service_object.hpp b/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_service_object.hpp index d5f86dd2..17abad21 100644 --- a/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_service_object.hpp +++ b/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_service_object.hpp @@ -101,8 +101,6 @@ namespace ams::sf::cmif { static constexpr inline DomainServiceObjectDispatchTable s_CmifServiceDispatchTable{}; private: virtual ServerDomainBase *GetServerDomain() = 0; - public: - /* TODO: Implement to use domain object processor. */ }; class MitmDomainServiceObject : public DomainServiceObject{}; diff --git a/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp b/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp index 04cbd79c..8011289e 100644 --- a/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp +++ b/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp @@ -102,7 +102,6 @@ namespace ams::sf::hipc { /* Otherwise, we're either a mitm session or a non-mitm session. */ if constexpr (IsMitmServer) { /* Custom deleter ensures that nothing goes awry. */ - /* TODO: Should this just be a custom wrapper object? */ std::shared_ptr<::Service> forward_service = std::move(ServerSession::CreateForwardService()); /* Get mitm forward session. */ diff --git a/libvapours/include/vapours/results/creport_results.hpp b/libvapours/include/vapours/results/creport_results.hpp index 6f836d8b..240c2d71 100644 --- a/libvapours/include/vapours/results/creport_results.hpp +++ b/libvapours/include/vapours/results/creport_results.hpp @@ -30,7 +30,7 @@ namespace ams::creport { R_DEFINE_ERROR_RESULT(UserBreak, 6); R_DEFINE_ERROR_RESULT(DebuggerBreak, 7); R_DEFINE_ERROR_RESULT(UndefinedSystemCall, 8); - R_DEFINE_ERROR_RESULT(SystemMemoryError, 9); + R_DEFINE_ERROR_RESULT(MemorySystemError, 9); R_DEFINE_ERROR_RESULT(IncompleteReport, 99); diff --git a/libvapours/include/vapours/svc.hpp b/libvapours/include/vapours/svc.hpp index fce88714..4ff9fbc5 100644 --- a/libvapours/include/vapours/svc.hpp +++ b/libvapours/include/vapours/svc.hpp @@ -19,3 +19,4 @@ #include "results.hpp" #include "svc/svc_types.hpp" +#include "svc/svc_definitions.hpp" diff --git a/libvapours/include/vapours/svc/board/nintendo/switch/svc_device_name.hpp b/libvapours/include/vapours/svc/board/nintendo/switch/svc_device_name.hpp new file mode 100644 index 00000000..bce98672 --- /dev/null +++ b/libvapours/include/vapours/svc/board/nintendo/switch/svc_device_name.hpp @@ -0,0 +1,65 @@ +/* + * 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 + +namespace ams::svc { + + enum DeviceName { + DeviceName_Afi = 0, + DeviceName_Avpc = 1, + DeviceName_Dc = 2, + DeviceName_Dcb = 3, + DeviceName_Hc = 4, + DeviceName_Hda = 5, + DeviceName_Isp2 = 6, + DeviceName_MsencNvenc = 7, + DeviceName_Nv = 8, + DeviceName_Nv2 = 9, + DeviceName_Ppcs = 10, + DeviceName_Sata = 11, + DeviceName_Vi = 12, + DeviceName_Vic = 13, + DeviceName_XusbHost = 14, + DeviceName_XusbDev = 15, + DeviceName_Tsec = 16, + DeviceName_Ppcs1 = 17, + DeviceName_Dc1 = 18, + DeviceName_Sdmmc1a = 19, + DeviceName_Sdmmc2a = 20, + DeviceName_Sdmmc3a = 21, + DeviceName_Sdmmc4a = 22, + DeviceName_Isp2b = 23, + DeviceName_Gpu = 24, + DeviceName_Gpub = 25, + DeviceName_Ppcs2 = 26, + DeviceName_Nvdec = 27, + DeviceName_Ape = 28, + DeviceName_Se = 29, + DeviceName_Nvjpg = 30, + DeviceName_Hc1 = 31, + DeviceName_Se1 = 32, + DeviceName_Axiap = 33, + DeviceName_Etr = 34, + DeviceName_Tsecb = 35, + DeviceName_Tsec1 = 36, + DeviceName_Tsecb1 = 37, + DeviceName_Nvdec1 = 38, + + DeviceName_Count, + }; + +} \ No newline at end of file diff --git a/libvapours/include/vapours/svc/svc_common.hpp b/libvapours/include/vapours/svc/svc_common.hpp new file mode 100644 index 00000000..fcb841f8 --- /dev/null +++ b/libvapours/include/vapours/svc/svc_common.hpp @@ -0,0 +1,61 @@ +/* + * 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 "../results.hpp" + +namespace ams::svc { + + /* TODO: C++ style handle? */ +#ifdef ATMOSPHERE_IS_STRATOSPHERE + using Handle = ::Handle; +#elif defined ATMOSPHERE_IS_MESOSPHERE + using Handle = u32; +#else + #error "Unknown target for svc::Handle" +#endif + +#ifdef ATMOSPHERE_ARCH_ARM64 + + + namespace lp64 { /* ... */ } + namespace aarch64 { /* ... */ } + using namespace ::ams::svc::lp64; + using namespace ::ams::svc::aarch64; + + /* TODO: ifdef ATMOSPHERE_ABI_LP64 */ + #if 1 + namespace aarch64::lp64 { /* ... */ } + using namespace ::ams::svc::aarch64::lp64; + #else + namespace aarch64::ilp32 { /* ... */ } + using namespace ::ams::svc::aarch64::ilp32; + #endif + +#elif defined ATMOSPHERE_ARCH_ARM + + namespace ilp32 { /* ... */ } + namespace aarch32 { /* ... */ } + using namespace ::ams::svc::ilp32; + using namespace ::ams::svc::aarch32; + +#else + + #error "Unknown Architecture" + +#endif + +} diff --git a/libvapours/include/vapours/svc/svc_definitions.hpp b/libvapours/include/vapours/svc/svc_definitions.hpp new file mode 100644 index 00000000..95df5bea --- /dev/null +++ b/libvapours/include/vapours/svc/svc_definitions.hpp @@ -0,0 +1,185 @@ +/* + * 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 "svc_common.hpp" +#include "svc_types.hpp" + +#define AMS_SVC_KERN_INPUT_HANDLER(TYPE, NAME) TYPE NAME +#define AMS_SVC_KERN_OUTPUT_HANDLER(TYPE, NAME) TYPE *NAME +#define AMS_SVC_KERN_INPTR_HANDLER(TYPE, NAME) ::ams::kern::KUserPointer NAME +#define AMS_SVC_KERN_OUTPTR_HANDLER(TYPE, NAME) ::ams::kern::KUserPointer NAME + +#define AMS_SVC_USER_INPUT_HANDLER(TYPE, NAME) TYPE NAME +#define AMS_SVC_USER_OUTPUT_HANDLER(TYPE, NAME) TYPE *NAME +#define AMS_SVC_USER_INPTR_HANDLER(TYPE, NAME) const TYPE *NAME +#define AMS_SVC_USER_OUTPTR_HANDLER(TYPE, NAME) TYPE *NAME + +#define AMS_SVC_FOREACH_DEFINITION_IMPL(HANDLER, NAMESPACE, INPUT, OUTPUT, INPTR, OUTPTR) \ + HANDLER(0x01, Result, SetHeapSize, OUTPUT(::ams::svc::Address, out_address), INPUT(::ams::svc::Size, size)) \ + HANDLER(0x02, Result, SetMemoryPermission, INPUT(::ams::svc::Address, address), INPUT(::ams::svc::Size, size), INPUT(::ams::svc::MemoryPermission, perm)) \ + HANDLER(0x03, Result, SetMemoryAttribute, INPUT(::ams::svc::Address, address), INPUT(::ams::svc::Size, size), INPUT(uint32_t, mask), INPUT(uint32_t, attr)) \ + HANDLER(0x04, Result, MapMemory, INPUT(::ams::svc::Address, dst_address), INPUT(::ams::svc::Address, src_address), INPUT(::ams::svc::Size, size)) \ + HANDLER(0x05, Result, UnmapMemory, INPUT(::ams::svc::Address, dst_address), INPUT(::ams::svc::Address, src_address), INPUT(::ams::svc::Size, size)) \ + HANDLER(0x06, Result, QueryMemory, OUTPTR(::ams::svc::NAMESPACE::MemoryInfo, out_memory_info), OUTPUT(::ams::svc::PageInfo, out_page_info), INPUT(::ams::svc::Address, address)) \ + HANDLER(0x07, void, ExitProcess) \ + HANDLER(0x08, Result, CreateThread, OUTPUT(::ams::svc::Handle, out_handle), INPUT(::ams::svc::ThreadFunc, func), INPUT(::ams::svc::Address, arg), INPUT(::ams::svc::Address, stack_bottom), INPUT(int32_t, priority), INPUT(int32_t, core_id)) \ + HANDLER(0x09, Result, StartThread, INPUT(::ams::svc::Handle, thread_handle)) \ + HANDLER(0x0A, void, ExitThread) \ + HANDLER(0x0B, void, SleepThread, INPUT(int64_t, ns)) \ + HANDLER(0x0C, Result, GetThreadPriority, OUTPUT(int32_t, out_priority), INPUT(::ams::svc::Handle, thread_handle)) \ + HANDLER(0x0D, Result, SetThreadPriority, INPUT(::ams::svc::Handle, thread_handle), INPUT(int32_t, priority)) \ + HANDLER(0x0E, Result, GetThreadCoreMask, OUTPUT(int32_t, out_core_id), OUTPUT(uint64_t, out_affinity_mask), INPUT(::ams::svc::Handle, thread_handle)) \ + HANDLER(0x0F, Result, SetThreadCoreMask, INPUT(::ams::svc::Handle, thread_handle), INPUT(int32_t, core_id), INPUT(uint64_t, affinity_mask)) \ + HANDLER(0x10, int32_t, GetCurrentProcessorNumber) \ + HANDLER(0x11, Result, SignalEvent, INPUT(::ams::svc::Handle, event_handle)) \ + HANDLER(0x12, Result, ClearEvent, INPUT(::ams::svc::Handle, event_handle)) \ + HANDLER(0x13, Result, MapSharedMemory, INPUT(::ams::svc::Handle, shmem_handle), INPUT(::ams::svc::Address, address), INPUT(::ams::svc::Size, size), INPUT(::ams::svc::MemoryPermission, map_perm)) \ + HANDLER(0x14, Result, UnmapSharedMemory, INPUT(::ams::svc::Handle, shmem_handle), INPUT(::ams::svc::Address, address), INPUT(::ams::svc::Size, size)) \ + HANDLER(0x15, Result, CreateTransferMemory, OUTPUT(::ams::svc::Handle, out_handle), INPUT(::ams::svc::Address, address), INPUT(::ams::svc::Size, size), INPUT(::ams::svc::MemoryPermission, map_perm)) \ + HANDLER(0x16, Result, CloseHandle, INPUT(::ams::svc::Handle, handle)) \ + HANDLER(0x17, Result, ResetSignal, INPUT(::ams::svc::Handle, handle)) \ + HANDLER(0x18, Result, WaitSynchronization, OUTPUT(int32_t, out_index), INPTR(::ams::svc::Handle, handles), INPUT(int32_t, numHandles), INPUT(int64_t, timeout_ns)) \ + HANDLER(0x19, Result, CancelSynchronization, INPUT(::ams::svc::Handle, handle)) \ + HANDLER(0x1A, Result, ArbitrateLock, INPUT(::ams::svc::Handle, thread_handle), INPUT(::ams::svc::Address, address), INPUT(uint32_t, tag)) \ + HANDLER(0x1B, Result, ArbitrateUnlock, INPUT(::ams::svc::Address, address)) \ + HANDLER(0x1C, Result, WaitProcessWideKeyAtomic, INPUT(::ams::svc::Address, address), INPUT(::ams::svc::Address, cv_key), INPUT(uint32_t, tag), INPUT(int64_t, timeout_ns)) \ + HANDLER(0x1D, void, SignalProcessWideKey, INPUT(::ams::svc::Address, cv_key), INPUT(int32_t, count)) \ + HANDLER(0x1E, int64_t, GetSystemTick) \ + HANDLER(0x1F, Result, ConnectToNamedPort, OUTPUT(::ams::svc::Handle, out_handle), INPTR(char, name)) \ + HANDLER(0x20, Result, SendSyncRequestLight, INPUT(::ams::svc::Handle, session_handle)) \ + HANDLER(0x21, Result, SendSyncRequest, INPUT(::ams::svc::Handle, session_handle)) \ + HANDLER(0x22, Result, SendSyncRequestWithUserBuffer, INPUT(::ams::svc::Address, message_buffer), INPUT(::ams::svc::Size, message_buffer_size), INPUT(::ams::svc::Handle, session_handle)) \ + HANDLER(0x23, Result, SendAsyncRequestWithUserBuffer, OUTPUT(::ams::svc::Handle, out_event_handle), INPUT(::ams::svc::Address, message_buffer), INPUT(::ams::svc::Size, message_buffer_size), INPUT(::ams::svc::Handle, session_handle)) \ + HANDLER(0x24, Result, GetProcessId, OUTPUT(uint64_t, out_process_id), INPUT(::ams::svc::Handle, process_handle)) \ + HANDLER(0x25, Result, GetThreadId, OUTPUT(uint64_t, out_thread_id), INPUT(::ams::svc::Handle, thread_handle)) \ + HANDLER(0x26, void, Break, INPUT(::ams::svc::BreakReason, break_reason), INPUT(::ams::svc::Address, arg), INPUT(::ams::svc::Size, size)) \ + HANDLER(0x27, Result, OutputDebugString, INPTR(char, debug_str), INPUT(::ams::svc::Size, len)) \ + HANDLER(0x28, void, ReturnFromException, INPUT(::ams::Result, result)) \ + HANDLER(0x29, Result, GetInfo, OUTPUT(uint64_t, out), INPUT(::ams::svc::InfoType, info_type), INPUT(::ams::svc::Handle, handle), INPUT(uint64_t, info_subtype)) \ + HANDLER(0x2A, void, FlushEntireDataCache) \ + HANDLER(0x2B, Result, FlushDataCache, INPUT(::ams::svc::Address, address), INPUT(::ams::svc::Size, size)) \ + HANDLER(0x2C, Result, MapPhysicalMemory, INPUT(::ams::svc::Address, address), INPUT(::ams::svc::Size, size)) \ + HANDLER(0x2D, Result, UnmapPhysicalMemory, INPUT(::ams::svc::Address, address), INPUT(::ams::svc::Size, size)) \ + HANDLER(0x2E, Result, GetDebugFutureThreadInfo, OUTPUT(::ams::svc::NAMESPACE::LastThreadContext, out_context), OUTPUT(uint64_t, thread_id), INPUT(::ams::svc::Handle, debug_handle), INPUT(int64_t, ns)) \ + HANDLER(0x2F, Result, GetLastThreadInfo, OUTPUT(::ams::svc::NAMESPACE::LastThreadContext, out_context), OUTPUT(::ams::svc::Address, out_tls_address), OUTPUT(uint32_t, out_flags)) \ + HANDLER(0x30, Result, GetResourceLimitLimitValue, OUTPUT(int64_t, out_limit_value), INPUT(::ams::svc::Handle, resource_limit_handle), INPUT(::ams::svc::LimitableResource, which)) \ + HANDLER(0x31, Result, GetResourceLimitCurrentValue, OUTPUT(int64_t, out_current_value), INPUT(::ams::svc::Handle, resource_limit_handle), INPUT(::ams::svc::LimitableResource, which)) \ + HANDLER(0x32, Result, SetThreadActivity, INPUT(::ams::svc::Handle, thread_handle), INPUT(::ams::svc::ThreadActivity, thread_activity)) \ + HANDLER(0x33, Result, GetThreadContext3, OUTPTR(::ams::svc::ThreadContext, out_context), INPUT(::ams::svc::Handle, thread_handle)) \ + HANDLER(0x34, Result, WaitForAddress, INPUT(::ams::svc::Address, address), INPUT(::ams::svc::ArbitrationType, arb_type), INPUT(int32_t, value), INPUT(int64_t, timeout_ns)) \ + HANDLER(0x35, Result, SignalToAddress, INPUT(::ams::svc::Address, address), INPUT(::ams::svc::SignalType, signal_type), INPUT(int32_t, value), INPUT(int32_t, count)) \ + HANDLER(0x36, void, SynchronizePreemptionState) \ + \ + HANDLER(0x3C, void, KernelDebug, INPUT(::ams::svc::KernelDebugType, kern_debug_type), INPUT(uint64_t, arg0), INPUT(uint64_t, arg1), INPUT(uint64_t, arg2)) \ + HANDLER(0x3D, void, ChangeKernelTraceState, INPUT(::ams::svc::KernelTraceState, kern_trace_state)) \ + \ + HANDLER(0x40, Result, CreateSession, OUTPUT(::ams::svc::Handle, out_server_session_handle), OUTPUT(::ams::svc::Handle, out_client_session_handle), INPUT(bool, is_light), INPUT(::ams::svc::Address, name)) \ + HANDLER(0x41, Result, AcceptSession, OUTPUT(::ams::svc::Handle, out_handle), INPUT(::ams::svc::Handle, port)) \ + HANDLER(0x42, Result, ReplyAndReceiveLight, INPUT(::ams::svc::Handle, handle)) \ + HANDLER(0x43, Result, ReplyAndReceive, OUTPUT(int32_t, out_index), INPTR(::ams::svc::Handle, handles), INPUT(int32_t, num_handles), INPUT(::ams::svc::Handle, reply_target), INPUT(int64_t, timeout_ns)) \ + HANDLER(0x44, Result, ReplyAndReceiveWithUserBuffer, OUTPUT(int32_t, out_index), INPUT(::ams::svc::Address, message_buffer), INPUT(::ams::svc::Size, message_buffer_size), INPTR(::ams::svc::Handle, handles), INPUT(int32_t, num_handles), INPUT(::ams::svc::Handle, reply_target), INPUT(int64_t, timeout_ns)) \ + HANDLER(0x45, Result, CreateEvent, OUTPUT(::ams::svc::Handle, out_write_handle), OUTPUT(::ams::svc::Handle, out_read_handle)) \ + \ + HANDLER(0x48, Result, MapPhysicalMemoryUnsafe, INPUT(::ams::svc::Address, address), INPUT(::ams::svc::Size, size)) \ + HANDLER(0x49, Result, UnmapPhysicalMemoryUnsafe, INPUT(::ams::svc::Address, address), INPUT(::ams::svc::Size, size)) \ + HANDLER(0x4A, Result, SetUnsafeLimit, INPUT(::ams::svc::Size, limit)) \ + HANDLER(0x4B, Result, CreateCodeMemory, OUTPUT(::ams::svc::Handle, out_handle), INPUT(::ams::svc::Address, address), INPUT(::ams::svc::Size, size)) \ + HANDLER(0x4C, Result, ControlCodeMemory, INPUT(::ams::svc::Handle, code_memory_handle), INPUT(::ams::svc::CodeMemoryOperation, operation), INPUT(uint64_t, address), INPUT(uint64_t, size), INPUT(::ams::svc::MemoryPermission, perm)) \ + HANDLER(0x4D, void, SleepSystem) \ + HANDLER(0x4E, Result, ReadWriteRegister, OUTPUT(uint32_t, out_value), INPUT(::ams::svc::PhysicalAddress, address), INPUT(uint32_t, mask), INPUT(uint32_t, value)) \ + HANDLER(0x4F, Result, SetProcessActivity, INPUT(::ams::svc::Handle, process_handle), INPUT(::ams::svc::ProcessActivity, process_activity)) \ + HANDLER(0x50, Result, CreateSharedMemory, OUTPUT(::ams::svc::Handle, out_handle), INPUT(::ams::svc::Size, size), INPUT(::ams::svc::MemoryPermission, owner_perm), INPUT(::ams::svc::MemoryPermission, remote_perm)) \ + HANDLER(0x51, Result, MapTransferMemory, INPUT(::ams::svc::Handle, trmem_handle), INPUT(::ams::svc::Address, address), INPUT(::ams::svc::Size, size), INPUT(::ams::svc::MemoryPermission, owner_perm)) \ + HANDLER(0x52, Result, UnmapTransferMemory, INPUT(::ams::svc::Handle, trmem_handle), INPUT(::ams::svc::Address, address), INPUT(::ams::svc::Size, size)) \ + HANDLER(0x53, Result, CreateInterruptEvent, OUTPUT(::ams::svc::Handle, out_read_handle), INPUT(int32_t, interrupt_id), INPUT(::ams::svc::InterruptType, interrupt_type)) \ + HANDLER(0x54, Result, QueryPhysicalAddress, OUTPUT(::ams::svc::NAMESPACE::PhysicalMemoryInfo, out_info), INPUT(::ams::svc::Address, address)) \ + HANDLER(0x55, Result, QueryIoMapping, OUTPUT(::ams::svc::Address, out_address), INPUT(::ams::svc::PhysicalAddress, physical_address), INPUT(::ams::svc::Size, size)) \ + HANDLER(0x56, Result, CreateDeviceAddressSpace, OUTPUT(::ams::svc::Handle, out_handle), INPUT(uint64_t, das_address), INPUT(uint64_t, das_size)) \ + HANDLER(0x57, Result, AttachDeviceAddressSpace, INPUT(::ams::svc::DeviceName, device_name), INPUT(::ams::svc::Handle, das_handle)) \ + HANDLER(0x58, Result, DetachDeviceAddressSpace, INPUT(::ams::svc::DeviceName, device_name), INPUT(::ams::svc::Handle, das_handle)) \ + HANDLER(0x59, Result, MapDeviceAddressSpaceByForce, INPUT(::ams::svc::Handle, das_handle), INPUT(::ams::svc::Handle, process_handle), INPUT(uint64_t, process_address), INPUT(::ams::svc::Size, size), INPUT(uint64_t, device_address), INPUT(::ams::svc::MemoryPermission, device_perm)) \ + HANDLER(0x5A, Result, MapDeviceAddressSpaceAligned, INPUT(::ams::svc::Handle, das_handle), INPUT(::ams::svc::Handle, process_handle), INPUT(uint64_t, process_address), INPUT(::ams::svc::Size, size), INPUT(uint64_t, device_address), INPUT(::ams::svc::MemoryPermission, device_perm)) \ + HANDLER(0x5B, Result, MapDeviceAddressSpace, OUTPUT(::ams::svc::Size, out_mapped_size), INPUT(::ams::svc::Handle, das_handle), INPUT(::ams::svc::Handle, process_handle), INPUT(uint64_t, process_address), INPUT(::ams::svc::Size, size), INPUT(uint64_t, device_address), INPUT(::ams::svc::MemoryPermission, device_perm)) \ + HANDLER(0x5C, Result, UnmapDeviceAddressSpace, INPUT(::ams::svc::Handle, das_handle), INPUT(::ams::svc::Handle, process_handle), INPUT(uint64_t, process_address), INPUT(::ams::svc::Size, size), INPUT(uint64_t, device_address)) \ + HANDLER(0x5D, Result, InvalidateProcessDataCache, INPUT(::ams::svc::Handle, process_handle), INPUT(uint64_t, address), INPUT(uint64_t, size)) \ + HANDLER(0x5E, Result, StoreProcessDataCache, INPUT(::ams::svc::Handle, process_handle), INPUT(uint64_t, address), INPUT(uint64_t, size)) \ + HANDLER(0x5F, Result, FlushProcessDataCache, INPUT(::ams::svc::Handle, process_handle), INPUT(uint64_t, address), INPUT(uint64_t, size)) \ + HANDLER(0x60, Result, DebugActiveProcess, OUTPUT(::ams::svc::Handle, out_handle), INPUT(uint64_t, process_id)) \ + HANDLER(0x61, Result, BreakDebugProcess, INPUT(::ams::svc::Handle, debug_handle)) \ + HANDLER(0x62, Result, TerminateDebugProcess, INPUT(::ams::svc::Handle, debug_handle)) \ + HANDLER(0x63, Result, GetDebugEvent, OUTPTR(::ams::svc::NAMESPACE::DebugEventInfo, out_info), INPUT(::ams::svc::Handle, debug_handle)) \ + HANDLER(0x64, Result, ContinueDebugEvent, INPUT(::ams::svc::Handle, debug_handle), INPUT(uint32_t, flags), INPTR(uint64_t, thread_ids), INPUT(int32_t, num_thread_ids)) \ + HANDLER(0x65, Result, GetProcessList, OUTPUT(int32_t, out_num_processes), OUTPTR(uint64_t, out_process_ids), INPUT(int32_t, max_out_count)) \ + HANDLER(0x66, Result, GetThreadList, OUTPUT(int32_t, out_num_threads), OUTPTR(uint64_t, out_thread_ids), INPUT(int32_t, max_out_count), INPUT(::ams::svc::Handle, debug_handle)) \ + HANDLER(0x67, Result, GetDebugThreadContext, OUTPTR(::ams::svc::ThreadContext, out_context), INPUT(::ams::svc::Handle, debug_handle), INPUT(uint64_t, thread_id), INPUT(uint32_t, context_flags)) \ + HANDLER(0x68, Result, SetDebugThreadContext, INPUT(::ams::svc::Handle, debug_handle), INPUT(uint64_t, thread_id), INPTR(::ams::svc::ThreadContext, context), INPUT(uint32_t, context_flags)) \ + HANDLER(0x69, Result, QueryDebugProcessMemory, OUTPTR(::ams::svc::NAMESPACE::MemoryInfo, out_memory_info), OUTPUT(::ams::svc::PageInfo, out_page_info), INPUT(::ams::svc::Handle, process_handle), INPUT(::ams::svc::Address, address)) \ + HANDLER(0x6A, Result, ReadDebugProcessMemory, INPUT(::ams::svc::Address, buffer), INPUT(::ams::svc::Handle, debug_handle), INPUT(::ams::svc::Address, address), INPUT(::ams::svc::Size, size)) \ + HANDLER(0x6B, Result, WriteDebugProcessMemory, INPUT(::ams::svc::Handle, debug_handle), INPUT(::ams::svc::Address, buffer), INPUT(::ams::svc::Address, address), INPUT(::ams::svc::Size, size)) \ + HANDLER(0x6C, Result, SetHardwareBreakPoint, INPUT(::ams::svc::HardwareBreakPointRegisterName, name), INPUT(uint64_t, flags), INPUT(uint64_t, value)) \ + HANDLER(0x6D, Result, GetDebugThreadParam, OUTPUT(uint64_t, out_64), OUTPUT(uint32_t, out_32), INPUT(::ams::svc::Handle, debug_handle), INPUT(uint64_t, thread_id), INPUT(::ams::svc::DebugThreadParam, param)) \ + \ + HANDLER(0x6F, Result, GetSystemInfo, OUTPUT(uint64_t, out), INPUT(::ams::svc::SystemInfoType, info_type), INPUT(::ams::svc::Handle, handle), INPUT(uint64_t, info_subtype)) \ + HANDLER(0x70, Result, CreatePort, OUTPUT(::ams::svc::Handle, out_server_handle), OUTPUT(::ams::svc::Handle, out_client_handle), INPUT(int32_t, max_sessions), INPUT(bool, is_light), INPUT(::ams::svc::Address, name)) \ + HANDLER(0x71, Result, ManageNamedPort, OUTPUT(::ams::svc::Handle, out_server_handle), INPTR(char, name), INPUT(int32_t, max_sessions)) \ + HANDLER(0x72, Result, ConnectToPort, OUTPUT(::ams::svc::Handle, out_handle), INPUT(::ams::svc::Handle, port)) \ + HANDLER(0x73, Result, SetProcessMemoryPermission, INPUT(::ams::svc::Handle, process_handle), INPUT(uint64_t, address), INPUT(uint64_t, size), INPUT(::ams::svc::MemoryPermission, perm)) \ + HANDLER(0x74, Result, MapProcessMemory, INPUT(::ams::svc::Address, dst_address), INPUT(::ams::svc::Handle, process_handle), INPUT(uint64_t, src_address), INPUT(::ams::svc::Size, size)) \ + HANDLER(0x75, Result, UnmapProcessMemory, INPUT(::ams::svc::Address, dst_address), INPUT(::ams::svc::Handle, process_handle), INPUT(uint64_t, src_address), INPUT(::ams::svc::Size, size)) \ + HANDLER(0x76, Result, QueryProcessMemory, OUTPTR(::ams::svc::NAMESPACE::MemoryInfo, out_memory_info), OUTPUT(::ams::svc::PageInfo, out_page_info), INPUT(::ams::svc::Handle, process_handle), INPUT(uint64_t, address)) \ + HANDLER(0x77, Result, MapProcessCodeMemory, INPUT(::ams::svc::Handle, process_handle), INPUT(uint64_t, dst_address), INPUT(uint64_t, src_address), INPUT(uint64_t, size)) \ + HANDLER(0x78, Result, UnmapProcessCodeMemory, INPUT(::ams::svc::Handle, process_handle), INPUT(uint64_t, dst_address), INPUT(uint64_t, src_address), INPUT(uint64_t, size)) \ + HANDLER(0x79, Result, CreateProcess, OUTPUT(::ams::svc::Handle, out_handle), INPTR(::ams::svc::NAMESPACE::CreateProcessParameter, parameters), INPTR(uint32_t, caps), INPUT(int32_t, num_caps)) \ + HANDLER(0x7A, Result, StartProcess, INPUT(::ams::svc::Handle, process_handle), INPUT(int32_t, priority), INPUT(int32_t, core_id), INPUT(uint64_t, main_thread_stack_size)) \ + HANDLER(0x7B, Result, TerminateProcess, INPUT(::ams::svc::Handle, process_handle)) \ + HANDLER(0x7C, Result, GetProcessInfo, OUTPUT(int64_t, out_info), INPUT(::ams::svc::Handle, process_handle), INPUT(::ams::svc::ProcessInfoType, info_type)) \ + HANDLER(0x7D, Result, CreateResourceLimit, OUTPUT(::ams::svc::Handle, out_handle)) \ + HANDLER(0x7E, Result, SetResourceLimitLimitValue, INPUT(::ams::svc::Handle, resource_limit_handle), INPUT(::ams::svc::LimitableResource, which), INPUT(int64_t, limit_value)) \ + HANDLER(0x7F, void, CallSecureMonitor, OUTPUT(::ams::svc::NAMESPACE::SecureMonitorArguments, args)) + +#define AMS_SVC_FOREACH_USER_DEFINITION(HANDLER, NAMESPACE) AMS_SVC_FOREACH_DEFINITION_IMPL(HANDLER, NAMESPACE, AMS_SVC_USER_INPUT_HANDLER, AMS_SVC_USER_OUTPUT_HANDLER, AMS_SVC_USER_INPTR_HANDLER, AMS_SVC_USER_OUTPTR_HANDLER) +#define AMS_SVC_FOREACH_KERN_DEFINITION(HANDLER, NAMESPACE) AMS_SVC_FOREACH_DEFINITION_IMPL(HANDLER, NAMESPACE, AMS_SVC_KERN_INPUT_HANDLER, AMS_SVC_KERN_OUTPUT_HANDLER, AMS_SVC_KERN_INPTR_HANDLER, AMS_SVC_KERN_OUTPTR_HANDLER) + +#define AMS_SVC_DECLARE_FUNCTION_PROTOTYPE(ID, RETURN_TYPE, NAME, ...) \ + RETURN_TYPE NAME(__VA_ARGS__); + +#ifdef ATMOSPHERE_IS_STRATOSPHERE + +namespace ams::svc { + + namespace aarch64::lp64 { + + AMS_SVC_FOREACH_USER_DEFINITION(AMS_SVC_DECLARE_FUNCTION_PROTOTYPE, lp64) + + } + + namespace aarch64::ilp32 { + + AMS_SVC_FOREACH_USER_DEFINITION(AMS_SVC_DECLARE_FUNCTION_PROTOTYPE, ilp32) + + } + + namespace aarch32 { + + AMS_SVC_FOREACH_USER_DEFINITION(AMS_SVC_DECLARE_FUNCTION_PROTOTYPE, ilp32) + + } + +} + +#endif + diff --git a/libvapours/include/vapours/svc/svc_types.hpp b/libvapours/include/vapours/svc/svc_types.hpp index 2284f955..8222c9b0 100644 --- a/libvapours/include/vapours/svc/svc_types.hpp +++ b/libvapours/include/vapours/svc/svc_types.hpp @@ -13,196 +13,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #pragma once -#include "../results.hpp" -namespace ams::svc { - - /* Debug event types. */ - enum class DebugEventType : u32 { - AttachProcess = 0, - AttachThread = 1, - ExitProcess = 2, - ExitThread = 3, - Exception = 4, - }; - - struct DebugInfoAttachProcess { - u64 program_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), - }; - - /* Type for svcCreateInterruptEvent. */ - enum InterruptType : u32 { - InterruptType_Edge = 0, - InterruptType_Level = 1, - }; - -} +#include "svc_common.hpp" +#include "svc_types_common.hpp" +#include "svc_types_base.hpp" +#include "svc_types_dd.hpp" +#include "svc_types_dmnt.hpp" +#include "svc_types_priv.hpp" diff --git a/libvapours/include/vapours/svc/svc_types_base.hpp b/libvapours/include/vapours/svc/svc_types_base.hpp new file mode 100644 index 00000000..061c253d --- /dev/null +++ b/libvapours/include/vapours/svc/svc_types_base.hpp @@ -0,0 +1,65 @@ +/* + * 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 "svc_types_common.hpp" + +namespace ams::svc { + + namespace lp64 { + + struct MemoryInfo { + u64 addr; + u64 size; + MemoryState state; + MemoryAttribute attr; + MemoryPermission perm; + u32 ipc_refcount; + u32 device_refcount; + u32 padding; + }; + + struct LastThreadContext { + u64 fp; + u64 sp; + u64 lr; + u64 pc; + }; + + } + + namespace ilp32 { + + struct MemoryInfo { + u64 addr; + u64 size; + MemoryState state; + MemoryAttribute attr; + MemoryPermission perm; + u32 ipc_refcount; + u32 device_refcount; + u32 padding; + }; + + struct LastThreadContext { + u32 fp; + u32 sp; + u32 lr; + u32 pc; + }; + + } + +} diff --git a/libvapours/include/vapours/svc/svc_types_common.hpp b/libvapours/include/vapours/svc/svc_types_common.hpp new file mode 100644 index 00000000..dc5d036c --- /dev/null +++ b/libvapours/include/vapours/svc/svc_types_common.hpp @@ -0,0 +1,506 @@ +/* + * 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 "svc_common.hpp" + +namespace ams::svc { + + /* Utility classes required to encode information into the type system for SVC veneers. */ + class Size { + private: + size_t size; + public: + constexpr ALWAYS_INLINE Size(size_t s) : size(s) { /* ... */ } + constexpr ALWAYS_INLINE operator size_t() { return this->size; } + }; + static_assert(sizeof(Size) == sizeof(size_t)); + static_assert(std::is_trivially_destructible::value); + + class Address { + private: + uintptr_t uintptr; + public: + constexpr ALWAYS_INLINE Address(uintptr_t u) : uintptr(u) { /* ... */ } + constexpr ALWAYS_INLINE operator uintptr_t() { return this->uintptr; } + }; + static_assert(sizeof(Address) == sizeof(uintptr_t)); + static_assert(std::is_trivially_destructible
::value); + + using PhysicalAddress = u64; + + /* Memory types. */ + enum MemoryState : u32 { + MemoryState_Free = 0x00, + MemoryState_Io = 0x01, + MemoryState_Static = 0x02, + MemoryState_Code = 0x03, + MemoryState_CodeData = 0x04, + MemoryState_Normal = 0x05, + MemoryState_Shared = 0x06, + MemoryState_Alias = 0x07, + MemoryState_AliasCode = 0x08, + MemoryState_AliasCodeData = 0x09, + MemoryState_Ipc = 0x0A, + MemoryState_Stack = 0x0B, + MemoryState_ThreadLocal = 0x0C, + MemoryState_Transfered = 0x0D, + MemoryState_SharedTransfered = 0x0E, + MemoryState_SharedCode = 0x0F, + MemoryState_Inaccessible = 0x10, + MemoryState_NonSecureIpc = 0x11, + MemoryState_NonDeviceIpc = 0x12, + MemoryState_Kernel = 0x13, + MemoryState_GeneratedCode = 0x14, + MemoryState_CodeOut = 0x15, + }; + + enum MemoryPermission : u32 { + MemoryPermission_None = (0 << 0), + + MemoryPermission_Read = (1 << 0), + MemoryPermission_Write = (1 << 1), + MemoryPermission_Execute = (1 << 1), + + MemoryPermission_ReadWrite = MemoryPermission_Read | MemoryPermission_Write, + MemoryPermission_ReadExecute = MemoryPermission_Read | MemoryPermission_Execute, + + MemoryPermission_DontCare = (1 << 28), /* For SharedMemory */ + }; + + enum MemoryAttribute : u32 { + MemoryAttribute_Locked = (1 << 0), + MemoryAttribute_IpcLocked = (1 << 1), + MemoryAttribute_DeviceShared = (1 << 2), + MemoryAttribute_Uncached = (1 << 3), + }; + + struct PageInfo { + u32 flags; + }; + + /* Info Types. */ + enum InfoType : u32 { + InfoType_CoreMask = 0, + InfoType_PriorityMask = 1, + InfoType_AliasRegionAddress = 2, + InfoType_AliasRegionSize = 3, + InfoType_HeapRegionAddress = 4, + InfoType_HeapRegionSize = 5, + InfoType_TotalMemorySize = 6, + InfoType_UsedMemorySize = 7, + InfoType_DebuggerAttached = 8, + InfoType_ResourceLimit = 9, + InfoType_IdleTickCount = 10, + InfoType_RandomEntropy = 11, + InfoType_AslrRegionAddress = 12, + InfoType_AslrRegionSize = 13, + InfoType_StackRegionAddress = 14, + InfoType_StackRegionSize = 15, + InfoType_SystemResourceSizeTotal = 16, + InfoType_SystemResourceSizeUsed = 17, + InfoType_ProgramId = 18, + InfoType_InitialProcessIdRange = 19, + InfoType_UserExceptionContextAddress = 20, + InfoType_TotalNonSystemMemorySize = 21, + InfoType_UsedNonSystemMemorySize = 22, + InfoType_IsApplication = 23, + + InfoType_ThreadTickCount = 0xF0000002, + }; + + enum TickCountInfo : u64 { + TickCountInfo_Core0 = 0, + TickCountInfo_Core1 = 1, + TickCountInfo_Core2 = 2, + TickCountInfo_Core3 = 3, + + TickCountInfo_Total = std::numeric_limits::max(), + }; + + enum SystemInfoType : u32 { + SystemInfoType_TotalPhysicalMemorySize = 0, + SystemInfoType_UsedPhysicalMemorySize = 1, + SystemInfoType_InitialProcessIdRange = 2, + }; + + enum InitialProcessIdRangeInfo : u64 { + InitialProcessIdRangeInfo_Minimum = 0, + InitialProcessIdRangeInfo_Maximum = 1, + }; + + enum PhysicalMemoryInfo : u64 { + PhysicalMemoryInfo_Application = 0, + PhysicalMemoryInfo_Applet = 1, + PhysicalMemoryInfo_System = 2, + PhysicalMemoryInfo_SystemUnsafe = 3, + }; + + enum LastThreadInfoFlag : u32 { + /* TODO */ + }; + + enum LimitableResource : u32 { + LimitableResource_PhysicalMemoryMax = 0, + LimitableResource_ThreadCountMax = 1, + LimitableResource_EventCountMax = 2, + LimitableResource_TransferMemoryCountMax = 3, + LimitableResource_SessionCountMax = 4, + + LimitableResource_Count, + }; + + enum CodeMemoryOperation : u32 { + CodeMemoryOperation_MapOwner = 0, + CodeMemoryOperation_MapSlave = 1, + CodeMemoryOperation_UnmapOwner = 2, + CodeMemoryOperation_UnmapSlave = 3, + }; + + /* Synchronization types. */ + enum SignalType : u32 { + SignalType_Signal = 0, + SignalType_SignalAndIfEqual = 1, + SignalType_SignalAndModifyBasedOnWaitingThreadCountIfEqual = 2, + }; + + enum ArbitrationType : u32 { + ArbitrationType_WaitIfLessThan = 0, + ArbitrationType_DecrementAndWaitIfLessThan = 1, + ArbitrationType_WaitIfEqual = 2, + }; + + enum YieldType : s64 { + YieldType_WithoutCoreMigration = 0, + YieldType_WithCoreMigration = -1, + YieldType_ToAnyThread = -2, + }; + + enum InterruptType : u32 { + InterruptType_Edge = 0, + InterruptType_Level = 1, + }; + + /* Thread types. */ + using ThreadFunc = ams::svc::Address; + +#ifdef ATMOSPHERE_ARCH_ARM64 + + struct ThreadContext { + u64 r[29]; + u64 fp; + u64 lr; + u64 sp; + u64 pc; + u32 pstate; + u32 padding; + u128 v[32]; + u32 fpcr; + u32 fpsr; + u64 tpidr; + }; + static_assert(sizeof(ThreadContext) == 0x320); + +#else + #error "Unknown Architecture for ams::svc::ThreadContext" +#endif + + enum ThreadSuspend : u32 { + ThreadSuspend_Debug = (1 << 0), + ThreadSuspend_User = (1 << 1), + }; + + enum ThreadState : u32 { + ThreadState_Waiting = 0, + ThreadState_Running = 1, + ThreadState_Terminated = 4, + ThreadState_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), + }; + + enum ThreadExitReason : u32 { + ThreadExitReason_ExitThread = 0, + ThreadExitReason_TerminateThread = 1, + ThreadExitReason_ExitProcess = 2, + ThreadExitReason_TerminateProcess = 3, + }; + + enum ThreadActivity : u32 { + ThreadActivity_Runnable = 0, + ThreadActivity_Paused = 1, + }; + + /* Process types. */ + enum ProcessInfoType : u32 { + ProcessInfoType_ProcessState = 0, + }; + + enum ProcessState : u32 { + ProcessState_Created = 0, + ProcessState_CreatedAttached = 1, + ProcessState_Running = 2, + ProcessState_Crashed = 3, + ProcessState_RunningAttached = 4, + ProcessState_Exiting = 5, + ProcessState_Exited = 6, + ProcessState_DebugSuspended = 7, + }; + + enum ProcessExitReason : u32 { + ProcessExitReason_ExitProcess = 0, + ProcessExitReason_TerminateProcess = 1, + ProcessExitReason_Exception = 2, + }; + + enum ProcessActivity : u32 { + ProcessActivity_Runnable = 0, + ProcessActivity_Paused = 1, + }; + + 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), + }; + + /* Debug types. */ + enum DebugEvent : u32 { + DebugEvent_AttachProcess = 0, + DebugEvent_AttachThread = 1, + DebugEvent_ExitProcess = 2, + DebugEvent_ExitThread = 3, + DebugEvent_Exception = 4, + }; + + enum DebugThreadParam : u32 { + DebugThreadParam_Priority = 0, + DebugThreadParam_State = 1, + DebugThreadParam_IdealCore = 2, + DebugThreadParam_CurrentCore = 3, + DebugThreadParam_AffinityMask = 4, + }; + + enum DebugException : u32 { + DebugException_UndefinedInstruction = 0, + DebugException_InstructionAbort = 1, + DebugException_DataAbort = 2, + DebugException_AlignmentFault = 3, + DebugException_DebuggerAttached = 4, + DebugException_BreakPoint = 5, + DebugException_UserBreak = 6, + DebugException_DebuggerBreak = 7, + DebugException_UndefinedSystemCall = 8, + DebugException_MemorySystemError = 9, + }; + + enum ExceptionType : u32 { + ExceptionType_Init = 0x000, + ExceptionType_InstructionAbort = 0x100, + ExceptionType_DataAbort = 0x101, + ExceptionType_UnalignedInstruction = 0x102, + ExceptionType_UnalignedData = 0x103, + ExceptionType_UndefinedInstruction = 0x104, + ExceptionType_ExceptionInstruction = 0x105, + ExceptionType_MemorySystemError = 0x106, + ExceptionType_FpuException = 0x200, + ExceptionType_InvalidSystemCall = 0x301, + ExceptionType_SystemCallBreak = 0x302, + + ExceptionType_AtmosphereStdAbort = 0xFFE, + }; + + enum BreakReason : u32 { + /* TODO */ + }; + + enum KernelDebugType : u32 { + /* TODO */ + }; + + enum KernelTraceState : u32 { + KernelTraceState_Disabled = 0, + KernelTraceState_Enabled = 1, + }; + + enum BreakPointType : u32 { + BreakPointType_HardwareInstruction = 0, + BreakPointType_HardwareData = 1, + }; + + enum HardwareBreakPointRegisterName : u32 { + HardwareBreakPointRegisterName_I0 = 0, + HardwareBreakPointRegisterName_I1 = 1, + HardwareBreakPointRegisterName_I2 = 2, + HardwareBreakPointRegisterName_I3 = 3, + HardwareBreakPointRegisterName_I4 = 4, + HardwareBreakPointRegisterName_I5 = 5, + HardwareBreakPointRegisterName_I6 = 6, + HardwareBreakPointRegisterName_I7 = 7, + HardwareBreakPointRegisterName_I8 = 8, + HardwareBreakPointRegisterName_I9 = 9, + HardwareBreakPointRegisterName_I10 = 10, + HardwareBreakPointRegisterName_I11 = 11, + HardwareBreakPointRegisterName_I12 = 12, + HardwareBreakPointRegisterName_I13 = 13, + HardwareBreakPointRegisterName_I14 = 14, + HardwareBreakPointRegisterName_I15 = 15, + HardwareBreakPointRegisterName_D0 = 16, + HardwareBreakPointRegisterName_D1 = 17, + HardwareBreakPointRegisterName_D2 = 18, + HardwareBreakPointRegisterName_D3 = 19, + HardwareBreakPointRegisterName_D4 = 20, + HardwareBreakPointRegisterName_D5 = 21, + HardwareBreakPointRegisterName_D6 = 22, + HardwareBreakPointRegisterName_D7 = 23, + HardwareBreakPointRegisterName_D8 = 24, + HardwareBreakPointRegisterName_D9 = 25, + HardwareBreakPointRegisterName_D10 = 26, + HardwareBreakPointRegisterName_D11 = 27, + HardwareBreakPointRegisterName_D12 = 28, + HardwareBreakPointRegisterName_D13 = 29, + HardwareBreakPointRegisterName_D14 = 30, + HardwareBreakPointRegisterName_D15 = 31, + }; + + /* Architecture specific types. */ + namespace aarch64 { + + struct ExceptionInfo { + u64 r[9]; + u64 lr; + u64 sp; + u64 pc; + u32 pstate; + u32 afsr0; + u32 afsr1; + u32 esr; + u64 far; + }; + static_assert(sizeof(ExceptionInfo) == 0x78); + + struct ProcessLocalRegion { + u64 data[(0x1C0 - sizeof(ExceptionInfo)) / sizeof(u64)]; + ExceptionInfo exception_info; + u64 dying_message_region_address; + u64 dying_message_region_size; + u64 padding[6]; + }; + static_assert(sizeof(ProcessLocalRegion) == 0x200); + static_assert(OFFSETOF(ProcessLocalRegion, dying_message_region_address) == 0x1C0); + + } + + namespace aarch32 { + + struct ExceptionInfoStatus32 { + u32 cpsr; + u32 fsr; + u32 far; + u32 fpexc; + u32 fpinst; + u32 fpinst2; + }; + + struct ExceptionInfoStatus64 { + u32 pstate; + u32 afsr0; + u32 esr; + u32 far; + }; + + struct ExceptionInfo { + u32 r[8]; + u32 sp; + u32 lr; + u32 pc; + u32 flags; + union { + ExceptionInfoStatus32 status_32; + ExceptionInfoStatus64 status_64; + }; + }; + static_assert(sizeof(ExceptionInfo) == 0x48); + + struct ProcessLocalRegion { + u32 data[(0x1C0 - sizeof(ExceptionInfo)) / sizeof(u32)]; + ExceptionInfo exception_info; + u64 dying_message_region_address; + u64 dying_message_region_size; + u64 padding[6]; + }; + static_assert(sizeof(ProcessLocalRegion) == 0x200); + static_assert(OFFSETOF(ProcessLocalRegion, dying_message_region_address) == 0x1C0); + + } + + /* Secure monitor argument shims. */ + namespace lp64 { + + struct SecureMonitorArguments { + u64 r[8]; + }; + static_assert(sizeof(SecureMonitorArguments) == 0x40); + + } + + namespace ilp32 { + + struct SecureMonitorArguments { + u32 r[8]; + }; + static_assert(sizeof(SecureMonitorArguments) == 0x20); + + } + +} diff --git a/libvapours/include/vapours/svc/svc_types_dd.hpp b/libvapours/include/vapours/svc/svc_types_dd.hpp new file mode 100644 index 00000000..d4323085 --- /dev/null +++ b/libvapours/include/vapours/svc/svc_types_dd.hpp @@ -0,0 +1,51 @@ +/* + * 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 "svc_types_common.hpp" + +#ifdef ATMOSPHERE_BOARD_NINTENDO_SWITCH + + #include "board/nintendo/switch/svc_device_name.hpp" + +#else + + #error "Unknown board for svc::DeviceName" + +#endif + +namespace ams::svc { + + namespace lp64 { + + struct PhysicalMemoryInfo { + PhysicalAddress physical_address; + u64 virtual_address; + u64 size; + }; + + } + + namespace ilp32 { + + struct PhysicalMemoryInfo { + PhysicalAddress physical_address; + u32 virtual_address; + u32 size; + }; + + } + +} diff --git a/libvapours/include/vapours/svc/svc_types_dmnt.hpp b/libvapours/include/vapours/svc/svc_types_dmnt.hpp new file mode 100644 index 00000000..fa6d699e --- /dev/null +++ b/libvapours/include/vapours/svc/svc_types_dmnt.hpp @@ -0,0 +1,200 @@ +/* + * 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 "svc_types_common.hpp" + +namespace ams::svc { + + namespace lp64 { + + struct DebugInfoAttachProcess { + u64 program_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; + }; + + struct DebugInfoExitProcess { + ProcessExitReason reason; + }; + + struct DebugInfoExitThread { + ThreadExitReason reason; + }; + + struct DebugInfoUndefinedInstructionException { + u32 insn; + }; + + struct DebugInfoDataAbortException { + u64 address; + }; + + struct DebugInfoAlignmentFaultException { + u64 address; + }; + + struct DebugInfoBreakPointException { + BreakPointType type; + u64 address; + }; + + struct DebugInfoUserBreakException { + BreakReason break_reason; + u64 address; + u64 size; + }; + + struct DebugInfoDebuggerBreakException { + u64 active_thread_ids[4]; + }; + + struct DebugInfoUndefinedSystemCallException { + u32 id; + }; + + union DebugInfoSpecificException { + DebugInfoUndefinedInstructionException undefined_instruction; + DebugInfoDataAbortException data_abort; + DebugInfoAlignmentFaultException alignment_fault; + DebugInfoBreakPointException break_point; + DebugInfoUserBreakException user_break; + DebugInfoDebuggerBreakException debugger_break; + DebugInfoUndefinedSystemCallException undefined_system_call; + u64 raw; + }; + + struct DebugInfoException { + DebugException type; + u64 address; + DebugInfoSpecificException specific; + }; + + union DebugInfo { + DebugInfoAttachProcess attach_process; + DebugInfoAttachThread attach_thread; + DebugInfoExitProcess exit_process; + DebugInfoExitThread exit_thread; + DebugInfoException exception; + }; + + struct DebugEventInfo { + DebugEvent type; + u32 flags; + u64 thread_id; + DebugInfo info; + }; + static_assert(sizeof(DebugEventInfo) >= 0x40); + + } + + namespace ilp32 { + + struct DebugInfoAttachProcess { + u64 program_id; + u64 process_id; + char name[0xC]; + u32 flags; + u32 user_exception_context_address; /* 5.0.0+ */ + }; + + struct DebugInfoAttachThread { + u64 thread_id; + u32 tls_address; + u32 entrypoint; + }; + + struct DebugInfoExitProcess { + ProcessExitReason reason; + }; + + struct DebugInfoExitThread { + ThreadExitReason reason; + }; + + struct DebugInfoUndefinedInstructionException { + u32 insn; + }; + + struct DebugInfoDataAbortException { + u32 address; + }; + + struct DebugInfoAlignmentFaultException { + u32 address; + }; + + struct DebugInfoBreakPointException { + BreakPointType type; + u32 address; + }; + + struct DebugInfoUserBreakException { + BreakReason break_reason; + u32 address; + u32 size; + }; + + struct DebugInfoDebuggerBreakException { + u64 active_thread_ids[4]; + }; + + struct DebugInfoUndefinedSystemCallException { + u32 id; + }; + + union DebugInfoSpecificException { + DebugInfoUndefinedInstructionException undefined_instruction; + DebugInfoDataAbortException data_abort; + DebugInfoAlignmentFaultException alignment_fault; + DebugInfoBreakPointException break_point; + DebugInfoUserBreakException user_break; + DebugInfoDebuggerBreakException debugger_break; + DebugInfoUndefinedSystemCallException undefined_system_call; + u64 raw; + }; + + struct DebugInfoException { + DebugException type; + u32 address; + DebugInfoSpecificException specific; + }; + + union DebugInfo { + DebugInfoAttachProcess attach_process; + DebugInfoAttachThread attach_thread; + DebugInfoExitProcess exit_process; + DebugInfoExitThread exit_thread; + DebugInfoException exception; + }; + + struct DebugEventInfo { + DebugEvent type; + u32 flags; + u64 thread_id; + DebugInfo info; + }; + + } + +} diff --git a/libvapours/include/vapours/svc/svc_types_priv.hpp b/libvapours/include/vapours/svc/svc_types_priv.hpp new file mode 100644 index 00000000..08c8fb28 --- /dev/null +++ b/libvapours/include/vapours/svc/svc_types_priv.hpp @@ -0,0 +1,53 @@ +/* + * 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 "svc_types_common.hpp" + +namespace ams::svc { + + namespace lp64 { + + struct CreateProcessParameter { + char name[12]; + u32 version; + u64 program_id; + u64 code_address; + u32 code_num_pages; + u32 flags; + Handle reslimit; + u32 system_resource_num_pages; + }; + static_assert(sizeof(CreateProcessParameter) == 0x30); + + } + + namespace ilp32 { + + struct CreateProcessParameter { + char name[12]; + u32 version; + u64 program_id; + u64 code_address; + u32 code_num_pages; + u32 flags; + Handle reslimit; + u32 system_resource_num_pages; + }; + static_assert(sizeof(CreateProcessParameter) == 0x30); + + } + +} diff --git a/libvapours/include/vapours/types.hpp b/libvapours/include/vapours/types.hpp index 894ec889..91d8a09b 100644 --- a/libvapours/include/vapours/types.hpp +++ b/libvapours/include/vapours/types.hpp @@ -45,7 +45,7 @@ typedef volatile s32 vs32; ///< 32-bit volatile signed integer. typedef volatile s64 vs64; ///< 64-bit volatile signed integer. typedef volatile s128 vs128; ///< 128-bit volatile signed integer. -typedef u32 Result; ///< Function error code result type. +typedef u32 Result; ///< Function error code result type. /// Creates a bitmask from a bit number. #ifndef BIT @@ -70,4 +70,4 @@ typedef u32 Result; ///< Function error code result type. #define NX_CONSTEXPR NX_INLINE constexpr #else #define NX_CONSTEXPR NX_INLINE -#endif \ No newline at end of file +#endif