1stack_violation(3C) Standard C Library Functions stack_violation(3C)
2
3
4
6 stack_violation - determine stack boundary violation event
7
9 #include <ucontext.h>
10
11 int stack_violation(int sig, const siginfo_t *sip,
12 const ucontext_t *ucp);
13
14
16 The stack_violation() function returns a boolean value indicating
17 whether the signal, sig, and accompanying signal information, sip, and
18 saved context, ucp, represent a stack boundary violation event or a
19 stack overflow.
20
22 The stack_violation() function returns 0 if the signal does not repre‐
23 sent a stack boundary violation event and 1 if the signal does repre‐
24 sent a stack boundary violation event.
25
27 No errors are defined.
28
30 Example 1 Set up a signal handler to run on an alternate stack.
31
32
33 The following example sets up a signal handler for SIGSEGV to run on an
34 alternate signal stack. For each signal it handles, the handler emits a
35 message to indicate if the signal was produced due to a stack boundary
36 violation.
37
38
39 #include <stdlib.h>
40 #include <unistd.h>
41 #include <ucontext.h>
42 #include <signal.h>
43
44
45 static void
46 handler(int sig, siginfo_t *sip, void *p)
47 {
48 ucontext_t *ucp = p;
49 const char *str;
50
51 if (stack_violation(sig, sip, ucp))
52 str = "stack violation.\n";
53 else
54 str = "no stack violation.\n";
55
56 (void) write(STDERR_FILENO, str, strlen(str));
57
58 exit(1);
59 }
60
61 int
62 main(int argc, char **argv)
63 {
64 struct sigaction sa;
65 stack_t altstack;
66
67 altstack.ss_size = SIGSTKSZ;
68 altstack.ss_sp = malloc(SIGSTKSZ);
69 altstack.ss_flags = 0;
70
71 (void) sigaltstack(&altstack, NULL);
72
73 sa.sa_sigaction = handler;
74 (void) sigfillset(&sa.sa_mask);
75 sa.sa_flags = SA_ONSTACK | SA_SIGINFO;
76 (void) sigaction(SIGSEGV, &sa, NULL);
77
78 /*
79 * The application is now set up to use stack_violation(3C).
80 */
81
82 return (0);
83 }
84
85
87 An application typically uses stack_violation() in a signal handler
88 that has been installed for SIGSEGV using sigaction(2) with the SA_SIG‐
89 INFO flag set and is configured to run on an alternate signal stack.
90
92 See attributes(5) for descriptions of the following attributes:
93
94
95
96
97 ┌─────────────────────────────┬─────────────────────────────┐
98 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
99 ├─────────────────────────────┼─────────────────────────────┤
100 │Interface Stability │Evolving │
101 ├─────────────────────────────┼─────────────────────────────┤
102 │MT-Level │Async-Signal-Safe │
103 └─────────────────────────────┴─────────────────────────────┘
104
106 sigaction(2), sigaltstack(2), stack_getbounds(3C), stack_inbounds(3C),
107 stack_setbounds(3C), attributes(5)
108
109
110
111SunOS 5.11 18 Jul 2002 stack_violation(3C)