File: sysc_stat.stp

package info (click to toggle)
systemtap 5.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 47,556 kB
  • sloc: cpp: 81,117; ansic: 54,933; xml: 49,795; exp: 43,595; sh: 11,526; python: 5,003; perl: 2,252; tcl: 1,312; makefile: 1,006; javascript: 149; lisp: 105; awk: 101; asm: 91; java: 70; sed: 16
file content (198 lines) | stat: -rw-r--r-- 6,535 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# stat _______________________________________________________
# long sys_stat(char __user * filename, struct __old_stat __user * statbuf)
# long sys32_stat64(char __user * filename, struct stat64 __user *statbuf)
# long sys_stat64(char __user * filename, struct stat64 __user * statbuf)
# long sys_oabi_stat64(char __user * filename, struct oldabi_stat64 __user * statbuf)
# long compat_sys_newstat(char __user * filename, struct compat_stat __user *statbuf)
# COMPAT_SYSCALL_DEFINE2(s390_stat64, const char __user *, filename, struct stat64_emu31 __user *, statbuf)
#

@define _SYSCALL_STAT_NAME
%(
	name = "stat"
%)

@define _SYSCALL_STAT_ARGSTR
%(
	argstr = sprintf("%s, %p", filename, buf_uaddr)
%)

@define _SYSCALL_STAT_REGARGS
%(
	filename_uaddr = pointer_arg(1)
	filename = user_string_quoted(filename_uaddr)
	filename_unquoted = user_string_nofault(pointer_arg(1))
	buf_uaddr = pointer_arg(2)
%)

@define _SYSCALL_STAT_REGARGS_STORE
%(
        if (@probewrite(filename_uaddr))
          set_pointer_arg(1, filename_uaddr)

	if (@probewrite(filename_unquoted))
	  set_user_string_arg(pointer_arg(1), filename_unquoted)

	if (@probewrite(buf_uaddr))
	  set_pointer_arg(2, buf_uaddr)
%)

probe syscall.stat = dw_syscall.stat !, nd_syscall.stat ? {}
probe syscall.stat.return = dw_syscall.stat.return !, nd_syscall.stat.return ? {}

# dw_stat _____________________________________________________

probe dw_syscall.stat = kernel.function("sys_stat").call ?,
                     kernel.function("sys_newstat").call ?,
                     kernel.function("sys32_stat64").call ?,
                     kernel.function("sys_stat64").call ?,
                     kernel.function("sys_oabi_stat64").call ?,
%( arch == "s390" %?
                     kernel.function("compat_sys_s390_stat64").call ?,
%)
%( arch == "x86_64" %?
                     kernel.function("compat_sys_x86_stat64").call ?,
%)
                     kernel.function("compat_sys_newstat").call ?
{
	@_SYSCALL_STAT_NAME
	filename_uaddr = $filename
	filename = user_string_quoted($filename)
	buf_uaddr = $statbuf
	@_SYSCALL_STAT_ARGSTR
}
probe dw_syscall.stat.return = kernel.function("sys_stat").return ?,
                            kernel.function("sys_newstat").return ?,
                            kernel.function("sys32_stat64").return ?,
                            kernel.function("sys_stat64").return ?,
                            kernel.function("sys_oabi_stat64").return ?,
%( arch == "s390" %?
                            kernel.function("compat_sys_s390_stat64").return ?,
%)
%( arch == "x86_64" %?
                            kernel.function("compat_sys_x86_stat64").return ?,
%)
                            kernel.function("compat_sys_newstat").return ?
{
	@_SYSCALL_STAT_NAME
	@SYSC_RETVALSTR($return)
}

# nd_stat _____________________________________________________

probe nd_syscall.stat = nd1_syscall.stat!, nd2_syscall.stat!, tp_syscall.stat
  { }

probe nd1_syscall.stat = kprobe.function("sys_stat") ?,
                         kprobe.function("sys_newstat") ?,
                         kprobe.function("sys32_stat64") ?,
                         kprobe.function("sys_stat64") ?,
                         kprobe.function("sys_oabi_stat64") ?,
