0

我正在尝试创建一个需要生成随机数才能正常工作的内核模块。为了实现这一点,我在我的代码中包含了<stdlib.h><time.h>,但我无法使用 make 命令编译模块。

我在网上搜索帮助并尝试将其包含EXTRA_CFLAGS := -I/usr/include到 Makefile 中,但在此之后我不断收到更多错误。

这是我收到的错误消息:

kernel@KernelDev:~/Modulos/DropProb$ make
make -C /lib/modules/3.2.0-37-generic/build SUBDIRS=/home/kernel/Modulos/DropProb modules
make[1]: Entering directory `/usr/src/linux-headers-3.2.0-37-generic'
  CC [M]  /home/kernel/Modulos/DropProb/drop_prob.o
In file included from /home/kernel/Modulos/DropProb/drop_prob.c:15:0:
/usr/include/stdlib.h: In function ‘atof’:
/usr/include/stdlib.h:280:1: error: SSE register return with SSE disabled
In file included from include/linux/compiler.h:48:0,
                 from include/linux/linkage.h:4,
                 from include/linux/kernel.h:13,
                 from /home/kernel/Modulos/DropProb/drop_prob.c:19:
include/linux/compiler-gcc.h: At top level:
include/linux/compiler-gcc.h:87:0: warning: "__attribute_const__" redefined [enabled by default]
/usr/include/sys/cdefs.h:241:0: note: this is the location of the previous definition
In file included from include/linux/compiler.h:48:0,
                 from include/linux/linkage.h:4,
                 from include/linux/kernel.h:13,
                 from /home/kernel/Modulos/DropProb/drop_prob.c:19:
include/linux/compiler-gcc.h:106:0: warning: "__always_inline" redefined [enabled by default]
/usr/include/sys/cdefs.h:312:0: note: this is the location of the previous definition
In file included from include/linux/kernel.h:15:0,
                 from /home/kernel/Modulos/DropProb/drop_prob.c:19:
include/linux/types.h:23:26: error: conflicting types for ‘fd_set’
/usr/include/sys/select.h:76:5: note: previous declaration of ‘fd_set’ was here
include/linux/types.h:24:25: error: conflicting types for ‘dev_t’
/usr/include/sys/types.h:61:17: note: previous declaration of ‘dev_t’ was here
include/linux/types.h:33:26: error: conflicting types for ‘timer_t’
/usr/include/time.h:104:19: note: previous declaration of ‘timer_t’ was here
include/linux/types.h:53:26: error: conflicting types for ‘loff_t’
/usr/include/sys/types.h:45:18: note: previous declaration of ‘loff_t’ was here
include/linux/types.h:120:17: error: conflicting types for ‘u_int64_t’
/usr/include/sys/types.h:204:1: note: previous declaration of ‘u_int64_t’ was here
include/linux/types.h:121:17: error: conflicting types for ‘int64_t’
/usr/include/sys/types.h:198:1: note: previous declaration of ‘int64_t’ was here
include/linux/types.h:142:23: error: conflicting types for ‘blkcnt_t’
/usr/include/sys/types.h:236:20: note: previous declaration of ‘blkcnt_t’ was here
In file included from include/linux/stat.h:60:0,
                 from include/linux/module.h:10,
                 from /home/kernel/Modulos/DropProb/drop_prob.c:20:
include/linux/time.h:14:8: error: redefinition of ‘struct timespec’
/usr/include/time.h:120:8: note: originally defined here
include/linux/time.h:20:8: error: redefinition of ‘struct timeval’
/usr/include/bits/time.h:31:8: note: originally defined here
include/linux/time.h:74:22: error: conflicting types for ‘mktime’
/usr/include/time.h:193:15: note: previous declaration of ‘mktime’ was here
include/linux/time.h:206:8: error: redefinition of ‘struct tm’
/usr/include/time.h:133:8: note: originally defined here
include/linux/time.h:289:0: warning: "FD_SET" redefined [enabled by default]
/usr/include/sys/select.h:91:0: note: this is the location of the previous definition
include/linux/time.h:290:0: warning: "FD_CLR" redefined [enabled by default]
/usr/include/sys/select.h:92:0: note: this is the location of the previous definition
include/linux/time.h:291:0: warning: "FD_ISSET" redefined [enabled by default]
/usr/include/sys/select.h:93:0: note: this is the location of the previous definition
include/linux/time.h:292:0: warning: "FD_ZERO" redefined [enabled by default]
/usr/include/sys/select.h:94:0: note: this is the location of the previous definition
include/linux/time.h:302:8: error: redefinition of ‘struct itimerspec’
/usr/include/time.h:161:8: note: originally defined here
include/linux/time.h:337:0: warning: "TIMER_ABSTIME" redefined [enabled by default]
/usr/include/bits/time.h:82:0: note: this is the location of the previous definition
In file included from include/linux/mmzone.h:9:0,
                 from include/linux/gfp.h:4,
                 from include/linux/kmod.h:22,
                 from include/linux/module.h:13,
                 from /home/kernel/Modulos/DropProb/drop_prob.c:20:
include/linux/wait.h:4:0: warning: "WNOHANG" redefined [enabled by default]
/usr/include/bits/waitflags.h:26:0: note: this is the location of the previous definition
include/linux/wait.h:5:0: warning: "WUNTRACED" redefined [enabled by default]
/usr/include/bits/waitflags.h:27:0: note: this is the location of the previous definition
include/linux/wait.h:6:0: warning: "WSTOPPED" redefined [enabled by default]
/usr/include/bits/waitflags.h:30:0: note: this is the location of the previous definition
include/linux/wait.h:7:0: warning: "WEXITED" redefined [enabled by default]
/usr/include/bits/waitflags.h:31:0: note: this is the location of the previous definition
include/linux/wait.h:8:0: warning: "WCONTINUED" redefined [enabled by default]
/usr/include/bits/waitflags.h:32:0: note: this is the location of the previous definition
In file included from /usr/src/linux-headers-3.2.0-37-generic/arch/x86/include/asm/param.h:1:0,
                 from include/linux/param.h:4,
                 from include/linux/timex.h:172,
                 from include/linux/jiffies.h:8,
                 from include/linux/ktime.h:25,
                 from include/linux/timer.h:5,
                 from include/linux/workqueue.h:8,
                 from include/linux/pm.h:25,
                 from /usr/src/linux-headers-3.2.0-37-generic/arch/x86/include/asm/apic.h:5,
                 from /usr/src/linux-headers-3.2.0-37-generic/arch/x86/include/asm/smp.h:13,
                 from /usr/src/linux-headers-3.2.0-37-generic/arch/x86/include/asm/mmzone_64.h:10,
                 from /usr/src/linux-headers-3.2.0-37-generic/arch/x86/include/asm/mmzone.h:4,
                 from include/linux/mmzone.h:815,
                 from include/linux/gfp.h:4,
                 from include/linux/kmod.h:22,
                 from include/linux/module.h:13,
                 from /home/kernel/Modulos/DropProb/drop_prob.c:20:
include/asm-generic/param.h:7:0: warning: "CLOCKS_PER_SEC" redefined [enabled by default]
/usr/include/bits/time.h:49:0: note: this is the location of the previous definition
In file included from include/linux/signal.h:4:0,
                 from include/linux/sched.h:73,
                 from /usr/src/linux-headers-3.2.0-37-generic/arch/x86/include/asm/compat.h:8,
                 from include/linux/compat.h:18,
                 from include/linux/ethtool.h:17,
                 from include/linux/netdevice.h:47,
                 from include/net/sock.h:50,
                 from include/linux/tcp.h:211,
                 from /home/kernel/Modulos/DropProb/drop_prob.c:25:
/usr/src/linux-headers-3.2.0-37-generic/arch/x86/include/asm/signal.h:32:3: error: conflicting types for ‘sigset_t’
/usr/include/sys/select.h:38:20: note: previous declaration of ‘sigset_t’ was here
/home/kernel/Modulos/DropProb/drop_prob.c: In function ‘drop_tcp_hookfn’:
/home/kernel/Modulos/DropProb/drop_prob.c:76:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
/home/kernel/Modulos/DropProb/drop_prob.c: At top level:
/home/kernel/Modulos/DropProb/drop_prob.c:31:36: warning: ‘nfho_out’ defined but not used [-Wunused-variable]
make[2]: *** [/home/kernel/Modulos/DropProb/drop_prob.o] Error 1
make[1]: *** [_module_/home/kernel/Modulos/DropProb] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.2.0-37-generic'
make: *** [default] Error 2
4

1 回答 1

0

您不允许将stdlib.hlibc中的内容包含在内核中(即使在模块中)。

查看此页面以获取允许的基本 C 库函数列表以及如何使用它们:http ://www.kernel.org/doc/htmldocs/kernel-api/libc.html

如果您想获取内核空间中的当前时间,可以查看time_to_tm函数。它会返回structure tm. 时区也应该在一个名为 的变量中可用sys_tz,并可用于调整偏移量并获取本地时间。

于 2013-03-01T01:29:18.993 回答