File: sysc_mmap2.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 (222 lines) | stat: -rw-r--r-- 6,229 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
%( kernel_v >= "2.6.33" %?
# In newer kernels (2.6.33+), all the sys_mmap() variants are just
# wrappers around sys_mmap_pgoff(), which is in arch-generic code.
#
# long sys_mmap_pgoff(unsigned long addr, unsigned long len,
#		unsigned long prot, unsigned long flags,
#		unsigned long fd, unsigned long pgoff)

@define _SYSCALL_MMAP2_NAME
%(
	name = "mmap2"
%)

@define _SYSCALL_MMAP2_ARGSTR
%(
	argstr = sprintf("%p, %u, %s, %s, %d, %d", start, length,
	                 prot_str, flags_str, fd, pgoffset)
%)

@define _SYSCALL_MMAP2_REGARGS_STORE
%(
        if (@probewrite(start))
          set_ulong_arg(1, start)

	if (@probewrite(length))
	  set_ulong_arg(2, length)

	if (@probewrite(prot))
	  set_ulong_arg(3, prot)

	if (@probewrite(flags))
	  set_ulong_arg(4, flags)

	if (@probewrite(fd))
	  set_int_arg(5, fd)

	if (@probewrite(pgoffset))
	  set_ulong_arg(6, pgoffset)
%)

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

# dw_mmap2 _____________________________________________________

probe dw_syscall.mmap2 = kernel.function("sys_mmap_pgoff") ?
{
	@_SYSCALL_MMAP2_NAME
	start = $addr
	length = __ulong($len)
	prot = $prot
	prot_str = _mprotect_prot_str(prot)
	flags = $flags
	flags_str = _mmap_flags(flags)
	# Although the kernel gets an unsigned long fd, on the
	# user-side it is a signed int.  Fix this.
	fd = __int32($fd)
	# $pgoff is the number of pages. Convert this back into a
	# number of bytes.
	pgoffset = $pgoff * @const("PAGE_SIZE")
	@_SYSCALL_MMAP2_ARGSTR
}
probe dw_syscall.mmap2.return = kernel.function("sys_mmap_pgoff").return ?
{
        @_SYSCALL_MMAP2_NAME
        @SYSC_RETVALSTR2($return)
}

# nd_mmap2 _____________________________________________________

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

probe nd1_syscall.mmap2 = kprobe.function("sys_mmap_pgoff") ?
{
	@_SYSCALL_MMAP2_NAME
	asmlinkage()
	start = ulong_arg(1)
	length = ulong_arg(2)
	prot = ulong_arg(3)
	prot_str = _mprotect_prot_str(prot)
	flags = ulong_arg(4)
	flags_str = _mmap_flags(flags)
	# Although the kernel gets an unsigned long fd, on the
	# user-side it is a signed int.  Fix this.
	fd = int_arg(5)
	# $pgoff is the number of pages. Convert this back into a
	# number of bytes.
	pgoffset = ulong_arg(6) * @const("PAGE_SIZE")
	@_SYSCALL_MMAP2_ARGSTR
}

/* kernel 4.17+ */
probe nd2_syscall.mmap2 = __nd2_syscall.mmap, __nd2_syscall.mmap_pgoff
{
}
probe __nd2_syscall.mmap = kprobe.function(@arch_syscall_prefix "sys_mmap") ?
{
	__set_syscall_pt_regs(pointer_arg(1))
	@_SYSCALL_MMAP2_NAME
	start = ulong_arg(1)
	length = ulong_arg(2)
	prot = ulong_arg(3)
	prot_str = _mprotect_prot_str(prot)
	flags = ulong_arg(4)
	flags_str = _mmap_flags(flags)
	# Although the kernel gets an unsigned long fd, on the
	# user-side it is a signed int.  Fix this.
	fd = int_arg(5)
	# Here $pgoff is the number of bytes, no conversion needed
	pgoffset = ulong_arg(6)
	@_SYSCALL_MMAP2_ARGSTR
},
{
        %( @_IS_SREG_KERNEL %? @_SYSCALL_MMAP2_REGARGS_STORE %)
}
probe __nd2_syscall.mmap_pgoff = kprobe.function(@arch_syscall_prefix "sys_mmap_pgoff") ?
{
	__set_syscall_pt_regs(pointer_arg(1))
	@_SYSCALL_MMAP2_NAME
	start = ulong_arg(1)
	length = ulong_arg(2)
	prot = ulong_arg(3)
	prot_str = _mprotect_prot_str(prot)
	flags = ulong_arg(4)
	flags_str = _mmap_flags(flags)
	# Although the kernel gets an unsigned long fd, on the
	# user-side it is a signed int.  Fix this.
	fd = int_arg(5)
	# $pgoff is the number of pages. Convert this back into a
	# number of bytes.
	pgoffset = ulong_arg(6) * @const("PAGE_SIZE")
	@_SYSCALL_MMAP2_ARGSTR
},
{
        %( @_IS_SREG_KERNEL %? @_SYSCALL_MMAP2_REGARGS_STORE %)
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.mmap2 = __tp_syscall.mmap, __tp_syscall.mmap_pgoff
{
}
probe __tp_syscall.mmap = kernel.trace("sys_enter")
{
	__set_syscall_pt_regs($regs)
	@__syscall_gate(@const("__NR_mmap"))
	@_SYSCALL_MMAP2_NAME
	start = ulong_arg(1)
	length = ulong_arg(2)
	prot = ulong_arg(3)
	prot_str = _mprotect_prot_str(prot)
	flags = ulong_arg(4)
	flags_str = _mmap_flags(flags)
	# Although the kernel gets an unsigned long fd, on the
	# user-side it is a signed int.  Fix this.
	fd = int_arg(5)
	# Here $pgoff is the number of bytes, no conversion needed
	pgoffset = ulong_arg(6)
	@_SYSCALL_MMAP2_ARGSTR
},
{
        %( @_IS_SREG_KERNEL %? @_SYSCALL_MMAP2_REGARGS_STORE %)
}
probe __tp_syscall.mmap_pgoff = kernel.trace("sys_enter")
{
	__set_syscall_pt_regs($regs)
	@__syscall_compat_gate(@const("__NR_mmap2"), @const("__NR_compat_mmap2"))
	@_SYSCALL_MMAP2_NAME
	start = ulong_arg(1)
	length = ulong_arg(2)
	prot = ulong_arg(3)
	prot_str = _mprotect_prot_str(prot)
	flags = ulong_arg(4)
	flags_str = _mmap_flags(flags)
	# Although the kernel gets an unsigned long fd, on the
	# user-side it is a signed int.  Fix this.
	fd = int_arg(5)
	# $pgoff is the number of pages. Convert this back into a
	# number of bytes.
	pgoffset = ulong_arg(6) * @const("PAGE_SIZE")
	@_SYSCALL_MMAP2_ARGSTR
},
{
        %( @_IS_SREG_KERNEL %? @_SYSCALL_MMAP2_REGARGS_STORE %)
}

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

probe nd1_syscall.mmap2.return = kprobe.function("sys_mmap_pgoff").return ?
{
        @_SYSCALL_MMAP2_NAME
        @SYSC_RETVALSTR2(returnval())
}

/* kernel 4.17+ */
probe nd2_syscall.mmap2.return = kprobe.function(@arch_syscall_prefix "sys_mmap").return ?,
	kprobe.function(@arch_syscall_prefix "sys_mmap_pgoff").return ?
{
	@_SYSCALL_MMAP2_NAME
	@SYSC_RETVALSTR2(returnval())
}
 
/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.mmap2.return = __tp_syscall.mmap.return, __tp_syscall.mmap_pgoff.return
{
}
probe __tp_syscall.mmap.return = kernel.trace("sys_exit")
{
	__set_syscall_pt_regs($regs)
	@__syscall_gate(@const("__NR_mmap"))
	@_SYSCALL_MMAP2_NAME
	@SYSC_RETVALSTR2($ret)
}
probe __tp_syscall.mmap_pgoff.return = kernel.trace("sys_exit")
{
	__set_syscall_pt_regs($regs)
	@__syscall_compat_gate(@const("__NR_mmap2"), @const("__NR_compat_mmap2"))
	@_SYSCALL_MMAP2_NAME
	@SYSC_RETVALSTR2($ret)
}
%)