svc_activity.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. GetCurrentProcess(system.Kernel()).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() == GetCurrentProcessPointer(system.Kernel()),
  25. ResultInvalidHandle);
  26. R_UNLESS(thread.GetPointerUnsafe() != GetCurrentThreadPointer(system.Kernel()), ResultBusy);
  27. // Set the activity.
  28. R_TRY(thread->SetActivity(thread_activity));
  29. return ResultSuccess;
  30. }
  31. Result SetProcessActivity(Core::System& system, Handle process_handle,
  32. ProcessActivity process_activity) {
  33. UNIMPLEMENTED();
  34. R_THROW(ResultNotImplemented);
  35. }
  36. Result SetThreadActivity64(Core::System& system, Handle thread_handle,
  37. ThreadActivity thread_activity) {
  38. return SetThreadActivity(system, thread_handle, thread_activity);
  39. }
  40. Result SetProcessActivity64(Core::System& system, Handle process_handle,
  41. ProcessActivity process_activity) {
  42. return SetProcessActivity(system, process_handle, process_activity);
  43. }
  44. Result SetThreadActivity64From32(Core::System& system, Handle thread_handle,
  45. ThreadActivity thread_activity) {
  46. return SetThreadActivity(system, thread_handle, thread_activity);
  47. }
  48. Result SetProcessActivity64From32(Core::System& system, Handle process_handle,
  49. ProcessActivity process_activity) {
  50. return SetProcessActivity(system, process_handle, process_activity);
  51. }
  52. } // namespace Kernel::Svc