kernel: Implement thread stopping and continuing
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
69771cbd85
commit
e1d5b7e7b4
@ -136,6 +136,7 @@ enum class DefaultSignalAction
|
||||
{
|
||||
Ignore,
|
||||
Terminate,
|
||||
Stop,
|
||||
};
|
||||
|
||||
// FIXME: Implement coredumps for some signals.
|
||||
@ -149,9 +150,9 @@ static constexpr DefaultSignalAction default_actions[] = {
|
||||
DefaultSignalAction::Ignore, // SIGCHLD
|
||||
DefaultSignalAction::Terminate, // SIGFPE (dump core)
|
||||
DefaultSignalAction::Terminate, // SIGKILL
|
||||
DefaultSignalAction::Terminate, // SIGSTOP (FIXME: Support stopping and continuing)
|
||||
DefaultSignalAction::Stop, // SIGSTOP
|
||||
DefaultSignalAction::Terminate, // SIGSEGV (dump core)
|
||||
DefaultSignalAction::Ignore, // SIGCONT (FIXME: Support stopping and continuing)
|
||||
DefaultSignalAction::Ignore, // SIGCONT (Handled separately)
|
||||
DefaultSignalAction::Terminate, // SIGPIPE
|
||||
DefaultSignalAction::Terminate, // SIGALRM
|
||||
DefaultSignalAction::Terminate, // SIGTERM
|
||||
@ -193,6 +194,7 @@ void Thread::process_pending_signals(Registers* current_regs)
|
||||
{
|
||||
case DefaultSignalAction::Ignore: return;
|
||||
case DefaultSignalAction::Terminate: exit_and_signal_parent(signo | _SIGBIT);
|
||||
case DefaultSignalAction::Stop: stop();
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
@ -227,12 +229,25 @@ void Thread::send_signal(int signo)
|
||||
if (is_kernel) return;
|
||||
if (state == ThreadState::Exited || state == ThreadState::Dying) return;
|
||||
|
||||
if (state == ThreadState::Stopped && signo == SIGCONT)
|
||||
{
|
||||
wake_up();
|
||||
return;
|
||||
}
|
||||
|
||||
check(signo > 0 && signo <= NSIG);
|
||||
pending_signals.set(signo - 1, true);
|
||||
|
||||
if (state == ThreadState::Waiting || state == ThreadState::Sleeping || is_in_kernel(®s))
|
||||
{
|
||||
if (state == ThreadState::Stopped && signo != SIGKILL) return;
|
||||
interrupted = true;
|
||||
wake_up();
|
||||
}
|
||||
}
|
||||
|
||||
void Thread::stop()
|
||||
{
|
||||
state = ThreadState::Stopped;
|
||||
kernel_yield();
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ enum class ThreadState
|
||||
Runnable,
|
||||
Sleeping,
|
||||
Waiting,
|
||||
Stopped,
|
||||
Exited,
|
||||
Dying
|
||||
};
|
||||
@ -152,6 +153,9 @@ struct Thread : public LinkedListNode<Thread>
|
||||
Result<u64> push_mem_on_stack(const u8* mem, usize size);
|
||||
Result<u64> pop_mem_from_stack(u8* mem, usize size);
|
||||
|
||||
void stop();
|
||||
void resume();
|
||||
|
||||
void send_signal(int signo);
|
||||
|
||||
static void init();
|
||||
|
Loading…
Reference in New Issue
Block a user