X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=probes%2Flttng-tracepoint-event-impl.h;h=39454fb3d9c13d68fc4648aa135a1aacd224bb80;hb=d1f652f8d4f6d1de8f6d32ae8711d6469c38892c;hp=aa16475d24d181dd3f7c22ce7e786d3759060d1a;hpb=141ddf2856b853516b4170ef8104afe85e6efe68;p=lttng-modules.git diff --git a/probes/lttng-tracepoint-event-impl.h b/probes/lttng-tracepoint-event-impl.h index aa16475d..39454fb3 100644 --- a/probes/lttng-tracepoint-event-impl.h +++ b/probes/lttng-tracepoint-event-impl.h @@ -1,22 +1,9 @@ -/* +/* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1) + * * lttng-tracepoint-event-impl.h * * Copyright (C) 2009 Steven Rostedt * Copyright (C) 2009-2014 Mathieu Desnoyers - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; only - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include @@ -24,6 +11,7 @@ #include #include #include +#include #include #include @@ -34,6 +22,9 @@ #include #include #include +#include + +#define __LTTNG_NULL_STRING "(null)" /* * Macro declarations used for all stages. @@ -220,6 +211,24 @@ void __event_template_proto___##_name(void); .string = (_string), \ }, +/* Enumeration entry (automatic value; follows the rules of CTF) */ +#undef ctf_enum_auto +#define ctf_enum_auto(_string) \ + { \ + .start = { \ + .signedness = -1, \ + .value = -1, \ + }, \ + .end = { \ + .signedness = -1, \ + .value = -1, \ + }, \ + .string = (_string), \ + .options = { \ + .is_auto = 1, \ + } \ + }, + #undef TP_ENUM_VALUES #define TP_ENUM_VALUES(...) \ __VA_ARGS__ @@ -254,7 +263,7 @@ void __event_template_proto___##_name(void); }, #undef _ctf_array_encoded -#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \ +#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _byte_order, _base, _user, _nowrite) \ { \ .name = #_item, \ .type = \ @@ -264,7 +273,7 @@ void __event_template_proto___##_name(void); { \ .array = \ { \ - .elem_type = __type_integer(_type, 0, 0, 0, __BYTE_ORDER, 10, _encoding), \ + .elem_type = __type_integer(_type, 0, 0, 0, _byte_order, _base, _encoding), \ .length = _length, \ } \ } \ @@ -279,7 +288,7 @@ void __event_template_proto___##_name(void); .name = #_item, \ .type = \ { \ - .atype = atype_array, \ + .atype = atype_array_bitfield, \ .u = \ { \ .array = \ @@ -325,7 +334,7 @@ void __event_template_proto___##_name(void); .name = #_item, \ .type = \ { \ - .atype = atype_sequence, \ + .atype = atype_sequence_bitfield, \ .u = \ { \ .sequence = \ @@ -455,13 +464,13 @@ static void __event_probe__##_name(void *__data); __event_len += sizeof(_type); #undef _ctf_array_encoded -#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \ +#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _byte_order, _base, _user, _nowrite) \ __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \ __event_len += sizeof(_type) * (_length); #undef _ctf_array_bitfield #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \ - _ctf_array_encoded(_type, _item, _src, _length, none, _user, _nowrite) + _ctf_array_encoded(_type, _item, _src, _length, none, __LITTLE_ENDIAN, 0, _user, _nowrite) #undef _ctf_sequence_encoded #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \ @@ -500,7 +509,7 @@ static void __event_probe__##_name(void *__data); max_t(size_t, lttng_strlen_user_inatomic(_src), 1); \ } else { \ __event_len += this_cpu_ptr(<tng_dynamic_len_stack)->stack[this_cpu_ptr(<tng_dynamic_len_stack)->offset - 1] = \ - strlen(_src) + 1; \ + strlen((_src) ? (_src) : __LTTNG_NULL_STRING) + 1; \ } #undef _ctf_enum @@ -677,7 +686,7 @@ error: \ _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite) #undef _ctf_array_encoded -#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \ +#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _byte_order, _base, _user, _nowrite) \ { \ unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \ const void *__ctf_tmp_ptr = (_src); \ @@ -689,7 +698,7 @@ error: \ #undef _ctf_array_bitfield #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \ - _ctf_array_encoded(_type, _item, _src, _length, none, _user, _nowrite) + _ctf_array_encoded(_type, _item, _src, _length, none, __LITTLE_ENDIAN, 0, _user, _nowrite) #undef _ctf_sequence_encoded #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \ @@ -713,7 +722,8 @@ error: \ #undef _ctf_string #define _ctf_string(_item, _src, _user, _nowrite) \ { \ - const void *__ctf_tmp_ptr = (_src); \ + const void *__ctf_tmp_ptr = \ + ((_src) ? (_src) : __LTTNG_NULL_STRING); \ memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \ __stack_data += sizeof(void *); \ } @@ -770,12 +780,12 @@ void __event_prepare_filter_stack__##_name(char *__stack_data, \ __event_align = max_t(size_t, __event_align, lttng_alignof(_type)); #undef _ctf_array_encoded -#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \ +#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _byte_order, _base, _user, _nowrite) \ __event_align = max_t(size_t, __event_align, lttng_alignof(_type)); #undef _ctf_array_bitfield #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \ - _ctf_array_encoded(_type, _item, _src, _length, none, _user, _nowrite) + _ctf_array_encoded(_type, _item, _src, _length, none, __LITTLE_ENDIAN, 0, _user, _nowrite) #undef _ctf_sequence_encoded #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \ @@ -884,7 +894,7 @@ static inline size_t __event_get_align__##_name(void *__tp_locvar) \ _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite) #undef _ctf_array_encoded -#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \ +#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _byte_order, _base, _user, _nowrite) \ lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \ if (_user) { \ __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \ @@ -1024,12 +1034,16 @@ static inline size_t __event_get_align__##_name(void *__tp_locvar) \ #undef _ctf_string #define _ctf_string(_item, _src, _user, _nowrite) \ - lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \ if (_user) { \ + lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \ __chan->ops->event_strcpy_from_user(&__ctx, _src, \ __get_dynamic_len(dest)); \ } else { \ - __chan->ops->event_strcpy(&__ctx, _src, \ + const char *__ctf_tmp_string = \ + ((_src) ? (_src) : __LTTNG_NULL_STRING); \ + lib_ring_buffer_align_ctx(&__ctx, \ + lttng_alignof(*__ctf_tmp_string)); \ + __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \ __get_dynamic_len(dest)); \ } @@ -1105,7 +1119,7 @@ static void __event_probe__##_name(void *__data, _proto) \ struct lib_ring_buffer_ctx __ctx; \ ssize_t __event_len; \ size_t __event_align; \ - size_t __orig_dynamic_len_offset, __dynamic_len_idx; \ + size_t __orig_dynamic_len_offset, __dynamic_len_idx __attribute__((unused)); \ union { \ size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)]; \ char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \ @@ -1114,18 +1128,37 @@ static void __event_probe__##_name(void *__data, _proto) \ struct probe_local_vars __tp_locvar; \ struct probe_local_vars *tp_locvar __attribute__((unused)) = \ &__tp_locvar; \ - struct lttng_pid_tracker *__lpf; \ + struct lttng_id_tracker_rcu *__lf; \ \ if (!_TP_SESSION_CHECK(session, __session)) \ return; \ - if (unlikely(!ACCESS_ONCE(__session->active))) \ + if (unlikely(!READ_ONCE(__session->active))) \ + return; \ + if (unlikely(!READ_ONCE(__chan->enabled))) \ + return; \ + if (unlikely(!READ_ONCE(__event->enabled))) \ + return; \ + __lf = lttng_rcu_dereference(__session->pid_tracker.p); \ + if (__lf && likely(!lttng_id_tracker_lookup(__lf, current->tgid))) \ return; \ - if (unlikely(!ACCESS_ONCE(__chan->enabled))) \ + __lf = lttng_rcu_dereference(__session->vpid_tracker.p); \ + if (__lf && likely(!lttng_id_tracker_lookup(__lf, task_tgid_vnr(current)))) \ return; \ - if (unlikely(!ACCESS_ONCE(__event->enabled))) \ + __lf = lttng_rcu_dereference(__session->uid_tracker.p); \ + if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ + from_kuid(&init_user_ns, current_uid())))) \ return; \ - __lpf = lttng_rcu_dereference(__session->pid_tracker); \ - if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \ + __lf = lttng_rcu_dereference(__session->vuid_tracker.p); \ + if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ + from_kuid(current_user_ns(), current_uid())))) \ + return; \ + __lf = lttng_rcu_dereference(__session->gid_tracker.p); \ + if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ + from_kgid(&init_user_ns, current_gid())))) \ + return; \ + __lf = lttng_rcu_dereference(__session->vgid_tracker.p); \ + if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ + from_kgid(current_user_ns(), current_gid())))) \ return; \ __orig_dynamic_len_offset = this_cpu_ptr(<tng_dynamic_len_stack)->offset; \ __dynamic_len_idx = __orig_dynamic_len_offset; \ @@ -1179,7 +1212,7 @@ static void __event_probe__##_name(void *__data) \ struct lib_ring_buffer_ctx __ctx; \ ssize_t __event_len; \ size_t __event_align; \ - size_t __orig_dynamic_len_offset, __dynamic_len_idx; \ + size_t __orig_dynamic_len_offset, __dynamic_len_idx __attribute__((unused)); \ union { \ size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)]; \ char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \ @@ -1188,18 +1221,37 @@ static void __event_probe__##_name(void *__data) \ struct probe_local_vars __tp_locvar; \ struct probe_local_vars *tp_locvar __attribute__((unused)) = \ &__tp_locvar; \ - struct lttng_pid_tracker *__lpf; \ + struct lttng_id_tracker_rcu *__lf; \ \ if (!_TP_SESSION_CHECK(session, __session)) \ return; \ - if (unlikely(!ACCESS_ONCE(__session->active))) \ + if (unlikely(!READ_ONCE(__session->active))) \ + return; \ + if (unlikely(!READ_ONCE(__chan->enabled))) \ + return; \ + if (unlikely(!READ_ONCE(__event->enabled))) \ + return; \ + __lf = lttng_rcu_dereference(__session->pid_tracker.p); \ + if (__lf && likely(!lttng_id_tracker_lookup(__lf, current->tgid))) \ + return; \ + __lf = lttng_rcu_dereference(__session->vpid_tracker.p); \ + if (__lf && likely(!lttng_id_tracker_lookup(__lf, task_tgid_vnr(current)))) \ + return; \ + __lf = lttng_rcu_dereference(__session->uid_tracker.p); \ + if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ + from_kuid(&init_user_ns, current_uid())))) \ return; \ - if (unlikely(!ACCESS_ONCE(__chan->enabled))) \ + __lf = lttng_rcu_dereference(__session->vuid_tracker.p); \ + if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ + from_kuid(current_user_ns(), current_uid())))) \ return; \ - if (unlikely(!ACCESS_ONCE(__event->enabled))) \ + __lf = lttng_rcu_dereference(__session->gid_tracker.p); \ + if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ + from_kgid(&init_user_ns, current_gid())))) \ return; \ - __lpf = lttng_rcu_dereference(__session->pid_tracker); \ - if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \ + __lf = lttng_rcu_dereference(__session->vgid_tracker.p); \ + if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ + from_kgid(current_user_ns(), current_gid())))) \ return; \ __orig_dynamic_len_offset = this_cpu_ptr(<tng_dynamic_len_stack)->offset; \ __dynamic_len_idx = __orig_dynamic_len_offset; \