원래 do_fork 주소를 호출하기 전에 내 보낸 심볼 'do_fork'의 주소를 내 함수를 가리 키도록 변경하려고 시도한 모듈을 작성했습니다. 지금까지 나는 좌상 피연산자로 요구되는 lvalue 에러를주는 것처럼 주소를 바꿀 수 없다. '커널 함수 포인터 주소 변경
do_fork() 포인터를 내 함수 fake_fork()로 변경하는 방법을 모르겠습니다.
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/sched.h>
#include <linux/module.h>
int c=0;
long fake_fork(unsigned long a, unsigned long b, unsigned long c, int __user *d, int __user *e)
{
++c;
return do_fork(a, b, c, d, e);
}
EXPORT_SYMBOL(fake_fork);
static int fork_proc_show(struct seq_file *m, void *v)
{
seq_printf(m, "System Call fork called: %d times.\n", c);
return 0;
}
static int fork_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, fork_proc_show, NULL);
}
static const struct file_operations fork_proc_fops = {
.open = fork_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static int __init proc_fork_init(void)
{
do_fork = fake_fork; // <-- Not working
printk("init proc forkcounter\n");
proc_create("forkcounter", 0, NULL, &fork_proc_fops);
return 0;
}
static void __exit cleanup_fork_module(void)
{
remove_proc_entry("forkcounter",NULL);
printk("cleanup proc forkcounter\n");
}
module_init(proc_fork_init);
module_exit(cleanup_fork_module);
'fake_fork()'를 직접 호출해야하는 이유는 무엇입니까? –