Fix: don't generate 0-len array in tracepoint probes
[lttng-ust.git] / include / lttng / ust-tracepoint-event.h
index d9aa6ce6bdb8f8496b7b7a1dc41facf20ca6a169..1e75d613350ea65c588e9928acc0093422eb25e5 100644 (file)
@@ -28,6 +28,7 @@
 #include <lttng/ringbuffer-config.h>
 #include <lttng/ust-compiler.h>
 #include <lttng/tracepoint.h>
+#include <byteswap.h>
 #include <string.h>
 
 #undef tp_list_for_each_entry_rcu
@@ -207,6 +208,7 @@ static const char                                                   \
 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields)                            \
        static const struct lttng_event_field __event_fields___##_provider##___##_name[] = { \
                _fields                                                                      \
+               ctf_integer(int, dummy, 0)      /* Dummy, C99 forbids 0-len array. */        \
        };
 
 #include TRACEPOINT_INCLUDE
@@ -318,18 +320,24 @@ size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS
                case 2:                                                        \
                {                                                              \
                        union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
+                       if (_byte_order != BYTE_ORDER)                         \
+                               __tmp.v = bswap_16(__tmp.v);                   \
                        __ctf_tmp_int64 = (int64_t) __tmp.v;                   \
                        break;                                                 \
                }                                                              \
                case 4:                                                        \
                {                                                              \
                        union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
+                       if (_byte_order != BYTE_ORDER)                         \
+                               __tmp.v = bswap_32(__tmp.v);                   \
                        __ctf_tmp_int64 = (int64_t) __tmp.v;                   \
                        break;                                                 \
                }                                                              \
                case 8:                                                        \
                {                                                              \
                        union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
+                       if (_byte_order != BYTE_ORDER)                         \
+                               __tmp.v = bswap_64(__tmp.v);                   \
                        __ctf_tmp_int64 = (int64_t) __tmp.v;                   \
                        break;                                                 \
                }                                                              \
@@ -349,18 +357,24 @@ size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS
                case 2:                                                        \
                {                                                              \
                        union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
+                       if (_byte_order != BYTE_ORDER)                         \
+                               __tmp.v = bswap_16(__tmp.v);                   \
                        __ctf_tmp_uint64 = (uint64_t) __tmp.v;                 \
                        break;                                                 \
                }                                                              \
                case 4:                                                        \
                {                                                              \
                        union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
+                       if (_byte_order != BYTE_ORDER)                         \
+                               __tmp.v = bswap_32(__tmp.v);                   \
                        __ctf_tmp_uint64 = (uint64_t) __tmp.v;                 \
                        break;                                                 \
                }                                                              \
                case 8:                                                        \
                {                                                              \
                        union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
+                       if (_byte_order != BYTE_ORDER)                         \
+                               __tmp.v = bswap_64(__tmp.v);                   \
                        __ctf_tmp_uint64 = (uint64_t) __tmp.v;                 \
                        break;                                                 \
                }                                                              \
@@ -566,11 +580,23 @@ size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args))      \
 #define _TP_SESSION_CHECK(session, csession)   1
 #endif /* TP_SESSION_CHECK */
 
+/*
+ * Use of __builtin_return_address(0) sometimes seems to cause stack
+ * corruption on 32-bit PowerPC. Disable this feature on that
+ * architecture for now by always using the NULL value for the ip
+ * context.
+ */
 #undef _TP_IP_PARAM
 #ifdef TP_IP_PARAM
 #define _TP_IP_PARAM(x)                (x)
 #else /* TP_IP_PARAM */
+
+#if defined(__PPC__) && !defined(__PPC64__)
+#define _TP_IP_PARAM(x)                NULL
+#else /* #if defined(__PPC__) && !defined(__PPC64__) */
 #define _TP_IP_PARAM(x)                __builtin_return_address(0)
+#endif /* #else #if defined(__PPC__) && !defined(__PPC64__) */
+
 #endif /* TP_IP_PARAM */
 
 /*
@@ -593,8 +619,8 @@ void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args))           \
        size_t __event_len, __event_align;                                    \
        size_t __dynamic_len_idx = 0;                                         \
        union {                                                               \
-               size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
-               char __filter_stack_data[2 * sizeof(unsigned long) * _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
+               size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1]; \
+               char __filter_stack_data[2 * sizeof(unsigned long) * (_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1)]; \
        } __stackvar;                                                         \
        int __ret;                                                            \
                                                                              \
@@ -723,7 +749,7 @@ const struct lttng_event_desc __event_desc___##_provider##_##_name = {             \
        .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\
        .ctx = NULL,                                                           \
        .fields = __event_fields___##_provider##___##_template,                \
-       .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template), \
+       .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template) - 1, \
        .loglevel = &__ref_loglevel___##_provider##___##_name,                 \
        .signature = __tp_event_signature___##_provider##___##_template,       \
        .u = { .ext = { .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name } }, \
@@ -746,6 +772,7 @@ const struct lttng_event_desc __event_desc___##_provider##_##_name = {             \
 
 static const struct lttng_event_desc *_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)[] = {
 #include TRACEPOINT_INCLUDE
+       NULL,   /* Dummy, C99 forbids 0-len array. */
 };
 
 
@@ -759,7 +786,7 @@ static const struct lttng_event_desc *_TP_COMBINE_TOKENS(__event_desc___, TRACEP
 static struct lttng_probe_desc _TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER) = {
        .provider = __tp_stringify(TRACEPOINT_PROVIDER),
        .event_desc = _TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER),
-       .nr_events = _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)),
+       .nr_events = _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)) - 1,
        .head = { NULL, NULL },
        .lazy_init_head = { NULL, NULL },
        .lazy = 0,
This page took 0.030606 seconds and 4 git commands to generate.