mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-27 21:24:11 -04:00
os: remove ManagedHandle, refactor to use NativeHandle typename
This commit is contained in:
parent
a774833790
commit
6f76066d24
71 changed files with 473 additions and 397 deletions
|
@ -22,7 +22,7 @@ namespace ams::fssystem {
|
|||
constexpr inline size_t MaxExternalCodeFileSystem = 0x10;
|
||||
|
||||
util::BoundedMap<ncm::ProgramId, fs::RemoteFileSystem, MaxExternalCodeFileSystem> g_ecs_map;
|
||||
util::BoundedMap<ncm::ProgramId, os::ManagedHandle, MaxExternalCodeFileSystem> g_hnd_map;
|
||||
util::BoundedMap<ncm::ProgramId, os::NativeHandle, MaxExternalCodeFileSystem> g_hnd_map;
|
||||
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ namespace ams::fssystem {
|
|||
if (auto *hnd = g_hnd_map.Find(program_id); hnd != nullptr) {
|
||||
/* Create a service using libnx bindings. */
|
||||
Service srv;
|
||||
serviceCreate(std::addressof(srv), hnd->Move());
|
||||
serviceCreate(std::addressof(srv), *hnd);
|
||||
g_hnd_map.Remove(program_id);
|
||||
|
||||
/* Create a remote filesystem. */
|
||||
|
@ -66,7 +66,11 @@ namespace ams::fssystem {
|
|||
|
||||
void DestroyExternalCode(ncm::ProgramId program_id) {
|
||||
g_ecs_map.Remove(program_id);
|
||||
g_hnd_map.Remove(program_id);
|
||||
|
||||
if (auto *hnd = g_hnd_map.Find(program_id); hnd != nullptr) {
|
||||
os::CloseNativeHandle(*hnd);
|
||||
g_hnd_map.Remove(program_id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace ams::os::impl {
|
|||
|
||||
namespace {
|
||||
|
||||
inline void SetupInterProcessEventType(InterProcessEventType *event, Handle read_handle, bool read_handle_managed, Handle write_handle, bool write_handle_managed, EventClearMode clear_mode) {
|
||||
inline void SetupInterProcessEventType(InterProcessEventType *event, NativeHandle read_handle, bool read_handle_managed, NativeHandle write_handle, bool write_handle_managed, EventClearMode clear_mode) {
|
||||
/* Set handles. */
|
||||
event->readable_handle = read_handle;
|
||||
event->is_readable_handle_managed = read_handle_managed;
|
||||
|
@ -42,7 +42,7 @@ namespace ams::os::impl {
|
|||
}
|
||||
|
||||
Result CreateInterProcessEvent(InterProcessEventType *event, EventClearMode clear_mode) {
|
||||
Handle rh, wh;
|
||||
NativeHandle rh, wh;
|
||||
R_TRY(impl::InterProcessEventImpl::Create(std::addressof(wh), std::addressof(rh)));
|
||||
|
||||
SetupInterProcessEventType(event, rh, true, wh, true, clear_mode);
|
||||
|
@ -57,14 +57,14 @@ namespace ams::os::impl {
|
|||
|
||||
/* Close handles if required. */
|
||||
if (event->is_readable_handle_managed) {
|
||||
if (event->readable_handle != svc::InvalidHandle) {
|
||||
if (event->readable_handle != os::InvalidNativeHandle) {
|
||||
impl::InterProcessEventImpl::Close(event->readable_handle);
|
||||
}
|
||||
event->is_readable_handle_managed = false;
|
||||
}
|
||||
|
||||
if (event->is_writable_handle_managed) {
|
||||
if (event->writable_handle != svc::InvalidHandle) {
|
||||
if (event->writable_handle != os::InvalidNativeHandle) {
|
||||
impl::InterProcessEventImpl::Close(event->writable_handle);
|
||||
}
|
||||
event->is_writable_handle_managed = false;
|
||||
|
@ -74,28 +74,29 @@ namespace ams::os::impl {
|
|||
util::DestroyAt(event->multi_wait_object_list_storage);
|
||||
}
|
||||
|
||||
void AttachInterProcessEvent(InterProcessEventType *event, Handle read_handle, bool read_handle_managed, Handle write_handle, bool write_handle_managed, EventClearMode clear_mode) {
|
||||
AMS_ASSERT(read_handle != svc::InvalidHandle || write_handle != svc::InvalidHandle);
|
||||
void AttachInterProcessEvent(InterProcessEventType *event, NativeHandle read_handle, bool read_handle_managed, NativeHandle write_handle, bool write_handle_managed, EventClearMode clear_mode) {
|
||||
AMS_ASSERT(read_handle != os::InvalidNativeHandle || write_handle != os::InvalidNativeHandle);
|
||||
|
||||
return SetupInterProcessEventType(event, read_handle, read_handle_managed, write_handle, write_handle_managed, clear_mode);
|
||||
}
|
||||
|
||||
Handle DetachReadableHandleOfInterProcessEvent(InterProcessEventType *event) {
|
||||
NativeHandle DetachReadableHandleOfInterProcessEvent(InterProcessEventType *event) {
|
||||
AMS_ASSERT(event->state == InterProcessEventType::State_Initialized);
|
||||
|
||||
const Handle handle = event->readable_handle;
|
||||
const NativeHandle handle = event->readable_handle;
|
||||
|
||||
event->readable_handle = svc::InvalidHandle;
|
||||
event->readable_handle = os::InvalidNativeHandle;
|
||||
event->is_readable_handle_managed = false;
|
||||
|
||||
return handle;
|
||||
}
|
||||
Handle DetachWritableHandleOfInterProcessEvent(InterProcessEventType *event) {
|
||||
|
||||
NativeHandle DetachWritableHandleOfInterProcessEvent(InterProcessEventType *event) {
|
||||
AMS_ASSERT(event->state == InterProcessEventType::State_Initialized);
|
||||
|
||||
const Handle handle = event->writable_handle;
|
||||
const NativeHandle handle = event->writable_handle;
|
||||
|
||||
event->writable_handle = svc::InvalidHandle;
|
||||
event->writable_handle = os::InvalidNativeHandle;
|
||||
event->is_writable_handle_managed = false;
|
||||
|
||||
return handle;
|
||||
|
@ -130,19 +131,19 @@ namespace ams::os::impl {
|
|||
AMS_ASSERT(event->state != InterProcessEventType::State_NotInitialized);
|
||||
|
||||
auto handle = event->readable_handle;
|
||||
if (handle == svc::InvalidHandle) {
|
||||
if (handle == os::InvalidNativeHandle) {
|
||||
handle = event->writable_handle;
|
||||
}
|
||||
return impl::InterProcessEventImpl::Clear(handle);
|
||||
}
|
||||
|
||||
Handle GetReadableHandleOfInterProcessEvent(const InterProcessEventType *event) {
|
||||
NativeHandle GetReadableHandleOfInterProcessEvent(const InterProcessEventType *event) {
|
||||
AMS_ASSERT(event->state != InterProcessEventType::State_NotInitialized);
|
||||
|
||||
return event->readable_handle;
|
||||
}
|
||||
|
||||
Handle GetWritableHandleOfInterProcessEvent(const InterProcessEventType *event) {
|
||||
NativeHandle GetWritableHandleOfInterProcessEvent(const InterProcessEventType *event) {
|
||||
AMS_ASSERT(event->state != InterProcessEventType::State_NotInitialized);
|
||||
|
||||
return event->writable_handle;
|
||||
|
|
|
@ -21,10 +21,10 @@ namespace ams::os::impl {
|
|||
Result CreateInterProcessEvent(InterProcessEventType *event, EventClearMode clear_mode);
|
||||
void DestroyInterProcessEvent(InterProcessEventType *event);
|
||||
|
||||
void AttachInterProcessEvent(InterProcessEventType *event, Handle read_handle, bool read_handle_managed, Handle write_handle, bool write_handle_managed, EventClearMode clear_mode);
|
||||
void AttachInterProcessEvent(InterProcessEventType *event, NativeHandle read_handle, bool read_handle_managed, NativeHandle write_handle, bool write_handle_managed, EventClearMode clear_mode);
|
||||
|
||||
Handle DetachReadableHandleOfInterProcessEvent(InterProcessEventType *event);
|
||||
Handle DetachWritableHandleOfInterProcessEvent(InterProcessEventType *event);
|
||||
NativeHandle DetachReadableHandleOfInterProcessEvent(InterProcessEventType *event);
|
||||
NativeHandle DetachWritableHandleOfInterProcessEvent(InterProcessEventType *event);
|
||||
|
||||
void WaitInterProcessEvent(InterProcessEventType *event);
|
||||
bool TryWaitInterProcessEvent(InterProcessEventType *event);
|
||||
|
@ -33,8 +33,8 @@ namespace ams::os::impl {
|
|||
void SignalInterProcessEvent(InterProcessEventType *event);
|
||||
void ClearInterProcessEvent(InterProcessEventType *event);
|
||||
|
||||
Handle GetReadableHandleOfInterProcessEvent(const InterProcessEventType *event);
|
||||
Handle GetWritableHandleOfInterProcessEvent(const InterProcessEventType *event);
|
||||
NativeHandle GetReadableHandleOfInterProcessEvent(const InterProcessEventType *event);
|
||||
NativeHandle GetWritableHandleOfInterProcessEvent(const InterProcessEventType *event);
|
||||
|
||||
void InitializeMultiWaitHolder(MultiWaitHolderType *multi_wait_holder, InterProcessEventType *event);
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
namespace ams::os::impl {
|
||||
|
||||
Result InterProcessEventImpl::Create(Handle *out_write, Handle *out_read) {
|
||||
Result InterProcessEventImpl::Create(NativeHandle *out_write, NativeHandle *out_read) {
|
||||
/* Create the event handles. */
|
||||
svc::Handle wh, rh;
|
||||
R_TRY_CATCH(svc::CreateEvent(std::addressof(wh), std::addressof(rh))) {
|
||||
|
@ -32,29 +32,29 @@ namespace ams::os::impl {
|
|||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void InterProcessEventImpl::Close(Handle handle) {
|
||||
if (handle != svc::InvalidHandle) {
|
||||
R_ABORT_UNLESS(svc::CloseHandle(svc::Handle(handle)));
|
||||
void InterProcessEventImpl::Close(NativeHandle handle) {
|
||||
if (handle != os::InvalidNativeHandle) {
|
||||
R_ABORT_UNLESS(svc::CloseHandle(handle));
|
||||
}
|
||||
}
|
||||
|
||||
void InterProcessEventImpl::Signal(Handle handle) {
|
||||
R_ABORT_UNLESS(svc::SignalEvent(svc::Handle(handle)));
|
||||
void InterProcessEventImpl::Signal(NativeHandle handle) {
|
||||
R_ABORT_UNLESS(svc::SignalEvent(handle));
|
||||
}
|
||||
|
||||
void InterProcessEventImpl::Clear(Handle handle) {
|
||||
R_ABORT_UNLESS(svc::ClearEvent(svc::Handle(handle)));
|
||||
void InterProcessEventImpl::Clear(NativeHandle handle) {
|
||||
R_ABORT_UNLESS(svc::ClearEvent(handle));
|
||||
}
|
||||
|
||||
void InterProcessEventImpl::Wait(Handle handle, bool auto_clear) {
|
||||
void InterProcessEventImpl::Wait(NativeHandle handle, bool auto_clear) {
|
||||
while (true) {
|
||||
/* Continuously wait, until success. */
|
||||
s32 index;
|
||||
Result res = svc::WaitSynchronization(std::addressof(index), reinterpret_cast<svc::Handle *>(std::addressof(handle)), 1, svc::WaitInfinite);
|
||||
Result res = svc::WaitSynchronization(std::addressof(index), static_cast<svc::Handle *>(std::addressof(handle)), 1, svc::WaitInfinite);
|
||||
if (R_SUCCEEDED(res)) {
|
||||
/* Clear, if we must. */
|
||||
if (auto_clear) {
|
||||
R_TRY_CATCH(svc::ResetSignal(svc::Handle(handle))) {
|
||||
R_TRY_CATCH(svc::ResetSignal(handle)) {
|
||||
/* Some other thread might have caught this before we did. */
|
||||
R_CATCH(svc::ResultInvalidState) { continue; }
|
||||
} R_END_TRY_CATCH_WITH_ABORT_UNLESS;
|
||||
|
@ -67,17 +67,17 @@ namespace ams::os::impl {
|
|||
}
|
||||
}
|
||||
|
||||
bool InterProcessEventImpl::TryWait(Handle handle, bool auto_clear) {
|
||||
bool InterProcessEventImpl::TryWait(NativeHandle handle, bool auto_clear) {
|
||||
/* If we're auto clear, just try to reset. */
|
||||
if (auto_clear) {
|
||||
return R_SUCCEEDED(svc::ResetSignal(svc::Handle(handle)));
|
||||
return R_SUCCEEDED(svc::ResetSignal(handle));
|
||||
}
|
||||
|
||||
/* Not auto-clear. */
|
||||
while (true) {
|
||||
/* Continuously wait, until success or timeout. */
|
||||
s32 index;
|
||||
Result res = svc::WaitSynchronization(std::addressof(index), reinterpret_cast<svc::Handle *>(std::addressof(handle)), 1, 0);
|
||||
Result res = svc::WaitSynchronization(std::addressof(index), static_cast<svc::Handle *>(std::addressof(handle)), 1, 0);
|
||||
|
||||
/* If we succeeded, we're signaled. */
|
||||
if (R_SUCCEEDED(res)) {
|
||||
|
@ -93,17 +93,17 @@ namespace ams::os::impl {
|
|||
}
|
||||
}
|
||||
|
||||
bool InterProcessEventImpl::TimedWait(Handle handle, bool auto_clear, TimeSpan timeout) {
|
||||
bool InterProcessEventImpl::TimedWait(NativeHandle handle, bool auto_clear, TimeSpan timeout) {
|
||||
TimeoutHelper timeout_helper(timeout);
|
||||
|
||||
while (true) {
|
||||
/* Continuously wait, until success. */
|
||||
s32 index;
|
||||
Result res = svc::WaitSynchronization(std::addressof(index), reinterpret_cast<svc::Handle *>(std::addressof(handle)), 1, timeout_helper.GetTimeLeftOnTarget().GetNanoSeconds());
|
||||
Result res = svc::WaitSynchronization(std::addressof(index), static_cast<svc::Handle *>(std::addressof(handle)), 1, timeout_helper.GetTimeLeftOnTarget().GetNanoSeconds());
|
||||
if (R_SUCCEEDED(res)) {
|
||||
/* Clear, if we must. */
|
||||
if (auto_clear) {
|
||||
R_TRY_CATCH(svc::ResetSignal(svc::Handle(handle))) {
|
||||
R_TRY_CATCH(svc::ResetSignal(handle)) {
|
||||
/* Some other thread might have caught this before we did. */
|
||||
R_CATCH(svc::ResultInvalidState) { continue; }
|
||||
} R_END_TRY_CATCH_WITH_ABORT_UNLESS;
|
||||
|
|
|
@ -20,13 +20,13 @@ namespace ams::os::impl {
|
|||
|
||||
class InterProcessEventImpl {
|
||||
public:
|
||||
static Result Create(Handle *out_write, Handle *out_read);
|
||||
static void Close(Handle handle);
|
||||
static void Signal(Handle handle);
|
||||
static void Clear(Handle handle);
|
||||
static void Wait(Handle handle, bool auto_clear);
|
||||
static bool TryWait(Handle handle, bool auto_clear);
|
||||
static bool TimedWait(Handle handle, bool auto_clear, TimeSpan timeout);
|
||||
static Result Create(NativeHandle *out_write, NativeHandle *out_read);
|
||||
static void Close(NativeHandle handle);
|
||||
static void Signal(NativeHandle handle);
|
||||
static void Clear(NativeHandle handle);
|
||||
static void Wait(NativeHandle handle, bool auto_clear);
|
||||
static bool TryWait(NativeHandle handle, bool auto_clear);
|
||||
static bool TimedWait(NativeHandle handle, bool auto_clear, TimeSpan timeout);
|
||||
};
|
||||
|
||||
}
|
|
@ -50,7 +50,7 @@ namespace ams::os::impl {
|
|||
return this->impl.IsSignaled();
|
||||
}
|
||||
|
||||
Handle GetHandle() const {
|
||||
NativeHandle GetHandle() const {
|
||||
return this->impl.GetHandle();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace ams::os::impl {
|
|||
return TriBool::Undefined;
|
||||
}
|
||||
|
||||
Handle GetHandle() const {
|
||||
NativeHandle GetHandle() const {
|
||||
return this->handle;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -20,10 +20,10 @@ namespace ams::os::impl {
|
|||
|
||||
class IoRegionImpl {
|
||||
public:
|
||||
static Result CreateIoRegion(Handle *out, Handle io_pool_handle, uintptr_t address, size_t size, MemoryMapping mapping, MemoryPermission permission);
|
||||
static Result CreateIoRegion(NativeHandle *out, NativeHandle io_pool_handle, uintptr_t address, size_t size, MemoryMapping mapping, MemoryPermission permission);
|
||||
|
||||
static Result MapIoRegion(void **out, Handle handle, size_t size, MemoryPermission perm);
|
||||
static void UnmapIoRegion(Handle handle, void *address, size_t size);
|
||||
static Result MapIoRegion(void **out, NativeHandle handle, size_t size, MemoryPermission perm);
|
||||
static void UnmapIoRegion(NativeHandle handle, void *address, size_t size);
|
||||
};
|
||||
|
||||
}
|
|
@ -39,7 +39,7 @@ namespace ams::os::impl {
|
|||
|
||||
}
|
||||
|
||||
Result IoRegionImpl::CreateIoRegion(Handle *out, Handle io_pool_handle, uintptr_t address, size_t size, MemoryMapping mapping, MemoryPermission permission) {
|
||||
Result IoRegionImpl::CreateIoRegion(NativeHandle *out, NativeHandle io_pool_handle, uintptr_t address, size_t size, MemoryMapping mapping, MemoryPermission permission) {
|
||||
/* Convert mapping/permission. */
|
||||
const auto svc_mapping = ConvertToSvcMemoryMapping(mapping);
|
||||
const auto svc_perm = ConvertToSvcMemoryPermission(permission);
|
||||
|
@ -53,7 +53,7 @@ namespace ams::os::impl {
|
|||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result IoRegionImpl::MapIoRegion(void **out, Handle handle, size_t size, MemoryPermission perm) {
|
||||
Result IoRegionImpl::MapIoRegion(void **out, NativeHandle handle, size_t size, MemoryPermission perm) {
|
||||
/* Convert permission. */
|
||||
const auto svc_perm = ConvertToSvcMemoryPermission(perm);
|
||||
|
||||
|
@ -81,7 +81,7 @@ namespace ams::os::impl {
|
|||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void IoRegionImpl::UnmapIoRegion(Handle handle, void *address, size_t size) {
|
||||
void IoRegionImpl::UnmapIoRegion(NativeHandle handle, void *address, size_t size) {
|
||||
R_ABORT_UNLESS(svc::UnmapIoRegion(handle, reinterpret_cast<uintptr_t>(address), size));
|
||||
}
|
||||
|
||||
|
|
|
@ -34,8 +34,8 @@ namespace ams::os::impl {
|
|||
virtual TriBool LinkToObjectList() = 0;
|
||||
/* Removes from the multi wait's object list. */
|
||||
virtual void UnlinkFromObjectList() = 0;
|
||||
/* Gets handle to output, returns INVALID_HANDLE on failure. */
|
||||
virtual Handle GetHandle() const = 0;
|
||||
/* Gets handle to output, returns os::InvalidNativeHandle on failure. */
|
||||
virtual NativeHandle GetHandle() const = 0;
|
||||
/* Gets the amount of time remaining until this wakes up. */
|
||||
virtual TimeSpan GetAbsoluteWakeupTime() const {
|
||||
return TimeSpan::FromNanoSeconds(std::numeric_limits<s64>::max());
|
||||
|
@ -58,8 +58,8 @@ namespace ams::os::impl {
|
|||
class MultiWaitHolderOfUserObject : public MultiWaitHolderBase {
|
||||
public:
|
||||
/* All user objects have no handle to wait on. */
|
||||
virtual Handle GetHandle() const override final {
|
||||
return svc::InvalidHandle;
|
||||
virtual NativeHandle GetHandle() const override final {
|
||||
return os::InvalidNativeHandle;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -20,16 +20,16 @@ namespace ams::os::impl {
|
|||
|
||||
class MultiWaitHolderOfHandle : public MultiWaitHolderOfKernelObject {
|
||||
private:
|
||||
Handle handle;
|
||||
NativeHandle handle;
|
||||
public:
|
||||
explicit MultiWaitHolderOfHandle(Handle h) : handle(h) { /* ... */ }
|
||||
explicit MultiWaitHolderOfHandle(NativeHandle h) : handle(h) { /* ... */ }
|
||||
|
||||
/* IsSignaled, GetHandle both implemented. */
|
||||
virtual TriBool IsSignaled() const override {
|
||||
return TriBool::Undefined;
|
||||
}
|
||||
|
||||
virtual Handle GetHandle() const override {
|
||||
virtual NativeHandle GetHandle() const override {
|
||||
return this->handle;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace ams::os::impl {
|
|||
return TriBool::Undefined;
|
||||
}
|
||||
|
||||
virtual Handle GetHandle() const override {
|
||||
virtual NativeHandle GetHandle() const override {
|
||||
return this->event->readable_handle;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
namespace ams::os::impl {
|
||||
|
||||
Handle MultiWaitHolderOfInterruptEvent::GetHandle() const {
|
||||
NativeHandle MultiWaitHolderOfInterruptEvent::GetHandle() const {
|
||||
return GetReference(event->impl).GetHandle();
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace ams::os::impl {
|
|||
return TriBool::Undefined;
|
||||
}
|
||||
|
||||
virtual Handle GetHandle() const override;
|
||||
virtual NativeHandle GetHandle() const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
namespace ams::os::impl {
|
||||
|
||||
Result MultiWaitImpl::WaitAnyImpl(MultiWaitHolderBase **out, bool infinite, TimeSpan timeout, bool reply, Handle reply_target) {
|
||||
Result MultiWaitImpl::WaitAnyImpl(MultiWaitHolderBase **out, bool infinite, TimeSpan timeout, bool reply, NativeHandle reply_target) {
|
||||
/* Prepare for processing. */
|
||||
this->signaled_holder = nullptr;
|
||||
this->target_impl.SetCurrentThreadHandleForCancelWait();
|
||||
|
@ -37,7 +37,7 @@ namespace ams::os::impl {
|
|||
/* Process object array. */
|
||||
Result wait_result = ResultSuccess();
|
||||
if (holder != nullptr) {
|
||||
if (reply && reply_target != svc::InvalidHandle) {
|
||||
if (reply && reply_target != os::InvalidNativeHandle) {
|
||||
s32 index;
|
||||
wait_result = this->target_impl.TimedReplyAndReceive(std::addressof(index), nullptr, 0, 0, reply_target, TimeSpan::FromNanoSeconds(0));
|
||||
if (R_FAILED(wait_result)) {
|
||||
|
@ -59,8 +59,8 @@ namespace ams::os::impl {
|
|||
return wait_result;
|
||||
}
|
||||
|
||||
Result MultiWaitImpl::WaitAnyHandleImpl(MultiWaitHolderBase **out, bool infinite, TimeSpan timeout, bool reply, Handle reply_target) {
|
||||
Handle object_handles[MaximumHandleCount];
|
||||
Result MultiWaitImpl::WaitAnyHandleImpl(MultiWaitHolderBase **out, bool infinite, TimeSpan timeout, bool reply, NativeHandle reply_target) {
|
||||
NativeHandle object_handles[MaximumHandleCount];
|
||||
MultiWaitHolderBase *objects[MaximumHandleCount];
|
||||
|
||||
const s32 count = this->BuildHandleArray(object_handles, objects, MaximumHandleCount);
|
||||
|
@ -132,15 +132,15 @@ namespace ams::os::impl {
|
|||
break;
|
||||
}
|
||||
|
||||
reply_target = svc::InvalidHandle;
|
||||
reply_target = os::InvalidNativeHandle;
|
||||
}
|
||||
}
|
||||
|
||||
s32 MultiWaitImpl::BuildHandleArray(Handle out_handles[], MultiWaitHolderBase *out_objects[], s32 num) {
|
||||
s32 MultiWaitImpl::BuildHandleArray(NativeHandle out_handles[], MultiWaitHolderBase *out_objects[], s32 num) {
|
||||
s32 count = 0;
|
||||
|
||||
for (MultiWaitHolderBase &holder_base : this->multi_wait_list) {
|
||||
if (Handle handle = holder_base.GetHandle(); handle != svc::InvalidHandle) {
|
||||
if (auto handle = holder_base.GetHandle(); handle != os::InvalidNativeHandle) {
|
||||
AMS_ASSERT(count < num);
|
||||
|
||||
out_handles[count] = handle;
|
||||
|
|
|
@ -38,9 +38,9 @@ namespace ams::os::impl {
|
|||
InternalCriticalSection cs_wait;
|
||||
MultiWaitTargetImpl target_impl;
|
||||
private:
|
||||
Result WaitAnyImpl(MultiWaitHolderBase **out, bool infinite, TimeSpan timeout, bool reply, Handle reply_target);
|
||||
Result WaitAnyHandleImpl(MultiWaitHolderBase **out, bool infinite, TimeSpan timeout, bool reply, Handle reply_target);
|
||||
s32 BuildHandleArray(Handle out_handles[], MultiWaitHolderBase *out_objects[], s32 num);
|
||||
Result WaitAnyImpl(MultiWaitHolderBase **out, bool infinite, TimeSpan timeout, bool reply, NativeHandle reply_target);
|
||||
Result WaitAnyHandleImpl(MultiWaitHolderBase **out, bool infinite, TimeSpan timeout, bool reply, NativeHandle reply_target);
|
||||
s32 BuildHandleArray(NativeHandle out_handles[], MultiWaitHolderBase *out_objects[], s32 num);
|
||||
|
||||
MultiWaitHolderBase *LinkHoldersToObjectList();
|
||||
void UnlinkHoldersFromObjectList();
|
||||
|
@ -50,7 +50,7 @@ namespace ams::os::impl {
|
|||
MultiWaitHolderBase *WaitAnyImpl(bool infinite, TimeSpan timeout) {
|
||||
MultiWaitHolderBase *holder = nullptr;
|
||||
|
||||
const Result wait_result = this->WaitAnyImpl(std::addressof(holder), infinite, timeout, false, svc::InvalidHandle);
|
||||
const Result wait_result = this->WaitAnyImpl(std::addressof(holder), infinite, timeout, false, os::InvalidNativeHandle);
|
||||
R_ASSERT(wait_result);
|
||||
AMS_UNUSED(wait_result);
|
||||
|
||||
|
@ -70,7 +70,7 @@ namespace ams::os::impl {
|
|||
return this->WaitAnyImpl(false, ts);
|
||||
}
|
||||
|
||||
Result ReplyAndReceive(MultiWaitHolderBase **out, Handle reply_target) {
|
||||
Result ReplyAndReceive(MultiWaitHolderBase **out, NativeHandle reply_target) {
|
||||
return this->WaitAnyImpl(out, true, TimeSpan::FromNanoSeconds(std::numeric_limits<s64>::max()), true, reply_target);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
namespace ams::os::impl {
|
||||
|
||||
Result MultiWaitHorizonImpl::WaitSynchronizationN(s32 *out_index, s32 num, Handle arr[], s32 array_size, s64 ns) {
|
||||
Result MultiWaitHorizonImpl::WaitSynchronizationN(s32 *out_index, s32 num, NativeHandle arr[], s32 array_size, s64 ns) {
|
||||
AMS_ASSERT(!(num == 0 && ns == 0));
|
||||
s32 index = MultiWaitImpl::WaitInvalid;
|
||||
|
||||
|
@ -37,7 +37,7 @@ namespace ams::os::impl {
|
|||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result MultiWaitHorizonImpl::ReplyAndReceiveN(s32 *out_index, s32 num, Handle arr[], s32 array_size, s64 ns, Handle reply_target) {
|
||||
Result MultiWaitHorizonImpl::ReplyAndReceiveN(s32 *out_index, s32 num, NativeHandle arr[], s32 array_size, s64 ns, NativeHandle reply_target) {
|
||||
/* NOTE: Nintendo does not initialize this value, which seems like it can cause incorrect behavior. */
|
||||
s32 index = MultiWaitImpl::WaitInvalid;
|
||||
static_assert(MultiWaitImpl::WaitInvalid != -1);
|
||||
|
|
|
@ -23,22 +23,22 @@ namespace ams::os::impl {
|
|||
public:
|
||||
static constexpr size_t MaximumHandleCount = static_cast<size_t>(ams::svc::ArgumentHandleCountMax);
|
||||
private:
|
||||
Handle handle;
|
||||
NativeHandle handle;
|
||||
private:
|
||||
Result WaitSynchronizationN(s32 *out_index, s32 num, Handle arr[], s32 array_size, s64 ns);
|
||||
Result ReplyAndReceiveN(s32 *out_index, s32 num, Handle arr[], s32 array_size, s64 ns, Handle reply_target);
|
||||
Result WaitSynchronizationN(s32 *out_index, s32 num, NativeHandle arr[], s32 array_size, s64 ns);
|
||||
Result ReplyAndReceiveN(s32 *out_index, s32 num, NativeHandle arr[], s32 array_size, s64 ns, NativeHandle reply_target);
|
||||
public:
|
||||
void CancelWait();
|
||||
|
||||
Result WaitAny(s32 *out_index, Handle arr[], s32 array_size, s32 num) {
|
||||
Result WaitAny(s32 *out_index, NativeHandle arr[], s32 array_size, s32 num) {
|
||||
return this->WaitSynchronizationN(out_index, num, arr, array_size, svc::WaitInfinite);
|
||||
}
|
||||
|
||||
Result TryWaitAny(s32 *out_index, Handle arr[], s32 array_size, s32 num) {
|
||||
Result TryWaitAny(s32 *out_index, NativeHandle arr[], s32 array_size, s32 num) {
|
||||
return this->WaitSynchronizationN(out_index, num, arr, array_size, 0);
|
||||
}
|
||||
|
||||
Result TimedWaitAny(s32 *out_index, Handle arr[], s32 array_size, s32 num, TimeSpan ts) {
|
||||
Result TimedWaitAny(s32 *out_index, NativeHandle arr[], s32 array_size, s32 num, TimeSpan ts) {
|
||||
s64 timeout = ts.GetNanoSeconds();
|
||||
if (timeout < 0) {
|
||||
timeout = 0;
|
||||
|
@ -46,11 +46,11 @@ namespace ams::os::impl {
|
|||
return this->WaitSynchronizationN(out_index, num, arr, array_size, timeout);
|
||||
}
|
||||
|
||||
Result ReplyAndReceive(s32 *out_index, Handle arr[], s32 array_size, s32 num, Handle reply_target) {
|
||||
Result ReplyAndReceive(s32 *out_index, NativeHandle arr[], s32 array_size, s32 num, NativeHandle reply_target) {
|
||||
return this->ReplyAndReceiveN(out_index, num, arr, array_size, std::numeric_limits<s64>::max(), reply_target);
|
||||
}
|
||||
|
||||
Result TimedReplyAndReceive(s32 *out_index, Handle arr[], s32 array_size, s32 num, Handle reply_target, TimeSpan ts) {
|
||||
Result TimedReplyAndReceive(s32 *out_index, NativeHandle arr[], s32 array_size, s32 num, NativeHandle reply_target, TimeSpan ts) {
|
||||
return this->ReplyAndReceiveN(out_index, num, arr, array_size, ts.GetNanoSeconds(), reply_target);
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ namespace ams::os::impl {
|
|||
}
|
||||
|
||||
void ClearCurrentThreadHandleForCancelWait() {
|
||||
this->handle = svc::InvalidHandle;
|
||||
this->handle = os::InvalidNativeHandle;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
#pragma once
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
ncm::ProgramId GetCurrentProgramId();
|
||||
|
||||
}
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
#include "os_native_handle_impl.os.horizon.hpp"
|
||||
#else
|
||||
#error "Unknown OS for ams::os::NativeHandleImpl"
|
||||
#endif
|
|
@ -13,15 +13,18 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <stratosphere.hpp>
|
||||
#include "os_program_id_impl.hpp"
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
ncm::ProgramId GetCurrentProgramId() {
|
||||
u64 value;
|
||||
R_ABORT_UNLESS(svc::GetInfo(std::addressof(value), svc::InfoType_ProgramId, svc::PseudoHandle::CurrentProcess, 0));
|
||||
return {value};
|
||||
}
|
||||
class NativeHandleHorizonImpl {
|
||||
public:
|
||||
static ALWAYS_INLINE void Close(NativeHandle handle) {
|
||||
R_ABORT_UNLESS(svc::CloseHandle(handle));
|
||||
}
|
||||
};
|
||||
|
||||
using NativeHandleImpl = NativeHandleHorizonImpl;
|
||||
|
||||
}
|
|
@ -13,14 +13,11 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <stratosphere.hpp>
|
||||
#include "impl/os_program_id_impl.hpp"
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
ncm::ProgramId GetCurrentProgramId() {
|
||||
return ::ams::os::impl::GetCurrentProgramId();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
#include "os_process_handle_impl.os.horizon.hpp"
|
||||
#else
|
||||
#error "Unknown OS for ams::os::ProcessHandleImpl"
|
||||
#endif
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace ams::os::impl {
|
||||
|
||||
class ProcessHandleHorizonImpl {
|
||||
public:
|
||||
static consteval NativeHandle GetCurrentProcessHandle() {
|
||||
return svc::PseudoHandle::CurrentProcess;
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE Result GetProcessId(ProcessId *out, NativeHandle handle) {
|
||||
return svc::GetProcessId(std::addressof(out->value), handle);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE Result GetProgramId(ncm::ProgramId *out, NativeHandle handle) {
|
||||
return svc::GetInfo(std::addressof(out->value), svc::InfoType_ProgramId, svc::PseudoHandle::CurrentProcess, 0);
|
||||
}
|
||||
};
|
||||
|
||||
using ProcessHandleImpl = ProcessHandleHorizonImpl;
|
||||
|
||||
}
|
|
@ -20,11 +20,11 @@ namespace ams::os::impl {
|
|||
|
||||
class SharedMemoryImpl {
|
||||
public:
|
||||
static Result Create(Handle *out, size_t size, MemoryPermission my_perm, MemoryPermission other_perm);
|
||||
static void Close(Handle handle);
|
||||
static Result Create(NativeHandle *out, size_t size, MemoryPermission my_perm, MemoryPermission other_perm);
|
||||
static void Close(NativeHandle handle);
|
||||
|
||||
static Result Map(void **out, Handle handle, size_t size, MemoryPermission perm);
|
||||
static void Unmap(Handle handle, void *address, size_t size);
|
||||
static Result Map(void **out, NativeHandle handle, size_t size, MemoryPermission perm);
|
||||
static void Unmap(NativeHandle handle, void *address, size_t size);
|
||||
};
|
||||
|
||||
}
|
|
@ -33,7 +33,7 @@ namespace ams::os::impl {
|
|||
|
||||
}
|
||||
|
||||
Result SharedMemoryImpl::Create(Handle *out, size_t size, MemoryPermission my_perm, MemoryPermission other_perm) {
|
||||
Result SharedMemoryImpl::Create(NativeHandle *out, size_t size, MemoryPermission my_perm, MemoryPermission other_perm) {
|
||||
/* Convert memory permissions. */
|
||||
const auto svc_my_perm = ConvertToSvcMemoryPermission(my_perm);
|
||||
const auto svc_other_perm = ConvertToSvcMemoryPermission(other_perm);
|
||||
|
@ -49,11 +49,11 @@ namespace ams::os::impl {
|
|||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void SharedMemoryImpl::Close(Handle handle) {
|
||||
void SharedMemoryImpl::Close(NativeHandle handle) {
|
||||
R_ABORT_UNLESS(svc::CloseHandle(handle));
|
||||
}
|
||||
|
||||
Result SharedMemoryImpl::Map(void **out, Handle handle, size_t size, MemoryPermission perm) {
|
||||
Result SharedMemoryImpl::Map(void **out, NativeHandle handle, size_t size, MemoryPermission perm) {
|
||||
/* Convert memory permission. */
|
||||
const auto svc_perm = ConvertToSvcMemoryPermission(perm);
|
||||
|
||||
|
@ -77,7 +77,7 @@ namespace ams::os::impl {
|
|||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void SharedMemoryImpl::Unmap(Handle handle, void *address, size_t size) {
|
||||
void SharedMemoryImpl::Unmap(NativeHandle handle, void *address, size_t size) {
|
||||
R_ABORT_UNLESS(svc::UnmapSharedMemory(handle, reinterpret_cast<uintptr_t>(address), size));
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace ams::os::impl {
|
|||
return GetThreadManager().GetCurrentThread();
|
||||
}
|
||||
|
||||
ALWAYS_INLINE Handle GetCurrentThreadHandle() {
|
||||
ALWAYS_INLINE NativeHandle GetCurrentThreadHandle() {
|
||||
/* return GetCurrentThread()->thread_impl->handle; */
|
||||
return ::threadGetCurHandle();
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace ams::os::impl {
|
|||
|
||||
/* Set the thread's id. */
|
||||
u64 thread_id;
|
||||
R_ABORT_UNLESS(svc::GetThreadId(std::addressof(thread_id), svc::Handle(thread->thread_impl->handle)));
|
||||
R_ABORT_UNLESS(svc::GetThreadId(std::addressof(thread_id), thread->thread_impl->handle));
|
||||
thread->thread_id = thread_id;
|
||||
|
||||
/* Invoke the thread. */
|
||||
|
@ -60,7 +60,7 @@ namespace ams::os::impl {
|
|||
|
||||
/* Set the thread id. */
|
||||
u64 thread_id;
|
||||
R_ABORT_UNLESS(svc::GetThreadId(std::addressof(thread_id), svc::Handle(thread_impl->handle)));
|
||||
R_ABORT_UNLESS(svc::GetThreadId(std::addressof(thread_id), thread_impl->handle));
|
||||
main_thread->thread_id = thread_id;
|
||||
|
||||
/* NOTE: Here Nintendo would set the thread pointer in TLS. */
|
||||
|
@ -94,7 +94,7 @@ namespace ams::os::impl {
|
|||
}
|
||||
|
||||
void ThreadManagerHorizonImpl::WaitForThreadExit(ThreadType *thread) {
|
||||
const svc::Handle handle(thread->thread_impl->handle);
|
||||
const svc::Handle handle = thread->thread_impl->handle;
|
||||
|
||||
while (true) {
|
||||
s32 index;
|
||||
|
@ -107,7 +107,7 @@ namespace ams::os::impl {
|
|||
}
|
||||
|
||||
bool ThreadManagerHorizonImpl::TryWaitForThreadExit(ThreadType *thread) {
|
||||
const svc::Handle handle(thread->thread_impl->handle);
|
||||
const svc::Handle handle = thread->thread_impl->handle;
|
||||
|
||||
while (true) {
|
||||
/* Continuously wait, until success or timeout. */
|
||||
|
@ -137,9 +137,7 @@ namespace ams::os::impl {
|
|||
}
|
||||
|
||||
bool ThreadManagerHorizonImpl::ChangePriority(ThreadType *thread, s32 priority) {
|
||||
const svc::Handle handle(thread->thread_impl->handle);
|
||||
|
||||
auto res = svc::SetThreadPriority(handle, ConvertToHorizonPriority(priority));
|
||||
auto res = svc::SetThreadPriority(thread->thread_impl->handle, ConvertToHorizonPriority(priority));
|
||||
if (svc::ResultInvalidPriority::Includes(res)) {
|
||||
AMS_ABORT("Invalid thread priority");
|
||||
}
|
||||
|
@ -148,10 +146,8 @@ namespace ams::os::impl {
|
|||
}
|
||||
|
||||
s32 ThreadManagerHorizonImpl::GetCurrentPriority(const ThreadType *thread) const {
|
||||
const svc::Handle handle(thread->thread_impl->handle);
|
||||
s32 priority;
|
||||
|
||||
R_ABORT_UNLESS(svc::GetThreadPriority(std::addressof(priority), handle));
|
||||
R_ABORT_UNLESS(svc::GetThreadPriority(std::addressof(priority), thread->thread_impl->handle));
|
||||
|
||||
return ConvertToUserPriority(priority);
|
||||
}
|
||||
|
@ -161,21 +157,15 @@ namespace ams::os::impl {
|
|||
}
|
||||
|
||||
void ThreadManagerHorizonImpl::SuspendThreadUnsafe(ThreadType *thread) {
|
||||
const svc::Handle handle(thread->thread_impl->handle);
|
||||
|
||||
R_ABORT_UNLESS(svc::SetThreadActivity(handle, svc::ThreadActivity_Paused));
|
||||
R_ABORT_UNLESS(svc::SetThreadActivity(thread->thread_impl->handle, svc::ThreadActivity_Paused));
|
||||
}
|
||||
|
||||
void ThreadManagerHorizonImpl::ResumeThreadUnsafe(ThreadType *thread) {
|
||||
const svc::Handle handle(thread->thread_impl->handle);
|
||||
|
||||
R_ABORT_UNLESS(svc::SetThreadActivity(handle, svc::ThreadActivity_Runnable));
|
||||
R_ABORT_UNLESS(svc::SetThreadActivity(thread->thread_impl->handle, svc::ThreadActivity_Runnable));
|
||||
}
|
||||
|
||||
void ThreadManagerHorizonImpl::CancelThreadSynchronizationUnsafe(ThreadType *thread) {
|
||||
const svc::Handle handle(thread->thread_impl->handle);
|
||||
|
||||
R_ABORT_UNLESS(svc::CancelSynchronization(handle));
|
||||
R_ABORT_UNLESS(svc::CancelSynchronization(thread->thread_impl->handle));
|
||||
}
|
||||
|
||||
/* TODO: void GetThreadContextUnsafe(ThreadContextInfo *out_context, const ThreadType *thread); */
|
||||
|
@ -185,16 +175,14 @@ namespace ams::os::impl {
|
|||
}
|
||||
|
||||
void ThreadManagerHorizonImpl::SetThreadCoreMask(ThreadType *thread, s32 ideal_core, u64 affinity_mask) const {
|
||||
const svc::Handle handle(thread->thread_impl->handle);
|
||||
R_ABORT_UNLESS(svc::SetThreadCoreMask(handle, ideal_core, affinity_mask));
|
||||
R_ABORT_UNLESS(svc::SetThreadCoreMask(thread->thread_impl->handle, ideal_core, affinity_mask));
|
||||
}
|
||||
|
||||
void ThreadManagerHorizonImpl::GetThreadCoreMask(s32 *out_ideal_core, u64 *out_affinity_mask, const ThreadType *thread) const {
|
||||
s32 ideal_core;
|
||||
u64 affinity_mask;
|
||||
|
||||
const svc::Handle handle(thread->thread_impl->handle);
|
||||
R_ABORT_UNLESS(svc::GetThreadCoreMask(std::addressof(ideal_core), std::addressof(affinity_mask), handle));
|
||||
R_ABORT_UNLESS(svc::GetThreadCoreMask(std::addressof(ideal_core), std::addressof(affinity_mask), thread->thread_impl->handle));
|
||||
|
||||
if (out_ideal_core) {
|
||||
*out_ideal_core = ideal_core;
|
||||
|
|
|
@ -20,11 +20,11 @@ namespace ams::os::impl {
|
|||
|
||||
class TransferMemoryImpl {
|
||||
public:
|
||||
static Result Create(Handle *out, void *address, size_t size, MemoryPermission perm);
|
||||
static void Close(Handle handle);
|
||||
static Result Create(NativeHandle *out, void *address, size_t size, MemoryPermission perm);
|
||||
static void Close(NativeHandle handle);
|
||||
|
||||
static Result Map(void **out, Handle handle, size_t size, MemoryPermission owner_perm);
|
||||
static void Unmap(Handle handle, void *address, size_t size);
|
||||
static Result Map(void **out, NativeHandle handle, size_t size, MemoryPermission owner_perm);
|
||||
static void Unmap(NativeHandle handle, void *address, size_t size);
|
||||
};
|
||||
|
||||
}
|
|
@ -33,7 +33,7 @@ namespace ams::os::impl {
|
|||
|
||||
}
|
||||
|
||||
Result TransferMemoryImpl::Create(Handle *out, void *address, size_t size, MemoryPermission perm) {
|
||||
Result TransferMemoryImpl::Create(NativeHandle *out, void *address, size_t size, MemoryPermission perm) {
|
||||
/* Convert memory permission. */
|
||||
const auto svc_perm = ConvertToSvcMemoryPermission(perm);
|
||||
|
||||
|
@ -48,11 +48,11 @@ namespace ams::os::impl {
|
|||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void TransferMemoryImpl::Close(Handle handle) {
|
||||
void TransferMemoryImpl::Close(NativeHandle handle) {
|
||||
R_ABORT_UNLESS(svc::CloseHandle(handle));
|
||||
}
|
||||
|
||||
Result TransferMemoryImpl::Map(void **out, Handle handle, size_t size, MemoryPermission owner_perm) {
|
||||
Result TransferMemoryImpl::Map(void **out, NativeHandle handle, size_t size, MemoryPermission owner_perm) {
|
||||
/* Convert memory permission. */
|
||||
const auto svc_owner_perm = ConvertToSvcMemoryPermission(owner_perm);
|
||||
|
||||
|
@ -79,7 +79,7 @@ namespace ams::os::impl {
|
|||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void TransferMemoryImpl::Unmap(Handle handle, void *address, size_t size) {
|
||||
void TransferMemoryImpl::Unmap(NativeHandle handle, void *address, size_t size) {
|
||||
R_ABORT_UNLESS(svc::UnmapTransferMemory(handle, reinterpret_cast<uintptr_t>(address), size));
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace ams::os {
|
|||
|
||||
namespace {
|
||||
|
||||
void InitializeIoRegion(IoRegionType *io_region, Handle handle, size_t size, bool managed) {
|
||||
void InitializeIoRegion(IoRegionType *io_region, NativeHandle handle, size_t size, bool managed) {
|
||||
/* Set state. */
|
||||
io_region->state = IoRegionType::State_Initialized;
|
||||
|
||||
|
@ -36,7 +36,7 @@ namespace ams::os {
|
|||
|
||||
}
|
||||
|
||||
Result CreateIoRegion(IoRegionType *io_region, Handle io_pool_handle, uintptr_t address, size_t size, MemoryMapping mapping, MemoryPermission permission) {
|
||||
Result CreateIoRegion(IoRegionType *io_region, NativeHandle io_pool_handle, uintptr_t address, size_t size, MemoryMapping mapping, MemoryPermission permission) {
|
||||
/* Check pre-conditions. */
|
||||
AMS_ASSERT(io_region != nullptr);
|
||||
AMS_ASSERT(io_pool_handle != svc::InvalidHandle);
|
||||
|
@ -49,7 +49,7 @@ namespace ams::os {
|
|||
auto state_guard = SCOPE_GUARD { io_region->state = IoRegionType::State_NotInitialized; };
|
||||
|
||||
/* Create the io region. */
|
||||
Handle handle;
|
||||
NativeHandle handle;
|
||||
R_TRY(impl::IoRegionImpl::CreateIoRegion(std::addressof(handle), io_pool_handle, address, size, mapping, permission));
|
||||
|
||||
/* Setup the object. */
|
||||
|
@ -59,7 +59,7 @@ namespace ams::os {
|
|||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void AttachIoRegionHandle(IoRegionType *io_region, size_t size, Handle handle, bool managed) {
|
||||
void AttachIoRegionHandle(IoRegionType *io_region, size_t size, NativeHandle handle, bool managed) {
|
||||
/* Check pre-conditions. */
|
||||
AMS_ASSERT(io_region != nullptr);
|
||||
AMS_ASSERT(util::IsAligned(size, os::MemoryPageSize));
|
||||
|
@ -81,8 +81,7 @@ namespace ams::os {
|
|||
|
||||
/* If managed, close the handle. */
|
||||
if (io_region->handle_managed) {
|
||||
/* TODO: os::CloseNativeHandle */
|
||||
R_ABORT_UNLESS(svc::CloseHandle(io_region->handle));
|
||||
os::CloseNativeHandle(io_region->handle);
|
||||
}
|
||||
|
||||
/* Clear members. */
|
||||
|
@ -95,7 +94,7 @@ namespace ams::os {
|
|||
io_region->state = IoRegionType::State_NotInitialized;
|
||||
}
|
||||
|
||||
Handle GetIoRegionHandle(const IoRegionType *io_region) {
|
||||
NativeHandle GetIoRegionHandle(const IoRegionType *io_region) {
|
||||
/* Check pre-conditions. */
|
||||
AMS_ASSERT(io_region->state != IoRegionType::State_NotInitialized);
|
||||
|
||||
|
|
|
@ -141,8 +141,8 @@ namespace ams::os {
|
|||
return holder->user_data;
|
||||
}
|
||||
|
||||
void InitializeMultiWaitHolder(MultiWaitHolderType *holder, Handle handle) {
|
||||
AMS_ASSERT(handle != svc::InvalidHandle);
|
||||
void InitializeMultiWaitHolder(MultiWaitHolderType *holder, NativeHandle handle) {
|
||||
AMS_ASSERT(handle != os::InvalidNativeHandle);
|
||||
|
||||
util::ConstructAt(GetReference(holder->impl_storage).holder_of_handle_storage, handle);
|
||||
|
||||
|
|
|
@ -14,31 +14,14 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "impl/os_native_handle_impl.hpp"
|
||||
|
||||
namespace ams {
|
||||
namespace ams::os {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr inline ::Handle GetCurrentProcessHandleImpl() {
|
||||
return CUR_PROCESS_HANDLE;
|
||||
void CloseNativeHandle(NativeHandle handle) {
|
||||
if (handle != os::InvalidNativeHandle) {
|
||||
impl::NativeHandleImpl::Close(handle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace os {
|
||||
|
||||
::Handle __attribute__((const)) GetCurrentProcessHandle() {
|
||||
return GetCurrentProcessHandleImpl();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace dd {
|
||||
|
||||
::Handle __attribute__((const)) GetCurrentProcessHandle() {
|
||||
return GetCurrentProcessHandleImpl();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "impl/os_process_handle_impl.hpp"
|
||||
|
||||
namespace ams {
|
||||
|
||||
namespace dd {
|
||||
|
||||
dd::ProcessHandle __attribute__((const)) GetCurrentProcessHandle() {
|
||||
return ::ams::os::impl::ProcessHandleImpl::GetCurrentProcessHandle();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace os {
|
||||
|
||||
NativeHandle __attribute__((const)) GetCurrentProcessHandle() {
|
||||
return ::ams::os::impl::ProcessHandleImpl::GetCurrentProcessHandle();
|
||||
}
|
||||
|
||||
Result GetProcessId(os::ProcessId *out, NativeHandle handle) {
|
||||
return ::ams::os::impl::ProcessHandleImpl::GetProcessId(out, handle);
|
||||
}
|
||||
|
||||
Result GetProgramId(ncm::ProgramId *out, NativeHandle handle) {
|
||||
return ::ams::os::impl::ProcessHandleImpl::GetProgramId(out, handle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -32,7 +32,7 @@ namespace ams::os {
|
|||
|
||||
}
|
||||
|
||||
Result SdkReplyAndReceive(os::MultiWaitHolderType **out, Handle reply_target, MultiWaitType *multi_wait) {
|
||||
Result SdkReplyAndReceive(os::MultiWaitHolderType **out, NativeHandle reply_target, MultiWaitType *multi_wait) {
|
||||
auto &impl = GetMultiWaitImpl(multi_wait);
|
||||
|
||||
AMS_ASSERT(multi_wait->state == MultiWaitType::State_Initialized);
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace ams::os {
|
|||
|
||||
namespace {
|
||||
|
||||
void SetupSharedMemoryType(SharedMemoryType *shared_memory, size_t size, Handle handle, bool managed) {
|
||||
void SetupSharedMemoryType(SharedMemoryType *shared_memory, size_t size, NativeHandle handle, bool managed) {
|
||||
/* Set members. */
|
||||
shared_memory->handle = handle;
|
||||
shared_memory->size = size;
|
||||
|
@ -43,7 +43,7 @@ namespace ams::os {
|
|||
AMS_ASSERT(util::IsAligned(size, MemoryPageSize));
|
||||
|
||||
/* Create the memory. */
|
||||
Handle handle;
|
||||
NativeHandle handle;
|
||||
R_TRY(impl::SharedMemoryImpl::Create(std::addressof(handle), size, my_perm, other_perm));
|
||||
|
||||
/* Setup the object. */
|
||||
|
@ -52,11 +52,11 @@ namespace ams::os {
|
|||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void AttachSharedMemory(SharedMemoryType *shared_memory, size_t size, Handle handle, bool managed) {
|
||||
void AttachSharedMemory(SharedMemoryType *shared_memory, size_t size, NativeHandle handle, bool managed) {
|
||||
/* Check pre-conditions. */
|
||||
AMS_ASSERT(size > 0);
|
||||
AMS_ASSERT(util::IsAligned(size, MemoryPageSize));
|
||||
AMS_ASSERT(handle != svc::InvalidHandle);
|
||||
AMS_ASSERT(handle != os::InvalidNativeHandle);
|
||||
|
||||
/* Setup the object. */
|
||||
SetupSharedMemoryType(shared_memory, size, handle, managed);
|
||||
|
@ -83,7 +83,7 @@ namespace ams::os {
|
|||
/* Clear members. */
|
||||
shared_memory->address = nullptr;
|
||||
shared_memory->size = 0;
|
||||
shared_memory->handle = svc::InvalidHandle;
|
||||
shared_memory->handle = os::InvalidNativeHandle;
|
||||
|
||||
/* Destroy the critical section. */
|
||||
util::DestroyAt(shared_memory->cs_shared_memory);
|
||||
|
@ -147,7 +147,7 @@ namespace ams::os {
|
|||
return shared_memory->size;
|
||||
}
|
||||
|
||||
Handle GetSharedMemoryHandle(const SharedMemoryType *shared_memory) {
|
||||
NativeHandle GetSharedMemoryHandle(const SharedMemoryType *shared_memory) {
|
||||
/* Check pre-conditions. */
|
||||
AMS_ASSERT(shared_memory->state == SharedMemoryType::State_Initialized || shared_memory->state == SharedMemoryType::State_Mapped);
|
||||
|
||||
|
|
|
@ -42,36 +42,36 @@ namespace ams::os {
|
|||
}
|
||||
}
|
||||
|
||||
void AttachSystemEvent(SystemEventType *event, Handle read_handle, bool read_handle_managed, Handle write_handle, bool write_handle_managed, EventClearMode clear_mode) {
|
||||
void AttachSystemEvent(SystemEventType *event, NativeHandle read_handle, bool read_handle_managed, NativeHandle write_handle, bool write_handle_managed, EventClearMode clear_mode) {
|
||||
AMS_ASSERT(read_handle != svc::InvalidHandle || write_handle != svc::InvalidHandle);
|
||||
impl::AttachInterProcessEvent(std::addressof(event->inter_process_event), read_handle, read_handle_managed, write_handle, write_handle_managed, clear_mode);
|
||||
event->state = SystemEventType::State_InitializedAsInterProcessEvent;
|
||||
}
|
||||
|
||||
void AttachReadableHandleToSystemEvent(SystemEventType *event, Handle read_handle, bool manage_read_handle, EventClearMode clear_mode) {
|
||||
void AttachReadableHandleToSystemEvent(SystemEventType *event, NativeHandle read_handle, bool manage_read_handle, EventClearMode clear_mode) {
|
||||
return AttachSystemEvent(event, read_handle, manage_read_handle, svc::InvalidHandle, false, clear_mode);
|
||||
}
|
||||
|
||||
void AttachWritableHandleToSystemEvent(SystemEventType *event, Handle write_handle, bool manage_write_handle, EventClearMode clear_mode) {
|
||||
void AttachWritableHandleToSystemEvent(SystemEventType *event, NativeHandle write_handle, bool manage_write_handle, EventClearMode clear_mode) {
|
||||
return AttachSystemEvent(event, svc::InvalidHandle, false, write_handle, manage_write_handle, clear_mode);
|
||||
}
|
||||
|
||||
Handle DetachReadableHandleOfSystemEvent(SystemEventType *event) {
|
||||
NativeHandle DetachReadableHandleOfSystemEvent(SystemEventType *event) {
|
||||
AMS_ASSERT(event->state == SystemEventType::State_InitializedAsInterProcessEvent);
|
||||
return impl::DetachReadableHandleOfInterProcessEvent(std::addressof(event->inter_process_event));
|
||||
}
|
||||
|
||||
Handle DetachWritableHandleOfSystemEvent(SystemEventType *event) {
|
||||
NativeHandle DetachWritableHandleOfSystemEvent(SystemEventType *event) {
|
||||
AMS_ASSERT(event->state == SystemEventType::State_InitializedAsInterProcessEvent);
|
||||
return impl::DetachWritableHandleOfInterProcessEvent(std::addressof(event->inter_process_event));
|
||||
}
|
||||
|
||||
Handle GetReadableHandleOfSystemEvent(const SystemEventType *event) {
|
||||
NativeHandle GetReadableHandleOfSystemEvent(const SystemEventType *event) {
|
||||
AMS_ASSERT(event->state == SystemEventType::State_InitializedAsInterProcessEvent);
|
||||
return impl::GetReadableHandleOfInterProcessEvent(std::addressof(event->inter_process_event));
|
||||
}
|
||||
|
||||
Handle GetWritableHandleOfSystemEvent(const SystemEventType *event) {
|
||||
NativeHandle GetWritableHandleOfSystemEvent(const SystemEventType *event) {
|
||||
AMS_ASSERT(event->state == SystemEventType::State_InitializedAsInterProcessEvent);
|
||||
return impl::GetWritableHandleOfInterProcessEvent(std::addressof(event->inter_process_event));
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace ams::os {
|
|||
|
||||
namespace {
|
||||
|
||||
inline void SetupTransferMemoryType(TransferMemoryType *tmem, size_t size, Handle handle, bool managed) {
|
||||
inline void SetupTransferMemoryType(TransferMemoryType *tmem, size_t size, NativeHandle handle, bool managed) {
|
||||
/* Set members. */
|
||||
tmem->handle = handle;
|
||||
tmem->size = size;
|
||||
|
@ -45,7 +45,7 @@ namespace ams::os {
|
|||
AMS_ASSERT(util::IsAligned(reinterpret_cast<uintptr_t>(address), os::MemoryPageSize));
|
||||
|
||||
/* Create the memory. */
|
||||
Handle handle;
|
||||
NativeHandle handle;
|
||||
R_TRY(impl::TransferMemoryImpl::Create(std::addressof(handle), address, size, perm));
|
||||
|
||||
/* Setup the object. */
|
||||
|
@ -54,7 +54,7 @@ namespace ams::os {
|
|||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void AttachTransferMemory(TransferMemoryType *tmem, size_t size, Handle handle, bool managed) {
|
||||
void AttachTransferMemory(TransferMemoryType *tmem, size_t size, NativeHandle handle, bool managed) {
|
||||
AMS_ASSERT(size > 0);
|
||||
AMS_ASSERT(util::IsAligned(size, os::MemoryPageSize));
|
||||
AMS_ASSERT(handle != svc::InvalidHandle);
|
||||
|
@ -63,16 +63,16 @@ namespace ams::os {
|
|||
SetupTransferMemoryType(tmem, size, handle, managed);
|
||||
}
|
||||
|
||||
Handle DetachTransferMemory(TransferMemoryType *tmem) {
|
||||
NativeHandle DetachTransferMemory(TransferMemoryType *tmem) {
|
||||
AMS_ASSERT(tmem->state == TransferMemoryType::State_Created);
|
||||
|
||||
/* Set state to detached. */
|
||||
tmem->state = TransferMemoryType::State_Detached;
|
||||
|
||||
/* Clear handle. */
|
||||
Handle handle = tmem->handle;
|
||||
const NativeHandle handle = tmem->handle;
|
||||
|
||||
tmem->handle = svc::InvalidHandle;
|
||||
tmem->handle = os::InvalidNativeHandle;
|
||||
tmem->handle_managed = false;
|
||||
|
||||
return handle;
|
||||
|
@ -99,7 +99,7 @@ namespace ams::os {
|
|||
/* Clear members. */
|
||||
tmem->address = nullptr;
|
||||
tmem->size = 0;
|
||||
tmem->handle = svc::InvalidHandle;
|
||||
tmem->handle = os::InvalidNativeHandle;
|
||||
|
||||
/* Destroy the critical section. */
|
||||
util::DestroyAt(tmem->cs_transfer_memory);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue