カーネル空間内で,プロセスIDからそのプロセスのページディレクトリの物理アドレスを得るシステムコールを作った.
arch/x86/kernel/pid2cr3.c (システムコール本体)
#include <linux/pid2cr3.h> #include <linux/sched.h> #include <linux/pid.h> asmlinkage unsigned long sys_pid2cr3(int pid) { struct task_struct *p; p = pid_task(find_vpid(pid), PIDTYPE_PID); if (p && (p->active_mm != NULL)) return __pa((unsigned long) (p->active_mm->pgd)); else return 1; }
/usr/include/linux/pid2cr3.h
#ifndef NR_PID2CR3_H #define NR_PID2CR3_H #include <linux/unistd.h> #include <sys/syscall.h> #define pid2cr3(pid) syscall(__NR_pid2cr3, pid) #endif
include/linux/pid2cr3.h
#ifndef NR_PID2CR3_H #define NR_PID2CR3_H #include <linux/unistd.h> #include <linux/linkage.h> #define pid2cr3(pid) syscall(__NR_pid2cr3, pid) #endif
あとは適当に.
おまけ Pythonから上記システムコールを使うためのモジュール
#include <Python.h> #include <linux/pid2cr3.h> static PyObject * get_cr3(PyObject *self, PyObject *args) { int ok, pid; ok = PyArg_ParseTuple(args, "i", &pid); return PyLong_FromUnsignedLong(pid2cr3(pid)); } // module method tbl init static PyMethodDef SpamMethods[] = { { "pid2cr3", get_cr3, METH_VARARGS, "get CR3 value from PID" }, {NULL, NULL, 0, NULL}, }; PyMODINIT_FUNC initpid2cr3(void) { PyObject *m; m = Py_InitModule("pid2cr3", SpamMethods); }