forked from Bananymous/banan-os
Kernel: Scheduler now sends queued signals
This commit is contained in:
parent
a989c44211
commit
b56316e9da
|
@ -37,6 +37,7 @@ namespace Kernel
|
|||
BAN::ErrorOr<Thread*> clone(Process*, uintptr_t rsp, uintptr_t rip);
|
||||
void setup_exec();
|
||||
|
||||
void handle_next_signal();
|
||||
void handle_signal(int signal, uintptr_t& return_rsp, uintptr_t& return_rip);
|
||||
|
||||
pid_t tid() const { return m_tid; }
|
||||
|
|
|
@ -794,6 +794,8 @@ namespace Kernel
|
|||
if (signal < _SIGMIN || signal > _SIGMAX)
|
||||
return BAN::Error::from_errno(EINVAL);
|
||||
ASSERT(m_threads.size() == 1);
|
||||
CriticalScope _;
|
||||
Thread::current().m_signal_queue.push(signal);
|
||||
Thread::current().handle_signal(signal, return_rsp, return_rip);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -212,6 +212,8 @@ namespace Kernel
|
|||
current.set_started();
|
||||
start_thread(current.rsp(), current.rip());
|
||||
case Thread::State::Executing:
|
||||
while (!current.m_signal_queue.empty())
|
||||
current.handle_next_signal();
|
||||
continue_thread(current.rsp(), current.rip());
|
||||
case Thread::State::Terminating:
|
||||
ENABLE_INTERRUPTS();
|
||||
|
|
|
@ -143,10 +143,20 @@ namespace Kernel
|
|||
}
|
||||
}
|
||||
|
||||
void Thread::handle_next_signal()
|
||||
{
|
||||
ASSERT(!interrupts_enabled());
|
||||
ASSERT(!m_signal_queue.empty());
|
||||
handle_signal(m_signal_queue.front(), m_rsp, m_rip);
|
||||
}
|
||||
|
||||
void Thread::handle_signal(int signal, uintptr_t& return_rsp, uintptr_t& return_rip)
|
||||
{
|
||||
ASSERT(!interrupts_enabled());
|
||||
ASSERT(signal >= _SIGMIN && signal <= _SIGMAX);
|
||||
ASSERT(&Thread::current() == this);
|
||||
ASSERT(!m_signal_queue.empty());
|
||||
ASSERT(m_signal_queue.front() == signal);
|
||||
|
||||
// Skip masked (ignored) signals
|
||||
if (m_signal_mask & (1ull << signal))
|
||||
|
@ -154,7 +164,6 @@ namespace Kernel
|
|||
|
||||
if (m_signal_handlers[signal])
|
||||
{
|
||||
asm volatile("cli");
|
||||
write_to_stack(return_rsp, return_rip);
|
||||
write_to_stack(return_rsp, signal);
|
||||
write_to_stack(return_rsp, m_signal_handlers[signal]);
|
||||
|
@ -193,6 +202,8 @@ namespace Kernel
|
|||
{
|
||||
auto message = BAN::String::formatted("killed by signal {}\n", signal);
|
||||
(void)process().tty().write(0, message.data(), message.size());
|
||||
|
||||
ENABLE_INTERRUPTS();
|
||||
process().exit(128 + signal);
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
@ -214,8 +225,6 @@ namespace Kernel
|
|||
}
|
||||
}
|
||||
|
||||
asm volatile("cli");
|
||||
if (!m_signal_queue.empty() && m_signal_queue.front() == signal)
|
||||
m_signal_queue.pop();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue