LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C copy_from_user question (https://www.linuxquestions.org/questions/programming-9/c-copy_from_user-question-909583/)

conlonloi 10-22-2011 03:01 PM

C copy_from_user question
 
Hi,
I'm trying to use the copy_from_user in kernel mode to copy a message from user's buffer

this is the function for copy from user:
Code:

asmlinkage long copyFrom(unsigned char *data, long length){
unsigned char *content;
content = kmalloc(length, GFP_KERNEL);
copy_from_user(content, data, length);

...

return 0;
}

Now I'm trying to display the data passed by user but if keeps giving me weird number
I tried using printk with %c %x %s but none works

Code:

printk("data: %c" *content");
printk("data: %x" *content");

The data I passed to this function is something like
data[]{0x34, 0x65, 0x14} and sizeof(data)

So how should I retrieve the correct data in the kernel mode? what should the printk be like?
thanks

jhwilliams 10-22-2011 11:49 PM

Hello,

So you've passed 3 bytes in an array? I think you'd want to print them as
Code:

printk("data: %x, %x, %x\n", content[0], content[1], content[2]);
Right?

Also, where does your data variable come from? Are you sure are referencing the correct location in memory -- where those values were placed in user mode?

Also, perhaps better to be using void *'s as are in the copy_from_user() signature: http://www.gnugeneration.com/mirrors...api/r4343.html


All times are GMT -5. The time now is 03:10 AM.