Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 5: Locking and Interprocess Communication


<asm-generic/siginfo.h>
typedef struct siginfo {
int si_signo;
int si_errno;
int si_code;

union {
/* Signal-specific information */
struct { ... } _kill;
struct { ... } _timer; /* POSIX.1b timers */
struct { ... } _rt; /* POSIX.1b signals */
struct { ... } _sigchld;
struct { ... } _sigfault; /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
struct { ... } _sigpoll;
} _sifields;
} siginfo_t;

❑ si_signoholds the signal number.
❑ si_errnohas a non-zero value if the signal was raised as a result of an error; otherwise, its
value is 0.
❑ si_codereturns detailed information on the origin of the signal; we are interested only in the
distinction between user signal (SI_USER) and kernel-generated signal (SI_KERNEL).
❑ Additional information needed by the kernel to handle some signals is held in the_sifield
union. For example,_sigfaultcontains the userspace address of the instruction that raised the
signal.

Because a very large number of data structures are used, Figure 5-8 gives an overview of how they are
interlinked.

pending
sighand

task_struct

count

k_sigaction[_NSIG]

list_head list
sigset_t signal

Figure 5-8: Data structures used in signal management.

ImplementingSignalHandling


Table 5-3 shows an overview of the most important system calls used by the kernel to implement signal
handling. In practice, there are a few more, some for historical reasons, some to ensure compatibility with
various standards — above all, POSIX.

Although the signal mechanism appears to be very simple, its implementation is made more complicated
by the many subtleties and details that must be takeninto account. Because these reveal no significant
Free download pdf