Debian Codegraph @

tapset/linux/sysc_dup2.stp

raw
1 # dup2 _______________________________________________________
2 # long sys_dup2(unsigned int oldfd, unsigned int newfd)
3
4 @define _SYSCALL_DUP2_NAME
5 %(
6 name = "dup2"
7 %)
8
9 @define _SYSCALL_DUP2_ARGSTR
10 %(
11 argstr = sprintf("%d, %d", oldfd, newfd)
12 %)
13
14 @define _SYSCALL_DUP2_REGARGS
15 %(
16 oldfd = int_arg(1)
17 newfd = int_arg(2)
18 # The dup2 syscall doesn't have a 'flags' argument. But, the
19 # syscall.dup2 and syscall.dup3 probes used to be combined, so
20 # both probes need a 'flags' and 'flags_str' variable.
21 flags = 0
22 flags_str = "0x0"
23 %)
24
25 @define _SYSCALL_DUP2_REGARGS_STORE
26 %(
27 if (@probewrite(oldfd))
28 set_int_arg(1, oldfd)
29
30 if (@probewrite(newfd))
31 set_int_arg(2, newfd)
32 %)
33
34 probe syscall.dup2 = dw_syscall.dup2 !, nd_syscall.dup2 {}
35 probe syscall.dup2.return = dw_syscall.dup2.return !, nd_syscall.dup2.return {}
36
37 # dw_dup2 _____________________________________________________
38
39 probe dw_syscall.dup2 = kernel.function("sys_dup2").call
40 {
41 @_SYSCALL_DUP2_NAME
42 oldfd = __int32($oldfd)
43 newfd = __int32($newfd)
44 # The dup2 syscall doesn't have a 'flags' argument. But, the
45 # dw_syscall.dup2 and syscall.dup3 probes used to be combined, so
46 # both probes need a 'flags' and 'flags_str' variable.
47 flags = 0
48 flags_str = "0x0"
49 @_SYSCALL_DUP2_ARGSTR
50 }
51 probe dw_syscall.dup2.return = kernel.function("sys_dup2").return
52 {
53 @_SYSCALL_DUP2_NAME
54 @SYSC_RETVALSTR($return)
55 }
56
57 # nd_dup2 _____________________________________________________
58
59 probe nd_syscall.dup2 = nd1_syscall.dup2!, nd2_syscall.dup2!, tp_syscall.dup2
60 { }
61
62 probe nd1_syscall.dup2 = kprobe.function("sys_dup2")
63 {
64 @_SYSCALL_DUP2_NAME
65 asmlinkage()
66 @_SYSCALL_DUP2_REGARGS
67 @_SYSCALL_DUP2_ARGSTR
68 }
69
70 /* kernel 4.17+ */
71 probe nd2_syscall.dup2 = kprobe.function(@arch_syscall_prefix "sys_dup2") ?
72 {
73 __set_syscall_pt_regs(pointer_arg(1))
74 @_SYSCALL_DUP2_NAME
75 @_SYSCALL_DUP2_REGARGS
76 @_SYSCALL_DUP2_ARGSTR
77 },
78 {
79 %( @_IS_SREG_KERNEL %? @_SYSCALL_DUP2_REGARGS_STORE %)
80 }
81
82 /* kernel 3.5+, but undesirable because it affects all syscalls */
83 probe tp_syscall.dup2 = kernel.trace("sys_enter")
84 {
85 __set_syscall_pt_regs($regs)
86 @__syscall_compat_gate(@const("__NR_dup2"), @const("__NR_compat_dup2"))
87 @_SYSCALL_DUP2_NAME
88 @_SYSCALL_DUP2_REGARGS
89 @_SYSCALL_DUP2_ARGSTR
90 },
91 {
92 %( @_IS_SREG_KERNEL %? @_SYSCALL_DUP2_REGARGS_STORE %)
93 }
94
95 probe nd_syscall.dup2.return = nd1_syscall.dup2.return!, nd2_syscall.dup2.return!, tp_syscall.dup2.return
96 { }
97
98 probe nd1_syscall.dup2.return = kprobe.function("sys_dup2").return
99 {
100 @_SYSCALL_DUP2_NAME
101 @SYSC_RETVALSTR(returnval())
102 }
103
104 /* kernel 4.17+ */
105 probe nd2_syscall.dup2.return = kprobe.function(@arch_syscall_prefix "sys_dup2").return ?
106 {
107 @_SYSCALL_DUP2_NAME
108 @SYSC_RETVALSTR(returnval())
109 }
110
111 /* kernel 3.5+, but undesirable because it affects all syscalls */
112 probe tp_syscall.dup2.return = kernel.trace("sys_exit")
113 {
114 __set_syscall_pt_regs($regs)
115 @__syscall_compat_gate(@const("__NR_dup2"), @const("__NR_compat_dup2"))
116 @_SYSCALL_DUP2_NAME
117 @SYSC_RETVALSTR($ret)
118 }