summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/k_thread.h
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2021-05-08 08:30:17 +0200
committerGitHub <noreply@github.com>2021-05-08 08:30:17 +0200
commitfaa067f175cbf5e916ed75776817f0046e6731c4 (patch)
tree8ab02a72a6e4d6578848c8da2c02af02684aeec7 /src/core/hle/kernel/k_thread.h
parentMerge pull request #6287 from lioncash/ldr-copy (diff)
parenthle: kernel: KPageTable: CanContain should not be constexpr. (diff)
downloadyuzu-faa067f175cbf5e916ed75776817f0046e6731c4.tar
yuzu-faa067f175cbf5e916ed75776817f0046e6731c4.tar.gz
yuzu-faa067f175cbf5e916ed75776817f0046e6731c4.tar.bz2
yuzu-faa067f175cbf5e916ed75776817f0046e6731c4.tar.lz
yuzu-faa067f175cbf5e916ed75776817f0046e6731c4.tar.xz
yuzu-faa067f175cbf5e916ed75776817f0046e6731c4.tar.zst
yuzu-faa067f175cbf5e916ed75776817f0046e6731c4.zip
Diffstat (limited to '')
-rw-r--r--src/core/hle/kernel/k_thread.h127
1 files changed, 49 insertions, 78 deletions
diff --git a/src/core/hle/kernel/k_thread.h b/src/core/hle/kernel/k_thread.h
index b442dfe57..4145ef56c 100644
--- a/src/core/hle/kernel/k_thread.h
+++ b/src/core/hle/kernel/k_thread.h
@@ -19,7 +19,7 @@
#include "core/hle/kernel/k_light_lock.h"
#include "core/hle/kernel/k_spin_lock.h"
#include "core/hle/kernel/k_synchronization_object.h"
-#include "core/hle/kernel/object.h"
+#include "core/hle/kernel/slab_helpers.h"
#include "core/hle/kernel/svc_common.h"
#include "core/hle/kernel/svc_types.h"
#include "core/hle/result.h"
@@ -37,7 +37,7 @@ namespace Kernel {
class GlobalSchedulerContext;
class KernelCore;
-class Process;
+class KProcess;
class KScheduler;
class KThreadQueue;
@@ -99,9 +99,13 @@ enum class ThreadWaitReasonForDebugging : u32 {
[[nodiscard]] KThread& GetCurrentThread(KernelCore& kernel);
[[nodiscard]] s32 GetCurrentCoreId(KernelCore& kernel);
-class KThread final : public KSynchronizationObject, public boost::intrusive::list_base_hook<> {
+class KThread final : public KAutoObjectWithSlabHeapAndContainer<KThread, KSynchronizationObject>,
+ public boost::intrusive::list_base_hook<> {
+ KERNEL_AUTOOBJECT_TRAITS(KThread, KSynchronizationObject);
+
+private:
friend class KScheduler;
- friend class Process;
+ friend class KProcess;
public:
static constexpr s32 DefaultThreadPriority = 44;
@@ -115,74 +119,10 @@ public:
using ThreadContext64 = Core::ARM_Interface::ThreadContext64;
using WaiterList = boost::intrusive::list<KThread>;
- /**
- * Creates and returns a new thread.
- * @param system The instance of the whole system
- * @param name The friendly name desired for the thread
- * @param entry_point The address at which the thread should start execution
- * @param priority The thread's priority
- * @param arg User data to pass to the thread
- * @param processor_id The ID(s) of the processors on which the thread is desired to be run
- * @param stack_top The address of the thread's stack top
- * @param owner_process The parent process for the thread, if null, it's a kernel thread
- * @return A shared pointer to the newly created thread
- */
- [[nodiscard]] static ResultVal<std::shared_ptr<KThread>> CreateThread(
- Core::System& system, ThreadType type_flags, std::string name, VAddr entry_point,
- u32 priority, u64 arg, s32 processor_id, VAddr stack_top, Process* owner_process);
-
- /**
- * Creates and returns a new thread, with a specified entry point.
- * @param system The instance of the whole system
- * @param name The friendly name desired for the thread
- * @param entry_point The address at which the thread should start execution
- * @param priority The thread's priority
- * @param arg User data to pass to the thread
- * @param processor_id The ID(s) of the processors on which the thread is desired to be run
- * @param stack_top The address of the thread's stack top
- * @param owner_process The parent process for the thread, if null, it's a kernel thread
- * @param thread_start_func The function where the host context will start.
- * @param thread_start_parameter The parameter which will passed to host context on init
- * @return A shared pointer to the newly created thread
- */
- [[nodiscard]] static ResultVal<std::shared_ptr<KThread>> CreateThread(
- Core::System& system, ThreadType type_flags, std::string name, VAddr entry_point,
- u32 priority, u64 arg, s32 processor_id, VAddr stack_top, Process* owner_process,
- std::function<void(void*)>&& thread_start_func, void* thread_start_parameter);
-
- /**
- * Creates and returns a new thread for the emulated "user" process.
- * @param system The instance of the whole system
- * @param name The friendly name desired for the thread
- * @param entry_point The address at which the thread should start execution
- * @param priority The thread's priority
- * @param arg User data to pass to the thread
- * @param processor_id The ID(s) of the processors on which the thread is desired to be run
- * @param stack_top The address of the thread's stack top
- * @param owner_process The parent process for the thread, if null, it's a kernel thread
- * @return A shared pointer to the newly created thread
- */
- [[nodiscard]] static ResultVal<std::shared_ptr<KThread>> CreateUserThread(
- Core::System& system, ThreadType type_flags, std::string name, VAddr entry_point,
- u32 priority, u64 arg, s32 processor_id, VAddr stack_top, Process* owner_process);
-
- [[nodiscard]] std::string GetName() const override {
- return name;
- }
-
void SetName(std::string new_name) {
name = std::move(new_name);
}
- [[nodiscard]] std::string GetTypeName() const override {
- return "Thread";
- }
-
- static constexpr HandleType HANDLE_TYPE = HandleType::Thread;
- [[nodiscard]] HandleType GetHandleType() const override {
- return HANDLE_TYPE;
- }
-
/**
* Gets the thread's current priority
* @return The current thread's priority
@@ -257,10 +197,6 @@ public:
void Suspend();
- void Finalize() override;
-
- bool IsSignaled() const override;
-
void SetSyncedObject(KSynchronizationObject* obj, ResultCode wait_res) {
synced_object = obj;
wait_result = wait_res;
@@ -354,11 +290,11 @@ public:
current_core_id = core;
}
- [[nodiscard]] Process* GetOwnerProcess() {
+ [[nodiscard]] KProcess* GetOwnerProcess() {
return parent;
}
- [[nodiscard]] const Process* GetOwnerProcess() const {
+ [[nodiscard]] const KProcess* GetOwnerProcess() const {
return parent;
}
@@ -422,6 +358,40 @@ public:
return termination_requested || GetRawState() == ThreadState::Terminated;
}
+ [[nodiscard]] virtual u64 GetId() const override final {
+ return this->GetThreadID();
+ }
+
+ [[nodiscard]] virtual bool IsInitialized() const override {
+ return initialized;
+ }
+
+ [[nodiscard]] virtual uintptr_t GetPostDestroyArgument() const override {
+ return reinterpret_cast<uintptr_t>(parent) | (resource_limit_release_hint ? 1 : 0);
+ }
+
+ virtual void Finalize() override;
+
+ [[nodiscard]] virtual bool IsSignaled() const override;
+
+ static void PostDestroy(uintptr_t arg);
+
+ [[nodiscard]] static ResultCode InitializeDummyThread(KThread* thread);
+
+ [[nodiscard]] static ResultCode InitializeIdleThread(Core::System& system, KThread* thread,
+ s32 virt_core);
+
+ [[nodiscard]] static ResultCode InitializeHighPriorityThread(Core::System& system,
+ KThread* thread,
+ KThreadFunction func,
+ uintptr_t arg, s32 virt_core);
+
+ [[nodiscard]] static ResultCode InitializeUserThread(Core::System& system, KThread* thread,
+ KThreadFunction func, uintptr_t arg,
+ VAddr user_stack_top, s32 prio,
+ s32 virt_core, KProcess* owner);
+
+public:
struct StackParameters {
u8 svc_permission[0x10];
std::atomic<u8> dpc_flags;
@@ -671,11 +641,13 @@ private:
void StartTermination();
[[nodiscard]] ResultCode Initialize(KThreadFunction func, uintptr_t arg, VAddr user_stack_top,
- s32 prio, s32 virt_core, Process* owner, ThreadType type);
+ s32 prio, s32 virt_core, KProcess* owner, ThreadType type);
[[nodiscard]] static ResultCode InitializeThread(KThread* thread, KThreadFunction func,
uintptr_t arg, VAddr user_stack_top, s32 prio,
- s32 core, Process* owner, ThreadType type);
+ s32 core, KProcess* owner, ThreadType type,
+ std::function<void(void*)>&& init_func,
+ void* init_func_parameter);
static void RestorePriority(KernelCore& kernel, KThread* thread);
@@ -697,7 +669,7 @@ private:
std::atomic<s64> cpu_time{};
KSynchronizationObject* synced_object{};
VAddr address_key{};
- Process* parent{};
+ KProcess* parent{};
VAddr kernel_stack_top{};
u32* light_ipc_data{};
VAddr tls_address{};
@@ -742,7 +714,6 @@ private:
VAddr mutex_wait_address_for_debugging{};
ThreadWaitReasonForDebugging wait_reason_for_debugging{};
ThreadType thread_type_for_debugging{};
- std::string name;
public:
using ConditionVariableThreadTreeType = ConditionVariableThreadTree;