1 /* 2 * %CopyrightBegin% 3 * 4 * Copyright Dustin Sallings, Michal Ptaszek, Scott Lystig Fritchie 2011-2017. 5 * All Rights Reserved. 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 * 19 * %CopyrightEnd% 20 */ 21 22 #ifndef __DTRACE_WRAPPER_H 23 #define __DTRACE_WRAPPER_H 24 25 #define DTRACE_TERM_BUF_SIZE 256 26 27 /* 28 * Some varieties of SystemTap macros do not like statically-sized 29 * char[N] buffers. (For example, CentOS 6's macros.) 30 * So, we'll play a game to humor them. 31 * 32 * The code necessary to play nice with CentOS 6's SystemTap looks 33 * stupid to a C programmer's eyes, so we hide the ugliness with this 34 * macro, which expands: 35 * 36 * DTRACE_CHARBUF(proc_name, 64); 37 * 38 * to become: 39 * 40 * char proc_name_BUFFER[64], *proc_name = proc_name_BUFFER; 41 */ 42 43 #define DTRACE_CHARBUF(name, size) \ 44 char name##_BUFFER[size], *name = name##_BUFFER 45 46 #define DTRACE_CHARBUF_NAME(name) name##_BUFFER 47 48 #if defined(USE_DYNAMIC_TRACE) && defined(USE_VM_PROBES) 49 50 #ifdef __cplusplus 51 extern "C++" { 52 /* Generated erlang_dtrace.h contains #include <sys/sdt.h>, which 53 * has C++ code requiring C++ linkage. However beam_asm.hpp includes 54 * global.h with C linkage, and compilation fails, because <sdt.h> 55 * uses C++ templates when __cplusplus is defined. 56 */ 57 #include "erlang_dtrace.h" 58 } 59 #else 60 #include "erlang_dtrace.h" 61 #endif 62 63 #define DTRACE_ENABLED(name) \ 64 erlang_##name##_enabled() 65 #define DTRACE0(name) \ 66 erlang_##name() 67 #define DTRACE1(name, a0) \ 68 erlang_##name(a0) 69 #define DTRACE2(name, a0, a1) \ 70 erlang_##name((a0), (a1)) 71 #define DTRACE3(name, a0, a1, a2) \ 72 erlang_##name((a0), (a1), (a2)) 73 #define DTRACE4(name, a0, a1, a2, a3) \ 74 erlang_##name((a0), (a1), (a2), (a3)) 75 #define DTRACE5(name, a0, a1, a2, a3, a4) \ 76 erlang_##name((a0), (a1), (a2), (a3), (a4)) 77 #define DTRACE6(name, a0, a1, a2, a3, a4, a5) \ 78 erlang_##name((a0), (a1), (a2), (a3), (a4), (a5)) 79 #define DTRACE7(name, a0, a1, a2, a3, a4, a5, a6) \ 80 erlang_##name((a0), (a1), (a2), (a3), (a4), (a5), (a6)) 81 #define DTRACE10(name, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) \ 82 erlang_##name((a0), (a1), (a2), (a3), (a4), (a5), (a6), (a7), (a8), (a9)) 83 #define DTRACE11(name, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) \ 84 erlang_##name((a0), (a1), (a2), (a3), (a4), (a5), (a6), (a7), (a8), (a9), (a10)) 85 86 #if defined(_SDT_PROBE) && !defined(STAP_PROBE11) 87 /* SLF: This is Ubuntu 11-style SystemTap hackery */ 88 /* workaround for missing STAP macro */ 89 #define STAP_PROBE11(provider,name,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11) \ 90 _SDT_PROBE(provider, name, 11, \ 91 (arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11)) 92 #define _SDT_ASM_OPERANDS_11(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11) \ 93 _SDT_ASM_OPERANDS_10(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9,arg10), \ 94 _SDT_ARG(11, arg11) 95 #endif 96 97 #ifdef STAP_PROBE_ADDR 98 /* SLF: This is CentOS 5-style SystemTap hackery */ 99 /* SystemTap compat mode cannot support 11 args. We'll ignore the 11th */ 100 #define STAP_PROBE11(provider,probe,parm1,parm2,parm3,parm4,parm5,parm6,parm7,parm8,parm9,parm10,parm11) \ 101 STAP_PROBE10(provider,probe,(parm1),(parm2),(parm3),(parm4),(parm5),(parm6),(parm7),(parm8),(parm9),(parm10)) 102 #endif /* STAP_PROBE_ADDR */ 103 104 #else /* USE_DYNAMIC_TRACE && USE_VM_PROBES */ 105 106 /* Render all macros to do nothing */ 107 #define DTRACE_ENABLED(name) 0 108 #define DTRACE0(name) do {} while (0) 109 #define DTRACE1(name, a0) do {} while (0) 110 #define DTRACE2(name, a0, a1) do {} while (0) 111 #define DTRACE3(name, a0, a1, a2) do {} while (0) 112 #define DTRACE4(name, a0, a1, a2, a3) do {} while (0) 113 #define DTRACE5(name, a0, a1, a2, a3, a4) do {} while (0) 114 #define DTRACE6(name, a0, a1, a2, a3, a4, a5) do {} while (0) 115 #define DTRACE7(name, a0, a1, a2, a3, a4, a5, a6) do {} while (0) 116 #define DTRACE10(name, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) \ 117 do {} while (0) 118 #define DTRACE11(name, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) \ 119 do {} while (0) 120 121 #endif /* USE_DYNAMIC_TRACE && USE_VM_PROBES */ 122 123 #endif /* __DTRACE_WRAPPER_H */ 124