Compare commits

..

No commits in common. "917203ef1143a379919ab49cb74694f8f253cf73" and "7c254e5e15067d3bef234e5419b0dabd7207d2ea" have entirely different histories.

8 changed files with 44 additions and 63 deletions

View File

@ -33,7 +33,6 @@ void reap_thread()
[[noreturn]] void init() [[noreturn]] void init()
{ {
{
kinfoln("Starting Moon %s %s", MOON_VERSION, MOON_RELEASE); kinfoln("Starting Moon %s %s", MOON_VERSION, MOON_RELEASE);
// Default hostname if nobody from userspace changes it // Default hostname if nobody from userspace changes it
@ -51,8 +50,8 @@ void reap_thread()
auto init = auto init =
mark_critical(VFS::resolve_path("/bin/preinit", Credentials {}), "Can't find init in the initial ramfs!"); mark_critical(VFS::resolve_path("/bin/preinit", Credentials {}), "Can't find init in the initial ramfs!");
auto init_thread = mark_critical(Scheduler::new_userspace_thread(init, "/bin/preinit"), auto init_thread =
"Failed to create PID 1 process for init"); mark_critical(Scheduler::new_userspace_thread(init, "/bin/preinit"), "Failed to create PID 1 process for init");
auto reap = mark_critical(Scheduler::new_kernel_thread(reap_thread, "[reap]"), auto reap = mark_critical(Scheduler::new_kernel_thread(reap_thread, "[reap]"),
"Failed to create the process reaper kernel thread"); "Failed to create the process reaper kernel thread");
@ -66,7 +65,6 @@ void reap_thread()
setup_log(log_debug_enabled(), log_serial_enabled(), false); setup_log(log_debug_enabled(), log_serial_enabled(), false);
init_thread->wake_up(); init_thread->wake_up();
}
kernel_exit(); kernel_exit();
} }

View File

@ -143,13 +143,10 @@ Result<void> UnixSocket::connect(Registers* regs, int flags, struct sockaddr* ad
m_blocked_thread = nullptr; m_blocked_thread = nullptr;
if (current->interrupted) if (current->interrupted)
{ {
if (current->will_ignore_pending_signal()) if (current->will_invoke_signal_handler()) return err(EINTR);
{
current->process_pending_signals(regs); current->process_pending_signals(regs);
continue; continue;
} }
return err(EINTR);
}
break; break;
} }
@ -185,13 +182,10 @@ Result<SharedPtr<OpenFileDescription>> UnixSocket::accept(Registers* regs, int f
m_blocked_thread = nullptr; m_blocked_thread = nullptr;
if (current->interrupted) if (current->interrupted)
{ {
if (current->will_ignore_pending_signal()) if (current->will_invoke_signal_handler()) return err(EINTR);
{
current->process_pending_signals(regs); current->process_pending_signals(regs);
continue; continue;
} }
return err(EINTR);
}
} }
check(peer); check(peer);

View File

@ -35,12 +35,8 @@ Result<u64> sys_read(Registers* regs, SyscallArgs args)
if (current->interrupted) if (current->interrupted)
{ {
kdbgln("signal: read interrupted by signal"); kdbgln("signal: read interrupted by signal");
if (current->will_ignore_pending_signal()) if (current->will_invoke_signal_handler()) return err(EINTR);
{
current->process_pending_signals(regs); current->process_pending_signals(regs);
continue;
}
return err(EINTR);
} }
} }

View File

