[英]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.
它可以在我的测试系统(x64)上运行,但是当我将其加载到目标系统,运行i386 linux并在此处进行编译时,它可以正常编译,但会引发分段错误。 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. 因此,回溯将指向timer_create作为原因。 Test system is Kernel 3.0.0-24-generic, target is 3.0.0-17-generic.
测试系统是3.3.0-24通用内核,目标是3.0.0-17通用内核。 Both systems are gcc v4.6.1.
这两个系统都是gcc v4.6.1。 They're both running installs of ubuntu 11.10.
他们都在运行ubuntu 11.10的安装。
Here's the output of catchsegv when run against it: 这是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]
Not sure of the best way to proceed. 不确定最好的进行方式。 Any ideas?
有任何想法吗?
tid
is an uninitialized pointer. tid
是未初始化的指针。 You have to declare an object of type timer_t
and pass a pointer to that object to timer_create
. 您必须声明一个类型为
timer_t
的对象,并将指向该对象的指针传递给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
. 您不能只创建带有不确定值的
timer_t *
类型的指针对象,并将该不确定值传递给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. 我无法从您发布的代码
struct sigevent
但是除非将struct sigevent
声明为全局struct sigevent
否则在使用前需要将其memset()
设置为零。
It is far too easy to miss setting an important struct field. 错过设置重要的struct字段太容易了。
And also, R. is right about the timer_t
pointer needing to point to a real object. 而且,R。关于需要指向实际对象的
timer_t
指针是正确的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.