--- Comment #8 from Iain Buclaw <> 2011-03-09 12:10:47 PST ---
Some notes:

- sigaction can be used to catch signals
- signals caught have a packed struct with some simple information attached.
 - si_signo: Signal number (ie: SIGSEGV = 11).
 - si_errno: Errno value (unused on Linux).
 - si_code: Signal code to indicate why this signal was sent.

- The two possible signal codes related to SIGSEGV signals are:
 - SEGV_MAPERR: address not mapped to object
 - SEGV_ACCERR: invalid permissions for mapped object

- General purpose signal codes tell how the signal was raised:
 - SI_USER:    kill, sigsend or raise
 - SI_KERNEL:  The kernel
 - SI_QUEUE:   sigqueue
 - SI_TIMER:   timer expired
 - SI_MESGQ:   mesq state changed
 - SI_ASYNCIO: AIO completed
 - SI_SIGIO:   queued SIGIO

- HLT is emitted from the kernel (SI_KERNEL).

Here is a quick sample program:

import core.stdc.stdio;
import core.sys.posix.unistd;
import core.sys.posix.signal;

extern(C) void signal_handler(int signum, siginfo_t* info, void* ptr)
    if (info.si_signo == SIGSEGV && info.si_code == SI_KERNEL)
        fprintf(stderr, "assert(0) or SEGV sent by kernel\n");

void main()
    sigaction_t action;
    action.sa_flags = SA_SIGINFO | SA_RESETHAND;
    action.sa_sigaction = &signal_handler;
    sigaction(SIGSEGV, &action, null);

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to