lttng-syscalls.c: extract function calling actual probe
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 23 Jan 2020 23:31:06 +0000 (18:31 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 18 Nov 2020 18:16:18 +0000 (13:16 -0500)
This function will be reused by the event notifier infrastructure.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Iad25a44202d74eac8f75af108eb8297d82303d63

src/lttng-syscalls.c

index 3d9f3736a6fa842e7f3361e04b53f61cad57a97a..3139a556822e543fcca852a40d96c968c34062d8 100644 (file)
@@ -387,77 +387,36 @@ static void syscall_entry_event_unknown(struct lttng_event *event,
                __event_probe__syscall_entry_unknown(event, id, args);
 }
 
-void syscall_entry_event_probe(void *__data, struct pt_regs *regs, long id)
+static __always_inline
+void syscall_entry_call_func(void *func, unsigned int nrargs, void *data,
+               struct pt_regs *regs)
 {
-       struct lttng_channel *chan = __data;
-       struct lttng_event *event, *unknown_event;
-       const struct trace_syscall_entry *table, *entry;
-       size_t table_len;
-
-       if (unlikely(in_compat_syscall())) {
-               struct lttng_syscall_filter *filter = chan->sc_filter;
-
-               if (id < 0 || id >= NR_compat_syscalls
-                       || (!READ_ONCE(chan->syscall_all) && !test_bit(id, filter->sc_compat_entry))) {
-                       /* System call filtered out. */
-                       return;
-               }
-               table = compat_sc_table;
-               table_len = ARRAY_SIZE(compat_sc_table);
-               unknown_event = chan->sc_compat_unknown;
-       } else {
-               struct lttng_syscall_filter *filter = chan->sc_filter;
-
-               if (id < 0 || id >= NR_syscalls
-                       || (!READ_ONCE(chan->syscall_all) && !test_bit(id, filter->sc_entry))) {
-                       /* System call filtered out. */
-                       return;
-               }
-               table = sc_table;
-               table_len = ARRAY_SIZE(sc_table);
-               unknown_event = chan->sc_unknown;
-       }
-       if (unlikely(id < 0 || id >= table_len)) {
-               syscall_entry_event_unknown(unknown_event, regs, id);
-               return;
-       }
-       if (unlikely(in_compat_syscall()))
-               event = chan->compat_sc_table[id];
-       else
-               event = chan->sc_table[id];
-       if (unlikely(!event)) {
-               syscall_entry_event_unknown(unknown_event, regs, id);
-               return;
-       }
-       entry = &table[id];
-       WARN_ON_ONCE(!entry);
-
-       switch (entry->nrargs) {
+       switch (nrargs) {
        case 0:
        {
-               void (*fptr)(void *__data) = entry->event_func;
+               void (*fptr)(void *__data) = func;
 
-               fptr(event);
+               fptr(data);
                break;
        }
        case 1:
        {
-               void (*fptr)(void *__data, unsigned long arg0) = entry->event_func;
+               void (*fptr)(void *__data, unsigned long arg0) = func;
                unsigned long args[LTTNG_SYSCALL_NR_ARGS];
 
                lttng_syscall_get_arguments(current, regs, args);
-               fptr(event, args[0]);
+               fptr(data, args[0]);
                break;
        }
        case 2:
        {
                void (*fptr)(void *__data,
                        unsigned long arg0,
-                       unsigned long arg1) = entry->event_func;
+                       unsigned long arg1) = func;
                unsigned long args[LTTNG_SYSCALL_NR_ARGS];
 
                lttng_syscall_get_arguments(current, regs, args);
-               fptr(event, args[0], args[1]);
+               fptr(data, args[0], args[1]);
                break;
        }
        case 3:
@@ -465,11 +424,11 @@ void syscall_entry_event_probe(void *__data, struct pt_regs *regs, long id)
                void (*fptr)(void *__data,
                        unsigned long arg0,
                        unsigned long arg1,
-                       unsigned long arg2) = entry->event_func;
+                       unsigned long arg2) = func;
                unsigned long args[LTTNG_SYSCALL_NR_ARGS];
 
                lttng_syscall_get_arguments(current, regs, args);
-               fptr(event, args[0], args[1], args[2]);
+               fptr(data, args[0], args[1], args[2]);
                break;
        }
        case 4:
@@ -478,11 +437,11 @@ void syscall_entry_event_probe(void *__data, struct pt_regs *regs, long id)
                        unsigned long arg0,
                        unsigned long arg1,
                        unsigned long arg2,
-                       unsigned long arg3) = entry->event_func;
+                       unsigned long arg3) = func;
                unsigned long args[LTTNG_SYSCALL_NR_ARGS];
 
                lttng_syscall_get_arguments(current, regs, args);
