#include <linux/module.h>
#include <linux/sched.h> /* For task_struct */
#include <linux/pid.h> /* For find_get_pid */
#include <linux/mm.h> /* For mm_struct and vm_area_struct */
void
print_memory_maps(
struct
task_struct *task)
{
struct
mm_struct *mm;
struct
vm_area_struct *vma;
if
(!task || !task->mm)
return
;
mm = task->mm;
down_read(&mm->mmap_sem);
for
(vma = mm->mmap; vma; vma = vma->vm_next) {
printk(KERN_INFO
"Address: %lx-%lx, Flags: %08lx\n"
,
(unsigned
long
)vma->vm_start,
(unsigned
long
)vma->vm_end,
(unsigned
long
)vma->vm_flags);
}
up_read(&mm->mmap_sem);
}
static
int
__init my_module_init(
void
)
{
struct
pid *pid;
struct
task_struct *task;
pid = find_get_pid(1234);
if
(pid) {
task = pid_task(pid, PIDTYPE_PID);
if
(task) {
print_memory_maps(task);
put_task_struct(task);
}
put_pid(pid);
}
return
0;
}
static
void
__exit my_module_exit(
void
)
{
}
module_init(my_module_init);
module_exit(my_module_exit);
MODULE_LICENSE(
"GPL"
);