X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Flttng-syscalls.c;h=de4dbacefc5c23e7331081696585e4a278b82a7c;hb=873a97436b75e272560fc164813971c8b5461eaa;hp=6f95fe9378fd13fbb930bcb06e8d40a4c0190cb8;hpb=606828e401c405619a0c7249e8c7e3291cc1cb45;p=lttng-modules.git diff --git a/src/lttng-syscalls.c b/src/lttng-syscalls.c index 6f95fe93..de4dbace 100644 --- a/src/lttng-syscalls.c +++ b/src/lttng-syscalls.c @@ -29,8 +29,11 @@ #include #include #include +#include #include +#include "lttng-syscalls.h" + #ifndef CONFIG_COMPAT # ifndef is_compat_task # define is_compat_task() (0) @@ -59,18 +62,9 @@ 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); - /* * Forward declarations for old kernels. */ @@ -117,265 +111,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 - -struct trace_syscall_entry { - void *event_func; - void *event_notifier_func; - const struct lttng_kernel_event_desc *desc; - const struct lttng_kernel_event_field **fields; - unsigned int nrargs; -}; - -#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, \ - .event_notifier_func = __event_notifier_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 -}; - -#undef TRACE_SYSCALL_TABLE -#define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \ - [ _nr ] = { \ - .event_func = __event_probe__compat_syscall_entry_##_template, \ - .event_notifier_func = __event_notifier_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 -}; - -#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, \ - .event_notifier_func = __event_notifier_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 -}; +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, \ - .event_notifier_func = __event_notifier_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 -}; #undef SC_EXIT @@ -388,67 +132,38 @@ struct lttng_syscall_filter { DECLARE_BITMAP(sc_compat_exit, NR_compat_syscalls); }; +static +int lttng_syscalls_create_matching_event_notifiers(struct lttng_event_enabler_common *event_enabler); + static void syscall_entry_event_unknown(struct hlist_head *unknown_action_list_head, struct pt_regs *regs, long id) { unsigned long args[LTTNG_SYSCALL_NR_ARGS]; - struct lttng_event *event; - - lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(event, unknown_action_list_head, u.syscall.node) { - if (unlikely(in_compat_syscall())) - __event_probe__compat_syscall_entry_unknown(event, id, args); - else - __event_probe__syscall_entry_unknown(event, id, args); - } -} - -static void syscall_entry_event_notifier_unknown( - struct hlist_head *unknown_dispatch_list_head, - struct pt_regs *regs, long id) -{ - unsigned long args[LTTNG_SYSCALL_NR_ARGS]; - struct lttng_event_notifier *notifier; - - lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(notifier, unknown_dispatch_list_head, u.syscall.node) { - if (unlikely(in_compat_syscall())) - __event_notifier_probe__compat_syscall_entry_unknown(notifier, id, args); - else - __event_notifier_probe__syscall_entry_unknown(notifier, id, args); - } -} - -static void syscall_exit_event_notifier_unknown( - struct hlist_head *unknown_dispatch_list_head, - struct pt_regs *regs, long id, long ret) -{ - unsigned long args[LTTNG_SYSCALL_NR_ARGS]; - struct lttng_event_notifier *notifier; + struct lttng_kernel_event_common_private *event_priv; lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(notifier, unknown_dispatch_list_head, u.syscall.node) { + lttng_hlist_for_each_entry_rcu(event_priv, unknown_action_list_head, u.syscall.node) { if (unlikely(in_compat_syscall())) - __event_notifier_probe__compat_syscall_exit_unknown(notifier, id, ret, args); + __event_probe__compat_syscall_entry_unknown(event_priv->pub, id, args); else - __event_notifier_probe__syscall_exit_unknown(notifier, id, ret, args); + __event_probe__syscall_entry_unknown(event_priv->pub, id, args); } } static __always_inline -void syscall_entry_call_func(struct hlist_head *action_list, +void syscall_entry_event_call_func(struct hlist_head *action_list, void *func, unsigned int nrargs, struct pt_regs *regs) { - struct lttng_event *event; + struct lttng_kernel_event_common_private *event_priv; switch (nrargs) { case 0: { void (*fptr)(void *__data) = func; - lttng_hlist_for_each_entry_rcu(event, action_list, u.syscall.node) - fptr(event); + lttng_hlist_for_each_entry_rcu(event_priv, action_list, u.syscall.node) + fptr(event_priv->pub); break; } case 1: @@ -457,8 +172,8 @@ void syscall_entry_call_func(struct hlist_head *action_list, unsigned long args[LTTNG_SYSCALL_NR_ARGS]; lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(event, action_list, u.syscall.node) - fptr(event, args[0]); + lttng_hlist_for_each_entry_rcu(event_priv, action_list, u.syscall.node) + fptr(event_priv->pub, args[0]); break; } case 2: @@ -469,8 +184,8 @@ void syscall_entry_call_func(struct hlist_head *action_list, unsigned long args[LTTNG_SYSCALL_NR_ARGS]; lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(event, action_list, u.syscall.node) - fptr(event, args[0], args[1]); + lttng_hlist_for_each_entry_rcu(event_priv, action_list, u.syscall.node) + fptr(event_priv->pub, args[0], args[1]); break; } case 3: @@ -482,8 +197,8 @@ void syscall_entry_call_func(struct hlist_head *action_list, unsigned long args[LTTNG_SYSCALL_NR_ARGS]; lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(event, action_list, u.syscall.node) - fptr(event, args[0], args[1], args[2]); + lttng_hlist_for_each_entry_rcu(event_priv, action_list, u.syscall.node) + fptr(event_priv->pub, args[0], args[1], args[2]); break; } case 4: @@ -496,8 +211,8 @@ void syscall_entry_call_func(struct hlist_head *action_list, unsigned long args[LTTNG_SYSCALL_NR_ARGS]; lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(event, action_list, u.syscall.node) - fptr(event, args[0], args[1], args[2], args[3]); + lttng_hlist_for_each_entry_rcu(event_priv, action_list, u.syscall.node) + fptr(event_priv->pub, args[0], args[1], args[2], args[3]); break; } case 5: @@ -511,8 +226,8 @@ void syscall_entry_call_func(struct hlist_head *action_list, unsigned long args[LTTNG_SYSCALL_NR_ARGS]; lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(event, action_list, u.syscall.node) - fptr(event, args[0], args[1], args[2], args[3], args[4]); + lttng_hlist_for_each_entry_rcu(event_priv, action_list, u.syscall.node) + fptr(event_priv->pub, args[0], args[1], args[2], args[3], args[4]); break; } case 6: @@ -527,8 +242,8 @@ void syscall_entry_call_func(struct hlist_head *action_list, unsigned long args[LTTNG_SYSCALL_NR_ARGS]; lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(event, action_list, u.syscall.node) - fptr(event, args[0], args[1], args[2], + lttng_hlist_for_each_entry_rcu(event_priv, action_list, u.syscall.node) + fptr(event_priv->pub, args[0], args[1], args[2], args[3], args[4], args[5]); break; } @@ -537,135 +252,35 @@ void syscall_entry_call_func(struct hlist_head *action_list, } } -static __always_inline -void syscall_entry_event_notifier_call_func(struct hlist_head *dispatch_list, - void *func, unsigned int nrargs, struct pt_regs *regs) -{ - struct lttng_event_notifier *notifier; - - switch (nrargs) { - case 0: - { - void (*fptr)(void *__data) = func; - - lttng_hlist_for_each_entry_rcu(notifier, dispatch_list, u.syscall.node) - fptr(notifier); - break; - } - case 1: - { - void (*fptr)(void *__data, unsigned long arg0) = func; - unsigned long args[LTTNG_SYSCALL_NR_ARGS]; - - lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(notifier, dispatch_list, u.syscall.node) - fptr(notifier, args[0]); - break; - } - case 2: - { - void (*fptr)(void *__data, - unsigned long arg0, - unsigned long arg1) = func; - unsigned long args[LTTNG_SYSCALL_NR_ARGS]; - - lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(notifier, dispatch_list, u.syscall.node) - fptr(notifier, args[0], args[1]); - break; - } - case 3: - { - void (*fptr)(void *__data, - unsigned long arg0, - unsigned long arg1, - unsigned long arg2) = func; - unsigned long args[LTTNG_SYSCALL_NR_ARGS]; - - lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(notifier, dispatch_list, u.syscall.node) - fptr(notifier, args[0], args[1], args[2]); - break; - } - case 4: - { - void (*fptr)(void *__data, - unsigned long arg0, - unsigned long arg1, - unsigned long arg2, - unsigned long arg3) = func; - unsigned long args[LTTNG_SYSCALL_NR_ARGS]; - - lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(notifier, dispatch_list, u.syscall.node) - fptr(notifier, args[0], args[1], args[2], args[3]); - break; - } - case 5: - { - void (*fptr)(void *__data, - unsigned long arg0, - unsigned long arg1, - unsigned long arg2, - unsigned long arg3, - unsigned long arg4) = func; - unsigned long args[LTTNG_SYSCALL_NR_ARGS]; - - lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(notifier, dispatch_list, u.syscall.node) - fptr(notifier, args[0], args[1], args[2], args[3], args[4]); - break; - } - case 6: - { - void (*fptr)(void *__data, - unsigned long arg0, - unsigned long arg1, - unsigned long arg2, - unsigned long arg3, - unsigned long arg4, - unsigned long arg5) = func; - unsigned long args[LTTNG_SYSCALL_NR_ARGS]; - - lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(notifier, dispatch_list, u.syscall.node) - fptr(notifier, args[0], args[1], args[2], args[3], args[4], args[5]); - break; - } - default: - break; - } -} - void syscall_entry_event_probe(void *__data, struct pt_regs *regs, long id) { - struct lttng_channel *chan = __data; + struct lttng_kernel_syscall_table *syscall_table = __data; struct hlist_head *action_list, *unknown_action_list; const struct trace_syscall_entry *table, *entry; size_t table_len; if (unlikely(in_compat_syscall())) { - struct lttng_syscall_filter *filter = chan->sc_filter; + struct lttng_syscall_filter *filter = syscall_table->sc_filter; if (id < 0 || id >= NR_compat_syscalls - || (!READ_ONCE(chan->syscall_all_entry) && !test_bit(id, filter->sc_compat_entry))) { + || (!READ_ONCE(syscall_table->syscall_all_entry) && !test_bit(id, filter->sc_compat_entry))) { /* System call filtered out. */ return; } - table = compat_sc_table; - table_len = ARRAY_SIZE(compat_sc_table); - unknown_action_list = &chan->sc_compat_unknown; + table = compat_sc_table.table; + table_len = compat_sc_table.len; + unknown_action_list = &syscall_table->compat_unknown_syscall_dispatch; } else { - struct lttng_syscall_filter *filter = chan->sc_filter; + struct lttng_syscall_filter *filter = syscall_table->sc_filter; if (id < 0 || id >= NR_syscalls - || (!READ_ONCE(chan->syscall_all_entry) && !test_bit(id, filter->sc_entry))) { + || (!READ_ONCE(syscall_table->syscall_all_entry) && !test_bit(id, filter->sc_entry))) { /* System call filtered out. */ return; } - table = sc_table; - table_len = ARRAY_SIZE(sc_table); - unknown_action_list = &chan->sc_unknown; + table = sc_table.table; + table_len = sc_table.len; + unknown_action_list = &syscall_table->unknown_syscall_dispatch; } if (unlikely(id < 0 || id >= table_len)) { syscall_entry_event_unknown(unknown_action_list, regs, id); @@ -679,105 +294,46 @@ void syscall_entry_event_probe(void *__data, struct pt_regs *regs, long id) } if (unlikely(in_compat_syscall())) { - action_list = &chan->compat_sc_table[id]; + action_list = &syscall_table->compat_syscall_dispatch[id]; } else { - action_list = &chan->sc_table[id]; + action_list = &syscall_table->syscall_dispatch[id]; } if (unlikely(hlist_empty(action_list))) return; - syscall_entry_call_func(action_list, entry->event_func, entry->nrargs, regs); -} - -void syscall_entry_event_notifier_probe(void *__data, struct pt_regs *regs, - long id) -{ - struct lttng_event_notifier_group *group = __data; - const struct trace_syscall_entry *table, *entry; - struct hlist_head *dispatch_list, *unknown_dispatch_list; - size_t table_len; - - if (unlikely(in_compat_syscall())) { - struct lttng_syscall_filter *filter = group->sc_filter; - - if (id < 0 || id >= NR_compat_syscalls - || (!READ_ONCE(group->syscall_all_entry) && - !test_bit(id, filter->sc_compat_entry))) { - /* System call filtered out. */ - return; - } - table = compat_sc_table; - table_len = ARRAY_SIZE(compat_sc_table); - unknown_dispatch_list = &group->event_notifier_compat_unknown_syscall_dispatch; - } else { - struct lttng_syscall_filter *filter = group->sc_filter; - - if (id < 0 || id >= NR_syscalls - || (!READ_ONCE(group->syscall_all_entry) && - !test_bit(id, filter->sc_entry))) { - /* System call filtered out. */ - return; - } - table = sc_table; - table_len = ARRAY_SIZE(sc_table); - unknown_dispatch_list = &group->event_notifier_unknown_syscall_dispatch; - } - /* Check if the syscall id is out of bound. */ - if (unlikely(id < 0 || id >= table_len)) { - syscall_entry_event_notifier_unknown(unknown_dispatch_list, - regs, id); - return; - } - - entry = &table[id]; - if (!entry->event_notifier_func) { - syscall_entry_event_notifier_unknown(unknown_dispatch_list, - regs, id); - return; - } - - if (unlikely(in_compat_syscall())) { - dispatch_list = &group->event_notifier_compat_syscall_dispatch[id]; - } else { - dispatch_list = &group->event_notifier_syscall_dispatch[id]; - } - if (unlikely(hlist_empty(dispatch_list))) - return; - - syscall_entry_event_notifier_call_func(dispatch_list, - entry->event_notifier_func, entry->nrargs, regs); + syscall_entry_event_call_func(action_list, entry->event_func, entry->nrargs, regs); } static void syscall_exit_event_unknown(struct hlist_head *unknown_action_list_head, struct pt_regs *regs, long id, long ret) { unsigned long args[LTTNG_SYSCALL_NR_ARGS]; - struct lttng_event *event; + struct lttng_kernel_event_common_private *event_priv; lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(event, unknown_action_list_head, u.syscall.node) { + lttng_hlist_for_each_entry_rcu(event_priv, unknown_action_list_head, u.syscall.node) { if (unlikely(in_compat_syscall())) - __event_probe__compat_syscall_exit_unknown(event, id, ret, + __event_probe__compat_syscall_exit_unknown(event_priv->pub, id, ret, args); else - __event_probe__syscall_exit_unknown(event, id, ret, args); + __event_probe__syscall_exit_unknown(event_priv->pub, id, ret, args); } } static __always_inline -void syscall_exit_call_func(struct hlist_head *action_list, +void syscall_exit_event_call_func(struct hlist_head *action_list, void *func, unsigned int nrargs, struct pt_regs *regs, long ret) { - struct lttng_event *event; + struct lttng_kernel_event_common_private *event_priv; switch (nrargs) { case 0: { void (*fptr)(void *__data, long ret) = func; - lttng_hlist_for_each_entry_rcu(event, action_list, u.syscall.node) - fptr(event, ret); + lttng_hlist_for_each_entry_rcu(event_priv, action_list, u.syscall.node) + fptr(event_priv->pub, ret); break; } case 1: @@ -788,8 +344,8 @@ void syscall_exit_call_func(struct hlist_head *action_list, unsigned long args[LTTNG_SYSCALL_NR_ARGS]; lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(event, action_list, u.syscall.node) - fptr(event, ret, args[0]); + lttng_hlist_for_each_entry_rcu(event_priv, action_list, u.syscall.node) + fptr(event_priv->pub, ret, args[0]); break; } case 2: @@ -801,8 +357,8 @@ void syscall_exit_call_func(struct hlist_head *action_list, unsigned long args[LTTNG_SYSCALL_NR_ARGS]; lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(event, action_list, u.syscall.node) - fptr(event, ret, args[0], args[1]); + lttng_hlist_for_each_entry_rcu(event_priv, action_list, u.syscall.node) + fptr(event_priv->pub, ret, args[0], args[1]); break; } case 3: @@ -815,8 +371,8 @@ void syscall_exit_call_func(struct hlist_head *action_list, unsigned long args[LTTNG_SYSCALL_NR_ARGS]; lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(event, action_list, u.syscall.node) - fptr(event, ret, args[0], args[1], args[2]); + lttng_hlist_for_each_entry_rcu(event_priv, action_list, u.syscall.node) + fptr(event_priv->pub, ret, args[0], args[1], args[2]); break; } case 4: @@ -830,8 +386,8 @@ void syscall_exit_call_func(struct hlist_head *action_list, unsigned long args[LTTNG_SYSCALL_NR_ARGS]; lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(event, action_list, u.syscall.node) - fptr(event, ret, args[0], args[1], args[2], args[3]); + lttng_hlist_for_each_entry_rcu(event_priv, action_list, u.syscall.node) + fptr(event_priv->pub, ret, args[0], args[1], args[2], args[3]); break; } case 5: @@ -846,8 +402,8 @@ void syscall_exit_call_func(struct hlist_head *action_list, unsigned long args[LTTNG_SYSCALL_NR_ARGS]; lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(event, action_list, u.syscall.node) - fptr(event, ret, args[0], args[1], args[2], args[3], args[4]); + lttng_hlist_for_each_entry_rcu(event_priv, action_list, u.syscall.node) + fptr(event_priv->pub, ret, args[0], args[1], args[2], args[3], args[4]); break; } case 6: @@ -863,8 +419,8 @@ void syscall_exit_call_func(struct hlist_head *action_list, unsigned long args[LTTNG_SYSCALL_NR_ARGS]; lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(event, action_list, u.syscall.node) - fptr(event, ret, args[0], args[1], args[2], + lttng_hlist_for_each_entry_rcu(event_priv, action_list, u.syscall.node) + fptr(event_priv->pub, ret, args[0], args[1], args[2], args[3], args[4], args[5]); break; } @@ -875,7 +431,7 @@ void syscall_exit_call_func(struct hlist_head *action_list, void syscall_exit_event_probe(void *__data, struct pt_regs *regs, long ret) { - struct lttng_channel *chan = __data; + struct lttng_kernel_syscall_table *syscall_table = __data; struct hlist_head *action_list, *unknown_action_list; const struct trace_syscall_entry *table, *entry; size_t table_len; @@ -884,27 +440,27 @@ void syscall_exit_event_probe(void *__data, struct pt_regs *regs, long ret) id = syscall_get_nr(current, regs); if (unlikely(in_compat_syscall())) { - struct lttng_syscall_filter *filter = chan->sc_filter; + struct lttng_syscall_filter *filter = syscall_table->sc_filter; if (id < 0 || id >= NR_compat_syscalls - || (!READ_ONCE(chan->syscall_all_exit) && !test_bit(id, filter->sc_compat_exit))) { + || (!READ_ONCE(syscall_table->syscall_all_exit) && !test_bit(id, filter->sc_compat_exit))) { /* System call filtered out. */ return; } - table = compat_sc_exit_table; - table_len = ARRAY_SIZE(compat_sc_exit_table); - unknown_action_list = &chan->compat_sc_exit_unknown; + table = compat_sc_exit_table.table; + table_len = compat_sc_exit_table.len; + unknown_action_list = &syscall_table->compat_unknown_syscall_exit_dispatch; } else { - struct lttng_syscall_filter *filter = chan->sc_filter; + struct lttng_syscall_filter *filter = syscall_table->sc_filter; if (id < 0 || id >= NR_syscalls - || (!READ_ONCE(chan->syscall_all_exit) && !test_bit(id, filter->sc_exit))) { + || (!READ_ONCE(syscall_table->syscall_all_exit) && !test_bit(id, filter->sc_exit))) { /* System call filtered out. */ return; } - table = sc_exit_table; - table_len = ARRAY_SIZE(sc_exit_table); - unknown_action_list = &chan->sc_exit_unknown; + table = sc_exit_table.table; + table_len = sc_exit_table.len; + unknown_action_list = &syscall_table->unknown_syscall_exit_dispatch; } if (unlikely(id < 0 || id >= table_len)) { syscall_exit_event_unknown(unknown_action_list, regs, id, ret); @@ -918,202 +474,79 @@ void syscall_exit_event_probe(void *__data, struct pt_regs *regs, long ret) } if (unlikely(in_compat_syscall())) { - action_list = &chan->compat_sc_exit_table[id]; + action_list = &syscall_table->compat_syscall_exit_dispatch[id]; } else { - action_list = &chan->sc_exit_table[id]; + action_list = &syscall_table->syscall_exit_dispatch[id]; } if (unlikely(hlist_empty(action_list))) return; - syscall_exit_call_func(action_list, entry->event_func, entry->nrargs, + syscall_exit_event_call_func(action_list, entry->event_func, entry->nrargs, regs, ret); } -static __always_inline -void syscall_exit_event_notifier_call_func(struct hlist_head *dispatch_list, - void *func, unsigned int nrargs, struct pt_regs *regs, long ret) +static +struct lttng_kernel_syscall_table *get_syscall_table_from_enabler(struct lttng_event_enabler_common *event_enabler) { - struct lttng_event_notifier *notifier; - - switch (nrargs) { - case 0: - { - void (*fptr)(void *__data, long ret) = func; - - lttng_hlist_for_each_entry_rcu(notifier, dispatch_list, u.syscall.node) - fptr(notifier, ret); - break; - } - case 1: - { - void (*fptr)(void *__data, long ret, unsigned long arg0) = func; - unsigned long args[LTTNG_SYSCALL_NR_ARGS]; - - lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(notifier, dispatch_list, u.syscall.node) - fptr(notifier, ret, args[0]); - break; - } - case 2: - { - void (*fptr)(void *__data, - long ret, - unsigned long arg0, - unsigned long arg1) = func; - unsigned long args[LTTNG_SYSCALL_NR_ARGS]; - - lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(notifier, dispatch_list, u.syscall.node) - fptr(notifier, ret, args[0], args[1]); - break; - } - case 3: - { - void (*fptr)(void *__data, - long ret, - unsigned long arg0, - unsigned long arg1, - unsigned long arg2) = func; - unsigned long args[LTTNG_SYSCALL_NR_ARGS]; - - lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(notifier, dispatch_list, u.syscall.node) - fptr(notifier, ret, args[0], args[1], args[2]); - break; - } - case 4: - { - void (*fptr)(void *__data, - long ret, - unsigned long arg0, - unsigned long arg1, - unsigned long arg2, - unsigned long arg3) = func; - unsigned long args[LTTNG_SYSCALL_NR_ARGS]; - - lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(notifier, dispatch_list, u.syscall.node) - fptr(notifier, ret, args[0], args[1], args[2], args[3]); - break; - } - case 5: + switch (event_enabler->enabler_type) { + case LTTNG_EVENT_ENABLER_TYPE_RECORDER: { - void (*fptr)(void *__data, - long ret, - unsigned long arg0, - unsigned long arg1, - unsigned long arg2, - unsigned long arg3, - unsigned long arg4) = func; - unsigned long args[LTTNG_SYSCALL_NR_ARGS]; - - lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(notifier, dispatch_list, u.syscall.node) - fptr(notifier, ret, args[0], args[1], args[2], args[3], args[4]); - break; + struct lttng_event_recorder_enabler *event_recorder_enabler = + container_of(event_enabler, struct lttng_event_recorder_enabler, parent); + return &event_recorder_enabler->chan->priv->parent.syscall_table; } - case 6: + case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER: { - void (*fptr)(void *__data, - long ret, - unsigned long arg0, - unsigned long arg1, - unsigned long arg2, - unsigned long arg3, - unsigned long arg4, - unsigned long arg5) = func; - unsigned long args[LTTNG_SYSCALL_NR_ARGS]; - - lttng_syscall_get_arguments(current, regs, args); - lttng_hlist_for_each_entry_rcu(notifier, dispatch_list, u.syscall.node) - fptr(notifier, ret, args[0], args[1], args[2], args[3], args[4], args[5]); - break; + struct lttng_event_notifier_enabler *event_notifier_enabler = + container_of(event_enabler, struct lttng_event_notifier_enabler, parent); + return &event_notifier_enabler->group->syscall_table; } default: - break; + return NULL; } } static -void syscall_exit_event_notifier_probe(void *__data, struct pt_regs *regs, - long ret) +struct lttng_kernel_syscall_table *get_syscall_table_from_event(struct lttng_kernel_event_common *event) { - struct lttng_event_notifier_group *group = __data; - const struct trace_syscall_entry *table, *entry; - struct hlist_head *dispatch_list, *unknown_dispatch_list; - size_t table_len; - long id; - - id = syscall_get_nr(current, regs); - - if (unlikely(in_compat_syscall())) { - struct lttng_syscall_filter *filter = group->sc_filter; - - if (id < 0 || id >= NR_compat_syscalls - || (!READ_ONCE(group->syscall_all_exit) && - !test_bit(id, filter->sc_compat_exit))) { - /* System call filtered out. */ - return; - } - table = compat_sc_exit_table; - table_len = ARRAY_SIZE(compat_sc_exit_table); - unknown_dispatch_list = &group->event_notifier_exit_compat_unknown_syscall_dispatch; - } else { - struct lttng_syscall_filter *filter = group->sc_filter; - - if (id < 0 || id >= NR_syscalls - || (!READ_ONCE(group->syscall_all_exit) && - !test_bit(id, filter->sc_exit))) { - /* System call filtered out. */ - return; - } - table = sc_exit_table; - table_len = ARRAY_SIZE(sc_exit_table); - unknown_dispatch_list = &group->event_notifier_exit_unknown_syscall_dispatch; - } - /* Check if the syscall id is out of bound. */ - if (unlikely(id < 0 || id >= table_len)) { - syscall_exit_event_notifier_unknown(unknown_dispatch_list, - regs, id, ret); - return; + switch (event->type) { + case LTTNG_KERNEL_EVENT_TYPE_RECORDER: + { + struct lttng_kernel_event_recorder *event_recorder = + container_of(event, struct lttng_kernel_event_recorder, parent); + return &event_recorder->chan->priv->parent.syscall_table; } - - entry = &table[id]; - if (!entry->event_notifier_func) { - syscall_entry_event_notifier_unknown(unknown_dispatch_list, - regs, id); - return; + case LTTNG_KERNEL_EVENT_TYPE_NOTIFIER: + { + struct lttng_kernel_event_notifier *event_notifier = + container_of(event, struct lttng_kernel_event_notifier, parent); + return &event_notifier->priv->group->syscall_table; } - - if (unlikely(in_compat_syscall())) { - dispatch_list = &group->event_notifier_exit_compat_syscall_dispatch[id]; - } else { - dispatch_list = &group->event_notifier_exit_syscall_dispatch[id]; + default: + return NULL; } - if (unlikely(hlist_empty(dispatch_list))) - return; - - syscall_exit_event_notifier_call_func(dispatch_list, - entry->event_notifier_func, entry->nrargs, regs, ret); } + /* * noinline to diminish caller stack size. * Should be called with sessions lock held. */ static int lttng_create_syscall_event_if_missing(const struct trace_syscall_entry *table, size_t table_len, - struct hlist_head *chan_table, struct lttng_event_enabler *event_enabler, - void *filter, enum sc_type type) + struct hlist_head *chan_table, struct lttng_event_recorder_enabler *syscall_event_enabler, + enum sc_type type) { - struct lttng_channel *chan = event_enabler->chan; - struct lttng_session *session = chan->session; + struct lttng_event_ht *events_ht = lttng_get_event_ht_from_enabler(&syscall_event_enabler->parent); + struct lttng_kernel_channel_buffer *chan = syscall_event_enabler->chan; unsigned int i; /* Allocate events for each syscall matching enabler, insert into table */ for (i = 0; i < table_len; i++) { const struct lttng_kernel_event_desc *desc = table[i].desc; + struct lttng_event_recorder_enabler *event_enabler; struct lttng_kernel_abi_event ev; - struct lttng_event *event; + struct lttng_kernel_event_common *event; + struct lttng_kernel_event_common_private *event_priv; struct hlist_head *head; bool found = false; @@ -1121,18 +554,15 @@ int lttng_create_syscall_event_if_missing(const struct trace_syscall_entry *tabl /* Unknown syscall */ continue; } - if (lttng_desc_match_enabler(desc, - lttng_event_enabler_as_enabler(event_enabler)) <= 0) + if (!lttng_desc_match_enabler(desc, + lttng_event_recorder_enabler_as_enabler(syscall_event_enabler))) continue; /* * Check if already created. */ - head = utils_borrow_hash_table_bucket( - session->events_ht.table, LTTNG_EVENT_HT_SIZE, - desc->event_name); - lttng_hlist_for_each_entry(event, head, hlist) { - if (event->desc == desc - && event->chan == event_enabler->chan) + head = utils_borrow_hash_table_bucket(events_ht->table, LTTNG_EVENT_HT_SIZE, desc->event_name); + lttng_hlist_for_each_entry(event_priv, head, hlist_node) { + if (lttng_event_enabler_desc_match_event(&syscall_event_enabler->parent, desc, event_priv->pub)) found = true; } if (found) @@ -1161,9 +591,13 @@ int lttng_create_syscall_event_if_missing(const struct trace_syscall_entry *tabl strncpy(ev.name, desc->event_name, LTTNG_KERNEL_ABI_SYM_NAME_LEN - 1); ev.name[LTTNG_KERNEL_ABI_SYM_NAME_LEN - 1] = '\0'; ev.instrumentation = LTTNG_KERNEL_ABI_SYSCALL; - event = _lttng_event_create(chan, &ev, filter, - desc, ev.instrumentation); + event_enabler = lttng_event_recorder_enabler_create(LTTNG_ENABLER_FORMAT_NAME, &ev, chan); + if (!event_enabler) { + return -ENOMEM; + } + event = _lttng_kernel_event_create(&event_enabler->parent, desc); WARN_ON_ONCE(!event); + lttng_event_enabler_destroy(&event_enabler->parent); if (IS_ERR(event)) { /* * If something goes wrong in event registration @@ -1173,59 +607,30 @@ int lttng_create_syscall_event_if_missing(const struct trace_syscall_entry *tabl */ return PTR_ERR(event); } - hlist_add_head(&event->u.syscall.node, &chan_table[i]); + hlist_add_head(&event->priv->u.syscall.node, &chan_table[i]); } return 0; } -/* - * Should be called with sessions lock held. - */ -int lttng_syscalls_register_event(struct lttng_event_enabler *event_enabler, void *filter) +static +int lttng_syscalls_populate_events(struct lttng_event_enabler_common *syscall_event_enabler) { - struct lttng_channel *chan = event_enabler->chan; + struct lttng_kernel_syscall_table *syscall_table = get_syscall_table_from_enabler(syscall_event_enabler); + struct lttng_event_recorder_enabler *event_recorder_enabler; + struct lttng_kernel_channel_buffer *chan; struct lttng_kernel_abi_event ev; int ret; - wrapper_vmalloc_sync_mappings(); - - if (!chan->sc_table) { - /* create syscall table mapping syscall to events */ - chan->sc_table = kzalloc(sizeof(struct lttng_event *) - * ARRAY_SIZE(sc_table), GFP_KERNEL); - if (!chan->sc_table) - return -ENOMEM; - } - if (!chan->sc_exit_table) { - /* create syscall table mapping syscall to events */ - chan->sc_exit_table = kzalloc(sizeof(struct lttng_event *) - * ARRAY_SIZE(sc_exit_table), GFP_KERNEL); - if (!chan->sc_exit_table) - return -ENOMEM; - } - - -#ifdef CONFIG_COMPAT - if (!chan->compat_sc_table) { - /* create syscall table mapping compat syscall to events */ - chan->compat_sc_table = kzalloc(sizeof(struct lttng_event *) - * ARRAY_SIZE(compat_sc_table), GFP_KERNEL); - if (!chan->compat_sc_table) - return -ENOMEM; - } + if (syscall_event_enabler->enabler_type != LTTNG_EVENT_ENABLER_TYPE_RECORDER) + return 0; + event_recorder_enabler = container_of(syscall_event_enabler, struct lttng_event_recorder_enabler, parent); + chan = event_recorder_enabler->chan; - if (!chan->compat_sc_exit_table) { - /* create syscall table mapping compat syscall to events */ - chan->compat_sc_exit_table = kzalloc(sizeof(struct lttng_event *) - * ARRAY_SIZE(compat_sc_exit_table), GFP_KERNEL); - if (!chan->compat_sc_exit_table) - return -ENOMEM; - } -#endif - if (hlist_empty(&chan->sc_unknown)) { + if (hlist_empty(&syscall_table->unknown_syscall_dispatch)) { const struct lttng_kernel_event_desc *desc = &__event_desc___syscall_entry_unknown; - struct lttng_event *event; + struct lttng_kernel_event_common *event; + struct lttng_event_recorder_enabler *event_enabler; memset(&ev, 0, sizeof(ev)); strncpy(ev.name, desc->event_name, LTTNG_KERNEL_ABI_SYM_NAME_LEN); @@ -1233,19 +638,24 @@ int lttng_syscalls_register_event(struct lttng_event_enabler *event_enabler, voi ev.instrumentation = LTTNG_KERNEL_ABI_SYSCALL; ev.u.syscall.entryexit = LTTNG_KERNEL_ABI_SYSCALL_ENTRY; ev.u.syscall.abi = LTTNG_KERNEL_ABI_SYSCALL_ABI_NATIVE; - event = _lttng_event_create(chan, &ev, filter, desc, - ev.instrumentation); + event_enabler = lttng_event_recorder_enabler_create(LTTNG_ENABLER_FORMAT_NAME, &ev, chan); + if (!event_enabler) { + return -ENOMEM; + } + event = _lttng_kernel_event_create(&event_enabler->parent, desc); + lttng_event_enabler_destroy(&event_enabler->parent); WARN_ON_ONCE(!event); if (IS_ERR(event)) { return PTR_ERR(event); } - hlist_add_head(&event->u.syscall.node, &chan->sc_unknown); + hlist_add_head(&event->priv->u.syscall.node, &syscall_table->unknown_syscall_dispatch); } - if (hlist_empty(&chan->sc_compat_unknown)) { + if (hlist_empty(&syscall_table->compat_unknown_syscall_dispatch)) { const struct lttng_kernel_event_desc *desc = &__event_desc___compat_syscall_entry_unknown; - struct lttng_event *event; + struct lttng_kernel_event_common *event; + struct lttng_event_recorder_enabler *event_enabler; memset(&ev, 0, sizeof(ev)); strncpy(ev.name, desc->event_name, LTTNG_KERNEL_ABI_SYM_NAME_LEN); @@ -1253,19 +663,24 @@ int lttng_syscalls_register_event(struct lttng_event_enabler *event_enabler, voi ev.instrumentation = LTTNG_KERNEL_ABI_SYSCALL; ev.u.syscall.entryexit = LTTNG_KERNEL_ABI_SYSCALL_ENTRY; ev.u.syscall.abi = LTTNG_KERNEL_ABI_SYSCALL_ABI_COMPAT; - event = _lttng_event_create(chan, &ev, filter, desc, - ev.instrumentation); + event_enabler = lttng_event_recorder_enabler_create(LTTNG_ENABLER_FORMAT_NAME, &ev, chan); + if (!event_enabler) { + return -ENOMEM; + } + event = _lttng_kernel_event_create(&event_enabler->parent, desc); WARN_ON_ONCE(!event); + lttng_event_enabler_destroy(&event_enabler->parent); if (IS_ERR(event)) { return PTR_ERR(event); } - hlist_add_head(&event->u.syscall.node, &chan->sc_compat_unknown); + hlist_add_head(&event->priv->u.syscall.node, &syscall_table->compat_unknown_syscall_dispatch); } - if (hlist_empty(&chan->compat_sc_exit_unknown)) { + if (hlist_empty(&syscall_table->compat_unknown_syscall_exit_dispatch)) { const struct lttng_kernel_event_desc *desc = &__event_desc___compat_syscall_exit_unknown; - struct lttng_event *event; + struct lttng_kernel_event_common *event; + struct lttng_event_recorder_enabler *event_enabler; memset(&ev, 0, sizeof(ev)); strncpy(ev.name, desc->event_name, LTTNG_KERNEL_ABI_SYM_NAME_LEN); @@ -1273,19 +688,24 @@ int lttng_syscalls_register_event(struct lttng_event_enabler *event_enabler, voi ev.instrumentation = LTTNG_KERNEL_ABI_SYSCALL; ev.u.syscall.entryexit = LTTNG_KERNEL_ABI_SYSCALL_EXIT; ev.u.syscall.abi = LTTNG_KERNEL_ABI_SYSCALL_ABI_COMPAT; - event = _lttng_event_create(chan, &ev, filter, desc, - ev.instrumentation); + event_enabler = lttng_event_recorder_enabler_create(LTTNG_ENABLER_FORMAT_NAME, &ev, chan); + if (!event_enabler) { + return -ENOMEM; + } + event = _lttng_kernel_event_create(&event_enabler->parent, desc); WARN_ON_ONCE(!event); + lttng_event_enabler_destroy(&event_enabler->parent); if (IS_ERR(event)) { return PTR_ERR(event); } - hlist_add_head(&event->u.syscall.node, &chan->compat_sc_exit_unknown); + hlist_add_head(&event->priv->u.syscall.node, &syscall_table->compat_unknown_syscall_exit_dispatch); } - if (hlist_empty(&chan->sc_exit_unknown)) { + if (hlist_empty(&syscall_table->unknown_syscall_exit_dispatch)) { const struct lttng_kernel_event_desc *desc = &__event_desc___syscall_exit_unknown; - struct lttng_event *event; + struct lttng_kernel_event_common *event; + struct lttng_event_recorder_enabler *event_enabler; memset(&ev, 0, sizeof(ev)); strncpy(ev.name, desc->event_name, LTTNG_KERNEL_ABI_SYM_NAME_LEN); @@ -1293,169 +713,111 @@ int lttng_syscalls_register_event(struct lttng_event_enabler *event_enabler, voi ev.instrumentation = LTTNG_KERNEL_ABI_SYSCALL; ev.u.syscall.entryexit = LTTNG_KERNEL_ABI_SYSCALL_EXIT; ev.u.syscall.abi = LTTNG_KERNEL_ABI_SYSCALL_ABI_NATIVE; - event = _lttng_event_create(chan, &ev, filter, desc, - ev.instrumentation); + event_enabler = lttng_event_recorder_enabler_create(LTTNG_ENABLER_FORMAT_NAME, &ev, chan); + if (!event_enabler) { + return -ENOMEM; + } + event = _lttng_kernel_event_create(&event_enabler->parent, desc); WARN_ON_ONCE(!event); + lttng_event_enabler_destroy(&event_enabler->parent); if (IS_ERR(event)) { return PTR_ERR(event); } - hlist_add_head(&event->u.syscall.node, &chan->sc_exit_unknown); + hlist_add_head(&event->priv->u.syscall.node, &syscall_table->unknown_syscall_exit_dispatch); } - ret = lttng_create_syscall_event_if_missing(sc_table, ARRAY_SIZE(sc_table), - chan->sc_table, event_enabler, filter, SC_TYPE_ENTRY); + ret = lttng_create_syscall_event_if_missing(sc_table.table, sc_table.len, + syscall_table->syscall_dispatch, event_recorder_enabler, SC_TYPE_ENTRY); if (ret) return ret; - ret = lttng_create_syscall_event_if_missing(sc_exit_table, ARRAY_SIZE(sc_exit_table), - chan->sc_exit_table, event_enabler, filter, SC_TYPE_EXIT); + ret = lttng_create_syscall_event_if_missing(sc_exit_table.table, sc_exit_table.len, + syscall_table->syscall_exit_dispatch, event_recorder_enabler, SC_TYPE_EXIT); if (ret) return ret; #ifdef CONFIG_COMPAT - ret = lttng_create_syscall_event_if_missing(compat_sc_table, ARRAY_SIZE(compat_sc_table), - chan->compat_sc_table, event_enabler, filter, - SC_TYPE_COMPAT_ENTRY); + ret = lttng_create_syscall_event_if_missing(compat_sc_table.table, compat_sc_table.len, + syscall_table->compat_syscall_dispatch, event_recorder_enabler, SC_TYPE_COMPAT_ENTRY); if (ret) return ret; - ret = lttng_create_syscall_event_if_missing(compat_sc_exit_table, ARRAY_SIZE(compat_sc_exit_table), - chan->compat_sc_exit_table, event_enabler, filter, - SC_TYPE_COMPAT_EXIT); + ret = lttng_create_syscall_event_if_missing(compat_sc_exit_table.table, compat_sc_exit_table.len, + syscall_table->compat_syscall_exit_dispatch, event_recorder_enabler, SC_TYPE_COMPAT_EXIT); if (ret) return ret; #endif - - if (!chan->sc_filter) { - chan->sc_filter = kzalloc(sizeof(struct lttng_syscall_filter), - GFP_KERNEL); - if (!chan->sc_filter) - return -ENOMEM; - } - - if (!chan->sys_enter_registered) { - ret = lttng_wrapper_tracepoint_probe_register("sys_enter", - (void *) syscall_entry_event_probe, chan); - if (ret) - return ret; - chan->sys_enter_registered = 1; - } - /* - * We change the name of sys_exit tracepoint due to namespace - * conflict with sys_exit syscall entry. - */ - if (!chan->sys_exit_registered) { - ret = lttng_wrapper_tracepoint_probe_register("sys_exit", - (void *) syscall_exit_event_probe, chan); - if (ret) { - WARN_ON_ONCE(lttng_wrapper_tracepoint_probe_unregister("sys_enter", - (void *) syscall_entry_event_probe, chan)); - return ret; - } - chan->sys_exit_registered = 1; - } return ret; } /* * Should be called with sessions lock held. */ -int lttng_syscalls_register_event_notifier( - struct lttng_event_notifier_enabler *event_notifier_enabler, - void *filter) +int lttng_event_enabler_create_syscall_events_if_missing(struct lttng_event_enabler_common *syscall_event_enabler) { - struct lttng_event_notifier_group *group = event_notifier_enabler->group; - unsigned int i; - int ret = 0; - - wrapper_vmalloc_sync_mappings(); + struct lttng_kernel_syscall_table *syscall_table = get_syscall_table_from_enabler(syscall_event_enabler); + int ret; - if (!group->event_notifier_syscall_dispatch) { - group->event_notifier_syscall_dispatch = - kzalloc(sizeof(struct hlist_head) * ARRAY_SIZE(sc_table), - GFP_KERNEL); - if (!group->event_notifier_syscall_dispatch) + if (!syscall_table->syscall_dispatch) { + /* create syscall table mapping syscall to events */ + syscall_table->syscall_dispatch = kzalloc(sizeof(struct hlist_head) * sc_table.len, GFP_KERNEL); + if (!syscall_table->syscall_dispatch) return -ENOMEM; - - /* Initialize all list_head */ - for (i = 0; i < ARRAY_SIZE(sc_table); i++) - INIT_HLIST_HEAD(&group->event_notifier_syscall_dispatch[i]); - - /* Init the unknown syscall notifier list. */ - INIT_HLIST_HEAD(&group->event_notifier_unknown_syscall_dispatch); } - - if (!group->event_notifier_exit_syscall_dispatch) { - group->event_notifier_exit_syscall_dispatch = - kzalloc(sizeof(struct hlist_head) * ARRAY_SIZE(sc_table), - GFP_KERNEL); - if (!group->event_notifier_exit_syscall_dispatch) + if (!syscall_table->syscall_exit_dispatch) { + /* create syscall table mapping syscall to events */ + syscall_table->syscall_exit_dispatch = kzalloc(sizeof(struct hlist_head) * sc_exit_table.len, GFP_KERNEL); + if (!syscall_table->syscall_exit_dispatch) return -ENOMEM; - - /* Initialize all list_head */ - for (i = 0; i < ARRAY_SIZE(sc_table); i++) - INIT_HLIST_HEAD(&group->event_notifier_exit_syscall_dispatch[i]); - - /* Init the unknown exit syscall notifier list. */ - INIT_HLIST_HEAD(&group->event_notifier_exit_unknown_syscall_dispatch); } + #ifdef CONFIG_COMPAT - if (!group->event_notifier_compat_syscall_dispatch) { - group->event_notifier_compat_syscall_dispatch = - kzalloc(sizeof(struct hlist_head) * ARRAY_SIZE(compat_sc_table), - GFP_KERNEL); - if (!group->event_notifier_syscall_dispatch) + if (!syscall_table->compat_syscall_dispatch) { + /* create syscall table mapping compat syscall to events */ + syscall_table->compat_syscall_dispatch = kzalloc(sizeof(struct hlist_head) * compat_sc_table.len, GFP_KERNEL); + if (!syscall_table->compat_syscall_dispatch) return -ENOMEM; - - /* Initialize all list_head */ - for (i = 0; i < ARRAY_SIZE(compat_sc_table); i++) - INIT_HLIST_HEAD(&group->event_notifier_compat_syscall_dispatch[i]); - - /* Init the unknown syscall notifier list. */ - INIT_HLIST_HEAD(&group->event_notifier_compat_unknown_syscall_dispatch); } - if (!group->event_notifier_exit_compat_syscall_dispatch) { - group->event_notifier_exit_compat_syscall_dispatch = - kzalloc(sizeof(struct hlist_head) * ARRAY_SIZE(compat_sc_exit_table), - GFP_KERNEL); - if (!group->event_notifier_exit_syscall_dispatch) + if (!syscall_table->compat_syscall_exit_dispatch) { + /* create syscall table mapping compat syscall to events */ + syscall_table->compat_syscall_exit_dispatch = kzalloc(sizeof(struct hlist_head) * compat_sc_exit_table.len, GFP_KERNEL); + if (!syscall_table->compat_syscall_exit_dispatch) return -ENOMEM; - - /* Initialize all list_head */ - for (i = 0; i < ARRAY_SIZE(compat_sc_exit_table); i++) - INIT_HLIST_HEAD(&group->event_notifier_exit_compat_syscall_dispatch[i]); - - /* Init the unknown exit syscall notifier list. */ - INIT_HLIST_HEAD(&group->event_notifier_exit_compat_unknown_syscall_dispatch); } #endif - - if (!group->sc_filter) { - group->sc_filter = kzalloc(sizeof(struct lttng_syscall_filter), + if (!syscall_table->sc_filter) { + syscall_table->sc_filter = kzalloc(sizeof(struct lttng_syscall_filter), GFP_KERNEL); - if (!group->sc_filter) + if (!syscall_table->sc_filter) return -ENOMEM; } - if (!group->sys_enter_registered) { + ret = lttng_syscalls_populate_events(syscall_event_enabler); + if (ret) + return ret; + + if (!syscall_table->sys_enter_registered) { ret = lttng_wrapper_tracepoint_probe_register("sys_enter", - (void *) syscall_entry_event_notifier_probe, group); + (void *) syscall_entry_event_probe, syscall_table); if (ret) return ret; - group->sys_enter_registered = 1; + syscall_table->sys_enter_registered = 1; } - - if (!group->sys_exit_registered) { + if (!syscall_table->sys_exit_registered) { ret = lttng_wrapper_tracepoint_probe_register("sys_exit", - (void *) syscall_exit_event_notifier_probe, group); + (void *) syscall_exit_event_probe, syscall_table); if (ret) { WARN_ON_ONCE(lttng_wrapper_tracepoint_probe_unregister("sys_enter", - (void *) syscall_entry_event_notifier_probe, group)); + (void *) syscall_entry_event_probe, syscall_table)); return ret; } - group->sys_exit_registered = 1; + syscall_table->sys_exit_registered = 1; } + ret = lttng_syscalls_create_matching_event_notifiers(syscall_event_enabler); + if (ret) + return ret; + return ret; } @@ -1464,13 +826,16 @@ int create_unknown_event_notifier( struct lttng_event_notifier_enabler *event_notifier_enabler, enum sc_type type) { - struct lttng_event_notifier *notifier; + struct lttng_event_ht *events_ht = lttng_get_event_ht_from_enabler(&event_notifier_enabler->parent); + struct lttng_kernel_event_common_private *event_priv; + struct lttng_kernel_event_common *event; const struct lttng_kernel_event_desc *desc; struct lttng_event_notifier_group *group = event_notifier_enabler->group; + struct lttng_kernel_syscall_table *syscall_table = &group->syscall_table; struct lttng_kernel_abi_event_notifier event_notifier_param; - uint64_t user_token = event_notifier_enabler->base.user_token; + uint64_t user_token = event_notifier_enabler->parent.user_token; uint64_t error_counter_index = event_notifier_enabler->error_counter_index; - struct lttng_enabler *base_enabler = lttng_event_notifier_enabler_as_enabler( + struct lttng_event_enabler_common *base_enabler = lttng_event_notifier_enabler_as_enabler( event_notifier_enabler); struct hlist_head *unknown_dispatch_list; int ret = 0; @@ -1482,25 +847,25 @@ int create_unknown_event_notifier( switch (type) { case SC_TYPE_ENTRY: desc = &__event_desc___syscall_entry_unknown; - unknown_dispatch_list = &group->event_notifier_unknown_syscall_dispatch; + unknown_dispatch_list = &syscall_table->unknown_syscall_dispatch; entryexit = LTTNG_KERNEL_ABI_SYSCALL_ENTRY; abi = LTTNG_KERNEL_ABI_SYSCALL_ABI_NATIVE; break; case SC_TYPE_EXIT: desc = &__event_desc___syscall_exit_unknown; - unknown_dispatch_list = &group->event_notifier_exit_unknown_syscall_dispatch; + unknown_dispatch_list = &syscall_table->unknown_syscall_exit_dispatch; entryexit = LTTNG_KERNEL_ABI_SYSCALL_EXIT; abi = LTTNG_KERNEL_ABI_SYSCALL_ABI_NATIVE; break; case SC_TYPE_COMPAT_ENTRY: desc = &__event_desc___compat_syscall_entry_unknown; - unknown_dispatch_list = &group->event_notifier_compat_unknown_syscall_dispatch; + unknown_dispatch_list = &syscall_table->compat_unknown_syscall_dispatch; entryexit = LTTNG_KERNEL_ABI_SYSCALL_ENTRY; abi = LTTNG_KERNEL_ABI_SYSCALL_ABI_COMPAT; break; case SC_TYPE_COMPAT_EXIT: desc = &__event_desc___compat_syscall_exit_unknown; - unknown_dispatch_list = &group->event_notifier_exit_compat_unknown_syscall_dispatch; + unknown_dispatch_list = &syscall_table->compat_unknown_syscall_exit_dispatch; entryexit = LTTNG_KERNEL_ABI_SYSCALL_EXIT; abi = LTTNG_KERNEL_ABI_SYSCALL_ABI_COMPAT; break; @@ -1511,11 +876,9 @@ int create_unknown_event_notifier( /* * Check if already created. */ - head = utils_borrow_hash_table_bucket(group->event_notifiers_ht.table, - LTTNG_EVENT_NOTIFIER_HT_SIZE, desc->event_name); - lttng_hlist_for_each_entry(notifier, head, hlist) { - if (notifier->desc == desc && - notifier->user_token == base_enabler->user_token) + head = utils_borrow_hash_table_bucket(events_ht->table, LTTNG_EVENT_HT_SIZE, desc->event_name); + lttng_hlist_for_each_entry(event_priv, head, hlist_node) { + if (lttng_event_enabler_desc_match_event(base_enabler, desc, event_priv->pub)) found = true; } if (found) @@ -1528,40 +891,47 @@ int create_unknown_event_notifier( event_notifier_param.event.name[LTTNG_KERNEL_ABI_SYM_NAME_LEN - 1] = '\0'; event_notifier_param.event.instrumentation = LTTNG_KERNEL_ABI_SYSCALL; + event_notifier_param.event.token = user_token; event_notifier_param.event.u.syscall.abi = abi; event_notifier_param.event.u.syscall.entryexit = entryexit; - - notifier = _lttng_event_notifier_create(desc, user_token, - error_counter_index, group, &event_notifier_param, NULL, - event_notifier_param.event.instrumentation); - if (IS_ERR(notifier)) { + event_notifier_param.error_counter_index = error_counter_index; + + event_notifier_enabler = lttng_event_notifier_enabler_create(LTTNG_ENABLER_FORMAT_NAME, + &event_notifier_param, group); + WARN_ON_ONCE(!event_notifier_enabler); + event = _lttng_kernel_event_create(&event_notifier_enabler->parent, desc); + lttng_event_enabler_destroy(&event_notifier_enabler->parent); + if (IS_ERR(event)) { printk(KERN_INFO "Unable to create unknown notifier %s\n", desc->event_name); ret = -ENOMEM; goto end; } - hlist_add_head_rcu(¬ifier->u.syscall.node, unknown_dispatch_list); + hlist_add_head_rcu(&event->priv->u.syscall.node, unknown_dispatch_list); end: return ret; } static int create_matching_event_notifiers( - struct lttng_event_notifier_enabler *event_notifier_enabler, - void *filter, const struct trace_syscall_entry *table, + struct lttng_event_notifier_enabler *syscall_event_notifier_enabler, + const struct trace_syscall_entry *table, size_t table_len, enum sc_type type) { - struct lttng_event_notifier_group *group = event_notifier_enabler->group; + struct lttng_event_ht *events_ht = lttng_get_event_ht_from_enabler(&syscall_event_notifier_enabler->parent); + struct lttng_event_notifier_group *group = syscall_event_notifier_enabler->group; const struct lttng_kernel_event_desc *desc; - uint64_t user_token = event_notifier_enabler->base.user_token; - uint64_t error_counter_index = event_notifier_enabler->error_counter_index; + uint64_t user_token = syscall_event_notifier_enabler->parent.user_token; + uint64_t error_counter_index = syscall_event_notifier_enabler->error_counter_index; unsigned int i; int ret = 0; /* iterate over all syscall and create event_notifier that match */ for (i = 0; i < table_len; i++) { - struct lttng_event_notifier *event_notifier; + struct lttng_event_notifier_enabler *event_notifier_enabler; + struct lttng_kernel_event_common_private *event_priv; + struct lttng_kernel_event_common *event; struct lttng_kernel_abi_event_notifier event_notifier_param; struct hlist_head *head; int found = 0; @@ -1573,17 +943,15 @@ static int create_matching_event_notifiers( } if (!lttng_desc_match_enabler(desc, - lttng_event_notifier_enabler_as_enabler(event_notifier_enabler))) + lttng_event_notifier_enabler_as_enabler(syscall_event_notifier_enabler))) continue; /* * Check if already created. */ - head = utils_borrow_hash_table_bucket(group->event_notifiers_ht.table, - LTTNG_EVENT_NOTIFIER_HT_SIZE, desc->event_name); - lttng_hlist_for_each_entry(event_notifier, head, hlist) { - if (event_notifier->desc == desc - && event_notifier->user_token == event_notifier_enabler->base.user_token) + head = utils_borrow_hash_table_bucket(events_ht->table, LTTNG_EVENT_HT_SIZE, desc->event_name); + lttng_hlist_for_each_entry(event_priv, head, hlist_node) { + if (lttng_event_enabler_desc_match_event(&syscall_event_notifier_enabler->parent, desc, event_priv->pub)) found = 1; } if (found) @@ -1612,18 +980,22 @@ static int create_matching_event_notifiers( LTTNG_KERNEL_ABI_SYM_NAME_LEN - strlen(event_notifier_param.event.name) - 1); event_notifier_param.event.name[LTTNG_KERNEL_ABI_SYM_NAME_LEN - 1] = '\0'; event_notifier_param.event.instrumentation = LTTNG_KERNEL_ABI_SYSCALL; - - event_notifier = _lttng_event_notifier_create(desc, user_token, - error_counter_index, group, &event_notifier_param, - filter, event_notifier_param.event.instrumentation); - if (IS_ERR(event_notifier)) { + event_notifier_param.event.token = user_token; + event_notifier_param.error_counter_index = error_counter_index; + + event_notifier_enabler = lttng_event_notifier_enabler_create(LTTNG_ENABLER_FORMAT_NAME, + &event_notifier_param, group); + WARN_ON_ONCE(!event_notifier_enabler); + event = _lttng_kernel_event_create(&event_notifier_enabler->parent, desc); + lttng_event_enabler_destroy(&event_notifier_enabler->parent); + if (IS_ERR(event)) { printk(KERN_INFO "Unable to create event_notifier %s\n", desc->event_name); ret = -ENOMEM; goto end; } - event_notifier->u.syscall.syscall_id = i; + event->priv->u.syscall.syscall_id = i; } end: @@ -1631,24 +1003,26 @@ end: } -int lttng_syscals_create_matching_event_notifiers( - struct lttng_event_notifier_enabler *event_notifier_enabler, - void *filter) +static +int lttng_syscalls_create_matching_event_notifiers(struct lttng_event_enabler_common *event_enabler) { int ret; - struct lttng_enabler *base_enabler = - lttng_event_notifier_enabler_as_enabler(event_notifier_enabler); enum lttng_kernel_abi_syscall_entryexit entryexit = - base_enabler->event_param.u.syscall.entryexit; + event_enabler->event_param.u.syscall.entryexit; + struct lttng_event_notifier_enabler *event_notifier_enabler; + + if (event_enabler->enabler_type != LTTNG_EVENT_ENABLER_TYPE_NOTIFIER) + return 0; + event_notifier_enabler = container_of(event_enabler, struct lttng_event_notifier_enabler, parent); if (entryexit == LTTNG_KERNEL_ABI_SYSCALL_ENTRY || entryexit == LTTNG_KERNEL_ABI_SYSCALL_ENTRYEXIT) { ret = create_matching_event_notifiers(event_notifier_enabler, - filter, sc_table, ARRAY_SIZE(sc_table), SC_TYPE_ENTRY); + sc_table.table, sc_table.len, SC_TYPE_ENTRY); if (ret) goto end; ret = create_matching_event_notifiers(event_notifier_enabler, - filter, compat_sc_table, ARRAY_SIZE(compat_sc_table), + compat_sc_table.table, compat_sc_table.len, SC_TYPE_COMPAT_ENTRY); if (ret) goto end; @@ -1666,7 +1040,7 @@ int lttng_syscals_create_matching_event_notifiers( if (entryexit == LTTNG_KERNEL_ABI_SYSCALL_EXIT || entryexit == LTTNG_KERNEL_ABI_SYSCALL_ENTRYEXIT) { ret = create_matching_event_notifiers(event_notifier_enabler, - filter, sc_exit_table, ARRAY_SIZE(sc_exit_table), + sc_exit_table.table, sc_exit_table.len, SC_TYPE_EXIT); if (ret) goto end; @@ -1677,7 +1051,7 @@ int lttng_syscals_create_matching_event_notifiers( goto end; ret = create_matching_event_notifiers(event_notifier_enabler, - filter, compat_sc_exit_table, ARRAY_SIZE(compat_sc_exit_table), + compat_sc_exit_table.table, compat_sc_exit_table.len, SC_TYPE_COMPAT_EXIT); if (ret) goto end; @@ -1692,75 +1066,38 @@ end: return ret; } -/* - * Unregister the syscall event_notifier probes from the callsites. - */ -int lttng_syscalls_unregister_event_notifier_group( - struct lttng_event_notifier_group *event_notifier_group) +int lttng_syscalls_unregister_syscall_table(struct lttng_kernel_syscall_table *syscall_table) { int ret; - /* - * Only register the event_notifier probe on the `sys_enter` callsite for now. - * At the moment, we don't think it's desirable to have one fired - * event_notifier for the entry and one for the exit of a syscall. - */ - if (event_notifier_group->sys_enter_registered) { - ret = lttng_wrapper_tracepoint_probe_unregister("sys_enter", - (void *) syscall_entry_event_notifier_probe, event_notifier_group); - if (ret) - return ret; - event_notifier_group->sys_enter_registered = 0; - } - if (event_notifier_group->sys_exit_registered) { - ret = lttng_wrapper_tracepoint_probe_unregister("sys_exit", - (void *) syscall_exit_event_notifier_probe, event_notifier_group); - if (ret) - return ret; - event_notifier_group->sys_enter_registered = 0; - } - - kfree(event_notifier_group->event_notifier_syscall_dispatch); - kfree(event_notifier_group->event_notifier_exit_syscall_dispatch); -#ifdef CONFIG_COMPAT - kfree(event_notifier_group->event_notifier_compat_syscall_dispatch); - kfree(event_notifier_group->event_notifier_exit_compat_syscall_dispatch); -#endif - return 0; -} - -int lttng_syscalls_unregister_channel(struct lttng_channel *chan) -{ - int ret; - - if (!chan->sc_table) + if (!syscall_table->syscall_dispatch) return 0; - if (chan->sys_enter_registered) { + if (syscall_table->sys_enter_registered) { ret = lttng_wrapper_tracepoint_probe_unregister("sys_enter", - (void *) syscall_entry_event_probe, chan); + (void *) syscall_entry_event_probe, syscall_table); if (ret) return ret; - chan->sys_enter_registered = 0; + syscall_table->sys_enter_registered = 0; } - if (chan->sys_exit_registered) { + if (syscall_table->sys_exit_registered) { ret = lttng_wrapper_tracepoint_probe_unregister("sys_exit", - (void *) syscall_exit_event_probe, chan); + (void *) syscall_exit_event_probe, syscall_table); if (ret) return ret; - chan->sys_exit_registered = 0; + syscall_table->sys_exit_registered = 0; } return 0; } -int lttng_syscalls_destroy_event(struct lttng_channel *chan) +int lttng_syscalls_destroy_syscall_table(struct lttng_kernel_syscall_table *syscall_table) { - kfree(chan->sc_table); - kfree(chan->sc_exit_table); + kfree(syscall_table->syscall_dispatch); + kfree(syscall_table->syscall_exit_dispatch); #ifdef CONFIG_COMPAT - kfree(chan->compat_sc_table); - kfree(chan->compat_sc_exit_table); + kfree(syscall_table->compat_syscall_dispatch); + kfree(syscall_table->compat_syscall_exit_dispatch); #endif - kfree(chan->sc_filter); + kfree(syscall_table->sc_filter); return 0; } @@ -1770,11 +1107,11 @@ int get_syscall_nr(const char *syscall_name) int syscall_nr = -1; int i; - for (i = 0; i < ARRAY_SIZE(sc_table); i++) { + for (i = 0; i < sc_table.len; i++) { const struct trace_syscall_entry *entry; const char *it_name; - entry = &sc_table[i]; + entry = &sc_table.table[i]; if (!entry->desc) continue; it_name = entry->desc->event_name; @@ -1793,11 +1130,11 @@ int get_compat_syscall_nr(const char *syscall_name) int syscall_nr = -1; int i; - for (i = 0; i < ARRAY_SIZE(compat_sc_table); i++) { + for (i = 0; i < compat_sc_table.len; i++) { const struct trace_syscall_entry *entry; const char *it_name; - entry = &compat_sc_table[i]; + entry = &compat_sc_table.table[i]; if (!entry->desc) continue; it_name = entry->desc->event_name; @@ -1813,7 +1150,7 @@ int get_compat_syscall_nr(const char *syscall_name) static uint32_t get_sc_tables_len(void) { - return ARRAY_SIZE(sc_table) + ARRAY_SIZE(compat_sc_table); + return sc_table.len + compat_sc_table.len; } static @@ -1909,75 +1246,72 @@ int lttng_syscall_filter_enable( return 0; } -int lttng_syscall_filter_enable_event_notifier( - struct lttng_event_notifier *notifier) +int lttng_syscall_filter_enable_event(struct lttng_kernel_event_common *event) { - struct lttng_event_notifier_group *group = notifier->group; - unsigned int syscall_id = notifier->u.syscall.syscall_id; - struct hlist_head *dispatch_list; - int ret = 0; + struct lttng_kernel_syscall_table *syscall_table = get_syscall_table_from_event(event); + int ret; - WARN_ON_ONCE(notifier->instrumentation != LTTNG_KERNEL_ABI_SYSCALL); + WARN_ON_ONCE(event->priv->instrumentation != LTTNG_KERNEL_ABI_SYSCALL); - ret = lttng_syscall_filter_enable(group->sc_filter, - notifier->desc->event_name, notifier->u.syscall.abi, - notifier->u.syscall.entryexit); - if (ret) { - goto end; - } + ret = lttng_syscall_filter_enable(syscall_table->sc_filter, + event->priv->desc->event_name, event->priv->u.syscall.abi, + event->priv->u.syscall.entryexit); + if (ret) + return ret; - switch (notifier->u.syscall.entryexit) { - case LTTNG_SYSCALL_ENTRY: - switch (notifier->u.syscall.abi) { - case LTTNG_SYSCALL_ABI_NATIVE: - dispatch_list = &group->event_notifier_syscall_dispatch[syscall_id]; - break; - case LTTNG_SYSCALL_ABI_COMPAT: - dispatch_list = &group->event_notifier_compat_syscall_dispatch[syscall_id]; - break; - default: - ret = -EINVAL; - goto end; - } + switch (event->type) { + case LTTNG_KERNEL_EVENT_TYPE_RECORDER: break; - case LTTNG_SYSCALL_EXIT: - switch (notifier->u.syscall.abi) { - case LTTNG_SYSCALL_ABI_NATIVE: - dispatch_list = &group->event_notifier_exit_syscall_dispatch[syscall_id]; + case LTTNG_KERNEL_EVENT_TYPE_NOTIFIER: + { + unsigned int syscall_id = event->priv->u.syscall.syscall_id; + struct hlist_head *dispatch_list; + + switch (event->priv->u.syscall.entryexit) { + case LTTNG_SYSCALL_ENTRY: + switch (event->priv->u.syscall.abi) { + case LTTNG_SYSCALL_ABI_NATIVE: + dispatch_list = &syscall_table->syscall_dispatch[syscall_id]; + break; + case LTTNG_SYSCALL_ABI_COMPAT: + dispatch_list = &syscall_table->compat_syscall_dispatch[syscall_id]; + break; + default: + ret = -EINVAL; + goto end; + } break; - case LTTNG_SYSCALL_ABI_COMPAT: - dispatch_list = &group->event_notifier_exit_compat_syscall_dispatch[syscall_id]; + case LTTNG_SYSCALL_EXIT: + switch (event->priv->u.syscall.abi) { + case LTTNG_SYSCALL_ABI_NATIVE: + dispatch_list = &syscall_table->syscall_exit_dispatch[syscall_id]; + break; + case LTTNG_SYSCALL_ABI_COMPAT: + dispatch_list = &syscall_table->compat_syscall_exit_dispatch[syscall_id]; + break; + default: + ret = -EINVAL; + goto end; + } break; default: ret = -EINVAL; goto end; } + + hlist_add_head_rcu(&event->priv->u.syscall.node, dispatch_list); break; + } default: - ret = -EINVAL; - goto end; + WARN_ON_ONCE(1); + return -ENOSYS; } - - hlist_add_head_rcu(¬ifier->u.syscall.node, dispatch_list); - end: - return ret ; -} - -int lttng_syscall_filter_enable_event( - struct lttng_channel *channel, - struct lttng_event *event) -{ - WARN_ON_ONCE(event->instrumentation != LTTNG_KERNEL_ABI_SYSCALL); - - return lttng_syscall_filter_enable(channel->sc_filter, - event->desc->event_name, event->u.syscall.abi, - event->u.syscall.entryexit); + return ret; } static -int lttng_syscall_filter_disable( - struct lttng_syscall_filter *filter, +int lttng_syscall_filter_disable(struct lttng_syscall_filter *filter, const char *desc_name, enum lttng_syscall_abi abi, enum lttng_syscall_entryexit entryexit) { @@ -2035,30 +1369,53 @@ int lttng_syscall_filter_disable( return 0; } -int lttng_syscall_filter_disable_event_notifier( - struct lttng_event_notifier *notifier) +int lttng_syscall_filter_disable_event(struct lttng_kernel_event_common *event) { - struct lttng_event_notifier_group *group = notifier->group; + struct lttng_kernel_syscall_table *syscall_table = get_syscall_table_from_event(event); int ret; - WARN_ON_ONCE(notifier->instrumentation != LTTNG_KERNEL_ABI_SYSCALL); - - ret = lttng_syscall_filter_disable(group->sc_filter, - notifier->desc->event_name, notifier->u.syscall.abi, - notifier->u.syscall.entryexit); - WARN_ON_ONCE(ret != 0); + ret = lttng_syscall_filter_disable(syscall_table->sc_filter, + event->priv->desc->event_name, event->priv->u.syscall.abi, + event->priv->u.syscall.entryexit); + if (ret) + return ret; - hlist_del_rcu(¬ifier->u.syscall.node); + switch (event->type) { + case LTTNG_KERNEL_EVENT_TYPE_RECORDER: + break; + case LTTNG_KERNEL_EVENT_TYPE_NOTIFIER: + { + hlist_del_rcu(&event->priv->u.syscall.node); + break; + } + default: + WARN_ON_ONCE(1); + return -ENOSYS; + } return 0; } -int lttng_syscall_filter_disable_event( - struct lttng_channel *channel, - struct lttng_event *event) +void lttng_syscall_table_set_wildcard_all(struct lttng_event_enabler_common *event_enabler) { - return lttng_syscall_filter_disable(channel->sc_filter, - event->desc->event_name, event->u.syscall.abi, - event->u.syscall.entryexit); + struct lttng_kernel_syscall_table *syscall_table = get_syscall_table_from_enabler(event_enabler); + enum lttng_kernel_abi_syscall_entryexit entryexit; + int enabled = event_enabler->enabled; + + if (event_enabler->event_param.instrumentation != LTTNG_KERNEL_ABI_SYSCALL) + return; + if (event_enabler->event_param.u.syscall.abi != LTTNG_KERNEL_ABI_SYSCALL_ABI_ALL) + return; + if (event_enabler->event_param.u.syscall.match != LTTNG_KERNEL_ABI_SYSCALL_MATCH_NAME) + return; + if (strcmp(event_enabler->event_param.name, "*")) + return; + + entryexit = event_enabler->event_param.u.syscall.entryexit; + if (entryexit == LTTNG_KERNEL_ABI_SYSCALL_ENTRY || entryexit == LTTNG_KERNEL_ABI_SYSCALL_ENTRYEXIT) + WRITE_ONCE(syscall_table->syscall_all_entry, enabled); + + if (entryexit == LTTNG_KERNEL_ABI_SYSCALL_EXIT || entryexit == LTTNG_KERNEL_ABI_SYSCALL_ENTRYEXIT) + WRITE_ONCE(syscall_table->syscall_all_exit, enabled); } static @@ -2067,14 +1424,14 @@ const struct trace_syscall_entry *syscall_list_get_entry(loff_t *pos) const struct trace_syscall_entry *entry; int iter = 0; - for (entry = sc_table; - entry < sc_table + ARRAY_SIZE(sc_table); + for (entry = sc_table.table; + entry < sc_table.table + sc_table.len; entry++) { if (iter++ >= *pos) return entry; } - for (entry = compat_sc_table; - entry < compat_sc_table + ARRAY_SIZE(compat_sc_table); + for (entry = compat_sc_table.table; + entry < compat_sc_table.table + compat_sc_table.len; entry++) { if (iter++ >= *pos) return entry; @@ -2106,21 +1463,21 @@ int get_sc_table(const struct trace_syscall_entry *entry, const struct trace_syscall_entry **table, unsigned int *bitness) { - if (entry >= sc_table && entry < sc_table + ARRAY_SIZE(sc_table)) { + if (entry >= sc_table.table && entry < sc_table.table + sc_table.len) { if (bitness) *bitness = BITS_PER_LONG; if (table) - *table = sc_table; + *table = sc_table.table; return 0; } - if (!(entry >= compat_sc_table - && entry < compat_sc_table + ARRAY_SIZE(compat_sc_table))) { + if (!(entry >= compat_sc_table.table + && entry < compat_sc_table.table + compat_sc_table.len)) { return -EINVAL; } if (bitness) *bitness = 32; if (table) - *table = compat_sc_table; + *table = compat_sc_table.table; return 0; } @@ -2138,11 +1495,11 @@ int syscall_list_show(struct seq_file *m, void *p) return ret; if (!entry->desc) return 0; - if (table == sc_table) { + if (table == sc_table.table) { index = entry - table; name = &entry->desc->event_name[strlen(SYSCALL_ENTRY_STR)]; } else { - index = (entry - table) + ARRAY_SIZE(sc_table); + index = (entry - table) + sc_table.len; name = &entry->desc->event_name[strlen(COMPAT_SYSCALL_ENTRY_STR)]; } seq_printf(m, "syscall { index = %lu; name = %s; bitness = %u; };\n", @@ -2175,7 +1532,7 @@ const struct file_operations lttng_syscall_list_fops = { /* * A syscall is enabled if it is traced for either entry or exit. */ -long lttng_channel_syscall_mask(struct lttng_channel *channel, +long lttng_syscall_table_get_active_mask(struct lttng_kernel_syscall_table *syscall_table, struct lttng_kernel_abi_syscall_mask __user *usyscall_mask) { uint32_t len, sc_tables_len, bitmask_len; @@ -2195,14 +1552,14 @@ long lttng_channel_syscall_mask(struct lttng_channel *channel, tmp_mask = kzalloc(bitmask_len, GFP_KERNEL); if (!tmp_mask) return -ENOMEM; - filter = channel->sc_filter; + filter = syscall_table->sc_filter; - for (bit = 0; bit < ARRAY_SIZE(sc_table); bit++) { + for (bit = 0; bit < sc_table.len; bit++) { char state; - if (channel->sc_table) { - if (!(READ_ONCE(channel->syscall_all_entry) - || READ_ONCE(channel->syscall_all_exit)) && filter) + if (syscall_table->syscall_dispatch) { + if (!(READ_ONCE(syscall_table->syscall_all_entry) + || READ_ONCE(syscall_table->syscall_all_exit)) && filter) state = test_bit(bit, filter->sc_entry) || test_bit(bit, filter->sc_exit); else @@ -2215,12 +1572,12 @@ long lttng_channel_syscall_mask(struct lttng_channel *channel, for (; bit < sc_tables_len; bit++) { char state; - if (channel->compat_sc_table) { - if (!(READ_ONCE(channel->syscall_all_entry) - || READ_ONCE(channel->syscall_all_exit)) && filter) - state = test_bit(bit - ARRAY_SIZE(sc_table), + if (syscall_table->compat_syscall_dispatch) { + if (!(READ_ONCE(syscall_table->syscall_all_entry) + || READ_ONCE(syscall_table->syscall_all_exit)) && filter) + state = test_bit(bit - sc_table.len, filter->sc_compat_entry) - || test_bit(bit - ARRAY_SIZE(sc_table), + || test_bit(bit - sc_table.len, filter->sc_compat_exit); else state = 1;