Debian Codegraph @

tapset/linux/sysc_lseek.stp

raw
1 # lseek ______________________________________________________
2 # off_t sys_lseek(unsigned int fd, off_t offset, unsigned int whence)
3 # COMPAT_SYSCALL_DEFINE3(lseek, unsigned int, fd, compat_off_t, offset,
4 # unsigned int, whence)
5 # long sys32_lseek(unsigned int fd, int offset, unsigned int whence)
6 #
7
8 @define _SYSCALL_LSEEK_NAME
9 %(
10 name = "lseek"
11 %)
12
13 @define _SYSCALL_LSEEK_ARGSTR
14 %(
15 argstr = sprintf("%d, %d, %s", fildes, offset, whence_str)
16 %)
17
18 @define _SYSCALL_LSEEK_REGARGS
19 %(
20 fildes = int_arg(1)
21 offset = @__compat_task ? int_arg(2) : long_arg(2)
22 whence = uint_arg(3)
23 whence_str = _seek_whence_str(whence)
24 %)
25
26 @define _SYSCALL_LSEEK_REGARGS_STORE
27 %(
28 if (@probewrite(fildes))
29 set_int_arg(1, fildes)
30
31 if (@probewrite(offset)) {
32 if (@__compat_task)
33 set_int_arg(2, offset)
34 else
35 set_long_arg(2, offset)
36 }
37
38 if (@probewrite(whence))
39 set_uint_arg(3, whence)
40 %)
41
42 @define _SYSCALL_GATE
43 %(
44 %( arch == "s390" %?
45 // On s390x, older kernels used sys32_lseek_wrapper() as the
46 // lseek compat function. Since sys32_lseek_wrapper() was
47 // written in assembly language, we can't probe it. So, on
48 // those kernels, we'll probe sys_lseek().
49 %( kernel_v >= "3.10" %?
50 @__syscall_gate_compat_simple
51 %)
52 %:
53 @__syscall_gate_compat_simple
54 %)
55 %)
56
57 probe syscall.lseek = dw_syscall.lseek !, nd_syscall.lseek ? {}
58 probe syscall.lseek.return = dw_syscall.lseek.return !, nd_syscall.lseek.return ? {}
59
60 # dw_lseek _____________________________________________________
61
62 probe dw_syscall.lseek = __syscall.lseek ?,
63 %( arch == "powerpc" %?
64 kernel.function("ppc32_lseek").call ?,
65 %)
66 kernel.function("compat_sys_lseek").call ?,
67 kernel.function("sys32_lseek").call ?
68 {
69 @_SYSCALL_LSEEK_NAME
70 fildes = __int32($fd)
71 offset = @__compat_long($offset)
72 whence = @__compat_ulong(@choose_defined($whence, $origin))
73 whence_str = _seek_whence_str(whence)
74 @_SYSCALL_LSEEK_ARGSTR
75 }
76 probe __syscall.lseek = kernel.function("sys_lseek").call ?
77 {
78 @_SYSCALL_GATE
79 }
80 probe dw_syscall.lseek.return = __syscall.lseek.return ?,
81 %( arch == "powerpc" %?
82 kernel.function("ppc32_lseek").return ?,
83 %)
84 kernel.function("compat_sys_lseek").return ?,
85 kernel.function("sys32_lseek").return ?
86 {
87 @_SYSCALL_LSEEK_NAME
88 @SYSC_RETVALSTR($return)
89 }
90 probe __syscall.lseek.return = kernel.function("sys_lseek").return ?
91 {
92 @_SYSCALL_GATE
93 }
94
95 # nd_lseek _____________________________________________________
96
97 probe nd_syscall.lseek = nd1_syscall.lseek!, nd2_syscall.lseek!, tp_syscall.lseek
98 { }
99
100 probe nd1_syscall.lseek = __nd1_syscall.lseek ?,
101 %( arch == "powerpc" %?
102 kprobe.function("ppc32_lseek") ?,
103 %)
104 kprobe.function("compat_sys_lseek") ?,
105 kprobe.function("sys32_lseek") ?
106 {
107 @_SYSCALL_LSEEK_NAME
108 asmlinkage()
109 @_SYSCALL_LSEEK_REGARGS
110 @_SYSCALL_LSEEK_ARGSTR
111 }
112 probe __nd1_syscall.lseek = kprobe.function("sys_lseek") ?
113 {
114 @_SYSCALL_GATE
115 }
116
117 /* kernel 4.17+ */
118 probe nd2_syscall.lseek = kprobe.function(@arch_syscall_prefix "sys_lseek") ?
119 {
120 __set_syscall_pt_regs(pointer_arg(1))
121 @_SYSCALL_LSEEK_NAME
122 @_SYSCALL_LSEEK_REGARGS
123 @_SYSCALL_LSEEK_ARGSTR
124 },
125 {
126 %( @_IS_SREG_KERNEL %? @_SYSCALL_LSEEK_REGARGS_STORE %)
127 }
128
129 /* kernel 3.5+, but undesirable because it affects all syscalls */
130 probe tp_syscall.lseek = kernel.trace("sys_enter")
131 {
132 __set_syscall_pt_regs($regs)
133 @__syscall_compat_gate(@const("__NR_lseek"), @const("__NR_compat_lseek"))
134 @_SYSCALL_LSEEK_NAME
135 @_SYSCALL_LSEEK_REGARGS
136 @_SYSCALL_LSEEK_ARGSTR
137 },
138 {
139 %( @_IS_SREG_KERNEL %? @_SYSCALL_LSEEK_REGARGS_STORE %)
140 }
141
142 probe nd_syscall.lseek.return = nd1_syscall.lseek.return!, nd2_syscall.lseek.return!, tp_syscall.lseek.return
143 { }
144
145 probe nd1_syscall.lseek.return = __nd1_syscall.lseek.return ?,
146 %( arch == "powerpc" %?
147 kprobe.function("ppc32_lseek").return ?,
148 %)
149 kprobe.function("compat_sys_lseek").return ?,
150 kprobe.function("sys32_lseek").return ?
151 {
152 @_SYSCALL_LSEEK_NAME
153 @SYSC_RETVALSTR(returnval())
154 }
155 probe __nd1_syscall.lseek.return = kprobe.function("sys_lseek").return ?
156 {
157 @_SYSCALL_GATE
158 }
159
160 /* kernel 4.17+ */
161 probe nd2_syscall.lseek.return = kprobe.function(@arch_syscall_prefix "sys_lseek").return ?
162 {
163 @_SYSCALL_LSEEK_NAME
164 @SYSC_RETVALSTR(returnval())
165 }
166
167 /* kernel 3.5+, but undesirable because it affects all syscalls */
168 probe tp_syscall.lseek.return = kernel.trace("sys_exit")
169 {
170 __set_syscall_pt_regs($regs)
171 @__syscall_compat_gate(@const("__NR_lseek"), @const("__NR_compat_lseek"))
172 @_SYSCALL_LSEEK_NAME
173 @SYSC_RETVALSTR($ret)
174 }