kernel module function arguments
- From: Ciur Eugen <ciur.eugen@xxxxxxxxx>
- Date: Thu, 06 Sep 2007 07:23:38 -0000
hi guys!
I am experimenting a kernel module:
here is it's tiny code:
/// KERNEL MODULE CODE START
#define MY_SYSCALL_NO 0
extern void* sys_call_table[];
asmlinkage int (*orig_syscall)(struct pt_regs);
asmlinkage long my_syscall(struct pt_regs regs){
// regs.eax regs.ebx regs.ecx
return 0;
}
static int dummy_init(void){
orig_syscall=sys_call_table[MY_SYSCALL_NO];
sys_call_table[MY_SYSCALL_NO] = my_syscall;
return 0;
}
static void dummy_exit(void){
sys_call_table[MY_SYSCALL_NO]=orig_syscall;
}
module_init(dummy_init);
module_exit(dummy_exit);
/// KERNEL MODULE CODE END
It's purporse is to intecept system call with number ZERO - call
function my_syscall instead actually :)
But if in userspace I use the following code, which is supposed to be
intercepted in my kernel module(please
don't ask me about the bellow code, because I am not really aware of
what it is doing) :
// USERSPACE CODE START
__attribute__((regparm(0))) int msyscall(int sno, long *args)
{
int ret;
__asm__ __volatile__ ( " push %%ebp" : :);
__asm__ __volatile__ ( " push %0" : : "g" (sno));
__asm__ __volatile__ ( " push %0" : : "g" (args[0]));
__asm__ __volatile__ ( " push %0" : : "g" (args[1]));
__asm__ __volatile__ ( " push %0" : : "g" (args[2]));
__asm__ __volatile__ ( " push %0" : : "g" (args[3]));
__asm__ __volatile__ ( " push %0" : : "g" (args[4]));
__asm__ __volatile__ ( " push %0" : : "g" (args[5]));
__asm__ __volatile__ ( " pop %%ebp; pop %%edi; pop %%esi; pop %%edx;
\
pop %%ecx; pop %%ebx; pop %%eax; int $0x80; \
pop %%ebp" : : );
__asm__ __volatile__ ( " movl %%eax, %0" : "=g" (ret):);
return ret;
}
int vsyscall(int sno, int n, ...)
{
va_list va;
long args[6];
int i;
va_start(va, n);
for(i=0; i<n; i++)
args[i]=va_arg(va, long);
va_end(va);
return msyscall(sno, args);
}
int main(int argc, char** argv)
{
vsyscall(MY_SYSCALL_NO, 3, 4, 5, 90);
return 0;
}
// USERSPACE CODE END
As a result my kernel module intercept vsyscall call (calling
my_syscall), and it's
(my_syscall's argument ) regs.eax is 0 --- showing that system call
with number 0 was intercepted.
BUT HERE IS THE PROBLEM: the other registers (regs.ebx,regs.ecx)
aren't they supposed to be equal to
3,4,5, 90 -- because un client space I pushed them on the stack ?
OK -- if not, how then I can find out arguments passed to
my_systemcall ?
Please help .
.
- Follow-Ups:
- Re: kernel module function arguments
- From: Gil Hamilton
- Re: kernel module function arguments
- From: kazaam
- Re: kernel module function arguments
- Prev by Date: Re: scull driver problem
- Next by Date: Re: kernel module function arguments
- Previous by thread: scull driver problem
- Next by thread: Re: kernel module function arguments
- Index(es):
Relevant Pages
|
|