I am trying to write a Linux device driver. Everything worked out very well until I tried to use "memcpy". I donβt even get a compiler error, when I βdoβ it just warns me:
WARNING: "memcpy" [/root/homedir/sv/main.ko] undefined!
OK, and when I try to load via insmod, I am on the console:
insmod: error inserting './main.ko': -1 Unknown symbol in module
and on dmesg:
main: Unknown symbol memcpy (err 0)
I include the following:
#include <linux/module.h> #include <linux/moduleparam.h> #include <linux/init.h> #include <linux/kernel.h> /* printk() */ #include <linux/slab.h> /* kmalloc() */ #include <linux/fs.h> /* everything... */ #include <linux/errno.h> /* error codes */ #include <linux/types.h> /* size_t */ #include <linux/fcntl.h> /* O_ACCMODE */ #include <linux/cdev.h> #include <asm/system.h> /* cli(), *_flags */ #include <asm/uaccess.h> /* copy_*_user */
Function using 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; 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; }
Can someone help me? I thought it was Linux / string.h, but I get the error exactly the same. I use the 2.6.37-rc1 kernel (I work in user-mode-linux, which only works with 2.6.37-rc1). Any help is appreciated.
# 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
c linux-kernel memcpy device-driver
Hinton
source share