Custom linux kernel syscall wrapper function

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)

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 ?


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:

long <???>__wrap_process_info(int myid , void *udata, long *err )
{
    long result;
    result = syscall(337 , myid , udata);
    *err = errno;
    return result;
}
链接地址: http://www.djcxy.com/p/90878.html

上一篇: C库如何调用内核系统调用

下一篇: 自定义linux内核的系统调用包装函数