我正在尝试编写Linux设备驱动程序。 我已经让它工作得很好,直到我尝试使用“memcpy”。 我甚至没有得到编译器错误,当我“制造”它只是警告我:
WARNING: "memcpy" [/root/homedir/sv/main.ko] undefined!
好的,当我尝试通过insmod加载时,我进入控制台:
insmod: error inserting './main.ko': -1 Unknown symbol in module
在dmesg上:
main: Unknown symbol memcpy (err 0)
我包括以下内容:
#include
#include
#include
#include /* printk() */
#include /* kmalloc() */
#include /* everything... */
#include /* error codes */
#include /* size_t */
#include /* O_ACCMODE */
#include
#include /* cli(), *_flags */
#include /* copy_*_user */
使用memcpy的功能:
static int dc_copy_to_user(char __user *buf, size_t count, loff_t *f_pos,
struct sv_data_dev *dev)
{
char data[MAX_KEYLEN];
size_t i = 0;
/* Copy the bulk as long as there are 10 more bytes to copy */
while (i < (count + MAX_KEYLEN)) {
memcpy(data, &dev->data[*f_pos + i], MAX_KEYLEN);
ec_block(dev->key, data, MAX_KEYLEN);
if (copy_to_user(&buf[i], data, MAX_KEYLEN)) {
return -EFAULT;
}
i += MAX_KEYLEN;
}
return 0;
}
有人能帮助我吗? 我认为这件事是在linux / string.h中,但我得到的错误是一样的。 我正在使用内核2.6.37-rc1(我在用户模式linux中进行,仅在2.6.37-rc1之后才有效)。 任何帮助是极大的赞赏。
# Context dependent makefile that can be called directly and will invoke itself
# through the kernel module building system.
KERNELDIR=/usr/src/linux
ifneq ($(KERNELRELEASE),)
EXTRA_CFLAGS+=-I $(PWD) -ARCH=um
obj-m := main.o
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD = $(shell pwd)
all:
$(MAKE) V=1 ARCH=um -C $(KERNELDIR) M=$(PWD) modules
clean:
rm -rf Module.symvers .*.cmd *.ko .*.o *.o *.mod.c .tmp_versions *.order
endif