svc_activity.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "core/core.h"
  4. #include "core/hle/kernel/k_process.h"
  5. #include "core/hle/kernel/k_thread.h"
  6. #include "core/hle/kernel/svc.h"
  7. #include "core/hle/kernel/svc_results.h"
  8. namespace Kernel::Svc {
  9. /// Sets the thread activity
  10. Result SetThreadActivity(Core::System& system, Handle thread_handle,
  11. ThreadActivity thread_activity) {
  12. LOG_DEBUG(Kernel_SVC, "called, handle=0x{:08X}, activity=0x{:08X}", thread_handle,
  13. thread_activity);
  14. // Validate the activity.
  15. constexpr auto IsValidThreadActivity = [](ThreadActivity activity) {
  16. return activity == ThreadActivity::Runnable || activity == ThreadActivity::Paused;
  17. };
  18. R_UNLESS(IsValidThreadActivity(thread_activity), ResultInvalidEnumValue);
  19. // Get the thread from its handle.
  20. KScopedAutoObject thread =
  21. system.Kernel().CurrentProcess()->GetHandleTable().GetObject<KThread>(thread_handle);
  22. R_UNLESS(thread.IsNotNull(), ResultInvalidHandle);
  23. // Check that the activity is being set on a non-current thread for the current process.
  24. R_UNLESS(thread->GetOwnerProcess() == system.Kernel().CurrentProcess(), ResultInvalidHandle);
  25. R_UNLESS(thread.GetPointerUnsafe() != GetCurrentThreadPointer(system.Kernel()), ResultBusy);
  26. // Set the activity.
  27. R_TRY(thread->SetActivity(thread_activity));
  28. return ResultSuccess;
  29. }
  30. Result SetThreadActivity32(Core::System& system, Handle thread_handle,
  31. ThreadActivity thread_activity) {
  32. return SetThreadActivity(system, thread_handle, thread_activity);
  33. }
  34. } // namespace Kernel::Svc