Quantcast
Channel: Active questions tagged linux-kernel - Stack Overflow
Viewing all articles
Browse latest Browse all 12244

Cannot find pid in system call in linux kernel

$
0
0

Using Ubuntu 18.04.3 x64 I upgraded the kernel from 4.x.x to 5.1.0. Then I made a new system call below.

SYSCALL_DEFINE1(get_mem_info, pid_t, input_pid)
{
    printk("Starting system call (get_mem_info)\n");
    struct task_struct *task;
    int found = 0;
    for (task = &init_task; next_task(task) != &init_task; task = next_task(task))
    {
        if (task->pid == input_pid)
        {
            found = 1;
            printk("Task was found\n");
            break;
        }
    }
    if (found)
    {
        struct vm_area_struct *vma;
        unsigned long total_size = 0;
        int i = 0;

        vma = task->mm->mmap;

        while (vma != NULL)
        {
            printk("The number %d vma's access permissions is %lu\n", i, vma->vm_page_prot.pgprot);
            printk("The file name mapped to this vma is %s\n", vma->vm_file->f_path.dentry->d_name.name);

            total_size += (vma->vm_end - vma->vm_start);
            i++;
            vma = vma->vm_next;
        }

        printk("The size of the process' virtual address space is %lu\n", total_size);
    }
    else
    {
        printk("Task not found\n");
    }
  return 0;
}

Then I compiled the kernel to reflect this change. Then using a tester file I have the below:

#include <linux/unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>

#define __NR_get_mem_info 338


int main(int argc, char *argv[])
{
    pid_t pid = getpid();   //get current process pid
    syscall (__NR_get_mem_info, pid);
    return 0;
}

But when I run the tester file I get:

"Task not found."

Where is the problem?


Viewing all articles
Browse latest Browse all 12244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>