mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:37:35 +00:00
ptrace: Add PT_PEEK
PT_PEEK reads a single word from the tracee's address space and returns it to the tracer.
This commit is contained in:
parent
77f671b462
commit
984ff93406
4 changed files with 28 additions and 2 deletions
|
@ -108,9 +108,17 @@ int main(int argc, char** argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("hit breakpoint\n");
|
PtraceRegisters regs;
|
||||||
|
if (ptrace(PT_GETREGS, g_pid, ®s, 0) == -1) {
|
||||||
|
perror("getregs");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
sleep(1);
|
printf("hit breakpoint\n");
|
||||||
|
printf("eip:0x%x\n", regs.eip);
|
||||||
|
|
||||||
|
uint32_t data = ptrace(PT_PEEK, g_pid, (void*)regs.eip, 0);
|
||||||
|
printf("data: 0x%x\n", data);
|
||||||
|
|
||||||
if (ptrace(PT_CONTINUE, g_pid, 0, 0) == -1) {
|
if (ptrace(PT_CONTINUE, g_pid, 0, 0) == -1) {
|
||||||
perror("continue");
|
perror("continue");
|
||||||
|
|
|
@ -69,6 +69,7 @@
|
||||||
#include <Kernel/Time/TimeManagement.h>
|
#include <Kernel/Time/TimeManagement.h>
|
||||||
#include <Kernel/VM/PageDirectory.h>
|
#include <Kernel/VM/PageDirectory.h>
|
||||||
#include <Kernel/VM/PrivateInodeVMObject.h>
|
#include <Kernel/VM/PrivateInodeVMObject.h>
|
||||||
|
#include <Kernel/VM/ProcessPagingScope.h>
|
||||||
#include <Kernel/VM/PurgeableVMObject.h>
|
#include <Kernel/VM/PurgeableVMObject.h>
|
||||||
#include <Kernel/VM/SharedInodeVMObject.h>
|
#include <Kernel/VM/SharedInodeVMObject.h>
|
||||||
#include <LibBareMetal/IO.h>
|
#include <LibBareMetal/IO.h>
|
||||||
|
@ -4973,6 +4974,21 @@ int Process::sys$ptrace(const Syscall::SC_ptrace_params* user_params)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case PT_PEEK: {
|
||||||
|
uint32_t* addr = reinterpret_cast<uint32_t*>(params.addr);
|
||||||
|
if (!MM.validate_user_read(peer->process(), VirtualAddress(addr), sizeof(uint32_t))) {
|
||||||
|
return -EFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t result;
|
||||||
|
|
||||||
|
SmapDisabler dis;
|
||||||
|
ProcessPagingScope scope(peer->process());
|
||||||
|
result = *addr;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
|
@ -554,3 +554,4 @@ struct rtentry {
|
||||||
#define PT_SYSCALL 4
|
#define PT_SYSCALL 4
|
||||||
#define PT_GETREGS 5
|
#define PT_GETREGS 5
|
||||||
#define PT_DETACH 6
|
#define PT_DETACH 6
|
||||||
|
#define PT_PEEK 7
|
||||||
|
|
|
@ -36,6 +36,7 @@ __BEGIN_DECLS
|
||||||
#define PT_SYSCALL 4
|
#define PT_SYSCALL 4
|
||||||
#define PT_GETREGS 5
|
#define PT_GETREGS 5
|
||||||
#define PT_DETACH 6
|
#define PT_DETACH 6
|
||||||
|
#define PT_PEEK 7
|
||||||
|
|
||||||
int ptrace(int request, pid_t pid, void* addr, int data);
|
int ptrace(int request, pid_t pid, void* addr, int data);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue