From aa2844bcf9b2b9bca2ce263270b963ffd13b05e7 Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 20 Apr 2021 22:18:56 -0700 Subject: hle: kernel: HandleTable: Remove deprecated APIs. --- src/core/hle/kernel/handle_table.cpp | 77 +++++------------------------------- 1 file changed, 9 insertions(+), 68 deletions(-) (limited to 'src/core/hle/kernel/handle_table.cpp') diff --git a/src/core/hle/kernel/handle_table.cpp b/src/core/hle/kernel/handle_table.cpp index 9291f0a76..cd752da4e 100644 --- a/src/core/hle/kernel/handle_table.cpp +++ b/src/core/hle/kernel/handle_table.cpp @@ -47,50 +47,6 @@ ResultCode HandleTable::SetSize(s32 handle_table_size) { return RESULT_SUCCESS; } -ResultVal HandleTable::Create(Object* obj) { - DEBUG_ASSERT(obj != nullptr); - - switch (obj->GetHandleType()) { - case HandleType::SharedMemory: - case HandleType::Thread: - case HandleType::Event: - case HandleType::Process: - case HandleType::ReadableEvent: - case HandleType::WritableEvent: - case HandleType::ClientSession: - case HandleType::ServerSession: - case HandleType::Session: - case HandleType::TransferMemory: { - Handle handle{}; - Add(&handle, reinterpret_cast(obj), {}); - return MakeResult(handle); - } - default: - break; - } - - const u16 slot = next_free_slot; - if (slot >= table_size) { - LOG_ERROR(Kernel, "Unable to allocate Handle, too many slots in use."); - return ResultOutOfHandles; - } - next_free_slot = generations[slot]; - - const u16 generation = next_generation++; - - // Overflow count so it fits in the 15 bits dedicated to the generation in the handle. - // Horizon OS uses zero to represent an invalid handle, so skip to 1. - if (next_generation >= (1 << 15)) { - next_generation = 1; - } - - generations[slot] = generation; - objects[slot] = std::move(SharedFrom(obj)); - - Handle handle = generation | (slot << 15); - return MakeResult(handle); -} - ResultCode HandleTable::Add(Handle* out_handle, KAutoObject* obj, u16 type) { ASSERT(obj != nullptr); @@ -110,7 +66,7 @@ ResultCode HandleTable::Add(Handle* out_handle, KAutoObject* obj, u16 type) { } generations[slot] = generation; - objects_new[slot] = obj; + objects[slot] = obj; obj->Open(); *out_handle = generation | (slot << 15); @@ -119,12 +75,16 @@ ResultCode HandleTable::Add(Handle* out_handle, KAutoObject* obj, u16 type) { } ResultVal HandleTable::Duplicate(Handle handle) { - auto object = GetGeneric(handle); - if (object == nullptr) { + auto object = GetObject(handle); + if (object.IsNull()) { LOG_ERROR(Kernel, "Tried to duplicate invalid handle: {:08X}", handle); return ResultInvalidHandle; } - return Create(object); + + Handle out_handle{}; + R_TRY(Add(&out_handle, object.GetPointerUnsafe())); + + return MakeResult(out_handle); } bool HandleTable::Remove(Handle handle) { @@ -139,12 +99,7 @@ bool HandleTable::Remove(Handle handle) { objects[slot]->Close(); } - if (objects_new[slot]) { - objects_new[slot]->Close(); - } - objects[slot] = nullptr; - objects_new[slot] = nullptr; generations[slot] = next_free_slot; next_free_slot = slot; @@ -155,28 +110,14 @@ bool HandleTable::Remove(Handle handle) { bool HandleTable::IsValid(Handle handle) const { const std::size_t slot = GetSlot(handle); const u16 generation = GetGeneration(handle); - const bool is_object_valid = (objects[slot] != nullptr) || (objects_new[slot] != nullptr); + const bool is_object_valid = (objects[slot] != nullptr); return slot < table_size && is_object_valid && generations[slot] == generation; } -Object* HandleTable::GetGeneric(Handle handle) const { - if (handle == CurrentThread) { - return (kernel.CurrentScheduler()->GetCurrentThread()); - } else if (handle == CurrentProcess) { - return (kernel.CurrentProcess()); - } - - if (!IsValid(handle)) { - return nullptr; - } - return objects[GetSlot(handle)].get(); -} - void HandleTable::Clear() { for (u16 i = 0; i < table_size; ++i) { generations[i] = static_cast(i + 1); objects[i] = nullptr; - objects_new[i] = nullptr; } next_free_slot = 0; } -- cgit v1.2.3