1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:17:44 +00:00

Add some basic signal support.

It only works for sending a signal to a process that's in userspace code.

We implement reception by synthesizing a PUSHA+PUSHF in the receiving process
(operating on values in the TSS.)
The TSS CS:EIP is then rerouted to the signal handler and a tiny return
trampoline is constructed in a dedicated region in the receiving process.

Also hacked up /bin/kill to be able to send arbitrary signals (kill -N PID)
This commit is contained in:
Andreas Kling 2018-11-06 10:46:40 +01:00
parent 52d502e11f
commit 153ea704af
13 changed files with 240 additions and 30 deletions

View file

@ -15,6 +15,13 @@ class PageDirectory;
class Region;
class Zone;
struct SignalActionData {
LinearAddress handler_or_sigaction;
dword mask { 0 };
int flags { 0 };
LinearAddress restorer;
};
class Process : public InlineLinkedListNode<Process> {
friend class InlineLinkedListNode<Process>;
public:
@ -129,6 +136,7 @@ public:
int sys$getdtablesize();
int sys$dup(int oldfd);
int sys$dup2(int oldfd, int newfd);
int sys$sigaction(int signum, const Unix::sigaction* act, Unix::sigaction* old_act);
static void initialize();
@ -162,6 +170,7 @@ public:
const FileHandle* file_descriptor(size_t i) const { return m_file_descriptors[i].ptr(); }
void send_signal(int signal, Process* sender);
void terminate_due_to_signal(int signal, Process* sender);
Process* fork(RegisterDump&);
int exec(const String& path, Vector<String>&& arguments, Vector<String>&& environment);
@ -172,7 +181,7 @@ private:
Process(String&& name, uid_t, gid_t, pid_t parentPID, RingLevel, RetainPtr<VirtualFileSystem::Node>&& cwd = nullptr, RetainPtr<VirtualFileSystem::Node>&& executable = nullptr, TTY* = nullptr, Process* fork_parent = nullptr);
void allocateLDT();
void push_value_on_stack(dword);
PageDirectory* m_page_directory { nullptr };
@ -205,6 +214,7 @@ private:
int m_waiteeStatus { 0 };
int m_fdBlockedOnRead { -1 };
size_t m_max_open_file_descriptors { 16 };
SignalActionData m_signal_action_data[32];
RetainPtr<VirtualFileSystem::Node> m_cwd;
RetainPtr<VirtualFileSystem::Node> m_executable;
@ -221,6 +231,8 @@ private:
// FIXME: Implement some kind of ASLR?
LinearAddress m_nextRegion;
LinearAddress m_return_from_signal_trampoline;
pid_t m_parentPID { 0 };
static void notify_waiters(pid_t waitee, int exit_status, int signal);