From: Francis Deslauriers Date: Fri, 30 Apr 2021 21:30:48 +0000 (-0400) Subject: Split syscall tracepoint generation in their own files X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=e42c4f49c15b4365de8d01b1a010c9b7e95163b8;p=deliverable%2Flttng-modules.git Split syscall tracepoint generation in their own files This commit tracepoint generation of the 4 different types of syscalls (entry, exit, entry_compat, and exit_compat) each in their own .c file. The compilation time of the lttng-modules projects is currently dominated by the compilation of the src/lttng-syscalls.o object. This is caused by the extensive use of macros to generate tracepoint for all syscalls. This also uses a lot of memory making the compilation of the project tedious on system with low memory. This allows for parallelization of the compilation which offers 2 improvements: Reduction of compilation time and reduction of the memory usage. In term of compilation time, on my 4 cpus laptop, I measured a 15sec (20%) speedup over 10 runs when using all 4 cpus (make -j4). On a larger machine (16 cpus), I measured 30sec (60%) speedup when using all 16 cpus. In term of memory usage, I was able to compile the project on a virtual machine with 500MB of memory without hitting memory exhaustion errors. Signed-off-by: Francis Deslauriers Signed-off-by: Mathieu Desnoyers Change-Id: I025a4c36ef16b935be2a86f5b6649526752a7393 --- diff --git a/include/instrumentation/syscalls/headers/syscalls_pointers_override.h b/include/instrumentation/syscalls/headers/syscalls_pointers_override.h index 000756db..c84efdc9 100644 --- a/include/instrumentation/syscalls/headers/syscalls_pointers_override.h +++ b/include/instrumentation/syscalls/headers/syscalls_pointers_override.h @@ -810,7 +810,7 @@ SC_LTTNG_TRACEPOINT_EVENT_CODE(epoll_ctl, sc_in( ctf_custom_field( ctf_custom_type( - lttng_kernel_static_type_struct(ARRAY_SIZE(epoll_ctl_fields), epoll_ctl_fields, 0) + (const struct lttng_kernel_type_common *) &epoll_ctl_fields_struct ), event, ctf_custom_code( @@ -914,7 +914,7 @@ LTTNG_TRACEPOINT_TYPE(PARAMS(const struct lttng_kernel_type_struct lttng_epoll_w ctf_custom_field( \ ctf_custom_type( \ lttng_kernel_static_type_sequence("fds_length", \ - lttng_kernel_static_type_struct(ARRAY_SIZE(lttng_epoll_wait_fields), lttng_epoll_wait_fields, 0), \ + (const struct lttng_kernel_type_common *) <tng_epoll_wait_fields_struct, \ 0, \ none) \ ), \ diff --git a/include/lttng/tracepoint-event.h b/include/lttng/tracepoint-event.h index d3ad1b32..37da4347 100644 --- a/include/lttng/tracepoint-event.h +++ b/include/lttng/tracepoint-event.h @@ -22,30 +22,48 @@ #define _LTTNG_INSTRUMENTATION(...) #endif +#undef LTTNG_TRACEPOINT_EVENT #define LTTNG_TRACEPOINT_EVENT(name, proto, args, fields) \ _LTTNG_INSTRUMENTATION(DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))) +#undef LTTNG_TRACEPOINT_EVENT_CODE #define LTTNG_TRACEPOINT_EVENT_CODE(name, proto, args, _locvar, _code_pre, fields, _code_post) \ _LTTNG_INSTRUMENTATION(DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))) +#undef LTTNG_TRACEPOINT_EVENT_CODE_MAP #define LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, map, proto, args, _locvar, _code_pre, fields, _code_post) \ _LTTNG_INSTRUMENTATION(DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))) +#undef LTTNG_TRACEPOINT_EVENT_MAP #define LTTNG_TRACEPOINT_EVENT_MAP(name, map, proto, args, fields) \ _LTTNG_INSTRUMENTATION(DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))) +#undef LTTNG_TRACEPOINT_EVENT_MAP_NOARGS #define LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, map, fields) \ _LTTNG_INSTRUMENTATION(DECLARE_TRACE_NOARGS(name)) +#undef LTTNG_TRACEPOINT_EVENT_CLASS #define LTTNG_TRACEPOINT_EVENT_CLASS(name, proto, args, fields) +#undef LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS +#define LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(name, fields) +#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) +#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) +#undef LTTNG_TRACEPOINT_EVENT_INSTANCE #define LTTNG_TRACEPOINT_EVENT_INSTANCE(template, name, proto, args) \ _LTTNG_INSTRUMENTATION(DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))) +#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS #define LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(template, name) \ _LTTNG_INSTRUMENTATION(DECLARE_TRACE_NOARGS(name)) +#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \ _LTTNG_INSTRUMENTATION(DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))) +#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \ _LTTNG_INSTRUMENTATION(DECLARE_TRACE_NOARGS(name)) +#undef LTTNG_TRACEPOINT_ENUM #define LTTNG_TRACEPOINT_ENUM(_name, _values) +#undef LTTNG_TRACEPOINT_TYPE +#define LTTNG_TRACEPOINT_TYPE(_prototype, _init) + #endif /* LTTNG_TRACEPOINT_EVENT_H */ diff --git a/src/Kbuild b/src/Kbuild index b03b4b93..0eba20d8 100644 --- a/src/Kbuild +++ b/src/Kbuild @@ -90,6 +90,10 @@ lttng-wrapper-objs := wrapper/page_alloc.o \ ifneq ($(CONFIG_HAVE_SYSCALL_TRACEPOINTS),) lttng-tracer-objs += lttng-syscalls.o + lttng-tracer-objs += lttng-syscalls-entry-table.o + lttng-tracer-objs += lttng-syscalls-entry-compat-table.o + lttng-tracer-objs += lttng-syscalls-exit-table.o + lttng-tracer-objs += lttng-syscalls-exit-compat-table.o lttng-tracer-objs += lttng-syscalls-enum.o endif # CONFIG_HAVE_SYSCALL_TRACEPOINTS diff --git a/src/lttng-syscalls-entry-compat-table.c b/src/lttng-syscalls-entry-compat-table.c new file mode 100644 index 00000000..2c2902bd --- /dev/null +++ b/src/lttng-syscalls-entry-compat-table.c @@ -0,0 +1,114 @@ +/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) + * + * lttng-syscalls-entry-compat-table.c + * + * LTTng syscall entry compat probes. + * + * Copyright (C) 2010-2012 Mathieu Desnoyers + * Copyright (C) 2021 Francis Deslauriers + */ + +#include + +#include "lttng-syscalls.h" + + +#ifdef IA32_NR_syscalls +#define NR_compat_syscalls IA32_NR_syscalls +#else +#define NR_compat_syscalls NR_syscalls +#endif + +/* + * Create LTTng tracepoint probes. + */ +#define LTTNG_PACKAGE_BUILD +#define CREATE_TRACE_POINTS +#define TP_MODULE_NOINIT +#define TRACE_INCLUDE_PATH instrumentation/syscalls/headers + +#define PARAMS(args...) args + +#define SC_ENTER + +#undef sc_exit +#define sc_exit(...) +#undef sc_in +#define sc_in(...) __VA_ARGS__ +#undef sc_out +#define sc_out(...) +#undef sc_inout +#define sc_inout(...) __VA_ARGS__ + +#define LTTNG_TRACEPOINT_TYPE_EXTERN + +#include + +/* Hijack probe callback for system call enter */ +#undef TP_PROBE_CB +#define TP_PROBE_CB(_template) &syscall_entry_event_probe +#define LTTNG_SC_COMPAT +#define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \ + LTTNG_TRACEPOINT_EVENT(compat_syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \ + PARAMS(_fields)) +#define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ + LTTNG_TRACEPOINT_EVENT_CODE(compat_syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \ + PARAMS(_locvar), PARAMS(_code_pre), \ + PARAMS(_fields), PARAMS(_code_post)) +#define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \ + LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(compat_syscall_entry_##_name, PARAMS(_fields)) +#define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \ + LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(compat_syscall_entry_##_template, compat_syscall_entry_##_name) + +#define SC_LTTNG_TRACEPOINT_ENUM(_name, _values) \ + LTTNG_TRACEPOINT_ENUM(_name, PARAMS(_values)) +#undef TRACE_SYSTEM +#define TRACE_SYSTEM compat_syscall_entry_integers +#define TRACE_INCLUDE_FILE compat_syscalls_integers +#include +#undef TRACE_INCLUDE_FILE +#undef TRACE_SYSTEM +#define TRACE_SYSTEM compat_syscall_entry_pointers +#define TRACE_INCLUDE_FILE compat_syscalls_pointers +#include +#undef TRACE_INCLUDE_FILE +#undef TRACE_SYSTEM +#undef SC_LTTNG_TRACEPOINT_ENUM +#undef SC_LTTNG_TRACEPOINT_EVENT_CODE +#undef SC_LTTNG_TRACEPOINT_EVENT +#undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS +#undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS +#undef TP_PROBE_CB + +#undef _TRACE_SYSCALLS_INTEGERS_H +#undef _TRACE_SYSCALLS_POINTERS_H +#undef LTTNG_SC_COMPAT + +#define CREATE_SYSCALL_TABLE + +#undef sc_exit +#define sc_exit(...) + +#undef TRACE_SYSCALL_TABLE +#define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \ + [ _nr ] = { \ + .event_func = __event_probe__compat_syscall_entry_##_template, \ + .nrargs = (_nrargs), \ + .fields = __event_fields___compat_syscall_entry_##_template, \ + .desc = &__event_desc___compat_syscall_entry_##_name, \ + }, + +/* Event compat syscall enter table */ +const struct trace_syscall_entry _compat_sc_table[] = { +#include +#include +}; + +const struct trace_syscall_table compat_sc_table = { + .table = _compat_sc_table, + .len = ARRAY_SIZE(_compat_sc_table), +}; + +#undef SC_ENTER + +#undef CREATE_SYSCALL_TABLE diff --git a/src/lttng-syscalls-entry-table.c b/src/lttng-syscalls-entry-table.c new file mode 100644 index 00000000..7324f487 --- /dev/null +++ b/src/lttng-syscalls-entry-table.c @@ -0,0 +1,111 @@ +/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) + * + * lttng-syscalls-entry-table.c + * + * LTTng syscall entry probes. + * + * Copyright (C) 2010-2012 Mathieu Desnoyers + * Copyright (C) 2021 Francis Deslauriers + */ + +#include + +#include "lttng-syscalls.h" + + +#ifdef IA32_NR_syscalls +#define NR_compat_syscalls IA32_NR_syscalls +#else +#define NR_compat_syscalls NR_syscalls +#endif + +/* + * Create LTTng tracepoint probes. + */ +#define LTTNG_PACKAGE_BUILD +#define CREATE_TRACE_POINTS +#define TP_MODULE_NOINIT +#define TRACE_INCLUDE_PATH instrumentation/syscalls/headers + +#define PARAMS(args...) args + +#define SC_ENTER + +#undef sc_exit +#define sc_exit(...) +#undef sc_in +#define sc_in(...) __VA_ARGS__ +#undef sc_out +#define sc_out(...) +#undef sc_inout +#define sc_inout(...) __VA_ARGS__ + +#define LTTNG_TRACEPOINT_TYPE_EXTERN + +#include + +/* Hijack probe callback for system call enter */ +#undef TP_PROBE_CB +#define TP_PROBE_CB(_template) &syscall_entry_event_probe +#define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \ + LTTNG_TRACEPOINT_EVENT(syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \ + PARAMS(_fields)) +#define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ + LTTNG_TRACEPOINT_EVENT_CODE(syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \ + PARAMS(_locvar), PARAMS(_code_pre), \ + PARAMS(_fields), PARAMS(_code_post)) +#define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \ + LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscall_entry_##_name, PARAMS(_fields)) +#define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \ + LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(syscall_entry_##_template, syscall_entry_##_name) + +#define SC_LTTNG_TRACEPOINT_ENUM(_name, _values) \ + LTTNG_TRACEPOINT_ENUM(_name, PARAMS(_values)) +#undef TRACE_SYSTEM +#define TRACE_SYSTEM syscall_entry_integers +#define TRACE_INCLUDE_FILE syscalls_integers +#include +#undef TRACE_INCLUDE_FILE +#undef TRACE_SYSTEM +#define TRACE_SYSTEM syscall_entry_pointers +#define TRACE_INCLUDE_FILE syscalls_pointers +#include +#undef TRACE_INCLUDE_FILE +#undef TRACE_SYSTEM +#undef SC_LTTNG_TRACEPOINT_ENUM +#undef SC_LTTNG_TRACEPOINT_EVENT_CODE +#undef SC_LTTNG_TRACEPOINT_EVENT +#undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS +#undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS +#undef TP_PROBE_CB +#undef _TRACE_SYSCALLS_INTEGERS_H +#undef _TRACE_SYSCALLS_POINTERS_H + +#define CREATE_SYSCALL_TABLE + +#undef sc_exit +#define sc_exit(...) + +#undef TRACE_SYSCALL_TABLE +#define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \ + [ _nr ] = { \ + .event_func = __event_probe__syscall_entry_##_template, \ + .nrargs = (_nrargs), \ + .fields = __event_fields___syscall_entry_##_template, \ + .desc = &__event_desc___syscall_entry_##_name, \ + }, + +/* Event syscall enter tracing table */ +static const struct trace_syscall_entry _sc_table[] = { +#include +#include +}; + +const struct trace_syscall_table sc_table = { + .table = _sc_table, + .len = ARRAY_SIZE(_sc_table), +}; + +#undef SC_ENTER + +#undef CREATE_SYSCALL_TABLE diff --git a/src/lttng-syscalls-exit-compat-table.c b/src/lttng-syscalls-exit-compat-table.c new file mode 100644 index 00000000..58fc3275 --- /dev/null +++ b/src/lttng-syscalls-exit-compat-table.c @@ -0,0 +1,113 @@ +/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) + * + * lttng-syscalls-exit-compat-table.c + * + * LTTng syscall exit compat probes. + * + * Copyright (C) 2010-2012 Mathieu Desnoyers + * Copyright (C) 2021 Francis Deslauriers + */ + +#include + +#include "lttng-syscalls.h" + + +#ifdef IA32_NR_syscalls +#define NR_compat_syscalls IA32_NR_syscalls +#else +#define NR_compat_syscalls NR_syscalls +#endif + +/* + * Create LTTng tracepoint probes. + */ +#define LTTNG_PACKAGE_BUILD +#define CREATE_TRACE_POINTS +#define TP_MODULE_NOINIT +#define TRACE_INCLUDE_PATH instrumentation/syscalls/headers + +#define PARAMS(args...) args + +#define SC_EXIT + +#undef sc_in +#define sc_in(...) __VA_ARGS__ +#undef sc_out +#define sc_out(...) +#undef sc_inout +#define sc_inout(...) __VA_ARGS__ +#undef sc_exit +#define sc_exit(...) __VA_ARGS__ + +#define LTTNG_TRACEPOINT_TYPE_EXTERN + +#include + +/* Hijack probe callback for system call compat exit */ +#undef TP_PROBE_CB +#define LTTNG_SC_COMPAT +#define TP_PROBE_CB(_template) &syscall_exit_event_probe +#define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \ + LTTNG_TRACEPOINT_EVENT(compat_syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \ + PARAMS(_fields)) +#define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ + LTTNG_TRACEPOINT_EVENT_CODE(compat_syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \ + PARAMS(_locvar), PARAMS(_code_pre), \ + PARAMS(_fields), PARAMS(_code_post)) +#define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \ + LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(compat_syscall_exit_##_name, PARAMS(_fields)) +#define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \ + LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(compat_syscall_exit_##_template, compat_syscall_exit_##_name) + +#define SC_LTTNG_TRACEPOINT_ENUM(_name, _values) \ + LTTNG_TRACEPOINT_ENUM(_name, PARAMS(_values)) +#undef TRACE_SYSTEM +#define TRACE_SYSTEM compat_syscall_exit_integers +#define TRACE_INCLUDE_FILE compat_syscalls_integers +#include +#undef TRACE_INCLUDE_FILE +#undef TRACE_SYSTEM +#define TRACE_SYSTEM compat_syscall_exit_pointers +#define TRACE_INCLUDE_FILE compat_syscalls_pointers +#include +#undef TRACE_INCLUDE_FILE +#undef TRACE_SYSTEM +#undef SC_LTTNG_TRACEPOINT_ENUM +#undef SC_LTTNG_TRACEPOINT_EVENT_CODE +#undef SC_LTTNG_TRACEPOINT_EVENT +#undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS +#undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS +#undef TP_PROBE_CB +#undef _TRACE_SYSCALLS_INTEGERS_H +#undef _TRACE_SYSCALLS_POINTERS_H +#undef LTTNG_SC_COMPAT + +#define CREATE_SYSCALL_TABLE + +#undef sc_exit +#define sc_exit(...) + +#undef TRACE_SYSCALL_TABLE +#define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \ + [ _nr ] = { \ + .event_func = __event_probe__compat_syscall_exit_##_template, \ + .nrargs = (_nrargs), \ + .fields = __event_fields___compat_syscall_exit_##_template, \ + .desc = &__event_desc___compat_syscall_exit_##_name, \ + }, + +/* Event compat syscall exit table */ +const struct trace_syscall_entry _compat_sc_exit_table[] = { +#include +#include +}; + +const struct trace_syscall_table compat_sc_exit_table = { + .table = _compat_sc_exit_table, + .len = ARRAY_SIZE(_compat_sc_exit_table), +}; + +#undef SC_EXIT + +#undef CREATE_SYSCALL_TABLE diff --git a/src/lttng-syscalls-exit-table.c b/src/lttng-syscalls-exit-table.c new file mode 100644 index 00000000..aaaa331b --- /dev/null +++ b/src/lttng-syscalls-exit-table.c @@ -0,0 +1,110 @@ +/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) + * + * lttng-syscalls-exit-table.c + * + * LTTng syscall exit probes. + * + * Copyright (C) 2010-2012 Mathieu Desnoyers + * Copyright (C) 2021 Francis Deslauriers + */ + +#include + +#include "lttng-syscalls.h" + + +#ifdef IA32_NR_syscalls +#define NR_compat_syscalls IA32_NR_syscalls +#else +#define NR_compat_syscalls NR_syscalls +#endif + +/* + * Create LTTng tracepoint probes. + */ +#define LTTNG_PACKAGE_BUILD +#define CREATE_TRACE_POINTS +#define TP_MODULE_NOINIT +#define TRACE_INCLUDE_PATH instrumentation/syscalls/headers + +#define PARAMS(args...) args + +#define SC_EXIT + +#undef sc_in +#define sc_in(...) __VA_ARGS__ +#undef sc_out +#define sc_out(...) +#undef sc_inout +#define sc_inout(...) __VA_ARGS__ +#undef sc_exit +#define sc_exit(...) __VA_ARGS__ + +#define LTTNG_TRACEPOINT_TYPE_EXTERN + +#include + +/* Hijack probe callback for system call enter */ +#undef TP_PROBE_CB +#define TP_PROBE_CB(_template) &syscall_exit_event_probe +#define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \ + LTTNG_TRACEPOINT_EVENT(syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \ + PARAMS(_fields)) +#define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ + LTTNG_TRACEPOINT_EVENT_CODE(syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \ + PARAMS(_locvar), PARAMS(_code_pre), \ + PARAMS(_fields), PARAMS(_code_post)) +#define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \ + LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscall_exit_##_name, PARAMS(_fields)) +#define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \ + LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(syscall_exit_##_template, syscall_exit_##_name) + +#define SC_LTTNG_TRACEPOINT_ENUM(_name, _values) \ + LTTNG_TRACEPOINT_ENUM(_name, PARAMS(_values)) +#undef TRACE_SYSTEM +#define TRACE_SYSTEM syscall_exit_integers +#define TRACE_INCLUDE_FILE syscalls_integers +#include +#undef TRACE_INCLUDE_FILE +#undef TRACE_SYSTEM +#define TRACE_SYSTEM syscall_exit_pointers +#define TRACE_INCLUDE_FILE syscalls_pointers +#include +#undef TRACE_INCLUDE_FILE +#undef TRACE_SYSTEM +#undef SC_LTTNG_TRACEPOINT_ENUM +#undef SC_LTTNG_TRACEPOINT_EVENT_CODE +#undef SC_LTTNG_TRACEPOINT_EVENT +#undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS +#undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS +#undef TP_PROBE_CB +#undef _TRACE_SYSCALLS_INTEGERS_H +#undef _TRACE_SYSCALLS_POINTERS_H + +#define CREATE_SYSCALL_TABLE + +#undef sc_exit +#define sc_exit(...) + +#undef TRACE_SYSCALL_TABLE +#define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \ + [ _nr ] = { \ + .event_func = __event_probe__syscall_exit_##_template, \ + .nrargs = (_nrargs), \ + .fields = __event_fields___syscall_exit_##_template, \ + .desc = &__event_desc___syscall_exit_##_name, \ + }, + +/* Event syscall enter tracing table */ +static const struct trace_syscall_entry _sc_exit_table[] = { +#include +#include +}; + +const struct trace_syscall_table sc_exit_table = { + .table = _sc_exit_table, + .len = ARRAY_SIZE(_sc_exit_table), +}; +#undef SC_EXIT + +#undef CREATE_SYSCALL_TABLE diff --git a/src/lttng-syscalls.c b/src/lttng-syscalls.c index 2b469cb5..6b52b69b 100644 --- a/src/lttng-syscalls.c +++ b/src/lttng-syscalls.c @@ -62,15 +62,11 @@ enum sc_type { #define SYSCALL_EXIT_STR __stringify(SYSCALL_EXIT_TOK) #define COMPAT_SYSCALL_EXIT_STR __stringify(COMPAT_SYSCALL_EXIT_TOK) -static void syscall_entry_event_probe(void *__data, struct pt_regs *regs, long id); -static void syscall_exit_event_probe(void *__data, struct pt_regs *regs, long ret); -static void syscall_entry_event_notifier_probe(void *__data, struct pt_regs *regs, long id); -static void syscall_exit_event_notifier_probe(void *__data, struct pt_regs *regs, long ret); @@ -120,275 +116,15 @@ typedef __kernel_old_time_t time_t; #include #undef TRACE_SYSTEM -#define SC_ENTER - -#undef sc_exit -#define sc_exit(...) -#undef sc_in -#define sc_in(...) __VA_ARGS__ -#undef sc_out -#define sc_out(...) -#undef sc_inout -#define sc_inout(...) __VA_ARGS__ - -/* Hijack probe callback for system call enter */ -#undef TP_PROBE_CB -#define TP_PROBE_CB(_template) &syscall_entry_event_probe -#define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \ - LTTNG_TRACEPOINT_EVENT(syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \ - PARAMS(_fields)) -#define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ - LTTNG_TRACEPOINT_EVENT_CODE(syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \ - PARAMS(_locvar), PARAMS(_code_pre), \ - PARAMS(_fields), PARAMS(_code_post)) -#define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \ - LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscall_entry_##_name, PARAMS(_fields)) -#define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \ - LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(syscall_entry_##_template, syscall_entry_##_name) -/* Enumerations only defined at first inclusion. */ -#define SC_LTTNG_TRACEPOINT_ENUM(_name, _values) \ - LTTNG_TRACEPOINT_ENUM(_name, PARAMS(_values)) -#undef TRACE_SYSTEM -#define TRACE_SYSTEM syscall_entry_integers -#define TRACE_INCLUDE_FILE syscalls_integers -#include -#undef TRACE_INCLUDE_FILE -#undef TRACE_SYSTEM -#define TRACE_SYSTEM syscall_entry_pointers -#define TRACE_INCLUDE_FILE syscalls_pointers -#include -#undef TRACE_INCLUDE_FILE -#undef TRACE_SYSTEM -#undef SC_LTTNG_TRACEPOINT_ENUM -#undef SC_LTTNG_TRACEPOINT_EVENT_CODE -#undef SC_LTTNG_TRACEPOINT_EVENT -#undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS -#undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS -#undef TP_PROBE_CB -#undef _TRACE_SYSCALLS_INTEGERS_H -#undef _TRACE_SYSCALLS_POINTERS_H - -/* Hijack probe callback for compat system call enter */ -#define TP_PROBE_CB(_template) &syscall_entry_event_probe -#define LTTNG_SC_COMPAT -#define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \ - LTTNG_TRACEPOINT_EVENT(compat_syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \ - PARAMS(_fields)) -#define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ - LTTNG_TRACEPOINT_EVENT_CODE(compat_syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \ - PARAMS(_locvar), PARAMS(_code_pre), PARAMS(_fields), PARAMS(_code_post)) -#define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \ - LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(compat_syscall_entry_##_name, PARAMS(_fields)) -#define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \ - LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(compat_syscall_entry_##_template, \ - compat_syscall_entry_##_name) -/* Enumerations only defined at inital inclusion (not here). */ -#define SC_LTTNG_TRACEPOINT_ENUM(_name, _values) -#define TRACE_SYSTEM compat_syscall_entry_integers -#define TRACE_INCLUDE_FILE compat_syscalls_integers -#include -#undef TRACE_INCLUDE_FILE -#undef TRACE_SYSTEM -#define TRACE_SYSTEM compat_syscall_entry_pointers -#define TRACE_INCLUDE_FILE compat_syscalls_pointers -#include -#undef TRACE_INCLUDE_FILE -#undef TRACE_SYSTEM -#undef SC_LTTNG_TRACEPOINT_ENUM -#undef SC_LTTNG_TRACEPOINT_EVENT_CODE -#undef SC_LTTNG_TRACEPOINT_EVENT -#undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS -#undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS -#undef TP_PROBE_CB -#undef _TRACE_SYSCALLS_INTEGERS_H -#undef _TRACE_SYSCALLS_POINTERS_H -#undef LTTNG_SC_COMPAT - -#undef SC_ENTER - -#define SC_EXIT - -#undef sc_exit -#define sc_exit(...) __VA_ARGS__ -#undef sc_in -#define sc_in(...) -#undef sc_out -#define sc_out(...) __VA_ARGS__ -#undef sc_inout -#define sc_inout(...) __VA_ARGS__ - -/* Hijack probe callback for system call exit */ -#define TP_PROBE_CB(_template) &syscall_exit_event_probe -#define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \ - LTTNG_TRACEPOINT_EVENT(syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \ - PARAMS(_fields)) -#define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ - LTTNG_TRACEPOINT_EVENT_CODE(syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \ - PARAMS(_locvar), PARAMS(_code_pre), PARAMS(_fields), PARAMS(_code_post)) -#define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \ - LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscall_exit_##_name, PARAMS(_fields)) -#define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \ - LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(syscall_exit_##_template, \ - syscall_exit_##_name) -/* Enumerations only defined at inital inclusion (not here). */ -#define SC_LTTNG_TRACEPOINT_ENUM(_name, _values) -#define TRACE_SYSTEM syscall_exit_integers -#define TRACE_INCLUDE_FILE syscalls_integers -#include -#undef TRACE_INCLUDE_FILE -#undef TRACE_SYSTEM -#define TRACE_SYSTEM syscall_exit_pointers -#define TRACE_INCLUDE_FILE syscalls_pointers -#include -#undef TRACE_INCLUDE_FILE -#undef TRACE_SYSTEM -#undef SC_LTTNG_TRACEPOINT_ENUM -#undef SC_LTTNG_TRACEPOINT_EVENT_CODE -#undef SC_LTTNG_TRACEPOINT_EVENT -#undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS -#undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS -#undef TP_PROBE_CB -#undef _TRACE_SYSCALLS_INTEGERS_H -#undef _TRACE_SYSCALLS_POINTERS_H - - -/* Hijack probe callback for compat system call exit */ -#define TP_PROBE_CB(_template) &syscall_exit_event_probe -#define LTTNG_SC_COMPAT -#define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \ - LTTNG_TRACEPOINT_EVENT(compat_syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \ - PARAMS(_fields)) -#define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ - LTTNG_TRACEPOINT_EVENT_CODE(compat_syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \ - PARAMS(_locvar), PARAMS(_code_pre), PARAMS(_fields), PARAMS(_code_post)) -#define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \ - LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(compat_syscall_exit_##_name, PARAMS(_fields)) -#define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \ - LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(compat_syscall_exit_##_template, \ - compat_syscall_exit_##_name) -/* Enumerations only defined at inital inclusion (not here). */ -#define SC_LTTNG_TRACEPOINT_ENUM(_name, _values) -#define TRACE_SYSTEM compat_syscall_exit_integers -#define TRACE_INCLUDE_FILE compat_syscalls_integers -#include -#undef TRACE_INCLUDE_FILE -#undef TRACE_SYSTEM -#define TRACE_SYSTEM compat_syscall_exit_pointers -#define TRACE_INCLUDE_FILE compat_syscalls_pointers -#include -#undef TRACE_INCLUDE_FILE -#undef TRACE_SYSTEM -#undef SC_LTTNG_TRACEPOINT_ENUM -#undef SC_LTTNG_TRACEPOINT_EVENT_CODE -#undef SC_LTTNG_TRACEPOINT_EVENT -#undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS -#undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS #undef TP_PROBE_CB -#undef _TRACE_SYSCALLS_INTEGERS_H -#undef _TRACE_SYSCALLS_POINTERS_H -#undef LTTNG_SC_COMPAT - -#undef SC_EXIT - -#undef TP_MODULE_NOINIT -#undef LTTNG_PACKAGE_BUILD -#undef CREATE_TRACE_POINTS - -#define CREATE_SYSCALL_TABLE - -#define SC_ENTER -#undef sc_exit -#define sc_exit(...) - -#undef TRACE_SYSCALL_TABLE -#define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \ - [ _nr ] = { \ - .event_func = __event_probe__syscall_entry_##_template, \ - .nrargs = (_nrargs), \ - .fields = __event_fields___syscall_entry_##_template, \ - .desc = &__event_desc___syscall_entry_##_name, \ - }, - -/* Event syscall enter tracing table */ -static const struct trace_syscall_entry _sc_table[] = { -#include -#include -}; - - -const struct trace_syscall_table sc_table = { - .table = _sc_table, - .len = ARRAY_SIZE(_sc_table), -}; - -#undef TRACE_SYSCALL_TABLE -#define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \ - [ _nr ] = { \ - .event_func = __event_probe__compat_syscall_entry_##_template, \ - .nrargs = (_nrargs), \ - .fields = __event_fields___compat_syscall_entry_##_template, \ - .desc = &__event_desc___compat_syscall_entry_##_name, \ - }, - -/* Event compat syscall enter table */ -const struct trace_syscall_entry _compat_sc_table[] = { -#include -#include -}; - -const struct trace_syscall_table compat_sc_table = { - .table = _compat_sc_table, - .len = ARRAY_SIZE(_compat_sc_table), -}; - -#undef SC_ENTER - -#define SC_EXIT - -#undef sc_exit -#define sc_exit(...) __VA_ARGS__ - -#undef TRACE_SYSCALL_TABLE -#define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \ - [ _nr ] = { \ - .event_func = __event_probe__syscall_exit_##_template, \ - .nrargs = (_nrargs), \ - .fields = __event_fields___syscall_exit_##_template, \ - .desc = &__event_desc___syscall_exit_##_name, \ - }, +extern const struct trace_syscall_table sc_table; +extern const struct trace_syscall_table compat_sc_table; /* Event syscall exit table */ -static const struct trace_syscall_entry _sc_exit_table[] = { -#include -#include -}; - -const struct trace_syscall_table sc_exit_table = { - .table = _sc_exit_table, - .len = ARRAY_SIZE(_sc_exit_table), -}; - +extern const struct trace_syscall_table sc_exit_table; +extern const struct trace_syscall_table compat_sc_exit_table; -#undef TRACE_SYSCALL_TABLE -#define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \ - [ _nr ] = { \ - .event_func = __event_probe__compat_syscall_exit_##_template, \ - .nrargs = (_nrargs), \ - .fields = __event_fields___compat_syscall_exit_##_template, \ - .desc = &__event_desc___compat_syscall_exit_##_name, \ - }, - -/* Event compat syscall exit table */ -const struct trace_syscall_entry _compat_sc_exit_table[] = { -#include -#include -}; - -const struct trace_syscall_table compat_sc_exit_table = { - .table = _compat_sc_exit_table, - .len = ARRAY_SIZE(_compat_sc_exit_table), -}; #undef SC_EXIT @@ -810,7 +546,6 @@ void syscall_exit_event_probe(void *__data, struct pt_regs *regs, long ret) regs, ret); } -static void syscall_exit_event_notifier_probe(void *__data, struct pt_regs *regs, long ret) { diff --git a/src/lttng-syscalls.h b/src/lttng-syscalls.h index 9a9d9173..d221dfb7 100644 --- a/src/lttng-syscalls.h +++ b/src/lttng-syscalls.h @@ -1,9 +1,47 @@ +/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) + * + * lttng-syscalls.h + * + * LTTng syscall header. + * + * Copyright (C) 2021 Francis Deslauriers + */ + #ifndef LTTNG_SYSCALLS_H #define LTTNG_SYSCALLS_H #include +#include + #include +#include + + +/* + * Forward declarations for old kernels. + */ +struct mmsghdr; +struct rlimit64; +struct oldold_utsname; +struct old_utsname; +struct sel_arg_struct; +struct mmap_arg_struct; +struct file_handle; +struct user_msghdr; + +/* + * Forward declaration for kernels >= 5.6 + */ +struct timex; +struct timeval; +struct itimerval; +struct itimerspec; + +#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,6,0)) +typedef __kernel_old_time_t time_t; +#endif + struct trace_syscall_entry { void *event_func; const struct lttng_kernel_event_desc *desc; @@ -15,4 +53,18 @@ struct trace_syscall_table { const struct trace_syscall_entry *table; const size_t len; }; + +extern +void syscall_entry_event_probe(void *__data, struct pt_regs *regs, long id); + +extern +void syscall_exit_event_probe(void *__data, struct pt_regs *regs, long ret); + +extern +void syscall_entry_event_notifier_probe(void *__data, struct pt_regs *regs, + long id); +extern +void syscall_exit_event_notifier_probe(void *__data, struct pt_regs *regs, + long ret); + #endif /* LTTNG_SYSCALLS_H */