@ -5,7 +5,7 @@
#include "thread/Scheduler.h" #include "thread/Scheduler.h"
#include <bits/poll.h> #include <bits/poll.h>
Result<u64> sys_poll(Registers*, SyscallArgs args) Result<u64> sys_poll(Registers* regs, SyscallArgs args)
{ {
struct pollfd* fds = (struct pollfd*)args[0]; struct pollfd* fds = (struct pollfd*)args[0];
nfds_t nfds = (nfds_t)args[1]; nfds_t nfds = (nfds_t)args[1];
@ -58,6 +58,8 @@ Result<u64> sys_poll(Registers*, SyscallArgs args)
{ {
guard.deactivate(); guard.deactivate();
free_impl(kfds); free_impl(kfds);
if (current->will_invoke_signal_handler()) return err(EINTR);
current->process_pending_signals(regs);
return err(EINTR); return err(EINTR);
} }
continue; continue;

View File

@ -27,13 +27,10 @@ Result<u64> sys_waitpid(Registers* regs, SyscallArgs args)
if (current->interrupted) if (current->interrupted)
{ {
kdbgln("signal: waitpid interrupted by signal"); kdbgln("signal: waitpid interrupted by signal");
if (current->will_ignore_pending_signal()) if (current->will_invoke_signal_handler()) return err(EINTR);
{
current->process_pending_signals(regs); current->process_pending_signals(regs);
goto wait_for_child; goto wait_for_child;
} }
return err(EINTR);
}
check(thread->state == ThreadState::Exited); check(thread->state == ThreadState::Exited);
} }
@ -51,13 +48,10 @@ Result<u64> sys_waitpid(Registers* regs, SyscallArgs args)
if (current->interrupted) if (current->interrupted)
{ {
kdbgln("signal: waitpid interrupted by signal"); kdbgln("signal: waitpid interrupted by signal");
if (current->will_ignore_pending_signal()) if (current->will_invoke_signal_handler()) return err(EINTR);
{
current->process_pending_signals(regs); current->process_pending_signals(regs);
goto wait_for_any_child; goto wait_for_any_child;
} }
return err(EINTR);
}
check(current->child_being_waited_for.value_or(-1) != -1); check(current->child_being_waited_for.value_or(-1) != -1);

View File

@ -186,19 +186,18 @@ void Thread::process_pending_signals(Registers* current_regs)
} }
} }
bool Thread::will_ignore_pending_signal() bool Thread::will_invoke_signal_handler()
{ {
for (int i = 0; i < NSIG; i++) for (int i = 0; i < NSIG; i++)
{ {
if (pending_signals & (1 << i)) if (pending_signals & (1 << i))
{ {
int signo = i + 1; int signo = i + 1;
if (signo == SIGKILL || signo == SIGSTOP) return false; if (signo != SIGKILL && signo != SIGSTOP && signal_mask & (1 << i)) continue;
if (signal_mask & (1 << i)) continue;
auto handler = signal_handlers[i]; auto handler = signal_handlers[i];
if (handler.sa_handler == SIG_IGN) return true; if (handler.sa_handler == SIG_IGN || handler.sa_handler == SIG_DFL) return false;
if (handler.sa_handler == SIG_DFL && default_actions[i] == DefaultSignalAction::Ignore) return true; if (signo == SIGKILL || signo == SIGSTOP) return false;
return false; return true;
} }
} }
return false; return false;

View File

@ -159,7 +159,7 @@ struct Thread : public LinkedListNode<Thread>
void process_pending_signals(Registers* current_regs); void process_pending_signals(Registers* current_regs);
bool will_ignore_pending_signal(); bool will_invoke_signal_handler();
bool deliver_signal(int signo, Registers* current_regs); bool deliver_signal(int signo, Registers* current_regs);
void sigreturn(Registers* current_regs); void sigreturn(Registers* current_regs);

View File

@ -135,8 +135,6 @@ static ssize_t read_data_into_buffer(FILE* stream)
stream->_buf.index = 0; stream->_buf.index = 0;
ssize_t nread = read(stream->_fd, stream->_buf.buffer, stream->_buf.capacity); ssize_t nread = read(stream->_fd, stream->_buf.buffer, stream->_buf.capacity);
if (nread >= 0) stream->_buf.size = nread; if (nread >= 0) stream->_buf.size = nread;
else
stream->_buf.size = 0;
stream->_buf.status |= FileStatusFlags::LastRead; stream->_buf.status |= FileStatusFlags::LastRead;
return nread; return nread;
} }