strat: use svc:: over ::svc

This commit is contained in:
Michael Scire 2021-10-04 14:54:13 -07:00
parent 002422d5dc
commit 5a71876ca8
23 changed files with 366 additions and 369 deletions

View File

@ -22,7 +22,7 @@ namespace ams::fssystem {
fs::fsa::IFileSystem *GetExternalCodeFileSystem(ncm::ProgramId program_id); fs::fsa::IFileSystem *GetExternalCodeFileSystem(ncm::ProgramId program_id);
Result CreateExternalCode(Handle *out, ncm::ProgramId program_id); Result CreateExternalCode(os::NativeHandle *out, ncm::ProgramId program_id);
void DestroyExternalCode(ncm::ProgramId program_id); void DestroyExternalCode(ncm::ProgramId program_id);
} }

View File

@ -152,7 +152,7 @@ namespace ams::fssystem {
NX_INLINE Result RetryFinitelyForTargetLocked(F f) { NX_INLINE Result RetryFinitelyForTargetLocked(F f) {
/* Retry up to 10 times, 100ms between retries. */ /* Retry up to 10 times, 100ms between retries. */
constexpr s32 MaxRetryCount = 10; constexpr s32 MaxRetryCount = 10;
constexpr u64 RetryWaitTime = 100'000'000ul; constexpr TimeSpan RetryWaitTime = TimeSpan::FromMilliSeconds(100);
s32 remaining_retries = MaxRetryCount; s32 remaining_retries = MaxRetryCount;
while (true) { while (true) {
@ -161,7 +161,7 @@ namespace ams::fssystem {
R_UNLESS(remaining_retries > 0, fs::ResultTargetLocked()); R_UNLESS(remaining_retries > 0, fs::ResultTargetLocked());
remaining_retries--; remaining_retries--;
svcSleepThread(RetryWaitTime); os::SleepThread(RetryWaitTime);
continue; continue;
} }
} R_END_TRY_CATCH; } R_END_TRY_CATCH;

View File

@ -20,9 +20,9 @@
namespace ams::map { namespace ams::map {
/* Public API. */ /* Public API. */
Result GetProcessAddressSpaceInfo(AddressSpaceInfo *out, Handle process_h); Result GetProcessAddressSpaceInfo(AddressSpaceInfo *out, os::NativeHandle process_h);
Result LocateMappableSpace(uintptr_t *out_address, size_t size); Result LocateMappableSpace(uintptr_t *out_address, size_t size);
Result MapCodeMemoryInProcess(MappedCodeMemory &out_mcm, Handle process_handle, uintptr_t base_address, size_t size); Result MapCodeMemoryInProcess(MappedCodeMemory &out_mcm, os::NativeHandle process_handle, uintptr_t base_address, size_t size);
bool CanAddGuardRegionsInProcess(Handle process_handle, uintptr_t address, size_t size); bool CanAddGuardRegionsInProcess(os::NativeHandle process_handle, uintptr_t address, size_t size);
} }

View File

@ -16,6 +16,7 @@
#pragma once #pragma once
#include <vapours.hpp> #include <vapours.hpp>
#include <stratosphere/os/os_native_handle.hpp>
namespace ams::map { namespace ams::map {
@ -41,19 +42,19 @@ namespace ams::map {
class AutoCloseMap { class AutoCloseMap {
private: private:
Handle process_handle; os::NativeHandle process_handle;
Result result; Result result;
void *mapped_address; uintptr_t mapped_address;
uintptr_t base_address; uintptr_t base_address;
size_t size; size_t size;
public: public:
AutoCloseMap(uintptr_t mp, Handle p_h, uintptr_t ba, size_t sz) : process_handle(p_h), mapped_address(reinterpret_cast<void *>(mp)), base_address(ba), size(sz) { AutoCloseMap(uintptr_t mp, os::NativeHandle p_h, uintptr_t ba, size_t sz) : process_handle(p_h), mapped_address(mp), base_address(ba), size(sz) {
this->result = svcMapProcessMemory(this->mapped_address, this->process_handle, this->base_address, this->size); this->result = svc::MapProcessMemory(this->mapped_address, this->process_handle, this->base_address, this->size);
} }
~AutoCloseMap() { ~AutoCloseMap() {
if (this->process_handle != INVALID_HANDLE && R_SUCCEEDED(this->result)) { if (this->process_handle != os::InvalidNativeHandle && R_SUCCEEDED(this->result)) {
R_ABORT_UNLESS(svcUnmapProcessMemory(this->mapped_address, this->process_handle, this->base_address, this->size)); R_ABORT_UNLESS(svc::UnmapProcessMemory(this->mapped_address, this->process_handle, this->base_address, this->size));
} }
} }
@ -66,7 +67,7 @@ namespace ams::map {
} }
void Invalidate() { void Invalidate() {
this->process_handle = INVALID_HANDLE; this->process_handle = os::InvalidNativeHandle;
} }
}; };
@ -78,17 +79,17 @@ namespace ams::map {
uintptr_t src_address; uintptr_t src_address;
size_t size; size_t size;
public: public:
MappedCodeMemory(Result init_res) : process_handle(INVALID_HANDLE), result(init_res), dst_address(0), src_address(0), size(0) { MappedCodeMemory(Result init_res) : process_handle(os::InvalidNativeHandle), result(init_res), dst_address(0), src_address(0), size(0) {
/* ... */ /* ... */
} }
MappedCodeMemory(Handle p_h, uintptr_t dst, uintptr_t src, size_t sz) : process_handle(p_h), dst_address(dst), src_address(src), size(sz) { MappedCodeMemory(Handle p_h, uintptr_t dst, uintptr_t src, size_t sz) : process_handle(p_h), dst_address(dst), src_address(src), size(sz) {
this->result = svcMapProcessCodeMemory(this->process_handle, this->dst_address, this->src_address, this->size); this->result = svc::MapProcessCodeMemory(this->process_handle, this->dst_address, this->src_address, this->size);
} }
~MappedCodeMemory() { ~MappedCodeMemory() {
if (this->process_handle != INVALID_HANDLE && R_SUCCEEDED(this->result) && this->size > 0) { if (this->process_handle != os::InvalidNativeHandle && R_SUCCEEDED(this->result) && this->size > 0) {
R_ABORT_UNLESS(svcUnmapProcessCodeMemory(this->process_handle, this->dst_address, this->src_address, this->size)); R_ABORT_UNLESS(svc::UnmapProcessCodeMemory(this->process_handle, this->dst_address, this->src_address, this->size));
} }
} }
@ -105,7 +106,7 @@ namespace ams::map {
} }
void Invalidate() { void Invalidate() {
this->process_handle = INVALID_HANDLE; this->process_handle = os::InvalidNativeHandle;
} }
MappedCodeMemory &operator=(MappedCodeMemory &&o) { MappedCodeMemory &operator=(MappedCodeMemory &&o) {

View File

@ -26,8 +26,8 @@ namespace ams::pm::dmnt {
Result StartProcess(os::ProcessId process_id); Result StartProcess(os::ProcessId process_id);
Result GetProcessId(os::ProcessId *out_process_id, const ncm::ProgramId program_id); Result GetProcessId(os::ProcessId *out_process_id, const ncm::ProgramId program_id);
Result GetApplicationProcessId(os::ProcessId *out_process_id); Result GetApplicationProcessId(os::ProcessId *out_process_id);
Result HookToCreateApplicationProcess(Handle *out_handle); Result HookToCreateApplicationProcess(os::NativeHandle *out_handle);
Result AtmosphereGetProcessInfo(Handle *out_handle, ncm::ProgramLocation *out_loc, cfg::OverrideStatus *out_status, os::ProcessId process_id); Result AtmosphereGetProcessInfo(os::NativeHandle *out_handle, ncm::ProgramLocation *out_loc, cfg::OverrideStatus *out_status, os::ProcessId process_id);
Result AtmosphereGetCurrentLimitInfo(u64 *out_current_value, u64 *out_limit_value, ResourceLimitGroup group, LimitableResource resource); Result AtmosphereGetCurrentLimitInfo(u64 *out_current_value, u64 *out_limit_value, ResourceLimitGroup group, LimitableResource resource);
} }

View File

@ -28,13 +28,13 @@ namespace ams::sf::hipc {
NeedsRetry, NeedsRetry,
}; };
void AttachMultiWaitHolderForAccept(os::MultiWaitHolderType *holder, Handle port); void AttachMultiWaitHolderForAccept(os::MultiWaitHolderType *holder, os::NativeHandle port);
void AttachMultiWaitHolderForReply(os::MultiWaitHolderType *holder, Handle request); void AttachMultiWaitHolderForReply(os::MultiWaitHolderType *holder, os::NativeHandle request);
Result Receive(ReceiveResult *out_recv_result, Handle session_handle, const cmif::PointerAndSize &message_buffer); Result Receive(ReceiveResult *out_recv_result, os::NativeHandle session_handle, const cmif::PointerAndSize &message_buffer);
Result Receive(bool *out_closed, Handle session_handle, const cmif::PointerAndSize &message_buffer); Result Receive(bool *out_closed, os::NativeHandle session_handle, const cmif::PointerAndSize &message_buffer);
Result Reply(Handle session_handle, const cmif::PointerAndSize &message_buffer); Result Reply(os::NativeHandle session_handle, const cmif::PointerAndSize &message_buffer);
Result CreateSession(Handle *out_server_handle, Handle *out_client_handle); Result CreateSession(os::NativeHandle *out_server_handle, os::NativeHandle *out_client_handle);
} }

View File

@ -49,11 +49,11 @@ namespace ams::sf::hipc {
cmif::PointerAndSize pointer_buffer; cmif::PointerAndSize pointer_buffer;
cmif::PointerAndSize saved_message; cmif::PointerAndSize saved_message;
std::shared_ptr<::Service> forward_service; std::shared_ptr<::Service> forward_service;
Handle session_handle; os::NativeHandle session_handle;
bool is_closed; bool is_closed;
bool has_received; bool has_received;
public: public:
ServerSession(Handle h, cmif::ServiceObjectHolder &&obj) : srv_obj_holder(std::move(obj)), session_handle(h) { ServerSession(os::NativeHandle h, cmif::ServiceObjectHolder &&obj) : srv_obj_holder(std::move(obj)), session_handle(h) {
hipc::AttachMultiWaitHolderForReply(this, h); hipc::AttachMultiWaitHolderForReply(this, h);
this->is_closed = false; this->is_closed = false;
this->has_received = false; this->has_received = false;
@ -61,7 +61,7 @@ namespace ams::sf::hipc {
AMS_ABORT_UNLESS(!this->IsMitmSession()); AMS_ABORT_UNLESS(!this->IsMitmSession());
} }
ServerSession(Handle h, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv) : srv_obj_holder(std::move(obj)), session_handle(h) { ServerSession(os::NativeHandle h, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv) : srv_obj_holder(std::move(obj)), session_handle(h) {
hipc::AttachMultiWaitHolderForReply(this, h); hipc::AttachMultiWaitHolderForReply(this, h);
this->is_closed = false; this->is_closed = false;
this->has_received = false; this->has_received = false;
@ -117,55 +117,55 @@ namespace ams::sf::hipc {
Result ReceiveRequestImpl(ServerSession *session, const cmif::PointerAndSize &message); Result ReceiveRequestImpl(ServerSession *session, const cmif::PointerAndSize &message);
void CloseSessionImpl(ServerSession *session); void CloseSessionImpl(ServerSession *session);
Result RegisterSessionImpl(ServerSession *session_memory, Handle session_handle, cmif::ServiceObjectHolder &&obj); Result RegisterSessionImpl(ServerSession *session_memory, os::NativeHandle session_handle, cmif::ServiceObjectHolder &&obj);
Result AcceptSessionImpl(ServerSession *session_memory, Handle port_handle, cmif::ServiceObjectHolder &&obj); Result AcceptSessionImpl(ServerSession *session_memory, os::NativeHandle port_handle, cmif::ServiceObjectHolder &&obj);
Result RegisterMitmSessionImpl(ServerSession *session_memory, Handle mitm_session_handle, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv); Result RegisterMitmSessionImpl(ServerSession *session_memory, os::NativeHandle mitm_session_handle, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv);
Result AcceptMitmSessionImpl(ServerSession *session_memory, Handle mitm_port_handle, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv); Result AcceptMitmSessionImpl(ServerSession *session_memory, os::NativeHandle mitm_port_handle, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv);
Result ReceiveRequest(ServerSession *session, const cmif::PointerAndSize &message) { Result ReceiveRequest(ServerSession *session, const cmif::PointerAndSize &message) {
return this->ReceiveRequestImpl(session, message); return this->ReceiveRequestImpl(session, message);
} }
Result RegisterSession(ServerSession **out, Handle session_handle, cmif::ServiceObjectHolder &&obj) { Result RegisterSession(ServerSession **out, os::NativeHandle session_handle, cmif::ServiceObjectHolder &&obj) {
auto ctor = [&](ServerSession *session_memory) -> Result { auto ctor = [&](ServerSession *session_memory) -> Result {
return this->RegisterSessionImpl(session_memory, session_handle, std::forward<cmif::ServiceObjectHolder>(obj)); return this->RegisterSessionImpl(session_memory, session_handle, std::forward<cmif::ServiceObjectHolder>(obj));
}; };
return this->CreateSessionImpl(out, ctor); return this->CreateSessionImpl(out, ctor);
} }
Result AcceptSession(ServerSession **out, Handle port_handle, cmif::ServiceObjectHolder &&obj) { Result AcceptSession(ServerSession **out, os::NativeHandle port_handle, cmif::ServiceObjectHolder &&obj) {
auto ctor = [&](ServerSession *session_memory) -> Result { auto ctor = [&](ServerSession *session_memory) -> Result {
return this->AcceptSessionImpl(session_memory, port_handle, std::forward<cmif::ServiceObjectHolder>(obj)); return this->AcceptSessionImpl(session_memory, port_handle, std::forward<cmif::ServiceObjectHolder>(obj));
}; };
return this->CreateSessionImpl(out, ctor); return this->CreateSessionImpl(out, ctor);
} }
Result RegisterMitmSession(ServerSession **out, Handle mitm_session_handle, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv) { Result RegisterMitmSession(ServerSession **out, os::NativeHandle mitm_session_handle, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv) {
auto ctor = [&](ServerSession *session_memory) -> Result { auto ctor = [&](ServerSession *session_memory) -> Result {
return this->RegisterMitmSessionImpl(session_memory, mitm_session_handle, std::forward<cmif::ServiceObjectHolder>(obj), std::forward<std::shared_ptr<::Service>>(fsrv)); return this->RegisterMitmSessionImpl(session_memory, mitm_session_handle, std::forward<cmif::ServiceObjectHolder>(obj), std::forward<std::shared_ptr<::Service>>(fsrv));
}; };
return this->CreateSessionImpl(out, ctor); return this->CreateSessionImpl(out, ctor);
} }
Result AcceptMitmSession(ServerSession **out, Handle mitm_port_handle, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv) { Result AcceptMitmSession(ServerSession **out, os::NativeHandle mitm_port_handle, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv) {
auto ctor = [&](ServerSession *session_memory) -> Result { auto ctor = [&](ServerSession *session_memory) -> Result {
return this->AcceptMitmSessionImpl(session_memory, mitm_port_handle, std::forward<cmif::ServiceObjectHolder>(obj), std::forward<std::shared_ptr<::Service>>(fsrv)); return this->AcceptMitmSessionImpl(session_memory, mitm_port_handle, std::forward<cmif::ServiceObjectHolder>(obj), std::forward<std::shared_ptr<::Service>>(fsrv));
}; };
return this->CreateSessionImpl(out, ctor); return this->CreateSessionImpl(out, ctor);
} }
public: public:
Result RegisterSession(Handle session_handle, cmif::ServiceObjectHolder &&obj); Result RegisterSession(os::NativeHandle session_handle, cmif::ServiceObjectHolder &&obj);
Result AcceptSession(Handle port_handle, cmif::ServiceObjectHolder &&obj); Result AcceptSession(os::NativeHandle port_handle, cmif::ServiceObjectHolder &&obj);
Result RegisterMitmSession(Handle session_handle, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv); Result RegisterMitmSession(os::NativeHandle session_handle, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv);
Result AcceptMitmSession(Handle mitm_port_handle, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv); Result AcceptMitmSession(os::NativeHandle mitm_port_handle, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv);
template<typename Interface> template<typename Interface>
Result AcceptSession(Handle port_handle, SharedPointer<Interface> obj) { Result AcceptSession(os::NativeHandle port_handle, SharedPointer<Interface> obj) {
return this->AcceptSession(port_handle, cmif::ServiceObjectHolder(std::move(obj))); return this->AcceptSession(port_handle, cmif::ServiceObjectHolder(std::move(obj)));
} }
template<typename Interface> template<typename Interface>
Result AcceptMitmSession(Handle mitm_port_handle, SharedPointer<Interface> obj, std::shared_ptr<::Service> &&fsrv) { Result AcceptMitmSession(os::NativeHandle mitm_port_handle, SharedPointer<Interface> obj, std::shared_ptr<::Service> &&fsrv) {
return this->AcceptMitmSession(mitm_port_handle, cmif::ServiceObjectHolder(std::move(obj)), std::forward<std::shared_ptr<::Service>>(fsrv)); return this->AcceptMitmSession(mitm_port_handle, cmif::ServiceObjectHolder(std::move(obj)), std::forward<std::shared_ptr<::Service>>(fsrv));
} }

View File

@ -837,12 +837,12 @@ namespace ams::sf::impl {
private: private:
template<size_t Index> template<size_t Index>
NX_CONSTEXPR void SetOutObjectImpl(const HipcRequest &response, hipc::ServerSessionManager *manager, cmif::ServiceObjectHolder &&object) { NX_CONSTEXPR void SetOutObjectImpl(const HipcRequest &response, hipc::ServerSessionManager *manager, cmif::ServiceObjectHolder &&object) {
/* If no object, write INVALID_HANDLE. This is what official software does. */ /* If no object, write os::InvalidNativeHandle. This is what official software does. */
if (!object) { if (!object) {
response.move_handles[Index] = INVALID_HANDLE; response.move_handles[Index] = os::InvalidNativeHandle;
return; return;
} }
Handle server_handle, client_handle; os::NativeHandle server_handle, client_handle;
R_ABORT_UNLESS(sf::hipc::CreateSession(&server_handle, &client_handle)); R_ABORT_UNLESS(sf::hipc::CreateSession(&server_handle, &client_handle));
R_ABORT_UNLESS(manager->RegisterSession(server_handle, std::move(object))); R_ABORT_UNLESS(manager->RegisterSession(server_handle, std::move(object)));
response.move_handles[Index] = client_handle; response.move_handles[Index] = client_handle;

View File

@ -28,17 +28,17 @@ namespace ams::sf {
template<u32 Attribute> template<u32 Attribute>
struct InHandle : public InHandleTag { struct InHandle : public InHandleTag {
::Handle handle; os::NativeHandle handle;
constexpr InHandle() : handle(INVALID_HANDLE) { /* ... */ } constexpr InHandle() : handle(os::InvalidNativeHandle) { /* ... */ }
constexpr InHandle(::Handle h) : handle(h) { /* ... */ } constexpr InHandle(os::NativeHandle h) : handle(h) { /* ... */ }
constexpr InHandle(const InHandle &o) : handle(o.handle) { /* ... */ } constexpr InHandle(const InHandle &o) : handle(o.handle) { /* ... */ }
constexpr void operator=(const ::Handle &h) { this->handle = h; } constexpr void operator=(const os::NativeHandle &h) { this->handle = h; }
constexpr void operator=(const InHandle &o) { this->handle = o.handle; } constexpr void operator=(const InHandle &o) { this->handle = o.handle; }
constexpr /* TODO: explicit? */ operator ::Handle() const { return this->handle; } constexpr /* TODO: explicit? */ operator os::NativeHandle() const { return this->handle; }
constexpr ::Handle GetValue() const { return this->handle; } constexpr os::NativeHandle GetValue() const { return this->handle; }
}; };
template<typename T> template<typename T>
@ -49,7 +49,7 @@ namespace ams::sf {
public: public:
constexpr OutHandleImpl(T *p) : ptr(p) { /* ... */ } constexpr OutHandleImpl(T *p) : ptr(p) { /* ... */ }
constexpr void SetValue(const Handle &value) { constexpr void SetValue(const os::NativeHandle &value) {
*this->ptr = value; *this->ptr = value;
} }
@ -65,7 +65,7 @@ namespace ams::sf {
return this->ptr; return this->ptr;
} }
constexpr Handle *GetHandlePointer() const { constexpr os::NativeHandle *GetHandlePointer() const {
return &this->ptr->handle; return &this->ptr->handle;
} }
@ -83,8 +83,8 @@ namespace ams::sf {
using MoveHandle = typename impl::InHandle<SfOutHandleAttr_HipcMove>; using MoveHandle = typename impl::InHandle<SfOutHandleAttr_HipcMove>;
using CopyHandle = typename impl::InHandle<SfOutHandleAttr_HipcCopy>; using CopyHandle = typename impl::InHandle<SfOutHandleAttr_HipcCopy>;
static_assert(sizeof(MoveHandle) == sizeof(::Handle), "sizeof(MoveHandle)"); static_assert(sizeof(MoveHandle) == sizeof(os::NativeHandle), "sizeof(MoveHandle)");
static_assert(sizeof(CopyHandle) == sizeof(::Handle), "sizeof(CopyHandle)"); static_assert(sizeof(CopyHandle) == sizeof(os::NativeHandle), "sizeof(CopyHandle)");
template<> template<>
class IsOutForceEnabled<MoveHandle> : public std::true_type{}; class IsOutForceEnabled<MoveHandle> : public std::true_type{};
@ -99,7 +99,7 @@ namespace ams::sf {
public: public:
constexpr Out<T>(T *p) : Base(p) { /* ... */ } constexpr Out<T>(T *p) : Base(p) { /* ... */ }
constexpr void SetValue(const Handle &value) { constexpr void SetValue(const os::NativeHandle &value) {
Base::SetValue(value); Base::SetValue(value);
} }
@ -115,7 +115,7 @@ namespace ams::sf {
return Base::GetPointer(); return Base::GetPointer();
} }
constexpr Handle *GetHandlePointer() const { constexpr os::NativeHandle *GetHandlePointer() const {
return Base::GetHandlePointer(); return Base::GetHandlePointer();
} }
@ -139,7 +139,7 @@ namespace ams::sf {
constexpr Out<T>(T *p) : Base(p), m_managed(nullptr) { /* ... */ } constexpr Out<T>(T *p) : Base(p), m_managed(nullptr) { /* ... */ }
constexpr Out<T>(T *p, bool *m) : Base(p), m_managed(m) { /* ... */ } constexpr Out<T>(T *p, bool *m) : Base(p), m_managed(m) { /* ... */ }
constexpr void SetValue(const Handle &value) { constexpr void SetValue(const os::NativeHandle &value) {
Base::SetValue(value); Base::SetValue(value);
} }
@ -160,7 +160,7 @@ namespace ams::sf {
return Base::GetPointer(); return Base::GetPointer();
} }
constexpr Handle *GetHandlePointer() const { constexpr os::NativeHandle *GetHandlePointer() const {
return Base::GetHandlePointer(); return Base::GetHandlePointer();
} }

View File

@ -390,6 +390,10 @@
return ::svcContinueDebugEvent(debug_handle, flags, const_cast<u64 *>(thread_ids.GetPointerUnsafe()), num_thread_ids); return ::svcContinueDebugEvent(debug_handle, flags, const_cast<u64 *>(thread_ids.GetPointerUnsafe()), num_thread_ids);
} }
ALWAYS_INLINE Result LegacyContinueDebugEvent(::ams::svc::Handle debug_handle, uint32_t flags, uint64_t thread_id) {
return ::svcLegacyContinueDebugEvent(debug_handle, flags, thread_id);
}
ALWAYS_INLINE Result GetProcessList(int32_t *out_num_processes, ::ams::svc::UserPointer<uint64_t *> out_process_ids, int32_t max_out_count) { ALWAYS_INLINE Result GetProcessList(int32_t *out_num_processes, ::ams::svc::UserPointer<uint64_t *> out_process_ids, int32_t max_out_count) {
return ::svcGetProcessList(out_num_processes, out_process_ids.GetPointerUnsafe(), max_out_count); return ::svcGetProcessList(out_num_processes, out_process_ids.GetPointerUnsafe(), max_out_count);
} }

View File

@ -27,17 +27,17 @@ namespace ams::tipc {
template<u32 Attribute> template<u32 Attribute>
struct InHandle : public InHandleTag { struct InHandle : public InHandleTag {
::Handle handle; os::NativeHandle handle;
constexpr InHandle() : handle(INVALID_HANDLE) { /* ... */ } constexpr InHandle() : handle(os::InvalidNativeHandle) { /* ... */ }
constexpr InHandle(::Handle h) : handle(h) { /* ... */ } constexpr InHandle(os::NativeHandle h) : handle(h) { /* ... */ }
constexpr InHandle(const InHandle &o) : handle(o.handle) { /* ... */ } constexpr InHandle(const InHandle &o) : handle(o.handle) { /* ... */ }
constexpr void operator=(const ::Handle &h) { this->handle = h; } constexpr void operator=(const os::NativeHandle &h) { this->handle = h; }
constexpr void operator=(const InHandle &o) { this->handle = o.handle; } constexpr void operator=(const InHandle &o) { this->handle = o.handle; }
constexpr /* TODO: explicit? */ operator ::Handle() const { return this->handle; } constexpr /* TODO: explicit? */ operator os::NativeHandle() const { return this->handle; }
constexpr ::Handle GetValue() const { return this->handle; } constexpr os::NativeHandle GetValue() const { return this->handle; }
}; };
template<typename T> template<typename T>
@ -48,7 +48,7 @@ namespace ams::tipc {
public: public:
constexpr OutHandleImpl(T *p) : ptr(p) { /* ... */ } constexpr OutHandleImpl(T *p) : ptr(p) { /* ... */ }
constexpr void SetValue(const Handle &value) { constexpr void SetValue(const os::NativeHandle &value) {
*this->ptr = value; *this->ptr = value;
} }
@ -64,7 +64,7 @@ namespace ams::tipc {
return this->ptr; return this->ptr;
} }
constexpr Handle *GetHandlePointer() const { constexpr os::NativeHandle *GetHandlePointer() const {
return &this->ptr->handle; return &this->ptr->handle;
} }
@ -82,8 +82,8 @@ namespace ams::tipc {
using MoveHandle = typename impl::InHandle<SfOutHandleAttr_HipcMove>; using MoveHandle = typename impl::InHandle<SfOutHandleAttr_HipcMove>;
using CopyHandle = typename impl::InHandle<SfOutHandleAttr_HipcCopy>; using CopyHandle = typename impl::InHandle<SfOutHandleAttr_HipcCopy>;
static_assert(sizeof(MoveHandle) == sizeof(::Handle), "sizeof(MoveHandle)"); static_assert(sizeof(MoveHandle) == sizeof(os::NativeHandle), "sizeof(MoveHandle)");
static_assert(sizeof(CopyHandle) == sizeof(::Handle), "sizeof(CopyHandle)"); static_assert(sizeof(CopyHandle) == sizeof(os::NativeHandle), "sizeof(CopyHandle)");
template<> template<>
class IsOutForceEnabled<MoveHandle> : public std::true_type{}; class IsOutForceEnabled<MoveHandle> : public std::true_type{};
@ -98,7 +98,7 @@ namespace ams::tipc {
public: public:
constexpr Out<T>(T *p) : Base(p) { /* ... */ } constexpr Out<T>(T *p) : Base(p) { /* ... */ }
constexpr void SetValue(const Handle &value) { constexpr void SetValue(const os::NativeHandle &value) {
Base::SetValue(value); Base::SetValue(value);
} }
@ -114,7 +114,7 @@ namespace ams::tipc {
return Base::GetPointer(); return Base::GetPointer();
} }
constexpr Handle *GetHandlePointer() const { constexpr os::NativeHandle *GetHandlePointer() const {
return Base::GetHandlePointer(); return Base::GetHandlePointer();
} }
@ -135,7 +135,7 @@ namespace ams::tipc {
public: public:
constexpr Out<T>(T *p) : Base(p) { /* ... */ } constexpr Out<T>(T *p) : Base(p) { /* ... */ }
constexpr void SetValue(const Handle &value) { constexpr void SetValue(const os::NativeHandle &value) {
Base::SetValue(value); Base::SetValue(value);
} }
@ -151,7 +151,7 @@ namespace ams::tipc {
return Base::GetPointer(); return Base::GetPointer();
} }
constexpr Handle *GetHandlePointer() const { constexpr os::NativeHandle *GetHandlePointer() const {
return Base::GetHandlePointer(); return Base::GetHandlePointer();
} }

View File

@ -141,7 +141,7 @@ namespace ams {
} }
/* Grab 0x100 of tls. */ /* Grab 0x100 of tls. */
std::memcpy(ams_ctx.tls, armGetTls(), sizeof(ams_ctx.tls)); std::memcpy(ams_ctx.tls, svc::GetThreadLocalRegion(), sizeof(ams_ctx.tls));
} }
/* Just call the user exception handler. */ /* Just call the user exception handler. */

View File

@ -52,10 +52,10 @@ namespace ams::fssystem {
return nullptr; return nullptr;
} }
Result CreateExternalCode(Handle *out, ncm::ProgramId program_id) { Result CreateExternalCode(os::NativeHandle *out, ncm::ProgramId program_id) {
/* Create a handle pair. */ /* Create a handle pair. */
Handle server, client; os::NativeHandle server, client;
R_TRY(svcCreateSession(std::addressof(server), std::addressof(client), false, 0)); R_TRY(svc::CreateSession(std::addressof(server), std::addressof(client), false, 0));
/* Insert the handle into the map. */ /* Insert the handle into the map. */
g_hnd_map.Emplace(program_id, client); g_hnd_map.Emplace(program_id, client);

View File

@ -25,8 +25,8 @@ namespace ams::map {
/* Deprecated/Modern implementations. */ /* Deprecated/Modern implementations. */
Result LocateMappableSpaceDeprecated(uintptr_t *out_address, size_t size) { Result LocateMappableSpaceDeprecated(uintptr_t *out_address, size_t size) {
MemoryInfo mem_info = {}; svc::MemoryInfo mem_info;
u32 page_info = 0; svc::PageInfo page_info;
uintptr_t cur_base = 0; uintptr_t cur_base = 0;
AddressSpaceInfo address_space; AddressSpaceInfo address_space;
@ -34,15 +34,15 @@ namespace ams::map {
cur_base = address_space.aslr_base; cur_base = address_space.aslr_base;
do { do {
R_TRY(svcQueryMemory(&mem_info, &page_info, cur_base)); R_TRY(svc::QueryMemory(&mem_info, &page_info, cur_base));
if (mem_info.type == MemType_Unmapped && mem_info.addr - cur_base + mem_info.size >= size) { if (mem_info.state == svc::MemoryState_Free && mem_info.addr - cur_base + mem_info.size >= size) {
*out_address = cur_base; *out_address = cur_base;
return ResultSuccess(); return ResultSuccess();
} }
const uintptr_t mem_end = mem_info.addr + mem_info.size; const uintptr_t mem_end = mem_info.addr + mem_info.size;
R_UNLESS(mem_info.type != MemType_Reserved, svc::ResultOutOfMemory()); R_UNLESS(mem_info.state != svc::MemoryState_Inaccessible, svc::ResultOutOfMemory());
R_UNLESS(cur_base <= mem_end, svc::ResultOutOfMemory()); R_UNLESS(cur_base <= mem_end, svc::ResultOutOfMemory());
R_UNLESS(mem_end <= static_cast<uintptr_t>(std::numeric_limits<s32>::max()), svc::ResultOutOfMemory()); R_UNLESS(mem_end <= static_cast<uintptr_t>(std::numeric_limits<s32>::max()), svc::ResultOutOfMemory());
@ -51,8 +51,8 @@ namespace ams::map {
} }
Result LocateMappableSpaceModern(uintptr_t *out_address, size_t size) { Result LocateMappableSpaceModern(uintptr_t *out_address, size_t size) {
MemoryInfo mem_info = {}; svc::MemoryInfo mem_info;
u32 page_info = 0; svc::PageInfo page_info;
uintptr_t cur_base = 0, cur_end = 0; uintptr_t cur_base = 0, cur_end = 0;
AddressSpaceInfo address_space; AddressSpaceInfo address_space;
@ -72,8 +72,8 @@ namespace ams::map {
R_UNLESS(cur_base != address_space.alias_end, svc::ResultOutOfMemory()); R_UNLESS(cur_base != address_space.alias_end, svc::ResultOutOfMemory());
cur_base = address_space.alias_end; cur_base = address_space.alias_end;
} else { } else {
R_ABORT_UNLESS(svcQueryMemory(&mem_info, &page_info, cur_base)); R_ABORT_UNLESS(svc::QueryMemory(&mem_info, &page_info, cur_base));
if (mem_info.type == 0 && mem_info.addr - cur_base + mem_info.size >= size) { if (mem_info.state == svc::MemoryState_Free && mem_info.addr - cur_base + mem_info.size >= size) {
*out_address = cur_base; *out_address = cur_base;
return ResultSuccess(); return ResultSuccess();
} }
@ -87,7 +87,7 @@ namespace ams::map {
} }
} }
Result MapCodeMemoryInProcessDeprecated(MappedCodeMemory &out_mcm, Handle process_handle, uintptr_t base_address, size_t size) { Result MapCodeMemoryInProcessDeprecated(MappedCodeMemory &out_mcm, os::NativeHandle process_handle, uintptr_t base_address, size_t size) {
AddressSpaceInfo address_space; AddressSpaceInfo address_space;
R_TRY(GetProcessAddressSpaceInfo(&address_space, process_handle)); R_TRY(GetProcessAddressSpaceInfo(&address_space, process_handle));
@ -114,7 +114,7 @@ namespace ams::map {
return ro::ResultOutOfAddressSpace(); return ro::ResultOutOfAddressSpace();
} }
Result MapCodeMemoryInProcessModern(MappedCodeMemory &out_mcm, Handle process_handle, uintptr_t base_address, size_t size) { Result MapCodeMemoryInProcessModern(MappedCodeMemory &out_mcm, os::NativeHandle process_handle, uintptr_t base_address, size_t size) {
AddressSpaceInfo address_space; AddressSpaceInfo address_space;
R_TRY(GetProcessAddressSpaceInfo(&address_space, process_handle)); R_TRY(GetProcessAddressSpaceInfo(&address_space, process_handle));
@ -153,32 +153,21 @@ namespace ams::map {
} }
/* Public API. */ /* Public API. */
Result GetProcessAddressSpaceInfo(AddressSpaceInfo *out, Handle process_h) { Result GetProcessAddressSpaceInfo(AddressSpaceInfo *out, os::NativeHandle process_h) {
/* Clear output. */ /* Clear output. */
std::memset(out, 0, sizeof(*out)); std::memset(out, 0, sizeof(*out));
/* Retrieve info from kernel. */ /* Retrieve info from kernel. */
R_TRY(svcGetInfo(&out->heap_base, InfoType_HeapRegionAddress, process_h, 0)); R_TRY(svc::GetInfo(&out->heap_base, svc::InfoType_HeapRegionAddress, process_h, 0));
R_TRY(svcGetInfo(&out->heap_size, InfoType_HeapRegionSize, process_h, 0)); R_TRY(svc::GetInfo(&out->heap_size, svc::InfoType_HeapRegionSize, process_h, 0));
R_TRY(svcGetInfo(&out->alias_base, InfoType_AliasRegionAddress, process_h, 0)); R_TRY(svc::GetInfo(&out->alias_base, svc::InfoType_AliasRegionAddress, process_h, 0));
R_TRY(svcGetInfo(&out->alias_size, InfoType_AliasRegionSize, process_h, 0)); R_TRY(svc::GetInfo(&out->alias_size, svc::InfoType_AliasRegionSize, process_h, 0));
if (hos::GetVersion() >= hos::Version_2_0_0) { R_TRY(svc::GetInfo(&out->aslr_base, svc::InfoType_AslrRegionAddress, process_h, 0));
R_TRY(svcGetInfo(&out->aslr_base, InfoType_AslrRegionAddress, process_h, 0)); R_TRY(svc::GetInfo(&out->aslr_size, svc::InfoType_AslrRegionSize, process_h, 0));
R_TRY(svcGetInfo(&out->aslr_size, InfoType_AslrRegionSize, process_h, 0));
} else {
/* Auto-detect 32-bit vs 64-bit. */
if (out->heap_base < AslrBase64BitDeprecated || out->alias_base < AslrBase64BitDeprecated) {
out->aslr_base = AslrBase32Bit;
out->aslr_size = AslrSize32Bit;
} else {
out->aslr_base = AslrBase64BitDeprecated;
out->aslr_size = AslrSize64BitDeprecated;
}
}
out->heap_end = out->heap_base + out->heap_size; out->heap_end = out->heap_base + out->heap_size;
out->alias_end = out->alias_base + out->alias_size; out->alias_end = out->alias_base + out->alias_size;
out->aslr_end = out->aslr_base + out->aslr_size; out->aslr_end = out->aslr_base + out->aslr_size;
return ResultSuccess(); return ResultSuccess();
} }
@ -190,7 +179,7 @@ namespace ams::map {
} }
} }
Result MapCodeMemoryInProcess(MappedCodeMemory &out_mcm, Handle process_handle, uintptr_t base_address, size_t size) { Result MapCodeMemoryInProcess(MappedCodeMemory &out_mcm, os::NativeHandle process_handle, uintptr_t base_address, size_t size) {
if (hos::GetVersion() >= hos::Version_2_0_0) { if (hos::GetVersion() >= hos::Version_2_0_0) {
return MapCodeMemoryInProcessModern(out_mcm, process_handle, base_address, size); return MapCodeMemoryInProcessModern(out_mcm, process_handle, base_address, size);
} else { } else {
@ -198,16 +187,16 @@ namespace ams::map {
} }
} }
bool CanAddGuardRegionsInProcess(Handle process_handle, uintptr_t address, size_t size) { bool CanAddGuardRegionsInProcess(os::NativeHandle process_handle, uintptr_t address, size_t size) {
MemoryInfo mem_info; svc::MemoryInfo mem_info;
u32 page_info; svc::PageInfo page_info;
/* Nintendo doesn't validate SVC return values at all. */ /* Nintendo doesn't validate SVC return values at all. */
/* TODO: Should we allow these to fail? */ /* TODO: Should we allow these to fail? */
R_ABORT_UNLESS(svcQueryProcessMemory(&mem_info, &page_info, process_handle, address - 1)); R_ABORT_UNLESS(svc::QueryProcessMemory(&mem_info, &page_info, process_handle, address - 1));
if (mem_info.type == MemType_Unmapped && address - GuardRegionSize >= mem_info.addr) { if (mem_info.state == svc::MemoryState_Free && address - GuardRegionSize >= mem_info.addr) {
R_ABORT_UNLESS(svcQueryProcessMemory(&mem_info, &page_info, process_handle, address + size)); R_ABORT_UNLESS(svc::QueryProcessMemory(&mem_info, &page_info, process_handle, address + size));
return mem_info.type == MemType_Unmapped && address + size + GuardRegionSize <= mem_info.addr + mem_info.size; return mem_info.state == svc::MemoryState_Free && address + size + GuardRegionSize <= mem_info.addr + mem_info.size;
} }
return false; return false;

View File

@ -25,8 +25,8 @@ namespace ams::os::impl {
/* Nintendo does not check the result of these invocations, but we will for safety. */ /* Nintendo does not check the result of these invocations, but we will for safety. */
/* Nintendo uses entropy values 0, 1 to seed the public TinyMT random, and values */ /* Nintendo uses entropy values 0, 1 to seed the public TinyMT random, and values */
/* 2, 3 to seed os::detail::RngManager's private TinyMT random. */ /* 2, 3 to seed os::detail::RngManager's private TinyMT random. */
R_ABORT_UNLESS(svcGetInfo(reinterpret_cast<u64 *>(&seed[0]), InfoType_RandomEntropy, INVALID_HANDLE, 0)); R_ABORT_UNLESS(svc::GetInfo(reinterpret_cast<u64 *>(seed + 0), svc::InfoType_RandomEntropy, svc::InvalidHandle, 0));
R_ABORT_UNLESS(svcGetInfo(reinterpret_cast<u64 *>(&seed[2]), InfoType_RandomEntropy, INVALID_HANDLE, 1)); R_ABORT_UNLESS(svc::GetInfo(reinterpret_cast<u64 *>(seed + 2), svc::InfoType_RandomEntropy, svc::InvalidHandle, 1));
mt->Initialize(seed, util::size(seed)); mt->Initialize(seed, util::size(seed));
} }

View File

@ -26,8 +26,8 @@ namespace ams::os::impl {
/* Nintendo does not check the result of these invocations, but we will for safety. */ /* Nintendo does not check the result of these invocations, but we will for safety. */
/* Nintendo uses entropy values 0, 1 to seed the public TinyMT random, and values */ /* Nintendo uses entropy values 0, 1 to seed the public TinyMT random, and values */
/* 2, 3 to seed os::detail::RngManager's private TinyMT random. */ /* 2, 3 to seed os::detail::RngManager's private TinyMT random. */
R_ABORT_UNLESS(svcGetInfo(reinterpret_cast<u64 *>(&seed[0]), InfoType_RandomEntropy, INVALID_HANDLE, 2)); R_ABORT_UNLESS(svc::GetInfo(reinterpret_cast<u64 *>(seed + 0), svc::InfoType_RandomEntropy, svc::InvalidHandle, 2));
R_ABORT_UNLESS(svcGetInfo(reinterpret_cast<u64 *>(&seed[2]), InfoType_RandomEntropy, INVALID_HANDLE, 3)); R_ABORT_UNLESS(svc::GetInfo(reinterpret_cast<u64 *>(seed + 2), svc::InfoType_RandomEntropy, svc::InvalidHandle, 3));
this->mt.Initialize(seed, util::size(seed)); this->mt.Initialize(seed, util::size(seed));

View File

@ -19,10 +19,10 @@ namespace ams::os {
namespace { namespace {
/* TODO: Remove, add VammManager */ /* TODO: Remove, add VammManager/horizon-impl */
size_t GetSystemResourceSize() { size_t GetSystemResourceSize() {
u64 v; u64 v;
if (R_SUCCEEDED(svcGetInfo(std::addressof(v), InfoType_SystemResourceSizeTotal, CUR_PROCESS_HANDLE, 0))) { if (R_SUCCEEDED(svc::GetInfo(std::addressof(v), svc::InfoType_SystemResourceSizeTotal, os::GetCurrentProcessHandle(), 0))) {
return v; return v;
} else { } else {
return 0; return 0;

View File

@ -32,15 +32,15 @@ namespace ams::pm::dmnt {
return pmdmntGetApplicationProcessId(reinterpret_cast<u64 *>(out_process_id)); return pmdmntGetApplicationProcessId(reinterpret_cast<u64 *>(out_process_id));
} }
Result HookToCreateApplicationProcess(Handle *out_handle) { Result HookToCreateApplicationProcess(os::NativeHandle *out_handle) {
Event evt; Event evt;
R_TRY(pmdmntHookToCreateApplicationProcess(&evt)); R_TRY(pmdmntHookToCreateApplicationProcess(&evt));
*out_handle = evt.revent; *out_handle = evt.revent;
return ResultSuccess(); return ResultSuccess();
} }
Result AtmosphereGetProcessInfo(Handle *out_handle, ncm::ProgramLocation *out_loc, cfg::OverrideStatus *out_status, os::ProcessId process_id) { Result AtmosphereGetProcessInfo(os::NativeHandle *out_handle, ncm::ProgramLocation *out_loc, cfg::OverrideStatus *out_status, os::ProcessId process_id) {
*out_handle = INVALID_HANDLE; *out_handle = os::InvalidNativeHandle;
*out_loc = {}; *out_loc = {};
*out_status = {}; *out_status = {};
static_assert(sizeof(*out_status) == sizeof(CfgOverrideStatus)); static_assert(sizeof(*out_status) == sizeof(CfgOverrideStatus));

View File

@ -19,37 +19,37 @@ namespace ams::sf::hipc {
namespace { namespace {
ALWAYS_INLINE Result ReceiveImpl(Handle session_handle, void *message_buf, size_t message_buf_size) { ALWAYS_INLINE Result ReceiveImpl(os::NativeHandle session_handle, void *message_buf, size_t message_buf_size) {
s32 unused_index; s32 unused_index;
if (message_buf == armGetTls()) { if (message_buf == svc::GetThreadLocalRegion()->message_buffer) {
/* Consider: AMS_ABORT_UNLESS(message_buf_size == TlsMessageBufferSize); */ /* Consider: AMS_ABORT_UNLESS(message_buf_size == TlsMessageBufferSize); */
return svcReplyAndReceive(&unused_index, &session_handle, 1, INVALID_HANDLE, std::numeric_limits<u64>::max()); return svc::ReplyAndReceive(&unused_index, &session_handle, 1, svc::InvalidHandle, std::numeric_limits<u64>::max());
} else { } else {
return svcReplyAndReceiveWithUserBuffer(&unused_index, message_buf, message_buf_size, &session_handle, 1, INVALID_HANDLE, std::numeric_limits<u64>::max()); return svc::ReplyAndReceiveWithUserBuffer(&unused_index, reinterpret_cast<uintptr_t>(message_buf), message_buf_size, &session_handle, 1, svc::InvalidHandle, std::numeric_limits<u64>::max());
} }
} }
ALWAYS_INLINE Result ReplyImpl(Handle session_handle, void *message_buf, size_t message_buf_size) { ALWAYS_INLINE Result ReplyImpl(os::NativeHandle session_handle, void *message_buf, size_t message_buf_size) {
s32 unused_index; s32 unused_index;
if (message_buf == armGetTls()) { if (message_buf == svc::GetThreadLocalRegion()->message_buffer) {
/* Consider: AMS_ABORT_UNLESS(message_buf_size == TlsMessageBufferSize); */ /* Consider: AMS_ABORT_UNLESS(message_buf_size == TlsMessageBufferSize); */
return svcReplyAndReceive(&unused_index, &session_handle, 0, session_handle, 0); return svc::ReplyAndReceive(&unused_index, &session_handle, 0, session_handle, 0);
} else { } else {
return svcReplyAndReceiveWithUserBuffer(&unused_index, message_buf, message_buf_size, &session_handle, 0, session_handle, 0); return svc::ReplyAndReceiveWithUserBuffer(&unused_index, reinterpret_cast<uintptr_t>(message_buf), message_buf_size, &session_handle, 0, session_handle, 0);
} }
} }
} }
void AttachMultiWaitHolderForAccept(os::MultiWaitHolderType *holder, Handle port) { void AttachMultiWaitHolderForAccept(os::MultiWaitHolderType *holder, os::NativeHandle port) {
return os::InitializeMultiWaitHolder(holder, port); return os::InitializeMultiWaitHolder(holder, port);
} }
void AttachMultiWaitHolderForReply(os::MultiWaitHolderType *holder, Handle request) { void AttachMultiWaitHolderForReply(os::MultiWaitHolderType *holder, os::NativeHandle request) {
return os::InitializeMultiWaitHolder(holder, request); return os::InitializeMultiWaitHolder(holder, request);
} }
Result Receive(ReceiveResult *out_recv_result, Handle session_handle, const cmif::PointerAndSize &message_buffer) { Result Receive(ReceiveResult *out_recv_result, os::NativeHandle session_handle, const cmif::PointerAndSize &message_buffer) {
R_TRY_CATCH(ReceiveImpl(session_handle, message_buffer.GetPointer(), message_buffer.GetSize())) { R_TRY_CATCH(ReceiveImpl(session_handle, message_buffer.GetPointer(), message_buffer.GetSize())) {
R_CATCH(svc::ResultSessionClosed) { R_CATCH(svc::ResultSessionClosed) {
*out_recv_result = ReceiveResult::Closed; *out_recv_result = ReceiveResult::Closed;
@ -64,7 +64,7 @@ namespace ams::sf::hipc {
return ResultSuccess(); return ResultSuccess();
} }
Result Receive(bool *out_closed, Handle session_handle, const cmif::PointerAndSize &message_buffer) { Result Receive(bool *out_closed, os::NativeHandle session_handle, const cmif::PointerAndSize &message_buffer) {
R_TRY_CATCH(ReceiveImpl(session_handle, message_buffer.GetPointer(), message_buffer.GetSize())) { R_TRY_CATCH(ReceiveImpl(session_handle, message_buffer.GetPointer(), message_buffer.GetSize())) {
R_CATCH(svc::ResultSessionClosed) { R_CATCH(svc::ResultSessionClosed) {
*out_closed = true; *out_closed = true;
@ -75,7 +75,7 @@ namespace ams::sf::hipc {
return ResultSuccess(); return ResultSuccess();
} }
Result Reply(Handle session_handle, const cmif::PointerAndSize &message_buffer) { Result Reply(os::NativeHandle session_handle, const cmif::PointerAndSize &message_buffer) {
R_TRY_CATCH(ReplyImpl(session_handle, message_buffer.GetPointer(), message_buffer.GetSize())) { R_TRY_CATCH(ReplyImpl(session_handle, message_buffer.GetPointer(), message_buffer.GetSize())) {
R_CONVERT(svc::ResultTimedOut, ResultSuccess()) R_CONVERT(svc::ResultTimedOut, ResultSuccess())
R_CONVERT(svc::ResultSessionClosed, ResultSuccess()) R_CONVERT(svc::ResultSessionClosed, ResultSuccess())
@ -84,8 +84,8 @@ namespace ams::sf::hipc {
AMS_ABORT_UNLESS(false); AMS_ABORT_UNLESS(false);
} }
Result CreateSession(Handle *out_server_handle, Handle *out_client_handle) { Result CreateSession(os::NativeHandle *out_server_handle, os::NativeHandle *out_client_handle) {
R_TRY_CATCH(svcCreateSession(out_server_handle, out_client_handle, 0, 0)) { R_TRY_CATCH(svc::CreateSession(out_server_handle, out_client_handle, 0, 0)) {
R_CONVERT(svc::ResultOutOfResource, sf::hipc::ResultOutOfSessions()); R_CONVERT(svc::ResultOutOfResource, sf::hipc::ResultOutOfSessions());
} R_END_TRY_CATCH; } R_END_TRY_CATCH;
return ResultSuccess(); return ResultSuccess();

View File

@ -113,7 +113,7 @@ namespace ams::sf::hipc {
ServerSession *session = static_cast<ServerSession *>(holder); ServerSession *session = static_cast<ServerSession *>(holder);
cmif::PointerAndSize tls_message(armGetTls(), hipc::TlsMessageBufferSize); cmif::PointerAndSize tls_message(svc::GetThreadLocalRegion()->message_buffer, hipc::TlsMessageBufferSize);
const cmif::PointerAndSize &saved_message = session->saved_message; const cmif::PointerAndSize &saved_message = session->saved_message;
AMS_ABORT_UNLESS(tls_message.GetSize() == saved_message.GetSize()); AMS_ABORT_UNLESS(tls_message.GetSize() == saved_message.GetSize());
if (!session->has_received) { if (!session->has_received) {

View File

@ -45,18 +45,21 @@ namespace ams::sf::hipc {
AMS_ABORT_UNLESS(this->saved_message.GetPointer() != nullptr); AMS_ABORT_UNLESS(this->saved_message.GetPointer() != nullptr);
AMS_ABORT_UNLESS(this->saved_message.GetSize() == TlsMessageBufferSize); AMS_ABORT_UNLESS(this->saved_message.GetSize() == TlsMessageBufferSize);
/* Get TLS message buffer. */
u32 * const message_buffer = svc::GetThreadLocalRegion()->message_buffer;
/* Copy saved TLS in. */ /* Copy saved TLS in. */
std::memcpy(armGetTls(), this->saved_message.GetPointer(), this->saved_message.GetSize()); std::memcpy(message_buffer, this->saved_message.GetPointer(), this->saved_message.GetSize());
/* Prepare buffer. */ /* Prepare buffer. */
PreProcessCommandBufferForMitm(ctx, this->pointer_buffer, reinterpret_cast<uintptr_t>(armGetTls())); PreProcessCommandBufferForMitm(ctx, this->pointer_buffer, reinterpret_cast<uintptr_t>(message_buffer));
/* Dispatch forwards. */ /* Dispatch forwards. */
R_TRY(svcSendSyncRequest(this->forward_service->session)); R_TRY(svc::SendSyncRequest(this->forward_service->session));
/* Parse, to ensure we catch any copy handles and close them. */ /* Parse, to ensure we catch any copy handles and close them. */
{ {
const auto response = hipcParseResponse(armGetTls()); const auto response = hipcParseResponse(message_buffer);
if (response.num_copy_handles) { if (response.num_copy_handles) {
ctx.handles_to_close->num_handles = response.num_copy_handles; ctx.handles_to_close->num_handles = response.num_copy_handles;
for (size_t i = 0; i < response.num_copy_handles; i++) { for (size_t i = 0; i < response.num_copy_handles; i++) {
@ -77,13 +80,13 @@ namespace ams::sf::hipc {
} }
void ServerSessionManager::CloseSessionImpl(ServerSession *session) { void ServerSessionManager::CloseSessionImpl(ServerSession *session) {
const Handle session_handle = session->session_handle; const auto session_handle = session->session_handle;
os::FinalizeMultiWaitHolder(session); os::FinalizeMultiWaitHolder(session);
this->DestroySession(session); this->DestroySession(session);
R_ABORT_UNLESS(svcCloseHandle(session_handle)); os::CloseNativeHandle(session_handle);
} }
Result ServerSessionManager::RegisterSessionImpl(ServerSession *session_memory, Handle session_handle, cmif::ServiceObjectHolder &&obj) { Result ServerSessionManager::RegisterSessionImpl(ServerSession *session_memory, os::NativeHandle session_handle, cmif::ServiceObjectHolder &&obj) {
/* Create session object. */ /* Create session object. */
std::construct_at(session_memory, session_handle, std::forward<cmif::ServiceObjectHolder>(obj)); std::construct_at(session_memory, session_handle, std::forward<cmif::ServiceObjectHolder>(obj));
@ -96,12 +99,12 @@ namespace ams::sf::hipc {
return ResultSuccess(); return ResultSuccess();
} }
Result ServerSessionManager::AcceptSessionImpl(ServerSession *session_memory, Handle port_handle, cmif::ServiceObjectHolder &&obj) { Result ServerSessionManager::AcceptSessionImpl(ServerSession *session_memory, os::NativeHandle port_handle, cmif::ServiceObjectHolder &&obj) {
/* Create session handle. */ /* Create session handle. */
Handle session_handle; os::NativeHandle session_handle;
R_TRY(svcAcceptSession(&session_handle, port_handle)); R_TRY(svc::AcceptSession(&session_handle, port_handle));
auto session_guard = SCOPE_GUARD { R_ABORT_UNLESS(svc::CloseHandle(session_handle)); }; auto session_guard = SCOPE_GUARD { os::CloseNativeHandle(session_handle); };
/* Register session. */ /* Register session. */
R_TRY(this->RegisterSessionImpl(session_memory, session_handle, std::forward<cmif::ServiceObjectHolder>(obj))); R_TRY(this->RegisterSessionImpl(session_memory, session_handle, std::forward<cmif::ServiceObjectHolder>(obj)));
@ -110,7 +113,7 @@ namespace ams::sf::hipc {
return ResultSuccess(); return ResultSuccess();
} }
Result ServerSessionManager::RegisterMitmSessionImpl(ServerSession *session_memory, Handle mitm_session_handle, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv) { Result ServerSessionManager::RegisterMitmSessionImpl(ServerSession *session_memory, os::NativeHandle mitm_session_handle, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv) {
/* Create session object. */ /* Create session object. */
std::construct_at(session_memory, mitm_session_handle, std::forward<cmif::ServiceObjectHolder>(obj), std::forward<std::shared_ptr<::Service>>(fsrv)); std::construct_at(session_memory, mitm_session_handle, std::forward<cmif::ServiceObjectHolder>(obj), std::forward<std::shared_ptr<::Service>>(fsrv));
@ -127,12 +130,12 @@ namespace ams::sf::hipc {
return ResultSuccess(); return ResultSuccess();
} }
Result ServerSessionManager::AcceptMitmSessionImpl(ServerSession *session_memory, Handle mitm_port_handle, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv) { Result ServerSessionManager::AcceptMitmSessionImpl(ServerSession *session_memory, os::NativeHandle mitm_port_handle, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv) {
/* Create session handle. */ /* Create session handle. */
Handle mitm_session_handle; os::NativeHandle mitm_session_handle;
R_TRY(svcAcceptSession(&mitm_session_handle, mitm_port_handle)); R_TRY(svc::AcceptSession(&mitm_session_handle, mitm_port_handle));
auto session_guard = SCOPE_GUARD { R_ABORT_UNLESS(svc::CloseHandle(mitm_session_handle)); }; auto session_guard = SCOPE_GUARD { os::CloseNativeHandle(mitm_session_handle); };
/* Register session. */ /* Register session. */
R_TRY(this->RegisterMitmSessionImpl(session_memory, mitm_session_handle, std::forward<cmif::ServiceObjectHolder>(obj), std::forward<std::shared_ptr<::Service>>(fsrv))); R_TRY(this->RegisterMitmSessionImpl(session_memory, mitm_session_handle, std::forward<cmif::ServiceObjectHolder>(obj), std::forward<std::shared_ptr<::Service>>(fsrv)));
@ -141,25 +144,25 @@ namespace ams::sf::hipc {
return ResultSuccess(); return ResultSuccess();
} }
Result ServerSessionManager::RegisterSession(Handle session_handle, cmif::ServiceObjectHolder &&obj) { Result ServerSessionManager::RegisterSession(os::NativeHandle session_handle, cmif::ServiceObjectHolder &&obj) {
/* We don't actually care about what happens to the session. It'll get linked. */ /* We don't actually care about what happens to the session. It'll get linked. */
ServerSession *session_ptr = nullptr; ServerSession *session_ptr = nullptr;
return this->RegisterSession(&session_ptr, session_handle, std::forward<cmif::ServiceObjectHolder>(obj)); return this->RegisterSession(&session_ptr, session_handle, std::forward<cmif::ServiceObjectHolder>(obj));
} }
Result ServerSessionManager::AcceptSession(Handle port_handle, cmif::ServiceObjectHolder &&obj) { Result ServerSessionManager::AcceptSession(os::NativeHandle port_handle, cmif::ServiceObjectHolder &&obj) {
/* We don't actually care about what happens to the session. It'll get linked. */ /* We don't actually care about what happens to the session. It'll get linked. */
ServerSession *session_ptr = nullptr; ServerSession *session_ptr = nullptr;
return this->AcceptSession(&session_ptr, port_handle, std::forward<cmif::ServiceObjectHolder>(obj)); return this->AcceptSession(&session_ptr, port_handle, std::forward<cmif::ServiceObjectHolder>(obj));
} }
Result ServerSessionManager::RegisterMitmSession(Handle mitm_session_handle, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv) { Result ServerSessionManager::RegisterMitmSession(os::NativeHandle mitm_session_handle, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv) {
/* We don't actually care about what happens to the session. It'll get linked. */ /* We don't actually care about what happens to the session. It'll get linked. */
ServerSession *session_ptr = nullptr; ServerSession *session_ptr = nullptr;
return this->RegisterMitmSession(&session_ptr, mitm_session_handle, std::forward<cmif::ServiceObjectHolder>(obj), std::forward<std::shared_ptr<::Service>>(fsrv)); return this->RegisterMitmSession(&session_ptr, mitm_session_handle, std::forward<cmif::ServiceObjectHolder>(obj), std::forward<std::shared_ptr<::Service>>(fsrv));
} }
Result ServerSessionManager::AcceptMitmSession(Handle mitm_port_handle, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv) { Result ServerSessionManager::AcceptMitmSession(os::NativeHandle mitm_port_handle, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv) {
/* We don't actually care about what happens to the session. It'll get linked. */ /* We don't actually care about what happens to the session. It'll get linked. */
ServerSession *session_ptr = nullptr; ServerSession *session_ptr = nullptr;
return this->AcceptMitmSession(&session_ptr, mitm_port_handle, std::forward<cmif::ServiceObjectHolder>(obj), std::forward<std::shared_ptr<::Service>>(fsrv)); return this->AcceptMitmSession(&session_ptr, mitm_port_handle, std::forward<cmif::ServiceObjectHolder>(obj), std::forward<std::shared_ptr<::Service>>(fsrv));
@ -313,7 +316,7 @@ namespace ams::sf::hipc {
{ {
ON_SCOPE_EXIT { ON_SCOPE_EXIT {
for (size_t i = 0; i < handles_to_close.num_handles; i++) { for (size_t i = 0; i < handles_to_close.num_handles; i++) {
R_ABORT_UNLESS(svcCloseHandle(handles_to_close.handles[i])); os::CloseNativeHandle(handles_to_close.handles[i]);
} }
}; };
R_TRY(hipc::Reply(session->session_handle, out_message)); R_TRY(hipc::Reply(session->session_handle, out_message));

View File

@ -18,292 +18,292 @@
namespace ams::spl::smc { namespace ams::spl::smc {
Result SetConfig(spl::ConfigItem which, const void *address, const u64 *value, size_t num_qwords) { Result SetConfig(spl::ConfigItem which, const void *address, const u64 *value, size_t num_qwords) {
SecmonArgs args; svc::SecureMonitorArguments args;
args.X[0] = static_cast<u64>(FunctionId::SetConfig); args.r[0] = static_cast<u64>(FunctionId::SetConfig);
args.X[1] = static_cast<u64>(which); args.r[1] = static_cast<u64>(which);
args.X[2] = reinterpret_cast<u64>(address); args.r[2] = reinterpret_cast<u64>(address);
for (size_t i = 0; i < std::min(size_t(4), num_qwords); i++) { for (size_t i = 0; i < std::min(size_t(4), num_qwords); i++) {
args.X[3 + i] = value[i]; args.r[3 + i] = value[i];
} }
svcCallSecureMonitor(&args); svc::CallSecureMonitor(std::addressof(args));
return static_cast<Result>(args.X[0]); return static_cast<Result>(args.r[0]);
} }
Result GetConfig(u64 *out, size_t num_qwords, spl::ConfigItem which) { Result GetConfig(u64 *out, size_t num_qwords, spl::ConfigItem which) {
SecmonArgs args; svc::SecureMonitorArguments args;
args.X[0] = static_cast<u64>(FunctionId::GetConfig); args.r[0] = static_cast<u64>(FunctionId::GetConfig);
args.X[1] = static_cast<u64>(which); args.r[1] = static_cast<u64>(which);
svcCallSecureMonitor(&args); svc::CallSecureMonitor(std::addressof(args));
for (size_t i = 0; i < std::min(size_t(4), num_qwords); i++) { for (size_t i = 0; i < std::min(size_t(4), num_qwords); i++) {
out[i] = args.X[1 + i]; out[i] = args.r[1 + i];
} }
return static_cast<Result>(args.X[0]); return static_cast<Result>(args.r[0]);
} }
Result GetResult(Result *out, AsyncOperationKey op) { Result GetResult(Result *out, AsyncOperationKey op) {
SecmonArgs args; svc::SecureMonitorArguments args;
args.X[0] = static_cast<u64>(FunctionId::GetResult); args.r[0] = static_cast<u64>(FunctionId::GetResult);
args.X[1] = op.value; args.r[1] = op.value;
svcCallSecureMonitor(&args); svc::CallSecureMonitor(std::addressof(args));
*out = static_cast<Result>(args.X[1]); *out = static_cast<Result>(args.r[1]);
return static_cast<Result>(args.X[0]); return static_cast<Result>(args.r[0]);
} }
Result GetResultData(Result *out, void *out_buf, size_t out_buf_size, AsyncOperationKey op) { Result GetResultData(Result *out, void *out_buf, size_t out_buf_size, AsyncOperationKey op) {
SecmonArgs args; svc::SecureMonitorArguments args;
args.X[0] = static_cast<u64>(FunctionId::GetResultData); args.r[0] = static_cast<u64>(FunctionId::GetResultData);
args.X[1] = op.value; args.r[1] = op.value;
args.X[2] = reinterpret_cast<u64>(out_buf); args.r[2] = reinterpret_cast<u64>(out_buf);
args.X[3] = out_buf_size; args.r[3] = out_buf_size;
svcCallSecureMonitor(&args); svc::CallSecureMonitor(std::addressof(args));
*out = static_cast<Result>(args.X[1]); *out = static_cast<Result>(args.r[1]);
return static_cast<Result>(args.X[0]); return static_cast<Result>(args.r[0]);
} }
Result ModularExponentiate(AsyncOperationKey *out_op, const void *base, const void *exp, size_t exp_size, const void *mod) { Result ModularExponentiate(AsyncOperationKey *out_op, const void *base, const void *exp, size_t exp_size, const void *mod) {
SecmonArgs args; svc::SecureMonitorArguments args;
args.X[0] = static_cast<u64>(FunctionId::ModularExponentiate); args.r[0] = static_cast<u64>(FunctionId::ModularExponentiate);
args.X[1] = reinterpret_cast<u64>(base); args.r[1] = reinterpret_cast<u64>(base);
args.X[2] = reinterpret_cast<u64>(exp); args.r[2] = reinterpret_cast<u64>(exp);
args.X[3] = reinterpret_cast<u64>(mod); args.r[3] = reinterpret_cast<u64>(mod);
args.X[4] = exp_size; args.r[4] = exp_size;
svcCallSecureMonitor(&args); svc::CallSecureMonitor(std::addressof(args));
out_op->value = args.X[1]; out_op->value = args.r[1];
return static_cast<Result>(args.X[0]); return static_cast<Result>(args.r[0]);
} }
Result GenerateRandomBytes(void *out, size_t size) { Result GenerateRandomBytes(void *out, size_t size) {
SecmonArgs args; svc::SecureMonitorArguments args;
args.X[0] = static_cast<u64>(FunctionId::GenerateRandomBytes); args.r[0] = static_cast<u64>(FunctionId::GenerateRandomBytes);
args.X[1] = size; args.r[1] = size;
svcCallSecureMonitor(&args); svc::CallSecureMonitor(std::addressof(args));
if (args.X[0] == static_cast<u64>(Result::Success) && (size <= sizeof(args) - sizeof(args.X[0]))) { if (args.r[0] == static_cast<u64>(Result::Success) && (size <= sizeof(args) - sizeof(args.r[0]))) {
std::memcpy(out, &args.X[1], size); std::memcpy(out, &args.r[1], size);
} }
return static_cast<Result>(args.X[0]); return static_cast<Result>(args.r[0]);
} }
Result GenerateAesKek(AccessKey *out, const KeySource &source, u32 generation, u32 option) { Result GenerateAesKek(AccessKey *out, const KeySource &source, u32 generation, u32 option) {
SecmonArgs args; svc::SecureMonitorArguments args;
args.X[0] = static_cast<u64>(FunctionId::GenerateAesKek); args.r[0] = static_cast<u64>(FunctionId::GenerateAesKek);
args.X[1] = source.data64[0]; args.r[1] = source.data64[0];
args.X[2] = source.data64[1]; args.r[2] = source.data64[1];
args.X[3] = generation; args.r[3] = generation;
args.X[4] = option; args.r[4] = option;
svcCallSecureMonitor(&args); svc::CallSecureMonitor(std::addressof(args));
out->data64[0] = args.X[1]; out->data64[0] = args.r[1];
out->data64[1] = args.X[2]; out->data64[1] = args.r[2];
return static_cast<Result>(args.X[0]); return static_cast<Result>(args.r[0]);
} }
Result LoadAesKey(u32 keyslot, const AccessKey &access_key, const KeySource &source) { Result LoadAesKey(u32 keyslot, const AccessKey &access_key, const KeySource &source) {
SecmonArgs args; svc::SecureMonitorArguments args;
args.X[0] = static_cast<u64>(FunctionId::LoadAesKey); args.r[0] = static_cast<u64>(FunctionId::LoadAesKey);
args.X[1] = keyslot; args.r[1] = keyslot;
args.X[2] = access_key.data64[0]; args.r[2] = access_key.data64[0];
args.X[3] = access_key.data64[1]; args.r[3] = access_key.data64[1];
args.X[4] = source.data64[0]; args.r[4] = source.data64[0];
args.X[5] = source.data64[1]; args.r[5] = source.data64[1];
svcCallSecureMonitor(&args); svc::CallSecureMonitor(std::addressof(args));
return static_cast<Result>(args.X[0]); return static_cast<Result>(args.r[0]);
} }
Result ComputeAes(AsyncOperationKey *out_op, u32 mode, const IvCtr &iv_ctr, u32 dst_addr, u32 src_addr, size_t size) { Result ComputeAes(AsyncOperationKey *out_op, u32 mode, const IvCtr &iv_ctr, u32 dst_addr, u32 src_addr, size_t size) {
SecmonArgs args; svc::SecureMonitorArguments args;
args.X[0] = static_cast<u64>(FunctionId::ComputeAes); args.r[0] = static_cast<u64>(FunctionId::ComputeAes);
args.X[1] = mode; args.r[1] = mode;
args.X[2] = iv_ctr.data64[0]; args.r[2] = iv_ctr.data64[0];
args.X[3] = iv_ctr.data64[1]; args.r[3] = iv_ctr.data64[1];
args.X[4] = src_addr; args.r[4] = src_addr;
args.X[5] = dst_addr; args.r[5] = dst_addr;
args.X[6] = size; args.r[6] = size;
svcCallSecureMonitor(&args); svc::CallSecureMonitor(std::addressof(args));
out_op->value = args.X[1]; out_op->value = args.r[1];
return static_cast<Result>(args.X[0]); return static_cast<Result>(args.r[0]);
} }
Result GenerateSpecificAesKey(AesKey *out_key, const KeySource &source, u32 generation, u32 which) { Result GenerateSpecificAesKey(AesKey *out_key, const KeySource &source, u32 generation, u32 which) {
SecmonArgs args; svc::SecureMonitorArguments args;
args.X[0] = static_cast<u64>(FunctionId::GenerateSpecificAesKey); args.r[0] = static_cast<u64>(FunctionId::GenerateSpecificAesKey);
args.X[1] = source.data64[0]; args.r[1] = source.data64[0];
args.X[2] = source.data64[1]; args.r[2] = source.data64[1];
args.X[3] = generation; args.r[3] = generation;
args.X[4] = which; args.r[4] = which;
svcCallSecureMonitor(&args); svc::CallSecureMonitor(std::addressof(args));
out_key->data64[0] = args.X[1]; out_key->data64[0] = args.r[1];
out_key->data64[1] = args.X[2]; out_key->data64[1] = args.r[2];
return static_cast<Result>(args.X[0]); return static_cast<Result>(args.r[0]);
} }
Result ComputeCmac(Cmac *out_mac, u32 keyslot, const void *data, size_t size) { Result ComputeCmac(Cmac *out_mac, u32 keyslot, const void *data, size_t size) {
SecmonArgs args; svc::SecureMonitorArguments args;
args.X[0] = static_cast<u64>(FunctionId::ComputeCmac); args.r[0] = static_cast<u64>(FunctionId::ComputeCmac);
args.X[1] = keyslot; args.r[1] = keyslot;
args.X[2] = reinterpret_cast<u64>(data); args.r[2] = reinterpret_cast<u64>(data);
args.X[3] = size; args.r[3] = size;
svcCallSecureMonitor(&args); svc::CallSecureMonitor(std::addressof(args));
out_mac->data64[0] = args.X[1]; out_mac->data64[0] = args.r[1];
out_mac->data64[1] = args.X[2]; out_mac->data64[1] = args.r[2];
return static_cast<Result>(args.X[0]); return static_cast<Result>(args.r[0]);
} }
Result ReencryptDeviceUniqueData(void *data, size_t size, const AccessKey &access_key_dec, const KeySource &source_dec, const AccessKey &access_key_enc, const KeySource &source_enc, u32 option) { Result ReencryptDeviceUniqueData(void *data, size_t size, const AccessKey &access_key_dec, const KeySource &source_dec, const AccessKey &access_key_enc, const KeySource &source_enc, u32 option) {
SecmonArgs args; svc::SecureMonitorArguments args;
args.X[0] = static_cast<u64>(FunctionId::ReencryptDeviceUniqueData); args.r[0] = static_cast<u64>(FunctionId::ReencryptDeviceUniqueData);
args.X[1] = reinterpret_cast<u64>(&access_key_dec); args.r[1] = reinterpret_cast<u64>(&access_key_dec);
args.X[2] = reinterpret_cast<u64>(&access_key_enc); args.r[2] = reinterpret_cast<u64>(&access_key_enc);
args.X[3] = option; args.r[3] = option;
args.X[4] = reinterpret_cast<u64>(data); args.r[4] = reinterpret_cast<u64>(data);
args.X[5] = size; args.r[5] = size;
args.X[6] = reinterpret_cast<u64>(&source_dec); args.r[6] = reinterpret_cast<u64>(&source_dec);
args.X[7] = reinterpret_cast<u64>(&source_enc); args.r[7] = reinterpret_cast<u64>(&source_enc);
svcCallSecureMonitor(&args); svc::CallSecureMonitor(std::addressof(args));
return static_cast<Result>(args.X[0]); return static_cast<Result>(args.r[0]);
} }
Result DecryptDeviceUniqueData(void *data, size_t size, const AccessKey &access_key, const KeySource &source, DeviceUniqueDataMode mode) { Result DecryptDeviceUniqueData(void *data, size_t size, const AccessKey &access_key, const KeySource &source, DeviceUniqueDataMode mode) {
SecmonArgs args; svc::SecureMonitorArguments args;
args.X[0] = static_cast<u64>(FunctionId::DecryptDeviceUniqueData); args.r[0] = static_cast<u64>(FunctionId::DecryptDeviceUniqueData);
args.X[1] = access_key.data64[0]; args.r[1] = access_key.data64[0];
args.X[2] = access_key.data64[1]; args.r[2] = access_key.data64[1];
args.X[3] = static_cast<u32>(mode); args.r[3] = static_cast<u32>(mode);
args.X[4] = reinterpret_cast<u64>(data); args.r[4] = reinterpret_cast<u64>(data);
args.X[5] = size; args.r[5] = size;
args.X[6] = source.data64[0]; args.r[6] = source.data64[0];
args.X[7] = source.data64[1]; args.r[7] = source.data64[1];
svcCallSecureMonitor(&args); svc::CallSecureMonitor(std::addressof(args));
return static_cast<Result>(args.X[0]); return static_cast<Result>(args.r[0]);
} }
Result ModularExponentiateWithStorageKey(AsyncOperationKey *out_op, const void *base, const void *mod, ModularExponentiateWithStorageKeyMode mode) { Result ModularExponentiateWithStorageKey(AsyncOperationKey *out_op, const void *base, const void *mod, ModularExponentiateWithStorageKeyMode mode) {
SecmonArgs args; svc::SecureMonitorArguments args;
args.X[0] = static_cast<u64>(FunctionId::ModularExponentiateWithStorageKey); args.r[0] = static_cast<u64>(FunctionId::ModularExponentiateWithStorageKey);
args.X[1] = reinterpret_cast<u64>(base); args.r[1] = reinterpret_cast<u64>(base);
args.X[2] = reinterpret_cast<u64>(mod); args.r[2] = reinterpret_cast<u64>(mod);
args.X[3] = static_cast<u32>(mode); args.r[3] = static_cast<u32>(mode);
svcCallSecureMonitor(&args); svc::CallSecureMonitor(std::addressof(args));
out_op->value = args.X[1]; out_op->value = args.r[1];
return static_cast<Result>(args.X[0]); return static_cast<Result>(args.r[0]);
} }
Result PrepareEsDeviceUniqueKey(AsyncOperationKey *out_op, const void *base, const void *mod, const void *label_digest, size_t label_digest_size, u32 option) { Result PrepareEsDeviceUniqueKey(AsyncOperationKey *out_op, const void *base, const void *mod, const void *label_digest, size_t label_digest_size, u32 option) {
SecmonArgs args; svc::SecureMonitorArguments args;
args.X[0] = static_cast<u64>(FunctionId::PrepareEsDeviceUniqueKey); args.r[0] = static_cast<u64>(FunctionId::PrepareEsDeviceUniqueKey);
args.X[1] = reinterpret_cast<u64>(base); args.r[1] = reinterpret_cast<u64>(base);
args.X[2] = reinterpret_cast<u64>(mod); args.r[2] = reinterpret_cast<u64>(mod);
std::memset(&args.X[3], 0, 4 * sizeof(args.X[3])); std::memset(&args.r[3], 0, 4 * sizeof(args.r[3]));
std::memcpy(&args.X[3], label_digest, std::min(size_t(4 * sizeof(args.X[3])), label_digest_size)); std::memcpy(&args.r[3], label_digest, std::min(size_t(4 * sizeof(args.r[3])), label_digest_size));
args.X[7] = option; args.r[7] = option;
svcCallSecureMonitor(&args); svc::CallSecureMonitor(std::addressof(args));
out_op->value = args.X[1]; out_op->value = args.r[1];
return static_cast<Result>(args.X[0]); return static_cast<Result>(args.r[0]);
} }
Result LoadPreparedAesKey(u32 keyslot, const AccessKey &access_key) { Result LoadPreparedAesKey(u32 keyslot, const AccessKey &access_key) {
SecmonArgs args; svc::SecureMonitorArguments args;
args.X[0] = static_cast<u64>(FunctionId::LoadPreparedAesKey); args.r[0] = static_cast<u64>(FunctionId::LoadPreparedAesKey);
args.X[1] = keyslot; args.r[1] = keyslot;
args.X[2] = access_key.data64[0]; args.r[2] = access_key.data64[0];
args.X[3] = access_key.data64[1]; args.r[3] = access_key.data64[1];
svcCallSecureMonitor(&args); svc::CallSecureMonitor(std::addressof(args));
return static_cast<Result>(args.X[0]); return static_cast<Result>(args.r[0]);
} }
Result PrepareCommonEsTitleKey(AccessKey *out, const KeySource &source, u32 generation) { Result PrepareCommonEsTitleKey(AccessKey *out, const KeySource &source, u32 generation) {
SecmonArgs args; svc::SecureMonitorArguments args;
args.X[0] = static_cast<u64>(FunctionId::PrepareCommonEsTitleKey); args.r[0] = static_cast<u64>(FunctionId::PrepareCommonEsTitleKey);
args.X[1] = source.data64[0]; args.r[1] = source.data64[0];
args.X[2] = source.data64[1]; args.r[2] = source.data64[1];
args.X[3] = generation; args.r[3] = generation;
svcCallSecureMonitor(&args); svc::CallSecureMonitor(std::addressof(args));
out->data64[0] = args.X[1]; out->data64[0] = args.r[1];
out->data64[1] = args.X[2]; out->data64[1] = args.r[2];
return static_cast<Result>(args.X[0]); return static_cast<Result>(args.r[0]);
} }
/* Deprecated functions. */ /* Deprecated functions. */
Result LoadEsDeviceKey(const void *data, size_t size, const AccessKey &access_key, const KeySource &source, u32 option) { Result LoadEsDeviceKey(const void *data, size_t size, const AccessKey &access_key, const KeySource &source, u32 option) {
SecmonArgs args; svc::SecureMonitorArguments args;
args.X[0] = static_cast<u64>(FunctionId::LoadEsDeviceKey); args.r[0] = static_cast<u64>(FunctionId::LoadEsDeviceKey);
args.X[1] = access_key.data64[0]; args.r[1] = access_key.data64[0];
args.X[2] = access_key.data64[1]; args.r[2] = access_key.data64[1];
args.X[3] = option; args.r[3] = option;
args.X[4] = reinterpret_cast<u64>(data); args.r[4] = reinterpret_cast<u64>(data);
args.X[5] = size; args.r[5] = size;
args.X[6] = source.data64[0]; args.r[6] = source.data64[0];
args.X[7] = source.data64[1]; args.r[7] = source.data64[1];
svcCallSecureMonitor(&args); svc::CallSecureMonitor(std::addressof(args));
return static_cast<Result>(args.X[0]); return static_cast<Result>(args.r[0]);
} }
Result DecryptDeviceUniqueData(size_t *out_size, void *data, size_t size, const AccessKey &access_key, const KeySource &source, u32 option) { Result DecryptDeviceUniqueData(size_t *out_size, void *data, size_t size, const AccessKey &access_key, const KeySource &source, u32 option) {
SecmonArgs args; svc::SecureMonitorArguments args;
args.X[0] = static_cast<u64>(FunctionId::DecryptDeviceUniqueData); args.r[0] = static_cast<u64>(FunctionId::DecryptDeviceUniqueData);
args.X[1] = access_key.data64[0]; args.r[1] = access_key.data64[0];
args.X[2] = access_key.data64[1]; args.r[2] = access_key.data64[1];
args.X[3] = option; args.r[3] = option;
args.X[4] = reinterpret_cast<u64>(data); args.r[4] = reinterpret_cast<u64>(data);
args.X[5] = size; args.r[5] = size;
args.X[6] = source.data64[0]; args.r[6] = source.data64[0];
args.X[7] = source.data64[1]; args.r[7] = source.data64[1];
svcCallSecureMonitor(&args); svc::CallSecureMonitor(std::addressof(args));
*out_size = static_cast<size_t>(args.X[1]); *out_size = static_cast<size_t>(args.r[1]);
return static_cast<Result>(args.X[0]); return static_cast<Result>(args.r[0]);
} }
Result DecryptAndStoreGcKey(const void *data, size_t size, const AccessKey &access_key, const KeySource &source, u32 option) { Result DecryptAndStoreGcKey(const void *data, size_t size, const AccessKey &access_key, const KeySource &source, u32 option) {
SecmonArgs args; svc::SecureMonitorArguments args;
args.X[0] = static_cast<u64>(FunctionId::DecryptAndStoreGcKey); args.r[0] = static_cast<u64>(FunctionId::DecryptAndStoreGcKey);
args.X[1] = access_key.data64[0]; args.r[1] = access_key.data64[0];
args.X[2] = access_key.data64[1]; args.r[2] = access_key.data64[1];
args.X[3] = option; args.r[3] = option;
args.X[4] = reinterpret_cast<u64>(data); args.r[4] = reinterpret_cast<u64>(data);
args.X[5] = size; args.r[5] = size;
args.X[6] = source.data64[0]; args.r[6] = source.data64[0];
args.X[7] = source.data64[1]; args.r[7] = source.data64[1];
svcCallSecureMonitor(&args); svc::CallSecureMonitor(std::addressof(args));
return static_cast<Result>(args.X[0]); return static_cast<Result>(args.r[0]);
} }
/* Atmosphere functions. */ /* Atmosphere functions. */
@ -315,15 +315,15 @@ namespace ams::spl::smc {
}; };
inline Result AtmosphereIramCopy(uintptr_t dram_address, uintptr_t iram_address, size_t size, IramCopyDirection direction) { inline Result AtmosphereIramCopy(uintptr_t dram_address, uintptr_t iram_address, size_t size, IramCopyDirection direction) {
SecmonArgs args; svc::SecureMonitorArguments args;
args.X[0] = static_cast<u64>(FunctionId::AtmosphereIramCopy); args.r[0] = static_cast<u64>(FunctionId::AtmosphereIramCopy);
args.X[1] = dram_address; args.r[1] = dram_address;
args.X[2] = iram_address; args.r[2] = iram_address;
args.X[3] = size; args.r[3] = size;
args.X[4] = static_cast<u64>(direction); args.r[4] = static_cast<u64>(direction);
svcCallSecureMonitor(&args); svc::CallSecureMonitor(std::addressof(args));
return static_cast<Result>(args.X[0]); return static_cast<Result>(args.r[0]);
} }
} }
@ -337,29 +337,29 @@ namespace ams::spl::smc {
} }
Result AtmosphereReadWriteRegister(uint64_t address, uint32_t mask, uint32_t value, uint32_t *out_value) { Result AtmosphereReadWriteRegister(uint64_t address, uint32_t mask, uint32_t value, uint32_t *out_value) {
SecmonArgs args; svc::SecureMonitorArguments args;
args.X[0] = static_cast<u64>(FunctionId::AtmosphereReadWriteRegister); args.r[0] = static_cast<u64>(FunctionId::AtmosphereReadWriteRegister);
args.X[1] = address; args.r[1] = address;
args.X[2] = mask; args.r[2] = mask;
args.X[3] = value; args.r[3] = value;
svcCallSecureMonitor(&args); svc::CallSecureMonitor(std::addressof(args));
*out_value = static_cast<uint32_t>(args.X[1]); *out_value = static_cast<uint32_t>(args.r[1]);
return static_cast<Result>(args.X[0]); return static_cast<Result>(args.r[0]);
} }
Result AtmosphereGetEmummcConfig(void *out_config, void *out_paths, u32 storage_id) { Result AtmosphereGetEmummcConfig(void *out_config, void *out_paths, u32 storage_id) {
const u64 paths = reinterpret_cast<u64>(out_paths); const u64 paths = reinterpret_cast<u64>(out_paths);
AMS_ABORT_UNLESS(util::IsAligned(paths, os::MemoryPageSize)); AMS_ABORT_UNLESS(util::IsAligned(paths, os::MemoryPageSize));
SecmonArgs args = {}; svc::SecureMonitorArguments args = {};
args.X[0] = static_cast<u64>(FunctionId::AtmosphereGetEmummcConfig); args.r[0] = static_cast<u64>(FunctionId::AtmosphereGetEmummcConfig);
args.X[1] = storage_id; args.r[1] = storage_id;
args.X[2] = paths; args.r[2] = paths;
svcCallSecureMonitor(&args); svc::CallSecureMonitor(std::addressof(args));
std::memcpy(out_config, &args.X[1], sizeof(args) - sizeof(args.X[0])); std::memcpy(out_config, &args.r[1], sizeof(args) - sizeof(args.r[0]));
return static_cast<Result>(args.X[0]); return static_cast<Result>(args.r[0]);
} }
} }

View File

@ -31,7 +31,7 @@ namespace ams::svc::arch::arm64 {
ALWAYS_INLINE ThreadLocalRegion *GetThreadLocalRegion() { ALWAYS_INLINE ThreadLocalRegion *GetThreadLocalRegion() {
ThreadLocalRegion *tlr; ThreadLocalRegion *tlr;
__asm__ __volatile__("mrs %[tlr], tpidrro_el0" : [tlr]"=&r"(tlr) :: "memory"); __asm__ __volatile__("mrs %[tlr], tpidrro_el0" : [tlr]"=&r"(tlr));
return tlr; return tlr;
} }