简体   繁体   中英

timer_create causing segmentation fault on i386 system, but not x86_64 system(linux)

I'm having an odd issue with this timer call. It works on my test system (x64), but when I load it into the target system, running i386 linux and compile there, it compiles fine but throws a segmentation fault. Here's the suspected code:

507: int SwitchData = 0xFF,s, retval = EX_SOFTWARE;
508: struct sigevent sev;
509: struct itimerspec ts;
510: timer_t *tid;

snip

517: if(EX_OK != retval)
518: {
519:     fprintf(stderr,"init failed\n");
520:     return EX_SOFTWARE;
521: }
522: //notify via thread
    523:    sev.sigev_notify = SIGEV_THREAD;
    524:    sev.sigev_notify_function = SwitchThreadHandler;
    525:    sev.sigev_notify_attributes = NULL;
    526:    sev.sigev_value.sival_ptr = tid;
    527:    ts.it_interval.tv_sec = 0;
    528:    ts.it_interval.tv_nsec = 200000000;
    529:    if(-1 == timer_create(CLOCK_REALTIME,&sev,tid))
    530:    {
    531:        retval = EX_SOFTWARE;
    532:        fprintf(stderr,"Failed to create timer.");
    533:        return retval;
    534:    }
    535:    timer_settime(tid,0,&ts,NULL);

So, the backtrace points to timer_create as the cause. Test system is Kernel 3.0.0-24-generic, target is 3.0.0-17-generic. Both systems are gcc v4.6.1. They're both running installs of ubuntu 11.10.

Here's the output of catchsegv when run against it:

*** Segmentation fault
Register dump:

EAX: 005c6ff4   EBX: 003daff4   ECX: 00000000   EDX: 00000001
ESI: 003db228   EDI: 00000000   EBP: 09ba00d0   ESP: bf96b2c8

EIP: 003d7058   EFLAGS: 00010292

CS: 0073   DS: 007b   ES: 007b   FS: 0000   GS: 0033   SS: 007b

Trap: 0000000e   Error: 00000007   OldMask: 00000000
ESP/signal: bf96b2c8   CR2: 005c6ff4

FPUCW: ffff037f   FPUSW: ffff0000   TAG: ffffffff
IPOFF: 00000000   CSSEL: 0000   DATAOFF: 00000000   DATASEL: 0000

ST(0) 0000 0000000000000000   ST(1) 0000 0000000000000000
ST(2) 0000 0000000000000000   ST(3) 0000 0000000000000000
ST(4) 0000 0000000000000000   ST(5) 0000 0000000000000000
ST(6) 0000 0000000000000000   ST(7) 0000 0000000000000000

Backtrace:
/lib/i386-linux-gnu/librt.so.1(timer_create+0x208)[0x3d7058]
/home/vislink/aircam/AircamFrontPanel/FrontPanel.c:529(main)[0x8048fd6]
/lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf3)[0x466113]
??:0(_start)[0x80488c1]

Memory map:

00240000-00257000 r-xp 00000000 08:01 131477 /lib/i386-linux-gnu/libpthread-2.13.so
00257000-00258000 r--p 00016000 08:01 131477 /lib/i386-linux-gnu/libpthread-2.13.so
00258000-00259000 rw-p 00017000 08:01 131477 /lib/i386-linux-gnu/libpthread-2.13.so
00259000-0025b000 rw-p 00000000 00:00 0
003d3000-003da000 r-xp 00000000 08:01 131479 /lib/i386-linux-gnu/librt-2.13.so
003da000-003db000 r--p 00006000 08:01 131479 /lib/i386-linux-gnu/librt-2.13.so
003db000-003dc000 rw-p 00007000 08:01 131479 /lib/i386-linux-gnu/librt-2.13.so
00447000-0044b000 r-xp 00000000 08:01 310504 /usr/local/lib/libmpsse.so
0044b000-0044c000 r--p 00003000 08:01 310504 /usr/local/lib/libmpsse.so
0044c000-0044d000 rw-p 00004000 08:01 310504 /usr/local/lib/libmpsse.so
0044d000-005c5000 r-xp 00000000 08:01 131463 /lib/i386-linux-gnu/libc-2.13.so
005c5000-005c7000 r--p 00178000 08:01 131463 /lib/i386-linux-gnu/libc-2.13.so
005c7000-005c8000 rw-p 0017a000 08:01 131463 /lib/i386-linux-gnu/libc-2.13.so
005c8000-005cb000 rw-p 00000000 00:00 0
00600000-00603000 r-xp 00000000 08:01 131480 /lib/i386-linux-gnu/libSegFault.so
00603000-00604000 r--p 00002000 08:01 131480 /lib/i386-linux-gnu/libSegFault.so
00604000-00605000 rw-p 00003000 08:01 131480 /lib/i386-linux-gnu/libSegFault.so
0081f000-0083d000 r-xp 00000000 08:01 131460 /lib/i386-linux-gnu/ld-2.13.so
0083d000-0083e000 r--p 0001d000 08:01 131460 /lib/i386-linux-gnu/ld-2.13.so
0083e000-0083f000 rw-p 0001e000 08:01 131460 /lib/i386-linux-gnu/ld-2.13.so
0093c000-00942000 r-xp 00000000 08:01 308124 /usr/local/lib/libftdi.so.1.20.0
00942000-00943000 r--p 00005000 08:01 308124 /usr/local/lib/libftdi.so.1.20.0
00943000-00944000 rw-p 00006000 08:01 308124 /usr/local/lib/libftdi.so.1.20.0
00a98000-00a9f000 r-xp 00000000 08:01 131345 /lib/libusb-0.1.so.4.4.4
00a9f000-00aa0000 r--p 00006000 08:01 131345 /lib/libusb-0.1.so.4.4.4
00aa0000-00aa1000 rw-p 00007000 08:01 131345 /lib/libusb-0.1.so.4.4.4
00aa1000-00aa2000 rw-p 00000000 00:00 0
00d22000-00d3e000 r-xp 00000000 08:01 130812 /lib/i386-linux-gnu/libgcc_s.so.1
00d3e000-00d3f000 r--p 0001b000 08:01 130812 /lib/i386-linux-gnu/libgcc_s.so.1
00d3f000-00d40000 rw-p 0001c000 08:01 130812 /lib/i386-linux-gnu/libgcc_s.so.1
00d56000-00d57000 r-xp 00000000 00:00 0 [vdso]
08048000-0804b000 r-xp 00000000 08:01 342 /home/vislink/aircam/AircamFrontPanel/debugimage
0804b000-0804c000 r--p 00003000 08:01 342 /home/vislink/aircam/AircamFrontPanel/debugimage
0804c000-0804d000 rw-p 00004000 08:01 342 /home/vislink/aircam/AircamFrontPanel/debugimage
09b9c000-09bc1000 rw-p 00000000 00:00 0 [heap]
b7704000-b7707000 rw-p 00000000 00:00 0
b7711000-b7712000 ---p 00000000 00:00 0
b7712000-b7717000 rw-p 00000000 00:00 0
bf94b000-bf96c000 rw-p 00000000 00:00 0 [stack]

Not sure of the best way to proceed. Any ideas?

tid is an uninitialized pointer. You have to declare an object of type timer_t and pass a pointer to that object to timer_create . You can't just create a pointer object of type timer_t * with indeterminate value and pass that indeterminate value to timer_create .

I cannot tell from your posted code but unless your struct sigevent is declared as a global, you need to memset() it to zero before using it.

It is far too easy to miss setting an important struct field.

And also, R. is right about the timer_t pointer needing to point to a real object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM