Fix: endianness of integers received by filter
[deliverable/lttng-modules.git] / probes / lttng-tracepoint-event-impl.h
index 91de803abe0d927060e21cd3431e6db2f302919d..ba906ac49c01fa46b34bf8e8d4a87570ab3b3a9e 100644 (file)
 #include <linux/debugfs.h>
 #include <linux/rculist.h>
 #include <asm/byteorder.h>
+#include <linux/swab.h>
 
 #include <probes/lttng.h>
 #include <probes/lttng-types.h>
 #include <probes/lttng-probe-user.h>
 #include <wrapper/vmalloc.h>   /* for wrapper_vmalloc_sync_all() */
 #include <wrapper/ringbuffer/frontend_types.h>
+#include <wrapper/ringbuffer/backend.h>
 #include <wrapper/rcu.h>
 #include <lttng-events.h>
 #include <lttng-tracer-core.h>
  */
 
 /* Reset all macros within TRACEPOINT_EVENT */
-#include "lttng-events-reset.h"
+#include <probes/lttng-events-reset.h>
 
 #undef TP_PROTO
 #define TP_PROTO(...)  __VA_ARGS__
@@ -151,7 +153,7 @@ void trace_##_name(void);
  * class and the instance using the class actually match.
  */
 
-#include "lttng-events-reset.h"        /* Reset all macros within TRACE_EVENT */
+#include <probes/lttng-events-reset.h> /* Reset all macros within TRACE_EVENT */
 
 #undef TP_PROTO
 #define TP_PROTO(...)  __VA_ARGS__
@@ -185,9 +187,9 @@ void __event_template_proto___##_name(void);
  */
 
 /* Reset all macros within TRACEPOINT_EVENT */
-#include "lttng-events-reset.h"
-#include "lttng-events-write.h"
-#include "lttng-events-nowrite.h"
+#include <probes/lttng-events-reset.h>
+#include <probes/lttng-events-write.h>
+#include <probes/lttng-events-nowrite.h>
 
 #undef _ctf_integer_ext
 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
@@ -323,7 +325,7 @@ void __event_template_proto___##_name(void);
  */
 
 /* Reset all macros within TRACEPOINT_EVENT */
-#include "lttng-events-reset.h"
+#include <probes/lttng-events-reset.h>
 
 #undef TP_PROTO
 #define TP_PROTO(...)  __VA_ARGS__
@@ -345,8 +347,8 @@ static void __event_probe__##_name(void *__data);
  */
 
 /* Reset all macros within TRACEPOINT_EVENT */
-#include "lttng-events-reset.h"
-#include "lttng-events-write.h"
+#include <probes/lttng-events-reset.h>
+#include <probes/lttng-events-write.h>
 
 #undef _ctf_integer_ext
 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
@@ -438,9 +440,9 @@ static inline size_t __event_get_size__##_name(size_t *__dynamic_len,             \
  */
 
 /* Reset all macros within TRACEPOINT_EVENT */
-#include "lttng-events-reset.h"
-#include "lttng-events-write.h"
-#include "lttng-events-nowrite.h"
+#include <probes/lttng-events-reset.h>
+#include <probes/lttng-events-write.h>
+#include <probes/lttng-events-nowrite.h>
 
 #undef _ctf_integer_ext_fetched
 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
@@ -456,18 +458,24 @@ static inline size_t __event_get_size__##_name(size_t *__dynamic_len,           \
                case 2:                                                        \
                {                                                              \
                        union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
+                       if (_byte_order != __BYTE_ORDER)                       \
+                               __swab16s(&__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)                       \
+                               __swab32s(&__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)                       \
+                               __swab64s(&__tmp.v);                           \
                        __ctf_tmp_int64 = (int64_t) __tmp.v;                   \
                        break;                                                 \
                }                                                              \
@@ -487,18 +495,24 @@ static inline size_t __event_get_size__##_name(size_t *__dynamic_len,           \
                case 2:                                                        \
                {                                                              \
                        union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
+                       if (_byte_order != __BYTE_ORDER)                       \
+                               __swab16s(&__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)                       \
+                               __swab32s(&__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)                       \
+                               __swab64s(&__tmp.v);                           \
                        __ctf_tmp_uint64 = (uint64_t) __tmp.v;                 \
                        break;                                                 \
                }                                                              \
@@ -515,11 +529,15 @@ static inline size_t __event_get_size__##_name(size_t *__dynamic_len,           \
 
 #undef _ctf_integer_ext_isuser1
 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
-{                                                                             \
-       __typeof__(_user_src) _src;                                            \
-       if (get_user(_src, &(_user_src)))                                      \
-               _src = 0;                                                      \
-       _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
+{                                                                                      \
+       union {                                                                         \
+               char __array[sizeof(_user_src)];                                        \
+               __typeof__(_user_src) __v;                                              \
+       } __tmp_fetch;                                                                  \
+       if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array,           \
+                               &(_user_src), sizeof(_user_src)))                       \
+               memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array));            \
+       _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \
 }
 
 #undef _ctf_integer_ext
@@ -608,8 +626,8 @@ void __event_prepare_filter_stack__##_name(char *__stack_data,                    \
  */
 
 /* Reset all macros within TRACEPOINT_EVENT */
-#include "lttng-events-reset.h"
-#include "lttng-events-write.h"
+#include <probes/lttng-events-reset.h>
+#include <probes/lttng-events-write.h>
 
 #undef _ctf_integer_ext
 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
@@ -680,8 +698,8 @@ static inline size_t __event_get_align__##_name(void *__tp_locvar)        \
  */
 
 /* Reset all macros within TRACEPOINT_EVENT */
-#include "lttng-events-reset.h"
-#include "lttng-events-write.h"
+#include <probes/lttng-events-reset.h>
+#include <probes/lttng-events-write.h>
 
 #undef _ctf_integer_ext_fetched
 #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
@@ -698,10 +716,14 @@ static inline size_t __event_get_align__##_name(void *__tp_locvar)              \
 #undef _ctf_integer_ext_isuser1
 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
 {                                                                             \
-       __typeof__(_user_src) _src;                                            \
-       if (get_user(_src, &(_user_src)))                                      \
-               _src = 0;                                                      \
-       _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
+       union {                                                                         \
+               char __array[sizeof(_user_src)];                                        \
+               __typeof__(_user_src) __v;                                              \
+       } __tmp_fetch;                                                                  \
+       if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array,           \
+                               &(_user_src), sizeof(_user_src)))                       \
+               memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array));            \
+       _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \
 }
 
 #undef _ctf_integer_ext
@@ -1041,7 +1063,7 @@ __post:                                                                         \
 
 /* Named field types must be defined in lttng-types.h */
 
-#include "lttng-events-reset.h"        /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
+#include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
 
 #ifndef TP_PROBE_CB
 #define TP_PROBE_CB(_template) &__event_probe__##_template
@@ -1070,7 +1092,7 @@ static const struct lttng_event_desc __event_desc___##_map = {            \
  * Create an array of event description pointers.
  */
 
-#include "lttng-events-reset.h"        /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
+#include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
 
 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
@@ -1118,7 +1140,7 @@ static __used struct lttng_probe_desc TP_ID(__probe_desc___, TRACE_SYSTEM) = {
  * Register/unregister probes at module load/unload.
  */
 
-#include "lttng-events-reset.h"        /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
+#include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
 
 #define TP_ID1(_token, _system)        _token##_system
 #define TP_ID(_token, _system) TP_ID1(_token, _system)
This page took 0.027563 seconds and 5 git commands to generate.