tracepoint: Refactor representation of nested types
[lttng-modules.git] / instrumentation / syscalls / headers / syscalls_pointers_override.h
index 184f3a96e8c08b0b0604999531e17f70af817e56..89f2cd8e61f7a3bdc7f866b1d0637af39d594cbf 100644 (file)
@@ -1,3 +1,5 @@
+/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) */
+
 #ifndef CREATE_SYSCALL_TABLE
 
 #define OVERRIDE_32_execve
@@ -100,9 +102,8 @@ SC_LTTNG_TRACEPOINT_EVENT(pipe2,
                }                                                                       \
                                                                                        \
                if (inp) {                                                              \
-                       tp_locvar->fds_in = kmalloc(                                    \
-                                       tp_locvar->nr_ulong * sizeof(unsigned long),    \
-                                       GFP_ATOMIC | GFP_NOWAIT);                       \
+                       tp_locvar->fds_in = lttng_tp_mempool_alloc(                             \
+                                       tp_locvar->nr_ulong * sizeof(unsigned long));                   \
                        if (!tp_locvar->fds_in)                                         \
                                goto error;                                             \
                                                                                        \
@@ -113,9 +114,8 @@ SC_LTTNG_TRACEPOINT_EVENT(pipe2,
                                goto error;                                             \
                }                                                                       \
                if (outp) {                                                             \
-                       tp_locvar->fds_out = kmalloc(                                   \
-                                       tp_locvar->nr_ulong * sizeof(unsigned long),    \
-                                       GFP_ATOMIC | GFP_NOWAIT);                       \
+                       tp_locvar->fds_out = lttng_tp_mempool_alloc(                            \
+                                       tp_locvar->nr_ulong * sizeof(unsigned long));   \
                        if (!tp_locvar->fds_out)                                        \
                                goto error;                                             \
                                                                                        \
@@ -126,9 +126,8 @@ SC_LTTNG_TRACEPOINT_EVENT(pipe2,
                                goto error;                                             \
                }                                                                       \
                if (exp) {                                                              \
-                       tp_locvar->fds_ex = kmalloc(                                    \
-                                       tp_locvar->nr_ulong * sizeof(unsigned long),    \
-                                       GFP_ATOMIC | GFP_NOWAIT);                       \
+                       tp_locvar->fds_ex = lttng_tp_mempool_alloc(                             \
+                                       tp_locvar->nr_ulong * sizeof(unsigned long));   \
                        if (!tp_locvar->fds_ex)                                         \
                                goto error;                                             \
                                                                                        \
@@ -150,25 +149,36 @@ end:      ; /* Label at end of compound statement. */                                     \
 #define LTTNG_SYSCALL_SELECT_fds_field_LE(name, input)                                                 \
        ctf_custom_field(                                                                               \
                ctf_custom_type(                                                                        \
-                       .atype = atype_sequence,                                                        \
-                       .u.sequence.length_type = __type_integer(                                       \
-                               uint8_t, 0, 0, 0, __BYTE_ORDER, 10, none),                              \
-                       .u.sequence.elem_type = __type_integer(uint8_t, 0, 0, 0,                        \
-                               __BYTE_ORDER, 16, none),                                                \
+                       __type_integer(uint8_t, 0, 0, 0, __BYTE_ORDER, 10, none)                        \
                ),                                                                                      \
-               name,                                                                                   \
+               _ ## name ## _length,                                                                   \
                ctf_custom_code(                                                                        \
-                       unsigned int src;                                                               \
-                       unsigned int nr_bytes_out = 0;                                                  \
-                                                                                                       \
                        if (input) {                                                                    \
                                ctf_integer_type(uint8_t, tp_locvar->nr_bytes)                          \
                                ctf_align(uint8_t)                                                      \
                        } else {                                                                        \
                                ctf_integer_type(uint8_t, 0)                                            \
                                ctf_align(uint8_t)                                                      \
-                               goto skip_##name;                                                       \
                        }                                                                               \
+               )                                                                                       \
+       )                                                                                               \
+       ctf_custom_field(                                                                               \
+               ctf_custom_type(                                                                        \
+                       {                                                                               \
+                               .atype = atype_sequence_nestable,                                       \
+                               .u.sequence_nestable.length_name = "_" #name "_length",                 \
+                               .u.sequence_nestable.elem_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \
+                                       __type_integer(uint8_t, 0, 0, 0, __BYTE_ORDER, 16, none)),      \
+                               .u.sequence_nestable.alignment = 0,                                     \
+                       }                                                                               \
+               ),                                                                                      \
+               name,                                                                                   \
+               ctf_custom_code(                                                                        \
+                       unsigned int src;                                                               \
+                       unsigned int nr_bytes_out = 0;                                                  \
+                                                                                                       \
+                       if (!input)                                                                     \
+                               goto skip_##name;                                                       \
                                                                                                        \
                        for (src = 0; src < tp_locvar->nr_ulong; src++) {                               \
                                int dst;                                                                \
@@ -187,24 +197,34 @@ end:      ; /* Label at end of compound statement. */                                     \
 #define LTTNG_SYSCALL_SELECT_fds_field_BE(name, input)                                                 \
        ctf_custom_field(                                                                               \
                ctf_custom_type(                                                                        \
-                       .atype = atype_sequence,                                                        \
-                       .u.sequence.length_type = __type_integer(                                       \
-                               uint8_t, 0, 0, 0, __BYTE_ORDER, 10, none),                              \
-                       .u.sequence.elem_type = __type_integer(uint8_t, 0, 0, 0,                        \
-                               __BYTE_ORDER, 16, none),                                                \
+                       __type_integer(uint8_t, 0, 0, 0, __BYTE_ORDER, 10, none)                        \
                ),                                                                                      \
-               name,                                                                                   \
+               _ ## name ## _length,                                                                   \
                ctf_custom_code(                                                                        \
-                       unsigned int src, nr_bytes_out = 0;                                             \
-                                                                                                       \
                        if (input) {                                                                    \
                                ctf_integer_type(uint8_t, tp_locvar->nr_bytes)                          \
                                ctf_align(uint8_t)                                                      \
                        } else {                                                                        \
                                ctf_integer_type(uint8_t, 0)                                            \
                                ctf_align(uint8_t)                                                      \
-                               goto skip_##name;                                                       \
                        }                                                                               \
+               )                                                                                       \
+       )                                                                                               \
+       ctf_custom_field(                                                                               \
+               ctf_custom_type(                                                                        \
+                       {                                                                               \
+                               .atype = atype_sequence_nestable,                                       \
+                               .u.sequence_nestable.elem_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \
+                                       __type_integer(uint8_t, 0, 0, 0, __BYTE_ORDER, 16, none)),      \
+                               .u.sequence_nestable.alignment = 0,                                     \
+                       }                                                                               \
+               ),                                                                                      \
+               name,                                                                                   \
+               ctf_custom_code(                                                                        \
+                       unsigned int src, nr_bytes_out = 0;                                             \
+                                                                                                       \
+                       if (!input)                                                                     \
+                               goto skip_##name;                                                       \
                                                                                                        \
                        for (src = 0; src < tp_locvar->nr_ulong; src++) {                               \
                                int dst;                                                                \
@@ -221,9 +241,9 @@ end:        ; /* Label at end of compound statement. */                                     \
        )
 
 #define LTTNG_SYSCALL_SELECT_code_post \
-       kfree(tp_locvar->fds_in);       \
-       kfree(tp_locvar->fds_out);      \
-       kfree(tp_locvar->fds_ex);
+       lttng_tp_mempool_free(tp_locvar->fds_in);       \
+       lttng_tp_mempool_free(tp_locvar->fds_out);      \
+       lttng_tp_mempool_free(tp_locvar->fds_ex);
 
 #if defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM)
 #define OVERRIDE_32_select
@@ -354,17 +374,19 @@ static struct lttng_event_field lttng_pollfd_fields[] = {
        [2] = {
                .name = "events",
                .type = {
-                       .atype = atype_struct,
-                       .u._struct.nr_fields = ARRAY_SIZE(lttng_pollfd_flag_fields),
-                       .u._struct.fields = lttng_pollfd_flag_fields,
+                       .atype = atype_struct_nestable,
+                       .u.struct_nestable.nr_fields = ARRAY_SIZE(lttng_pollfd_flag_fields),
+                       .u.struct_nestable.fields = lttng_pollfd_flag_fields,
+                       .u.struct_nestable.alignment = 0,
                }
        },
 };
 
 static struct lttng_type lttng_pollfd_elem = {
-       .atype = atype_struct,
-       .u._struct.nr_fields = ARRAY_SIZE(lttng_pollfd_fields),
-       .u._struct.fields = lttng_pollfd_fields,
+       .atype = atype_struct_nestable,
+       .u.struct_nestable.nr_fields = ARRAY_SIZE(lttng_pollfd_fields),
+       .u.struct_nestable.fields = lttng_pollfd_fields,
+       .u.struct_nestable.alignment = 0,
 };
 #endif /* ONCE_LTTNG_TRACE_POLL_H */
 
@@ -413,8 +435,7 @@ static struct lttng_type lttng_pollfd_elem = {
        {                                                                               \
                int err;                                                                \
                                                                                        \
-               tp_locvar->fds = kmalloc(tp_locvar->alloc_fds,                          \
-                               GFP_ATOMIC | GFP_NOWAIT);                               \
+               tp_locvar->fds = lttng_tp_mempool_alloc(tp_locvar->alloc_fds);          \
                if (!tp_locvar->fds)                                                    \
                        goto error;                                                     \
                err = lib_ring_buffer_copy_from_user_check_nofault(                     \
@@ -434,9 +455,11 @@ end:                                                                                       \
        sc_in(                                                                                  \
                ctf_custom_field(                                                               \
                        ctf_custom_type(                                                        \
-                               .atype = atype_sequence_compound,                               \
-                               .u.sequence_compound.length_name = "fds_length",                \
-                               .u.sequence_compound.elem_type = &lttng_pollfd_elem,            \
+                               {                                                               \
+                                       .atype = atype_sequence_nestable,                       \
+                                       .u.sequence_nestable.length_name = "fds_length",        \
+                                       .u.sequence_nestable.elem_type = &lttng_pollfd_elem,    \
+                               }                                                               \
                        ),                                                                      \
                        fds,                                                                    \
                        ctf_custom_code(                                                        \
@@ -455,9 +478,11 @@ end:                                                                                       \
        sc_out(                                                                                 \
                ctf_custom_field(                                                               \
                        ctf_custom_type(                                                        \
-                               .atype = atype_sequence_compound,                               \
-                               .u.sequence_compound.length_name = "fds_length",                \
-                               .u.sequence_compound.elem_type = &lttng_pollfd_elem,            \
+                               {                                                               \
+                                       .atype = atype_sequence_nestable,                       \
+                                       .u.sequence_nestable.length_name = "fds_length",        \
+                                       .u.sequence_nestable.elem_type = &lttng_pollfd_elem,    \
+                               }                                                               \
                        ),                                                                      \
                        fds,                                                                    \
                        ctf_custom_code(                                                        \
@@ -494,7 +519,7 @@ end:                                                                                        \
        )
 
 #define LTTNG_SYSCALL_POLL_code_post   \
-       kfree(tp_locvar->fds);
+       lttng_tp_mempool_free(tp_locvar->fds);
 
 #if defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM)
 #define OVERRIDE_32_poll
@@ -621,9 +646,10 @@ static struct lttng_event_field epoll_ctl_fields[] = {
        [0] = {
                .name = "data_union",
                .type = {
-                       .atype = atype_struct,
-                       .u._struct.nr_fields = ARRAY_SIZE(lttng_epoll_data_fields),
-                       .u._struct.fields = lttng_epoll_data_fields,
+                       .atype = atype_struct_nestable,
+                       .u.struct_nestable.nr_fields = ARRAY_SIZE(lttng_epoll_data_fields),
+                       .u.struct_nestable.fields = lttng_epoll_data_fields,
+                       .u.struct_nestable.alignment = 0,
                }
        },
        [1] = {
@@ -633,9 +659,10 @@ static struct lttng_event_field epoll_ctl_fields[] = {
        [2] = {
                .name = "events",
                .type = {
-                       .atype = atype_struct,
-                       .u._struct.nr_fields = ARRAY_SIZE(lttng_epoll_ctl_events_fields),
-                       .u._struct.fields = lttng_epoll_ctl_events_fields,
+                       .atype = atype_struct_nestable,
+                       .u.struct_nestable.nr_fields = ARRAY_SIZE(lttng_epoll_ctl_events_fields),
+                       .u.struct_nestable.fields = lttng_epoll_ctl_events_fields,
+                       .u.struct_nestable.alignment = 0,
                }
        },
 };
@@ -664,9 +691,12 @@ SC_LTTNG_TRACEPOINT_EVENT_CODE(epoll_ctl,
                sc_in(
                        ctf_custom_field(
                                ctf_custom_type(
-                                       .atype = atype_struct,
-                                       .u._struct.nr_fields = ARRAY_SIZE(epoll_ctl_fields),
-                                       .u._struct.fields = epoll_ctl_fields,
+                                       {
+                                               .atype = atype_struct_nestable,
+                                               .u.struct_nestable.nr_fields = ARRAY_SIZE(epoll_ctl_fields),
+                                               .u.struct_nestable.fields = epoll_ctl_fields,
+                                               .u.struct_nestable.alignment = 0,
+                                       }
                                ),
                                event,
                                ctf_custom_code(
@@ -699,9 +729,10 @@ static struct lttng_event_field lttng_epoll_wait_fields[] = {
        [0] = {
                .name = "data_union",
                .type = {
-                       .atype = atype_struct,
-                       .u._struct.nr_fields = ARRAY_SIZE(lttng_epoll_data_fields),
-                       .u._struct.fields = lttng_epoll_data_fields,
+                       .atype = atype_struct_nestable,
+                       .u.struct_nestable.nr_fields = ARRAY_SIZE(lttng_epoll_data_fields),
+                       .u.struct_nestable.fields = lttng_epoll_data_fields,
+                       .u.struct_nestable.alignment = 0,
                }
        },
        [1] = {
@@ -711,17 +742,19 @@ static struct lttng_event_field lttng_epoll_wait_fields[] = {
        [2] = {
                .name = "events",
                .type = {
-                       .atype = atype_struct,
-                       .u._struct.nr_fields = ARRAY_SIZE(lttng_epoll_ctl_events_fields),
-                       .u._struct.fields = lttng_epoll_ctl_events_fields,
+                       .atype = atype_struct_nestable,
+                       .u.struct_nestable.nr_fields = ARRAY_SIZE(lttng_epoll_ctl_events_fields),
+                       .u.struct_nestable.fields = lttng_epoll_ctl_events_fields,
+                       .u.struct_nestable.alignment = 0,
                }
        },
 };
 
 static struct lttng_type lttng_epoll_wait_elem = {
-       .atype = atype_struct,
-       .u._struct.nr_fields = ARRAY_SIZE(lttng_epoll_wait_fields),
-       .u._struct.fields = lttng_epoll_wait_fields,
+       .atype = atype_struct_nestable,
+       .u.struct_nestable.nr_fields = ARRAY_SIZE(lttng_epoll_wait_fields),
+       .u.struct_nestable.fields = lttng_epoll_wait_fields,
+       .u.struct_nestable.alignment = 0,
 };
 
 #endif /* ONCE_LTTNG_TRACE_EPOLL_H */
@@ -761,9 +794,8 @@ static struct lttng_type lttng_epoll_wait_elem = {
                        tp_locvar->fds_length = ret;                            \
                }                                                               \
                                                                                \
-               tp_locvar->events = kmalloc(                                    \
-                       maxalloc * sizeof(struct epoll_event),                  \
-                       GFP_ATOMIC | GFP_NOWAIT);                               \
+               tp_locvar->events = lttng_tp_mempool_alloc(                             \
+                       maxalloc * sizeof(struct epoll_event));                 \
                if (!tp_locvar->events) {                                       \
                        tp_locvar->fds_length = 0;                              \
                        goto skip_code;                                         \
@@ -781,11 +813,13 @@ static struct lttng_type lttng_epoll_wait_elem = {
 #define LTTNG_SYSCALL_EPOLL_WAIT_fds_field                                             \
        ctf_custom_field(                                                               \
                ctf_custom_type(                                                        \
-                       .atype = atype_sequence_compound,                               \
-                       .u.sequence_compound.length_name =                              \
-                               "fds_length",                                           \
-                       .u.sequence_compound.elem_type =                                \
-                               &lttng_epoll_wait_elem,                                 \
+                       {                                                               \
+                               .atype = atype_sequence_nestable,                       \
+                               .u.sequence_nestable.length_name =                      \
+                                       "fds_length",                                   \
+                               .u.sequence_nestable.elem_type =                        \
+                                       &lttng_epoll_wait_elem,                         \
+                       }                                                               \
                ),                                                                      \
                fds,                                                                    \
                ctf_custom_code(                                                        \
@@ -805,7 +839,7 @@ static struct lttng_type lttng_epoll_wait_elem = {
 
 #define LTTNG_SYSCALL_EPOLL_WAIT_code_post     \
        sc_out(                                 \
-               kfree(tp_locvar->events);       \
+               lttng_tp_mempool_free(tp_locvar->events);       \
        )
 
 
@@ -887,4 +921,86 @@ SC_LTTNG_TRACEPOINT_EVENT(socketpair,
 )
 #endif /* (defined(CONFIG_X86_64) && !defined(LTTNG_SC_COMPAT)) || defined(CONFIG_ARM64) || defined(CONFIG_ARM) */
 
+/*
+ * Enumeration of the open flags, as described in the 'open'
+ * system call man page.
+ */
+SC_LTTNG_TRACEPOINT_ENUM(lttng_file_status_flags,
+       TP_ENUM_VALUES(
+               ctf_enum_value("O_RDONLY", O_RDONLY)
+               ctf_enum_value("O_WRONLY", O_WRONLY)
+               ctf_enum_value("O_RDWR", O_RDWR)
+               ctf_enum_value("O_CREAT", O_CREAT)
+               ctf_enum_value("O_EXCL", O_EXCL)
+               ctf_enum_value("O_NOCTTY", O_NOCTTY)
+               ctf_enum_value("O_TRUNC", O_TRUNC)
+               ctf_enum_value("O_APPEND", O_APPEND)
+               ctf_enum_value("O_NONBLOCK", O_NONBLOCK)
+               ctf_enum_value("O_DSYNC", O_DSYNC)
+               ctf_enum_value("FASYNC", FASYNC)
+               ctf_enum_value("O_DIRECT", O_DIRECT)
+               ctf_enum_value("O_LARGEFILE", O_LARGEFILE)
+               ctf_enum_value("O_DIRECTORY", O_DIRECTORY)
+               ctf_enum_value("O_NOFOLLOW", O_NOFOLLOW)
+               ctf_enum_value("O_NOATIME", O_NOATIME)
+               ctf_enum_value("O_CLOEXEC", O_CLOEXEC)
+               ctf_enum_value("O_SYNC", __O_SYNC)
+               ctf_enum_value("O_PATH", O_PATH)
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0))
+               ctf_enum_value("O_TMPFILE", __O_TMPFILE)
+#endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0)) */
+       )
+)
+
+/*
+ * Enumeration of the open flags, as described in the 'open'
+ * system call man page.
+ */
+SC_LTTNG_TRACEPOINT_ENUM(lttng_file_mode,
+       TP_ENUM_VALUES(
+               ctf_enum_value("S_IRWXU", S_IRWXU)
+               ctf_enum_value("S_IRUSR", S_IRUSR)
+               ctf_enum_value("S_IWUSR", S_IWUSR)
+               ctf_enum_value("S_IXUSR", S_IXUSR)
+               ctf_enum_value("S_IRWXG", S_IRWXG)
+               ctf_enum_value("S_IRGRP", S_IRGRP)
+               ctf_enum_value("S_IWGRP", S_IWGRP)
+               ctf_enum_value("S_IXGRP", S_IXGRP)
+               ctf_enum_value("S_IRWXO", S_IRWXO)
+               ctf_enum_value("S_IROTH", S_IROTH)
+               ctf_enum_value("S_IWOTH", S_IWOTH)
+               ctf_enum_value("S_IXOTH", S_IXOTH)
+               ctf_enum_value("S_ISUID", S_ISUID)
+               ctf_enum_value("S_ISGID", S_ISGID)
+               ctf_enum_value("S_ISVTX", S_ISVTX)
+       )
+)
+
+#define OVERRIDE_32_openat
+#define OVERRIDE_64_openat
+SC_LTTNG_TRACEPOINT_EVENT(openat,
+       TP_PROTO(sc_exit(long ret,) int dfd, const char * filename, int flags, umode_t mode),
+       TP_ARGS(sc_exit(ret,) dfd, filename, flags, mode),
+       TP_FIELDS(
+               sc_exit(ctf_integer(long, ret, ret))
+               sc_in(ctf_integer(int, dfd, dfd))
+               sc_in(ctf_user_string(filename, filename))
+               sc_in(ctf_enum(lttng_file_status_flags, int, flags, flags))
+               sc_in(ctf_enum(lttng_file_mode, umode_t, mode, mode))
+       )
+)
+
+#define OVERRIDE_32_open
+#define OVERRIDE_64_open
+SC_LTTNG_TRACEPOINT_EVENT(open,
+       TP_PROTO(sc_exit(long ret,) const char * filename, int flags, umode_t mode),
+       TP_ARGS(sc_exit(ret,) filename, flags, mode),
+       TP_FIELDS(
+               sc_exit(ctf_integer(long, ret, ret))
+               sc_in(ctf_user_string(filename, filename))
+               sc_in(ctf_enum(lttng_file_status_flags, int, flags, flags))
+               sc_in(ctf_enum(lttng_file_mode, umode_t, mode, mode))
+       )
+)
+
 #endif /* CREATE_SYSCALL_TABLE */
This page took 0.029541 seconds and 4 git commands to generate.