mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-24 10:12:25 -05:00
153ea704af
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)
32 lines
733 B
C++
32 lines
733 B
C++
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <assert.h>
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
if (argc != 2) {
|
|
printf("usage: cat <file>\n");
|
|
return 1;
|
|
}
|
|
int fd = open(argv[1], O_RDONLY);
|
|
if (fd == -1) {
|
|
printf("failed to open %s: %s\n", argv[1], strerror(errno));
|
|
return 1;
|
|
}
|
|
for (;;) {
|
|
char buf[1024];
|
|
ssize_t nread = read(fd, buf, sizeof(buf));
|
|
if (nread == 0)
|
|
break;
|
|
if (nread < 0) {
|
|
printf("read() error: %s\n", strerror(errno));
|
|
return 2;
|
|
}
|
|
for (ssize_t i = 0; i < nread; ++i)
|
|
putchar(buf[i]);
|
|
}
|
|
return 0;
|
|
}
|