Debian Codegraph @

tapset/linux/signal.stp

raw
1 // Signal tapset
2 // Copyright (C) 2006 IBM Corp.
3 // Copyright (C) 2006 Intel Corporation.
4 // Copyright (C) 2008-2017 Red Hat, Inc.
5 //
6 // This file is part of systemtap, and is free software. You can
7 // redistribute it and/or modify it under the terms of the GNU General
8 // Public License (GPL); either version 2, or (at your option) any
9 // later version.
10 //
11 //
12 // <tapsetdescription>
13 // This family of probe points is used to probe signal activities.
14 // Since there are so many signals sent to processes at any given
15 // point, it is advisable to filter the information according to the
16 // requirements. For example, filter only for a particular signal
17 // (if sig==2) or for a particular process (if pid_name==stap).
18 // </tapsetdescription>
19
20 /**
21 * probe signal.send - Signal being sent to a process
22 * Arguments:
23 * @sig: The number of the signal
24 * @sig_name: A string representation of the signal
25 * @sig_pid: The PID of the process receiving the signal
26 * @pid_name: The name of the signal recipient
27 * @si_code: Indicates the signal type
28 * @task: A task handle to the signal recipient
29 * @sinfo: The address of siginfo struct
30 * @shared: Indicates whether the signal is shared by the thread group
31 * @send2queue: Indicates whether the signal is sent to an existing
32 * sigqueue (deprecated in SystemTap 2.1)
33 * @name: The name of the function used to send out the signal
34 *
35 * Context:
36 * The signal's sender.
37 *
38 */
39 probe signal.send = __signal.send.signal_generate !,
40 __signal.send.send_sigqueue,
41 %( kernel_v > "2.6.25" %?
42 __signal.send.send_signal ?
43 %:
44 __signal.send.group_send_sig_info ?,
45 __signal.send.send_group_sigqueue ?,
46 __signal.send.specific_send_sig_info ?
47 %)
48 {
49 sig_name = _signal_name(sig)
50 sig_pid = task_pid(task)
51 pid_name = task_execname(task)
52
53 if (sinfo == 2) # 2 == SEND_SIG_FORCED
54 si_code ="SIGSTOP or SIGKILL"
55 else if (sinfo > 0)
56 si_code="SI_KERNEL (SIGFPE, SIGSEGV, SIGTRAP, SIGCHLD, SIGPOLL)"
57 else if (sinfo <= 0)
58 si_code="SI_USER or SI_TIMER or SI_ASYNCIO"
59 }
60
61 probe __signal.send.signal_generate = kernel.trace("signal_generate") ?
62 {
63 name = "signal_generate"
64 sig = $sig
65 task = $task
66 sinfo = $info
67 shared = (@choose_defined($group, 0) == 0) ? 0 : 1
68 %( systemtap_v <= "2.1" %?
69 send2queue = 0
70 %)
71 }
72
73 probe __signal.send.send_sigqueue = kernel.function("send_sigqueue")
74 {
75 name = "send_sigqueue"
76 task = @choose_defined($t, $p)
77 sig = @choose_defined($q->info->si_signo, $sig)
78 sinfo = @choose_defined($q->info, 0)
79 shared = 0
80 %( systemtap_v <= "2.1" %?
81 send2queue = 1
82 %)
83 }
84
85 probe __signal.send.send_signal =
86 kernel.function("__send_signal") !,
87 kernel.function("send_signal") ?
88 {
89 if (@defined($group)) {
90 name = "__send_signal"
91 shared = ($group == 0) ? 0 : 1
92 }
93 else {
94 name = "send_signal"
95 shared = 0
96 }
97 sig = $sig
98 task = $t
99 sinfo = $info
100 %( systemtap_v <= "2.1" %?
101 send2queue = 0
102 %)
103 }
104
105 probe __signal.send.group_send_sig_info =
106 kernel.function("__group_send_sig_info")
107 {
108 name = "__group_send_sig_info"
109 sig = $sig
110 task = $p
111 sinfo = $info
112 shared = 1
113 %( systemtap_v <= "2.1" %?
114 send2queue = 0
115 %)
116 }
117
118 probe __signal.send.send_group_sigqueue =
119 kernel.function("send_group_sigqueue") ?
120 {
121 name = "send_group_sigqueue"
122 sig = $sig
123 task = $p
124 sinfo = 0 # $q->info
125 shared = 1
126 %( systemtap_v <= "2.1" %?
127 send2queue = 1
128 %)
129 }
130
131 probe __signal.send.specific_send_sig_info =
132 kernel.function("specific_send_sig_info").call ?
133 {
134 name = "specific_send_sig_info"
135 sig = $sig
136 task = $t
137 sinfo = $info
138 shared = 0
139 %( systemtap_v <= "2.1" %?
140 send2queue = 0
141 %)
142 }
143
144 %( systemtap_v <= "2.1" %?
145 /**
146 * probe signal.send.return - Signal being sent to a process completed (deprecated in SystemTap 2.1)
147 * @retstr: The return value to either __group_send_sig_info, specific_send_sig_info, or send_sigqueue
148 * @shared: Indicates whether the sent signal is shared by the thread group.
149 * @send2queue: Indicates whether the sent signal was sent to an existing sigqueue
150 * @name: The name of the function used to send out the signal
151 *
152 * Context:
153 * The signal's sender. (correct?)
154 *
155 * Possible __group_send_sig_info and
156 * specific_send_sig_info return values are as follows;
157 *
158 * 0 -- The signal is successfully sent to a process,
159 * which means that, (1) the signal was ignored by the receiving process,
160 * (2) this is a non-RT signal and the system already has one queued, and
161 * (3) the signal was successfully added to the sigqueue of the receiving process.
162 *
163 * -EAGAIN -- The sigqueue of the receiving process is
164 * overflowing, the signal was RT, and the signal was sent by a user using something other
165 * than kill().
166 *
167 * Possible send_group_sigqueue and
168 * send_sigqueue return values are as follows;
169 *
170 * 0 -- The signal was either successfully added into the
171 * sigqueue of the receiving process, or a SI_TIMER entry is already
172 * queued (in which case, the overrun count will be simply incremented).
173 *
174 * 1 -- The signal was ignored by the receiving process.
175 *
176 * -1 -- (send_sigqueue only) The task was marked
177 * exiting, allowing * posix_timer_event to redirect it to the group
178 * leader.
179 *
180 */
181 probe signal.send.return = __signal.send.send_sigqueue.return,
182 %( kernel_v > "2.6.25" %?
183 __signal.send.send_signal.return ?
184 %:
185 __signal.send.group_send_sig_info.return ?,
186 __signal.send.send_group_sigqueue.return ?,
187 __signal.send.specific_send_sig_info.return ?
188 %)
189 {
190 retstr = return_str(1, $return)
191 }
192
193 // - return 0 if the signal is either sucessfully added into the
194 // sigqueue of receiving process or a SI_TIMER entry is already
195 // queued so just increment the overrun count
196 //
197 // - return 1 if this signal is ignored by receiving process
198 //
199 // - return -1 if the task is marked exiting, so posix_timer_event
200 // can redirect it to the group leader
201
202 probe __signal.send.send_sigqueue.return =
203 kernel.function("send_sigqueue").return ?
204 {
205 name = "send_sigqueue"
206 shared = 0
207 send2queue = 1
208 }
209
210 probe __signal.send.send_signal.return =
211 kernel.function("__send_signal").return !,
212 kernel.function("send_signal").return ?
213 {
214 if (@defined(@entry($group))) {
215 name = "__send_signal"
216 shared = (@entry($group) == 0) ? 0 : 1
217 }
218 else {
219 name = "send_signal"
220 shared = 0
221 }
222 send2queue = 0
223 }
224
225 // Return values for "__group_send_sig_info" and "specific_send_sig_info"
226 //
227 // - return 0 if the signal is successfully sent to a process,
228 // which means the following:
229 // <1> the signal is ignored by receiving process
230 // <2> this is a non-RT signal and we already have one queued
231 // <3> the signal is successfully added into the sigqueue of
232 // receiving process
233 //
234 // - return -EAGAIN if the sigqueue is overflow the signal was RT
235 // and sent by user using something other than kill()
236
237 probe __signal.send.group_send_sig_info.return =
238 kernel.function("__group_send_sig_info").return
239 {
240 name = "__group_send_sig_info"
241 shared = 1
242 send2queue = 0
243 }
244
245 probe __signal.send.specific_send_sig_info.return =
246 kernel.function("specific_send_sig_info").return ?
247 {
248 name = "specific_send_sig_info"
249 shared = 0
250 send2queue = 0
251 }
252
253 // - return 0 if the signal is either successfully added into the
254 // sigqueue of receiving process or a SI_TIMER entry is already
255 // queued so just increment the overrun count
256 //
257 // - return 1 if this signal is ignored by receiving process
258
259 probe __signal.send.send_group_siggueue.return =
260 kernel.function("send_group_sigqueue").return ?
261 {
262 name = "send_group_sigqueue"
263 shared = 1
264 send2queue = 1
265 }
266 %)
267
268 /**
269 * probe signal.checkperm - Check being performed on a sent signal
270 * @sig: The number of the signal
271 * @sig_name: A string representation of the signal
272 * @sig_pid: The PID of the process receiving the signal
273 * @pid_name: Name of the process receiving the signal
274 * @si_code: Indicates the signal type
275 * @task: A task handle to the signal recipient
276 * @sinfo: The address of the siginfo structure
277 * @name: Name of the probe point
278 */
279 probe signal.checkperm = kernel.function("check_kill_permission")
280 {
281 sig = $sig
282 task = $t
283 sinfo = $info
284 name = "checkperm"
285
286 sig_name = _signal_name($sig)
287 sig_pid = task_pid(task)
288 pid_name = task_execname(task)
289
290 if (sinfo == 2)
291 si_code ="SIGSTOP or SIGKILL"
292 else if (sinfo > 0)
293 si_code="SI_KERNEL (SIGFPE, SIGSEGV, SIGTRAP, SIGCHLD, SIGPOLL)"
294 else if (sinfo <= 0)
295 si_code="SI_USER or SI_TIMER or SI_ASYNCIO"
296 }
297
298 /**
299 * probe signal.checkperm.return - Check performed on a sent signal completed
300 * @name: Name of the probe point
301 * @retstr: Return value as a string
302 */
303 probe signal.checkperm.return =
304 kernel.function("check_kill_permission").return ?
305 {
306 name = "checkperm"
307 retstr = return_str(1, $return)
308 }
309
310
311 /**
312 * probe signal.wakeup - Sleeping process being wakened for signal
313 * @sig_pid: The PID of the process to wake
314 * @pid_name: Name of the process to wake
315 * @resume: Indicates whether to wake up a task in a
316 * STOPPED or TRACED state
317 * @state_mask: A string representation indicating the mask
318 * of task states to wake. Possible values are
319 * TASK_INTERRUPTIBLE, TASK_STOPPED,
320 * TASK_TRACED, TASK_WAKEKILL, and TASK_INTERRUPTIBLE.
321 */
322 probe __signal.wakeup.signal_wake_up_state
323 = kernel.function("signal_wake_up_state")
324 {
325 resume = ($state == 0) ? 0 : 1;
326 if ($state & @const("__TASK_STOPPED") != 0) {
327 state_mask .= " | TASK_STOPPED"
328 }
329 if ($state & @const("__TASK_TRACED") != 0) {
330 state_mask .= " | TASK_TRACED"
331 }
332 if ($state & @const("TASK_WAKEKILL") != 0) {
333 state_mask .= " | TASK_WAKEKILL"
334 }
335 state_mask = "TASK_INTERRUPTIBLE" . state_mask
336 }
337 probe __signal.wakeup.signal_wake_up = kernel.function("signal_wake_up")
338 {
339 resume = $resume
340 if (resume == 0) {
341 state_mask = "TASK_INTERRUPTIBLE"
342 } else {
343 state_mask = "TASK_INTERRUPTIBLE | TASK_STOPPED | TASK_TRACED"
344 }
345 }
346 probe signal.wakeup = __signal.wakeup.signal_wake_up_state !,
347 __signal.wakeup.signal_wake_up
348 {
349 name = "wakeup"
350 sig_pid = $t->pid
351 pid_name = kernel_string($t->comm)
352 }
353
354
355 /**
356 * probe signal.check_ignored - Checking to see signal is ignored
357 * @sig_pid: The PID of the process receiving the signal
358 * @pid_name: Name of the process receiving the signal
359 * @sig: The number of the signal
360 * @sig_name: A string representation of the signal
361 */
362 probe signal.check_ignored = kernel.function("sig_ignored")
363 {
364 name = "check_ignored"
365 sig_pid = $t->pid
366 pid_name = kernel_string($t->comm)
367 sig = $sig
368 sig_name = _signal_name($sig)
369 }
370
371 /**
372 * probe signal.check_ignored.return - Check to see signal is ignored completed
373 * @name: Name of the probe point
374 * @retstr: Return value as a string
375 */
376
377 /* On newer kernels, sig_ignored() is inline, so we can't do a return
378 * probe. So, instead we'll probe prepare_signal(), which is the only
379 * caller of sig_ignored(). */
380 probe __signal.check_ignored.sig_ignored.return =
381 kernel.function("sig_ignored").return
382 {
383 retstr = return_str(1, $return)
384 }
385 probe __signal.check_ignored.prepare_signal.return =
386 kernel.function("prepare_signal").return
387 {
388 /* The prepare_signal() function inverts the return value of
389 * sig_ignored(). */
390 retstr = return_str(1, !$return)
391 }
392 probe signal.check_ignored.return =
393 __signal.check_ignored.sig_ignored.return !,
394 __signal.check_ignored.prepare_signal.return
395 {
396 name = "check_ignored"
397 }
398
399
400 // probe signal.handle_stop
401 // For now, just comment it out since at the time handle_stop_signal()
402 // is called, it doesn't know whether current signal is STOP/COUNT.
403 // So the calling of handle_stop_signal() doesn't mean that the Kernel
404 // is now processing the STOP/COUNT signal
405 //
406 /*
407 probe signal.handle_stop = kernel.function("handle_stop_signal")
408 {
409 sig_pid = $p->pid
410 pid_name = kernel_string($p->comm)
411 sig_info = $sig
412 sig_name = _signal_name($sig)
413 }
414 */
415
416
417 /**
418 * probe signal.force_segv - Forcing send of SIGSEGV
419 * @sig_pid: The PID of the process receiving the signal
420 * @pid_name: Name of the process receiving the signal
421 * @sig: The number of the signal
422 * @sig_name: A string representation of the signal
423 * @name: Name of the probe point
424 */
425 probe signal.force_segv = _signal.force_segv.*
426 {
427 name = "force_segv"
428 }
429
430 probe _signal.force_segv.part1 = kernel.function("force_sigsegv")
431 {
432 sig_pid = $p->pid
433 pid_name = kernel_string($p->comm)
434 sig = $sig
435 sig_name = _signal_name($sig)
436 }
437
438 probe _signal.force_segv.part2 = kernel.function("force_sigsegv_info") ?
439 {
440 sig_pid = pid()
441 pid_name = execname()
442 sig = $sig
443 sig_name = _signal_name($sig)
444 }
445
446 /**
447 * probe signal.force_segv.return - Forcing send of SIGSEGV complete
448 * @name: Name of the probe point
449 * @retstr: Return value as a string
450 */
451 probe signal.force_segv.return =
452 kernel.function("force_sigsegv").return,
453 kernel.function("force_sigsegv_info").return ?
454 {
455 name = "force_segv"
456 retstr = return_str(1, $return)
457 }
458
459
460 /**
461 * probe signal.syskill - Sending kill signal to a process
462 * @name: Name of the probe point
463 * @sig: The specific signal sent to the process
464 * @sig_name: A string representation of the signal
465 * @sig_pid: The PID of the process receiving the signal
466 * @pid_name: The name of the signal recipient
467 * @task: A task handle to the signal recipient
468 */
469 probe signal.syskill = syscall.kill
470 {
471 name = "syskill"
472 sig_name = _signal_name(sig)
473 sig_pid = pid
474 task = pid2task(pid)
475 pid_name = task? task_execname(task): ""
476 }
477
478 /**
479 * probe signal.syskill.return - Sending kill signal completed
480 */
481 probe signal.syskill.return = syscall.kill.return
482 {
483 name = "syskill"
484 }
485
486 /**
487 * probe signal.sys_tkill - Sending a kill signal to a thread
488 * @name: Name of the probe point
489 * @sig_pid: The PID of the process receiving the kill signal
490 * @pid_name: The name of the signal recipient
491 * @sig: The specific signal sent to the process
492 * @sig_name: A string representation of the signal
493 * @task: A task handle to the signal recipient
494 *
495 * The tkill call is analogous to kill(2),
496 * except that it also allows a process within a specific thread group to
497 * be targeted. Such processes are targeted through their unique
498 * thread IDs (TID).
499 */
500 probe signal.systkill = syscall.tkill
501 {
502 name = "systkill"
503 sig_name = _signal_name(sig)
504 sig_pid = pid
505 task = pid2task(pid)
506 pid_name = task? task_execname(task): ""
507 }
508
509 /**
510 * probe signal.systkill.return - Sending kill signal to a thread completed
511 * @name: Name of the probe point
512 * @retstr: The return value to either __group_send_sig_info,
513 */
514 probe signal.systkill.return = syscall.tkill.return
515 {
516 name = "systkill"
517 }
518
519 /**
520 * probe signal.sys_tgkill - Sending kill signal to a thread group
521 * @name: Name of the probe point
522 * @sig_pid: The PID of the thread receiving the kill signal
523 * @pid_name: The name of the signal recipient
524 * @tgid: The thread group ID of the thread receiving the kill signal
525 * @sig: The specific kill signal sent to the process
526 * @sig_name: A string representation of the signal
527 * @task: A task handle to the signal recipient
528 *
529 * The tgkill call is similar to tkill,
530 * except that it also allows the caller to specify the thread group ID of
531 * the thread to be signalled. This protects against TID reuse.
532 */
533 probe signal.systgkill = syscall.tgkill
534 {
535 name = "systgkill"
536 sig_name = _signal_name(sig)
537 sig_pid = pid
538 task = pid2task(pid)
539 pid_name = task? task_execname(task): ""
540 }
541
542 /**
543 * probe signal.sys_tgkill.return - Sending kill signal to a thread group completed
544 * @name: Name of the probe point
545 * @retstr: The return value to either __group_send_sig_info,
546 */
547 probe signal.systgkill.return = syscall.tgkill.return
548 {
549 name = "systgkill"
550 }
551
552 /**
553 * probe signal.send_sig_queue - Queuing a signal to a process
554 * @name: Name of the probe point
555 * @sig: The queued signal
556 * @sig_name: A string representation of the signal
557 * @sig_pid: The PID of the process to which the signal is queued
558 * @pid_name: Name of the process to which the signal is queued
559 * @sigqueue_addr: The address of the signal queue
560 */
561 probe signal.send_sig_queue =
562 kernel.function("send_sigqueue"),
563 kernel.function("send_group_sigqueue") ?
564 {
565 name = "send_sig_queue"
566 if (! @defined($sig)) {
567 sig = $q->info->si_signo
568 sig_name = _signal_name($q->info->si_signo)
569 }
570 else {
571 sig = $sig
572 sig_name = _signal_name($sig)
573 }
574 if (@defined($t)) {
575 sig_pid = $t->pid
576 pid_name = kernel_string($t->comm)
577 }
578 else {
579 sig_pid = $p->pid
580 pid_name = kernel_string($p->comm)
581 }
582 sigqueue_addr = $q
583 }
584
585 /**
586 * probe signal.send_sig_queue.return - Queuing a signal to a process completed
587 * @name: Name of the probe point
588 * @retstr: Return value as a string
589 */
590 probe signal.send_sig_queue.return =
591 kernel.function("send_sigqueue").return,
592 kernel.function("send_group_sigqueue").return ?
593 {
594 name = "send_sig_queue"
595 retstr = return_str(1, $return)
596 }
597
598
599 /**
600 * probe signal.pending - Examining pending signal
601 * @name: Name of the probe point
602 * @sigset_add: The address of the user-space signal set
603 * (sigset_t)
604 * @sigset_size: The size of the user-space signal set
605 *
606 * This probe is used to examine a set of signals pending for delivery
607 * to a specific thread. This normally occurs when the
608 * do_sigpending kernel function is executed.
609 */
610 probe signal.pending = kernel.function("do_sigpending").call !,
611 kernel.function("sys_rt_sigpending").call ?,
612 kernel.function("compat_sys_rt_sigpending").call ?
613 {
614 name = "pending"
615 sigset_add=@choose_defined($set, $uset)
616
617 # Note that this isn't 100% correct if $sigsetsize doesn't
618 # exist (in the case of newer do_sigpending() calls). Instead,
619 # we're returning the default size of a sigset_t.
620 sigset_size=@choose_defined($sigsetsize, @cast_sizeof("sigset_t"))
621 }
622
623 /**
624 * probe signal.pending.return - Examination of pending signal completed
625 * @name: Name of the probe point
626 * @retstr: Return value as a string
627 */
628 probe signal.pending.return = kernel.function("do_sigpending").return !,
629 kernel.function("sys_rt_sigpending").return ?,
630 kernel.function("compat_sys_rt_sigpending").return ?
631 {
632 name = "pending"
633 retstr = return_str(1, $return)
634 }
635
636
637 /**
638 * probe signal.handle - Signal handler being invoked
639 * @name: Name of the probe point
640 * @sig: The signal number that invoked the signal handler
641 * @sig_name: A string representation of the signal
642 * @sinfo: The address of the siginfo table
643 * @sig_code: The si_code value of the siginfo signal
644 * @ka_addr: The address of the k_sigaction table
645 * associated with the signal
646 * @oldset_addr: The address of the bitmask array of blocked signals
647 * (deprecated in SystemTap 2.1)
648 * @regs: The address of the kernel-mode stack area (deprecated in
649 * SystemTap 2.1)
650 * @sig_mode: Indicates whether the signal was a user-mode or kernel-mode signal
651 */
652 probe signal.handle = __signal.handle.tp !, __signal.handle.kp
653 {
654 name = "handle"
655 // Check whether the signal is a User Mode or Kernel mode Signal.
656
657 if (sinfo == 0 && sig_code <= 0)
658 sig_mode = "User Mode Signal"
659 else if (sinfo >= 1)
660 sig_mode = "Kernel Mode Signal"
661 }
662
663 probe __signal.handle.tp = kernel.trace("signal_deliver") ?
664 {
665 sig = $sig
666 sig_name = _signal_name($sig)
667 sinfo = $info
668 sig_code = $info->si_code
669 ka_addr = $ka
670 %( systemtap_v <= "2.1" %?
671 oldset_addr = 0
672 regs = 0
673 %)
674 }
675
676 probe __signal.handle.kp = kernel.function("handle_rt_signal64") ?,
677 kernel.function("handle_rt_signal32") ?,
678 kernel.function("handle_signal32") !,
679 kernel.function("handle_signal")
680 {
681 if (@defined($sig)) {
682 sig = $sig
683 sig_name = _signal_name($sig)
684 }
685 else {
686 sig = $signr
687 sig_name = _signal_name($signr)
688 }
689 sinfo = $info
690 sig_code = $info->si_code
691 ka_addr = $ka
692 %( systemtap_v <= "2.1" %?
693 oldset_addr = @choose_defined($oldset, @choose_defined($set, 0))
694 regs = $regs
695 %)
696 }
697
698 %( systemtap_v <= "2.1" %?
699 /**
700 * probe signal.handle.return - Signal handler invocation completed
701 * (deprecated in SystemTap 2.1)
702 * @name: Name of the probe point
703 * @retstr: Return value as a string
704 */
705 probe signal.handle.return = kernel.function("handle_rt_signal64").return ?,
706 kernel.function("handle_rt_signal32").return ?,
707 kernel.function("handle_signal32").return !,
708 kernel.function("handle_signal").return ?
709 {
710 name = "handle"
711 retstr = return_str(1, $return)
712 }
713 %)
714
715
716 /**
717 * probe signal.do_action - Examining or changing a signal action
718 * @name: Name of the probe point
719 * @sig: The signal to be examined/changed
720 * @sig_name: A string representation of the signal
721 * @sigact_addr: The address of the new sigaction
722 * struct associated with the signal
723 * @oldsigact_addr: The address of the old sigaction
724 * struct associated with the signal
725 * @sa_handler: The new handler of the signal
726 * @sa_mask: The new mask of the signal
727 */
728 probe signal.do_action = kernel.function("do_sigaction")
729 {
730 name = "do_action"
731 sig = $sig
732 sig_name = _signal_name($sig)
733 sigact_addr = $act
734 oldsigact_addr = $oact
735 if(sigact_addr != 0)
736 {
737 sa_handler = $act->sa->sa_handler
738 sa_mask = __get_action_mask($act)
739 }
740 }
741
742 /**
743 * probe signal.do_action.return - Examining or changing a signal action completed
744 * @name: Name of the probe point
745 * @retstr: Return value as a string
746 */
747 probe signal.do_action.return = kernel.function("do_sigaction").return
748 {
749 name = "do_action"
750 retstr = return_str(1, $return)
751 }
752
753 function get_sigaction_mask:long(act:long)
754 {
755 return __get_action_mask(act)
756 }
757
758 @__private30 function __get_action_mask:long(act:long) %{ /* pure */
759 int i;
760 struct k_sigaction *act = (struct k_sigaction *)((uintptr_t)STAP_ARG_act);
761 sigset_t *sigset = &act->sa.sa_mask;
762 STAP_RETVALUE = kread(&(sigset->sig[0]));
763 for (i=1; i<_NSIG_WORDS; ++i) {
764 uint64_t part = kread(&(sigset->sig[i]));
765 STAP_RETVALUE |= part << (_NSIG_BPW*i);
766 }
767 CATCH_DEREF_FAULT();
768 %}
769
770
771 /**
772 * probe signal.procmask - Examining or changing blocked signals
773 * @name: Name of the probe point
774 * @how: Indicates how to change the blocked signals; possible values are
775 * SIG_BLOCK=0 (for blocking signals),
776 * SIG_UNBLOCK=1 (for unblocking signals), and
777 * SIG_SETMASK=2 for setting the signal mask.
778 * @sigset_addr: The address of the signal set (sigset_t)
779 * to be implemented
780 * @oldsigset_addr: The old address of the signal set
781 * (sigset_t)
782 * @sigset: The actual value to be set for sigset_t
783 * (correct?)
784 */
785 probe signal.procmask = kernel.function("sigprocmask")
786 {
787 name = "procmask"
788 how=$how
789 sigset_addr = $set
790 oldsigset_addr = $oldset
791 sigset = get_sigset($set)
792 }
793
794 function get_sigset:long(sigset:long) %{ /* pure */
795 int i;
796 sigset_t *sigset = (sigset_t *)((uintptr_t)STAP_ARG_sigset);
797 STAP_RETVALUE = kread(&(sigset->sig[0]));
798 for (i=1; i<_NSIG_WORDS; ++i) {
799 uint64_t part = kread(&(sigset->sig[i]));
800 STAP_RETVALUE |= part << (_NSIG_BPW*i);
801 }
802 CATCH_DEREF_FAULT();
803 %}
804
805 /**
806 * probe signal.procmask.return - Examining or changing blocked signals completed
807 * @name: Name of the probe point
808 * @retstr: Return value as a string
809 */
810 probe signal.procmask.return = kernel.function("sigprocmask").return
811 {
812 name = "procmask"
813 retstr = return_str(1, $return)
814 }
815
816
817 /**
818 * probe signal.flush - Flushing all pending signals for a task
819 * @name: Name of the probe point
820 * @task: The task handler of the process performing the flush
821 * @sig_pid: The PID of the process associated with the task
822 * performing the flush
823 * @pid_name: The name of the process associated with the task
824 * performing the flush
825 */
826 probe signal.flush = kernel.function("flush_signals")
827 {
828 name = "flush"
829 task = $t
830 sig_pid = $t->pid
831 pid_name = kernel_string($t->comm)
832 }
833
834 /**
835 * sfunction get_sa_flags - Returns the numeric value of sa_flags
836 *
837 * @act: address of the sigaction to query.
838 */
839 function get_sa_flags:long (act:long)
840 {
841 return @cast(act, "k_sigaction", "kernel")->sa->sa_flags
842 }
843
844 /**
845 * sfunction get_sa_handler - Returns the numeric value of sa_handler
846 *
847 * @act: address of the sigaction to query.
848 */
849 function get_sa_handler:long (act:long)
850 {
851 return @cast(act, "k_sigaction", "kernel")->sa->sa_handler
852 }
853
854 // sa_mask contains the set of signals to be blocked when executing the
855 // signal handler. This function returns a string, delimited by ",".
856 //
857 // struct task_struct {
858 // [...]
859 // struct signal_struct//signal;
860 // struct sighand_struct//sighand;
861 // [...]
862 // struct sighand_struct {
863 // atomic_t count;
864 // struct k_sigaction action[_NSIG];
865 // [...]
866 // struct k_sigaction {
867 // struct sigaction sa;
868 // };
869 //
870 // struct sigaction {
871 // [...]
872 // sigset_t sa_mask;
873 // };
874
875 /**
876 * sfunction sigset_mask_str - Returns the string representation of a sigset
877 *
878 * @mask: the sigset to convert to string.
879 */
880 function sigset_mask_str:string (mask:long) %{ /* pure */
881 int i, len;
882 char *str = STAP_RETVALUE, tmp[5];
883 str[0] = '\0';
884 for (i = 1; i < _NSIG; ++i, STAP_ARG_mask >>=1)
885 if (STAP_ARG_mask & 1) {
886 snprintf(tmp, sizeof(tmp), "%u,", i);
887 strlcat(str, tmp, MAXSTRINGLEN);
888 }
889 len = strlen(str);
890 if (len) str[len - 1] = '\0';
891 %}
892
893 // task_struct->blocked signal mask contains the set of signals that are
894 // currently blocked.
895 //
896 // struct task_struct {
897 // [...]
898 // sigset_t blocked, real_blocked;
899
900 /**
901 * sfunction is_sig_blocked - Returns 1 if the signal is currently blocked, or 0 if it is not
902 *
903 * @task: address of the task_struct to query.
904 * @sig: the signal number to test.
905 */
906 function is_sig_blocked:long (task:long, sig:long) %{ /* pure */
907 int i;
908 sigset_t blocked;
909 struct task_struct *p = (struct task_struct *)((uintptr_t)STAP_ARG_task);
910 for (i = 0; i < _NSIG_WORDS; ++i)
911 blocked.sig[i] = kread(&p->blocked.sig[i]);
912 STAP_RETVALUE = sigismember(&blocked, STAP_ARG_sig);
913 CATCH_DEREF_FAULT();
914 %}
915
916 /**
917 * sfunction sa_flags_str - Returns the string representation of sa_flags
918 *
919 * @sa_flags: the set of flags to convert to string.
920 */
921 function sa_flags_str:string (sa_flags:long) %{ /* pure */
922 int len;
923 char *str = STAP_RETVALUE;
924 str[0] = '\0';
925 if (STAP_ARG_sa_flags & 0x00000001u) strlcat(str, "NOCLDSTOP|", MAXSTRINGLEN);
926 if (STAP_ARG_sa_flags & 0x00000002u) strlcat(str, "NOCLDWAIT|", MAXSTRINGLEN);
927 if (STAP_ARG_sa_flags & 0x00000004u) strlcat(str, "SIGINFO|", MAXSTRINGLEN);
928 if (STAP_ARG_sa_flags & 0x08000000u) strlcat(str, "ONSTACK|", MAXSTRINGLEN);
929 if (STAP_ARG_sa_flags & 0x10000000u) strlcat(str, "RESTART|", MAXSTRINGLEN);
930 if (STAP_ARG_sa_flags & 0x40000000u) strlcat(str, "NODEFER|", MAXSTRINGLEN);
931 if (STAP_ARG_sa_flags & 0x80000000u) strlcat(str, "RESETHAND|", MAXSTRINGLEN);
932 if (STAP_ARG_sa_flags & 0x04000000) strlcat(str, "RESTORER|", MAXSTRINGLEN);
933 len = strlen(str);
934 if (len) str[len - 1] = '\0';
935 %}
936
937 /**
938 * sfunction sa_handler - Returns the string representation of an sa_handler
939 *
940 * @handler: the sa_handler to convert to string.
941 *
942 * Description: Returns the string representation of an sa_handler.
943 * If it is not SIG_DFL, SIG_IGN or SIG_ERR, it will return the address
944 * of the handler.
945 */
946 function sa_handler_str(handler) {
947 if (handler == 0) return "default"; /* SIG_DFL */
948 if (handler == 1) return "ignored"; /* SIG_IGN */
949 if (handler == -1) return "error"; /* SIG_ERR */
950 return sprintf("%p", handler); /* userspace address */
951 }
952
953 // Signals start from 1 not 0.
954
955 @__private30 global __sig[64]
956
957 probe init {
958 __sig[1] = "HUP"
959 __sig[2] = "INT"
960 __sig[3] = "QUIT"
961 __sig[4] = "ILL"
962 __sig[5] = "TRAP"
963 __sig[6] = "ABRT" /* or IOT */
964 __sig[7] = "BUS"
965 __sig[8] = "FPE"
966 __sig[9] = "KILL"
967 __sig[10] = "USR1"
968 __sig[11] = "SEGV"
969 __sig[12] = "USR2"
970 __sig[13] = "PIPE"
971 __sig[14] = "ALRM"
972 __sig[15] = "TERM"
973 __sig[16] = "STKFLT"
974 __sig[17] = "CHLD" /* or CLD */
975 __sig[18] = "CONT"
976 __sig[19] = "STOP"
977 __sig[20] = "TSTP"
978 __sig[21] = "TTIN"
979 __sig[22] = "TTOU"
980 __sig[23] = "URG"
981 __sig[24] = "XCPU"
982 __sig[25] = "XFSZ"
983 __sig[26] = "VTALRM"
984 __sig[27] = "PROF"
985 __sig[28] = "WINCH"
986 __sig[29] = "IO/POLL"
987 __sig[30] = "PWR"
988 __sig[31] = "SYS" /* or UNUSED */
989 __sig[32] = "RTMIN"
990 __sig[33] = "RTMIN+1"
991 __sig[34] = "RTMIN+2"
992 __sig[35] = "RTMIN+3"
993 __sig[36] = "RTMIN+4"
994 __sig[37] = "RTMIN+5"
995 __sig[38] = "RTMIN+6"
996 __sig[39] = "RTMIN+7"
997 __sig[40] = "RTMIN+8"
998 __sig[41] = "RTMIN+9"
999 __sig[42] = "RTMIN+10"
1000 __sig[43] = "RTMIN+11"
1001 __sig[44] = "RTMIN+12"
1002 __sig[45] = "RTMIN+13"
1003 __sig[46] = "RTMIN+14"
1004 __sig[47] = "RTMIN+15"
1005 __sig[48] = "RTMIN+16"
1006 __sig[49] = "RTMIN+17"
1007 __sig[50] = "RTMIN+18"
1008 __sig[51] = "RTMIN+19"
1009 __sig[52] = "RTMIN+20"
1010 __sig[53] = "RTMIN+21"
1011 __sig[54] = "RTMIN+22"
1012 __sig[55] = "RTMIN+23"
1013 __sig[56] = "RTMIN+24"
1014 __sig[57] = "RTMIN+25"
1015 __sig[58] = "RTMIN+26"
1016 __sig[59] = "RTMIN+27"
1017 __sig[60] = "RTMIN+28"
1018 __sig[61] = "RTMIN+29"
1019 __sig[62] = "RTMIN+30"
1020 __sig[63] = "RTMIN+31"
1021 __sig[64] = "RTMIN+32"
1022 }
1023
1024 /**
1025 * sfunction signal_str - Returns the string representation of a signal number
1026 *
1027 * @num: the signal number to convert to string.
1028 */
1029 function signal_str(num) {
1030 return __sig[num]
1031 }