Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
signal delivery speed
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

signal delivery speed



As part of the mono CLR virtual machine, we rely on the operation system
to deliver a signal when a NULL pointer is dereferenced, this avoids
adding checks in the generated native code for NULL pointers.
The program below will show a problem I found: it takes a long time to
get to the signal handler for the faulting instruction (note that
issuing the same signal with kill is fast).
Now, this should not happen normally, but still, waiting one second for
a signal handler is a lot, even if it's an error condition.
Anybody can reproduce it or suggest workarounds?
System version is 10.2.2.
Thanks!

#include <signal.h>
#include <stdio.h>

void segv (int signalid) {
	printf ("SEGV %d\n", signalid);
	fflush (stdout);
	if (signalid == SIGSEGV)
		return;
	_exit (0);
}

int main () {
	volatile int *p = NULL;
	struct sigaction sa;
	sa.sa_handler = segv;
	sigemptyset (&sa.sa_mask);
	sa.sa_flags = 0;
	if (sigaction (SIGBUS, &sa, NULL) == -1)
		perror ("sigaction");
	if (sigaction (SIGSEGV, &sa, NULL) == -1)
		perror ("sigaction");
	// this is fast
	kill (getpid(), SIGSEGV);
	// this is sloow
	*p = 10; //segv
	return 0;
}
/*
 kdump -R output below:

[...]
 19567 a.out    0.001180 CALL  sigaction(0xa,0xbffffb10,0)
 19567 a.out    0.000104 RET   sigaction 0
 19567 a.out    0.000043 CALL  sigaction(0xb,0xbffffb10,0)
 19567 a.out    0.000031 RET   sigaction 0
 19567 a.out    0.000030 CALL  getpid
 19567 a.out    0.000029 RET   getpid 19567/0x4c6f
 19567 a.out    0.000029 CALL  kill(0x4c6f,0xb)
 19567 a.out    0.000042 RET   kill 0
 19567 a.out    0.000037 PSIG  SIGSEGV caught handler=0x1b7c mask=0x0 code=0x0
                ^^^^^^^^
 19567 a.out    0.000095 CALL  fstat(0x1,0xbfffefe0)
 19567 a.out    0.000048 RET   fstat 0
 19567 a.out    0.000069 CALL  ioctl(0x1,TIOCGETA,0xbffff010)
 19567 a.out    0.000051 RET   ioctl 0
 19567 a.out    0.000097 CALL  write(0x1,0x84000,0x8)
 19567 a.out    0.000075 GIO   fd 1 wrote 8 bytes
       "SEGV 11
       "
 19567 a.out    0.000059 RET   write 8
 19567 a.out    0.000033 CALL  sigreturn(0xbffffa30)
 19567 a.out    0.000037 RET   sigreturn JUSTRETURN
 19567 a.out    1.005463 PSIG  SIGBUS caught handler=0x1b7c mask=0x0 code=0x0
                ^^^^^^^^
 19567 a.out    0.000316 CALL  write(0x1,0x84000,0x8)
 19567 a.out    0.000138 GIO   fd 1 wrote 8 bytes
       "SEGV 10
       "
 19567 a.out    0.000069 RET   write 8
 19567 a.out    0.000034 CALL  exit(0)
*/


lupus

--
-----------------------------------------------------------------
email@hidden                                     debian/rules
email@hidden                             Monkeys do it better
_______________________________________________
unix-porting mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/unix-porting
Do not post admin requests to the list. They will be ignored.





Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.