I'm trying to implement a system call counter, and as a result I included an int value in task_struct, and a function that increments it in a separate file. This function is supposed to be called from system_call right before it actually calls the required sys_call (I have my reasons to call it before and not after). However, if I place it before the sys_call then after compiling and booting there's a kernel panic ("tried to kill init_idle"), and if I place it right after the sys_call, it works. What's the difference and how do I overcome this?
Here's the relevant code
ENTRY(system_call)
pushl %eax # save orig_eax
SAVE_ALL
GET_CURRENT(%ebx)
testb $0x02,tsk_ptrace(%ebx) # PT_TRACESYS
jne tracesys
cmpl $(NR_syscalls),%eax
jae badsys
call update_counter /*This causes a kernel panic*/
call *SYMBOL_NAME(sys_call_table)(,%eax,4)
movl %eax,EAX(%esp) # save the return value
I would guess that %eax is being trashed by the call to update_counter. In particular, if that's a C function (rather than handwritten assembly), then the calling conventions mean that it will almost certainly be changed: %eax is defined to either return the result (or part of it), or (in other cases, such as a function returning void) be free for the callee to use without preserving it.
Try:
...
pushl %eax
call update_counter
popl %eax
call *SYMBOL_NAME(sys_call_table)(,%eax,4)
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With