remove m_kernel reference from global scheduler

This commit is contained in:
lizzie 2026-06-05 07:27:53 +00:00
parent 080ebb1760
commit f6f79aaf7b
25 changed files with 155 additions and 183 deletions

View File

@ -17,7 +17,8 @@
namespace Kernel {
GlobalSchedulerContext::GlobalSchedulerContext(KernelCore& kernel)
: m_kernel{kernel}, m_scheduler_lock{kernel} {}
: m_scheduler_lock{kernel}
{}
GlobalSchedulerContext::~GlobalSchedulerContext() = default;
@ -37,7 +38,7 @@ void GlobalSchedulerContext::RemoveThread(KThread* thread) noexcept {
/// and then does some core rebalancing. Preemption priorities can be found
/// in the array 'preemption_priorities'.
/// @note This operation happens every 10ms.
void GlobalSchedulerContext::PreemptThreads() noexcept {
void GlobalSchedulerContext::PreemptThreads(KernelCore& kernel) noexcept {
// The priority levels at which the global scheduler preempts threads every 10 ms. They are
// ordered from Core 0 to Core 3.
static constexpr std::array<u32, Core::Hardware::NUM_CPU_CORES> per_core{
@ -46,9 +47,9 @@ void GlobalSchedulerContext::PreemptThreads() noexcept {
59,
63,
};
ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(m_kernel));
ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(kernel));
for (u32 core_id = 0; core_id < per_core.size(); core_id++)
KScheduler::RotateScheduledQueue(m_kernel, core_id, per_core[core_id]);
KScheduler::RotateScheduledQueue(kernel, core_id, per_core[core_id]);
}
/// @brief Returns true if the global scheduler lock is acquired

View File

@ -50,7 +50,7 @@ public:
}
void AddThread(KThread* thread) noexcept;
void RemoveThread(KThread* thread) noexcept;
void PreemptThreads() noexcept;
void PreemptThreads(KernelCore& kernel) noexcept;
bool IsLocked() const noexcept;
void UnregisterDummyThreadForWakeup(KThread* thread) noexcept;
void RegisterDummyThreadForWakeup(KThread* thread) noexcept;
@ -60,7 +60,6 @@ private:
friend class KScopedSchedulerLock;
friend class KScopedSchedulerLockAndSleep;
KernelCore& m_kernel;
std::atomic_bool m_scheduler_update_needed{};
KSchedulerPriorityQueue m_priority_queue;
LockType m_scheduler_lock;

View File

@ -6,14 +6,15 @@
#include "core/hle/kernel/k_handle_table.h"
#include "core/hle/kernel/k_process.h"
#include "core/hle/kernel/kernel.h"
namespace Kernel {
void KHandleTable::Finalize() {
void KHandleTable::Finalize(KernelCore& kernel) {
// Get the table and clear our record of it.
u16 saved_table_size = 0;
{
KScopedDisableDispatch dd{m_kernel};
KScopedDisableDispatch dd{kernel};
KScopedSpinLock lk(m_lock);
std::swap(m_table_size, saved_table_size);
@ -27,7 +28,7 @@ void KHandleTable::Finalize() {
}
}
bool KHandleTable::Remove(Handle handle) {
bool KHandleTable::Remove(KernelCore& kernel, Handle handle) {
// Don't allow removal of a pseudo-handle.
if (Svc::IsPseudoHandle(handle)) [[unlikely]] {
return false;
@ -42,7 +43,7 @@ bool KHandleTable::Remove(Handle handle) {
// Find the object and free the entry.
KAutoObject* obj = nullptr;
{
KScopedDisableDispatch dd{m_kernel};
KScopedDisableDispatch dd{kernel};
KScopedSpinLock lk(m_lock);
if (this->IsValidHandle(handle)) [[likely]] {
@ -56,13 +57,13 @@ bool KHandleTable::Remove(Handle handle) {
}
// Close the object.
m_kernel.UnregisterInUseObject(obj);
kernel.UnregisterInUseObject(obj);
obj->Close();
return true;
}
Result KHandleTable::Add(Handle* out_handle, KAutoObject* obj) {
KScopedDisableDispatch dd{m_kernel};
Result KHandleTable::Add(KernelCore& kernel, Handle* out_handle, KAutoObject* obj) {
KScopedDisableDispatch dd{kernel};
KScopedSpinLock lk(m_lock);
// Never exceed our capacity.
@ -84,8 +85,7 @@ Result KHandleTable::Add(Handle* out_handle, KAutoObject* obj) {
R_SUCCEED();
}
KScopedAutoObject<KAutoObject> KHandleTable::GetObjectForIpc(Handle handle,
KThread* cur_thread) const {
KScopedAutoObject<KAutoObject> KHandleTable::GetObjectForIpc(KernelCore& kernel, Handle handle, KThread* cur_thread) const {
// Handle pseudo-handles.
ASSERT(cur_thread != nullptr);
if (handle == Svc::PseudoHandle::CurrentProcess) {
@ -96,12 +96,11 @@ KScopedAutoObject<KAutoObject> KHandleTable::GetObjectForIpc(Handle handle,
if (handle == Svc::PseudoHandle::CurrentThread) {
return cur_thread;
}
return GetObjectForIpcWithoutPseudoHandle(handle);
return GetObjectForIpcWithoutPseudoHandle(kernel, handle);
}
Result KHandleTable::Reserve(Handle* out_handle) {
KScopedDisableDispatch dd{m_kernel};
Result KHandleTable::Reserve(KernelCore& kernel, Handle* out_handle) {
KScopedDisableDispatch dd{kernel};
KScopedSpinLock lk(m_lock);
// Never exceed our capacity.
@ -111,8 +110,8 @@ Result KHandleTable::Reserve(Handle* out_handle) {
R_SUCCEED();
}
void KHandleTable::Unreserve(Handle handle) {
KScopedDisableDispatch dd{m_kernel};
void KHandleTable::Unreserve(KernelCore& kernel, Handle handle) {
KScopedDisableDispatch dd{kernel};
KScopedSpinLock lk(m_lock);
// Unpack the handle.
@ -130,8 +129,8 @@ void KHandleTable::Unreserve(Handle handle) {
}
}
void KHandleTable::Register(Handle handle, KAutoObject* obj) {
KScopedDisableDispatch dd{m_kernel};
void KHandleTable::Register(KernelCore& kernel, Handle handle, KAutoObject* obj) {
KScopedDisableDispatch dd{kernel};
KScopedSpinLock lk(m_lock);
// Unpack the handle.

View File

@ -31,14 +31,14 @@ public:
static constexpr size_t MaxTableSize = 1024;
public:
explicit KHandleTable(KernelCore& kernel) : m_kernel(kernel) {}
explicit KHandleTable(KernelCore& kernel) {}
Result Initialize(s32 size) {
Result Initialize(KernelCore& kernel, s32 size) {
// Check that the table size is valid.
R_UNLESS(size <= static_cast<s32>(MaxTableSize), ResultOutOfMemory);
// Lock.
KScopedDisableDispatch dd{m_kernel};
KScopedDisableDispatch dd{kernel};
KScopedSpinLock lk(m_lock);
// Initialize all fields.
@ -68,13 +68,13 @@ public:
return m_max_count;
}
void Finalize();
bool Remove(Handle handle);
void Finalize(KernelCore& kernel);
bool Remove(KernelCore& kernel, Handle handle);
template <typename T = KAutoObject>
KScopedAutoObject<T> GetObjectWithoutPseudoHandle(Handle handle) const {
KScopedAutoObject<T> GetObjectWithoutPseudoHandle(KernelCore& kernel, Handle handle) const {
// Lock and look up in table.
KScopedDisableDispatch dd{m_kernel};
KScopedDisableDispatch dd{kernel};
KScopedSpinLock lk(m_lock);
if constexpr (std::is_same_v<T, KAutoObject>) {
@ -89,17 +89,17 @@ public:
}
template <typename T = KAutoObject>
KScopedAutoObject<T> GetObject(Handle handle) const {
KScopedAutoObject<T> GetObject(KernelCore& kernel, Handle handle) const {
// Handle pseudo-handles.
if constexpr (std::derived_from<KProcess, T>) {
if (handle == Svc::PseudoHandle::CurrentProcess) {
auto* const cur_process = GetCurrentProcessPointer(m_kernel);
auto* const cur_process = GetCurrentProcessPointer(kernel);
ASSERT(cur_process != nullptr);
return cur_process;
}
} else if constexpr (std::derived_from<KThread, T>) {
if (handle == Svc::PseudoHandle::CurrentThread) {
auto* const cur_thread = GetCurrentThreadPointer(m_kernel);
auto* const cur_thread = GetCurrentThreadPointer(kernel);
ASSERT(cur_thread != nullptr);
return cur_thread;
}
@ -108,36 +108,33 @@ public:
return this->template GetObjectWithoutPseudoHandle<T>(handle);
}
KScopedAutoObject<KAutoObject> GetObjectForIpcWithoutPseudoHandle(Handle handle) const {
KScopedAutoObject<KAutoObject> GetObjectForIpcWithoutPseudoHandle(KernelCore& kernel, Handle handle) const {
// Lock and look up in table.
KScopedDisableDispatch dd{m_kernel};
KScopedDisableDispatch dd{kernel};
KScopedSpinLock lk(m_lock);
return this->GetObjectImpl(handle);
}
KScopedAutoObject<KAutoObject> GetObjectForIpc(Handle handle, KThread* cur_thread) const;
KScopedAutoObject<KAutoObject> GetObjectByIndex(Handle* out_handle, size_t index) const {
KScopedDisableDispatch dd{m_kernel};
KScopedAutoObject<KAutoObject> GetObjectForIpc(KernelCore& kernel, Handle handle, KThread* cur_thread) const;
KScopedAutoObject<KAutoObject> GetObjectByIndex(KernelCore& kernel, Handle* out_handle, size_t index) const {
KScopedDisableDispatch dd{kernel};
KScopedSpinLock lk(m_lock);
return this->GetObjectByIndexImpl(out_handle, index);
}
Result Reserve(Handle* out_handle);
void Unreserve(Handle handle);
Result Reserve(KernelCore& kernel, Handle* out_handle);
void Unreserve(KernelCore& kernel, Handle handle);
Result Add(Handle* out_handle, KAutoObject* obj);
void Register(Handle handle, KAutoObject* obj);
Result Add(KernelCore& kernel, Handle* out_handle, KAutoObject* obj);
void Register(KernelCore& kernel, Handle handle, KAutoObject* obj);
template <typename T>
bool GetMultipleObjects(T** out, const Handle* handles, size_t num_handles) const {
bool GetMultipleObjects(KernelCore& kernel, T** out, const Handle* handles, size_t num_handles) const {
// Try to convert and open all the handles.
size_t num_opened;
{
// Lock the table.
KScopedDisableDispatch dd{m_kernel};
KScopedDisableDispatch dd{kernel};
KScopedSpinLock lk(m_lock);
for (num_opened = 0; num_opened < num_handles; num_opened++) {
// Get the current handle.
@ -177,13 +174,9 @@ public:
private:
s32 AllocateEntry() {
ASSERT(m_count < m_table_size);
const auto index = m_free_head_index;
m_free_head_index = m_entry_infos[index].GetNextFreeIndex();
m_max_count = (std::max)(m_max_count, ++m_count);
return index;
}
@ -302,7 +295,6 @@ private:
};
private:
KernelCore& m_kernel;
std::array<EntryInfo, MaxTableSize> m_entry_infos{};
std::array<KAutoObject*, MaxTableSize> m_objects{};
mutable KSpinLock m_lock;

View File

@ -564,7 +564,7 @@ private:
Result InitializeHandleTable(s32 size) {
// Try to initialize the handle table.
R_TRY(m_handle_table.Initialize(size));
R_TRY(m_handle_table.Initialize(m_kernel, size));
// We succeeded, so note that we did.
m_is_handle_table_initialized = true;
@ -573,7 +573,7 @@ private:
void FinalizeHandleTable() {
// Finalize the table.
m_handle_table.Finalize();
m_handle_table.Finalize(m_kernel);
// Note that the table is finalized.
m_is_handle_table_initialized = false;

View File

@ -159,7 +159,7 @@ private:
};
template <bool MoveHandleAllowed>
Result ProcessMessageSpecialData(s32& offset, KProcess& dst_process, KProcess& src_process,
Result ProcessMessageSpecialData(KernelCore& kernel, s32& offset, KProcess& dst_process, KProcess& src_process,
KThread& src_thread, const MessageBuffer& dst_msg,
const MessageBuffer& src_msg,
const MessageBuffer::SpecialHeader& src_special_header) {
@ -185,10 +185,9 @@ Result ProcessMessageSpecialData(s32& offset, KProcess& dst_process, KProcess& s
// If we're in a success state, try to move the handle to the new table.
if (R_SUCCEEDED(result) && src_handle != Svc::InvalidHandle) {
KScopedAutoObject obj =
src_handle_table.GetObjectForIpc(src_handle, std::addressof(src_thread));
src_handle_table.GetObjectForIpc(kernel, src_handle, std::addressof(src_thread));
if (obj.IsNotNull()) {
Result add_result =
dst_handle_table.Add(std::addressof(dst_handle), obj.GetPointerUnsafe());
Result add_result = dst_handle_table.Add(kernel, std::addressof(dst_handle), obj.GetPointerUnsafe());
if (R_FAILED(add_result)) {
result = add_result;
dst_handle = Svc::InvalidHandle;
@ -213,12 +212,10 @@ Result ProcessMessageSpecialData(s32& offset, KProcess& dst_process, KProcess& s
if (src_handle != Svc::InvalidHandle) {
if (R_SUCCEEDED(result)) {
KScopedAutoObject obj =
src_handle_table.GetObjectForIpcWithoutPseudoHandle(src_handle);
src_handle_table.GetObjectForIpcWithoutPseudoHandle(kernel, src_handle);
if (obj.IsNotNull()) {
Result add_result = dst_handle_table.Add(std::addressof(dst_handle),
obj.GetPointerUnsafe());
src_handle_table.Remove(src_handle);
Result add_result = dst_handle_table.Add(kernel, std::addressof(dst_handle), obj.GetPointerUnsafe());
src_handle_table.Remove(kernel, src_handle);
if (R_FAILED(add_result)) {
result = add_result;
@ -228,7 +225,7 @@ Result ProcessMessageSpecialData(s32& offset, KProcess& dst_process, KProcess& s
result = ResultInvalidHandle;
}
} else {
src_handle_table.Remove(src_handle);
src_handle_table.Remove(kernel, src_handle);
}
}
@ -336,7 +333,7 @@ constexpr Result GetMapAliasTestStateAndAttributeMask(KMemoryState& out_state,
R_SUCCEED();
}
void CleanupSpecialData(KProcess& dst_process, u32* dst_msg_ptr, size_t dst_buffer_size) {
void CleanupSpecialData(KernelCore& kernel, KProcess& dst_process, u32* dst_msg_ptr, size_t dst_buffer_size) {
// Parse the message.
const MessageBuffer dst_msg(dst_msg_ptr, dst_buffer_size);
const MessageBuffer::MessageHeader dst_header(dst_msg);
@ -363,15 +360,14 @@ void CleanupSpecialData(KProcess& dst_process, u32* dst_msg_ptr, size_t dst_buff
const Handle handle = dst_msg.GetHandle(offset);
if (handle != Svc::InvalidHandle) {
dst_handle_table.Remove(handle);
dst_handle_table.Remove(kernel, handle);
}
offset = dst_msg.SetHandle(offset, Svc::InvalidHandle);
}
}
Result CleanupServerHandles(KernelCore& kernel, uint64_t message, size_t buffer_size,
KPhysicalAddress message_paddr) {
Result CleanupServerHandles(KernelCore& kernel, uint64_t message, size_t buffer_size, KPhysicalAddress message_paddr) {
// Server is assumed to be current thread.
KThread& thread = GetCurrentThread(kernel);
@ -410,7 +406,7 @@ Result CleanupServerHandles(KernelCore& kernel, uint64_t message, size_t buffer_
// Close the handles.
for (auto i = 0; i < special_header.GetMoveHandleCount(); ++i) {
handle_table.Remove(msg.GetHandle(offset));
handle_table.Remove(kernel, msg.GetHandle(offset));
offset += static_cast<int>(sizeof(Svc::Handle) / sizeof(u32));
}
}
@ -639,7 +635,7 @@ Result ReceiveMessage(KernelCore& kernel, bool& recv_list_broken, uint64_t dst_m
// Cleanup special data.
if (src_header.GetHasSpecialHeader()) {
CleanupSpecialData(dst_process, dst_msg_ptr, dst_buffer_size);
CleanupSpecialData(kernel, dst_process, dst_msg_ptr, dst_buffer_size);
}
// Cleanup the header if the receive list isn't broken.
@ -661,7 +657,7 @@ Result ReceiveMessage(KernelCore& kernel, bool& recv_list_broken, uint64_t dst_m
};
// Process special data.
R_TRY(ProcessMessageSpecialData<false>(offset, dst_process, src_process, src_thread,
R_TRY(ProcessMessageSpecialData<false>(kernel, offset, dst_process, src_process, src_thread,
dst_msg, src_msg, src_special_header));
}
@ -922,7 +918,7 @@ Result SendMessage(KernelCore& kernel, uint64_t src_message_buffer, size_t src_b
// Cleanup special data.
if (processed_special_data) {
if (src_header.GetHasSpecialHeader()) {
CleanupSpecialData(dst_process, dst_msg_ptr, dst_buffer_size);
CleanupSpecialData(kernel, dst_process, dst_msg_ptr, dst_buffer_size);
}
} else {
CleanupServerHandles(kernel, src_user ? src_message_buffer : 0, src_buffer_size,
@ -987,7 +983,7 @@ Result SendMessage(KernelCore& kernel, uint64_t src_message_buffer, size_t src_b
ASSERT(GetCurrentThreadPointer(kernel) == std::addressof(src_thread));
processed_special_data = true;
if (src_header.GetHasSpecialHeader()) {
R_TRY(ProcessMessageSpecialData<true>(offset, dst_process, src_process, src_thread,
R_TRY(ProcessMessageSpecialData<true>(kernel, offset, dst_process, src_process, src_thread,
dst_msg, src_msg, src_special_header));
}

View File

@ -22,13 +22,11 @@ Result SetThreadActivity(Core::System& system, Handle thread_handle,
R_UNLESS(IsValidThreadActivity(thread_activity), ResultInvalidEnumValue);
// Get the thread from its handle.
KScopedAutoObject thread =
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(thread_handle);
KScopedAutoObject thread = GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(system.Kernel(), thread_handle);
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
// Check that the activity is being set on a non-current thread for the current process.
R_UNLESS(thread->GetOwnerProcess() == GetCurrentProcessPointer(system.Kernel()),
ResultInvalidHandle);
R_UNLESS(thread->GetOwnerProcess() == GetCurrentProcessPointer(system.Kernel()), ResultInvalidHandle);
R_UNLESS(thread.GetPointerUnsafe() != GetCurrentThreadPointer(system.Kernel()), ResultBusy);
// Set the activity.

View File

@ -37,8 +37,7 @@ Result FlushProcessDataCache(Core::System& system, Handle process_handle, u64 ad
R_UNLESS(size == static_cast<uint64_t>(size), ResultInvalidCurrentMemory);
// Get the process from its handle.
KScopedAutoObject process =
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(process_handle);
KScopedAutoObject process = GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(system.Kernel(), process_handle);
R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
// Verify the region is within range.

View File

@ -63,7 +63,7 @@ Result CreateCodeMemory(Core::System& system, Handle* out, u64 address, uint64_t
KCodeMemory::Register(kernel, code_mem);
// Add the code memory to the handle table.
R_TRY(GetCurrentProcess(system.Kernel()).GetHandleTable().Add(out, code_mem));
R_TRY(GetCurrentProcess(system.Kernel()).GetHandleTable().Add(system.Kernel(), out, code_mem));
R_SUCCEED();
}
@ -85,8 +85,8 @@ Result ControlCodeMemory(Core::System& system, Handle code_memory_handle,
// Get the code memory from its handle.
KScopedAutoObject code_mem = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KCodeMemory>(code_memory_handle);
.GetHandleTable()
.GetObject<KCodeMemory>(system.Kernel(), code_memory_handle);
R_UNLESS(code_mem.IsNotNull(), ResultInvalidHandle);
// NOTE: Here, Atmosphere extends the SVC to allow code memory operations on one's own process.

View File

@ -39,7 +39,7 @@ Result CreateDeviceAddressSpace(Core::System& system, Handle* out, uint64_t das_
KDeviceAddressSpace::Register(system.Kernel(), das);
// Add to the handle table.
R_TRY(GetCurrentProcess(system.Kernel()).GetHandleTable().Add(out, das));
R_TRY(GetCurrentProcess(system.Kernel()).GetHandleTable().Add(system.Kernel(), out, das));
R_SUCCEED();
}
@ -47,8 +47,8 @@ Result CreateDeviceAddressSpace(Core::System& system, Handle* out, uint64_t das_
Result AttachDeviceAddressSpace(Core::System& system, DeviceName device_name, Handle das_handle) {
// Get the device address space.
KScopedAutoObject das = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KDeviceAddressSpace>(das_handle);
.GetHandleTable()
.GetObject<KDeviceAddressSpace>(system.Kernel(), das_handle);
R_UNLESS(das.IsNotNull(), ResultInvalidHandle);
// Attach.
@ -58,8 +58,8 @@ Result AttachDeviceAddressSpace(Core::System& system, DeviceName device_name, Ha
Result DetachDeviceAddressSpace(Core::System& system, DeviceName device_name, Handle das_handle) {
// Get the device address space.
KScopedAutoObject das = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KDeviceAddressSpace>(das_handle);
.GetHandleTable()
.GetObject<KDeviceAddressSpace>(system.Kernel(), das_handle);
R_UNLESS(das.IsNotNull(), ResultInvalidHandle);
// Detach.
@ -99,13 +99,13 @@ Result MapDeviceAddressSpaceByForce(Core::System& system, Handle das_handle, Han
// Get the device address space.
KScopedAutoObject das = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KDeviceAddressSpace>(das_handle);
.GetHandleTable()
.GetObject<KDeviceAddressSpace>(system.Kernel(), das_handle);
R_UNLESS(das.IsNotNull(), ResultInvalidHandle);
// Get the process.
KScopedAutoObject process =
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(process_handle);
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(system.Kernel(), process_handle);
R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
// Validate that the process address is within range.
@ -140,13 +140,13 @@ Result MapDeviceAddressSpaceAligned(Core::System& system, Handle das_handle, Han
// Get the device address space.
KScopedAutoObject das = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KDeviceAddressSpace>(das_handle);
.GetHandleTable()
.GetObject<KDeviceAddressSpace>(system.Kernel(), das_handle);
R_UNLESS(das.IsNotNull(), ResultInvalidHandle);
// Get the process.
KScopedAutoObject process =
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(process_handle);
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(system.Kernel(), process_handle);
R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
// Validate that the process address is within range.
@ -172,13 +172,12 @@ Result UnmapDeviceAddressSpace(Core::System& system, Handle das_handle, Handle p
// Get the device address space.
KScopedAutoObject das = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KDeviceAddressSpace>(das_handle);
.GetHandleTable()
.GetObject<KDeviceAddressSpace>(system.Kernel(), das_handle);
R_UNLESS(das.IsNotNull(), ResultInvalidHandle);
// Get the process.
KScopedAutoObject process =
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(process_handle);
KScopedAutoObject process = GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(system.Kernel(), process_handle);
R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
// Validate that the process address is within range.

View File

@ -22,7 +22,7 @@ Result SignalEvent(Core::System& system, Handle event_handle) {
// Fail-safe for system applets
const auto program_id = GetCurrentProcess(system.Kernel()).GetProgramId();
if ((program_id & 0xFFFFFFFFFFFFFF00ull) == 0x0100000000001000ull) {
KScopedAutoObject event = handle_table.GetObject<KEvent>(event_handle);
KScopedAutoObject event = handle_table.GetObject<KEvent>(system.Kernel(), event_handle);
if (event.IsNotNull()) {
event->Signal();
} else {
@ -34,7 +34,7 @@ Result SignalEvent(Core::System& system, Handle event_handle) {
// Get the event.
KScopedAutoObject event = handle_table.GetObject<KEvent>(event_handle);
KScopedAutoObject event = handle_table.GetObject<KEvent>(system.Kernel(), event_handle);
R_UNLESS(event.IsNotNull(), ResultInvalidHandle);
R_RETURN(event->Signal());
@ -48,7 +48,7 @@ Result ClearEvent(Core::System& system, Handle event_handle) {
// Try to clear the writable event.
{
KScopedAutoObject event = handle_table.GetObject<KEvent>(event_handle);
KScopedAutoObject event = handle_table.GetObject<KEvent>(system.Kernel(), event_handle);
if (event.IsNotNull()) {
event->Clear();
R_SUCCEED();
@ -57,7 +57,7 @@ Result ClearEvent(Core::System& system, Handle event_handle) {
// Try to clear the readable event.
{
KScopedAutoObject readable_event = handle_table.GetObject<KReadableEvent>(event_handle);
KScopedAutoObject readable_event = handle_table.GetObject<KReadableEvent>(system.Kernel(), event_handle);
if (readable_event.IsNotNull()) {
readable_event->Clear();
R_SUCCEED();
@ -99,15 +99,15 @@ Result CreateEvent(Core::System& system, Handle* out_write, Handle* out_read) {
KEvent::Register(kernel, event);
// Add the event to the handle table.
R_TRY(handle_table.Add(out_write, event));
R_TRY(handle_table.Add(system.Kernel(), out_write, event));
// Ensure that we maintain a clean handle state on exit.
ON_RESULT_FAILURE {
handle_table.Remove(*out_write);
handle_table.Remove(system.Kernel(), *out_write);
};
// Add the readable event to the handle table.
R_RETURN(handle_table.Add(out_read, std::addressof(event->GetReadableEvent())));
R_RETURN(handle_table.Add(system.Kernel(), out_read, std::addressof(event->GetReadableEvent())));
}
Result SignalEvent64(Core::System& system, Handle event_handle) {

View File

@ -46,7 +46,7 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle
R_UNLESS(info_sub_id == 0, ResultInvalidEnumValue);
const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
KScopedAutoObject process = handle_table.GetObject<KProcess>(handle);
KScopedAutoObject process = handle_table.GetObject<KProcess>(system.Kernel(), handle);
R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
switch (info_id_type) {
@ -175,7 +175,7 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle
}
Handle resource_handle{};
R_TRY(handle_table.Add(std::addressof(resource_handle), resource_limit));
R_TRY(handle_table.Add(system.Kernel(), std::addressof(resource_handle), resource_limit));
*result = resource_handle;
R_SUCCEED();
@ -203,8 +203,8 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle
}
KScopedAutoObject thread = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KThread>(static_cast<Handle>(handle));
.GetHandleTable()
.GetObject<KThread>(system.Kernel(), Handle(handle));
if (thread.IsNull()) {
LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}",
static_cast<Handle>(handle));
@ -256,7 +256,7 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle
// Get a new handle for the current process.
Handle tmp;
R_TRY(handle_table.Add(std::addressof(tmp), current_process));
R_TRY(handle_table.Add(system.Kernel(), std::addressof(tmp), current_process));
// Set the output.
*result = tmp;

View File

@ -20,11 +20,9 @@ namespace Kernel::Svc {
namespace {
Result SendSyncRequestImpl(KernelCore& kernel, uintptr_t message, size_t buffer_size,
Handle session_handle) {
Result SendSyncRequestImpl(KernelCore& kernel, uintptr_t message, size_t buffer_size, Handle session_handle) {
// Get the client session.
KScopedAutoObject session =
GetCurrentProcess(kernel).GetHandleTable().GetObject<KClientSession>(session_handle);
KScopedAutoObject session = GetCurrentProcess(kernel).GetHandleTable().GetObject<KClientSession>(kernel, session_handle);
R_UNLESS(session.IsNotNull(), ResultInvalidHandle);
// Get the parent, and persist a reference to it until we're done.
@ -41,8 +39,7 @@ Result ReplyAndReceiveImpl(KernelCore& kernel, int32_t* out_index, uintptr_t mes
int64_t timeout_ns) {
// Reply to the target, if one is specified.
if (reply_target != InvalidHandle) {
KScopedAutoObject session =
GetCurrentProcess(kernel).GetHandleTable().GetObject<KServerSession>(reply_target);
KScopedAutoObject session = GetCurrentProcess(kernel).GetHandleTable().GetObject<KServerSession>(kernel, reply_target);
R_UNLESS(session.IsNotNull(), ResultInvalidHandle);
// If we fail to reply, we want to set the output index to -1.
@ -127,7 +124,7 @@ Result ReplyAndReceiveImpl(KernelCore& kernel, int32_t* out_index, uintptr_t mes
// Convert the handles to objects.
R_UNLESS(
handle_table.GetMultipleObjects<KSynchronizationObject>(objs, handles, num_handles),
handle_table.GetMultipleObjects<KSynchronizationObject>(kernel, objs, handles, num_handles),
ResultInvalidHandle);
}
@ -193,7 +190,7 @@ Result SendAsyncRequestWithUserBuffer(Core::System& system, Handle* out_event_ha
R_UNLESS(event_reservation.Succeeded(), ResultLimitReached);
// Get the client session.
KScopedAutoObject session = process.GetHandleTable().GetObject<KClientSession>(session_handle);
KScopedAutoObject session = process.GetHandleTable().GetObject<KClientSession>(system.Kernel(), session_handle);
R_UNLESS(session.IsNotNull(), ResultInvalidHandle);
// Get the parent, and persist a reference to it until we're done.
@ -220,11 +217,11 @@ Result SendAsyncRequestWithUserBuffer(Core::System& system, Handle* out_event_ha
KEvent::Register(system.Kernel(), event);
// Add the readable event to the handle table.
R_TRY(handle_table.Add(out_event_handle, std::addressof(event->GetReadableEvent())));
R_TRY(handle_table.Add(system.Kernel(), out_event_handle, std::addressof(event->GetReadableEvent())));
// Ensure that if we fail to send the request, we close the readable handle.
ON_RESULT_FAILURE {
handle_table.Remove(*out_event_handle);
handle_table.Remove(system.Kernel(), *out_event_handle);
};
// Send the async request.

View File

@ -33,9 +33,9 @@ Result ConnectToNamedPort(Core::System& system, Handle* out, u64 user_name) {
// Reserve a handle for the port.
// NOTE: Nintendo really does write directly to the output handle here.
R_TRY(handle_table.Reserve(out));
R_TRY(handle_table.Reserve(system.Kernel(), out));
ON_RESULT_FAILURE {
handle_table.Unreserve(*out);
handle_table.Unreserve(system.Kernel(), *out);
};
// Create a session.
@ -43,7 +43,7 @@ Result ConnectToNamedPort(Core::System& system, Handle* out, u64 user_name) {
R_TRY(port->CreateSession(std::addressof(session)));
// Register the session in the table, close the extra reference.
handle_table.Register(*out, session);
handle_table.Register(system.Kernel(), *out, session);
session->Close();
// We succeeded.
@ -77,15 +77,15 @@ Result CreatePort(Core::System& system, Handle* out_server, Handle* out_client,
KPort::Register(kernel, port);
// Add the client to the handle table.
R_TRY(handle_table.Add(out_client, std::addressof(port->GetClientPort())));
R_TRY(handle_table.Add(system.Kernel(), out_client, std::addressof(port->GetClientPort())));
// Ensure that we maintain a clean handle state on exit.
ON_RESULT_FAILURE {
handle_table.Remove(*out_client);
handle_table.Remove(system.Kernel(), *out_client);
};
// Add the server to the handle table.
R_RETURN(handle_table.Add(out_server, std::addressof(port->GetServerPort())));
R_RETURN(handle_table.Add(system.Kernel(), out_server, std::addressof(port->GetServerPort())));
}
Result ConnectToPort(Core::System& system, Handle* out, Handle port) {
@ -93,14 +93,14 @@ Result ConnectToPort(Core::System& system, Handle* out, Handle port) {
auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
// Get the client port.
KScopedAutoObject client_port = handle_table.GetObject<KClientPort>(port);
KScopedAutoObject client_port = handle_table.GetObject<KClientPort>(system.Kernel(), port);
R_UNLESS(client_port.IsNotNull(), ResultInvalidHandle);
// Reserve a handle for the port.
// NOTE: Nintendo really does write directly to the output handle here.
R_TRY(handle_table.Reserve(out));
R_TRY(handle_table.Reserve(system.Kernel(), out));
ON_RESULT_FAILURE {
handle_table.Unreserve(*out);
handle_table.Unreserve(system.Kernel(), *out);
};
// Create the session.
@ -114,15 +114,14 @@ Result ConnectToPort(Core::System& system, Handle* out, Handle port) {
}
// Register the session.
handle_table.Register(*out, session);
handle_table.Register(system.Kernel(), *out, session);
session->Close();
// We succeeded.
R_SUCCEED();
}
Result ManageNamedPort(Core::System& system, Handle* out_server_handle, uint64_t user_name,
int32_t max_sessions) {
Result ManageNamedPort(Core::System& system, Handle* out_server_handle, uint64_t user_name, int32_t max_sessions) {
// Copy the provided name from user memory to kernel memory.
auto string_name =
GetCurrentMemory(system.Kernel()).ReadCString(user_name, KObjectName::NameLengthMax);
@ -156,9 +155,9 @@ Result ManageNamedPort(Core::System& system, Handle* out_server_handle, uint64_t
};
// Register the handle in the table.
R_TRY(handle_table.Add(out_server_handle, std::addressof(port->GetServerPort())));
R_TRY(handle_table.Add(system.Kernel(), out_server_handle, std::addressof(port->GetServerPort())));
ON_RESULT_FAILURE {
handle_table.Remove(*out_server_handle);
handle_table.Remove(system.Kernel(), *out_server_handle);
};
// Create a new object name.

View File

@ -27,8 +27,8 @@ Result GetProcessId(Core::System& system, u64* out_process_id, Handle handle) {
// Get the object from the handle table.
KScopedAutoObject obj = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KAutoObject>(static_cast<Handle>(handle));
.GetHandleTable()
.GetObject<KAutoObject>(system.Kernel(), Handle(handle));
R_UNLESS(obj.IsNotNull(), ResultInvalidHandle);
// Get the process from the object.
@ -98,7 +98,7 @@ Result GetProcessInfo(Core::System& system, s64* out, Handle process_handle,
LOG_DEBUG(Kernel_SVC, "called, handle=0x{:08X}, type={:#X}", process_handle, info_type);
const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
KScopedAutoObject process = handle_table.GetObject<KProcess>(process_handle);
KScopedAutoObject process = handle_table.GetObject<KProcess>(system.Kernel(), process_handle);
if (process.IsNull()) {
LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}",
process_handle);

View File

@ -48,7 +48,7 @@ Result SetProcessMemoryPermission(Core::System& system, Handle process_handle, u
// Get the process from its handle.
KScopedAutoObject process =
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(process_handle);
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(system.Kernel(), process_handle);
R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
// Validate that the address is in range.
@ -76,7 +76,7 @@ Result MapProcessMemory(Core::System& system, u64 dst_address, Handle process_ha
// Get the processes.
KProcess* dst_process = GetCurrentProcessPointer(system.Kernel());
KScopedAutoObject src_process =
dst_process->GetHandleTable().GetObjectWithoutPseudoHandle<KProcess>(process_handle);
dst_process->GetHandleTable().GetObjectWithoutPseudoHandle<KProcess>(system.Kernel(), process_handle);
R_UNLESS(src_process.IsNotNull(), ResultInvalidHandle);
// Get the page tables.
@ -117,7 +117,7 @@ Result UnmapProcessMemory(Core::System& system, u64 dst_address, Handle process_
// Get the processes.
KProcess* dst_process = GetCurrentProcessPointer(system.Kernel());
KScopedAutoObject src_process =
dst_process->GetHandleTable().GetObjectWithoutPseudoHandle<KProcess>(process_handle);
dst_process->GetHandleTable().GetObjectWithoutPseudoHandle<KProcess>(system.Kernel(), process_handle);
R_UNLESS(src_process.IsNotNull(), ResultInvalidHandle);
// Get the page tables.
@ -174,7 +174,7 @@ Result MapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst
}
const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
KScopedAutoObject process = handle_table.GetObject<KProcess>(process_handle);
KScopedAutoObject process = handle_table.GetObject<KProcess>(system.Kernel(), process_handle);
if (process.IsNull()) {
LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).",
process_handle);
@ -234,7 +234,7 @@ Result UnmapProcessCodeMemory(Core::System& system, Handle process_handle, u64 d
}
const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
KScopedAutoObject process = handle_table.GetObject<KProcess>(process_handle);
KScopedAutoObject process = handle_table.GetObject<KProcess>(system.Kernel(), process_handle);
if (process.IsNull()) {
LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).",
process_handle);

View File

@ -23,7 +23,7 @@ Result QueryProcessMemory(Core::System& system, uint64_t out_memory_info, PageIn
Handle process_handle, uint64_t address) {
LOG_TRACE(Kernel_SVC, "called process=0x{:08X} address={:X}", process_handle, address);
const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
KScopedAutoObject process = handle_table.GetObject<KProcess>(process_handle);
KScopedAutoObject process = handle_table.GetObject<KProcess>(system.Kernel(), process_handle);
if (process.IsNull()) {
LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}",
process_handle);

View File

@ -29,7 +29,7 @@ Result CreateResourceLimit(Core::System& system, Handle* out_handle) {
KResourceLimit::Register(kernel, resource_limit);
// Add the limit to the handle table.
R_RETURN(GetCurrentProcess(kernel).GetHandleTable().Add(out_handle, resource_limit));
R_RETURN(GetCurrentProcess(kernel).GetHandleTable().Add(system.Kernel(), out_handle, resource_limit));
}
Result GetResourceLimitLimitValue(Core::System& system, s64* out_limit_value,
@ -42,8 +42,8 @@ Result GetResourceLimitLimitValue(Core::System& system, s64* out_limit_value,
// Get the resource limit.
KScopedAutoObject resource_limit = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KResourceLimit>(resource_limit_handle);
.GetHandleTable()
.GetObject<KResourceLimit>(system.Kernel(), resource_limit_handle);
R_UNLESS(resource_limit.IsNotNull(), ResultInvalidHandle);
// Get the limit value.
@ -62,8 +62,8 @@ Result GetResourceLimitCurrentValue(Core::System& system, s64* out_current_value
// Get the resource limit.
KScopedAutoObject resource_limit = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KResourceLimit>(resource_limit_handle);
.GetHandleTable()
.GetObject<KResourceLimit>(system.Kernel(), resource_limit_handle);
R_UNLESS(resource_limit.IsNotNull(), ResultInvalidHandle);
// Get the current value.
@ -83,7 +83,7 @@ Result SetResourceLimitLimitValue(Core::System& system, Handle resource_limit_ha
// Get the resource limit.
KScopedAutoObject resource_limit = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KResourceLimit>(resource_limit_handle);
.GetObject<KResourceLimit>(system.Kernel(), resource_limit_handle);
R_UNLESS(resource_limit.IsNotNull(), ResultInvalidHandle);
// Set the limit value.

View File

@ -78,15 +78,15 @@ Result CreateSession(Core::System& system, Handle* out_server, Handle* out_clien
T::Register(system.Kernel(), session);
// Add the server session to the handle table.
R_TRY(handle_table.Add(out_server, std::addressof(session->GetServerSession())));
R_TRY(handle_table.Add(system.Kernel(), out_server, std::addressof(session->GetServerSession())));
// Ensure that we maintain a clean handle state on exit.
ON_RESULT_FAILURE {
handle_table.Remove(*out_server);
handle_table.Remove(system.Kernel(), *out_server);
};
// Add the client session to the handle table.
R_RETURN(handle_table.Add(out_client, std::addressof(session->GetClientSession())));
R_RETURN(handle_table.Add(system.Kernel(), out_client, std::addressof(session->GetClientSession())));
}
} // namespace
@ -105,13 +105,13 @@ Result AcceptSession(Core::System& system, Handle* out, Handle port_handle) {
auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
// Get the server port.
KScopedAutoObject port = handle_table.GetObject<KServerPort>(port_handle);
KScopedAutoObject port = handle_table.GetObject<KServerPort>(system.Kernel(), port_handle);
R_UNLESS(port.IsNotNull(), ResultInvalidHandle);
// Reserve an entry for the new session.
R_TRY(handle_table.Reserve(out));
R_TRY(handle_table.Reserve(system.Kernel(), out));
ON_RESULT_FAILURE {
handle_table.Unreserve(*out);
handle_table.Unreserve(system.Kernel(), *out);
};
// Accept the session.
@ -126,7 +126,7 @@ Result AcceptSession(Core::System& system, Handle* out, Handle port_handle) {
R_UNLESS(session != nullptr, ResultNotFound);
// Register the session.
handle_table.Register(*out, session);
handle_table.Register(system.Kernel(), *out, session);
session->Close();
R_SUCCEED();

View File

@ -49,7 +49,7 @@ Result MapSharedMemory(Core::System& system, Handle shmem_handle, u64 address, u
auto& page_table = process.GetPageTable();
// Get the shared memory.
KScopedAutoObject shmem = process.GetHandleTable().GetObject<KSharedMemory>(shmem_handle);
KScopedAutoObject shmem = process.GetHandleTable().GetObject<KSharedMemory>(system.Kernel(), shmem_handle);
R_UNLESS(shmem.IsNotNull(), ResultInvalidHandle);
// Verify that the mapping is in range.
@ -79,7 +79,7 @@ Result UnmapSharedMemory(Core::System& system, Handle shmem_handle, u64 address,
auto& page_table = process.GetPageTable();
// Get the shared memory.
KScopedAutoObject shmem = process.GetHandleTable().GetObject<KSharedMemory>(shmem_handle);
KScopedAutoObject shmem = process.GetHandleTable().GetObject<KSharedMemory>(system.Kernel(), shmem_handle);
R_UNLESS(shmem.IsNotNull(), ResultInvalidHandle);
// Verify that the mapping is in range.

View File

@ -20,7 +20,7 @@ Result CloseHandle(Core::System& system, Handle handle) {
LOG_TRACE(Kernel_SVC, "Closing handle 0x{:08X}", handle);
// Remove the handle.
R_UNLESS(GetCurrentProcess(system.Kernel()).GetHandleTable().Remove(handle),
R_UNLESS(GetCurrentProcess(system.Kernel()).GetHandleTable().Remove(system.Kernel(), handle),
ResultInvalidHandle);
R_SUCCEED();
@ -35,7 +35,7 @@ Result ResetSignal(Core::System& system, Handle handle) {
// Try to reset as readable event.
{
KScopedAutoObject readable_event = handle_table.GetObject<KReadableEvent>(handle);
KScopedAutoObject readable_event = handle_table.GetObject<KReadableEvent>(system.Kernel(), handle);
if (readable_event.IsNotNull()) {
R_RETURN(readable_event->Reset());
}
@ -43,7 +43,7 @@ Result ResetSignal(Core::System& system, Handle handle) {
// Try to reset as process.
{
KScopedAutoObject process = handle_table.GetObject<KProcess>(handle);
KScopedAutoObject process = handle_table.GetObject<KProcess>(system.Kernel(), handle);
if (process.IsNotNull()) {
R_RETURN(process->Reset());
}
@ -75,9 +75,7 @@ Result WaitSynchronization(Core::System& system, int32_t* out_index, u64 user_ha
ResultInvalidPointer);
// Convert the handles to objects.
R_UNLESS(handle_table.GetMultipleObjects<KSynchronizationObject>(
objs.data(), handles.data(), num_handles),
ResultInvalidHandle);
R_UNLESS(handle_table.GetMultipleObjects<KSynchronizationObject>(system.Kernel(), objs.data(), handles.data(), num_handles), ResultInvalidHandle);
}
// Ensure handles are closed when we're done.
@ -112,7 +110,7 @@ Result CancelSynchronization(Core::System& system, Handle handle) {
// Get the thread from its handle.
KScopedAutoObject thread =
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(handle);
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(system.Kernel(), handle);
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
// Cancel the thread's wait.

View File

@ -75,7 +75,7 @@ Result CreateThread(Core::System& system, Handle* out_handle, u64 entry_point, u
KThread::Register(kernel, thread);
// Add the thread to the handle table.
R_TRY(process.GetHandleTable().Add(out_handle, thread));
R_TRY(process.GetHandleTable().Add(system.Kernel(), out_handle, thread));
// Pass the thread handle to the thread local region.
process.GetMemory().Write32(GetInteger(thread->GetTlsAddress()) + 0x110, *out_handle);
@ -88,8 +88,7 @@ Result StartThread(Core::System& system, Handle thread_handle) {
LOG_DEBUG(Kernel_SVC, "called thread=0x{:08X}", thread_handle);
// Get the thread from its handle.
KScopedAutoObject thread =
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(thread_handle);
KScopedAutoObject thread = GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(system.Kernel(), thread_handle);
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
// Try to start the thread.
@ -150,8 +149,7 @@ Result GetThreadContext3(Core::System& system, u64 out_context, Handle thread_ha
auto& kernel = system.Kernel();
// Get the thread from its handle.
KScopedAutoObject thread =
GetCurrentProcess(kernel).GetHandleTable().GetObject<KThread>(thread_handle);
KScopedAutoObject thread = GetCurrentProcess(kernel).GetHandleTable().GetObject<KThread>(system.Kernel(), thread_handle);
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
// Require the handle be to a non-current thread in the current process.
@ -175,8 +173,7 @@ Result GetThreadPriority(Core::System& system, s32* out_priority, Handle handle)
LOG_TRACE(Kernel_SVC, "called");
// Get the thread from its handle.
KScopedAutoObject thread =
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(handle);
KScopedAutoObject thread = GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(system.Kernel(), handle);
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
// Get the thread's priority.
@ -195,7 +192,7 @@ Result SetThreadPriority(Core::System& system, Handle thread_handle, s32 priorit
R_UNLESS(process.CheckThreadPriority(priority), ResultInvalidPriority);
// Get the thread from its handle.
KScopedAutoObject thread = process.GetHandleTable().GetObject<KThread>(thread_handle);
KScopedAutoObject thread = process.GetHandleTable().GetObject<KThread>(system.Kernel(), thread_handle);
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
// Set the thread priority.
@ -248,8 +245,7 @@ Result GetThreadCoreMask(Core::System& system, s32* out_core_id, u64* out_affini
LOG_TRACE(Kernel_SVC, "called, handle=0x{:08X}", thread_handle);
// Get the thread from its handle.
KScopedAutoObject thread =
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(thread_handle);
KScopedAutoObject thread = GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(system.Kernel(), thread_handle);
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
// Get the core mask.
@ -279,7 +275,7 @@ Result SetThreadCoreMask(Core::System& system, Handle thread_handle, s32 core_id
// Get the thread from its handle.
KScopedAutoObject thread =
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(thread_handle);
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(system.Kernel(), thread_handle);
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
// Set the core mask.
@ -289,8 +285,7 @@ Result SetThreadCoreMask(Core::System& system, Handle thread_handle, s32 core_id
/// Get the ID for the specified thread.
Result GetThreadId(Core::System& system, u64* out_thread_id, Handle thread_handle) {
// Get the thread from its handle.
KScopedAutoObject thread =
GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(thread_handle);
KScopedAutoObject thread = GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(system.Kernel(), thread_handle);
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
// Get the thread's id.

View File

@ -69,7 +69,7 @@ Result CreateTransferMemory(Core::System& system, Handle* out, u64 address, u64
KTransferMemory::Register(kernel, trmem);
// Add the transfer memory to the handle table.
R_RETURN(handle_table.Add(out, trmem));
R_RETURN(handle_table.Add(system.Kernel(), out, trmem));
}
Result MapTransferMemory(Core::System& system, Handle trmem_handle, uint64_t address, uint64_t size,
@ -86,7 +86,7 @@ Result MapTransferMemory(Core::System& system, Handle trmem_handle, uint64_t add
// Get the transfer memory.
KScopedAutoObject trmem = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KTransferMemory>(trmem_handle);
.GetObject<KTransferMemory>(system.Kernel(), trmem_handle);
R_UNLESS(trmem.IsNotNull(), ResultInvalidHandle);
// Verify that the mapping is in range.
@ -113,7 +113,7 @@ Result UnmapTransferMemory(Core::System& system, Handle trmem_handle, uint64_t a
// Get the transfer memory.
KScopedAutoObject trmem = GetCurrentProcess(system.Kernel())
.GetHandleTable()
.GetObject<KTransferMemory>(trmem_handle);
.GetObject<KTransferMemory>(system.Kernel(), trmem_handle);
R_UNLESS(trmem.IsNotNull(), ResultInvalidHandle);
// Verify that the mapping is in range.

View File

@ -275,14 +275,14 @@ Result HLERequestContext::WriteToOutgoingCommandBuffer() {
for (auto& object : outgoing_copy_objects) {
Handle handle{};
if (object) {
R_TRY(handle_table.Add(&handle, object));
R_TRY(handle_table.Add(kernel, &handle, object));
}
cmd_buf[current_offset++] = handle;
}
for (auto& object : outgoing_move_objects) {
Handle handle{};
if (object) {
R_TRY(handle_table.Add(&handle, object));
R_TRY(handle_table.Add(kernel, &handle, object));
// Close our reference to the object, as it is being moved to the caller.
object->Close();

View File

@ -373,7 +373,7 @@ public:
template <typename T>
Kernel::KScopedAutoObject<T> GetObjectFromHandle(u32 handle) {
auto obj = client_handle_table->GetObjectForIpc(handle, thread);
auto obj = client_handle_table->GetObjectForIpc(kernel, handle, thread);
if (obj.IsNotNull()) {
return obj->DynamicCast<T*>();
}