Не удается найти pid в системном вызове в ядре Linux - PullRequest
0 голосов
/ 04 ноября 2019

Используя Ubuntu 18.04.3 x64, я обновил ядро ​​с 4.xx до 5.1.0. Затем я сделал новый системный вызов ниже.

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;
}

Затем я скомпилировал ядро, чтобы отразить это изменение. Затем, используя файл тестера, у меня есть следующее:

#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;
}

Но когда я запускаю файл тестера, я получаю:

"Task not found."

В чем проблема?

...