-               fptr(event, args[0], args[1], args[2], args[3]);
+               fptr(data, args[0], args[1], args[2], args[3]);
                break;
        }
        case 5:
@@ -492,11 +451,11 @@ void syscall_entry_event_probe(void *__data, struct pt_regs *regs, long id)
                        unsigned long arg1,
                        unsigned long arg2,
                        unsigned long arg3,
-                       unsigned long arg4) = entry->event_func;
+                       unsigned long arg4) = func;
                unsigned long args[LTTNG_SYSCALL_NR_ARGS];
 
                lttng_syscall_get_arguments(current, regs, args);
-               fptr(event, args[0], args[1], args[2], args[3], args[4]);
+               fptr(data, args[0], args[1], args[2], args[3], args[4]);
                break;
        }
        case 6:
@@ -507,11 +466,11 @@ void syscall_entry_event_probe(void *__data, struct pt_regs *regs, long id)
                        unsigned long arg2,
                        unsigned long arg3,
                        unsigned long arg4,
-                       unsigned long arg5) = entry->event_func;
+                       unsigned long arg5) = func;
                unsigned long args[LTTNG_SYSCALL_NR_ARGS];
 
                lttng_syscall_get_arguments(current, regs, args);
-               fptr(event, args[0], args[1], args[2],
+               fptr(data, args[0], args[1], args[2],
                        args[3], args[4], args[5]);
                break;
        }
@@ -520,6 +479,53 @@ void syscall_entry_event_probe(void *__data, struct pt_regs *regs, long id)
        }
 }
 
+void syscall_entry_event_probe(void *__data, struct pt_regs *regs, long id)
+{
+       struct lttng_channel *chan = __data;
+       struct lttng_event *event, *unknown_event;
+       const struct trace_syscall_entry *table, *entry;
+       size_t table_len;
+
+       if (unlikely(in_compat_syscall())) {
+               struct lttng_syscall_filter *filter = chan->sc_filter;
+
+               if (id < 0 || id >= NR_compat_syscalls
+                       || (!READ_ONCE(chan->syscall_all) && !test_bit(id, filter->sc_compat_entry))) {
+                       /* System call filtered out. */
+                       return;
+               }
+               table = compat_sc_table;
+               table_len = ARRAY_SIZE(compat_sc_table);
+               unknown_event = chan->sc_compat_unknown;
+       } else {
+               struct lttng_syscall_filter *filter = chan->sc_filter;
+
+               if (id < 0 || id >= NR_syscalls
+                       || (!READ_ONCE(chan->syscall_all) && !test_bit(id, filter->sc_entry))) {
+                       /* System call filtered out. */
+                       return;
+               }
+               table = sc_table;
+               table_len = ARRAY_SIZE(sc_table);
+               unknown_event = chan->sc_unknown;
+       }
+       if (unlikely(id < 0 || id >= table_len)) {
+               syscall_entry_event_unknown(unknown_event, regs, id);
+               return;
+       }
+       if (unlikely(in_compat_syscall()))
+               event = chan->compat_sc_table[id];
+       else
+               event = chan->sc_table[id];
+       if (unlikely(!event)) {
+               syscall_entry_event_unknown(unknown_event, regs, id);
+               return;
+       }
+       entry = &table[id];
+       WARN_ON_ONCE(!entry);
+       syscall_entry_call_func(entry->event_func, entry->nrargs, event, regs);
+}
+
 static void syscall_exit_event_unknown(struct lttng_event *event,
        struct pt_regs *regs, int id, long ret)
 {
This page took 0.032485 seconds and 4 git commands to generate.