yuzu-emu
/
yuzu-mainline
Archived
1
0
Fork 0

kernel: use GetCurrentProcess

This commit is contained in:
Liam 2023-02-13 10:44:41 -05:00
parent 770a49616d
commit 4363ca304a
34 changed files with 147 additions and 128 deletions

View File

@ -60,6 +60,7 @@ bool KClientPort::IsSignaled() const {
Result KClientPort::CreateSession(KClientSession** out) { Result KClientPort::CreateSession(KClientSession** out) {
// Reserve a new session from the resource limit. // Reserve a new session from the resource limit.
//! FIXME: we are reserving this from the wrong resource limit!
KScopedResourceReservation session_reservation(kernel.CurrentProcess()->GetResourceLimit(), KScopedResourceReservation session_reservation(kernel.CurrentProcess()->GetResourceLimit(),
LimitableResource::SessionCountMax); LimitableResource::SessionCountMax);
R_UNLESS(session_reservation.Succeeded(), ResultLimitReached); R_UNLESS(session_reservation.Succeeded(), ResultLimitReached);

View File

@ -21,7 +21,7 @@ KCodeMemory::KCodeMemory(KernelCore& kernel_)
Result KCodeMemory::Initialize(Core::DeviceMemory& device_memory, VAddr addr, size_t size) { Result KCodeMemory::Initialize(Core::DeviceMemory& device_memory, VAddr addr, size_t size) {
// Set members. // Set members.
m_owner = kernel.CurrentProcess(); m_owner = GetCurrentProcessPointer(kernel);
// Get the owner page table. // Get the owner page table.
auto& page_table = m_owner->PageTable(); auto& page_table = m_owner->PageTable();
@ -74,7 +74,7 @@ Result KCodeMemory::Map(VAddr address, size_t size) {
R_UNLESS(!m_is_mapped, ResultInvalidState); R_UNLESS(!m_is_mapped, ResultInvalidState);
// Map the memory. // Map the memory.
R_TRY(kernel.CurrentProcess()->PageTable().MapPageGroup( R_TRY(GetCurrentProcess(kernel).PageTable().MapPageGroup(
address, *m_page_group, KMemoryState::CodeOut, KMemoryPermission::UserReadWrite)); address, *m_page_group, KMemoryState::CodeOut, KMemoryPermission::UserReadWrite));
// Mark ourselves as mapped. // Mark ourselves as mapped.
@ -91,7 +91,7 @@ Result KCodeMemory::Unmap(VAddr address, size_t size) {
KScopedLightLock lk(m_lock); KScopedLightLock lk(m_lock);
// Unmap the memory. // Unmap the memory.
R_TRY(kernel.CurrentProcess()->PageTable().UnmapPageGroup(address, *m_page_group, R_TRY(GetCurrentProcess(kernel).PageTable().UnmapPageGroup(address, *m_page_group,
KMemoryState::CodeOut)); KMemoryState::CodeOut));
// Mark ourselves as unmapped. // Mark ourselves as unmapped.

View File

@ -164,8 +164,8 @@ Result KConditionVariable::WaitForAddress(Handle handle, VAddr addr, u32 value)
R_SUCCEED_IF(test_tag != (handle | Svc::HandleWaitMask)); R_SUCCEED_IF(test_tag != (handle | Svc::HandleWaitMask));
// Get the lock owner thread. // Get the lock owner thread.
owner_thread = kernel.CurrentProcess() owner_thread = GetCurrentProcess(kernel)
->GetHandleTable() .GetHandleTable()
.GetObjectWithoutPseudoHandle<KThread>(handle) .GetObjectWithoutPseudoHandle<KThread>(handle)
.ReleasePointerUnsafe(); .ReleasePointerUnsafe();
R_UNLESS(owner_thread != nullptr, ResultInvalidHandle); R_UNLESS(owner_thread != nullptr, ResultInvalidHandle);
@ -213,8 +213,8 @@ void KConditionVariable::SignalImpl(KThread* thread) {
thread->EndWait(ResultSuccess); thread->EndWait(ResultSuccess);
} else { } else {
// Get the previous owner. // Get the previous owner.
KThread* owner_thread = kernel.CurrentProcess() KThread* owner_thread = GetCurrentProcess(kernel)
->GetHandleTable() .GetHandleTable()
.GetObjectWithoutPseudoHandle<KThread>( .GetObjectWithoutPseudoHandle<KThread>(
static_cast<Handle>(prev_tag & ~Svc::HandleWaitMask)) static_cast<Handle>(prev_tag & ~Svc::HandleWaitMask))
.ReleasePointerUnsafe(); .ReleasePointerUnsafe();

View File

@ -90,7 +90,7 @@ public:
// Handle pseudo-handles. // Handle pseudo-handles.
if constexpr (std::derived_from<KProcess, T>) { if constexpr (std::derived_from<KProcess, T>) {
if (handle == Svc::PseudoHandle::CurrentProcess) { if (handle == Svc::PseudoHandle::CurrentProcess) {
auto* const cur_process = m_kernel.CurrentProcess(); auto* const cur_process = GetCurrentProcessPointer(m_kernel);
ASSERT(cur_process != nullptr); ASSERT(cur_process != nullptr);
return cur_process; return cur_process;
} }

View File

@ -16,7 +16,7 @@ void HandleInterrupt(KernelCore& kernel, s32 core_id) {
auto& current_thread = GetCurrentThread(kernel); auto& current_thread = GetCurrentThread(kernel);
if (auto* process = kernel.CurrentProcess(); process) { if (auto* process = GetCurrentProcessPointer(kernel); process) {
// If the user disable count is set, we may need to pin the current thread. // If the user disable count is set, we may need to pin the current thread.
if (current_thread.GetUserDisableCount() && !process->GetPinnedThread(core_id)) { if (current_thread.GetUserDisableCount() && !process->GetPinnedThread(core_id)) {
KScopedSchedulerLock sl{kernel}; KScopedSchedulerLock sl{kernel};

View File

@ -328,7 +328,7 @@ u64 KScheduler::UpdateHighestPriorityThreadsImpl(KernelCore& kernel) {
} }
void KScheduler::SwitchThread(KThread* next_thread) { void KScheduler::SwitchThread(KThread* next_thread) {
KProcess* const cur_process = kernel.CurrentProcess(); KProcess* const cur_process = GetCurrentProcessPointer(kernel);
KThread* const cur_thread = GetCurrentThreadPointer(kernel); KThread* const cur_thread = GetCurrentThreadPointer(kernel);
// We never want to schedule a null thread, so use the idle thread if we don't have a next. // We never want to schedule a null thread, so use the idle thread if we don't have a next.
@ -689,11 +689,11 @@ void KScheduler::RotateScheduledQueue(KernelCore& kernel, s32 core_id, s32 prior
void KScheduler::YieldWithoutCoreMigration(KernelCore& kernel) { void KScheduler::YieldWithoutCoreMigration(KernelCore& kernel) {
// Validate preconditions. // Validate preconditions.
ASSERT(CanSchedule(kernel)); ASSERT(CanSchedule(kernel));
ASSERT(kernel.CurrentProcess() != nullptr); ASSERT(GetCurrentProcessPointer(kernel) != nullptr);
// Get the current thread and process. // Get the current thread and process.
KThread& cur_thread = GetCurrentThread(kernel); KThread& cur_thread = GetCurrentThread(kernel);
KProcess& cur_process = *kernel.CurrentProcess(); KProcess& cur_process = GetCurrentProcess(kernel);
// If the thread's yield count matches, there's nothing for us to do. // If the thread's yield count matches, there's nothing for us to do.
if (cur_thread.GetYieldScheduleCount() == cur_process.GetScheduledCount()) { if (cur_thread.GetYieldScheduleCount() == cur_process.GetScheduledCount()) {
@ -728,11 +728,11 @@ void KScheduler::YieldWithoutCoreMigration(KernelCore& kernel) {
void KScheduler::YieldWithCoreMigration(KernelCore& kernel) { void KScheduler::YieldWithCoreMigration(KernelCore& kernel) {
// Validate preconditions. // Validate preconditions.
ASSERT(CanSchedule(kernel)); ASSERT(CanSchedule(kernel));
ASSERT(kernel.CurrentProcess() != nullptr); ASSERT(GetCurrentProcessPointer(kernel) != nullptr);
// Get the current thread and process. // Get the current thread and process.
KThread& cur_thread = GetCurrentThread(kernel); KThread& cur_thread = GetCurrentThread(kernel);
KProcess& cur_process = *kernel.CurrentProcess(); KProcess& cur_process = GetCurrentProcess(kernel);
// If the thread's yield count matches, there's nothing for us to do. // If the thread's yield count matches, there's nothing for us to do.
if (cur_thread.GetYieldScheduleCount() == cur_process.GetScheduledCount()) { if (cur_thread.GetYieldScheduleCount() == cur_process.GetScheduledCount()) {
@ -816,11 +816,11 @@ void KScheduler::YieldWithCoreMigration(KernelCore& kernel) {
void KScheduler::YieldToAnyThread(KernelCore& kernel) { void KScheduler::YieldToAnyThread(KernelCore& kernel) {
// Validate preconditions. // Validate preconditions.
ASSERT(CanSchedule(kernel)); ASSERT(CanSchedule(kernel));
ASSERT(kernel.CurrentProcess() != nullptr); ASSERT(GetCurrentProcessPointer(kernel) != nullptr);
// Get the current thread and process. // Get the current thread and process.
KThread& cur_thread = GetCurrentThread(kernel); KThread& cur_thread = GetCurrentThread(kernel);
KProcess& cur_process = *kernel.CurrentProcess(); KProcess& cur_process = GetCurrentProcess(kernel);
// If the thread's yield count matches, there's nothing for us to do. // If the thread's yield count matches, there's nothing for us to do.
if (cur_thread.GetYieldScheduleCount() == cur_process.GetScheduledCount()) { if (cur_thread.GetYieldScheduleCount() == cur_process.GetScheduledCount()) {

View File

@ -33,6 +33,7 @@ void KSession::Initialize(KClientPort* port_, const std::string& name_) {
name = name_; name = name_;
// Set our owner process. // Set our owner process.
//! FIXME: this is the wrong process!
process = kernel.CurrentProcess(); process = kernel.CurrentProcess();
process->Open(); process->Open();

View File

@ -1266,6 +1266,14 @@ KThread& GetCurrentThread(KernelCore& kernel) {
return *GetCurrentThreadPointer(kernel); return *GetCurrentThreadPointer(kernel);
} }
KProcess* GetCurrentProcessPointer(KernelCore& kernel) {
return GetCurrentThread(kernel).GetOwnerProcess();
}
KProcess& GetCurrentProcess(KernelCore& kernel) {
return *GetCurrentProcessPointer(kernel);
}
s32 GetCurrentCoreId(KernelCore& kernel) { s32 GetCurrentCoreId(KernelCore& kernel) {
return GetCurrentThread(kernel).GetCurrentCore(); return GetCurrentThread(kernel).GetCurrentCore();
} }

View File

@ -110,6 +110,8 @@ enum class StepState : u32 {
void SetCurrentThread(KernelCore& kernel, KThread* thread); void SetCurrentThread(KernelCore& kernel, KThread* thread);
[[nodiscard]] KThread* GetCurrentThreadPointer(KernelCore& kernel); [[nodiscard]] KThread* GetCurrentThreadPointer(KernelCore& kernel);
[[nodiscard]] KThread& GetCurrentThread(KernelCore& kernel); [[nodiscard]] KThread& GetCurrentThread(KernelCore& kernel);
[[nodiscard]] KProcess* GetCurrentProcessPointer(KernelCore& kernel);
[[nodiscard]] KProcess& GetCurrentProcess(KernelCore& kernel);
[[nodiscard]] s32 GetCurrentCoreId(KernelCore& kernel); [[nodiscard]] s32 GetCurrentCoreId(KernelCore& kernel);
class KThread final : public KAutoObjectWithSlabHeapAndContainer<KThread, KWorkerTask>, class KThread final : public KAutoObjectWithSlabHeapAndContainer<KThread, KWorkerTask>,

View File

@ -16,7 +16,7 @@ KTransferMemory::~KTransferMemory() = default;
Result KTransferMemory::Initialize(VAddr address_, std::size_t size_, Result KTransferMemory::Initialize(VAddr address_, std::size_t size_,
Svc::MemoryPermission owner_perm_) { Svc::MemoryPermission owner_perm_) {
// Set members. // Set members.
owner = kernel.CurrentProcess(); owner = GetCurrentProcessPointer(kernel);
// TODO(bunnei): Lock for transfer memory // TODO(bunnei): Lock for transfer memory

View File

@ -4426,7 +4426,7 @@ void Call(Core::System& system, u32 imm) {
auto& kernel = system.Kernel(); auto& kernel = system.Kernel();
kernel.EnterSVCProfile(); kernel.EnterSVCProfile();
if (system.CurrentProcess()->Is64BitProcess()) { if (GetCurrentProcess(system.Kernel()).Is64BitProcess()) {
Call64(system, imm); Call64(system, imm);
} else { } else {
Call32(system, imm); Call32(system, imm);

View File

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

View File

@ -72,7 +72,7 @@ Result WaitForAddress(Core::System& system, VAddr address, ArbitrationType arb_t
timeout = timeout_ns; timeout = timeout_ns;
} }
return system.Kernel().CurrentProcess()->WaitAddressArbiter(address, arb_type, value, timeout); return GetCurrentProcess(system.Kernel()).WaitAddressArbiter(address, arb_type, value, timeout);
} }
// Signals to an address (via Address Arbiter) // Signals to an address (via Address Arbiter)
@ -95,8 +95,8 @@ Result SignalToAddress(Core::System& system, VAddr address, SignalType signal_ty
return ResultInvalidEnumValue; return ResultInvalidEnumValue;
} }
return system.Kernel().CurrentProcess()->SignalAddressArbiter(address, signal_type, value, return GetCurrentProcess(system.Kernel())
count); .SignalAddressArbiter(address, signal_type, value, count);
} }
Result WaitForAddress64(Core::System& system, VAddr address, ArbitrationType arb_type, s32 value, Result WaitForAddress64(Core::System& system, VAddr address, ArbitrationType arb_type, s32 value,

View File

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

View File

@ -46,7 +46,7 @@ Result CreateCodeMemory(Core::System& system, Handle* out, VAddr address, size_t
R_UNLESS(code_mem != nullptr, ResultOutOfResource); R_UNLESS(code_mem != nullptr, ResultOutOfResource);
// Verify that the region is in range. // Verify that the region is in range.
R_UNLESS(system.CurrentProcess()->PageTable().Contains(address, size), R_UNLESS(GetCurrentProcess(system.Kernel()).PageTable().Contains(address, size),
ResultInvalidCurrentMemory); ResultInvalidCurrentMemory);
// Initialize the code memory. // Initialize the code memory.
@ -56,7 +56,7 @@ Result CreateCodeMemory(Core::System& system, Handle* out, VAddr address, size_t
KCodeMemory::Register(kernel, code_mem); KCodeMemory::Register(kernel, code_mem);
// Add the code memory to the handle table. // Add the code memory to the handle table.
R_TRY(system.CurrentProcess()->GetHandleTable().Add(out, code_mem)); R_TRY(GetCurrentProcess(system.Kernel()).GetHandleTable().Add(out, code_mem));
code_mem->Close(); code_mem->Close();
@ -79,8 +79,9 @@ Result ControlCodeMemory(Core::System& system, Handle code_memory_handle,
R_UNLESS((address < address + size), ResultInvalidCurrentMemory); R_UNLESS((address < address + size), ResultInvalidCurrentMemory);
// Get the code memory from its handle. // Get the code memory from its handle.
KScopedAutoObject code_mem = KScopedAutoObject code_mem = GetCurrentProcess(system.Kernel())
system.CurrentProcess()->GetHandleTable().GetObject<KCodeMemory>(code_memory_handle); .GetHandleTable()
.GetObject<KCodeMemory>(code_memory_handle);
R_UNLESS(code_mem.IsNotNull(), ResultInvalidHandle); R_UNLESS(code_mem.IsNotNull(), ResultInvalidHandle);
// NOTE: Here, Atmosphere extends the SVC to allow code memory operations on one's own process. // NOTE: Here, Atmosphere extends the SVC to allow code memory operations on one's own process.
@ -90,8 +91,9 @@ Result ControlCodeMemory(Core::System& system, Handle code_memory_handle,
switch (operation) { switch (operation) {
case CodeMemoryOperation::Map: { case CodeMemoryOperation::Map: {
// Check that the region is in range. // Check that the region is in range.
R_UNLESS( R_UNLESS(GetCurrentProcess(system.Kernel())
system.CurrentProcess()->PageTable().CanContain(address, size, KMemoryState::CodeOut), .PageTable()
.CanContain(address, size, KMemoryState::CodeOut),
ResultInvalidMemoryRegion); ResultInvalidMemoryRegion);
// Check the memory permission. // Check the memory permission.
@ -102,8 +104,9 @@ Result ControlCodeMemory(Core::System& system, Handle code_memory_handle,
} break; } break;
case CodeMemoryOperation::Unmap: { case CodeMemoryOperation::Unmap: {
// Check that the region is in range. // Check that the region is in range.
R_UNLESS( R_UNLESS(GetCurrentProcess(system.Kernel())
system.CurrentProcess()->PageTable().CanContain(address, size, KMemoryState::CodeOut), .PageTable()
.CanContain(address, size, KMemoryState::CodeOut),
ResultInvalidMemoryRegion); ResultInvalidMemoryRegion);
// Check the memory permission. // Check the memory permission.

View File

@ -43,8 +43,8 @@ Result WaitProcessWideKeyAtomic(Core::System& system, VAddr address, VAddr cv_ke
} }
// Wait on the condition variable. // Wait on the condition variable.
return system.Kernel().CurrentProcess()->WaitConditionVariable( return GetCurrentProcess(system.Kernel())
address, Common::AlignDown(cv_key, sizeof(u32)), tag, timeout); .WaitConditionVariable(address, Common::AlignDown(cv_key, sizeof(u32)), tag, timeout);
} }
/// Signal process wide key /// Signal process wide key
@ -52,8 +52,8 @@ void SignalProcessWideKey(Core::System& system, VAddr cv_key, s32 count) {
LOG_TRACE(Kernel_SVC, "called, cv_key=0x{:X}, count=0x{:08X}", cv_key, count); LOG_TRACE(Kernel_SVC, "called, cv_key=0x{:X}, count=0x{:08X}", cv_key, count);
// Signal the condition variable. // Signal the condition variable.
return system.Kernel().CurrentProcess()->SignalConditionVariable( return GetCurrentProcess(system.Kernel())
Common::AlignDown(cv_key, sizeof(u32)), count); .SignalConditionVariable(Common::AlignDown(cv_key, sizeof(u32)), count);
} }
Result WaitProcessWideKeyAtomic64(Core::System& system, uint64_t address, uint64_t cv_key, Result WaitProcessWideKeyAtomic64(Core::System& system, uint64_t address, uint64_t cv_key,

View File

@ -37,15 +37,16 @@ Result CreateDeviceAddressSpace(Core::System& system, Handle* out, uint64_t das_
KDeviceAddressSpace::Register(system.Kernel(), das); KDeviceAddressSpace::Register(system.Kernel(), das);
// Add to the handle table. // Add to the handle table.
R_TRY(system.CurrentProcess()->GetHandleTable().Add(out, das)); R_TRY(GetCurrentProcess(system.Kernel()).GetHandleTable().Add(out, das));
R_SUCCEED(); R_SUCCEED();
} }
Result AttachDeviceAddressSpace(Core::System& system, DeviceName device_name, Handle das_handle) { Result AttachDeviceAddressSpace(Core::System& system, DeviceName device_name, Handle das_handle) {
// Get the device address space. // Get the device address space.
KScopedAutoObject das = KScopedAutoObject das = GetCurrentProcess(system.Kernel())
system.CurrentProcess()->GetHandleTable().GetObject<KDeviceAddressSpace>(das_handle); .GetHandleTable()
.GetObject<KDeviceAddressSpace>(das_handle);
R_UNLESS(das.IsNotNull(), ResultInvalidHandle); R_UNLESS(das.IsNotNull(), ResultInvalidHandle);
// Attach. // Attach.
@ -54,8 +55,9 @@ Result AttachDeviceAddressSpace(Core::System& system, DeviceName device_name, Ha
Result DetachDeviceAddressSpace(Core::System& system, DeviceName device_name, Handle das_handle) { Result DetachDeviceAddressSpace(Core::System& system, DeviceName device_name, Handle das_handle) {
// Get the device address space. // Get the device address space.
KScopedAutoObject das = KScopedAutoObject das = GetCurrentProcess(system.Kernel())
system.CurrentProcess()->GetHandleTable().GetObject<KDeviceAddressSpace>(das_handle); .GetHandleTable()
.GetObject<KDeviceAddressSpace>(das_handle);
R_UNLESS(das.IsNotNull(), ResultInvalidHandle); R_UNLESS(das.IsNotNull(), ResultInvalidHandle);
// Detach. // Detach.
@ -94,13 +96,14 @@ Result MapDeviceAddressSpaceByForce(Core::System& system, Handle das_handle, Han
R_UNLESS(reserved == 0, ResultInvalidEnumValue); R_UNLESS(reserved == 0, ResultInvalidEnumValue);
// Get the device address space. // Get the device address space.
KScopedAutoObject das = KScopedAutoObject das = GetCurrentProcess(system.Kernel())
system.CurrentProcess()->GetHandleTable().GetObject<KDeviceAddressSpace>(das_handle); .GetHandleTable()
.GetObject<KDeviceAddressSpace>(das_handle);
R_UNLESS(das.IsNotNull(), ResultInvalidHandle); R_UNLESS(das.IsNotNull(), ResultInvalidHandle);
// Get the process. // Get the process.
KScopedAutoObject process = KScopedAutoObject process =
system.CurrentProcess()->GetHandleTable().GetObject<KProcess>(process_handle); GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(process_handle);
R_UNLESS(process.IsNotNull(), ResultInvalidHandle); R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
// Validate that the process address is within range. // Validate that the process address is within range.
@ -134,13 +137,14 @@ Result MapDeviceAddressSpaceAligned(Core::System& system, Handle das_handle, Han
R_UNLESS(reserved == 0, ResultInvalidEnumValue); R_UNLESS(reserved == 0, ResultInvalidEnumValue);
// Get the device address space. // Get the device address space.
KScopedAutoObject das = KScopedAutoObject das = GetCurrentProcess(system.Kernel())
system.CurrentProcess()->GetHandleTable().GetObject<KDeviceAddressSpace>(das_handle); .GetHandleTable()
.GetObject<KDeviceAddressSpace>(das_handle);
R_UNLESS(das.IsNotNull(), ResultInvalidHandle); R_UNLESS(das.IsNotNull(), ResultInvalidHandle);
// Get the process. // Get the process.
KScopedAutoObject process = KScopedAutoObject process =
system.CurrentProcess()->GetHandleTable().GetObject<KProcess>(process_handle); GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(process_handle);
R_UNLESS(process.IsNotNull(), ResultInvalidHandle); R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
// Validate that the process address is within range. // Validate that the process address is within range.
@ -165,13 +169,14 @@ Result UnmapDeviceAddressSpace(Core::System& system, Handle das_handle, Handle p
ResultInvalidCurrentMemory); ResultInvalidCurrentMemory);
// Get the device address space. // Get the device address space.
KScopedAutoObject das = KScopedAutoObject das = GetCurrentProcess(system.Kernel())
system.CurrentProcess()->GetHandleTable().GetObject<KDeviceAddressSpace>(das_handle); .GetHandleTable()
.GetObject<KDeviceAddressSpace>(das_handle);
R_UNLESS(das.IsNotNull(), ResultInvalidHandle); R_UNLESS(das.IsNotNull(), ResultInvalidHandle);
// Get the process. // Get the process.
KScopedAutoObject process = KScopedAutoObject process =
system.CurrentProcess()->GetHandleTable().GetObject<KProcess>(process_handle); GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(process_handle);
R_UNLESS(process.IsNotNull(), ResultInvalidHandle); R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
// Validate that the process address is within range. // Validate that the process address is within range.

View File

@ -15,7 +15,7 @@ Result SignalEvent(Core::System& system, Handle event_handle) {
LOG_DEBUG(Kernel_SVC, "called, event_handle=0x{:08X}", event_handle); LOG_DEBUG(Kernel_SVC, "called, event_handle=0x{:08X}", event_handle);
// Get the current handle table. // Get the current handle table.
const KHandleTable& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); const KHandleTable& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
// Get the event. // Get the event.
KScopedAutoObject event = handle_table.GetObject<KEvent>(event_handle); KScopedAutoObject event = handle_table.GetObject<KEvent>(event_handle);
@ -28,7 +28,7 @@ Result ClearEvent(Core::System& system, Handle event_handle) {
LOG_TRACE(Kernel_SVC, "called, event_handle=0x{:08X}", event_handle); LOG_TRACE(Kernel_SVC, "called, event_handle=0x{:08X}", event_handle);
// Get the current handle table. // Get the current handle table.
const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
// Try to clear the writable event. // Try to clear the writable event.
{ {
@ -56,10 +56,10 @@ Result CreateEvent(Core::System& system, Handle* out_write, Handle* out_read) {
// Get the kernel reference and handle table. // Get the kernel reference and handle table.
auto& kernel = system.Kernel(); auto& kernel = system.Kernel();
auto& handle_table = kernel.CurrentProcess()->GetHandleTable(); auto& handle_table = GetCurrentProcess(kernel).GetHandleTable();
// Reserve a new event from the process resource limit // Reserve a new event from the process resource limit
KScopedResourceReservation event_reservation(kernel.CurrentProcess(), KScopedResourceReservation event_reservation(GetCurrentProcessPointer(kernel),
LimitableResource::EventCountMax); LimitableResource::EventCountMax);
R_UNLESS(event_reservation.Succeeded(), ResultLimitReached); R_UNLESS(event_reservation.Succeeded(), ResultLimitReached);
@ -68,7 +68,7 @@ Result CreateEvent(Core::System& system, Handle* out_write, Handle* out_read) {
R_UNLESS(event != nullptr, ResultOutOfResource); R_UNLESS(event != nullptr, ResultOutOfResource);
// Initialize the event. // Initialize the event.
event->Initialize(kernel.CurrentProcess()); event->Initialize(GetCurrentProcessPointer(kernel));
// Commit the thread reservation. // Commit the thread reservation.
event_reservation.Commit(); event_reservation.Commit();

View File

@ -44,7 +44,7 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle
return ResultInvalidEnumValue; return ResultInvalidEnumValue;
} }
const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
KScopedAutoObject process = handle_table.GetObject<KProcess>(handle); KScopedAutoObject process = handle_table.GetObject<KProcess>(handle);
if (process.IsNull()) { if (process.IsNull()) {
LOG_ERROR(Kernel_SVC, "Process is not valid! info_id={}, info_sub_id={}, handle={:08X}", LOG_ERROR(Kernel_SVC, "Process is not valid! info_id={}, info_sub_id={}, handle={:08X}",
@ -154,7 +154,7 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle
return ResultInvalidCombination; return ResultInvalidCombination;
} }
KProcess* const current_process = system.Kernel().CurrentProcess(); KProcess* const current_process = GetCurrentProcessPointer(system.Kernel());
KHandleTable& handle_table = current_process->GetHandleTable(); KHandleTable& handle_table = current_process->GetHandleTable();
const auto resource_limit = current_process->GetResourceLimit(); const auto resource_limit = current_process->GetResourceLimit();
if (!resource_limit) { if (!resource_limit) {
@ -183,7 +183,7 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle
return ResultInvalidCombination; return ResultInvalidCombination;
} }
*result = system.Kernel().CurrentProcess()->GetRandomEntropy(info_sub_id); *result = GetCurrentProcess(system.Kernel()).GetRandomEntropy(info_sub_id);
return ResultSuccess; return ResultSuccess;
case InfoType::InitialProcessIdRange: case InfoType::InitialProcessIdRange:
@ -200,9 +200,9 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle
return ResultInvalidCombination; return ResultInvalidCombination;
} }
KScopedAutoObject thread = KScopedAutoObject thread = GetCurrentProcess(system.Kernel())
system.Kernel().CurrentProcess()->GetHandleTable().GetObject<KThread>( .GetHandleTable()
static_cast<Handle>(handle)); .GetObject<KThread>(static_cast<Handle>(handle));
if (thread.IsNull()) { if (thread.IsNull()) {
LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}", LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}",
static_cast<Handle>(handle)); static_cast<Handle>(handle));
@ -249,7 +249,7 @@ Result GetInfo(Core::System& system, u64* result, InfoType info_id_type, Handle
R_UNLESS(info_sub_id == 0, ResultInvalidCombination); R_UNLESS(info_sub_id == 0, ResultInvalidCombination);
// Get the handle table. // Get the handle table.
KProcess* current_process = system.Kernel().CurrentProcess(); KProcess* current_process = GetCurrentProcessPointer(system.Kernel());
KHandleTable& handle_table = current_process->GetHandleTable(); KHandleTable& handle_table = current_process->GetHandleTable();
// Get a new handle for the current process. // Get a new handle for the current process.

View File

@ -12,11 +12,9 @@ namespace Kernel::Svc {
/// Makes a blocking IPC call to a service. /// Makes a blocking IPC call to a service.
Result SendSyncRequest(Core::System& system, Handle handle) { Result SendSyncRequest(Core::System& system, Handle handle) {
auto& kernel = system.Kernel();
// Get the client session from its handle. // Get the client session from its handle.
KScopedAutoObject session = KScopedAutoObject session =
kernel.CurrentProcess()->GetHandleTable().GetObject<KClientSession>(handle); GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KClientSession>(handle);
R_UNLESS(session.IsNotNull(), ResultInvalidHandle); R_UNLESS(session.IsNotNull(), ResultInvalidHandle);
LOG_TRACE(Kernel_SVC, "called handle=0x{:08X}({})", handle, session->GetName()); LOG_TRACE(Kernel_SVC, "called handle=0x{:08X}({})", handle, session->GetName());
@ -40,7 +38,7 @@ Result SendAsyncRequestWithUserBuffer(Core::System& system, Handle* out_event_ha
Result ReplyAndReceive(Core::System& system, s32* out_index, uint64_t handles_addr, s32 num_handles, Result ReplyAndReceive(Core::System& system, s32* out_index, uint64_t handles_addr, s32 num_handles,
Handle reply_target, s64 timeout_ns) { Handle reply_target, s64 timeout_ns) {
auto& kernel = system.Kernel(); auto& kernel = system.Kernel();
auto& handle_table = GetCurrentThread(kernel).GetOwnerProcess()->GetHandleTable(); auto& handle_table = GetCurrentProcess(kernel).GetHandleTable();
R_UNLESS(0 <= num_handles && num_handles <= ArgumentHandleCountMax, ResultOutOfRange); R_UNLESS(0 <= num_handles && num_handles <= ArgumentHandleCountMax, ResultOutOfRange);
R_UNLESS(system.Memory().IsValidVirtualAddressRange( R_UNLESS(system.Memory().IsValidVirtualAddressRange(

View File

@ -24,7 +24,7 @@ Result ArbitrateLock(Core::System& system, Handle thread_handle, VAddr address,
return ResultInvalidAddress; return ResultInvalidAddress;
} }
return system.Kernel().CurrentProcess()->WaitForAddress(thread_handle, address, tag); return GetCurrentProcess(system.Kernel()).WaitForAddress(thread_handle, address, tag);
} }
/// Unlock a mutex /// Unlock a mutex
@ -43,7 +43,7 @@ Result ArbitrateUnlock(Core::System& system, VAddr address) {
return ResultInvalidAddress; return ResultInvalidAddress;
} }
return system.Kernel().CurrentProcess()->SignalToAddress(address); return GetCurrentProcess(system.Kernel()).SignalToAddress(address);
} }
Result ArbitrateLock64(Core::System& system, Handle thread_handle, uint64_t address, uint32_t tag) { Result ArbitrateLock64(Core::System& system, Handle thread_handle, uint64_t address, uint32_t tag) {

View File

@ -113,7 +113,7 @@ Result SetMemoryPermission(Core::System& system, VAddr address, u64 size, Memory
R_UNLESS(IsValidSetMemoryPermission(perm), ResultInvalidNewMemoryPermission); R_UNLESS(IsValidSetMemoryPermission(perm), ResultInvalidNewMemoryPermission);
// Validate that the region is in range for the current process. // Validate that the region is in range for the current process.
auto& page_table = system.Kernel().CurrentProcess()->PageTable(); auto& page_table = GetCurrentProcess(system.Kernel()).PageTable();
R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory); R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory);
// Set the memory attribute. // Set the memory attribute.
@ -137,7 +137,7 @@ Result SetMemoryAttribute(Core::System& system, VAddr address, u64 size, u32 mas
R_UNLESS((mask | attr | SupportedMask) == SupportedMask, ResultInvalidCombination); R_UNLESS((mask | attr | SupportedMask) == SupportedMask, ResultInvalidCombination);
// Validate that the region is in range for the current process. // Validate that the region is in range for the current process.
auto& page_table{system.Kernel().CurrentProcess()->PageTable()}; auto& page_table{GetCurrentProcess(system.Kernel()).PageTable()};
R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory); R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory);
// Set the memory attribute. // Set the memory attribute.
@ -149,7 +149,7 @@ Result MapMemory(Core::System& system, VAddr dst_addr, VAddr src_addr, u64 size)
LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr, LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr,
src_addr, size); src_addr, size);
auto& page_table{system.Kernel().CurrentProcess()->PageTable()}; auto& page_table{GetCurrentProcess(system.Kernel()).PageTable()};
if (const Result result{MapUnmapMemorySanityChecks(page_table, dst_addr, src_addr, size)}; if (const Result result{MapUnmapMemorySanityChecks(page_table, dst_addr, src_addr, size)};
result.IsError()) { result.IsError()) {
@ -164,7 +164,7 @@ Result UnmapMemory(Core::System& system, VAddr dst_addr, VAddr src_addr, u64 siz
LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr, LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr,
src_addr, size); src_addr, size);
auto& page_table{system.Kernel().CurrentProcess()->PageTable()}; auto& page_table{GetCurrentProcess(system.Kernel()).PageTable()};
if (const Result result{MapUnmapMemorySanityChecks(page_table, dst_addr, src_addr, size)}; if (const Result result{MapUnmapMemorySanityChecks(page_table, dst_addr, src_addr, size)};
result.IsError()) { result.IsError()) {

View File

@ -16,7 +16,7 @@ Result SetHeapSize(Core::System& system, VAddr* out_address, u64 size) {
R_UNLESS(size < MainMemorySizeMax, ResultInvalidSize); R_UNLESS(size < MainMemorySizeMax, ResultInvalidSize);
// Set the heap size. // Set the heap size.
R_TRY(system.Kernel().CurrentProcess()->PageTable().SetHeapSize(out_address, size)); R_TRY(GetCurrentProcess(system.Kernel()).PageTable().SetHeapSize(out_address, size));
return ResultSuccess; return ResultSuccess;
} }
@ -45,7 +45,7 @@ Result MapPhysicalMemory(Core::System& system, VAddr addr, u64 size) {
return ResultInvalidMemoryRegion; return ResultInvalidMemoryRegion;
} }
KProcess* const current_process{system.Kernel().CurrentProcess()}; KProcess* const current_process{GetCurrentProcessPointer(system.Kernel())};
auto& page_table{current_process->PageTable()}; auto& page_table{current_process->PageTable()};
if (current_process->GetSystemResourceSize() == 0) { if (current_process->GetSystemResourceSize() == 0) {
@ -94,7 +94,7 @@ Result UnmapPhysicalMemory(Core::System& system, VAddr addr, u64 size) {
return ResultInvalidMemoryRegion; return ResultInvalidMemoryRegion;
} }
KProcess* const current_process{system.Kernel().CurrentProcess()}; KProcess* const current_process{GetCurrentProcessPointer(system.Kernel())};
auto& page_table{current_process->PageTable()}; auto& page_table{current_process->PageTable()};
if (current_process->GetSystemResourceSize() == 0) { if (current_process->GetSystemResourceSize() == 0) {

View File

@ -34,7 +34,7 @@ Result ConnectToNamedPort(Core::System& system, Handle* out, VAddr port_name_add
// Get the current handle table. // Get the current handle table.
auto& kernel = system.Kernel(); auto& kernel = system.Kernel();
auto& handle_table = kernel.CurrentProcess()->GetHandleTable(); auto& handle_table = GetCurrentProcess(kernel).GetHandleTable();
// Find the client port. // Find the client port.
auto port = kernel.CreateNamedServicePort(port_name); auto port = kernel.CreateNamedServicePort(port_name);

View File

@ -9,7 +9,7 @@ namespace Kernel::Svc {
/// Exits the current process /// Exits the current process
void ExitProcess(Core::System& system) { void ExitProcess(Core::System& system) {
auto* current_process = system.Kernel().CurrentProcess(); auto* current_process = GetCurrentProcessPointer(system.Kernel());
LOG_INFO(Kernel_SVC, "Process {} exiting", current_process->GetProcessID()); LOG_INFO(Kernel_SVC, "Process {} exiting", current_process->GetProcessID());
ASSERT_MSG(current_process->GetState() == KProcess::State::Running, ASSERT_MSG(current_process->GetState() == KProcess::State::Running,
@ -23,9 +23,9 @@ Result GetProcessId(Core::System& system, u64* out_process_id, Handle handle) {
LOG_DEBUG(Kernel_SVC, "called handle=0x{:08X}", handle); LOG_DEBUG(Kernel_SVC, "called handle=0x{:08X}", handle);
// Get the object from the handle table. // Get the object from the handle table.
KScopedAutoObject obj = KScopedAutoObject obj = GetCurrentProcess(system.Kernel())
system.Kernel().CurrentProcess()->GetHandleTable().GetObject<KAutoObject>( .GetHandleTable()
static_cast<Handle>(handle)); .GetObject<KAutoObject>(static_cast<Handle>(handle));
R_UNLESS(obj.IsNotNull(), ResultInvalidHandle); R_UNLESS(obj.IsNotNull(), ResultInvalidHandle);
// Get the process from the object. // Get the process from the object.
@ -63,10 +63,10 @@ Result GetProcessList(Core::System& system, s32* out_num_processes, VAddr out_pr
return ResultOutOfRange; return ResultOutOfRange;
} }
const auto& kernel = system.Kernel(); auto& kernel = system.Kernel();
const auto total_copy_size = out_process_ids_size * sizeof(u64); const auto total_copy_size = out_process_ids_size * sizeof(u64);
if (out_process_ids_size > 0 && !kernel.CurrentProcess()->PageTable().IsInsideAddressSpace( if (out_process_ids_size > 0 && !GetCurrentProcess(kernel).PageTable().IsInsideAddressSpace(
out_process_ids, total_copy_size)) { out_process_ids, total_copy_size)) {
LOG_ERROR(Kernel_SVC, "Address range outside address space. begin=0x{:016X}, end=0x{:016X}", LOG_ERROR(Kernel_SVC, "Address range outside address space. begin=0x{:016X}, end=0x{:016X}",
out_process_ids, out_process_ids + total_copy_size); out_process_ids, out_process_ids + total_copy_size);
@ -92,7 +92,7 @@ Result GetProcessInfo(Core::System& system, s64* out, Handle process_handle,
ProcessInfoType info_type) { ProcessInfoType info_type) {
LOG_DEBUG(Kernel_SVC, "called, handle=0x{:08X}, type=0x{:X}", process_handle, info_type); LOG_DEBUG(Kernel_SVC, "called, handle=0x{:08X}, type=0x{:X}", process_handle, info_type);
const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
KScopedAutoObject process = handle_table.GetObject<KProcess>(process_handle); KScopedAutoObject process = handle_table.GetObject<KProcess>(process_handle);
if (process.IsNull()) { if (process.IsNull()) {
LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}", LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}",

View File

@ -45,7 +45,7 @@ Result SetProcessMemoryPermission(Core::System& system, Handle process_handle, V
// Get the process from its handle. // Get the process from its handle.
KScopedAutoObject process = KScopedAutoObject process =
system.CurrentProcess()->GetHandleTable().GetObject<KProcess>(process_handle); GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KProcess>(process_handle);
R_UNLESS(process.IsNotNull(), ResultInvalidHandle); R_UNLESS(process.IsNotNull(), ResultInvalidHandle);
// Validate that the address is in range. // Validate that the address is in range.
@ -71,7 +71,7 @@ Result MapProcessMemory(Core::System& system, VAddr dst_address, Handle process_
R_UNLESS((src_address < src_address + size), ResultInvalidCurrentMemory); R_UNLESS((src_address < src_address + size), ResultInvalidCurrentMemory);
// Get the processes. // Get the processes.
KProcess* dst_process = system.CurrentProcess(); KProcess* dst_process = GetCurrentProcessPointer(system.Kernel());
KScopedAutoObject src_process = KScopedAutoObject src_process =
dst_process->GetHandleTable().GetObjectWithoutPseudoHandle<KProcess>(process_handle); dst_process->GetHandleTable().GetObjectWithoutPseudoHandle<KProcess>(process_handle);
R_UNLESS(src_process.IsNotNull(), ResultInvalidHandle); R_UNLESS(src_process.IsNotNull(), ResultInvalidHandle);
@ -114,7 +114,7 @@ Result UnmapProcessMemory(Core::System& system, VAddr dst_address, Handle proces
R_UNLESS((src_address < src_address + size), ResultInvalidCurrentMemory); R_UNLESS((src_address < src_address + size), ResultInvalidCurrentMemory);
// Get the processes. // Get the processes.
KProcess* dst_process = system.CurrentProcess(); KProcess* dst_process = GetCurrentProcessPointer(system.Kernel());
KScopedAutoObject src_process = KScopedAutoObject src_process =
dst_process->GetHandleTable().GetObjectWithoutPseudoHandle<KProcess>(process_handle); dst_process->GetHandleTable().GetObjectWithoutPseudoHandle<KProcess>(process_handle);
R_UNLESS(src_process.IsNotNull(), ResultInvalidHandle); R_UNLESS(src_process.IsNotNull(), ResultInvalidHandle);
@ -174,7 +174,7 @@ Result MapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst
return ResultInvalidCurrentMemory; return ResultInvalidCurrentMemory;
} }
const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
KScopedAutoObject process = handle_table.GetObject<KProcess>(process_handle); KScopedAutoObject process = handle_table.GetObject<KProcess>(process_handle);
if (process.IsNull()) { if (process.IsNull()) {
LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).", LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).",
@ -242,7 +242,7 @@ Result UnmapProcessCodeMemory(Core::System& system, Handle process_handle, u64 d
return ResultInvalidCurrentMemory; return ResultInvalidCurrentMemory;
} }
const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
KScopedAutoObject process = handle_table.GetObject<KProcess>(process_handle); KScopedAutoObject process = handle_table.GetObject<KProcess>(process_handle);
if (process.IsNull()) { if (process.IsNull()) {
LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).", LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).",

View File

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

View File

@ -27,7 +27,7 @@ Result CreateResourceLimit(Core::System& system, Handle* out_handle) {
KResourceLimit::Register(kernel, resource_limit); KResourceLimit::Register(kernel, resource_limit);
// Add the limit to the handle table. // Add the limit to the handle table.
R_TRY(kernel.CurrentProcess()->GetHandleTable().Add(out_handle, resource_limit)); R_TRY(GetCurrentProcess(kernel).GetHandleTable().Add(out_handle, resource_limit));
return ResultSuccess; return ResultSuccess;
} }
@ -41,9 +41,9 @@ Result GetResourceLimitLimitValue(Core::System& system, s64* out_limit_value,
R_UNLESS(IsValidResourceType(which), ResultInvalidEnumValue); R_UNLESS(IsValidResourceType(which), ResultInvalidEnumValue);
// Get the resource limit. // Get the resource limit.
auto& kernel = system.Kernel(); KScopedAutoObject resource_limit = GetCurrentProcess(system.Kernel())
KScopedAutoObject resource_limit = .GetHandleTable()
kernel.CurrentProcess()->GetHandleTable().GetObject<KResourceLimit>(resource_limit_handle); .GetObject<KResourceLimit>(resource_limit_handle);
R_UNLESS(resource_limit.IsNotNull(), ResultInvalidHandle); R_UNLESS(resource_limit.IsNotNull(), ResultInvalidHandle);
// Get the limit value. // Get the limit value.
@ -61,9 +61,9 @@ Result GetResourceLimitCurrentValue(Core::System& system, s64* out_current_value
R_UNLESS(IsValidResourceType(which), ResultInvalidEnumValue); R_UNLESS(IsValidResourceType(which), ResultInvalidEnumValue);
// Get the resource limit. // Get the resource limit.
auto& kernel = system.Kernel(); KScopedAutoObject resource_limit = GetCurrentProcess(system.Kernel())
KScopedAutoObject resource_limit = .GetHandleTable()
kernel.CurrentProcess()->GetHandleTable().GetObject<KResourceLimit>(resource_limit_handle); .GetObject<KResourceLimit>(resource_limit_handle);
R_UNLESS(resource_limit.IsNotNull(), ResultInvalidHandle); R_UNLESS(resource_limit.IsNotNull(), ResultInvalidHandle);
// Get the current value. // Get the current value.
@ -81,9 +81,9 @@ Result SetResourceLimitLimitValue(Core::System& system, Handle resource_limit_ha
R_UNLESS(IsValidResourceType(which), ResultInvalidEnumValue); R_UNLESS(IsValidResourceType(which), ResultInvalidEnumValue);
// Get the resource limit. // Get the resource limit.
auto& kernel = system.Kernel(); KScopedAutoObject resource_limit = GetCurrentProcess(system.Kernel())
KScopedAutoObject resource_limit = .GetHandleTable()
kernel.CurrentProcess()->GetHandleTable().GetObject<KResourceLimit>(resource_limit_handle); .GetObject<KResourceLimit>(resource_limit_handle);
R_UNLESS(resource_limit.IsNotNull(), ResultInvalidHandle); R_UNLESS(resource_limit.IsNotNull(), ResultInvalidHandle);
// Set the limit value. // Set the limit value.

View File

@ -13,7 +13,7 @@ namespace {
template <typename T> template <typename T>
Result CreateSession(Core::System& system, Handle* out_server, Handle* out_client, u64 name) { Result CreateSession(Core::System& system, Handle* out_server, Handle* out_client, u64 name) {
auto& process = *system.CurrentProcess(); auto& process = GetCurrentProcess(system.Kernel());
auto& handle_table = process.GetHandleTable(); auto& handle_table = process.GetHandleTable();
// Declare the session we're going to allocate. // Declare the session we're going to allocate.

View File

@ -42,7 +42,7 @@ Result MapSharedMemory(Core::System& system, Handle shmem_handle, VAddr address,
R_UNLESS(IsValidSharedMemoryPermission(map_perm), ResultInvalidNewMemoryPermission); R_UNLESS(IsValidSharedMemoryPermission(map_perm), ResultInvalidNewMemoryPermission);
// Get the current process. // Get the current process.
auto& process = *system.Kernel().CurrentProcess(); auto& process = GetCurrentProcess(system.Kernel());
auto& page_table = process.PageTable(); auto& page_table = process.PageTable();
// Get the shared memory. // Get the shared memory.
@ -75,7 +75,7 @@ Result UnmapSharedMemory(Core::System& system, Handle shmem_handle, VAddr addres
R_UNLESS((address < address + size), ResultInvalidCurrentMemory); R_UNLESS((address < address + size), ResultInvalidCurrentMemory);
// Get the current process. // Get the current process.
auto& process = *system.Kernel().CurrentProcess(); auto& process = GetCurrentProcess(system.Kernel());
auto& page_table = process.PageTable(); auto& page_table = process.PageTable();
// Get the shared memory. // Get the shared memory.

View File

@ -14,7 +14,7 @@ Result CloseHandle(Core::System& system, Handle handle) {
LOG_TRACE(Kernel_SVC, "Closing handle 0x{:08X}", handle); LOG_TRACE(Kernel_SVC, "Closing handle 0x{:08X}", handle);
// Remove the handle. // Remove the handle.
R_UNLESS(system.Kernel().CurrentProcess()->GetHandleTable().Remove(handle), R_UNLESS(GetCurrentProcess(system.Kernel()).GetHandleTable().Remove(handle),
ResultInvalidHandle); ResultInvalidHandle);
return ResultSuccess; return ResultSuccess;
@ -25,7 +25,7 @@ Result ResetSignal(Core::System& system, Handle handle) {
LOG_DEBUG(Kernel_SVC, "called handle 0x{:08X}", handle); LOG_DEBUG(Kernel_SVC, "called handle 0x{:08X}", handle);
// Get the current handle table. // Get the current handle table.
const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); const auto& handle_table = GetCurrentProcess(system.Kernel()).GetHandleTable();
// Try to reset as readable event. // Try to reset as readable event.
{ {
@ -59,7 +59,7 @@ Result WaitSynchronization(Core::System& system, s32* index, VAddr handles_addre
auto& kernel = system.Kernel(); auto& kernel = system.Kernel();
std::vector<KSynchronizationObject*> objs(num_handles); std::vector<KSynchronizationObject*> objs(num_handles);
const auto& handle_table = kernel.CurrentProcess()->GetHandleTable(); const auto& handle_table = GetCurrentProcess(kernel).GetHandleTable();
Handle* handles = system.Memory().GetPointer<Handle>(handles_address); Handle* handles = system.Memory().GetPointer<Handle>(handles_address);
// Copy user handles. // Copy user handles.
@ -91,7 +91,7 @@ Result CancelSynchronization(Core::System& system, Handle handle) {
// Get the thread from its handle. // Get the thread from its handle.
KScopedAutoObject thread = KScopedAutoObject thread =
system.Kernel().CurrentProcess()->GetHandleTable().GetObject<KThread>(handle); GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(handle);
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
// Cancel the thread's wait. // Cancel the thread's wait.
@ -106,7 +106,7 @@ void SynchronizePreemptionState(Core::System& system) {
KScopedSchedulerLock sl{kernel}; KScopedSchedulerLock sl{kernel};
// If the current thread is pinned, unpin it. // If the current thread is pinned, unpin it.
KProcess* cur_process = system.Kernel().CurrentProcess(); KProcess* cur_process = GetCurrentProcessPointer(kernel);
const auto core_id = GetCurrentCoreId(kernel); const auto core_id = GetCurrentCoreId(kernel);
if (cur_process->GetPinnedThread(core_id) == GetCurrentThreadPointer(kernel)) { if (cur_process->GetPinnedThread(core_id) == GetCurrentThreadPointer(kernel)) {

View File

@ -28,7 +28,7 @@ Result CreateThread(Core::System& system, Handle* out_handle, VAddr entry_point,
// Adjust core id, if it's the default magic. // Adjust core id, if it's the default magic.
auto& kernel = system.Kernel(); auto& kernel = system.Kernel();
auto& process = *kernel.CurrentProcess(); auto& process = GetCurrentProcess(kernel);
if (core_id == IdealCoreUseProcessValue) { if (core_id == IdealCoreUseProcessValue) {
core_id = process.GetIdealCoreId(); core_id = process.GetIdealCoreId();
} }
@ -53,9 +53,9 @@ Result CreateThread(Core::System& system, Handle* out_handle, VAddr entry_point,
} }
// Reserve a new thread from the process resource limit (waiting up to 100ms). // Reserve a new thread from the process resource limit (waiting up to 100ms).
KScopedResourceReservation thread_reservation( KScopedResourceReservation thread_reservation(&process, LimitableResource::ThreadCountMax, 1,
kernel.CurrentProcess(), LimitableResource::ThreadCountMax, 1, system.CoreTiming().GetGlobalTimeNs().count() +
system.CoreTiming().GetGlobalTimeNs().count() + 100000000); 100000000);
if (!thread_reservation.Succeeded()) { if (!thread_reservation.Succeeded()) {
LOG_ERROR(Kernel_SVC, "Could not reserve a new thread"); LOG_ERROR(Kernel_SVC, "Could not reserve a new thread");
return ResultLimitReached; return ResultLimitReached;
@ -97,7 +97,7 @@ Result StartThread(Core::System& system, Handle thread_handle) {
// Get the thread from its handle. // Get the thread from its handle.
KScopedAutoObject thread = KScopedAutoObject thread =
system.Kernel().CurrentProcess()->GetHandleTable().GetObject<KThread>(thread_handle); GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(thread_handle);
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
// Try to start the thread. // Try to start the thread.
@ -156,11 +156,11 @@ Result GetThreadContext3(Core::System& system, VAddr out_context, Handle thread_
// Get the thread from its handle. // Get the thread from its handle.
KScopedAutoObject thread = KScopedAutoObject thread =
kernel.CurrentProcess()->GetHandleTable().GetObject<KThread>(thread_handle); GetCurrentProcess(kernel).GetHandleTable().GetObject<KThread>(thread_handle);
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
// Require the handle be to a non-current thread in the current process. // Require the handle be to a non-current thread in the current process.
const auto* current_process = kernel.CurrentProcess(); const auto* current_process = GetCurrentProcessPointer(kernel);
R_UNLESS(current_process == thread->GetOwnerProcess(), ResultInvalidId); R_UNLESS(current_process == thread->GetOwnerProcess(), ResultInvalidId);
// Verify that the thread isn't terminated. // Verify that the thread isn't terminated.
@ -211,7 +211,7 @@ Result GetThreadPriority(Core::System& system, s32* out_priority, Handle handle)
// Get the thread from its handle. // Get the thread from its handle.
KScopedAutoObject thread = KScopedAutoObject thread =
system.Kernel().CurrentProcess()->GetHandleTable().GetObject<KThread>(handle); GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(handle);
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
// Get the thread's priority. // Get the thread's priority.
@ -222,7 +222,7 @@ Result GetThreadPriority(Core::System& system, s32* out_priority, Handle handle)
/// Sets the priority for the specified thread /// Sets the priority for the specified thread
Result SetThreadPriority(Core::System& system, Handle thread_handle, s32 priority) { Result SetThreadPriority(Core::System& system, Handle thread_handle, s32 priority) {
// Get the current process. // Get the current process.
KProcess& process = *system.Kernel().CurrentProcess(); KProcess& process = GetCurrentProcess(system.Kernel());
// Validate the priority. // Validate the priority.
R_UNLESS(HighestThreadPriority <= priority && priority <= LowestThreadPriority, R_UNLESS(HighestThreadPriority <= priority && priority <= LowestThreadPriority,
@ -253,7 +253,7 @@ Result GetThreadList(Core::System& system, s32* out_num_threads, VAddr out_threa
return ResultOutOfRange; return ResultOutOfRange;
} }
auto* const current_process = system.Kernel().CurrentProcess(); auto* const current_process = GetCurrentProcessPointer(system.Kernel());
const auto total_copy_size = out_thread_ids_size * sizeof(u64); const auto total_copy_size = out_thread_ids_size * sizeof(u64);
if (out_thread_ids_size > 0 && if (out_thread_ids_size > 0 &&
@ -284,7 +284,7 @@ Result GetThreadCoreMask(Core::System& system, s32* out_core_id, u64* out_affini
// Get the thread from its handle. // Get the thread from its handle.
KScopedAutoObject thread = KScopedAutoObject thread =
system.Kernel().CurrentProcess()->GetHandleTable().GetObject<KThread>(thread_handle); GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(thread_handle);
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
// Get the core mask. // Get the core mask.
@ -297,11 +297,11 @@ Result SetThreadCoreMask(Core::System& system, Handle thread_handle, s32 core_id
u64 affinity_mask) { u64 affinity_mask) {
// Determine the core id/affinity mask. // Determine the core id/affinity mask.
if (core_id == IdealCoreUseProcessValue) { if (core_id == IdealCoreUseProcessValue) {
core_id = system.Kernel().CurrentProcess()->GetIdealCoreId(); core_id = GetCurrentProcess(system.Kernel()).GetIdealCoreId();
affinity_mask = (1ULL << core_id); affinity_mask = (1ULL << core_id);
} else { } else {
// Validate the affinity mask. // Validate the affinity mask.
const u64 process_core_mask = system.Kernel().CurrentProcess()->GetCoreMask(); const u64 process_core_mask = GetCurrentProcess(system.Kernel()).GetCoreMask();
R_UNLESS((affinity_mask | process_core_mask) == process_core_mask, ResultInvalidCoreId); R_UNLESS((affinity_mask | process_core_mask) == process_core_mask, ResultInvalidCoreId);
R_UNLESS(affinity_mask != 0, ResultInvalidCombination); R_UNLESS(affinity_mask != 0, ResultInvalidCombination);
@ -316,7 +316,7 @@ Result SetThreadCoreMask(Core::System& system, Handle thread_handle, s32 core_id
// Get the thread from its handle. // Get the thread from its handle.
KScopedAutoObject thread = KScopedAutoObject thread =
system.Kernel().CurrentProcess()->GetHandleTable().GetObject<KThread>(thread_handle); GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(thread_handle);
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
// Set the core mask. // Set the core mask.
@ -329,7 +329,7 @@ Result SetThreadCoreMask(Core::System& system, Handle thread_handle, s32 core_id
Result GetThreadId(Core::System& system, u64* out_thread_id, Handle thread_handle) { Result GetThreadId(Core::System& system, u64* out_thread_id, Handle thread_handle) {
// Get the thread from its handle. // Get the thread from its handle.
KScopedAutoObject thread = KScopedAutoObject thread =
system.Kernel().CurrentProcess()->GetHandleTable().GetObject<KThread>(thread_handle); GetCurrentProcess(system.Kernel()).GetHandleTable().GetObject<KThread>(thread_handle);
R_UNLESS(thread.IsNotNull(), ResultInvalidHandle); R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
// Get the thread's id. // Get the thread's id.

View File

@ -39,11 +39,11 @@ Result CreateTransferMemory(Core::System& system, Handle* out, VAddr address, u6
R_UNLESS(IsValidTransferMemoryPermission(map_perm), ResultInvalidNewMemoryPermission); R_UNLESS(IsValidTransferMemoryPermission(map_perm), ResultInvalidNewMemoryPermission);
// Get the current process and handle table. // Get the current process and handle table.
auto& process = *kernel.CurrentProcess(); auto& process = GetCurrentProcess(kernel);
auto& handle_table = process.GetHandleTable(); auto& handle_table = process.GetHandleTable();
// Reserve a new transfer memory from the process resource limit. // Reserve a new transfer memory from the process resource limit.
KScopedResourceReservation trmem_reservation(kernel.CurrentProcess(), KScopedResourceReservation trmem_reservation(&process,
LimitableResource::TransferMemoryCountMax); LimitableResource::TransferMemoryCountMax);
R_UNLESS(trmem_reservation.Succeeded(), ResultLimitReached); R_UNLESS(trmem_reservation.Succeeded(), ResultLimitReached);

View File

@ -592,7 +592,7 @@ void Call(Core::System& system, u32 imm) {
auto& kernel = system.Kernel(); auto& kernel = system.Kernel();
kernel.EnterSVCProfile(); kernel.EnterSVCProfile();
if (system.CurrentProcess()->Is64BitProcess()) { if (GetCurrentProcess(system.Kernel()).Is64BitProcess()) {
Call64(system, imm); Call64(system, imm);
} else { } else {
Call32(system, imm); Call32(system, imm);