mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:28:12 +00:00
Kernel: Add a systrace() syscall and implement /bin/strace using it.
Calling systrace(pid) gives you a file descriptor with a stream of the syscalls made by a peer process. The process must be owned by the same UID who calls systrace(). :^)
This commit is contained in:
parent
6693cfb26a
commit
5c68929aa1
12 changed files with 188 additions and 1 deletions
|
@ -22,6 +22,7 @@
|
|||
#include <Kernel/ELF/exec_elf.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <Kernel/SharedMemory.h>
|
||||
#include <Kernel/ProcessTracer.h>
|
||||
|
||||
//#define DEBUG_IO
|
||||
//#define TASK_DEBUG
|
||||
|
@ -1894,6 +1895,9 @@ void Process::finalize()
|
|||
|
||||
void Process::die()
|
||||
{
|
||||
if (m_tracer)
|
||||
m_tracer->set_dead();
|
||||
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
for_each_thread([] (Thread& thread) {
|
||||
|
@ -2482,3 +2486,26 @@ int Process::sys$ftruncate(int fd, off_t length)
|
|||
return -EINVAL;
|
||||
return descriptor->truncate(length);
|
||||
}
|
||||
|
||||
int Process::sys$systrace(pid_t pid)
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
auto* peer = Process::from_pid(pid);
|
||||
if (!peer)
|
||||
return -ESRCH;
|
||||
if (peer->uid() != m_euid)
|
||||
return -EACCES;
|
||||
int fd = alloc_fd();
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
auto descriptor = FileDescriptor::create(peer->ensure_tracer());
|
||||
m_fds[fd].set(move(descriptor), 0);
|
||||
return fd;
|
||||
}
|
||||
|
||||
ProcessTracer& Process::ensure_tracer()
|
||||
{
|
||||
if (!m_tracer)
|
||||
m_tracer = ProcessTracer::create(m_pid);
|
||||
return *m_tracer;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue