iov_base in iovec structure
Hello!
There is a structure: iovec, contains user data in the kernel source. I am trying to print data witch iov_base pointer points to(iov has iovec structure): printk(KERN_INFO "Data is: %d", **((int**)iov.iov_base)); The problem is that I can see data smaller than 5 character(not in a normal way in dmesg messages) but, for data greater than 5 characters segmentation fault happens and I can not access to all of it. I can not understand the problem! Do you have any idea? Im going to print all user data. with many thanks |
Try copying it into some temporary string upto iov_len characters & then print the string itself.
Regards, Zishan Shaikh |
Bear in mind the potential issue of null-terminated strings: never, in my opinion, appropriate for kernel programming. You should copy the data into a separate buffer, specifying a maximum length to be copied and ensuring that the buffer is properly terminated. Print e.g. from that.
|
Thanks for reply.
I did that as you said: ************************************** int data[iov.iov_len]; int i; //zero the content for (i=0;i<iov.iov_len;i++) data[i]=0; //fill data data[i]=(*((int**)iov.iov_base))[i]; //print data for (i=0;i<iov.iov_len;i++) printk("%d",data[i]); ************************************** But unfortunately nothing changes! I get this message with typing only one character "A" in a file names 'sample': ##################################### File Name to Write: sampleKilled root@sk:/mnt# M-D DOS Format M-A Append M-B Backup File Message from syslogd@sk at Nov 21 04:02:30 ...nd kernel:[ 7781.177092] Oops: 0000 [#3] SMP Message from syslogd@sk at Nov 21 04:02:30 ... kernel:[ 7781.177095] last sysfs file: /sys/devices/virtual/mtd/mtd0/mtdblock0/queue/hw_sector_size Message from syslogd@sk at Nov 21 04:02:30 ... kernel:[ 7781.177202] Stack: Message from syslogd@sk at Nov 21 04:02:30 ... kernel:[ 7781.177217] Call Trace: Message from syslogd@sk at Nov 21 04:02:30 ... kernel:[ 7781.177252] Code: ff c3 e8 59 d9 fa e0 48 63 c3 48 3b 45 b8 72 e3 48 c7 c7 26 a6 35 a0 31 c0 e8 42 d9 fa e0 31 c9 eb 10 48 8b 45 b0 ff c1 48 8b 00 <8b> 04 90 41 89 04 94 48 63 d1 48 3b 55 b8 72 e7 48 c7 c7 e8 aa Message from syslogd@sk at Nov 21 04:02:30 ... kernel:[ 7781.177293] CR2: 0000000000000a41 ###################################### and also get this one while typing more characters(more than 5): ###################################### File Name to Write: sampleSegmentation fault root@sk:/mnt# M-D DOS Format M-A Append M-B Backup File Message from syslogd@sk at Nov 21 04:08:54 ...nd kernel:[ 8163.939796] general protection fault: 0000 [#5] SMP Message from syslogd@sk at Nov 21 04:08:54 ... kernel:[ 8163.939800] last sysfs file: /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq Message from syslogd@sk at Nov 21 04:08:54 ... kernel:[ 8163.939909] Stack: Message from syslogd@sk at Nov 21 04:08:54 ... kernel:[ 8163.939923] Call Trace: Message from syslogd@sk at Nov 21 04:08:54 ... kernel:[ 8163.939959] Code: ff c3 e8 59 d9 fa e0 48 63 c3 48 3b 45 b8 72 e3 48 c7 c7 26 a6 35 a0 31 c0 e8 42 d9 fa e0 31 c9 eb 10 48 8b 45 b0 ff c1 48 8b 00 <8b> 04 90 41 89 04 94 48 63 d1 48 3b 55 b8 72 e7 48 c7 c7 e8 aa ###################################### Do you know what is the problem and what I have to do? Thanks. |
Hello
I am trying to install ns-2.28 on redhat 9 but I get this error:tk8.4.5 make faild! existing... How can I fix it? Thanks a lot |
Hi s.kr !
This is C language code, yes? Quote:
Quote:
Maybe this C code will show you what I mean: Code:
# include <stdio.h> Here's the output when I run the compiled program: Code:
sizeof(iov_base)=20 Hope this helps. |
All times are GMT -5. The time now is 12:51 AM. |