syscalls: extract `lttng_syscall_filter_enable()` for reuse
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 19 Nov 2020 22:00:19 +0000 (17:00 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 25 Nov 2020 16:47:22 +0000 (11:47 -0500)
The syscall event notifiers will reuse the concept of syscall filtering
to avoid needlessly preparing arguments for disabled syscalls.

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

include/lttng/events.h
src/lttng-syscalls.c

index 7226a27bed53162d63c4187b140db7a484562b64..05b0f7cf7a9740a1e32ade6753cd91fa763e379b 100644 (file)
@@ -773,10 +773,13 @@ void lttng_clock_unref(void);
 int lttng_syscalls_register_event(struct lttng_channel *chan, void *filter);
 int lttng_syscalls_unregister_event(struct lttng_channel *chan);
 int lttng_syscalls_destroy_event(struct lttng_channel *chan);
-int lttng_syscall_filter_enable_event(struct lttng_channel *chan,
+int lttng_syscall_filter_enable_event(
+               struct lttng_channel *chan,
                struct lttng_event *event);
-int lttng_syscall_filter_disable_event(struct lttng_channel *chan,
+int lttng_syscall_filter_disable_event(
+               struct lttng_channel *chan,
                struct lttng_event *event);
+
 long lttng_channel_syscall_mask(struct lttng_channel *channel,
                struct lttng_kernel_syscall_mask __user *usyscall_mask);
 
index 3139a556822e543fcca852a40d96c968c34062d8..3e9f791ab336c6c11067b8e54cab54256a1aa9f6 100644 (file)
@@ -1008,15 +1008,16 @@ uint32_t get_sc_tables_len(void)
 }
 
 static
-const char *get_syscall_name(struct lttng_event *event)
+const char *get_syscall_name(const char *desc_name,
+               enum lttng_syscall_abi abi,
+               enum lttng_syscall_entryexit entryexit)
 {
        size_t prefix_len = 0;
 
-       WARN_ON_ONCE(event->instrumentation != LTTNG_KERNEL_SYSCALL);
 
-       switch (event->u.syscall.entryexit) {
+       switch (entryexit) {
        case LTTNG_SYSCALL_ENTRY:
-               switch (event->u.syscall.abi) {
+               switch (abi) {
                case LTTNG_SYSCALL_ABI_NATIVE:
                        prefix_len = strlen(SYSCALL_ENTRY_STR);
                        break;
@@ -1026,7 +1027,7 @@ const char *get_syscall_name(struct lttng_event *event)
                }
                break;
        case LTTNG_SYSCALL_EXIT:
-               switch (event->u.syscall.abi) {
+               switch (abi) {
                case LTTNG_SYSCALL_ABI_NATIVE:
                        prefix_len = strlen(SYSCALL_EXIT_STR);
                        break;
@@ -1037,22 +1038,22 @@ const char *get_syscall_name(struct lttng_event *event)
                break;
        }
        WARN_ON_ONCE(prefix_len == 0);
-       return event->desc->name + prefix_len;
+       return desc_name + prefix_len;
 }
 
-int lttng_syscall_filter_enable_event(struct lttng_channel *chan,
-               struct lttng_event *event)
+static
+int lttng_syscall_filter_enable(
+               struct lttng_syscall_filter *filter,
+               const char *desc_name, enum lttng_syscall_abi abi,
+               enum lttng_syscall_entryexit entryexit)
 {
-       struct lttng_syscall_filter *filter = chan->sc_filter;
        const char *syscall_name;
        unsigned long *bitmap;
        int syscall_nr;
 
-       WARN_ON_ONCE(!chan->sc_table);
-
-       syscall_name = get_syscall_name(event);
+       syscall_name = get_syscall_name(desc_name, abi, entryexit);
 
-       switch (event->u.syscall.abi) {
+       switch (abi) {
        case LTTNG_SYSCALL_ABI_NATIVE:
                syscall_nr = get_syscall_nr(syscall_name);
                break;
@@ -1065,9 +1066,9 @@ int lttng_syscall_filter_enable_event(struct lttng_channel *chan,
        if (syscall_nr < 0)
                return -ENOENT;
 
-       switch (event->u.syscall.entryexit) {
+       switch (entryexit) {
        case LTTNG_SYSCALL_ENTRY:
-               switch (event->u.syscall.abi) {
+               switch (abi) {
                case LTTNG_SYSCALL_ABI_NATIVE:
                        bitmap = filter->sc_entry;
                        break;
@@ -1079,7 +1080,7 @@ int lttng_syscall_filter_enable_event(struct lttng_channel *chan,
                }
                break;
        case LTTNG_SYSCALL_EXIT:
-               switch (event->u.syscall.abi) {
+               switch (abi) {
                case LTTNG_SYSCALL_ABI_NATIVE:
                        bitmap = filter->sc_exit;
                        break;
@@ -1099,19 +1100,30 @@ int lttng_syscall_filter_enable_event(struct lttng_channel *chan,
        return 0;
 }
 
-int lttng_syscall_filter_disable_event(struct lttng_channel *chan,
+int lttng_syscall_filter_enable_event(
+               struct lttng_channel *channel,
                struct lttng_event *event)
 {
-       struct lttng_syscall_filter *filter = chan->sc_filter;
+       WARN_ON_ONCE(event->instrumentation != LTTNG_KERNEL_SYSCALL);
+
+       return lttng_syscall_filter_enable(channel->sc_filter,
+               event->desc->name, event->u.syscall.abi,
+               event->u.syscall.entryexit);
+}
+
+static
+int lttng_syscall_filter_disable(
+               struct lttng_syscall_filter *filter,
+               const char *desc_name, enum lttng_syscall_abi abi,
+               enum lttng_syscall_entryexit entryexit)
+{
        const char *syscall_name;
        unsigned long *bitmap;
        int syscall_nr;
 
-       WARN_ON_ONCE(!chan->sc_table);
+       syscall_name = get_syscall_name(desc_name, abi, entryexit);
 
-       syscall_name = get_syscall_name(event);
-
-       switch (event->u.syscall.abi) {
+       switch (abi) {
        case LTTNG_SYSCALL_ABI_NATIVE:
                syscall_nr = get_syscall_nr(syscall_name);
                break;
@@ -1124,9 +1136,9 @@ int lttng_syscall_filter_disable_event(struct lttng_channel *chan,
        if (syscall_nr < 0)
                return -ENOENT;
 
-       switch (event->u.syscall.entryexit) {
+       switch (entryexit) {
        case LTTNG_SYSCALL_ENTRY:
-               switch (event->u.syscall.abi) {
+               switch (abi) {
                case LTTNG_SYSCALL_ABI_NATIVE:
                        bitmap = filter->sc_entry;
                        break;
@@ -1138,7 +1150,7 @@ int lttng_syscall_filter_disable_event(struct lttng_channel *chan,
                }
                break;
        case LTTNG_SYSCALL_EXIT:
-               switch (event->u.syscall.abi) {
+               switch (abi) {
                case LTTNG_SYSCALL_ABI_NATIVE:
                        bitmap = filter->sc_exit;
                        break;
@@ -1159,6 +1171,15 @@ int lttng_syscall_filter_disable_event(struct lttng_channel *chan,
        return 0;
 }
 
+int lttng_syscall_filter_disable_event(
+               struct lttng_channel *channel,
+               struct lttng_event *event)
+{
+       return lttng_syscall_filter_disable(channel->sc_filter,
+               event->desc->name, event->u.syscall.abi,
+               event->u.syscall.entryexit);
+}
+
 static
 const struct trace_syscall_entry *syscall_list_get_entry(loff_t *pos)
 {
This page took 0.030739 seconds and 4 git commands to generate.