os: remove ManagedHandle, refactor to use NativeHandle typename

This commit is contained in:
Michael Scire 2021-10-04 12:33:09 -07:00
parent a774833790
commit 6f76066d24
71 changed files with 473 additions and 397 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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);
};
}

View file

@ -50,7 +50,7 @@ namespace ams::os::impl {
return this->impl.IsSignaled();
}
Handle GetHandle() const {
NativeHandle GetHandle() const {
return this->impl.GetHandle();
}
};

View file

@ -35,7 +35,7 @@ namespace ams::os::impl {
return TriBool::Undefined;
}
Handle GetHandle() const {
NativeHandle GetHandle() const {
return this->handle;
}
};

View file

@ -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);
};
}

View file

@ -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));
}

View file

@ -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;
}
};

View file

@ -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;
}
};

View file

@ -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;
}
};

View file

@ -19,7 +19,7 @@
namespace ams::os::impl {
Handle MultiWaitHolderOfInterruptEvent::GetHandle() const {
NativeHandle MultiWaitHolderOfInterruptEvent::GetHandle() const {
return GetReference(event->impl).GetHandle();
}

View file

@ -29,7 +29,7 @@ namespace ams::os::impl {
return TriBool::Undefined;
}
virtual Handle GetHandle() const override;
virtual NativeHandle GetHandle() const override;
};
}

View file

@ -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;

View file

@ -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);
}

View file

@ -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);

View file

@ -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;
}
};

View file

@ -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

View file

@ -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;
}

View file

@ -0,0 +1,23 @@
/*
* 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>
#if defined(ATMOSPHERE_OS_HORIZON)
#include "os_process_handle_impl.os.horizon.hpp"
#else
#error "Unknown OS for ams::os::ProcessHandleImpl"
#endif

View file

@ -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;
}

View file

@ -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);
};
}

View file

@ -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));
}

View file

@ -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();
}

View file

@ -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;

View file

@ -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);
};
}

View file

@ -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));
}