On Thu, 5 May 2005, linux wrote:
Hi all, i have a question about copy_to_user function.
I have a module which declares a struct test { int size; char *name; int
value_add };
I like to transfer that struct to userspace through an ioctl command like
that:
struct test test_struct;
memset(&test_struct,0,sizeof(test_struct);
test_struct.size= 100;
test_struct.name = "test name";
test_struct.value_add = 2;
copy_to_user((void __user *)arg,&test_struct,sizeof(struct test));
When i use the ioctl command in user-space and try to get the name item a
segfault occurs.Can u tell me why??
Can we transfer from kernel-space to user-space pointers like the one i use
or this is a fault approach???
Best regards,
Chris.
Accessing a kernel pointer from user-space isn't going to work.
But you can transfer data to/from user-space/kernel-space so
just don't use a pointer, do...
struct test struct {
char name[BIG_ENOUGN];
int size;
....
};
Write your strings to the name[] buffer-member and everybody is happy.
Cheers,
Dick Johnson
Penguin : Linux version 2.6.11 on an i686 machine (5537.79 BogoMips).
Notice : All mail here is now cached for review by Dictator Bush.
98.36% of all statistics are fiction.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]