Gcc không include được sys/syscall.h

mình đang làm một bài tập về việc hook device vào kernel nhưng mà lúc compile file thì gcc lại ko include dc sys/syscall.h
mình đã tìm trên mạng cả buổi tối rồi mà vẫn ko tìm được cách giải quyết
ai biết chỉ giùm mình với
xin cảm ơn

file hook-open.c

#include <linux/module.h>
#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/kdev_t.h>
#include <linux/fs.h>
#include <linux/device.h>
#include <linux/cdev.h>
#include <linux/random.h>
#include <sys/syscall.h>
#include <unistd.h>
#define DEVICE_AUTHOR "Nguyen Trong Tin - 1712816"
#define DEVICE_DESCRIPTION "MyDevice - hook-open"
asmlinkage int hook_function(const char *pathname, int flags)
{
	printk(KERN_INFO "Calling process:%s\n",current->comm);
	printk(KERN_INFO "Openning file:%s\n",pathname);
	return custom_syscall(const char *pathname, int flags);
}
static int __init my_init(void)
{
	printk(KERN_INFO "Hook Device: hook-open init\n");
	system_call_table_addr = (void*)0xffffffff81e001a0;
	custom_syscall = system_call_table_addr[__NR_open];
	make_rw((unsigned long)system_call_table_addr);
	system_call_table_addr[__NR_open] = hook_function;
	return 0;
}
static void __exit my_exit(void)
{
	printk(KERN_INFO "Hook Device: hook-open exit\n");
	system_call_table_addr[__NR_open] = custom_syscall;
	make_ro((unsigned long)system_call_table_addr);
	return 0;
}
module_init(my_init);
module_exit(my_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR(DEVICE_AUTHOR);
MODULE_DESCRIPTION(DEVICE_DESCRIPTION);

file hook-write.c

#include <linux/module.h>
#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/kdev_t.h>
#include <linux/fs.h>
#include <linux/device.h>
#include <linux/cdev.h>
#include <linux/random.h>
#include <sys/syscall.h>
#include <unistd.h>
#define DEVICE_AUTHOR "Nguyen Trong Tin - 1712816"
#define DEVICE_DESCRIPTION "MyDevice - hook-write"
ssize_t hook_function(int fd, const void *buf, size_t count)
{
	printk(KERN_INFO "Calling process:%s\n",current->comm);
	char pathname[255];
	fd_to_pathname(fd,pathname);
	printk(KERN_INFO "Written file: %s\n",pathname);
	int written_bytes = custom_syscall(fd, buf, count);
	printk(KERN_INFO "Number of written bytes:%d\n",
	written_bytes);
	return written_bytes;
}
static int __init my_init(void)
{
	printk(KERN_INFO "MyDevice: hook-write init\n");
	system_call_table_addr = (void*)0xffffffff81e001a0;
	custom_syscall = system_call_table_addr[__NR_write];
	make_rw((unsigned long)system_call_table_addr);
	system_call_table_addr[__NR_write] = hook_function;
	return 0;
}
static void __exit my_exit(void)
{
	printk(KERN_INFO "MyDevice: hook-write exit\n");
	system_call_table_addr[__NR_write] = custom_syscall;
	make_ro((unsigned long)system_call_table_addr);
	return 0;
}
module_init(my_init);
module_exit(my_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR(DEVICE_AUTHOR);
MODULE_DESCRIPTION(DEVICE_DESCRIPTION);

file Makefile

obj-m += hook-open.o
all:
	make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules
clean:
	make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) clean
obj-m += hook-write.o
all:
	make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules
clean:
	make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) clean

sys folder của bạn không có chứa file syscall.h. :slight_smile:

Bạn gg tìm download syscall.h library down về rồi bỏ vô sys.

3 Likes
download syscall.h

Đây là POSIX glibc header mà.

Chạy make VERBOSE=1 rồi đọc dòng đầu xem gcc nó bỏ vào những include path nào

3 Likes
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?