* Dynamic System Calls & System Call Hijacking - demo user program
@ 2004-04-20 9:09 Zoltan Menyhart
0 siblings, 0 replies; only message in thread
From: Zoltan Menyhart @ 2004-04-20 9:09 UTC (permalink / raw)
To: linux-kernel, linux-ia64
[-- Attachment #1: Type: text/plain, Size: 1 bytes --]
[-- Attachment #2: test.c --]
[-- Type: text/plain, Size: 1329 bytes --]
#include <linux/sys.h> /* For NR_syscalls */
#include <asm/unistd.h> /* For __NR_ni_syscall */
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <asm/fcntl.h> /* For O_RDONLY */
#define MY_SYSCALL "/proc/sys/kernel/dynamic_syscalls/foo"
/*
* Read out my actual system call number from "/proc/...".
*
* On error "-1" is returned and "errno" is set accordingly.
*/
static inline
get_my_syscall_no(void)
{
int fd;
int tmp;
char buff[5]; /* Should be enough :-) */
if ((fd = open(MY_SYSCALL, O_RDONLY)) < 0){
errno = ENOSYS;
return -1;
}
tmp = read(fd, buff, sizeof buff - 1);
close(fd);
if (tmp != sizeof buff - 1){
errno = ENOSYS;
return -1;
}
buff[sizeof buff - 1] = '\0';
tmp = atoi(buff);
if (tmp < __NR_ni_syscall || tmp >= __NR_ni_syscall + NR_syscalls){
errno = ENOSYS;
return -1;
}
return tmp;
}
/*
* Wrapper function for my system call.
*/
long
my_syscall(const int arg, const long arg2, const long arg3, const int arg4,
const int arg5)
{
static int syscall_no = -1;
if (syscall_no == -1)
if ((syscall_no = get_my_syscall_no())== -1)
return -1;
return syscall(syscall_no, arg, arg2, arg3, arg4, arg5);
}
main()
{
if (my_syscall(1, 0, 1, 0, 2) == -1)
perror("my syscall");
if (my_syscall(2, 3, 4, 5, 6) == -1)
perror("my syscall");
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2004-04-20 9:08 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-20 9:09 Dynamic System Calls & System Call Hijacking - demo user program Zoltan Menyhart
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox