core: hle: kernel: k_process: Change Status -> State.

This commit is contained in:
bunnei 2022-09-05 17:47:00 -07:00
parent 113a5ed68f
commit 25dcaf1eca
3 changed files with 27 additions and 37 deletions

View file

@ -72,7 +72,7 @@ Result KProcess::Initialize(KProcess* process, Core::System& system, std::string
process->name = std::move(process_name); process->name = std::move(process_name);
process->resource_limit = res_limit; process->resource_limit = res_limit;
process->status = ProcessStatus::Created; process->state = State::Created;
process->program_id = 0; process->program_id = 0;
process->process_id = type == ProcessType::KernelInternal ? kernel.CreateNewKernelProcessID() process->process_id = type == ProcessType::KernelInternal ? kernel.CreateNewKernelProcessID()
: kernel.CreateNewUserProcessID(); : kernel.CreateNewUserProcessID();
@ -289,7 +289,7 @@ Result KProcess::Reset() {
KScopedSchedulerLock sl{kernel}; KScopedSchedulerLock sl{kernel};
// Validate that we're in a state that we can reset. // Validate that we're in a state that we can reset.
R_UNLESS(status != ProcessStatus::Exited, ResultInvalidState); R_UNLESS(state != State::Terminated, ResultInvalidState);
R_UNLESS(is_signaled, ResultInvalidState); R_UNLESS(is_signaled, ResultInvalidState);
// Clear signaled. // Clear signaled.
@ -304,8 +304,8 @@ Result KProcess::SetActivity(ProcessActivity activity) {
KScopedSchedulerLock sl{kernel}; KScopedSchedulerLock sl{kernel};
// Validate our state. // Validate our state.
R_UNLESS(status != ProcessStatus::Exiting, ResultInvalidState); R_UNLESS(state != State::Terminating, ResultInvalidState);
R_UNLESS(status != ProcessStatus::Exited, ResultInvalidState); R_UNLESS(state != State::Terminated, ResultInvalidState);
// Either pause or resume. // Either pause or resume.
if (activity == ProcessActivity::Paused) { if (activity == ProcessActivity::Paused) {
@ -411,13 +411,13 @@ void KProcess::Run(s32 main_thread_priority, u64 stack_size) {
const std::size_t heap_capacity{memory_usage_capacity - (main_thread_stack_size + image_size)}; const std::size_t heap_capacity{memory_usage_capacity - (main_thread_stack_size + image_size)};
ASSERT(!page_table->SetMaxHeapSize(heap_capacity).IsError()); ASSERT(!page_table->SetMaxHeapSize(heap_capacity).IsError());
ChangeStatus(ProcessStatus::Running); ChangeState(State::Running);
SetupMainThread(kernel.System(), *this, main_thread_priority, main_thread_stack_top); SetupMainThread(kernel.System(), *this, main_thread_priority, main_thread_stack_top);
} }
void KProcess::PrepareForTermination() { void KProcess::PrepareForTermination() {
ChangeStatus(ProcessStatus::Exiting); ChangeState(State::Terminating);
const auto stop_threads = [this](const std::vector<KThread*>& in_thread_list) { const auto stop_threads = [this](const std::vector<KThread*>& in_thread_list) {
for (auto* thread : in_thread_list) { for (auto* thread : in_thread_list) {
@ -445,7 +445,7 @@ void KProcess::PrepareForTermination() {
main_thread_stack_size + image_size); main_thread_stack_size + image_size);
} }
ChangeStatus(ProcessStatus::Exited); ChangeState(State::Terminated);
} }
void KProcess::Finalize() { void KProcess::Finalize() {
@ -652,12 +652,12 @@ KProcess::KProcess(KernelCore& kernel_)
KProcess::~KProcess() = default; KProcess::~KProcess() = default;
void KProcess::ChangeStatus(ProcessStatus new_status) { void KProcess::ChangeState(State new_state) {
if (status == new_status) { if (state == new_state) {
return; return;
} }
status = new_status; state = new_state;
is_signaled = true; is_signaled = true;
NotifyAvailable(); NotifyAvailable();
} }

View file

@ -45,24 +45,6 @@ enum class MemoryRegion : u16 {
BASE = 3, BASE = 3,
}; };
/**
* Indicates the status of a Process instance.
*
* @note These match the values as used by kernel,
* so new entries should only be added if RE
* shows that a new value has been introduced.
*/
enum class ProcessStatus {
Created,
CreatedWithDebuggerAttached,
Running,
WaitingForDebuggerToAttach,
DebuggerAttached,
Exiting,
Exited,
DebugBreak,
};
enum class ProcessActivity : u32 { enum class ProcessActivity : u32 {
Runnable, Runnable,
Paused, Paused,
@ -89,6 +71,17 @@ public:
explicit KProcess(KernelCore& kernel_); explicit KProcess(KernelCore& kernel_);
~KProcess() override; ~KProcess() override;
enum class State {
Created = Svc::ProcessState_Created,
CreatedAttached = Svc::ProcessState_CreatedAttached,
Running = Svc::ProcessState_Running,
Crashed = Svc::ProcessState_Crashed,
RunningAttached = Svc::ProcessState_RunningAttached,
Terminating = Svc::ProcessState_Terminating,
Terminated = Svc::ProcessState_Terminated,
DebugBreak = Svc::ProcessState_DebugBreak,
};
enum : u64 { enum : u64 {
/// Lowest allowed process ID for a kernel initial process. /// Lowest allowed process ID for a kernel initial process.
InitialKIPIDMin = 1, InitialKIPIDMin = 1,
@ -163,8 +156,8 @@ public:
} }
/// Gets the current status of the process /// Gets the current status of the process
ProcessStatus GetStatus() const { State GetState() const {
return status; return state;
} }
/// Gets the unique ID that identifies this particular process. /// Gets the unique ID that identifies this particular process.
@ -415,10 +408,7 @@ private:
pinned_threads[core_id] = nullptr; pinned_threads[core_id] = nullptr;
} }
/// Changes the process status. If the status is different void ChangeState(State new_state);
/// from the current process status, then this will trigger
/// a process signal.
void ChangeStatus(ProcessStatus new_status);
/// Allocates the main thread stack for the process, given the stack size in bytes. /// Allocates the main thread stack for the process, given the stack size in bytes.
Result AllocateMainThreadStack(std::size_t stack_size); Result AllocateMainThreadStack(std::size_t stack_size);
@ -427,7 +417,7 @@ private:
std::unique_ptr<KPageTable> page_table; std::unique_ptr<KPageTable> page_table;
/// Current status of the process /// Current status of the process
ProcessStatus status{}; State state{};
/// The ID of this process /// The ID of this process
u64 process_id = 0; u64 process_id = 0;

View file

@ -1888,7 +1888,7 @@ static void ExitProcess(Core::System& system) {
auto* current_process = system.Kernel().CurrentProcess(); auto* current_process = system.Kernel().CurrentProcess();
LOG_INFO(Kernel_SVC, "Process {} exiting", current_process->GetProcessID()); LOG_INFO(Kernel_SVC, "Process {} exiting", current_process->GetProcessID());
ASSERT_MSG(current_process->GetStatus() == ProcessStatus::Running, ASSERT_MSG(current_process->GetState() == KProcess::State::Running,
"Process has already exited"); "Process has already exited");
system.Exit(); system.Exit();
@ -2557,7 +2557,7 @@ static Result GetProcessInfo(Core::System& system, u64* out, Handle process_hand
return ResultInvalidEnumValue; return ResultInvalidEnumValue;
} }
*out = static_cast<u64>(process->GetStatus()); *out = static_cast<u64>(process->GetState());
return ResultSuccess; return ResultSuccess;
} }