我对这个计时器调用有一个奇怪的问题。它适用于我的测试系统(x64),但是当我将它加载到目标系统中,运行 i386 linux 并在那里编译时,它编译得很好,但会引发分段错误。这是可疑的代码:
507: int SwitchData = 0xFF,s, retval = EX_SOFTWARE;
508: struct sigevent sev;
509: struct itimerspec ts;
510: timer_t *tid;
剪断
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);
因此,回溯指向 timer_create 作为原因。测试系统是 Kernel 3.0.0-24-generic,target 是 3.0.0-17-generic。两个系统都是 gcc v4.6.1。他们都在运行 ubuntu 11.10 的安装。
这是 catchsegv 运行时的输出:
*** 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]
不确定进行的最佳方式。有任何想法吗?