c - 在linux内核的系统调用中找不到pid
问题描述
使用 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."
问题出在哪里?
解决方案
推荐阅读
- windows - ec2 用户数据跳过 Powershell 块
- ios - 如何在 Swift 中制作单例 AdMob 插页式广告?
- django - 如何使 Django 表单字段唯一?
- firebase - 在初始化时读取用户的最佳方式
- ruby - 在 Postgres 中将带有 UTC 的时间戳转换为毫秒
- node.js - nodejs从会话中删除变量
- javascript - 如何从 JavaScript 中的 Set 中删除对象
- mysql - 无法重新启动 mysql(有关详细信息,请参阅“systemctl status mysql.service”和“journalctl -xe”。)
- jquery - 从 jquery-1.11.1.js 迁移到 jquery-1.12.4.js
- google-chrome-extension - 如何在不打开空选项卡的情况下从扩展程序启动自定义 URI?