更改entry.S中的system_call时发生内核恐慌
我正在尝试实现一个系统调用计数器,因此我在 task_struct 中包含了一个 int 值,以及一个在单独的文件中递增它的函数。这个函数应该在它实际调用所需的 sys_call 之前从 system_call 调用(我有理由在之前而不是之后调用它)。但是,如果我将它放在 sys_call 之前,那么在编译和启动之后会出现内核恐慌(“试图终止 init_idle”),如果我将它放在 sys_call 之后,它就会起作用。有什么区别以及如何克服这个问题?
这是相关代码
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'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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜想
%eax
会因调用update_counter
而被丢弃。特别是,如果这是一个 C 函数(而不是手写汇编),那么调用约定意味着它几乎肯定会被更改:%eax
被定义为返回结果(或其一部分) ,或者(在其他情况下,例如返回void
的函数)可供被调用者自由使用而不保留它。尝试:
I would guess that
%eax
is being trashed by the call toupdate_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 returningvoid
) be free for the callee to use without preserving it.Try: