+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)
+{
+ 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:
+ {
+ 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;
+ }
+ case 6:
+ {
+ 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;
+ }
+ default:
+ break;
+ }
+}
+
+static
+void syscall_exit_event_notifier_probe(void *__data, struct pt_regs *regs,
+ long ret)
+{
+ 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;
+ }
+
+ 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_exit_compat_syscall_dispatch[id];
+ } else {
+ dispatch_list = &group->event_notifier_exit_syscall_dispatch[id];
+ }
+ if (unlikely(hlist_empty(dispatch_list)))
+ return;
+
+ syscall_exit_event_notifier_call_func(dispatch_list,
+ entry->event_notifier_func, entry->nrargs, regs, ret);
+}