Use the memory pool instead of kmalloc
[lttng-modules.git] / instrumentation / syscalls / headers / syscalls_pointers_override.h
CommitLineData
e42e81fd
MD
1#ifndef CREATE_SYSCALL_TABLE
2
769ad370
MD
3#define OVERRIDE_32_execve
4#define OVERRIDE_64_execve
cb3ef14c 5SC_LTTNG_TRACEPOINT_EVENT(execve,
e17f92ba
MD
6 TP_PROTO(sc_exit(long ret,) const char *filename, char *const *argv, char *const *envp),
7 TP_ARGS(sc_exit(ret,) filename, argv, envp),
57ede728
MD
8 TP_FIELDS(sc_exit(ctf_integer(long, ret, ret))
9 sc_in(ctf_user_string(filename, filename))
10 sc_in(ctf_integer_hex(char *const *, argv, argv))
11 sc_in(ctf_integer_hex(char *const *, envp, envp))
12 )
e42e81fd
MD
13)
14
769ad370
MD
15#define OVERRIDE_32_clone
16#define OVERRIDE_64_clone
cb3ef14c 17SC_LTTNG_TRACEPOINT_EVENT(clone,
e17f92ba 18 TP_PROTO(sc_exit(long ret,) unsigned long clone_flags, unsigned long newsp,
ba21566b 19 void __user *parent_tid,
b5aa4b6a 20 void __user *child_tid),
e17f92ba 21 TP_ARGS(sc_exit(ret,) clone_flags, newsp, parent_tid, child_tid),
57ede728
MD
22 TP_FIELDS(
23 sc_exit(ctf_integer(long, ret, ret))
24 sc_in(ctf_integer_hex(unsigned long, clone_flags, clone_flags))
25 sc_in(ctf_integer_hex(unsigned long, newsp, newsp))
26 sc_in(ctf_integer_hex(void *, parent_tid, parent_tid))
27 sc_in(ctf_integer_hex(void *, child_tid, child_tid))
28 )
ba21566b
MD
29)
30
b5aa4b6a 31/* present in 32, missing in 64 due to old kernel headers */
644d6e9c
MD
32#define OVERRIDE_32_getcpu
33#define OVERRIDE_64_getcpu
cb3ef14c 34SC_LTTNG_TRACEPOINT_EVENT(getcpu,
e17f92ba
MD
35 TP_PROTO(sc_exit(long ret,) unsigned __user *cpup, unsigned __user *nodep, void *tcache),
36 TP_ARGS(sc_exit(ret,) cpup, nodep, tcache),
57ede728
MD
37 TP_FIELDS(
38 sc_exit(ctf_integer(long, ret, ret))
39 sc_out(ctf_integer_hex(unsigned *, cpup, cpup))
40 sc_out(ctf_integer_hex(unsigned *, nodep, nodep))
41 sc_inout(ctf_integer_hex(void *, tcache, tcache))
42 )
b5aa4b6a
MD
43)
44
af44bd3a
MD
45#define OVERRIDE_32_pipe2
46#define OVERRIDE_64_pipe2
cb3ef14c 47SC_LTTNG_TRACEPOINT_EVENT(pipe2,
af44bd3a
MD
48 TP_PROTO(sc_exit(long ret,) int * fildes, int flags),
49 TP_ARGS(sc_exit(ret,) fildes, flags),
57ede728
MD
50 TP_FIELDS(sc_exit(ctf_integer(long, ret, ret))
51 sc_out(ctf_user_array(int, fildes, fildes, 2))
52 sc_in(ctf_integer(int, flags, flags))
53 )
af44bd3a
MD
54)
55
29751f7c
JD
56#define LTTNG_SYSCALL_SELECT_locvar \
57 unsigned long *fds_in, *fds_out, *fds_ex; \
58 unsigned long nr_bytes, nr_ulong; \
59 uint8_t overflow;
60
61#define LTTNG_SYSCALL_SELECT_code_pre \
62 sc_inout( \
63 { \
64 int err; \
65 unsigned int n_in_bytes; \
66 \
67 tp_locvar->fds_in = NULL; \
68 tp_locvar->fds_out = NULL; \
69 tp_locvar->fds_ex = NULL; \
70 tp_locvar->overflow = 0; \
71 \
72 sc_out( \
73 if (ret <= 0) \
74 goto error; \
75 ) \
76 \
77 if (n <= 0) \
78 goto error; \
79 \
80 /* On error or bogus input, don't copy anything. */ \
81 if (n >__FD_SETSIZE) \
82 goto error; \
83 \
84 n_in_bytes = DIV_ROUND_UP((unsigned int) n, BITS_PER_BYTE); \
85 \
86 /* \
87 * Limit atomic memory allocation to one page, since n \
88 * is limited to 1024 and the smallest page size on Linux \
89 * is 4k, this should not happen, don't try to make it work. \
90 */ \
91 if (n_in_bytes > PAGE_SIZE) { \
92 WARN_ON_ONCE(1); \
93 /* Inform the user that we did not output everything. */ \
94 tp_locvar->overflow = 1; \
95 goto error; \
96 } else { \
97 tp_locvar->nr_bytes = n_in_bytes; \
98 tp_locvar->nr_ulong = DIV_ROUND_UP(n_in_bytes, \
99 sizeof(unsigned long)); \
100 } \
101 \
102 if (inp) { \
ec85ce1d
JD
103 tp_locvar->fds_in = lttng_tp_mempool_alloc( \
104 tp_locvar->nr_ulong * sizeof(unsigned long)); \
29751f7c
JD
105 if (!tp_locvar->fds_in) \
106 goto error; \
107 \
108 err = lib_ring_buffer_copy_from_user_check_nofault( \
109 tp_locvar->fds_in, inp, \
110 tp_locvar->nr_ulong * sizeof(unsigned long)); \
111 if (err != 0) \
112 goto error; \
113 } \
114 if (outp) { \
ec85ce1d
JD
115 tp_locvar->fds_out = lttng_tp_mempool_alloc( \
116 tp_locvar->nr_ulong * sizeof(unsigned long)); \
29751f7c
JD
117 if (!tp_locvar->fds_out) \
118 goto error; \
119 \
120 err = lib_ring_buffer_copy_from_user_check_nofault( \
121 tp_locvar->fds_out, outp, \
122 tp_locvar->nr_ulong * sizeof(unsigned long)); \
123 if (err != 0) \
124 goto error; \
125 } \
126 if (exp) { \
ec85ce1d
JD
127 tp_locvar->fds_ex = lttng_tp_mempool_alloc( \
128 tp_locvar->nr_ulong * sizeof(unsigned long)); \
29751f7c
JD
129 if (!tp_locvar->fds_ex) \
130 goto error; \
131 \
132 err = lib_ring_buffer_copy_from_user_check_nofault( \
133 tp_locvar->fds_ex, exp, \
134 tp_locvar->nr_ulong * sizeof(unsigned long)); \
135 if (err != 0) \
136 goto error; \
137 } \
138 goto end; \
139 \
140error: \
141 tp_locvar->nr_bytes = 0; \
142 tp_locvar->nr_ulong = 0; \
143end: ; /* Label at end of compound statement. */ \
144 } \
145 )
146
147#define LTTNG_SYSCALL_SELECT_fds_field_LE(name, input) \
148 ctf_custom_field( \
149 ctf_custom_type( \
150 .atype = atype_sequence, \
151 .u.sequence.length_type = __type_integer( \
152 uint8_t, 0, 0, 0, __BYTE_ORDER, 10, none), \
153 .u.sequence.elem_type = __type_integer(uint8_t, 0, 0, 0, \
154 __BYTE_ORDER, 16, none), \
155 ), \
156 name, \
157 ctf_custom_code( \
158 unsigned int src; \
159 unsigned int nr_bytes_out = 0; \
160 \
161 if (input) { \
162 ctf_integer_type(uint8_t, tp_locvar->nr_bytes) \
163 ctf_align(uint8_t) \
164 } else { \
165 ctf_integer_type(uint8_t, 0) \
166 ctf_align(uint8_t) \
167 goto skip_##name; \
168 } \
169 \
170 for (src = 0; src < tp_locvar->nr_ulong; src++) { \
171 int dst; \
172 for (dst = 0; dst < sizeof(long); dst++) { \
173 if (nr_bytes_out++ >= tp_locvar->nr_bytes) { \
174 goto skip_##name; \
175 } \
176 ctf_user_integer_type(uint8_t, \
177 ((uint8_t __user *) (input->fds_bits + src))[dst]); \
178 } \
179 } \
180 skip_##name: ; \
181 ) \
182 )
183
184#define LTTNG_SYSCALL_SELECT_fds_field_BE(name, input) \
185 ctf_custom_field( \
186 ctf_custom_type( \
187 .atype = atype_sequence, \
188 .u.sequence.length_type = __type_integer( \
189 uint8_t, 0, 0, 0, __BYTE_ORDER, 10, none), \
190 .u.sequence.elem_type = __type_integer(uint8_t, 0, 0, 0, \
191 __BYTE_ORDER, 16, none), \
192 ), \
193 name, \
194 ctf_custom_code( \
195 unsigned int src, nr_bytes_out = 0; \
196 \
197 if (input) { \
198 ctf_integer_type(uint8_t, tp_locvar->nr_bytes) \
199 ctf_align(uint8_t) \
200 } else { \
201 ctf_integer_type(uint8_t, 0) \
202 ctf_align(uint8_t) \
203 goto skip_##name; \
204 } \
205 \
206 for (src = 0; src < tp_locvar->nr_ulong; src++) { \
207 int dst; \
208 for (dst = sizeof(long); dst >= 0; dst--) { \
209 if (nr_bytes_out++ >= tp_locvar->nr_bytes) { \
210 goto skip_##name; \
211 } \
212 ctf_user_integer_type(uint8_t, \
213 ((uint8_t __user *) (input->fds_bits + src))[dst]); \
214 } \
215 } \
216 skip_##name: ; \
217 ) \
218 )
219
220#define LTTNG_SYSCALL_SELECT_code_post \
ec85ce1d
JD
221 lttng_tp_mempool_free(tp_locvar->fds_in); \
222 lttng_tp_mempool_free(tp_locvar->fds_out); \
223 lttng_tp_mempool_free(tp_locvar->fds_ex);
29751f7c 224
a6370148 225#if defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM)
29751f7c
JD
226#define OVERRIDE_32_select
227#define OVERRIDE_64_select
228SC_LTTNG_TRACEPOINT_EVENT_CODE(select,
229 TP_PROTO(sc_exit(long ret,) int n, fd_set __user *inp, fd_set __user *outp,
230 fd_set __user *exp, struct timeval *tvp),
231 TP_ARGS(sc_exit(ret,) n, inp, outp, exp, tvp),
232 TP_locvar(
233 LTTNG_SYSCALL_SELECT_locvar
234 ),
235 TP_code_pre(
236 LTTNG_SYSCALL_SELECT_code_pre
237 ),
238 TP_FIELDS(
239 sc_exit(ctf_integer(long, ret, ret))
240 sc_in(ctf_integer(int, n, n))
241 sc_inout(ctf_integer(uint8_t, overflow, tp_locvar->overflow))
242 sc_inout(ctf_integer(struct timeval *, tvp, tvp))
243
244 sc_inout(
245#if (__BYTE_ORDER == __LITTLE_ENDIAN)
246 LTTNG_SYSCALL_SELECT_fds_field_LE(readfds, inp)
247 LTTNG_SYSCALL_SELECT_fds_field_LE(writefds, outp)
248 LTTNG_SYSCALL_SELECT_fds_field_LE(exceptfds, exp)
249#else
250 LTTNG_SYSCALL_SELECT_fds_field_BE(readfds, inp)
251 LTTNG_SYSCALL_SELECT_fds_field_BE(writefds, outp)
252 LTTNG_SYSCALL_SELECT_fds_field_BE(exceptfds, exp)
253#endif
254 )
255 ),
256 TP_code_post(
257 LTTNG_SYSCALL_SELECT_code_post
258 )
259)
639655f9 260#endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM) */
29751f7c
JD
261
262#if defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64) || defined(CONFIG_ARM)
263#define OVERRIDE_32_pselect6
264#define OVERRIDE_64_pselect6
265SC_LTTNG_TRACEPOINT_EVENT_CODE(pselect6,
266 TP_PROTO(sc_exit(long ret,) int n, fd_set __user * inp, fd_set __user * outp,
267 fd_set __user * exp, struct timeval __user * tvp, void __user * sig),
268 TP_ARGS(sc_exit(ret,) n, inp, outp, exp, tvp, sig),
269 TP_locvar(
270 LTTNG_SYSCALL_SELECT_locvar
271 ),
272 TP_code_pre(
273 LTTNG_SYSCALL_SELECT_code_pre
274 ),
275 TP_FIELDS(
276 sc_exit(ctf_integer(long, ret, ret))
277 sc_in(ctf_integer(int, n, n))
278 sc_inout(ctf_integer(uint8_t, overflow, tp_locvar->overflow))
279 sc_inout(ctf_integer(struct timeval *, tvp, tvp))
280 sc_in(ctf_integer_hex(void *, sig, sig))
281
282 sc_inout(
283#if (__BYTE_ORDER == __LITTLE_ENDIAN)
284 LTTNG_SYSCALL_SELECT_fds_field_LE(readfds, inp)
285 LTTNG_SYSCALL_SELECT_fds_field_LE(writefds, outp)
286 LTTNG_SYSCALL_SELECT_fds_field_LE(exceptfds, exp)
287#else
288 LTTNG_SYSCALL_SELECT_fds_field_BE(readfds, inp)
289 LTTNG_SYSCALL_SELECT_fds_field_BE(writefds, outp)
290 LTTNG_SYSCALL_SELECT_fds_field_BE(exceptfds, exp)
291#endif
292 )
293 ),
294 TP_code_post(
295 LTTNG_SYSCALL_SELECT_code_post
296 )
297)
298#endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64) || defined(CONFIG_ARM) */
299
6a2ecd2e
JD
300#ifndef ONCE_LTTNG_TRACE_POLL_H
301#define ONCE_LTTNG_TRACE_POLL_H
302
303#define LTTNG_POLL_NRFLAGS (POLLNVAL + 1)
304#define POLL_FLAGS_PADDING_SIZE (sizeof(uint8_t) * BITS_PER_BYTE) - \
305 ilog2(LTTNG_POLL_NRFLAGS - 1)
306
307/*
308 * Only extract the values specified by iBCS2 for now.
309 */
310static struct lttng_event_field lttng_pollfd_flag_fields[] = {
311 [ilog2(POLLIN)] = {
312 .name = "POLLIN",
313 .type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
314 },
315 [ilog2(POLLPRI)] = {
316 .name = "POLLPRI",
317 .type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
318 },
319 [ilog2(POLLOUT)] = {
320 .name = "POLLOUT",
321 .type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
322 },
323 [ilog2(POLLERR)] = {
324 .name = "POLLERR",
325 .type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
326 },
327 [ilog2(POLLHUP)] = {
328 .name = "POLLHUP",
329 .type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
330 },
331 [ilog2(POLLNVAL)] = {
332 .name = "POLLNVAL",
333 .type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
334 },
335 [ilog2(LTTNG_POLL_NRFLAGS)] = {
336 .name = "padding",
337 .type = __type_integer(int, POLL_FLAGS_PADDING_SIZE, 1, 0,
338 __LITTLE_ENDIAN, 10, none),
339 },
340};
341
342static struct lttng_event_field lttng_pollfd_fields[] = {
343 [0] = {
344 .name = "fd",
345 .type = __type_integer(int, 0, 0, 0, __BYTE_ORDER, 10, none),
346 },
347 [1] = {
348 .name = "raw_events",
349 .type = __type_integer(short, 0, 0, 0, __BYTE_ORDER, 16, none),
350 },
351 [2] = {
352 .name = "events",
353 .type = {
354 .atype = atype_struct,
355 .u._struct.nr_fields = ARRAY_SIZE(lttng_pollfd_flag_fields),
356 .u._struct.fields = lttng_pollfd_flag_fields,
357 }
358 },
359};
360
361static struct lttng_type lttng_pollfd_elem = {
362 .atype = atype_struct,
363 .u._struct.nr_fields = ARRAY_SIZE(lttng_pollfd_fields),
364 .u._struct.fields = lttng_pollfd_fields,
365};
366#endif /* ONCE_LTTNG_TRACE_POLL_H */
367
368#define LTTNG_SYSCALL_POLL_locvar \
369 unsigned int fds_length, fds_max_len, alloc_fds; \
370 struct pollfd *fds; \
371 uint8_t overflow;
372
373#define LTTNG_SYSCALL_POLL_code_pre \
374 BUILD_BUG_ON(((ARRAY_SIZE(lttng_pollfd_flag_fields) - 1) + \
375 POLL_FLAGS_PADDING_SIZE) != \
376 sizeof(uint8_t) * BITS_PER_BYTE); \
377 tp_locvar->fds = NULL; \
378 tp_locvar->overflow = 0; \
379 \
380 sc_in( \
381 if (nfds > PAGE_SIZE / sizeof(struct pollfd)) { \
382 tp_locvar->fds_length = PAGE_SIZE / sizeof(struct pollfd); \
383 tp_locvar->fds_max_len = PAGE_SIZE / sizeof(struct pollfd); \
384 tp_locvar->overflow = 1; \
385 } else { \
386 tp_locvar->fds_length = nfds; \
387 tp_locvar->fds_max_len = nfds; \
388 } \
389 tp_locvar->alloc_fds = tp_locvar->fds_length * sizeof(struct pollfd); \
390 ) \
391 /* \
392 * On exit, the number of active FDs is determined by ret, \
393 * nfds stays the same as the entry, but we only want to \
394 * output the FDs that are relevant. \
395 */ \
396 sc_out( \
397 if (ret <= 0 || ret > nfds) \
398 goto error; \
399 \
400 if (nfds > PAGE_SIZE / sizeof(struct pollfd)) { \
401 tp_locvar->fds_length = PAGE_SIZE / sizeof(struct pollfd); \
402 tp_locvar->fds_max_len = PAGE_SIZE / sizeof(struct pollfd); \
403 tp_locvar->overflow = 1; \
404 } else { \
405 tp_locvar->fds_length = ret; \
406 tp_locvar->fds_max_len = nfds; \
407 } \
408 tp_locvar->alloc_fds = tp_locvar->fds_max_len * sizeof(struct pollfd); \
409 ) \
410 { \
411 int err; \
412 \
ec85ce1d 413 tp_locvar->fds = lttng_tp_mempool_alloc(tp_locvar->alloc_fds); \
6a2ecd2e
JD
414 if (!tp_locvar->fds) \
415 goto error; \
416 err = lib_ring_buffer_copy_from_user_check_nofault( \
41a3cca2 417 tp_locvar->fds, ufds, tp_locvar->alloc_fds); \
6a2ecd2e
JD
418 if (err != 0) \
419 goto error; \
420 } \
421 goto end; \
422 \
423error: \
424 tp_locvar->fds_length = 0; \
425 tp_locvar->fds_max_len = 0; \
426end: \
427 ;
428
429#define LTTNG_SYSCALL_POLL_fds_field \
430 sc_in( \
431 ctf_custom_field( \
432 ctf_custom_type( \
433 .atype = atype_sequence_compound, \
434 .u.sequence_compound.length_name = "fds_length", \
435 .u.sequence_compound.elem_type = &lttng_pollfd_elem, \
436 ), \
437 fds, \
438 ctf_custom_code( \
439 uint32_t i; \
440 \
441 ctf_align(int) /* Align on largest field in struct. */ \
442 for (i = 0; i < tp_locvar->fds_length; i++) { \
443 ctf_integer_type(int, tp_locvar->fds[i].fd) \
444 ctf_integer_type(short, tp_locvar->fds[i].events) \
445 ctf_integer_bitfield_type(uint8_t, \
446 (uint8_t) tp_locvar->fds[i].events) \
447 } \
448 ) \
449 ) \
450 ) \
451 sc_out( \
452 ctf_custom_field( \
453 ctf_custom_type( \
454 .atype = atype_sequence_compound, \
455 .u.sequence_compound.length_name = "fds_length", \
456 .u.sequence_compound.elem_type = &lttng_pollfd_elem, \
457 ), \
458 fds, \
459 ctf_custom_code( \
460 unsigned int i, nr = 0; \
461 \
462 ctf_align(int) /* Align on largest field in struct. */ \
463 /* \
464 * Iterate over the complete array, but only output \
465 * "ret" active FDs. \
466 */ \
467 for (i = 0; i < tp_locvar->fds_max_len; i++) { \
468 if (!tp_locvar->fds[i].revents) \
469 continue; \
470 if (nr++ >= tp_locvar->fds_length) \
471 break; \
472 ctf_integer_type(int, tp_locvar->fds[i].fd) \
473 ctf_integer_type(short, tp_locvar->fds[i].revents) \
474 ctf_integer_bitfield_type(uint8_t, \
475 (uint8_t) tp_locvar->fds[i].revents) \
476 } \
477 /* \
478 * If there is a discrepancy between ret and the \
479 * content of revents (e.g. caused by userspace corrupting \
480 * the array from a concurrent thread), we have to output \
481 * zeros to keep the trace readable. \
482 */ \
483 for (i = nr; i < tp_locvar->fds_length; i++) { \
484 ctf_integer_type(int, 0) \
485 ctf_integer_type(short, 0) \
486 ctf_integer_bitfield_type(uint8_t, 0) \
487 } \
488 ) \
489 ) \
490 )
491
492#define LTTNG_SYSCALL_POLL_code_post \
ec85ce1d 493 lttng_tp_mempool_free(tp_locvar->fds);
6a2ecd2e 494
a6370148 495#if defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM)
6a2ecd2e
JD
496#define OVERRIDE_32_poll
497#define OVERRIDE_64_poll
498SC_LTTNG_TRACEPOINT_EVENT_CODE(poll,
499 TP_PROTO(sc_exit(long ret,) struct pollfd __user * ufds,
500 unsigned int nfds, int timeout_msecs),
501 TP_ARGS(sc_exit(ret,) ufds, nfds, timeout_msecs),
502 TP_locvar(
503 LTTNG_SYSCALL_POLL_locvar
504 ),
505 TP_code_pre(
506 LTTNG_SYSCALL_POLL_code_pre
507 ),
508 TP_FIELDS(
509 sc_exit(ctf_integer(long, ret, ret))
510 sc_in(ctf_integer(int, timeout_msecs, timeout_msecs))
511 sc_inout(ctf_integer(unsigned int, nfds, nfds))
512 sc_inout(ctf_integer(unsigned int, fds_length, tp_locvar->fds_length))
513 sc_in(ctf_integer(uint8_t, overflow, tp_locvar->overflow))
514 LTTNG_SYSCALL_POLL_fds_field
515 ),
516 TP_code_post(
517 LTTNG_SYSCALL_POLL_code_post
518 )
519)
639655f9 520#endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM) */
6a2ecd2e
JD
521
522#if defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64) || defined(CONFIG_ARM)
523#define OVERRIDE_32_ppoll
524#define OVERRIDE_64_ppoll
525SC_LTTNG_TRACEPOINT_EVENT_CODE(ppoll,
526 TP_PROTO(sc_exit(long ret,) struct pollfd __user * ufds,
527 unsigned int nfds, struct timespec * tsp, const sigset_t * sigmask, size_t sigsetsize),
528 TP_ARGS(sc_exit(ret,) ufds, nfds, tsp, sigmask, sigsetsize),
529 TP_locvar(
530 LTTNG_SYSCALL_POLL_locvar
531 ),
532 TP_code_pre(
533 LTTNG_SYSCALL_POLL_code_pre
534 ),
535 TP_FIELDS(
536 sc_exit(ctf_integer(long, ret, ret))
537 sc_in(ctf_integer(struct timespec *, tsp, tsp))
538 sc_in(ctf_integer(const sigset_t *, sigmask, sigmask))
539 sc_in(ctf_integer(size_t, sigsetsize, sigsetsize))
540 sc_inout(ctf_integer(unsigned int, nfds, nfds))
541 sc_inout(ctf_integer(unsigned int, fds_length, tp_locvar->fds_length))
542 sc_inout(ctf_integer(uint8_t, overflow, tp_locvar->overflow))
543 LTTNG_SYSCALL_POLL_fds_field
544 ),
545 TP_code_post(
546 LTTNG_SYSCALL_POLL_code_post
547 )
548)
549#endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64) || defined(CONFIG_ARM) */
550
45e0ded1
JD
551#include <linux/eventpoll.h>
552
553SC_LTTNG_TRACEPOINT_ENUM(lttng_epoll_op,
554 TP_ENUM_VALUES(
555 ctf_enum_value("EPOLL_CTL_ADD", EPOLL_CTL_ADD)
556 ctf_enum_value("EPOLL_CTL_DEL", EPOLL_CTL_DEL)
557 ctf_enum_value("EPOLL_CTL_MOD", EPOLL_CTL_MOD)
558 )
559)
560
561#ifndef ONCE_LTTNG_TRACE_EPOLL_CTL_H
562#define ONCE_LTTNG_TRACE_EPOLL_CTL_H
563
564#define LTTNG_EPOLL_NRFLAGS (POLLHUP + 1)
565#define EPOLL_FLAGS_PADDING_SIZE (sizeof(uint8_t) * BITS_PER_BYTE) - \
566 ilog2(LTTNG_EPOLL_NRFLAGS - 1)
567
568/*
569 * Only extract the values specified by iBCS2 for now.
570 */
571static struct lttng_event_field lttng_epoll_ctl_events_fields[] = {
572 /* 0x0001 */
573 [ilog2(POLLIN)] = {
574 .name = "EPOLLIN",
575 .type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
576 },
577 /* 0x0002 */
578 [ilog2(POLLPRI)] = {
579 .name = "EPOLLPRI",
580 .type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
581 },
582 /* 0x0004 */
583 [ilog2(POLLOUT)] = {
584 .name = "EPOLLOUT",
585 .type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
586 },
587 /* 0x0008 */
588 [ilog2(POLLERR)] = {
589 .name = "EPOLLERR",
590 .type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
591 },
592 /* 0x0010 */
593 [ilog2(POLLHUP)] = {
594 .name = "EPOLLHUP",
595 .type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
596 },
597 [ilog2(LTTNG_EPOLL_NRFLAGS)] = {
598 .name = "padding",
599 .type = __type_integer(int, EPOLL_FLAGS_PADDING_SIZE, 1, 0,
600 __LITTLE_ENDIAN, 10, none),
601 },
602
603};
604
605static struct lttng_event_field lttng_epoll_data_fields[] = {
606 [0] = {
607 .name = "u64",
608 .type = __type_integer(uint64_t, 0, 0, 0, __BYTE_ORDER, 16, none),
609 },
610 [1] = {
611 .name = "fd",
612 .type = __type_integer(int, 0, 0, 0, __BYTE_ORDER, 10, none),
613 },
614};
615
616static struct lttng_event_field epoll_ctl_fields[] = {
617 [0] = {
618 .name = "data_union",
619 .type = {
620 .atype = atype_struct,
621 .u._struct.nr_fields = ARRAY_SIZE(lttng_epoll_data_fields),
622 .u._struct.fields = lttng_epoll_data_fields,
623 }
624 },
625 [1] = {
626 .name = "raw_events",
627 .type = __type_integer(uint32_t, 0, 0, 0, __BYTE_ORDER, 16, none),
628 },
629 [2] = {
630 .name = "events",
631 .type = {
632 .atype = atype_struct,
633 .u._struct.nr_fields = ARRAY_SIZE(lttng_epoll_ctl_events_fields),
634 .u._struct.fields = lttng_epoll_ctl_events_fields,
635 }
636 },
637};
638#endif /* ONCE_LTTNG_TRACE_EPOLL_CTL_H */
639
640#if defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64) || defined(CONFIG_ARM)
641#define OVERRIDE_32_epoll_ctl
642#define OVERRIDE_64_epoll_ctl
643SC_LTTNG_TRACEPOINT_EVENT_CODE(epoll_ctl,
644 TP_PROTO(sc_exit(long ret,) int epfd, int op, int fd,
645 struct epoll_event __user * uevent),
646 TP_ARGS(sc_exit(ret,) epfd, op, fd, uevent),
647 TP_locvar(
648 struct epoll_event event;
649 int err;
650 ),
651 TP_code_pre(
652 tp_locvar->err = lib_ring_buffer_copy_from_user_check_nofault(
653 &tp_locvar->event, uevent, sizeof(struct epoll_event));
654 ),
655 TP_FIELDS(
656 sc_exit(ctf_integer(long, ret, ret))
657 sc_in(ctf_integer(int, epfd, epfd))
658 sc_in(ctf_enum(lttng_epoll_op, int, op_enum, op))
659 sc_in(ctf_integer(int, fd, fd))
660 sc_in(
661 ctf_custom_field(
662 ctf_custom_type(
663 .atype = atype_struct,
664 .u._struct.nr_fields = ARRAY_SIZE(epoll_ctl_fields),
665 .u._struct.fields = epoll_ctl_fields,
666 ),
667 event,
668 ctf_custom_code(
669 ctf_align(uint64_t)
670 if (!tp_locvar->err) {
671 ctf_integer_type(uint64_t, tp_locvar->event.data)
672 ctf_integer_type(int, tp_locvar->event.data)
673 ctf_integer_bitfield_type(uint32_t,
674 tp_locvar->event.events)
675 ctf_integer_bitfield_type(uint8_t,
676 (uint8_t) tp_locvar->event.events)
677 } else {
678 ctf_integer_type(uint64_t, 0)
679 ctf_integer_type(int, 0)
680 ctf_integer_bitfield_type(uint32_t, 0)
681 ctf_integer_bitfield_type(uint8_t, 0)
682 }
683 )
684 )
685 )
686 ),
687 TP_code_post()
688)
689#endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64) || defined(CONFIG_ARM) */
690
f22697ca
JD
691#ifndef ONCE_LTTNG_TRACE_EPOLL_H
692#define ONCE_LTTNG_TRACE_EPOLL_H
693
694static struct lttng_event_field lttng_epoll_wait_fields[] = {
695 [0] = {
696 .name = "data_union",
697 .type = {
698 .atype = atype_struct,
699 .u._struct.nr_fields = ARRAY_SIZE(lttng_epoll_data_fields),
700 .u._struct.fields = lttng_epoll_data_fields,
701 }
702 },
703 [1] = {
704 .name = "raw_events",
705 .type = __type_integer(uint32_t, 0, 0, 0, __BYTE_ORDER, 16, none),
706 },
707 [2] = {
708 .name = "events",
709 .type = {
710 .atype = atype_struct,
711 .u._struct.nr_fields = ARRAY_SIZE(lttng_epoll_ctl_events_fields),
712 .u._struct.fields = lttng_epoll_ctl_events_fields,
713 }
714 },
715};
716
717static struct lttng_type lttng_epoll_wait_elem = {
718 .atype = atype_struct,
719 .u._struct.nr_fields = ARRAY_SIZE(lttng_epoll_wait_fields),
720 .u._struct.fields = lttng_epoll_wait_fields,
721};
722
723#endif /* ONCE_LTTNG_TRACE_EPOLL_H */
724
725#define LTTNG_SYSCALL_EPOLL_WAIT_locvar \
726 sc_out( \
727 unsigned int fds_length; \
728 uint8_t overflow; \
729 struct epoll_event *events; \
730 )
731
732#define LTTNG_SYSCALL_EPOLL_WAIT_code_pre \
733 BUILD_BUG_ON(((ARRAY_SIZE(lttng_epoll_ctl_events_fields) - 1) + \
734 EPOLL_FLAGS_PADDING_SIZE) != \
735 sizeof(uint8_t) * BITS_PER_BYTE); \
736 sc_out({ \
737 int err; \
738 unsigned long maxalloc; \
739 \
740 tp_locvar->fds_length = 0; \
741 tp_locvar->events = NULL; \
742 tp_locvar->overflow = 0; \
743 \
744 if (maxevents <= 0 || ret <= 0 || ret > maxevents) \
745 goto skip_code; \
746 \
747 if (maxevents > PAGE_SIZE / sizeof(struct epoll_event)) { \
748 maxalloc = PAGE_SIZE / sizeof(struct epoll_event); \
749 } else { \
750 maxalloc = maxevents; \
751 } \
752 \
753 if (ret > maxalloc) { \
754 tp_locvar->fds_length = maxalloc; \
755 tp_locvar->overflow = 1; \
756 } else { \
757 tp_locvar->fds_length = ret; \
758 } \
759 \
ec85ce1d
JD
760 tp_locvar->events = lttng_tp_mempool_alloc( \
761 maxalloc * sizeof(struct epoll_event)); \
f22697ca
JD
762 if (!tp_locvar->events) { \
763 tp_locvar->fds_length = 0; \
764 goto skip_code; \
765 } \
766 \
767 err = lib_ring_buffer_copy_from_user_check_nofault( \
768 tp_locvar->events, uevents, \
41a3cca2 769 maxalloc * sizeof(struct epoll_event)); \
f22697ca
JD
770 if (err != 0) \
771 tp_locvar->fds_length = 0; \
772 } \
773 skip_code: \
774 )
775
776#define LTTNG_SYSCALL_EPOLL_WAIT_fds_field \
777 ctf_custom_field( \
778 ctf_custom_type( \
779 .atype = atype_sequence_compound, \
780 .u.sequence_compound.length_name = \
781 "fds_length", \
782 .u.sequence_compound.elem_type = \
783 &lttng_epoll_wait_elem, \
784 ), \
785 fds, \
786 ctf_custom_code( \
787 uint32_t i; \
788 \
789 ctf_align(uint64_t) \
790 for (i = 0; i < tp_locvar->fds_length; i++) { \
791 ctf_integer_type(uint64_t, tp_locvar->events[i].data) \
792 ctf_integer_type(int, tp_locvar->events[i].data) \
793 ctf_integer_bitfield_type(uint32_t, \
794 tp_locvar->events[i].events) \
795 ctf_integer_bitfield_type(uint8_t, \
796 (uint8_t) tp_locvar->events[i].events) \
797 } \
798 ) \
799 )
800
801#define LTTNG_SYSCALL_EPOLL_WAIT_code_post \
802 sc_out( \
ec85ce1d 803 lttng_tp_mempool_free(tp_locvar->events); \
f22697ca
JD
804 )
805
806
a6370148 807#if defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM)
f22697ca
JD
808#define OVERRIDE_32_epoll_wait
809#define OVERRIDE_64_epoll_wait
810SC_LTTNG_TRACEPOINT_EVENT_CODE(epoll_wait,
811 TP_PROTO(sc_exit(long ret,) int epfd, struct epoll_event __user * uevents,
812 int maxevents, int timeout),
813 TP_ARGS(sc_exit(ret,) epfd, uevents, maxevents, timeout),
814 TP_locvar(
815 LTTNG_SYSCALL_EPOLL_WAIT_locvar
816 ),
817 TP_code_pre(
818 LTTNG_SYSCALL_EPOLL_WAIT_code_pre
819 ),
820 TP_FIELDS(
821 sc_exit(ctf_integer(long, ret, ret))
822 sc_in(ctf_integer(int, epfd, epfd))
823 sc_in(ctf_integer(int, maxevents, maxevents))
824 sc_in(ctf_integer(int, timeout, timeout))
825 sc_out(ctf_integer(unsigned int, fds_length, tp_locvar->fds_length))
826 sc_out(ctf_integer(uint8_t, overflow, tp_locvar->overflow))
827 sc_out(
828 LTTNG_SYSCALL_EPOLL_WAIT_fds_field
829 )
830 ),
831 TP_code_post(
832 LTTNG_SYSCALL_EPOLL_WAIT_code_post
833 )
834)
639655f9 835#endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM) */
f22697ca
JD
836
837#if defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64) || defined(CONFIG_ARM)
838#define OVERRIDE_32_epoll_pwait
839#define OVERRIDE_64_epoll_pwait
840SC_LTTNG_TRACEPOINT_EVENT_CODE(epoll_pwait,
841 TP_PROTO(sc_exit(long ret,) int epfd, struct epoll_event __user * uevents,
842 int maxevents, int timeout, const sigset_t __user * sigmask, size_t sigsetsize),
843 TP_ARGS(sc_exit(ret,) epfd, uevents, maxevents, timeout, sigmask, sigsetsize),
844 TP_locvar(
845 LTTNG_SYSCALL_EPOLL_WAIT_locvar
846 ),
847 TP_code_pre(
848 LTTNG_SYSCALL_EPOLL_WAIT_code_pre
849 ),
850 TP_FIELDS(
851 sc_exit(ctf_integer(long, ret, ret))
852 sc_in(ctf_integer(int, epfd, epfd))
853 sc_in(ctf_integer(int, maxevents, maxevents))
854 sc_in(ctf_integer(int, timeout, timeout))
855 sc_in(ctf_integer_hex(const sigset_t *, sigmask, sigmask))
856 sc_in(ctf_integer(size_t, sigsetsize, sigsetsize))
857 sc_out(ctf_integer(unsigned int, fds_length, tp_locvar->fds_length))
858 sc_out(ctf_integer(uint8_t, overflow, tp_locvar->overflow))
859 sc_out(
860 LTTNG_SYSCALL_EPOLL_WAIT_fds_field
861 )
862 ),
863 TP_code_post(
864 LTTNG_SYSCALL_EPOLL_WAIT_code_post
865 )
866)
867#endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64) || defined(CONFIG_ARM) */
868
771af27e
JW
869#if (defined(CONFIG_X86_64) && !defined(LTTNG_SC_COMPAT)) || defined(CONFIG_ARM64) || defined(CONFIG_ARM)
870#define OVERRIDE_32_socketpair
871#define OVERRIDE_64_socketpair
872SC_LTTNG_TRACEPOINT_EVENT(socketpair,
873 TP_PROTO(sc_exit(long ret,) int family, int type, int protocol, int *usockvec),
874 TP_ARGS(sc_exit(ret,) family, type, protocol, usockvec),
875 TP_FIELDS(
876 sc_exit(ctf_integer(long, ret, ret))
877 sc_in(ctf_integer(int, family, family))
878 sc_in(ctf_integer(int, type, type))
879 sc_in(ctf_integer(int, protocol, protocol))
880 sc_out(ctf_user_array(int, socket, usockvec, 2))
881 )
882)
883#endif /* (defined(CONFIG_X86_64) && !defined(LTTNG_SC_COMPAT)) || defined(CONFIG_ARM64) || defined(CONFIG_ARM) */
884
e42e81fd 885#endif /* CREATE_SYSCALL_TABLE */
This page took 0.069019 seconds and 4 git commands to generate.