%( arch == "s390" %?
                         kprobe.function("compat_sys_s390_stat64") ?,
%)
%( arch == "x86_64" %?
                         kprobe.function("compat_sys_x86_stat64") ?,
%)
                         kprobe.function("compat_sys_newstat") ?
{
	@_SYSCALL_STAT_NAME
	asmlinkage()
	@_SYSCALL_STAT_REGARGS
	@_SYSCALL_STAT_ARGSTR
}

/* kernel 4.17+ */
probe nd2_syscall.stat =
	kprobe.function(@arch_syscall_prefix "sys_stat") ?,
	kprobe.function(@arch_syscall_prefix "sys_newstat") ?,
	kprobe.function(@arch_syscall_prefix "compat_sys_newstat") ?,
	kprobe.function(@arch_syscall_prefix "compat_sys_x86_stat64") ?
{
	__set_syscall_pt_regs(pointer_arg(1))
	@_SYSCALL_STAT_NAME
	@_SYSCALL_STAT_REGARGS
	@_SYSCALL_STAT_ARGSTR
},
{
        %( @_IS_SREG_KERNEL %? @_SYSCALL_STAT_REGARGS_STORE %)
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.stat = __tp_syscall.stat,
                        __tp_syscall.stat64,
                        __tp_syscall.newstat
{
	__set_syscall_pt_regs($regs)
	@_SYSCALL_STAT_NAME
	@_SYSCALL_STAT_REGARGS
	@_SYSCALL_STAT_ARGSTR
},
{
        %( @_IS_SREG_KERNEL %? @_SYSCALL_STAT_REGARGS_STORE %)
}
probe __tp_syscall.stat = kernel.trace("sys_enter")
{
	@__syscall_compat_gate(@const("__NR_oldstat"), @const("__NR_compat_oldstat"))
}
probe __tp_syscall.stat64 = kernel.trace("sys_enter")
{
	@__syscall_compat_gate(@const("__NR_stat64"), @const("__NR_compat_stat64"))
}
probe __tp_syscall.newstat = kernel.trace("sys_enter")
{
	@__syscall_compat_gate(@const("__NR_stat"), @const("__NR_compat_stat"))
}

probe nd_syscall.stat.return = nd1_syscall.stat.return!, nd2_syscall.stat.return!, tp_syscall.stat.return
  { }

probe nd1_syscall.stat.return = kprobe.function("sys_stat").return ?,
	kprobe.function("sys_newstat").return ?,
	kprobe.function("sys32_stat64").return ?,
	kprobe.function("sys_stat64").return ?,
	kprobe.function("sys_oabi_stat64").return ?,
%( arch == "s390" %?
	kprobe.function("compat_sys_s390_stat64").return ?,
%)
%( arch == "x86_64" %?
	kprobe.function("compat_sys_x86_stat64").return ?,
%)
	kprobe.function("compat_sys_newstat").return ?
{
	@_SYSCALL_STAT_NAME
	@SYSC_RETVALSTR(returnval())
}

/* kernel 4.17+ */
probe nd2_syscall.stat.return =
	kprobe.function(@arch_syscall_prefix "sys_stat").return ?,
	kprobe.function(@arch_syscall_prefix "sys_newstat").return ?,
	kprobe.function(@arch_syscall_prefix "compat_sys_newstat").return ?,
	kprobe.function(@arch_syscall_prefix "compat_sys_x86_stat64").return
{
	@_SYSCALL_STAT_NAME
	@SYSC_RETVALSTR(returnval())
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.stat.return = __tp_syscall.stat.return,
                               __tp_syscall.stat64.return,
                               __tp_syscall.newstat.return
{
	__set_syscall_pt_regs($regs)
	@_SYSCALL_STAT_NAME
	@SYSC_RETVALSTR($ret)
}
probe __tp_syscall.stat.return = kernel.trace("sys_exit")
{
	@__syscall_compat_gate(@const("__NR_oldstat"), @const("__NR_compat_oldstat"))
}
probe __tp_syscall.stat64.return = kernel.trace("sys_exit")
{
	@__syscall_compat_gate(@const("__NR_stat64"), @const("__NR_compat_stat64"))
}
probe __tp_syscall.newstat.return = kernel.trace("sys_exit")
{
	@__syscall_compat_gate(@const("__NR_stat"), @const("__NR_compat_stat"))
}