LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 11-07-2012, 06:42 AM   #1
s.kr
LQ Newbie
 
Registered: Oct 2012
Posts: 8

Rep: Reputation: Disabled
Question 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
 
Old 11-20-2012, 03:27 AM   #2
zishan.shaikh
LQ Newbie
 
Registered: Dec 2011
Location: Pune, India
Distribution: Fedora 17
Posts: 6

Rep: Reputation: Disabled
Try copying it into some temporary string upto iov_len characters & then print the string itself.

Regards,
Zishan Shaikh
 
Old 11-20-2012, 07:25 AM   #3
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,377

Rep: Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108
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.
 
Old 11-21-2012, 03:15 AM   #4
s.kr
LQ Newbie
 
Registered: Oct 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
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.
 
Old 11-21-2012, 03:22 AM   #5
small_rz
LQ Newbie
 
Registered: Oct 2012
Posts: 7

Rep: Reputation: Disabled
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
 
Old 12-11-2012, 12:52 AM   #6
kakaka
Member
 
Registered: Sep 2003
Posts: 382

Rep: Reputation: 86
Hi s.kr !

This is C language code, yes?


Quote:
Originally Posted by s.kr View Post

[...]

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]);

[...]
You don't show this code:
Quote:
//fill data
data[i]=(*((int**)iov.iov_base))[i];
as being in a loop. Is it inside a loop? Or did you only intend to copy only as many bytes as fit inside one int on the processor that's being used?

Maybe this C code will show you what I mean:

Code:
# include <stdio.h>

# define IOV_LEN  20

int main(  int ac ,  char *av[]  )
{

    char iov_base[IOV_LEN] = "ME WANT CORE DUMP!" ;
    int data[IOV_LEN] ;
    int i ;

    printf(  "sizeof(iov_base)=%d\n", sizeof(iov_base)  ) ;
    printf(  "sizeof(\"ME WANT CORE DUMP!\")=%d\n", sizeof("ME WANT CORE DUMP!")  ) ;
    printf(  "sizeof(data)=%d\n", sizeof(data)  ) ;
    printf(  "sizeof(i)=%d\n", sizeof(i)  ) ;


    //zero the content
    for (  i=0 ;  i<IOV_LEN ;  i++  )
        data[i] = 0 ;

    printf(  "i = %d\n" ,  i  ) ;

    //fill data
    data[i] = ( *( (int**) iov_base ) )[i] ;

    printf(  "Executed assignment for filling data\n"  ) ;

    //print data
    for (  i=0 ;  i < IOV_LEN ;  i++  )
        printf(  "%d\n", data[i]  ) ;

    printf(  "Executed loop to print data\n"  ) ;

}
I'm expecting it will crash before it finishes executing the assignment statement. So we'll never see the message saying that it executed the assignment statement.

Here's the output when I run the compiled program:

Code:
sizeof(iov_base)=20
sizeof("ME WANT CORE DUMP!")=19
sizeof(data)=80
sizeof(i)=4
i = 20
Segmentation fault
When means it crashed while trying to execute the assignment statement.

Hope this helps.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
structure inside a structure in C batman4 Programming 3 09-13-2012 05:52 AM
Convert directory structure from long file names in Linux to DOS 8.3 structure? manorina Linux - Software 5 09-12-2009 09:18 AM
Structure in C divya_flora Programming 1 09-29-2008 02:46 AM
Home Jail Folder Structure like Gobolinux Directory Structure luispt Linux - General 3 07-26-2008 06:46 PM
structure within a structure in C knobby67 Programming 3 03-06-2007 09:00 AM


All times are GMT -5. The time now is 03:01 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration