所以我一直在将自定义系统调用添加到内核中。这是我的系统调用的源代码:
//sys_procmem.c. This syscall helps users to show the memory layout of a specific process.
#include <linux/linkage.h>
#include <linux/sched.h>
struct proc_segs {
unsigned long my_id;
unsigned long start_code;
unsigned long end_code;
unsigned long start_data;
unsigned long end_data;
unsigned long start_heap;
unsigned long end_heap;
unsigned long start_stack;
};
asmlinkage long sys_procmem( int pid, struct proc_segs * info) {
struct task_struct *task;
info->my_id = 1512853;
for_each_process(task){
if((int) task->pid==pid){
info->start_code=task->mm->start_code;
info->end_code=task->mm->end_code;
info->start_data=task->mm->start_data;
info->end_data=task->mm->end_data;
info->start_heap=task->mm->start_brk;
info->end_heap=task->mm->brk;
info->start_stack=task->mm->start_stack;
return 0;
}
}
return -1;
}
在我编译内核之后编写测试程序时,一切似乎都很好,源代码:
//sys.c
#include <sys/syscall.h>
#include <stdio.h>
#include <unistd.h>
#define SIZE 100
int main() {
long sysvalue;
unsigned long info[SIZE];
sysvalue = syscall([number_32], 1, info)
printf("My ID: %lu\n", info[0]);
}
我用以下程序编译了程序:
gcc sys.c -o sys
然后我用:
运行它./sys
我收到了这个错误:
请帮助我,谢谢你们阅读:)