strat: prefer os::NativeHandle to Handle/svc::Handle where sensible

This commit is contained in:
Michael Scire 2021-10-04 17:12:32 -07:00
parent 597d521f52
commit d0041a33ac
50 changed files with 193 additions and 190 deletions

View file

@ -25,9 +25,9 @@ namespace ams::dd {
Result CreateDeviceAddressSpace(DeviceAddressSpaceType *das, u64 size);
void DestroyDeviceAddressSpace(DeviceAddressSpaceType *das);
void AttachDeviceAddressSpaceHandle(DeviceAddressSpaceType *das, Handle handle, bool managed);
void AttachDeviceAddressSpaceHandle(DeviceAddressSpaceType *das, DeviceAddressSpaceHandle handle, bool managed);
Handle GetDeviceAddressSpaceHandle(DeviceAddressSpaceType *das);
DeviceAddressSpaceHandle GetDeviceAddressSpaceHandle(DeviceAddressSpaceType *das);
Result MapDeviceAddressSpaceAligned(DeviceAddressSpaceType *das, ProcessHandle process_handle, u64 process_address, size_t size, DeviceVirtualAddress device_address, MemoryPermission device_perm);
Result MapDeviceAddressSpaceNotAligned(DeviceAddressSpaceType *das, ProcessHandle process_handle, u64 process_address, size_t size, DeviceVirtualAddress device_address, MemoryPermission device_perm);

View file

@ -20,6 +20,7 @@
namespace ams::dd {
using DeviceName = ::ams::svc::DeviceName;
using enum ::ams::svc::DeviceName;
constexpr inline u64 DeviceAddressSpaceMemoryRegionAlignment = 4_KB;

View file

@ -21,7 +21,7 @@ namespace ams::dd {
using DeviceVirtualAddress = u64;
using DeviceAddressSpaceHandle = ::Handle;
using DeviceAddressSpaceHandle = os::NativeHandle;
struct DeviceAddressSpaceType {
enum State {

View file

@ -20,7 +20,7 @@
namespace ams::ldr::pm {
/* Process Manager API. */
Result CreateProcess(Handle *out, PinId pin_id, u32 flags, Handle reslimit);
Result CreateProcess(os::NativeHandle *out, PinId pin_id, u32 flags, os::NativeHandle reslimit);
Result GetProgramInfo(ProgramInfo *out, const ncm::ProgramLocation &loc);
Result PinProgram(PinId *out, const ncm::ProgramLocation &loc);
Result UnpinProgram(PinId pin_id);

View file

@ -73,7 +73,7 @@ namespace ams::map {
class MappedCodeMemory {
private:
Handle process_handle;
os::NativeHandle process_handle;
Result result;
uintptr_t dst_address;
uintptr_t src_address;
@ -83,7 +83,7 @@ namespace ams::map {
/* ... */
}
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(os::NativeHandle 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 = svc::MapProcessCodeMemory(this->process_handle, this->dst_address, this->src_address, this->size);
}

View file

@ -21,7 +21,7 @@ namespace ams::osdbg {
struct ThreadInfo;
Result InitializeThreadInfo(ThreadInfo *thread_info, svc::Handle debug_handle, const svc::DebugInfoCreateProcess *create_process, const svc::DebugInfoCreateThread *create_thread);
Result InitializeThreadInfo(ThreadInfo *thread_info, os::NativeHandle debug_handle, const svc::DebugInfoCreateProcess *create_process, const svc::DebugInfoCreateThread *create_thread);
Result UpdateThreadInfo(ThreadInfo *thread_info);
Result GetThreadName(char *dst, const ThreadInfo *thread_info);

View file

@ -40,7 +40,7 @@ namespace ams::osdbg {
uintptr_t _function;
uintptr_t _name_pointer;
impl::ThreadTypeCommon *_thread_type;
svc::Handle _debug_handle;
os::NativeHandle _debug_handle;
ThreadTypeType _thread_type_type;
svc::DebugInfoCreateProcess _debug_info_create_process;
svc::DebugInfoCreateThread _debug_info_create_thread;

View file

@ -31,7 +31,7 @@ namespace ams::sf::cmif {
class ServerMessageProcessor;
struct HandlesToClose {
Handle handles[8];
os::NativeHandle handles[8];
size_t num_handles;
};

View file

@ -55,7 +55,7 @@ namespace ams::sf::hipc {
NON_MOVEABLE(Server);
private:
cmif::ServiceObjectHolder static_object;
::Handle port_handle;
os::NativeHandle port_handle;
sm::ServiceName service_name;
int index;
bool service_managed;
@ -95,7 +95,7 @@ namespace ams::sf::hipc {
Result ProcessForMitmServer(os::MultiWaitHolderType *holder);
Result ProcessForSession(os::MultiWaitHolderType *holder);
void RegisterServerImpl(Server *server, Handle port_handle, bool is_mitm_server) {
void RegisterServerImpl(Server *server, os::NativeHandle port_handle, bool is_mitm_server) {
server->port_handle = port_handle;
hipc::AttachMultiWaitHolderForAccept(server, port_handle);
@ -111,7 +111,7 @@ namespace ams::sf::hipc {
os::LinkMultiWaitHolder(std::addressof(this->multi_wait), server);
}
void RegisterServerImpl(int index, cmif::ServiceObjectHolder &&static_holder, Handle port_handle, bool is_mitm_server) {
void RegisterServerImpl(int index, cmif::ServiceObjectHolder &&static_holder, os::NativeHandle port_handle, bool is_mitm_server) {
/* Allocate server memory. */
auto *server = this->AllocateServer();
AMS_ABORT_UNLESS(server != nullptr);
@ -128,7 +128,7 @@ namespace ams::sf::hipc {
Result RegisterServerImpl(int index, cmif::ServiceObjectHolder &&static_holder, sm::ServiceName service_name, size_t max_sessions) {
/* Register service. */
Handle port_handle;
os::NativeHandle port_handle;
R_TRY(sm::RegisterService(&port_handle, service_name, max_sessions, false));
/* Allocate server memory. */
@ -151,7 +151,7 @@ namespace ams::sf::hipc {
template<typename Interface>
Result RegisterMitmServerImpl(int index, cmif::ServiceObjectHolder &&static_holder, sm::ServiceName service_name) {
/* Install mitm service. */
Handle port_handle;
os::NativeHandle port_handle;
R_TRY(this->InstallMitmServerImpl(&port_handle, service_name, &Interface::ShouldMitm));
/* Allocate server memory. */
@ -171,7 +171,7 @@ namespace ams::sf::hipc {
return ResultSuccess();
}
Result InstallMitmServerImpl(Handle *out_port_handle, sm::ServiceName service_name, MitmQueryFunction query_func);
Result InstallMitmServerImpl(os::NativeHandle *out_port_handle, sm::ServiceName service_name, MitmQueryFunction query_func);
protected:
virtual Server *AllocateServer() = 0;
virtual void DestroyServer(Server *server) = 0;
@ -205,7 +205,7 @@ namespace ams::sf::hipc {
}
template<typename Interface>
void RegisterObjectForServer(SharedPointer<Interface> static_object, Handle port_handle) {
void RegisterObjectForServer(SharedPointer<Interface> static_object, os::NativeHandle port_handle) {
this->RegisterServerImpl(0, cmif::ServiceObjectHolder(std::move(static_object)), port_handle, false);
}
@ -214,7 +214,7 @@ namespace ams::sf::hipc {
return this->RegisterServerImpl(0, cmif::ServiceObjectHolder(std::move(static_object)), service_name, max_sessions);
}
void RegisterServer(int port_index, Handle port_handle) {
void RegisterServer(int port_index, os::NativeHandle port_handle) {
this->RegisterServerImpl(port_index, cmif::ServiceObjectHolder(), port_handle, false);
}

View file

@ -26,7 +26,7 @@ namespace ams::sm {
/* Ordinary SM API. */
Result GetService(Service *out, ServiceName name);
Result RegisterService(Handle *out, ServiceName name, size_t max_sessions, bool is_light);
Result RegisterService(os::NativeHandle *out, ServiceName name, size_t max_sessions, bool is_light);
Result UnregisterService(ServiceName name);
/* Atmosphere extensions. */

View file

@ -21,7 +21,7 @@
namespace ams::sm::mitm {
/* Mitm API. */
Result InstallMitm(Handle *out_port, Handle *out_query, ServiceName name);
Result InstallMitm(os::NativeHandle *out_port, os::NativeHandle *out_query, ServiceName name);
Result UninstallMitm(ServiceName name);
Result DeclareFutureMitm(ServiceName name);
Result ClearFutureMitm(ServiceName name);

View file

@ -28,12 +28,12 @@ namespace ams::tipc {
ObjectType_Session = 2,
};
private:
svc::Handle m_handle;
os::NativeHandle m_handle;
ObjectType m_type;
bool m_managed;
tipc::ServiceObjectBase *m_object;
private:
void InitializeImpl(ObjectType type, svc::Handle handle, bool managed, tipc::ServiceObjectBase *object) {
void InitializeImpl(ObjectType type, os::NativeHandle handle, bool managed, tipc::ServiceObjectBase *object) {
/* Validate that the object isn't already constructed. */
AMS_ASSERT(m_type == ObjectType_Invalid);
@ -44,16 +44,16 @@ namespace ams::tipc {
m_object = object;
}
public:
constexpr inline ObjectHolder() : m_handle(svc::InvalidHandle), m_type(ObjectType_Invalid), m_managed(false), m_object(nullptr) { /* ... */ }
constexpr inline ObjectHolder() : m_handle(os::InvalidNativeHandle), m_type(ObjectType_Invalid), m_managed(false), m_object(nullptr) { /* ... */ }
void InitializeAsPort(svc::Handle handle) {
void InitializeAsPort(os::NativeHandle handle) {
/* NOTE: Nintendo sets ports as managed, but this will cause a nullptr-deref if one is ever closed. */
/* This is theoretically a non-issue, as ports can't be closed, but we will set ours as unmanaged, */
/* just in case. */
this->InitializeImpl(ObjectType_Port, handle, false, nullptr);
}
void InitializeAsSession(svc::Handle handle, bool managed, tipc::ServiceObjectBase *object) {
void InitializeAsSession(os::NativeHandle handle, bool managed, tipc::ServiceObjectBase *object) {
this->InitializeImpl(ObjectType_Session, handle, managed, object);
}
@ -69,13 +69,13 @@ namespace ams::tipc {
}
/* Reset all fields. */
m_handle = svc::InvalidHandle;
m_handle = os::InvalidNativeHandle;
m_type = ObjectType_Invalid;
m_managed = false;
m_object = nullptr;
}
constexpr svc::Handle GetHandle() const {
constexpr os::NativeHandle GetHandle() const {
return m_handle;
}

View file

@ -37,7 +37,7 @@ namespace ams::tipc {
Entry *m_entries_end{};
os::MultiWaitType *m_multi_wait{};
private:
Entry *FindEntry(svc::Handle handle) {
Entry *FindEntry(os::NativeHandle handle) {
for (Entry *cur = m_entries_start; cur != m_entries_end; ++cur) {
if (GetReference(cur->object).GetHandle() == handle) {
return cur;
@ -76,7 +76,7 @@ namespace ams::tipc {
std::scoped_lock lk(m_mutex);
/* Find an empty entry. */
auto *entry = this->FindEntry(svc::InvalidHandle);
auto *entry = this->FindEntry(os::InvalidNativeHandle);
AMS_ABORT_UNLESS(entry != nullptr);
/* Set the entry's object. */
@ -87,7 +87,7 @@ namespace ams::tipc {
os::LinkMultiWaitHolder(m_multi_wait, std::addressof(entry->multi_wait_holder));
}
void CloseObject(svc::Handle handle) {
void CloseObject(os::NativeHandle handle) {
/* Lock ourselves. */
std::scoped_lock lk(m_mutex);
@ -103,14 +103,14 @@ namespace ams::tipc {
GetReference(entry->object).Destroy();
}
Result ReplyAndReceive(os::MultiWaitHolderType **out_holder, ObjectHolder *out_object, svc::Handle reply_target, os::MultiWaitType *multi_wait) {
Result ReplyAndReceive(os::MultiWaitHolderType **out_holder, ObjectHolder *out_object, os::NativeHandle reply_target, os::MultiWaitType *multi_wait) {
/* Declare signaled holder for processing ahead of time. */
os::MultiWaitHolderType *signaled_holder;
/* Reply and receive until we get a newly signaled target. */
Result result = os::SdkReplyAndReceive(out_holder, reply_target, multi_wait);
for (signaled_holder = *out_holder; signaled_holder == nullptr; signaled_holder = *out_holder) {
result = os::SdkReplyAndReceive(out_holder, svc::InvalidHandle, multi_wait);
result = os::SdkReplyAndReceive(out_holder, os::InvalidNativeHandle, multi_wait);
}
/* Find the entry matching the signaled holder. */
@ -125,7 +125,7 @@ namespace ams::tipc {
}
}
Result Reply(svc::Handle reply_target) {
Result Reply(os::NativeHandle reply_target) {
/* Perform the reply. */
s32 dummy;
R_TRY_CATCH(svc::ReplyAndReceive(std::addressof(dummy), nullptr, 0, reply_target, 0)) {

View file

@ -141,7 +141,7 @@ namespace ams::tipc {
m_object_manager = manager;
}
void RegisterPort(s32 index, svc::Handle port_handle) {
void RegisterPort(s32 index, os::NativeHandle port_handle) {
/* Set our port number. */
this->m_port_number = index;
@ -168,11 +168,11 @@ namespace ams::tipc {
return m_object_manager->Reply(object.GetHandle());
}
Result ReplyAndReceive(os::MultiWaitHolderType **out_holder, ObjectHolder *out_object, svc::Handle reply_target) {
Result ReplyAndReceive(os::MultiWaitHolderType **out_holder, ObjectHolder *out_object, os::NativeHandle reply_target) {
return m_object_manager->ReplyAndReceive(out_holder, out_object, reply_target, std::addressof(m_multi_wait));
}
void AddSession(svc::Handle session_handle, tipc::ServiceObjectBase *service_object) {
void AddSession(os::NativeHandle session_handle, tipc::ServiceObjectBase *service_object) {
/* Create an object holder for the session. */
tipc::ObjectHolder object;
@ -195,7 +195,7 @@ namespace ams::tipc {
case MessageType_AddSession:
{
/* Get the handle from where it's packed into the message type. */
const svc::Handle session_handle = static_cast<svc::Handle>(message_type >> BITSIZEOF(u32));
const os::NativeHandle session_handle = static_cast<os::NativeHandle>(message_type >> BITSIZEOF(u32));
/* Allocate a service object for the port. */
auto *service_object = m_server_manager->AllocateObject(static_cast<size_t>(message_data));
@ -292,7 +292,7 @@ namespace ams::tipc {
os::SendMessageQueue(std::addressof(m_message_queue), ConvertKeyToMessage(key));
}
void TriggerAddSession(svc::Handle session_handle, size_t port_index) {
void TriggerAddSession(os::NativeHandle session_handle, size_t port_index) {
/* Acquire exclusive server manager access. */
std::scoped_lock lk(m_server_manager->GetMutex());
@ -409,14 +409,14 @@ namespace ams::tipc {
}
template<size_t Ix>
void RegisterPort(svc::Handle port_handle) {
void RegisterPort(os::NativeHandle port_handle) {
this->GetPortManager<Ix>().RegisterPort(static_cast<s32>(Ix), port_handle);
}
template<size_t Ix>
void RegisterPort(sm::ServiceName service_name, size_t max_sessions) {
/* Register service. */
svc::Handle port_handle = svc::InvalidHandle;
os::NativeHandle port_handle;
R_ABORT_UNLESS(sm::RegisterService(std::addressof(port_handle), service_name, max_sessions, false));
/* Register the port handle. */
@ -463,13 +463,13 @@ namespace ams::tipc {
}(std::make_index_sequence<NumPorts>());
}
Result AddSession(svc::Handle *out, tipc::ServiceObjectBase *object) {
Result AddSession(os::NativeHandle *out, tipc::ServiceObjectBase *object) {
/* Acquire exclusive access to ourselves. */
std::scoped_lock lk(m_mutex);
/* Create a handle for the session. */
svc::Handle session_handle;
R_TRY(svc::CreateSession(std::addressof(session_handle), out, false, 0));
R_TRY(svc::CreateSession(std::addressof(session_handle), static_cast<svc::Handle *>(out), false, 0));
/* Select the best port manager. */
PortManagerBase *best_manager = nullptr;
@ -514,7 +514,7 @@ namespace ams::tipc {
std::memset(svc::ipc::GetMessageBuffer(), 0, svc::ipc::MessageBufferSize);
/* Process requests forever. */
svc::Handle reply_target = svc::InvalidHandle;
os::NativeHandle reply_target = os::InvalidNativeHandle;
while (true) {
/* Reply to our pending request, and receive a new one. */
os::MultiWaitHolderType *signaled_holder = nullptr;
@ -525,7 +525,7 @@ namespace ams::tipc {
port_manager.CloseSession(signaled_object);
/* We have nothing to reply to. */
reply_target = svc::InvalidHandle;
reply_target = os::InvalidNativeHandle;
continue;
}
} R_END_TRY_CATCH;
@ -542,7 +542,7 @@ namespace ams::tipc {
}
/* We have nothing to reply to. */
reply_target = svc::InvalidHandle;
reply_target = os::InvalidNativeHandle;
}
break;
case ObjectHolder::ObjectType_Session:
@ -557,7 +557,7 @@ namespace ams::tipc {
port_manager.ProcessRegisterRetry(signaled_object);
/* We have nothing to reply to. */
reply_target = svc::InvalidHandle;
reply_target = os::InvalidNativeHandle;
} else {
/* We're done processing, so we should reply. */
reply_target = signaled_object.GetHandle();
@ -571,7 +571,7 @@ namespace ams::tipc {
port_manager.CloseSessionIfNecessary(signaled_object, !tipc::ResultSessionClosed::Includes(process_result));
/* We have nothing to reply to. */
reply_target = svc::InvalidHandle;
reply_target = os::InvalidNativeHandle;
}
}
break;
@ -582,12 +582,12 @@ namespace ams::tipc {
port_manager.ProcessMessages();
/* We have nothing to reply to. */
reply_target = svc::InvalidHandle;
reply_target = os::InvalidNativeHandle;
}
}
}
void TriggerAddSession(svc::Handle session_handle, size_t port_index) {
void TriggerAddSession(os::NativeHandle session_handle, size_t port_index) {
/* Acquire exclusive access to ourselves. */
std::scoped_lock lk(m_mutex);

View file

@ -59,16 +59,16 @@ namespace ams::dd {
das->state = DeviceAddressSpaceType::State_NotInitialized;
}
void AttachDeviceAddressSpaceHandle(DeviceAddressSpaceType *das, Handle handle, bool managed) {
void AttachDeviceAddressSpaceHandle(DeviceAddressSpaceType *das, DeviceAddressSpaceHandle handle, bool managed) {
/* Check pre-conditions. */
AMS_ASSERT(handle != svc::InvalidHandle);
AMS_ASSERT(handle != os::InvalidNativeHandle);
das->device_handle = handle;
das->is_handle_managed = managed;
das->state = DeviceAddressSpaceType::State_Initialized;
}
Handle GetDeviceAddressSpaceHandle(DeviceAddressSpaceType *das) {
DeviceAddressSpaceHandle GetDeviceAddressSpaceHandle(DeviceAddressSpaceType *das) {
/* Check pre-conditions. */
AMS_ASSERT(das->state == DeviceAddressSpaceType::State_Initialized);

View file

@ -108,7 +108,7 @@ namespace ams::htc::server {
return ResultSuccess();
}
Result HtcmiscImpl::RunOnHostBegin(u32 *out_task_id, Handle *out_event, const char *args, size_t args_size) {
Result HtcmiscImpl::RunOnHostBegin(u32 *out_task_id, os::NativeHandle *out_event, const char *args, size_t args_size) {
/* Begin the task. */
u32 task_id;
R_TRY(m_rpc_client.Begin<rpc::RunOnHostTask>(std::addressof(task_id), args, args_size));

View file

@ -63,7 +63,7 @@ namespace ams::htc::server {
Result GetEnvironmentVariable(size_t *out_size, char *dst, size_t dst_size, const char *name, size_t name_size);
Result GetEnvironmentVariableLength(size_t *out_size, const char *name, size_t name_size);
Result RunOnHostBegin(u32 *out_task_id, Handle *out_event, const char *args, size_t args_size);
Result RunOnHostBegin(u32 *out_task_id, os::NativeHandle *out_event, const char *args, size_t args_size);
Result RunOnHostEnd(s32 *out_result, u32 task_id);
};

View file

@ -199,7 +199,7 @@ namespace ams::htc::server::rpc {
os::WaitEvent(m_task_table.Get<Task>(task_id)->GetEvent());
}
Handle DetachReadableHandle(u32 task_id) {
os::NativeHandle DetachReadableHandle(u32 task_id) {
return os::DetachReadableHandleOfSystemEvent(m_task_table.Get<Task>(task_id)->GetSystemEvent());
}

View file

@ -204,7 +204,7 @@ namespace ams::htcs::impl {
}
}
Result HtcsManager::AcceptStart(u32 *out_task_id, Handle *out_handle, s32 desc) {
Result HtcsManager::AcceptStart(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc) {
return m_impl->AcceptStart(out_task_id, out_handle, desc);
}
@ -227,7 +227,7 @@ namespace ams::htcs::impl {
}
}
Result HtcsManager::RecvStart(u32 *out_task_id, Handle *out_handle, s64 size, s32 desc, s32 flags) {
Result HtcsManager::RecvStart(u32 *out_task_id, os::NativeHandle *out_handle, s64 size, s32 desc, s32 flags) {
return m_impl->RecvStart(out_task_id, out_handle, size, desc, flags);
}
@ -255,11 +255,11 @@ namespace ams::htcs::impl {
}
}
Result HtcsManager::SendStart(u32 *out_task_id, Handle *out_handle, const char *buffer, s64 size, s32 desc, s32 flags) {
Result HtcsManager::SendStart(u32 *out_task_id, os::NativeHandle *out_handle, const char *buffer, s64 size, s32 desc, s32 flags) {
return m_impl->SendStart(out_task_id, out_handle, buffer, size, desc, flags);
}
Result HtcsManager::SendLargeStart(u32 *out_task_id, Handle *out_handle, const char **buffers, const s64 *sizes, s32 count, s32 desc, s32 flags) {
Result HtcsManager::SendLargeStart(u32 *out_task_id, os::NativeHandle *out_handle, const char **buffers, const s64 *sizes, s32 count, s32 desc, s32 flags) {
return m_impl->SendLargeStart(out_task_id, out_handle, buffers, sizes, count, desc, flags);
}
@ -287,7 +287,7 @@ namespace ams::htcs::impl {
}
}
Result HtcsManager::StartSend(u32 *out_task_id, Handle *out_handle, s32 desc, s64 size, s32 flags) {
Result HtcsManager::StartSend(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc, s64 size, s32 flags) {
return m_impl->StartSend(out_task_id, out_handle, desc, size, flags);
}
@ -328,7 +328,7 @@ namespace ams::htcs::impl {
}
}
Result HtcsManager::StartRecv(u32 *out_task_id, Handle *out_handle, s64 size, s32 desc, s32 flags) {
Result HtcsManager::StartRecv(u32 *out_task_id, os::NativeHandle *out_handle, s64 size, s32 desc, s32 flags) {
return m_impl->StartRecv(out_task_id, out_handle, size, desc, flags);
}
@ -356,7 +356,7 @@ namespace ams::htcs::impl {
}
}
Result HtcsManager::StartSelect(u32 *out_task_id, Handle *out_handle, Span<const int> read_handles, Span<const int> write_handles, Span<const int> exception_handles, s64 tv_sec, s64 tv_usec) {
Result HtcsManager::StartSelect(u32 *out_task_id, os::NativeHandle *out_handle, Span<const int> read_handles, Span<const int> write_handles, Span<const int> exception_handles, s64 tv_sec, s64 tv_usec) {
/* Invoke our implementation. */
R_TRY_CATCH(m_impl->StartSelect(out_task_id, out_handle, read_handles, write_handles, exception_handles, tv_sec, tv_usec)) {
R_CONVERT(htc::ResultTaskCancelled, tma::ResultUnknown())

View file

@ -43,24 +43,24 @@ namespace ams::htcs::impl {
void Shutdown(s32 *out_err, s32 *out_res, s32 how, s32 desc);
void Fcntl(s32 *out_err, s32 *out_res, s32 command, s32 value, s32 desc);
Result AcceptStart(u32 *out_task_id, Handle *out_handle, s32 desc);
Result AcceptStart(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc);
void AcceptResults(s32 *out_err, s32 *out_desc, SockAddrHtcs *out_address, u32 task_id, s32 desc);
Result RecvStart(u32 *out_task_id, Handle *out_handle, s64 size, s32 desc, s32 flags);
Result RecvStart(u32 *out_task_id, os::NativeHandle *out_handle, s64 size, s32 desc, s32 flags);
void RecvResults(s32 *out_err, s64 *out_size, char *buffer, s64 buffer_size, u32 task_id, s32 desc);
Result SendStart(u32 *out_task_id, Handle *out_handle, const char *buffer, s64 size, s32 desc, s32 flags);
Result SendLargeStart(u32 *out_task_id, Handle *out_handle, const char **buffers, const s64 *sizes, s32 count, s32 desc, s32 flags);
Result SendStart(u32 *out_task_id, os::NativeHandle *out_handle, const char *buffer, s64 size, s32 desc, s32 flags);
Result SendLargeStart(u32 *out_task_id, os::NativeHandle *out_handle, const char **buffers, const s64 *sizes, s32 count, s32 desc, s32 flags);
void SendResults(s32 *out_err, s64 *out_size, u32 task_id, s32 desc);
Result StartSend(u32 *out_task_id, Handle *out_handle, s32 desc, s64 size, s32 flags);
Result StartSend(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc, s64 size, s32 flags);
Result ContinueSend(s64 *out_size, const char *buffer, s64 buffer_size, u32 task_id, s32 desc);
void EndSend(s32 *out_err, s64 *out_size, u32 task_id, s32 desc);
Result StartRecv(u32 *out_task_id, Handle *out_handle, s64 size, s32 desc, s32 flags);
Result StartRecv(u32 *out_task_id, os::NativeHandle *out_handle, s64 size, s32 desc, s32 flags);
void EndRecv(s32 *out_err, s64 *out_size, char *buffer, s64 buffer_size, u32 task_id, s32 desc);
Result StartSelect(u32 *out_task_id, Handle *out_handle, Span<const int> read_handles, Span<const int> write_handles, Span<const int> exception_handles, s64 tv_sec, s64 tv_usec);
Result StartSelect(u32 *out_task_id, os::NativeHandle *out_handle, Span<const int> read_handles, Span<const int> write_handles, Span<const int> exception_handles, s64 tv_sec, s64 tv_usec);
Result EndSelect(s32 *out_err, s32 *out_count, Span<int> read_handles, Span<int> write_handles, Span<int> exception_handles, u32 task_id);
};

View file

@ -82,7 +82,7 @@ namespace ams::htcs::impl {
return m_service.Fcntl(out_err, out_res, desc, command, value);
}
Result HtcsManagerImpl::AcceptStart(u32 *out_task_id, Handle *out_handle, s32 desc) {
Result HtcsManagerImpl::AcceptStart(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc) {
return m_service.AcceptStart(out_task_id, out_handle, desc);
}
@ -90,7 +90,7 @@ namespace ams::htcs::impl {
return m_service.AcceptResults(out_err, out_desc, out_address, task_id, desc);
}
Result HtcsManagerImpl::RecvStart(u32 *out_task_id, Handle *out_handle, s64 size, s32 desc, s32 flags) {
Result HtcsManagerImpl::RecvStart(u32 *out_task_id, os::NativeHandle *out_handle, s64 size, s32 desc, s32 flags) {
return m_service.ReceiveSmallStart(out_task_id, out_handle, size, desc, flags);
}
@ -98,10 +98,10 @@ namespace ams::htcs::impl {
return m_service.ReceiveSmallResults(out_err, out_size, buffer, buffer_size, task_id, desc);
}
Result HtcsManagerImpl::SendStart(u32 *out_task_id, Handle *out_handle, const char *buffer, s64 size, s32 desc, s32 flags) {
Result HtcsManagerImpl::SendStart(u32 *out_task_id, os::NativeHandle *out_handle, const char *buffer, s64 size, s32 desc, s32 flags) {
/* Start the send. */
u32 task_id;
Handle handle;
os::NativeHandle handle;
R_TRY(m_service.SendSmallStart(std::addressof(task_id), std::addressof(handle), desc, size, flags));
/* Continue the send. */
@ -126,7 +126,7 @@ namespace ams::htcs::impl {
return ResultSuccess();
}
Result HtcsManagerImpl::SendLargeStart(u32 *out_task_id, Handle *out_handle, const char **buffers, const s64 *sizes, s32 count, s32 desc, s32 flags) {
Result HtcsManagerImpl::SendLargeStart(u32 *out_task_id, os::NativeHandle *out_handle, const char **buffers, const s64 *sizes, s32 count, s32 desc, s32 flags) {
/* NOTE: Nintendo aborts here, too. */
AMS_ABORT("HtcsManagerImpl::SendLargeStart is not implemented");
}
@ -135,7 +135,7 @@ namespace ams::htcs::impl {
return m_service.SendSmallResults(out_err, out_size, task_id, desc);
}
Result HtcsManagerImpl::StartSend(u32 *out_task_id, Handle *out_handle, s32 desc, s64 size, s32 flags) {
Result HtcsManagerImpl::StartSend(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc, s64 size, s32 flags) {
return m_service.SendStart(out_task_id, out_handle, desc, size, flags);
}
@ -147,7 +147,7 @@ namespace ams::htcs::impl {
return m_service.SendResults(out_err, out_size, task_id, desc);
}
Result HtcsManagerImpl::StartRecv(u32 *out_task_id, Handle *out_handle, s64 size, s32 desc, s32 flags) {
Result HtcsManagerImpl::StartRecv(u32 *out_task_id, os::NativeHandle *out_handle, s64 size, s32 desc, s32 flags) {
return m_service.ReceiveStart(out_task_id, out_handle, size, desc, flags);
}
@ -155,10 +155,10 @@ namespace ams::htcs::impl {
return m_service.ReceiveResults(out_err, out_size, buffer, buffer_size, task_id, desc);
}
Result HtcsManagerImpl::StartSelect(u32 *out_task_id, Handle *out_handle, Span<const int> read_handles, Span<const int> write_handles, Span<const int> exception_handles, s64 tv_sec, s64 tv_usec) {
Result HtcsManagerImpl::StartSelect(u32 *out_task_id, os::NativeHandle *out_handle, Span<const int> read_handles, Span<const int> write_handles, Span<const int> exception_handles, s64 tv_sec, s64 tv_usec) {
/* Start the select. */
u32 task_id;
Handle handle;
os::NativeHandle handle;
const Result result = m_service.SelectStart(std::addressof(task_id), std::addressof(handle), read_handles, write_handles, exception_handles, tv_sec, tv_usec);
/* Ensure our state ends up clean. */

View file

@ -52,24 +52,24 @@ namespace ams::htcs::impl {
Result Shutdown(s32 *out_err, s32 desc, s32 how);
Result Fcntl(s32 *out_err, s32 *out_res, s32 desc, s32 command, s32 value);
Result AcceptStart(u32 *out_task_id, Handle *out_handle, s32 desc);
Result AcceptStart(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc);
Result AcceptResults(s32 *out_err, s32 *out_desc, SockAddrHtcs *out_address, u32 task_id, s32 desc);
Result RecvStart(u32 *out_task_id, Handle *out_handle, s64 size, s32 desc, s32 flags);
Result RecvStart(u32 *out_task_id, os::NativeHandle *out_handle, s64 size, s32 desc, s32 flags);
Result RecvResults(s32 *out_err, s64 *out_size, char *buffer, s64 buffer_size, u32 task_id, s32 desc);
Result SendStart(u32 *out_task_id, Handle *out_handle, const char *buffer, s64 size, s32 desc, s32 flags);
Result SendLargeStart(u32 *out_task_id, Handle *out_handle, const char **buffers, const s64 *sizes, s32 count, s32 desc, s32 flags);
Result SendStart(u32 *out_task_id, os::NativeHandle *out_handle, const char *buffer, s64 size, s32 desc, s32 flags);
Result SendLargeStart(u32 *out_task_id, os::NativeHandle *out_handle, const char **buffers, const s64 *sizes, s32 count, s32 desc, s32 flags);
Result SendResults(s32 *out_err, s64 *out_size, u32 task_id, s32 desc);
Result StartSend(u32 *out_task_id, Handle *out_handle, s32 desc, s64 size, s32 flags);
Result StartSend(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc, s64 size, s32 flags);
Result ContinueSend(s64 *out_size, const char *buffer, s64 buffer_size, u32 task_id, s32 desc);
Result EndSend(s32 *out_err, s64 *out_size, u32 task_id, s32 desc);
Result StartRecv(u32 *out_task_id, Handle *out_handle, s64 size, s32 desc, s32 flags);
Result StartRecv(u32 *out_task_id, os::NativeHandle *out_handle, s64 size, s32 desc, s32 flags);
Result EndRecv(s32 *out_err, s64 *out_size, char *buffer, s64 buffer_size, u32 task_id, s32 desc);
Result StartSelect(u32 *out_task_id, Handle *out_handle, Span<const int> read_handles, Span<const int> write_handles, Span<const int> exception_handles, s64 tv_sec, s64 tv_usec);
Result StartSelect(u32 *out_task_id, os::NativeHandle *out_handle, Span<const int> read_handles, Span<const int> write_handles, Span<const int> exception_handles, s64 tv_sec, s64 tv_usec);
Result EndSelect(s32 *out_err, bool *out_empty, Span<int> read_handles, Span<int> write_handles, Span<int> exception_handles, u32 task_id);
};

View file

@ -196,7 +196,7 @@ namespace ams::htcs::impl {
return ResultSuccess();
}
Result HtcsService::AcceptStart(u32 *out_task_id, Handle *out_handle, s32 desc) {
Result HtcsService::AcceptStart(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc) {
/* Begin the task. */
u32 task_id;
R_TRY(m_rpc_client->Begin<rpc::AcceptTask>(std::addressof(task_id), desc));
@ -220,7 +220,7 @@ namespace ams::htcs::impl {
return ResultSuccess();
}
Result HtcsService::ReceiveSmallStart(u32 *out_task_id, Handle *out_handle, s64 size, s32 desc, s32 flags) {
Result HtcsService::ReceiveSmallStart(u32 *out_task_id, os::NativeHandle *out_handle, s64 size, s32 desc, s32 flags) {
/* Begin the task. */
u32 task_id;
R_TRY(m_rpc_client->Begin<rpc::ReceiveSmallTask>(std::addressof(task_id), desc, size, static_cast<htcs::MessageFlag>(flags)));
@ -245,7 +245,7 @@ namespace ams::htcs::impl {
return ResultSuccess();
}
Result HtcsService::SendSmallStart(u32 *out_task_id, Handle *out_handle, s32 desc, s64 size, s32 flags) {
Result HtcsService::SendSmallStart(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc, s64 size, s32 flags) {
/* Begin the task. */
u32 task_id;
R_TRY(m_rpc_client->Begin<rpc::SendSmallTask>(std::addressof(task_id), desc, size, static_cast<htcs::MessageFlag>(flags)));
@ -279,7 +279,7 @@ namespace ams::htcs::impl {
return ResultSuccess();
}
Result HtcsService::SendStart(u32 *out_task_id, Handle *out_handle, s32 desc, s64 size, s32 flags) {
Result HtcsService::SendStart(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc, s64 size, s32 flags) {
/* Begin the task. */
u32 task_id;
R_TRY(m_rpc_client->Begin<rpc::SendTask>(std::addressof(task_id), desc, size, static_cast<htcs::MessageFlag>(flags)));
@ -325,7 +325,7 @@ namespace ams::htcs::impl {
return ResultSuccess();
}
Result HtcsService::ReceiveStart(u32 *out_task_id, Handle *out_handle, s64 size, s32 desc, s32 flags) {
Result HtcsService::ReceiveStart(u32 *out_task_id, os::NativeHandle *out_handle, s64 size, s32 desc, s32 flags) {
/* Begin the task. */
u32 task_id;
R_TRY(m_rpc_client->Begin<rpc::ReceiveTask>(std::addressof(task_id), desc, size, static_cast<htcs::MessageFlag>(flags)));
@ -377,7 +377,7 @@ namespace ams::htcs::impl {
return ResultSuccess();
}
Result HtcsService::SelectStart(u32 *out_task_id, Handle *out_handle, Span<const int> read_handles, Span<const int> write_handles, Span<const int> exception_handles, s64 tv_sec, s64 tv_usec) {
Result HtcsService::SelectStart(u32 *out_task_id, os::NativeHandle *out_handle, Span<const int> read_handles, Span<const int> write_handles, Span<const int> exception_handles, s64 tv_sec, s64 tv_usec) {
/* Begin the task. */
u32 task_id;
R_TRY(m_rpc_client->Begin<rpc::SelectTask>(std::addressof(task_id), read_handles, write_handles, exception_handles, tv_sec, tv_usec));

View file

@ -41,24 +41,24 @@ namespace ams::htcs::impl {
Result Shutdown(s32 *out_err, s32 desc, s32 how);
Result Fcntl(s32 *out_err, s32 *out_res, s32 desc, s32 command, s32 value);
Result AcceptStart(u32 *out_task_id, Handle *out_handle, s32 desc);
Result AcceptStart(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc);
Result AcceptResults(s32 *out_err, s32 *out_desc, SockAddrHtcs *out_address, u32 task_id, s32 desc);
Result ReceiveSmallStart(u32 *out_task_id, Handle *out_handle, s64 size, s32 desc, s32 flags);
Result ReceiveSmallStart(u32 *out_task_id, os::NativeHandle *out_handle, s64 size, s32 desc, s32 flags);
Result ReceiveSmallResults(s32 *out_err, s64 *out_size, char *buffer, s64 buffer_size, u32 task_id, s32 desc);
Result SendSmallStart(u32 *out_task_id, Handle *out_handle, s32 desc, s64 size, s32 flags);
Result SendSmallStart(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc, s64 size, s32 flags);
Result SendSmallContinue(s64 *out_size, const char *buffer, s64 buffer_size, u32 task_id, s32 desc);
Result SendSmallResults(s32 *out_err, s64 *out_size, u32 task_id, s32 desc);
Result SendStart(u32 *out_task_id, Handle *out_handle, s32 desc, s64 size, s32 flags);
Result SendStart(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc, s64 size, s32 flags);
Result SendContinue(s64 *out_size, const char *buffer, s64 buffer_size, u32 task_id, s32 desc);
Result SendResults(s32 *out_err, s64 *out_size, u32 task_id, s32 desc);
Result ReceiveStart(u32 *out_task_id, Handle *out_handle, s64 size, s32 desc, s32 flags);
Result ReceiveStart(u32 *out_task_id, os::NativeHandle *out_handle, s64 size, s32 desc, s32 flags);
Result ReceiveResults(s32 *out_err, s64 *out_size, char *buffer, s64 buffer_size, u32 task_id, s32 desc);
Result SelectStart(u32 *out_task_id, Handle *out_handle, Span<const int> read_handles, Span<const int> write_handles, Span<const int> exception_handles, s64 tv_sec, s64 tv_usec);
Result SelectStart(u32 *out_task_id, os::NativeHandle *out_handle, Span<const int> read_handles, Span<const int> write_handles, Span<const int> exception_handles, s64 tv_sec, s64 tv_usec);
Result SelectEnd(s32 *out_err, bool *out_empty, Span<int> read_handles, Span<int> write_handles, Span<int> exception_handles, u32 task_id);
private:
void WaitTask(u32 task_id);

View file

@ -19,7 +19,7 @@
namespace ams::ldr::pm {
/* Information API. */
Result CreateProcess(Handle *out, PinId pin_id, u32 flags, Handle reslimit) {
Result CreateProcess(os::NativeHandle *out, PinId pin_id, u32 flags, Handle reslimit) {
return ldrPmCreateProcess(pin_id.value, flags, reslimit, out);
}

View file

@ -23,7 +23,7 @@
namespace ams::osdbg {
Result InitializeThreadInfo(ThreadInfo *thread_info, svc::Handle debug_handle, const svc::DebugInfoCreateProcess *create_process, const svc::DebugInfoCreateThread *create_thread) {
Result InitializeThreadInfo(ThreadInfo *thread_info, os::NativeHandle debug_handle, const svc::DebugInfoCreateProcess *create_process, const svc::DebugInfoCreateThread *create_thread) {
/* Set basic fields. */
thread_info->_thread_type = nullptr;
thread_info->_thread_type_type = ThreadTypeType_Unknown;

View file

@ -172,7 +172,7 @@ namespace ams::pgl::srv {
LoopProcessServer();
}
Result AllocateShellEventObserverForTipc(svc::Handle *out) {
Result AllocateShellEventObserverForTipc(os::NativeHandle *out) {
/* Get the shell event observer allocator. */
auto &allocator = GetGlobalsForTipc().observer_allocator;

View file

@ -18,6 +18,6 @@
namespace ams::pgl::srv {
Result AllocateShellEventObserverForTipc(svc::Handle *out);
Result AllocateShellEventObserverForTipc(os::NativeHandle *out);
}

View file

@ -54,7 +54,7 @@ namespace ams::sf::hipc::impl {
}
void RegisterMitmQueryHandle(Handle query_handle, ServerManagerBase::MitmQueryFunction query_func) {
void RegisterMitmQueryHandle(os::NativeHandle query_handle, ServerManagerBase::MitmQueryFunction query_func) {
std::scoped_lock lk(g_query_server_lock);
if (AMS_UNLIKELY(!g_constructed_server)) {

View file

@ -18,6 +18,6 @@
namespace ams::sf::hipc::impl {
void RegisterMitmQueryHandle(Handle query_handle, ServerManagerBase::MitmQueryFunction query_func);
void RegisterMitmQueryHandle(os::NativeHandle query_handle, ServerManagerBase::MitmQueryFunction query_func);
}

View file

@ -34,13 +34,13 @@ namespace ams::sf::hipc {
ServerSession *session;
bool is_mitm_session;
private:
Result CloneCurrentObjectImpl(Handle *out_client_handle, ServerSessionManager *tagged_manager) {
Result CloneCurrentObjectImpl(os::NativeHandle *out_client_handle, ServerSessionManager *tagged_manager) {
/* Clone the object. */
cmif::ServiceObjectHolder &&clone = this->session->srv_obj_holder.Clone();
R_UNLESS(clone, sf::hipc::ResultDomainObjectNotFound());
/* Create new session handles. */
Handle server_handle;
os::NativeHandle server_handle;
R_ABORT_UNLESS(hipc::CreateSession(&server_handle, out_client_handle));
/* Register with manager. */
@ -118,18 +118,18 @@ namespace ams::sf::hipc {
if (!this->is_mitm_session || object_id.value != serviceGetObjectId(this->session->forward_service.get())) {
/* Create new session handles. */
Handle server_handle;
os::NativeHandle server_handle;
R_ABORT_UNLESS(hipc::CreateSession(&server_handle, out.GetHandlePointer()));
/* Register. */
R_ABORT_UNLESS(this->manager->RegisterSession(server_handle, std::move(object)));
} else {
/* Copy from the target domain. */
Handle new_forward_target;
os::NativeHandle new_forward_target;
R_TRY(cmifCopyFromCurrentDomain(this->session->forward_service->session, object_id.value, &new_forward_target));
/* Create new session handles. */
Handle server_handle;
os::NativeHandle server_handle;
R_ABORT_UNLESS(hipc::CreateSession(&server_handle, out.GetHandlePointer()));
/* Register. */

View file

@ -18,9 +18,9 @@
namespace ams::sf::hipc {
Result ServerManagerBase::InstallMitmServerImpl(Handle *out_port_handle, sm::ServiceName service_name, ServerManagerBase::MitmQueryFunction query_func) {
Result ServerManagerBase::InstallMitmServerImpl(os::NativeHandle *out_port_handle, sm::ServiceName service_name, ServerManagerBase::MitmQueryFunction query_func) {
/* Install the Mitm. */
Handle query_handle;
os::NativeHandle query_handle;
R_TRY(sm::mitm::InstallMitm(out_port_handle, &query_handle, service_name));
/* Register the query handle. */

View file

@ -49,7 +49,7 @@ namespace ams::sm {
return smGetServiceWrapper(out, impl::ConvertName(name));
}
Result RegisterService(Handle *out, ServiceName name, size_t max_sessions, bool is_light) {
Result RegisterService(os::NativeHandle *out, ServiceName name, size_t max_sessions, bool is_light) {
return smRegisterService(out, impl::ConvertName(name), is_light, static_cast<int>(max_sessions));
}

View file

@ -19,7 +19,7 @@
namespace ams::sm::mitm {
/* Mitm API. */
Result InstallMitm(Handle *out_port, Handle *out_query, ServiceName name) {
Result InstallMitm(os::NativeHandle *out_port, os::NativeHandle *out_query, ServiceName name) {
return impl::DoWithPerThreadSession([&](TipcService *fwd) {
return smAtmosphereMitmInstall(fwd, out_port, out_query, impl::ConvertName(name));
});

View file

@ -41,7 +41,7 @@ namespace ams::spl {
return serviceDispatchIn(splCryptoGetServiceSession(), 22, slot);
}
Result GetAesKeySlotAvailableEventImpl(Handle *out) {
Result GetAesKeySlotAvailableEventImpl(os::NativeHandle *out) {
return serviceDispatch(splCryptoGetServiceSession(), 23,
.out_handle_attrs = { SfOutHandleAttr_HipcCopy },
.out_handles = out,
@ -49,8 +49,8 @@ namespace ams::spl {
}
void GetAesKeySlotAvailableEvent(os::SystemEvent *out) {
/* Get libnx event. */
Handle handle = svc::InvalidHandle;
/* Get event handle. */
os::NativeHandle handle;
R_ABORT_UNLESS(GetAesKeySlotAvailableEventImpl(std::addressof(handle)));
/* Attach to event. */

View file

@ -22,10 +22,9 @@
namespace ams::svc {
/* TODO: C++ style handle? */
#ifdef ATMOSPHERE_IS_STRATOSPHERE
using Handle = ::Handle;
#else
using Handle = u32;
#if defined(ATMOSPHERE_IS_STRATOSPHERE)
static_assert(std::same_as<::ams::svc::Handle, ::Handle>);
#endif
enum {

View file

@ -40,7 +40,7 @@ namespace ams::dmnt {
ContinueMode_Step,
};
private:
svc::Handle m_debug_handle{svc::InvalidHandle};
os::NativeHandle m_debug_handle{os::InvalidNativeHandle};
s32 m_thread_count{0};
bool m_is_valid{false};
bool m_is_64_bit{false};
@ -73,7 +73,7 @@ namespace ams::dmnt {
}
~DebugProcess() { this->Detach(); }
svc::Handle GetHandle() const { return m_debug_handle; }
os::NativeHandle GetHandle() const { return m_debug_handle; }
bool IsValid() const { return m_is_valid; }
bool Is64Bit() const { return m_is_64_bit; }
bool Is64BitAddressSpace() const { return m_is_64_bit_address_space; }

View file

@ -88,7 +88,7 @@ namespace ams::dmnt::cheat::impl {
os::Event debug_events_event; /* Autoclear. */
os::ThreadType detect_thread, debug_events_thread;
os::SystemEvent cheat_process_event;
Handle cheat_process_debug_handle = svc::InvalidHandle;
os::NativeHandle cheat_process_debug_handle = os::InvalidNativeHandle;
CheatProcessMetadata cheat_process_metadata = {};
os::ThreadType vm_thread;
@ -175,7 +175,7 @@ namespace ams::dmnt::cheat::impl {
}
void CloseActiveCheatProcess() {
if (this->cheat_process_debug_handle != svc::InvalidHandle) {
if (this->cheat_process_debug_handle != os::InvalidNativeHandle) {
/* We don't need to do any unsafe brekaing. */
this->broken_unsafe = false;
this->unsafe_break_event.Signal();
@ -185,7 +185,7 @@ namespace ams::dmnt::cheat::impl {
/* Close resources. */
R_ABORT_UNLESS(svc::CloseHandle(this->cheat_process_debug_handle));
this->cheat_process_debug_handle = svc::InvalidHandle;
this->cheat_process_debug_handle = os::InvalidNativeHandle;
/* Save cheat toggles. */
if (this->always_save_cheat_toggles || this->should_save_cheat_toggles) {
@ -218,7 +218,7 @@ namespace ams::dmnt::cheat::impl {
bool HasActiveCheatProcess() {
/* Note: This function *MUST* be called only with the cheat lock held. */
os::ProcessId pid;
bool has_cheat_process = this->cheat_process_debug_handle != svc::InvalidHandle;
bool has_cheat_process = this->cheat_process_debug_handle != os::InvalidNativeHandle;
has_cheat_process &= R_SUCCEEDED(os::GetProcessId(&pid, this->cheat_process_debug_handle));
has_cheat_process &= R_SUCCEEDED(pm::dmnt::GetApplicationProcessId(&pid));
has_cheat_process &= (pid == this->cheat_process_metadata.process_id);
@ -235,12 +235,12 @@ namespace ams::dmnt::cheat::impl {
return ResultSuccess();
}
Handle GetCheatProcessHandle() const {
os::NativeHandle GetCheatProcessHandle() const {
return this->cheat_process_debug_handle;
}
Handle HookToCreateApplicationProcess() const {
Handle h = svc::InvalidHandle;
os::NativeHandle HookToCreateApplicationProcess() const {
os::NativeHandle h;
R_ABORT_UNLESS(pm::dmnt::HookToCreateApplicationProcess(&h));
return h;
}
@ -284,7 +284,7 @@ namespace ams::dmnt::cheat::impl {
return this->HasActiveCheatProcess();
}
Handle GetCheatProcessEventHandle() const {
os::NativeHandle GetCheatProcessEventHandle() const {
return this->cheat_process_event.GetReadableHandle();
}
@ -704,7 +704,7 @@ namespace ams::dmnt::cheat::impl {
this_ptr->cheat_lock.Unlock();
this_ptr->unsafe_break_event.Wait();
this_ptr->cheat_lock.Lock();
if (this_ptr->GetCheatProcessHandle() != svc::InvalidHandle) {
if (this_ptr->GetCheatProcessHandle() != os::InvalidNativeHandle) {
continue;
} else {
break;
@ -1193,7 +1193,7 @@ namespace ams::dmnt::cheat::impl {
return GetReference(g_cheat_process_manager).GetHasActiveCheatProcess();
}
Handle GetCheatProcessEventHandle() {
os::NativeHandle GetCheatProcessEventHandle() {
return GetReference(g_cheat_process_manager).GetCheatProcessEventHandle();
}

View file

@ -21,7 +21,7 @@ namespace ams::dmnt::cheat::impl {
void InitializeCheatManager();
bool GetHasActiveCheatProcess();
Handle GetCheatProcessEventHandle();
os::NativeHandle GetCheatProcessEventHandle();
Result GetCheatProcessMetadata(CheatProcessMetadata *out);
Result ForceOpenCheatProcess();
Result PauseCheatProcess();

View file

@ -126,7 +126,7 @@ namespace ams::dmnt::cheat::impl {
}
}
Result ContinueCheatProcess(Handle cheat_dbg_hnd) {
Result ContinueCheatProcess(os::NativeHandle cheat_dbg_hnd) {
/* Loop getting all debug events. */
svc::DebugEventInfo d;
size_t target_core = NumCores - 1;
@ -151,7 +151,7 @@ namespace ams::dmnt::cheat::impl {
util::ConstructAt(g_events_manager);
}
Result ContinueCheatProcess(Handle cheat_dbg_hnd) {
Result ContinueCheatProcess(os::NativeHandle cheat_dbg_hnd) {
return GetReference(g_events_manager).ContinueCheatProcess(cheat_dbg_hnd);
}

View file

@ -20,6 +20,6 @@ namespace ams::dmnt::cheat::impl {
void InitializeDebugEventsManager();
Result ContinueCheatProcess(Handle cheat_dbg_hnd);
Result ContinueCheatProcess(os::NativeHandle cheat_dbg_hnd);
}

View file

@ -24,7 +24,7 @@ namespace ams::fatal::srv {
FatalConfig g_config;
/* Event creator. */
Handle GetFatalDirtyEventReadableHandle() {
os::NativeHandle GetFatalDirtyEventReadableHandle() {
Event evt;
R_ABORT_UNLESS(setsysAcquireFatalDirtyFlagEventHandle(&evt));
return evt.revent;

View file

@ -37,7 +37,7 @@ namespace ams::pm::resource {
/* Globals. */
constinit os::SdkMutex g_resource_limit_lock;
constinit Handle g_resource_limit_handles[ResourceLimitGroup_Count];
constinit os::NativeHandle g_resource_limit_handles[ResourceLimitGroup_Count];
constinit spl::MemoryArrangement g_memory_arrangement = spl::MemoryArrangement_Standard;
constinit u64 g_system_memory_boost_size = 0;
constinit u64 g_extra_application_threads_available = 0;
@ -136,7 +136,7 @@ namespace ams::pm::resource {
}
void WaitResourceAvailable(ResourceLimitGroup group) {
const Handle reslimit_hnd = GetResourceLimitHandle(group);
const auto reslimit_hnd = GetResourceLimitHandle(group);
for (size_t i = 0; i < svc::LimitableResource_Count; i++) {
const auto resource = LimitableResources[i];
@ -336,11 +336,11 @@ namespace ams::pm::resource {
return ResultSuccess();
}
Handle GetResourceLimitHandle(ResourceLimitGroup group) {
os::NativeHandle GetResourceLimitHandle(ResourceLimitGroup group) {
return g_resource_limit_handles[group];
}
Handle GetResourceLimitHandle(const ldr::ProgramInfo *info) {
os::NativeHandle GetResourceLimitHandle(const ldr::ProgramInfo *info) {
return GetResourceLimitHandle(GetResourceLimitGroup(info));
}
@ -358,7 +358,7 @@ namespace ams::pm::resource {
AMS_ABORT_UNLESS(group < ResourceLimitGroup_Count);
AMS_ABORT_UNLESS(resource < svc::LimitableResource_Count);
const Handle reslimit_hnd = GetResourceLimitHandle(group);
const auto reslimit_hnd = GetResourceLimitHandle(group);
R_TRY(svc::GetResourceLimitCurrentValue(out_cur, reslimit_hnd, resource));
R_TRY(svc::GetResourceLimitLimitValue(out_lim, reslimit_hnd, resource));

View file

@ -22,8 +22,10 @@ namespace ams::pm::resource {
Result InitializeResourceManager();
Result BoostSystemMemoryResourceLimit(u64 boost_size);
Result BoostApplicationThreadResourceLimit();
Handle GetResourceLimitHandle(ResourceLimitGroup group);
Handle GetResourceLimitHandle(const ldr::ProgramInfo *info);
os::NativeHandle GetResourceLimitHandle(ResourceLimitGroup group);
os::NativeHandle GetResourceLimitHandle(const ldr::ProgramInfo *info);
void WaitResourceAvailable(const ldr::ProgramInfo *info);
Result GetResourceLimitValues(s64 *out_cur, s64 *out_lim, ResourceLimitGroup group, svc::LimitableResource resource);

View file

@ -43,7 +43,8 @@ namespace ams::pm {
}
Result InformationService::AtmosphereGetProcessInfo(sf::Out<ncm::ProgramLocation> out_loc, sf::Out<cfg::OverrideStatus> out_status, os::ProcessId process_id) {
Handle dummy_handle;
/* NOTE: We don't need to worry about closing this handle, because it's an in-process copy, not a newly allocated handle. */
os::NativeHandle dummy_handle;
return impl::AtmosphereGetProcessInfo(&dummy_handle, out_loc.GetPointer(), out_status.GetPointer(), process_id);
}

View file

@ -53,10 +53,10 @@ namespace ams::sm::impl {
os::ProcessId owner_process_id;
os::ProcessId mitm_process_id;
os::ProcessId mitm_waiting_ack_process_id;
svc::Handle mitm_port_h;
svc::Handle mitm_query_h;
svc::Handle port_h;
svc::Handle mitm_fwd_sess_h;
os::NativeHandle mitm_port_h;
os::NativeHandle mitm_query_h;
os::NativeHandle port_h;
os::NativeHandle mitm_fwd_sess_h;
s32 max_sessions;
bool is_light;
bool mitm_waiting_ack;
@ -67,10 +67,10 @@ namespace ams::sm::impl {
.owner_process_id = os::InvalidProcessId,
.mitm_process_id = os::InvalidProcessId,
.mitm_waiting_ack_process_id = os::InvalidProcessId,
.mitm_port_h = svc::InvalidHandle,
.mitm_query_h = svc::InvalidHandle,
.port_h = svc::InvalidHandle,
.mitm_fwd_sess_h = svc::InvalidHandle,
.mitm_port_h = os::InvalidNativeHandle,
.mitm_query_h = os::InvalidNativeHandle,
.port_h = os::InvalidNativeHandle,
.mitm_fwd_sess_h = os::InvalidNativeHandle,
.max_sessions = 0,
.is_light = false,
.mitm_waiting_ack = false,
@ -361,7 +361,7 @@ namespace ams::sm::impl {
program_id == ncm::SystemProgramId::Creport;
}
Result GetMitmServiceHandleImpl(svc::Handle *out, ServiceInfo *service_info, const MitmProcessInfo &client_info) {
Result GetMitmServiceHandleImpl(os::NativeHandle *out, ServiceInfo *service_info, const MitmProcessInfo &client_info) {
/* Send command to query if we should mitm. */
bool should_mitm;
{
@ -376,15 +376,15 @@ namespace ams::sm::impl {
/* Create both handles. */
{
/* Get the forward handle. */
svc::Handle fwd_hnd;
os::NativeHandle fwd_hnd;
R_TRY(svc::ConnectToPort(std::addressof(fwd_hnd), service_info->port_h));
/* Ensure that the forward handle is closed, if we fail to get the mitm handle. */
auto fwd_guard = SCOPE_GUARD { R_ABORT_UNLESS(svc::CloseHandle(fwd_hnd)); };
auto fwd_guard = SCOPE_GUARD { os::CloseNativeHandle(fwd_hnd); };
/* Get the mitm handle. */
/* This should be guaranteed to succeed, since we got a forward handle. */
svc::Handle hnd;
os::NativeHandle hnd;
R_ABORT_UNLESS(svc::ConnectToPort(std::addressof(hnd), service_info->mitm_port_h));
/* We got both handles, so we no longer need to clean up the forward handle. */
@ -401,9 +401,9 @@ namespace ams::sm::impl {
return ResultSuccess();
}
Result GetServiceHandleImpl(svc::Handle *out, ServiceInfo *service_info, os::ProcessId process_id) {
Result GetServiceHandleImpl(os::NativeHandle *out, ServiceInfo *service_info, os::ProcessId process_id) {
/* Clear handle output. */
*out = svc::InvalidHandle;
*out = os::InvalidNativeHandle;
/* Check if we should return a mitm handle. */
if (IsValidProcessId(service_info->mitm_process_id) && service_info->mitm_process_id != process_id) {
@ -420,7 +420,7 @@ namespace ams::sm::impl {
return svc::ConnectToPort(out, service_info->port_h);
}
Result RegisterServiceImpl(svc::Handle *out, os::ProcessId process_id, ServiceName service, size_t max_sessions, bool is_light) {
Result RegisterServiceImpl(os::NativeHandle *out, os::ProcessId process_id, ServiceName service, size_t max_sessions, bool is_light) {
/* Validate service name. */
R_TRY(ValidateServiceName(service));
@ -432,8 +432,8 @@ namespace ams::sm::impl {
R_UNLESS(free_service != nullptr, sm::ResultOutOfServices());
/* Create the new service. */
*out = svc::InvalidHandle;
svc::Handle server_hnd = svc::InvalidHandle;
*out = os::InvalidNativeHandle;
os::NativeHandle server_hnd = os::InvalidNativeHandle;
R_TRY(svc::CreatePort(out, std::addressof(server_hnd), max_sessions, is_light, reinterpret_cast<uintptr_t>(free_service->name.name)));
/* Save info. */
@ -451,10 +451,10 @@ namespace ams::sm::impl {
void UnregisterServiceImpl(ServiceInfo *service_info) {
/* Close all valid handles. */
if (service_info->port_h != svc::InvalidHandle) { R_ABORT_UNLESS(svc::CloseHandle(service_info->port_h)); }
if (service_info->mitm_port_h != svc::InvalidHandle) { R_ABORT_UNLESS(svc::CloseHandle(service_info->mitm_port_h)); }
if (service_info->mitm_query_h != svc::InvalidHandle) { R_ABORT_UNLESS(svc::CloseHandle(service_info->mitm_query_h)); }
if (service_info->mitm_fwd_sess_h != svc::InvalidHandle) { R_ABORT_UNLESS(svc::CloseHandle(service_info->mitm_fwd_sess_h)); }
os::CloseNativeHandle(service_info->port_h);
os::CloseNativeHandle(service_info->mitm_port_h);
os::CloseNativeHandle(service_info->mitm_query_h);
os::CloseNativeHandle(service_info->mitm_fwd_sess_h);
/* Reset the info's state. */
*service_info = InvalidServiceInfo;
@ -547,7 +547,7 @@ namespace ams::sm::impl {
return StartRegisterRetry(service);
}
Result GetServiceHandle(svc::Handle *out, os::ProcessId process_id, ServiceName service) {
Result GetServiceHandle(os::NativeHandle *out, os::ProcessId process_id, ServiceName service) {
/* Acquire exclusive access to global state. */
std::scoped_lock lk(g_mutex);
@ -583,7 +583,7 @@ namespace ams::sm::impl {
return ResultSuccess();
}
Result RegisterService(svc::Handle *out, os::ProcessId process_id, ServiceName service, size_t max_sessions, bool is_light) {
Result RegisterService(os::NativeHandle *out, os::ProcessId process_id, ServiceName service, size_t max_sessions, bool is_light) {
/* Acquire exclusive access to global state. */
std::scoped_lock lk(g_mutex);
@ -604,7 +604,7 @@ namespace ams::sm::impl {
return RegisterServiceImpl(out, process_id, service, max_sessions, is_light);
}
Result RegisterServiceForSelf(svc::Handle *out, ServiceName service, size_t max_sessions) {
Result RegisterServiceForSelf(os::NativeHandle *out, ServiceName service, size_t max_sessions) {
/* Acquire exclusive access to global state. */
std::scoped_lock lk(g_mutex);
@ -665,7 +665,7 @@ namespace ams::sm::impl {
return StartRegisterRetry(service);
}
Result InstallMitm(svc::Handle *out, svc::Handle *out_query, os::ProcessId process_id, ServiceName service) {
Result InstallMitm(os::NativeHandle *out, os::NativeHandle *out_query, os::ProcessId process_id, ServiceName service) {
/* Acquire exclusive access to global state. */
std::scoped_lock lk(g_mutex);
@ -689,8 +689,8 @@ namespace ams::sm::impl {
R_UNLESS(!IsValidProcessId(service_info->mitm_process_id), sm::ResultAlreadyRegistered());
/* Always clear output. */
*out = svc::InvalidHandle;
*out_query = svc::InvalidHandle;
*out = os::InvalidNativeHandle;
*out_query = os::InvalidNativeHandle;
/* If we don't have a future mitm declaration, add one. */
/* Client will clear this when ready to process. */
@ -704,14 +704,14 @@ namespace ams::sm::impl {
/* Create mitm handles. */
{
/* Get the port handles. */
svc::Handle hnd, port_hnd;
os::NativeHandle hnd, port_hnd;
R_TRY(svc::CreatePort(std::addressof(hnd), std::addressof(port_hnd), service_info->max_sessions, service_info->is_light, reinterpret_cast<uintptr_t>(service_info->name.name)));
/* Ensure that we clean up the port handles, if something goes wrong creating the query sessions. */
auto port_guard = SCOPE_GUARD { R_ABORT_UNLESS(svc::CloseHandle(hnd)); R_ABORT_UNLESS(svc::CloseHandle(port_hnd)); };
auto port_guard = SCOPE_GUARD { os::CloseNativeHandle(hnd); os::CloseNativeHandle(port_hnd); };
/* Create the session for our query service. */
svc::Handle qry_hnd, mitm_qry_hnd;
os::NativeHandle qry_hnd, mitm_qry_hnd;
R_TRY(svc::CreateSession(std::addressof(qry_hnd), std::addressof(mitm_qry_hnd), false, 0));
/* We created the query service session, so we no longer need to clean up the port handles. */
@ -755,12 +755,12 @@ namespace ams::sm::impl {
/* Uninstall the mitm. */
{
/* Close mitm handles. */
R_ABORT_UNLESS(svc::CloseHandle(service_info->mitm_port_h));
R_ABORT_UNLESS(svc::CloseHandle(service_info->mitm_query_h));
os::CloseNativeHandle(service_info->mitm_port_h);
os::CloseNativeHandle(service_info->mitm_query_h);
/* Reset mitm members. */
service_info->mitm_port_h = svc::InvalidHandle;
service_info->mitm_query_h = svc::InvalidHandle;
service_info->mitm_port_h = os::InvalidNativeHandle;
service_info->mitm_query_h = os::InvalidNativeHandle;
service_info->mitm_process_id = os::InvalidProcessId;
}
@ -824,7 +824,7 @@ namespace ams::sm::impl {
return ResultSuccess();
}
Result AcknowledgeMitmSession(MitmProcessInfo *out_info, svc::Handle *out_hnd, os::ProcessId process_id, ServiceName service) {
Result AcknowledgeMitmSession(MitmProcessInfo *out_info, os::NativeHandle *out_hnd, os::ProcessId process_id, ServiceName service) {
/* Acquire exclusive access to global state. */
std::scoped_lock lk(g_mutex);
@ -852,7 +852,7 @@ namespace ams::sm::impl {
/* Set the output handle. */
*out_hnd = service_info->mitm_fwd_sess_h;
service_info->mitm_fwd_sess_h = svc::InvalidHandle;
service_info->mitm_fwd_sess_h = os::InvalidNativeHandle;
/* Clear acknowledgement-related fields. */
service_info->mitm_waiting_ack = false;

View file

@ -29,19 +29,19 @@ namespace ams::sm::impl {
/* Service management. */
Result HasService(bool *out, ServiceName service);
Result WaitService(ServiceName service);
Result GetServiceHandle(svc::Handle *out, os::ProcessId process_id, ServiceName service);
Result RegisterService(svc::Handle *out, os::ProcessId process_id, ServiceName service, size_t max_sessions, bool is_light);
Result RegisterServiceForSelf(svc::Handle *out, ServiceName service, size_t max_sessions);
Result GetServiceHandle(os::NativeHandle *out, os::ProcessId process_id, ServiceName service);
Result RegisterService(os::NativeHandle *out, os::ProcessId process_id, ServiceName service, size_t max_sessions, bool is_light);
Result RegisterServiceForSelf(os::NativeHandle *out, ServiceName service, size_t max_sessions);
Result UnregisterService(os::ProcessId process_id, ServiceName service);
/* Mitm extensions. */
Result HasMitm(bool *out, ServiceName service);
Result WaitMitm(ServiceName service);
Result InstallMitm(svc::Handle *out, svc::Handle *out_query, os::ProcessId process_id, ServiceName service);
Result InstallMitm(os::NativeHandle *out, os::NativeHandle *out_query, os::ProcessId process_id, ServiceName service);
Result UninstallMitm(os::ProcessId process_id, ServiceName service);
Result DeclareFutureMitm(os::ProcessId process_id, ServiceName service);
Result ClearFutureMitm(os::ProcessId process_id, ServiceName service);
Result AcknowledgeMitmSession(MitmProcessInfo *out_info, svc::Handle *out_hnd, os::ProcessId process_id, ServiceName service);
Result AcknowledgeMitmSession(MitmProcessInfo *out_info, os::NativeHandle *out_hnd, os::ProcessId process_id, ServiceName service);
/* Deferral extension (works around FS bug). */
Result EndInitialDefers();

View file

@ -143,7 +143,7 @@ namespace ams::sm {
g_server_manager.Initialize();
/* Create the handles for our ports. */
svc::Handle user_port_handle = svc::InvalidHandle, manager_port_handle = svc::InvalidHandle;
os::NativeHandle user_port_handle, manager_port_handle;
{
/* Create the user port handle. */
R_ABORT_UNLESS(svc::ManageNamedPort(std::addressof(user_port_handle), "sm:", MaxSessionsUser));

View file

@ -222,13 +222,13 @@ namespace ams::spl::impl {
class DeviceAddressSpaceMapHelper {
private:
Handle das_hnd;
os::NativeHandle das_hnd;
u64 dst_addr;
u64 src_addr;
size_t size;
svc::MemoryPermission perm;
public:
DeviceAddressSpaceMapHelper(Handle h, u64 dst, u64 src, size_t sz, svc::MemoryPermission p) : das_hnd(h), dst_addr(dst), src_addr(src), size(sz), perm(p) {
DeviceAddressSpaceMapHelper(os::NativeHandle h, u64 dst, u64 src, size_t sz, svc::MemoryPermission p) : das_hnd(h), dst_addr(dst), src_addr(src), size(sz), perm(p) {
R_ABORT_UNLESS(svc::MapDeviceAddressSpaceAligned(this->das_hnd, dd::GetCurrentProcessHandle(), this->src_addr, this->size, this->dst_addr, this->perm));
}
~DeviceAddressSpaceMapHelper() {
@ -241,7 +241,7 @@ namespace ams::spl::impl {
constinit os::InterruptEventType g_se_event;
constinit os::SystemEventType g_se_keyslot_available_event;
constinit Handle g_se_das_hnd;
constinit os::NativeHandle g_se_das_hnd = os::InvalidNativeHandle;
constinit u32 g_se_mapped_work_buffer_addr;
alignas(os::MemoryPageSize) constinit u8 g_work_buffer[2 * WorkBufferSizeMax];
@ -937,7 +937,7 @@ namespace ams::spl::impl {
return ResultSuccess();
}
Handle GetAesKeySlotAvailableEventHandle() {
os::NativeHandle GetAesKeySlotAvailableEventHandle() {
return os::GetReadableHandleOfSystemEvent(std::addressof(g_se_keyslot_available_event));
}

View file

@ -68,6 +68,6 @@ namespace ams::spl::impl {
/* Helper. */
Result DeallocateAllAesKeySlots(const void *owner);
Handle GetAesKeySlotAvailableEventHandle();
os::NativeHandle GetAesKeySlotAvailableEventHandle();
}