【发布时间】:2021-06-30 01:01:24
【问题描述】:
因此,我正在尝试在 Red Hat 2.4.20 中为我一直在从事的项目进行新的系统调用。对于我已经创建了一个 C 文件来尝试系统调用是否有效,并且几天来我一直收到相同的错误,取消引用指向不完整类型的指针。我的头文件在这里:
struct prcdata {
long counter; /* process counter value */
long nice; /* process nice value */
long prio; /* calculated with 20- processes’ nice value */
long weight; /* calculated with 20-nice+counter */
pid_t pid; /* process id */
long uid; /* user id of process owner */
int nofprocess; /* number of process of owner of current process
*/}
;
我的系统调用的C文件是这样的
#include <linux/mysyscall.h>
asmlinkage int cprocinf(struct prcdata *data)
{
cli();
struct prcdata temp;
copy_from_user(&temp,data,sizeof(struct prcdata));
temp.prio=20-current->nice;
temp.weight=current->counter + temp.prio;
temp.rank=2*current->nice;
temp.pid=current->pid;
temp.uid=current->uid;
temp.processcount=current->user->proccesses.counter;
copy_to_user(data,&temp,sizeof(struct prcdata));
return 0;
sti();
}
而尝试这段代码的文件是这样的
#include <linux/mysyscall.h>
#include <stdio.h>
main(){
int ret;
struct prcdata *data;
ret=mysyscall(data);
printf("First values of process\n");
printf("Nice Value. %d\nPriority: %d\n", -data->prio+20,data->prio);
printf("Weight: %d\n", data->weight);
printf("Rank: %d\nPid: %d\nPid: %d\nParent: %d\nProcess Count: %d\n",data->rank,data->pid,data->pidparent,data->processcount);
}
我做错了什么
【问题讨论】:
-
您将一个未初始化的指针传递给
mysycall。arg1是在哪里定义的?
标签: c linux pointers kernel system-calls