I'm new to kernel development so bear with me please. I'm looking to map Kernel memory to userspace in order to read it without copying. Here is a snippet of example code it seems to break in read_from_process().
struct mm_struct *mm;
struct task_struct *task; //global vars will get rid of them later
void find_process_info(void)
{
for_each_process(task)
{
const char *str1 = task->comm;
const char *str2 = "firefox";
if(!(strcmp(str1, str2)))
{
//printk(KERN_INFO "%s [%d]\n", task->comm, task->pid);
mm = task->mm;
break;
}
}
}
void read_from_process(void)
{
struct vm_area_struct *vma = mm->mmap;
unsigned long len = vma->vm_end - vma->vm_start;
int ret;
ret = remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, len, vma->vm_page_prot);
if(ret < 0)
{
printk(KERN_INFO "Could not map the address area!\n");
}
}
for_each_process is able to find the the task info for Firefox when open including printing out the PID to the kernel log so that's working, but the kernel module breaks in read_from_process when loading.