i am writing a custom system call for linux kernel everything works fine with the function call and now i am trying to create a wrapper function in order to use the function normally in any program without using the syscall (call)
我正在为linux内核编写自定义系统调用一切正常,函数调用现在我正在尝试创建一个包装函数,以便在任何程序中正常使用该函数而不使用syscall(调用)
what i have done so far is
到目前为止我所做的是
#include <stdlib.h>
#include<stdio.h>
#include<linux/unistd.h>
#include<errno.h>
#include <sys/types.h>
#include <unistd.h>
#include<string.h>
#include <linux/sched.h>
#include <linux/kernel.h>
long *__wrap_process_info(int myid , void *udata)
{
return syscall(337 , myid , udata);
}
my system call returns -1 on error and 0 if executed correctly my question is , how to make the wrapper function return the syscall return value ? and ,do i need to include a main in the wrapper function ?
我的系统调用在错误时返回-1,如果正确执行则返回0我的问题是,如何使包装函数返回syscall返回值?而且,我需要在包装函数中包含一个main吗?
1 个解决方案
#1
0
Assuming that you are using the *
as a wildcard and not pointer notation. Your implementation is already returning the value returned by the function syscall
. In case there is an error, it's code is stored in errno
variable, which you might want to copy to some additional parameter you will pass to your function:
假设您使用*作为通配符而不是指针表示法。您的实现已经返回函数syscall返回的值。如果出现错误,它的代码存储在errno变量中,您可能希望将其复制到您将传递给函数的其他参数:
long <???>__wrap_process_info(int myid , void *udata, long *err )
{
long result;
result = syscall(337 , myid , udata);
*err = errno;
return result;
}
#1
0
Assuming that you are using the *
as a wildcard and not pointer notation. Your implementation is already returning the value returned by the function syscall
. In case there is an error, it's code is stored in errno
variable, which you might want to copy to some additional parameter you will pass to your function:
假设您使用*作为通配符而不是指针表示法。您的实现已经返回函数syscall返回的值。如果出现错误,它的代码存储在errno变量中,您可能希望将其复制到您将传递给函数的其他参数:
long <???>__wrap_process_info(int myid , void *udata, long *err )
{
long result;
result = syscall(337 , myid , udata);
*err = errno;
return result;
}