Artifact
3af7fc1fb5a3307e84bea446f02f0c0e3090e256:
0000: 23 20 6e 6f 63 72 61 73 68 2e 6d 34 20 73 65 72 # nocrash.m4 ser
0010: 69 61 6c 20 32 0a 64 6e 6c 20 43 6f 70 79 72 69 ial 2.dnl Copyri
0020: 67 68 74 20 28 43 29 20 32 30 30 35 2c 20 32 30 ght (C) 2005, 20
0030: 30 39 2c 20 32 30 31 30 20 46 72 65 65 20 53 6f 09, 2010 Free So
0040: 66 74 77 61 72 65 20 46 6f 75 6e 64 61 74 69 6f ftware Foundatio
0050: 6e 2c 20 49 6e 63 2e 0a 64 6e 6c 20 54 68 69 73 n, Inc..dnl This
0060: 20 66 69 6c 65 20 69 73 20 66 72 65 65 20 73 6f file is free so
0070: 66 74 77 61 72 65 3b 20 74 68 65 20 46 72 65 65 ftware; the Free
0080: 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64 61 Software Founda
0090: 74 69 6f 6e 0a 64 6e 6c 20 67 69 76 65 73 20 75 tion.dnl gives u
00a0: 6e 6c 69 6d 69 74 65 64 20 70 65 72 6d 69 73 73 nlimited permiss
00b0: 69 6f 6e 20 74 6f 20 63 6f 70 79 20 61 6e 64 2f ion to copy and/
00c0: 6f 72 20 64 69 73 74 72 69 62 75 74 65 20 69 74 or distribute it
00d0: 2c 0a 64 6e 6c 20 77 69 74 68 20 6f 72 20 77 69 ,.dnl with or wi
00e0: 74 68 6f 75 74 20 6d 6f 64 69 66 69 63 61 74 69 thout modificati
00f0: 6f 6e 73 2c 20 61 73 20 6c 6f 6e 67 20 61 73 20 ons, as long as
0100: 74 68 69 73 20 6e 6f 74 69 63 65 20 69 73 20 70 this notice is p
0110: 72 65 73 65 72 76 65 64 2e 0a 0a 64 6e 6c 20 42 reserved...dnl B
0120: 61 73 65 64 20 6f 6e 20 6c 69 62 73 69 67 73 65 ased on libsigse
0130: 67 76 2c 20 66 72 6f 6d 20 42 72 75 6e 6f 20 48 gv, from Bruno H
0140: 61 69 62 6c 65 20 61 6e 64 20 50 61 6f 6c 6f 20 aible and Paolo
0150: 42 6f 6e 7a 69 6e 69 2e 0a 0a 41 43 5f 50 52 45 Bonzini...AC_PRE
0160: 52 45 51 28 5b 32 2e 31 33 5d 29 0a 0a 64 6e 6c REQ([2.13])..dnl
0170: 20 45 78 70 61 6e 64 73 20 74 6f 20 73 6f 6d 65 Expands to some
0180: 20 63 6f 64 65 20 66 6f 72 20 75 73 65 20 69 6e code for use in
0190: 20 2e 63 20 70 72 6f 67 72 61 6d 73 20 74 68 61 .c programs tha
01a0: 74 20 77 69 6c 6c 20 63 61 75 73 65 20 74 68 65 t will cause the
01b0: 20 63 6f 6e 66 69 67 75 72 65 0a 64 6e 6c 20 74 configure.dnl t
01c0: 65 73 74 20 74 6f 20 65 78 69 74 20 69 6e 73 74 est to exit inst
01d0: 65 61 64 20 6f 66 20 63 72 61 73 68 69 6e 67 2e ead of crashing.
01e0: 20 54 68 69 73 20 69 73 20 75 73 65 66 75 6c 20 This is useful
01f0: 74 6f 20 61 76 6f 69 64 20 74 72 69 67 67 65 72 to avoid trigger
0200: 69 6e 67 0a 64 6e 6c 20 61 63 74 69 6f 6e 20 66 ing.dnl action f
0210: 72 6f 6d 20 61 20 62 61 63 6b 67 72 6f 75 6e 64 rom a background
0220: 20 64 65 62 75 67 67 65 72 20 61 6e 64 20 74 6f debugger and to
0230: 20 61 76 6f 69 64 20 63 6f 72 65 20 64 75 6d 70 avoid core dump
0240: 73 2e 0a 64 6e 6c 20 55 73 61 67 65 3a 20 20 20 s..dnl Usage:
0250: 2e 2e 2e 0a 64 6e 6c 20 20 20 20 20 20 20 20 20 ....dnl
0260: 20 5d 47 4c 5f 4e 4f 43 52 41 53 48 5b 0a 64 6e ]GL_NOCRASH[.dn
0270: 6c 20 20 20 20 20 20 20 20 20 20 2e 2e 2e 0a 64 l ....d
0280: 6e 6c 20 20 20 20 20 20 20 20 20 20 69 6e 74 20 nl int
0290: 6d 61 69 6e 28 29 20 7b 20 6e 6f 63 72 61 73 68 main() { nocrash
02a0: 5f 69 6e 69 74 28 29 3b 20 2e 2e 2e 20 7d 0a 41 _init(); ... }.A
02b0: 43 5f 44 45 46 55 4e 28 5b 47 4c 5f 4e 4f 43 52 C_DEFUN([GL_NOCR
02c0: 41 53 48 5d 2c 5b 5b 0a 23 69 6e 63 6c 75 64 65 ASH],[[.#include
02d0: 20 3c 73 74 64 6c 69 62 2e 68 3e 0a 23 69 66 20 <stdlib.h>.#if
02e0: 64 65 66 69 6e 65 64 20 5f 5f 4d 41 43 48 5f 5f defined __MACH__
02f0: 20 26 26 20 64 65 66 69 6e 65 64 20 5f 5f 41 50 && defined __AP
0300: 50 4c 45 5f 5f 0a 2f 2a 20 41 76 6f 69 64 20 61 PLE__./* Avoid a
0310: 20 63 72 61 73 68 20 6f 6e 20 4d 61 63 4f 53 20 crash on MacOS
0320: 58 2e 20 20 2a 2f 0a 23 69 6e 63 6c 75 64 65 20 X. */.#include
0330: 3c 6d 61 63 68 2f 6d 61 63 68 2e 68 3e 0a 23 69 <mach/mach.h>.#i
0340: 6e 63 6c 75 64 65 20 3c 6d 61 63 68 2f 6d 61 63 nclude <mach/mac
0350: 68 5f 65 72 72 6f 72 2e 68 3e 0a 23 69 6e 63 6c h_error.h>.#incl
0360: 75 64 65 20 3c 6d 61 63 68 2f 74 68 72 65 61 64 ude <mach/thread
0370: 5f 73 74 61 74 75 73 2e 68 3e 0a 23 69 6e 63 6c _status.h>.#incl
0380: 75 64 65 20 3c 6d 61 63 68 2f 65 78 63 65 70 74 ude <mach/except
0390: 69 6f 6e 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 ion.h>.#include
03a0: 3c 6d 61 63 68 2f 74 61 73 6b 2e 68 3e 0a 23 69 <mach/task.h>.#i
03b0: 6e 63 6c 75 64 65 20 3c 70 74 68 72 65 61 64 2e nclude <pthread.
03c0: 68 3e 0a 2f 2a 20 54 68 65 20 65 78 63 65 70 74 h>./* The except
03d0: 69 6f 6e 20 70 6f 72 74 20 6f 6e 20 77 68 69 63 ion port on whic
03e0: 68 20 6f 75 72 20 74 68 72 65 61 64 20 6c 69 73 h our thread lis
03f0: 74 65 6e 73 2e 20 20 2a 2f 0a 73 74 61 74 69 63 tens. */.static
0400: 20 6d 61 63 68 5f 70 6f 72 74 5f 74 20 6f 75 72 mach_port_t our
0410: 5f 65 78 63 65 70 74 69 6f 6e 5f 70 6f 72 74 3b _exception_port;
0420: 0a 2f 2a 20 54 68 65 20 6d 61 69 6e 20 66 75 6e ./* The main fun
0430: 63 74 69 6f 6e 20 6f 66 20 74 68 65 20 74 68 72 ction of the thr
0440: 65 61 64 20 6c 69 73 74 65 6e 69 6e 67 20 66 6f ead listening fo
0450: 72 20 65 78 63 65 70 74 69 6f 6e 73 20 6f 66 20 r exceptions of
0460: 74 79 70 65 0a 20 20 20 45 58 43 5f 42 41 44 5f type. EXC_BAD_
0470: 41 43 43 45 53 53 2e 20 20 2a 2f 0a 73 74 61 74 ACCESS. */.stat
0480: 69 63 20 76 6f 69 64 20 2a 0a 6d 61 63 68 5f 65 ic void *.mach_e
0490: 78 63 65 70 74 69 6f 6e 5f 74 68 72 65 61 64 20 xception_thread
04a0: 28 76 6f 69 64 20 2a 61 72 67 29 0a 7b 0a 20 20 (void *arg).{.
04b0: 2f 2a 20 42 75 66 66 65 72 20 66 6f 72 20 61 20 /* Buffer for a
04c0: 6d 65 73 73 61 67 65 20 74 6f 20 62 65 20 72 65 message to be re
04d0: 63 65 69 76 65 64 2e 20 20 2a 2f 0a 20 20 73 74 ceived. */. st
04e0: 72 75 63 74 20 7b 0a 20 20 20 20 6d 61 63 68 5f ruct {. mach_
04f0: 6d 73 67 5f 68 65 61 64 65 72 5f 74 20 68 65 61 msg_header_t hea
0500: 64 3b 0a 20 20 20 20 6d 61 63 68 5f 6d 73 67 5f d;. mach_msg_
0510: 62 6f 64 79 5f 74 20 6d 73 67 68 5f 62 6f 64 79 body_t msgh_body
0520: 3b 0a 20 20 20 20 63 68 61 72 20 64 61 74 61 5b ;. char data[
0530: 31 30 32 34 5d 3b 0a 20 20 7d 20 6d 73 67 3b 0a 1024];. } msg;.
0540: 20 20 6d 61 63 68 5f 6d 73 67 5f 72 65 74 75 72 mach_msg_retur
0550: 6e 5f 74 20 72 65 74 76 61 6c 3b 0a 20 20 2f 2a n_t retval;. /*
0560: 20 57 61 69 74 20 66 6f 72 20 61 20 6d 65 73 73 Wait for a mess
0570: 61 67 65 20 6f 6e 20 74 68 65 20 65 78 63 65 70 age on the excep
0580: 74 69 6f 6e 20 70 6f 72 74 2e 20 20 2a 2f 0a 20 tion port. */.
0590: 20 72 65 74 76 61 6c 20 3d 20 6d 61 63 68 5f 6d retval = mach_m
05a0: 73 67 20 28 26 6d 73 67 2e 68 65 61 64 2c 20 4d sg (&msg.head, M
05b0: 41 43 48 5f 52 43 56 5f 4d 53 47 20 7c 20 4d 41 ACH_RCV_MSG | MA
05c0: 43 48 5f 52 43 56 5f 4c 41 52 47 45 2c 20 30 2c CH_RCV_LARGE, 0,
05d0: 20 73 69 7a 65 6f 66 20 28 6d 73 67 29 2c 0a 20 sizeof (msg),.
05e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
05f0: 20 20 20 20 6f 75 72 5f 65 78 63 65 70 74 69 6f our_exceptio
0600: 6e 5f 70 6f 72 74 2c 20 4d 41 43 48 5f 4d 53 47 n_port, MACH_MSG
0610: 5f 54 49 4d 45 4f 55 54 5f 4e 4f 4e 45 2c 20 4d _TIMEOUT_NONE, M
0620: 41 43 48 5f 50 4f 52 54 5f 4e 55 4c 4c 29 3b 0a ACH_PORT_NULL);.
0630: 20 20 69 66 20 28 72 65 74 76 61 6c 20 21 3d 20 if (retval !=
0640: 4d 41 43 48 5f 4d 53 47 5f 53 55 43 43 45 53 53 MACH_MSG_SUCCESS
0650: 29 0a 20 20 20 20 61 62 6f 72 74 20 28 29 3b 0a ). abort ();.
0660: 20 20 65 78 69 74 20 28 31 29 3b 0a 7d 0a 73 74 exit (1);.}.st
0670: 61 74 69 63 20 76 6f 69 64 0a 6e 6f 63 72 61 73 atic void.nocras
0680: 68 5f 69 6e 69 74 20 28 76 6f 69 64 29 0a 7b 0a h_init (void).{.
0690: 20 20 6d 61 63 68 5f 70 6f 72 74 5f 74 20 73 65 mach_port_t se
06a0: 6c 66 20 3d 20 6d 61 63 68 5f 74 61 73 6b 5f 73 lf = mach_task_s
06b0: 65 6c 66 20 28 29 3b 0a 20 20 2f 2a 20 41 6c 6c elf ();. /* All
06c0: 6f 63 61 74 65 20 61 20 70 6f 72 74 20 6f 6e 20 ocate a port on
06d0: 77 68 69 63 68 20 74 68 65 20 74 68 72 65 61 64 which the thread
06e0: 20 73 68 61 6c 6c 20 6c 69 73 74 65 6e 20 66 6f shall listen fo
06f0: 72 20 65 78 63 65 70 74 69 6f 6e 73 2e 20 20 2a r exceptions. *
0700: 2f 0a 20 20 69 66 20 28 6d 61 63 68 5f 70 6f 72 /. if (mach_por
0710: 74 5f 61 6c 6c 6f 63 61 74 65 20 28 73 65 6c 66 t_allocate (self
0720: 2c 20 4d 41 43 48 5f 50 4f 52 54 5f 52 49 47 48 , MACH_PORT_RIGH
0730: 54 5f 52 45 43 45 49 56 45 2c 20 26 6f 75 72 5f T_RECEIVE, &our_
0740: 65 78 63 65 70 74 69 6f 6e 5f 70 6f 72 74 29 0a exception_port).
0750: 20 20 20 20 20 20 3d 3d 20 4b 45 52 4e 5f 53 55 == KERN_SU
0760: 43 43 45 53 53 29 20 7b 0a 20 20 20 20 2f 2a 20 CCESS) {. /*
0770: 53 65 65 20 68 74 74 70 3a 2f 2f 77 65 62 2e 6d See http://web.m
0780: 69 74 2e 65 64 75 2f 64 61 72 77 69 6e 2f 73 72 it.edu/darwin/sr
0790: 63 2f 6d 6f 64 75 6c 65 73 2f 78 6e 75 2f 6f 73 c/modules/xnu/os
07a0: 66 6d 6b 2f 6d 61 6e 2f 6d 61 63 68 5f 70 6f 72 fmk/man/mach_por
07b0: 74 5f 69 6e 73 65 72 74 5f 72 69 67 68 74 2e 68 t_insert_right.h
07c0: 74 6d 6c 2e 20 20 2a 2f 0a 20 20 20 20 69 66 20 tml. */. if
07d0: 28 6d 61 63 68 5f 70 6f 72 74 5f 69 6e 73 65 72 (mach_port_inser
07e0: 74 5f 72 69 67 68 74 20 28 73 65 6c 66 2c 20 6f t_right (self, o
07f0: 75 72 5f 65 78 63 65 70 74 69 6f 6e 5f 70 6f 72 ur_exception_por
0800: 74 2c 20 6f 75 72 5f 65 78 63 65 70 74 69 6f 6e t, our_exception
0810: 5f 70 6f 72 74 2c 0a 20 20 20 20 20 20 20 20 20 _port,.
0820: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0830: 20 20 20 20 20 20 20 4d 41 43 48 5f 4d 53 47 5f MACH_MSG_
0840: 54 59 50 45 5f 4d 41 4b 45 5f 53 45 4e 44 29 0a TYPE_MAKE_SEND).
0850: 20 20 20 20 20 20 20 20 3d 3d 20 4b 45 52 4e 5f == KERN_
0860: 53 55 43 43 45 53 53 29 20 7b 0a 20 20 20 20 20 SUCCESS) {.
0870: 20 2f 2a 20 54 68 65 20 65 78 63 65 70 74 69 6f /* The exceptio
0880: 6e 73 20 77 65 20 77 61 6e 74 20 74 6f 20 63 61 ns we want to ca
0890: 74 63 68 2e 20 20 4f 6e 6c 79 20 45 58 43 5f 42 tch. Only EXC_B
08a0: 41 44 5f 41 43 43 45 53 53 20 69 73 20 69 6e 74 AD_ACCESS is int
08b0: 65 72 65 73 74 69 6e 67 0a 20 20 20 20 20 20 20 eresting.
08c0: 20 20 66 6f 72 20 75 73 2e 20 20 2a 2f 0a 20 20 for us. */.
08d0: 20 20 20 20 65 78 63 65 70 74 69 6f 6e 5f 6d 61 exception_ma
08e0: 73 6b 5f 74 20 6d 61 73 6b 20 3d 20 45 58 43 5f sk_t mask = EXC_
08f0: 4d 41 53 4b 5f 42 41 44 5f 41 43 43 45 53 53 3b MASK_BAD_ACCESS;
0900: 0a 20 20 20 20 20 20 2f 2a 20 43 72 65 61 74 65 . /* Create
0910: 20 74 68 65 20 74 68 72 65 61 64 20 6c 69 73 74 the thread list
0920: 65 6e 69 6e 67 20 6f 6e 20 74 68 65 20 65 78 63 ening on the exc
0930: 65 70 74 69 6f 6e 20 70 6f 72 74 2e 20 20 2a 2f eption port. */
0940: 0a 20 20 20 20 20 20 70 74 68 72 65 61 64 5f 61 . pthread_a
0950: 74 74 72 5f 74 20 61 74 74 72 3b 0a 20 20 20 20 ttr_t attr;.
0960: 20 20 70 74 68 72 65 61 64 5f 74 20 74 68 72 65 pthread_t thre
0970: 61 64 3b 0a 20 20 20 20 20 20 69 66 20 28 70 74 ad;. if (pt
0980: 68 72 65 61 64 5f 61 74 74 72 5f 69 6e 69 74 20 hread_attr_init
0990: 28 26 61 74 74 72 29 20 3d 3d 20 30 0a 20 20 20 (&attr) == 0.
09a0: 20 20 20 20 20 20 20 26 26 20 70 74 68 72 65 61 && pthrea
09b0: 64 5f 61 74 74 72 5f 73 65 74 64 65 74 61 63 68 d_attr_setdetach
09c0: 73 74 61 74 65 20 28 26 61 74 74 72 2c 20 50 54 state (&attr, PT
09d0: 48 52 45 41 44 5f 43 52 45 41 54 45 5f 44 45 54 HREAD_CREATE_DET
09e0: 41 43 48 45 44 29 20 3d 3d 20 30 0a 20 20 20 20 ACHED) == 0.
09f0: 20 20 20 20 20 20 26 26 20 70 74 68 72 65 61 64 && pthread
0a00: 5f 63 72 65 61 74 65 20 28 26 74 68 72 65 61 64 _create (&thread
0a10: 2c 20 26 61 74 74 72 2c 20 6d 61 63 68 5f 65 78 , &attr, mach_ex
0a20: 63 65 70 74 69 6f 6e 5f 74 68 72 65 61 64 2c 20 ception_thread,
0a30: 4e 55 4c 4c 29 20 3d 3d 20 30 29 20 7b 0a 20 20 NULL) == 0) {.
0a40: 20 20 20 20 20 20 70 74 68 72 65 61 64 5f 61 74 pthread_at
0a50: 74 72 5f 64 65 73 74 72 6f 79 20 28 26 61 74 74 tr_destroy (&att
0a60: 72 29 3b 0a 20 20 20 20 20 20 20 20 2f 2a 20 52 r);. /* R
0a70: 65 70 6c 61 63 65 20 74 68 65 20 65 78 63 65 70 eplace the excep
0a80: 74 69 6f 6e 20 70 6f 72 74 20 69 6e 66 6f 20 66 tion port info f
0a90: 6f 72 20 74 68 65 73 65 20 65 78 63 65 70 74 69 or these excepti
0aa0: 6f 6e 73 20 77 69 74 68 20 6f 75 72 20 6f 77 6e ons with our own
0ab0: 2e 0a 20 20 20 20 20 20 20 20 20 20 20 4e 6f 74 .. Not
0ac0: 65 20 74 68 61 74 20 77 65 20 72 65 70 6c 61 63 e that we replac
0ad0: 65 20 74 68 65 20 65 78 63 65 70 74 69 6f 6e 20 e the exception
0ae0: 70 6f 72 74 20 66 6f 72 20 74 68 65 20 65 6e 74 port for the ent
0af0: 69 72 65 20 74 61 73 6b 2c 20 6e 6f 74 20 6f 6e ire task, not on
0b00: 6c 79 0a 20 20 20 20 20 20 20 20 20 20 20 66 6f ly. fo
0b10: 72 20 61 20 70 61 72 74 69 63 75 6c 61 72 20 74 r a particular t
0b20: 68 72 65 61 64 2e 20 20 54 68 69 73 20 68 61 73 hread. This has
0b30: 20 74 68 65 20 65 66 66 65 63 74 20 74 68 61 74 the effect that
0b40: 20 77 68 65 6e 20 6f 75 72 20 65 78 63 65 70 74 when our except
0b50: 69 6f 6e 0a 20 20 20 20 20 20 20 20 20 20 20 70 ion. p
0b60: 6f 72 74 20 67 65 74 73 20 74 68 65 20 6d 65 73 ort gets the mes
0b70: 73 61 67 65 2c 20 74 68 65 20 74 68 72 65 61 64 sage, the thread
0b80: 20 73 70 65 63 69 66 69 63 20 65 78 63 65 70 74 specific except
0b90: 69 6f 6e 20 70 6f 72 74 20 68 61 73 20 61 6c 72 ion port has alr
0ba0: 65 61 64 79 0a 20 20 20 20 20 20 20 20 20 20 20 eady.
0bb0: 62 65 65 6e 20 61 73 6b 65 64 2c 20 61 6e 64 20 been asked, and
0bc0: 77 65 20 64 6f 6e 27 74 20 6e 65 65 64 20 74 6f we don't need to
0bd0: 20 62 6f 74 68 65 72 20 61 62 6f 75 74 20 69 74 bother about it
0be0: 2e 0a 20 20 20 20 20 20 20 20 20 20 20 53 65 65 .. See
0bf0: 20 68 74 74 70 3a 2f 2f 77 65 62 2e 6d 69 74 2e http://web.mit.
0c00: 65 64 75 2f 64 61 72 77 69 6e 2f 73 72 63 2f 6d edu/darwin/src/m
0c10: 6f 64 75 6c 65 73 2f 78 6e 75 2f 6f 73 66 6d 6b odules/xnu/osfmk
0c20: 2f 6d 61 6e 2f 74 61 73 6b 5f 73 65 74 5f 65 78 /man/task_set_ex
0c30: 63 65 70 74 69 6f 6e 5f 70 6f 72 74 73 2e 68 74 ception_ports.ht
0c40: 6d 6c 2e 20 20 2a 2f 0a 20 20 20 20 20 20 20 20 ml. */.
0c50: 74 61 73 6b 5f 73 65 74 5f 65 78 63 65 70 74 69 task_set_excepti
0c60: 6f 6e 5f 70 6f 72 74 73 20 28 73 65 6c 66 2c 20 on_ports (self,
0c70: 6d 61 73 6b 2c 20 6f 75 72 5f 65 78 63 65 70 74 mask, our_except
0c80: 69 6f 6e 5f 70 6f 72 74 2c 0a 20 20 20 20 20 20 ion_port,.
0c90: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0ca0: 20 20 20 20 20 20 20 20 20 20 20 20 45 58 43 45 EXCE
0cb0: 50 54 49 4f 4e 5f 44 45 46 41 55 4c 54 2c 20 4d PTION_DEFAULT, M
0cc0: 41 43 48 49 4e 45 5f 54 48 52 45 41 44 5f 53 54 ACHINE_THREAD_ST
0cd0: 41 54 45 29 3b 0a 20 20 20 20 20 20 7d 0a 20 20 ATE);. }.
0ce0: 20 20 7d 0a 20 20 7d 0a 7d 0a 23 65 6c 73 65 0a }. }.}.#else.
0cf0: 2f 2a 20 41 76 6f 69 64 20 61 20 63 72 61 73 68 /* Avoid a crash
0d00: 20 6f 6e 20 50 4f 53 49 58 20 73 79 73 74 65 6d on POSIX system
0d10: 73 2e 20 20 2a 2f 0a 23 69 6e 63 6c 75 64 65 20 s. */.#include
0d20: 3c 73 69 67 6e 61 6c 2e 68 3e 0a 2f 2a 20 41 20 <signal.h>./* A
0d30: 50 4f 53 49 58 20 73 69 67 6e 61 6c 20 68 61 6e POSIX signal han
0d40: 64 6c 65 72 2e 20 20 2a 2f 0a 73 74 61 74 69 63 dler. */.static
0d50: 20 76 6f 69 64 0a 65 78 63 65 70 74 69 6f 6e 5f void.exception_
0d60: 68 61 6e 64 6c 65 72 20 28 69 6e 74 20 73 69 67 handler (int sig
0d70: 29 0a 7b 0a 20 20 65 78 69 74 20 28 31 29 3b 0a ).{. exit (1);.
0d80: 7d 0a 73 74 61 74 69 63 20 76 6f 69 64 0a 6e 6f }.static void.no
0d90: 63 72 61 73 68 5f 69 6e 69 74 20 28 76 6f 69 64 crash_init (void
0da0: 29 0a 7b 0a 23 69 66 64 65 66 20 53 49 47 53 45 ).{.#ifdef SIGSE
0db0: 47 56 0a 20 20 73 69 67 6e 61 6c 20 28 53 49 47 GV. signal (SIG
0dc0: 53 45 47 56 2c 20 65 78 63 65 70 74 69 6f 6e 5f SEGV, exception_
0dd0: 68 61 6e 64 6c 65 72 29 3b 0a 23 65 6e 64 69 66 handler);.#endif
0de0: 0a 23 69 66 64 65 66 20 53 49 47 42 55 53 0a 20 .#ifdef SIGBUS.
0df0: 20 73 69 67 6e 61 6c 20 28 53 49 47 42 55 53 2c signal (SIGBUS,
0e00: 20 65 78 63 65 70 74 69 6f 6e 5f 68 61 6e 64 6c exception_handl
0e10: 65 72 29 3b 0a 23 65 6e 64 69 66 0a 7d 0a 23 65 er);.#endif.}.#e
0e20: 6e 64 69 66 0a 5d 5d 29 0a ndif.]]).