I’m just making a kernel module. And I meet this warnings:
WARNING: "sys_getpid" [/PATH/NAME.ko] undefined! WARNING: "sys_stat" [/PATH/NAME.ko] undefined! WARNING: "sys_rmdir" [/PATH/NAME.ko] undefined! WARNING: "sys_mremap" [/PATH/NAME.ko] undefined! WARNING: "sys_fchmod" [/PATH/NAME.ko] undefined! WARNING: "sys_gettimeofday" [/PATH/NAME.ko] undefined! WARNING: "sys_utimes" [/PATH/NAME.ko] undefined! WARNING: "sys_fcntl" [/PATH/NAME.ko] undefined! WARNING: "sys_getcwd" [/PATH/NAME.ko] undefined! WARNING: "sys_unlink" [/PATH/NAME.ko] undefined! WARNING: "localtime" [/PATH/NAME.ko] undefined! WARNING: "sys_write" [/PATH/NAME.ko] undefined! WARNING: "sys_fsync" [/PATH/NAME.ko] undefined! WARNING: "sys_fchown" [/PATH/NAME.ko] undefined! WARNING: "sys_ftruncate" [/PATH/NAME.ko] undefined! WARNING: "sys_fstat" [/PATH/NAME.ko] undefined! WARNING: "sys_munmap" [/PATH/NAME.ko] undefined! WARNING: "sys_geteuid" [/PATH/NAME.ko] undefined! WARNING: "sys_read" [/PATH/NAME.ko] undefined! WARNING: "sys_access" [/PATH/NAME.ko] undefined! WARNING: "sys_old_mmap" [/PATH/NAME.ko] undefined! WARNING: "errno" [/PATH/NAME.ko] undefined! WARNING: "getenv" [/PATH/NAME.ko] undefined! WARNING: "sys_mkdir" [/PATH/NAME.ko] undefined! WARNING: "sys_time" [/PATH/NAME.ko] undefined! WARNING: "sys_lseek" [/PATH/NAME.ko] undefined! WARNING: "sysconf" [/PATH/NAME.ko] undefined!
How can I fix this problem?
This is my codes:
#include <linux/string.h> #include <linux/kernel.h> #include <linux/syscalls.h> #include <linux/fs.h> #include <linux/delay.h> #include <linux/slab.h> #include <linux/types.h> #include <linux/stat.h> #include <linux/fcntl.h> #include <asm-generic/unistd.h> #include <uapi/asm-generic/fcntl.h> #include <linux/time.h> #include <linux/errno.h> #include <linux/mman.h> // And use functions(sys_open, sys_write, ...)
And my workspace is Ubuntu 3.13.0-66-generic.
I need to use file descriptor.
So, I can’t use filp_
functions(like filp_open
).
Edit1:
My Makefile: obj-m += NAME.o
NAME-objs := FILE1.o FILE2.o FILE3.o FILE4.o ccflags-y := -mhard-float -msse -mpreferred-stack-boundary=4 -w -I/usr/include -I/usr/include/x86_64-linux-gnu/ ldflags-y += -lpthread -ldl KDIR := /lib/modules/$(shell uname -r)/build PWD := $(shell pwd) default: $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules clean: rm -rf *.ko *.mod *.cmd *.o *.mod.c *.order *.symvers .tmp_versions
Advertisement
Answer
Calling system calls(sys_*
functions) from the kernel code is not a good idea. Actually, many of system calls can be expressed in functions, available for kernel modules.
I need to use file descriptor. So, I can’t use filp_ functions(like filp_open).
File descriptor can be easy transformed into file pointer using fdget
. See, e.g., implementation of fallocate system call (SYSCALL_DEFINE4(fallocate...)
in fs/open.h
).
As for errno
, this variable is user space only. System calls return error using -E
convention, it is libc who stores this value into errno
.