summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/svc/svc_activity.cpp
blob: 1dcdb7a15f0b6e62286561ae6868909a60838c05 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include "core/core.h"
#include "core/hle/kernel/k_process.h"
#include "core/hle/kernel/k_thread.h"
#include "core/hle/kernel/svc.h"
#include "core/hle/kernel/svc_results.h"

namespace Kernel::Svc {

/// Sets the thread activity
Result SetThreadActivity(Core::System& system, Handle thread_handle,
                         ThreadActivity thread_activity) {
    LOG_DEBUG(Kernel_SVC, "called, handle=0x{:08X}, activity=0x{:08X}", thread_handle,
              thread_activity);

    // Validate the activity.
    constexpr auto IsValidThreadActivity = [](ThreadActivity activity) {
        return activity == ThreadActivity::Runnable || activity == ThreadActivity::Paused;
    };
    R_UNLESS(IsValidThreadActivity(thread_activity), ResultInvalidEnumValue);

    // Get the thread from its handle.
    KScopedAutoObject thread =
        system.Kernel().CurrentProcess()->GetHandleTable().GetObject<KThread>(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() == system.Kernel().CurrentProcess(), ResultInvalidHandle);
    R_UNLESS(thread.GetPointerUnsafe() != GetCurrentThreadPointer(system.Kernel()), ResultBusy);

    // Set the activity.
    R_TRY(thread->SetActivity(thread_activity));

    return ResultSuccess;
}

Result SetProcessActivity(Core::System& system, Handle process_handle,
                          ProcessActivity process_activity) {
    UNIMPLEMENTED();
    R_THROW(ResultNotImplemented);
}

Result SetThreadActivity64(Core::System& system, Handle thread_handle,
                           ThreadActivity thread_activity) {
    return SetThreadActivity(system, thread_handle, thread_activity);
}

Result SetProcessActivity64(Core::System& system, Handle process_handle,
                            ProcessActivity process_activity) {
    return SetProcessActivity(system, process_handle, process_activity);
}

Result SetThreadActivity64From32(Core::System& system, Handle thread_handle,
                                 ThreadActivity thread_activity) {
    return SetThreadActivity(system, thread_handle, thread_activity);
}

Result SetProcessActivity64From32(Core::System& system, Handle process_handle,
                                  ProcessActivity process_activity) {
    return SetProcessActivity(system, process_handle, process_activity);
}

} // namespace Kernel::Svc