Skip to content

Commit dd887e1

Browse files
committed
Add a /proc/PID/regs that shows register state from the process's TSS.
1 parent 678882e commit dd887e1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Kernel/ProcFileSystem.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,27 @@ ByteBuffer procfs$pid_stack(Process& process)
105105
return buffer;
106106
}
107107

108+
ByteBuffer procfs$pid_regs(Process& process)
109+
{
110+
ProcessInspectionScope scope(process);
111+
auto& tss = process.tss();
112+
auto buffer = ByteBuffer::createUninitialized(1024);
113+
char* ptr = (char*)buffer.pointer();
114+
ptr += ksprintf(ptr, "eax: %x\n", tss.eax);
115+
ptr += ksprintf(ptr, "ebx: %x\n", tss.ebx);
116+
ptr += ksprintf(ptr, "ecx: %x\n", tss.ecx);
117+
ptr += ksprintf(ptr, "edx: %x\n", tss.edx);
118+
ptr += ksprintf(ptr, "esi: %x\n", tss.esi);
119+
ptr += ksprintf(ptr, "edi: %x\n", tss.edi);
120+
ptr += ksprintf(ptr, "ebp: %x\n", tss.ebp);
121+
ptr += ksprintf(ptr, "cr3: %x\n", tss.cr3);
122+
ptr += ksprintf(ptr, "flg: %x\n", tss.eflags);
123+
ptr += ksprintf(ptr, "sp: %w:%x\n", tss.ss, tss.esp);
124+
ptr += ksprintf(ptr, "pc: %w:%x\n", tss.cs, tss.eip);
125+
buffer.trim(ptr - (char*)buffer.pointer());
126+
return buffer;
127+
}
128+
108129
ByteBuffer procfs$pid_exe(Process& process)
109130
{
110131
ProcessInspectionScope scope(process);
@@ -121,6 +142,7 @@ void ProcFileSystem::addProcess(Process& process)
121142
m_pid2inode.set(process.pid(), dir.index());
122143
addFile(createGeneratedFile("vm", [&process] { return procfs$pid_vm(process); }), dir.index());
123144
addFile(createGeneratedFile("stack", [&process] { return procfs$pid_stack(process); }), dir.index());
145+
addFile(createGeneratedFile("regs", [&process] { return procfs$pid_regs(process); }), dir.index());
124146
addFile(createGeneratedFile("fds", [&process] { return procfs$pid_fds(process); }), dir.index());
125147
if (process.executableInode().isValid())
126148
addFile(createGeneratedFile("exe", [&process] { return procfs$pid_exe(process); }, 00120777), dir.index());

0 commit comments

Comments
 (0)