sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1 | /* -*- c -*- |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 2 | ---------------------------------------------------------------- |
| 3 | |
| 4 | Notice that the following BSD-style license applies to this one |
| 5 | file (valgrind.h) only. The entire rest of Valgrind is licensed |
| 6 | under the terms of the GNU General Public License, version 2. See |
| 7 | the COPYING file in the source distribution for details. |
| 8 | |
| 9 | ---------------------------------------------------------------- |
| 10 | |
njn | b9c427c | 2004-12-01 14:14:42 +0000 | [diff] [blame] | 11 | This file is part of Valgrind, a dynamic binary instrumentation |
| 12 | framework. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 13 | |
njn | 5361242 | 2005-03-12 16:22:54 +0000 | [diff] [blame] | 14 | Copyright (C) 2000-2005 Julian Seward. All rights reserved. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 15 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 16 | Redistribution and use in source and binary forms, with or without |
| 17 | modification, are permitted provided that the following conditions |
| 18 | are met: |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 19 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 20 | 1. Redistributions of source code must retain the above copyright |
| 21 | notice, this list of conditions and the following disclaimer. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 22 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 23 | 2. The origin of this software must not be misrepresented; you must |
| 24 | not claim that you wrote the original software. If you use this |
| 25 | software in a product, an acknowledgment in the product |
| 26 | documentation would be appreciated but is not required. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 27 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 28 | 3. Altered source versions must be plainly marked as such, and must |
| 29 | not be misrepresented as being the original software. |
| 30 | |
| 31 | 4. The name of the author may not be used to endorse or promote |
| 32 | products derived from this software without specific prior written |
| 33 | permission. |
| 34 | |
| 35 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
| 36 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 37 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 38 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 39 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 40 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 41 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 42 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 43 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 44 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 45 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 46 | |
| 47 | ---------------------------------------------------------------- |
| 48 | |
| 49 | Notice that the above BSD-style license applies to this one file |
| 50 | (valgrind.h) only. The entire rest of Valgrind is licensed under |
| 51 | the terms of the GNU General Public License, version 2. See the |
| 52 | COPYING file in the source distribution for details. |
| 53 | |
| 54 | ---------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 55 | */ |
| 56 | |
| 57 | |
njn | 30d76c6 | 2005-06-18 15:07:39 +0000 | [diff] [blame] | 58 | /* This file is for inclusion into client (your!) code. |
| 59 | |
| 60 | You can use these macros to manipulate and query Valgrind's |
| 61 | execution inside your own programs. |
| 62 | |
| 63 | The resulting executables will still run without Valgrind, just a |
| 64 | little bit more slowly than they otherwise would, but otherwise |
| 65 | unchanged. When not running on valgrind, each client request |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 66 | consumes very few (eg. 7) instructions, so the resulting performance |
njn | 30d76c6 | 2005-06-18 15:07:39 +0000 | [diff] [blame] | 67 | loss is negligible unless you plan to execute client requests |
| 68 | millions of times per second. Nevertheless, if that is still a |
| 69 | problem, you can compile with the NVALGRIND symbol defined (gcc |
| 70 | -DNVALGRIND) so that client requests are not even compiled in. */ |
| 71 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 72 | #ifndef __VALGRIND_H |
| 73 | #define __VALGRIND_H |
| 74 | |
fitzhardinge | 39de4b4 | 2003-10-31 07:12:21 +0000 | [diff] [blame] | 75 | #include <stdarg.h> |
| 76 | |
njn | 3dd0a91 | 2005-06-28 19:44:10 +0000 | [diff] [blame] | 77 | /* Nb: this file might be included in a file compiled with -ansi. So |
| 78 | we can't use C++ style "//" comments nor the "asm" keyword (instead |
| 79 | use "__asm__"). */ |
| 80 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 81 | /* Derive some tags indicating what the target architecture is. Note |
| 82 | that in this file we're using the compiler's CPP symbols for |
| 83 | identifying architectures, which are different to the ones we use |
| 84 | within the rest of Valgrind. Note, __powerpc__ is active for both |
| 85 | 32 and 64-bit PPC, whereas __powerpc64__ is only active for the |
| 86 | latter. */ |
| 87 | #undef ARCH_x86 |
| 88 | #undef ARCH_amd64 |
| 89 | #undef ARCH_ppc32 |
| 90 | #undef ARCH_ppc64 |
| 91 | |
| 92 | #if defined(__i386__) |
| 93 | # define ARCH_x86 1 |
| 94 | #elif defined(__x86_64__) |
| 95 | # define ARCH_amd64 1 |
| 96 | #elif defined(__powerpc__) && !defined(__powerpc64__) |
| 97 | # define ARCH_ppc32 1 |
| 98 | #elif defined(__powerpc__) && defined(__powerpc64__) |
| 99 | # define ARCH_ppc64 1 |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 100 | #endif |
| 101 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 102 | /* If we're not compiling for our target architecture, don't generate |
| 103 | any inline asms. */ |
| 104 | #if !defined(ARCH_x86) && !defined(ARCH_amd64) \ |
| 105 | && !defined(ARCH_ppc32) && !defined(ARCH_ppc64) |
| 106 | # if !defined(NVALGRIND) |
| 107 | # define NVALGRIND 1 |
| 108 | # endif |
| 109 | #endif |
| 110 | |
| 111 | |
njn | 30d76c6 | 2005-06-18 15:07:39 +0000 | [diff] [blame] | 112 | /* ------------------------------------------------------------------ */ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 113 | /* ARCHITECTURE SPECIFICS for SPECIAL INSTRUCTIONS. There is nothing */ |
| 114 | /* in here of use to end-users -- skip to the next section. */ |
njn | 30d76c6 | 2005-06-18 15:07:39 +0000 | [diff] [blame] | 115 | /* ------------------------------------------------------------------ */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 116 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 117 | #if defined(NVALGRIND) |
njn | 26aba4d | 2005-05-16 13:31:23 +0000 | [diff] [blame] | 118 | |
| 119 | /* Define NVALGRIND to completely remove the Valgrind magic sequence |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 120 | from the compiled code (analogous to NDEBUG's effects on |
| 121 | assert()) */ |
| 122 | #define VALGRIND_DO_CLIENT_REQUEST( \ |
| 123 | _zzq_rlval, _zzq_default, _zzq_request, \ |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 124 | _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 125 | { \ |
| 126 | (_zzq_rlval) = (_zzq_default); \ |
njn | 26aba4d | 2005-05-16 13:31:23 +0000 | [diff] [blame] | 127 | } |
| 128 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 129 | #else /* ! NVALGRIND */ |
nethercote | e90c683 | 2004-10-18 18:07:49 +0000 | [diff] [blame] | 130 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 131 | /* The following defines the magic code sequences which the JITter |
| 132 | spots and handles magically. Don't look too closely at them as |
| 133 | they will rot your brain. |
| 134 | |
| 135 | The assembly code sequences for all architectures is in this one |
| 136 | file. This is because this file must be stand-alone, and we don't |
| 137 | want to have multiple files. |
| 138 | |
| 139 | For VALGRIND_DO_CLIENT_REQUEST, we must ensure that the default |
| 140 | value gets put in the return slot, so that everything works when |
| 141 | this is executed not under Valgrind. Args are passed in a memory |
| 142 | block, and so there's no intrinsic limit to the number that could |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 143 | be passed, but it's currently five. |
nethercote | e90c683 | 2004-10-18 18:07:49 +0000 | [diff] [blame] | 144 | |
nethercote | 5426544 | 2004-10-26 12:56:58 +0000 | [diff] [blame] | 145 | The macro args are: |
| 146 | _zzq_rlval result lvalue |
| 147 | _zzq_default default value (result returned when running on real CPU) |
| 148 | _zzq_request request code |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 149 | _zzq_arg1..5 request params |
nethercote | 5426544 | 2004-10-26 12:56:58 +0000 | [diff] [blame] | 150 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 151 | The other two macros are used to support function wrapping, and are |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 152 | a lot simpler. VALGRIND_GET_NR_CONTEXT returns the value of the |
| 153 | guest's NRADDR pseudo-register and whatever other information is |
| 154 | needed to safely run the call original from the wrapper: on |
| 155 | ppc64-linux, the R2 value at the divert point is also needed. This |
| 156 | information is abstracted into a user-visible type, OrigFn. |
| 157 | |
| 158 | VALGRIND_CALL_NOREDIR_* behaves the same as the following on the |
| 159 | guest, but guarantees that the branch instruction will not be |
| 160 | redirected: x86: call *%eax, amd64: call *%rax, ppc32/ppc64: |
| 161 | branch-and-link-to-r11. VALGRIND_CALL_NOREDIR is just text, not a |
| 162 | complete inline asm, since it needs to be combined with more magic |
| 163 | inline asm stuff to be useful. |
nethercote | e90c683 | 2004-10-18 18:07:49 +0000 | [diff] [blame] | 164 | */ |
| 165 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 166 | /* ---------------------------- x86 ---------------------------- */ |
sewardj | de4a4ab | 2005-03-23 13:10:32 +0000 | [diff] [blame] | 167 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 168 | #if defined(ARCH_x86) |
sewardj | c885844 | 2006-01-20 15:17:20 +0000 | [diff] [blame] | 169 | |
| 170 | typedef |
| 171 | struct { |
| 172 | unsigned int nraddr; /* where's the code? */ |
| 173 | } |
| 174 | OrigFn; |
| 175 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 176 | #define __SPECIAL_INSTRUCTION_PREAMBLE \ |
| 177 | "roll $3, %%edi ; roll $13, %%edi\n\t" \ |
sewardj | 1a85f4f | 2006-01-12 21:15:35 +0000 | [diff] [blame] | 178 | "roll $29, %%edi ; roll $19, %%edi\n\t" |
sewardj | de4a4ab | 2005-03-23 13:10:32 +0000 | [diff] [blame] | 179 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 180 | #define VALGRIND_DO_CLIENT_REQUEST( \ |
| 181 | _zzq_rlval, _zzq_default, _zzq_request, \ |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 182 | _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ |
| 183 | { volatile unsigned int _zzq_args[6]; \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 184 | volatile unsigned int _zzq_result; \ |
| 185 | _zzq_args[0] = (unsigned int)(_zzq_request); \ |
| 186 | _zzq_args[1] = (unsigned int)(_zzq_arg1); \ |
| 187 | _zzq_args[2] = (unsigned int)(_zzq_arg2); \ |
| 188 | _zzq_args[3] = (unsigned int)(_zzq_arg3); \ |
| 189 | _zzq_args[4] = (unsigned int)(_zzq_arg4); \ |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 190 | _zzq_args[5] = (unsigned int)(_zzq_arg5); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 191 | __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ |
| 192 | /* %EDX = client_request ( %EAX ) */ \ |
| 193 | "xchgl %%ebx,%%ebx" \ |
| 194 | : "=d" (_zzq_result) \ |
| 195 | : "a" (&_zzq_args[0]), "0" (_zzq_default) \ |
| 196 | : "cc", "memory" \ |
| 197 | ); \ |
| 198 | _zzq_rlval = _zzq_result; \ |
cerion | 85665ca | 2005-06-20 15:51:07 +0000 | [diff] [blame] | 199 | } |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 200 | |
sewardj | c885844 | 2006-01-20 15:17:20 +0000 | [diff] [blame] | 201 | #define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ |
| 202 | { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ |
| 203 | volatile unsigned int __addr; \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 204 | __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ |
| 205 | /* %EAX = guest_NRADDR */ \ |
| 206 | "xchgl %%ecx,%%ecx" \ |
| 207 | : "=a" (__addr) \ |
| 208 | : \ |
| 209 | : "cc", "memory" \ |
| 210 | ); \ |
sewardj | c885844 | 2006-01-20 15:17:20 +0000 | [diff] [blame] | 211 | _zzq_orig->nraddr = __addr; \ |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 212 | } |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 213 | |
| 214 | #define VALGRIND_CALL_NOREDIR_EAX \ |
| 215 | __SPECIAL_INSTRUCTION_PREAMBLE \ |
| 216 | /* call-noredir *%EAX */ \ |
| 217 | "xchgl %%edx,%%edx\n\t" |
| 218 | #endif /* ARCH_x86 */ |
| 219 | |
| 220 | /* --------------------------- amd64 --------------------------- */ |
| 221 | |
| 222 | #if defined(ARCH_amd64) |
sewardj | c885844 | 2006-01-20 15:17:20 +0000 | [diff] [blame] | 223 | |
| 224 | typedef |
| 225 | struct { |
| 226 | unsigned long long int nraddr; /* where's the code? */ |
| 227 | } |
| 228 | OrigFn; |
| 229 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 230 | #define __SPECIAL_INSTRUCTION_PREAMBLE \ |
| 231 | "rolq $3, %%rdi ; rolq $13, %%rdi\n\t" \ |
sewardj | 1a85f4f | 2006-01-12 21:15:35 +0000 | [diff] [blame] | 232 | "rolq $61, %%rdi ; rolq $51, %%rdi\n\t" |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 233 | |
| 234 | #define VALGRIND_DO_CLIENT_REQUEST( \ |
| 235 | _zzq_rlval, _zzq_default, _zzq_request, \ |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 236 | _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ |
| 237 | { volatile unsigned long long int _zzq_args[6]; \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 238 | volatile unsigned long long int _zzq_result; \ |
| 239 | _zzq_args[0] = (unsigned long long int)(_zzq_request); \ |
| 240 | _zzq_args[1] = (unsigned long long int)(_zzq_arg1); \ |
| 241 | _zzq_args[2] = (unsigned long long int)(_zzq_arg2); \ |
| 242 | _zzq_args[3] = (unsigned long long int)(_zzq_arg3); \ |
| 243 | _zzq_args[4] = (unsigned long long int)(_zzq_arg4); \ |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 244 | _zzq_args[5] = (unsigned long long int)(_zzq_arg5); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 245 | __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ |
| 246 | /* %RDX = client_request ( %RAX ) */ \ |
| 247 | "xchgq %%rbx,%%rbx" \ |
| 248 | : "=d" (_zzq_result) \ |
| 249 | : "a" (&_zzq_args[0]), "0" (_zzq_default) \ |
| 250 | : "cc", "memory" \ |
| 251 | ); \ |
| 252 | _zzq_rlval = _zzq_result; \ |
| 253 | } |
| 254 | |
sewardj | c885844 | 2006-01-20 15:17:20 +0000 | [diff] [blame] | 255 | #define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ |
| 256 | { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ |
| 257 | volatile unsigned long long int __addr; \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 258 | __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ |
| 259 | /* %RAX = guest_NRADDR */ \ |
| 260 | "xchgq %%rcx,%%rcx" \ |
| 261 | : "=a" (__addr) \ |
| 262 | : \ |
| 263 | : "cc", "memory" \ |
| 264 | ); \ |
sewardj | c885844 | 2006-01-20 15:17:20 +0000 | [diff] [blame] | 265 | _zzq_orig->nraddr = __addr; \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | #define VALGRIND_CALL_NOREDIR_RAX \ |
| 269 | __SPECIAL_INSTRUCTION_PREAMBLE \ |
| 270 | /* call-noredir *%RAX */ \ |
| 271 | "xchgq %%rdx,%%rdx\n\t" |
| 272 | #endif /* ARCH_amd64 */ |
| 273 | |
| 274 | /* --------------------------- ppc32 --------------------------- */ |
| 275 | |
| 276 | #if defined(ARCH_ppc32) |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 277 | |
| 278 | typedef |
| 279 | struct { |
sewardj | c885844 | 2006-01-20 15:17:20 +0000 | [diff] [blame] | 280 | unsigned int nraddr; /* where's the code? */ |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 281 | } |
| 282 | OrigFn; |
| 283 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 284 | #define __SPECIAL_INSTRUCTION_PREAMBLE \ |
| 285 | "rlwinm 0,0,3,0,0 ; rlwinm 0,0,13,0,0\n\t" \ |
sewardj | 1a85f4f | 2006-01-12 21:15:35 +0000 | [diff] [blame] | 286 | "rlwinm 0,0,29,0,0 ; rlwinm 0,0,19,0,0\n\t" |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 287 | |
| 288 | #define VALGRIND_DO_CLIENT_REQUEST( \ |
| 289 | _zzq_rlval, _zzq_default, _zzq_request, \ |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 290 | _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 291 | \ |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 292 | { unsigned int _zzq_args[6]; \ |
sewardj | 1a85f4f | 2006-01-12 21:15:35 +0000 | [diff] [blame] | 293 | register unsigned int _zzq_result __asm__("r3"); \ |
| 294 | register unsigned int* _zzq_ptr __asm__("r4"); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 295 | _zzq_args[0] = (unsigned int)(_zzq_request); \ |
| 296 | _zzq_args[1] = (unsigned int)(_zzq_arg1); \ |
| 297 | _zzq_args[2] = (unsigned int)(_zzq_arg2); \ |
| 298 | _zzq_args[3] = (unsigned int)(_zzq_arg3); \ |
| 299 | _zzq_args[4] = (unsigned int)(_zzq_arg4); \ |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 300 | _zzq_args[5] = (unsigned int)(_zzq_arg5); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 301 | _zzq_ptr = _zzq_args; \ |
| 302 | __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ |
| 303 | /* %R3 = client_request ( %R4 ) */ \ |
| 304 | "or 1,1,1" \ |
| 305 | : "=r" (_zzq_result) \ |
| 306 | : "0" (_zzq_default), "r" (_zzq_ptr) \ |
| 307 | : "cc", "memory"); \ |
| 308 | _zzq_rlval = _zzq_result; \ |
| 309 | } |
| 310 | |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 311 | #define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ |
| 312 | { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ |
| 313 | register unsigned int __addr __asm__("r3"); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 314 | __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ |
| 315 | /* %R3 = guest_NRADDR */ \ |
| 316 | "or 2,2,2" \ |
| 317 | : "=r" (__addr) \ |
| 318 | : \ |
| 319 | : "cc", "memory" \ |
| 320 | ); \ |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 321 | _zzq_orig->nraddr = __addr; \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | #define VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ |
| 325 | __SPECIAL_INSTRUCTION_PREAMBLE \ |
| 326 | /* branch-and-link-to-noredir *%R11 */ \ |
| 327 | "or 3,3,3\n\t" |
| 328 | #endif /* ARCH_ppc32 */ |
| 329 | |
| 330 | /* --------------------------- ppc64 --------------------------- */ |
| 331 | |
| 332 | #if defined(ARCH_ppc64) |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 333 | |
| 334 | typedef |
| 335 | struct { |
| 336 | unsigned long long int nraddr; /* where's the code? */ |
| 337 | unsigned long long int r2; /* what tocptr do we need? */ |
| 338 | } |
| 339 | OrigFn; |
| 340 | |
sewardj | 1a85f4f | 2006-01-12 21:15:35 +0000 | [diff] [blame] | 341 | #define __SPECIAL_INSTRUCTION_PREAMBLE \ |
| 342 | "rotldi 0,0,3 ; rotldi 0,0,13\n\t" \ |
| 343 | "rotldi 0,0,61 ; rotldi 0,0,51\n\t" |
| 344 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 345 | #define VALGRIND_DO_CLIENT_REQUEST( \ |
| 346 | _zzq_rlval, _zzq_default, _zzq_request, \ |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 347 | _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 348 | \ |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 349 | { unsigned long long int _zzq_args[6]; \ |
sewardj | 1a85f4f | 2006-01-12 21:15:35 +0000 | [diff] [blame] | 350 | register unsigned long long int _zzq_result __asm__("r3"); \ |
| 351 | register unsigned long long int* _zzq_ptr __asm__("r4"); \ |
| 352 | _zzq_args[0] = (unsigned long long int)(_zzq_request); \ |
| 353 | _zzq_args[1] = (unsigned long long int)(_zzq_arg1); \ |
| 354 | _zzq_args[2] = (unsigned long long int)(_zzq_arg2); \ |
| 355 | _zzq_args[3] = (unsigned long long int)(_zzq_arg3); \ |
| 356 | _zzq_args[4] = (unsigned long long int)(_zzq_arg4); \ |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 357 | _zzq_args[5] = (unsigned long long int)(_zzq_arg5); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 358 | _zzq_ptr = _zzq_args; \ |
sewardj | 1a85f4f | 2006-01-12 21:15:35 +0000 | [diff] [blame] | 359 | __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ |
| 360 | /* %R3 = client_request ( %R4 ) */ \ |
| 361 | "or 1,1,1" \ |
| 362 | : "=r" (_zzq_result) \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 363 | : "0" (_zzq_default), "r" (_zzq_ptr) \ |
sewardj | 1a85f4f | 2006-01-12 21:15:35 +0000 | [diff] [blame] | 364 | : "cc", "memory"); \ |
| 365 | _zzq_rlval = _zzq_result; \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 366 | } |
sewardj | 1a85f4f | 2006-01-12 21:15:35 +0000 | [diff] [blame] | 367 | |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 368 | #define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ |
| 369 | { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ |
| 370 | register unsigned long long int __addr __asm__("r3"); \ |
sewardj | 1a85f4f | 2006-01-12 21:15:35 +0000 | [diff] [blame] | 371 | __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ |
| 372 | /* %R3 = guest_NRADDR */ \ |
| 373 | "or 2,2,2" \ |
| 374 | : "=r" (__addr) \ |
| 375 | : \ |
| 376 | : "cc", "memory" \ |
| 377 | ); \ |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 378 | _zzq_orig->nraddr = __addr; \ |
| 379 | __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ |
| 380 | /* %R3 = guest_NRADDR_GPR2 */ \ |
| 381 | "or 4,4,4" \ |
| 382 | : "=r" (__addr) \ |
| 383 | : \ |
| 384 | : "cc", "memory" \ |
| 385 | ); \ |
| 386 | _zzq_orig->r2 = __addr; \ |
sewardj | 1a85f4f | 2006-01-12 21:15:35 +0000 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | #define VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ |
| 390 | __SPECIAL_INSTRUCTION_PREAMBLE \ |
| 391 | /* branch-and-link-to-noredir *%R11 */ \ |
| 392 | "or 3,3,3\n\t" |
| 393 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 394 | #endif /* ARCH_ppc64 */ |
cerion | 85665ca | 2005-06-20 15:51:07 +0000 | [diff] [blame] | 395 | |
njn | 3dd0a91 | 2005-06-28 19:44:10 +0000 | [diff] [blame] | 396 | /* Insert assembly code for other architectures here... */ |
njn | 26aba4d | 2005-05-16 13:31:23 +0000 | [diff] [blame] | 397 | |
sewardj | 37091fb | 2002-11-16 11:06:50 +0000 | [diff] [blame] | 398 | #endif /* NVALGRIND */ |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 399 | |
nethercote | 69d9c46 | 2004-10-26 13:00:12 +0000 | [diff] [blame] | 400 | |
njn | 30d76c6 | 2005-06-18 15:07:39 +0000 | [diff] [blame] | 401 | /* ------------------------------------------------------------------ */ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 402 | /* ARCHITECTURE SPECIFICS for FUNCTION WRAPPING. This is all very */ |
| 403 | /* ugly. It's the least-worst tradeoff I can think of. */ |
| 404 | /* ------------------------------------------------------------------ */ |
| 405 | |
| 406 | /* This section defines magic (a.k.a appalling-hack) macros for doing |
| 407 | guaranteed-no-redirection macros, so as to get from function |
| 408 | wrappers to the functions they are wrapping. The whole point is to |
| 409 | construct standard call sequences, but to do the call itself with a |
| 410 | special no-redirect call pseudo-instruction that the JIT |
| 411 | understands and handles specially. This section is long and |
| 412 | repetitious, and I can't see a way to make it shorter. |
| 413 | |
| 414 | The naming scheme is as follows: |
| 415 | |
| 416 | CALL_FN_{W,v}_{v,W,WW,WWW,WWWW,5W,6W,7W,etc} |
| 417 | |
| 418 | 'W' stands for "word" and 'v' for "void". Hence there are |
| 419 | different macros for calling arity 0, 1, 2, 3, 4, etc, functions, |
| 420 | and for each, the possibility of returning a word-typed result, or |
| 421 | no result. |
| 422 | */ |
| 423 | |
| 424 | /* Use these to write the name of your wrapper. NOTE: duplicates |
| 425 | VG_WRAP_FUNCTION_Z{U,Z} in pub_tool_redir.h. */ |
| 426 | |
| 427 | #define I_WRAP_SONAME_FNNAME_ZU(soname,fnname) \ |
| 428 | _vgwZU_##soname##_##fnname |
| 429 | |
| 430 | #define I_WRAP_SONAME_FNNAME_ZZ(soname,fnname) \ |
| 431 | _vgwZZ_##soname##_##fnname |
| 432 | |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 433 | /* Use this macro from within a wrapper function to collect the |
| 434 | context (address and possibly other info) of the original function. |
| 435 | Once you have that you can then use it in one of the CALL_FN_ |
| 436 | macros. The type of the argument _lval is OrigFn. */ |
| 437 | #define VALGRIND_GET_ORIG_FN(_lval) VALGRIND_GET_NR_CONTEXT(_lval) |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 438 | |
| 439 | /* Derivatives of the main macros below, for calling functions |
| 440 | returning void. */ |
| 441 | |
| 442 | #define CALL_FN_v_v(fnptr) \ |
| 443 | do { volatile unsigned long _junk; \ |
| 444 | CALL_FN_W_v(_junk,fnptr); } while (0) |
| 445 | |
| 446 | #define CALL_FN_v_W(fnptr, arg1) \ |
| 447 | do { volatile unsigned long _junk; \ |
| 448 | CALL_FN_W_W(_junk,fnptr,arg1); } while (0) |
| 449 | |
| 450 | #define CALL_FN_v_WW(fnptr, arg1,arg2) \ |
| 451 | do { volatile unsigned long _junk; \ |
| 452 | CALL_FN_W_WW(_junk,fnptr,arg1,arg2); } while (0) |
| 453 | |
sewardj | 5ce4b15 | 2006-03-11 12:57:41 +0000 | [diff] [blame] | 454 | #define CALL_FN_v_WWW(fnptr, arg1,arg2,arg3) \ |
| 455 | do { volatile unsigned long _junk; \ |
| 456 | CALL_FN_W_WWW(_junk,fnptr,arg1,arg2,arg3); } while (0) |
| 457 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 458 | /* ---------------------------- x86 ---------------------------- */ |
| 459 | |
| 460 | #if defined(ARCH_x86) |
| 461 | |
| 462 | /* These regs are trashed by the hidden call. No need to mention eax |
| 463 | as gcc can already see that, plus causes gcc to bomb. */ |
| 464 | #define __CALLER_SAVED_REGS /*"eax"*/ "ecx", "edx" |
| 465 | |
| 466 | /* These CALL_FN_ macros assume that on x86-linux, sizeof(unsigned |
| 467 | long) == 4. */ |
| 468 | |
sewardj | 66226cc | 2006-01-20 15:46:46 +0000 | [diff] [blame] | 469 | #define CALL_FN_W_v(lval, orig) \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 470 | do { \ |
sewardj | 66226cc | 2006-01-20 15:46:46 +0000 | [diff] [blame] | 471 | volatile OrigFn _orig = (orig); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 472 | volatile unsigned long _argvec[1]; \ |
| 473 | volatile unsigned long _res; \ |
sewardj | 66226cc | 2006-01-20 15:46:46 +0000 | [diff] [blame] | 474 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 475 | __asm__ volatile( \ |
| 476 | "movl (%%eax), %%eax\n\t" /* target->%eax */ \ |
| 477 | VALGRIND_CALL_NOREDIR_EAX \ |
| 478 | : /*out*/ "=a" (_res) \ |
| 479 | : /*in*/ "a" (&_argvec[0]) \ |
| 480 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 481 | ); \ |
| 482 | lval = (__typeof__(lval)) _res; \ |
| 483 | } while (0) |
| 484 | |
sewardj | 66226cc | 2006-01-20 15:46:46 +0000 | [diff] [blame] | 485 | #define CALL_FN_W_W(lval, orig, arg1) \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 486 | do { \ |
sewardj | 66226cc | 2006-01-20 15:46:46 +0000 | [diff] [blame] | 487 | volatile OrigFn _orig = (orig); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 488 | volatile unsigned long _argvec[2]; \ |
| 489 | volatile unsigned long _res; \ |
sewardj | 66226cc | 2006-01-20 15:46:46 +0000 | [diff] [blame] | 490 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 491 | _argvec[1] = (unsigned long)(arg1); \ |
| 492 | __asm__ volatile( \ |
| 493 | "pushl 4(%%eax)\n\t" \ |
| 494 | "movl (%%eax), %%eax\n\t" /* target->%eax */ \ |
| 495 | VALGRIND_CALL_NOREDIR_EAX \ |
| 496 | "addl $4, %%esp\n" \ |
| 497 | : /*out*/ "=a" (_res) \ |
| 498 | : /*in*/ "a" (&_argvec[0]) \ |
| 499 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 500 | ); \ |
| 501 | lval = (__typeof__(lval)) _res; \ |
| 502 | } while (0) |
| 503 | |
sewardj | 66226cc | 2006-01-20 15:46:46 +0000 | [diff] [blame] | 504 | #define CALL_FN_W_WW(lval, orig, arg1,arg2) \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 505 | do { \ |
sewardj | 66226cc | 2006-01-20 15:46:46 +0000 | [diff] [blame] | 506 | volatile OrigFn _orig = (orig); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 507 | volatile unsigned long _argvec[3]; \ |
| 508 | volatile unsigned long _res; \ |
sewardj | 66226cc | 2006-01-20 15:46:46 +0000 | [diff] [blame] | 509 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 510 | _argvec[1] = (unsigned long)(arg1); \ |
| 511 | _argvec[2] = (unsigned long)(arg2); \ |
| 512 | __asm__ volatile( \ |
| 513 | "pushl 8(%%eax)\n\t" \ |
| 514 | "pushl 4(%%eax)\n\t" \ |
| 515 | "movl (%%eax), %%eax\n\t" /* target->%eax */ \ |
| 516 | VALGRIND_CALL_NOREDIR_EAX \ |
| 517 | "addl $8, %%esp\n" \ |
| 518 | : /*out*/ "=a" (_res) \ |
| 519 | : /*in*/ "a" (&_argvec[0]) \ |
| 520 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 521 | ); \ |
| 522 | lval = (__typeof__(lval)) _res; \ |
| 523 | } while (0) |
| 524 | |
sewardj | 9e8b07a | 2006-02-18 21:13:29 +0000 | [diff] [blame] | 525 | #define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \ |
| 526 | do { \ |
| 527 | volatile OrigFn _orig = (orig); \ |
| 528 | volatile unsigned long _argvec[4]; \ |
| 529 | volatile unsigned long _res; \ |
| 530 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
| 531 | _argvec[1] = (unsigned long)(arg1); \ |
| 532 | _argvec[2] = (unsigned long)(arg2); \ |
| 533 | _argvec[3] = (unsigned long)(arg3); \ |
| 534 | __asm__ volatile( \ |
| 535 | "pushl 12(%%eax)\n\t" \ |
| 536 | "pushl 8(%%eax)\n\t" \ |
| 537 | "pushl 4(%%eax)\n\t" \ |
| 538 | "movl (%%eax), %%eax\n\t" /* target->%eax */ \ |
| 539 | VALGRIND_CALL_NOREDIR_EAX \ |
| 540 | "addl $12, %%esp\n" \ |
| 541 | : /*out*/ "=a" (_res) \ |
| 542 | : /*in*/ "a" (&_argvec[0]) \ |
| 543 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 544 | ); \ |
| 545 | lval = (__typeof__(lval)) _res; \ |
| 546 | } while (0) |
| 547 | |
sewardj | 66226cc | 2006-01-20 15:46:46 +0000 | [diff] [blame] | 548 | #define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 549 | do { \ |
sewardj | 66226cc | 2006-01-20 15:46:46 +0000 | [diff] [blame] | 550 | volatile OrigFn _orig = (orig); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 551 | volatile unsigned long _argvec[5]; \ |
| 552 | volatile unsigned long _res; \ |
sewardj | 66226cc | 2006-01-20 15:46:46 +0000 | [diff] [blame] | 553 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 554 | _argvec[1] = (unsigned long)(arg1); \ |
| 555 | _argvec[2] = (unsigned long)(arg2); \ |
| 556 | _argvec[3] = (unsigned long)(arg3); \ |
| 557 | _argvec[4] = (unsigned long)(arg4); \ |
| 558 | __asm__ volatile( \ |
| 559 | "pushl 16(%%eax)\n\t" \ |
| 560 | "pushl 12(%%eax)\n\t" \ |
| 561 | "pushl 8(%%eax)\n\t" \ |
| 562 | "pushl 4(%%eax)\n\t" \ |
| 563 | "movl (%%eax), %%eax\n\t" /* target->%eax */ \ |
| 564 | VALGRIND_CALL_NOREDIR_EAX \ |
| 565 | "addl $16, %%esp\n" \ |
| 566 | : /*out*/ "=a" (_res) \ |
| 567 | : /*in*/ "a" (&_argvec[0]) \ |
| 568 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 569 | ); \ |
| 570 | lval = (__typeof__(lval)) _res; \ |
| 571 | } while (0) |
| 572 | |
sewardj | 66226cc | 2006-01-20 15:46:46 +0000 | [diff] [blame] | 573 | #define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 574 | do { \ |
sewardj | 66226cc | 2006-01-20 15:46:46 +0000 | [diff] [blame] | 575 | volatile OrigFn _orig = (orig); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 576 | volatile unsigned long _argvec[6]; \ |
| 577 | volatile unsigned long _res; \ |
sewardj | 66226cc | 2006-01-20 15:46:46 +0000 | [diff] [blame] | 578 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 579 | _argvec[1] = (unsigned long)(arg1); \ |
| 580 | _argvec[2] = (unsigned long)(arg2); \ |
| 581 | _argvec[3] = (unsigned long)(arg3); \ |
| 582 | _argvec[4] = (unsigned long)(arg4); \ |
| 583 | _argvec[5] = (unsigned long)(arg5); \ |
| 584 | __asm__ volatile( \ |
| 585 | "pushl 20(%%eax)\n\t" \ |
| 586 | "pushl 16(%%eax)\n\t" \ |
| 587 | "pushl 12(%%eax)\n\t" \ |
| 588 | "pushl 8(%%eax)\n\t" \ |
| 589 | "pushl 4(%%eax)\n\t" \ |
| 590 | "movl (%%eax), %%eax\n\t" /* target->%eax */ \ |
| 591 | VALGRIND_CALL_NOREDIR_EAX \ |
| 592 | "addl $20, %%esp\n" \ |
| 593 | : /*out*/ "=a" (_res) \ |
| 594 | : /*in*/ "a" (&_argvec[0]) \ |
| 595 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 596 | ); \ |
| 597 | lval = (__typeof__(lval)) _res; \ |
| 598 | } while (0) |
| 599 | |
sewardj | 66226cc | 2006-01-20 15:46:46 +0000 | [diff] [blame] | 600 | #define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 601 | do { \ |
sewardj | 66226cc | 2006-01-20 15:46:46 +0000 | [diff] [blame] | 602 | volatile OrigFn _orig = (orig); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 603 | volatile unsigned long _argvec[7]; \ |
| 604 | volatile unsigned long _res; \ |
sewardj | 66226cc | 2006-01-20 15:46:46 +0000 | [diff] [blame] | 605 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 606 | _argvec[1] = (unsigned long)(arg1); \ |
| 607 | _argvec[2] = (unsigned long)(arg2); \ |
| 608 | _argvec[3] = (unsigned long)(arg3); \ |
| 609 | _argvec[4] = (unsigned long)(arg4); \ |
| 610 | _argvec[5] = (unsigned long)(arg5); \ |
| 611 | _argvec[6] = (unsigned long)(arg6); \ |
| 612 | __asm__ volatile( \ |
| 613 | "pushl 24(%%eax)\n\t" \ |
| 614 | "pushl 20(%%eax)\n\t" \ |
| 615 | "pushl 16(%%eax)\n\t" \ |
| 616 | "pushl 12(%%eax)\n\t" \ |
| 617 | "pushl 8(%%eax)\n\t" \ |
| 618 | "pushl 4(%%eax)\n\t" \ |
| 619 | "movl (%%eax), %%eax\n\t" /* target->%eax */ \ |
| 620 | VALGRIND_CALL_NOREDIR_EAX \ |
| 621 | "addl $24, %%esp\n" \ |
| 622 | : /*out*/ "=a" (_res) \ |
| 623 | : /*in*/ "a" (&_argvec[0]) \ |
| 624 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 625 | ); \ |
| 626 | lval = (__typeof__(lval)) _res; \ |
| 627 | } while (0) |
| 628 | |
sewardj | 66226cc | 2006-01-20 15:46:46 +0000 | [diff] [blame] | 629 | #define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ |
| 630 | arg7) \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 631 | do { \ |
sewardj | 66226cc | 2006-01-20 15:46:46 +0000 | [diff] [blame] | 632 | volatile OrigFn _orig = (orig); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 633 | volatile unsigned long _argvec[8]; \ |
| 634 | volatile unsigned long _res; \ |
sewardj | 66226cc | 2006-01-20 15:46:46 +0000 | [diff] [blame] | 635 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 636 | _argvec[1] = (unsigned long)(arg1); \ |
| 637 | _argvec[2] = (unsigned long)(arg2); \ |
| 638 | _argvec[3] = (unsigned long)(arg3); \ |
| 639 | _argvec[4] = (unsigned long)(arg4); \ |
| 640 | _argvec[5] = (unsigned long)(arg5); \ |
| 641 | _argvec[6] = (unsigned long)(arg6); \ |
| 642 | _argvec[7] = (unsigned long)(arg7); \ |
| 643 | __asm__ volatile( \ |
| 644 | "pushl 28(%%eax)\n\t" \ |
| 645 | "pushl 24(%%eax)\n\t" \ |
| 646 | "pushl 20(%%eax)\n\t" \ |
| 647 | "pushl 16(%%eax)\n\t" \ |
| 648 | "pushl 12(%%eax)\n\t" \ |
| 649 | "pushl 8(%%eax)\n\t" \ |
| 650 | "pushl 4(%%eax)\n\t" \ |
| 651 | "movl (%%eax), %%eax\n\t" /* target->%eax */ \ |
| 652 | VALGRIND_CALL_NOREDIR_EAX \ |
| 653 | "addl $28, %%esp\n" \ |
| 654 | : /*out*/ "=a" (_res) \ |
| 655 | : /*in*/ "a" (&_argvec[0]) \ |
| 656 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 657 | ); \ |
| 658 | lval = (__typeof__(lval)) _res; \ |
| 659 | } while (0) |
| 660 | |
sewardj | 66226cc | 2006-01-20 15:46:46 +0000 | [diff] [blame] | 661 | #define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ |
| 662 | arg7,arg8) \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 663 | do { \ |
sewardj | 66226cc | 2006-01-20 15:46:46 +0000 | [diff] [blame] | 664 | volatile OrigFn _orig = (orig); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 665 | volatile unsigned long _argvec[9]; \ |
| 666 | volatile unsigned long _res; \ |
sewardj | 66226cc | 2006-01-20 15:46:46 +0000 | [diff] [blame] | 667 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 668 | _argvec[1] = (unsigned long)(arg1); \ |
| 669 | _argvec[2] = (unsigned long)(arg2); \ |
| 670 | _argvec[3] = (unsigned long)(arg3); \ |
| 671 | _argvec[4] = (unsigned long)(arg4); \ |
| 672 | _argvec[5] = (unsigned long)(arg5); \ |
| 673 | _argvec[6] = (unsigned long)(arg6); \ |
| 674 | _argvec[7] = (unsigned long)(arg7); \ |
| 675 | _argvec[8] = (unsigned long)(arg8); \ |
| 676 | __asm__ volatile( \ |
| 677 | "pushl 32(%%eax)\n\t" \ |
| 678 | "pushl 28(%%eax)\n\t" \ |
| 679 | "pushl 24(%%eax)\n\t" \ |
| 680 | "pushl 20(%%eax)\n\t" \ |
| 681 | "pushl 16(%%eax)\n\t" \ |
| 682 | "pushl 12(%%eax)\n\t" \ |
| 683 | "pushl 8(%%eax)\n\t" \ |
| 684 | "pushl 4(%%eax)\n\t" \ |
| 685 | "movl (%%eax), %%eax\n\t" /* target->%eax */ \ |
| 686 | VALGRIND_CALL_NOREDIR_EAX \ |
| 687 | "addl $32, %%esp\n" \ |
| 688 | : /*out*/ "=a" (_res) \ |
| 689 | : /*in*/ "a" (&_argvec[0]) \ |
| 690 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 691 | ); \ |
| 692 | lval = (__typeof__(lval)) _res; \ |
| 693 | } while (0) |
| 694 | |
sewardj | 45fa5b0 | 2006-03-09 19:06:23 +0000 | [diff] [blame] | 695 | #define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ |
| 696 | arg7,arg8,arg9) \ |
| 697 | do { \ |
| 698 | volatile OrigFn _orig = (orig); \ |
| 699 | volatile unsigned long _argvec[10]; \ |
| 700 | volatile unsigned long _res; \ |
| 701 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
| 702 | _argvec[1] = (unsigned long)(arg1); \ |
| 703 | _argvec[2] = (unsigned long)(arg2); \ |
| 704 | _argvec[3] = (unsigned long)(arg3); \ |
| 705 | _argvec[4] = (unsigned long)(arg4); \ |
| 706 | _argvec[5] = (unsigned long)(arg5); \ |
| 707 | _argvec[6] = (unsigned long)(arg6); \ |
| 708 | _argvec[7] = (unsigned long)(arg7); \ |
| 709 | _argvec[8] = (unsigned long)(arg8); \ |
| 710 | _argvec[9] = (unsigned long)(arg9); \ |
| 711 | __asm__ volatile( \ |
| 712 | "pushl 36(%%eax)\n\t" \ |
| 713 | "pushl 32(%%eax)\n\t" \ |
| 714 | "pushl 28(%%eax)\n\t" \ |
| 715 | "pushl 24(%%eax)\n\t" \ |
| 716 | "pushl 20(%%eax)\n\t" \ |
| 717 | "pushl 16(%%eax)\n\t" \ |
| 718 | "pushl 12(%%eax)\n\t" \ |
| 719 | "pushl 8(%%eax)\n\t" \ |
| 720 | "pushl 4(%%eax)\n\t" \ |
| 721 | "movl (%%eax), %%eax\n\t" /* target->%eax */ \ |
| 722 | VALGRIND_CALL_NOREDIR_EAX \ |
| 723 | "addl $36, %%esp\n" \ |
| 724 | : /*out*/ "=a" (_res) \ |
| 725 | : /*in*/ "a" (&_argvec[0]) \ |
| 726 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 727 | ); \ |
| 728 | lval = (__typeof__(lval)) _res; \ |
| 729 | } while (0) |
| 730 | |
| 731 | #define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ |
| 732 | arg7,arg8,arg9,arg10) \ |
| 733 | do { \ |
| 734 | volatile OrigFn _orig = (orig); \ |
| 735 | volatile unsigned long _argvec[11]; \ |
| 736 | volatile unsigned long _res; \ |
| 737 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
| 738 | _argvec[1] = (unsigned long)(arg1); \ |
| 739 | _argvec[2] = (unsigned long)(arg2); \ |
| 740 | _argvec[3] = (unsigned long)(arg3); \ |
| 741 | _argvec[4] = (unsigned long)(arg4); \ |
| 742 | _argvec[5] = (unsigned long)(arg5); \ |
| 743 | _argvec[6] = (unsigned long)(arg6); \ |
| 744 | _argvec[7] = (unsigned long)(arg7); \ |
| 745 | _argvec[8] = (unsigned long)(arg8); \ |
| 746 | _argvec[9] = (unsigned long)(arg9); \ |
| 747 | _argvec[10] = (unsigned long)(arg10); \ |
| 748 | __asm__ volatile( \ |
| 749 | "pushl 40(%%eax)\n\t" \ |
| 750 | "pushl 36(%%eax)\n\t" \ |
| 751 | "pushl 32(%%eax)\n\t" \ |
| 752 | "pushl 28(%%eax)\n\t" \ |
| 753 | "pushl 24(%%eax)\n\t" \ |
| 754 | "pushl 20(%%eax)\n\t" \ |
| 755 | "pushl 16(%%eax)\n\t" \ |
| 756 | "pushl 12(%%eax)\n\t" \ |
| 757 | "pushl 8(%%eax)\n\t" \ |
| 758 | "pushl 4(%%eax)\n\t" \ |
| 759 | "movl (%%eax), %%eax\n\t" /* target->%eax */ \ |
| 760 | VALGRIND_CALL_NOREDIR_EAX \ |
| 761 | "addl $40, %%esp\n" \ |
| 762 | : /*out*/ "=a" (_res) \ |
| 763 | : /*in*/ "a" (&_argvec[0]) \ |
| 764 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 765 | ); \ |
| 766 | lval = (__typeof__(lval)) _res; \ |
| 767 | } while (0) |
| 768 | |
sewardj | 5ce4b15 | 2006-03-11 12:57:41 +0000 | [diff] [blame] | 769 | #define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5, \ |
| 770 | arg6,arg7,arg8,arg9,arg10, \ |
| 771 | arg11) \ |
| 772 | do { \ |
| 773 | volatile OrigFn _orig = (orig); \ |
| 774 | volatile unsigned long _argvec[12]; \ |
| 775 | volatile unsigned long _res; \ |
| 776 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
| 777 | _argvec[1] = (unsigned long)(arg1); \ |
| 778 | _argvec[2] = (unsigned long)(arg2); \ |
| 779 | _argvec[3] = (unsigned long)(arg3); \ |
| 780 | _argvec[4] = (unsigned long)(arg4); \ |
| 781 | _argvec[5] = (unsigned long)(arg5); \ |
| 782 | _argvec[6] = (unsigned long)(arg6); \ |
| 783 | _argvec[7] = (unsigned long)(arg7); \ |
| 784 | _argvec[8] = (unsigned long)(arg8); \ |
| 785 | _argvec[9] = (unsigned long)(arg9); \ |
| 786 | _argvec[10] = (unsigned long)(arg10); \ |
| 787 | _argvec[11] = (unsigned long)(arg11); \ |
| 788 | __asm__ volatile( \ |
| 789 | "pushl 44(%%eax)\n\t" \ |
| 790 | "pushl 40(%%eax)\n\t" \ |
| 791 | "pushl 36(%%eax)\n\t" \ |
| 792 | "pushl 32(%%eax)\n\t" \ |
| 793 | "pushl 28(%%eax)\n\t" \ |
| 794 | "pushl 24(%%eax)\n\t" \ |
| 795 | "pushl 20(%%eax)\n\t" \ |
| 796 | "pushl 16(%%eax)\n\t" \ |
| 797 | "pushl 12(%%eax)\n\t" \ |
| 798 | "pushl 8(%%eax)\n\t" \ |
| 799 | "pushl 4(%%eax)\n\t" \ |
| 800 | "movl (%%eax), %%eax\n\t" /* target->%eax */ \ |
| 801 | VALGRIND_CALL_NOREDIR_EAX \ |
| 802 | "addl $44, %%esp\n" \ |
| 803 | : /*out*/ "=a" (_res) \ |
| 804 | : /*in*/ "a" (&_argvec[0]) \ |
| 805 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 806 | ); \ |
| 807 | lval = (__typeof__(lval)) _res; \ |
| 808 | } while (0) |
| 809 | |
sewardj | 66226cc | 2006-01-20 15:46:46 +0000 | [diff] [blame] | 810 | #define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5, \ |
| 811 | arg6,arg7,arg8,arg9,arg10, \ |
| 812 | arg11,arg12) \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 813 | do { \ |
sewardj | 66226cc | 2006-01-20 15:46:46 +0000 | [diff] [blame] | 814 | volatile OrigFn _orig = (orig); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 815 | volatile unsigned long _argvec[13]; \ |
| 816 | volatile unsigned long _res; \ |
sewardj | 66226cc | 2006-01-20 15:46:46 +0000 | [diff] [blame] | 817 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 818 | _argvec[1] = (unsigned long)(arg1); \ |
| 819 | _argvec[2] = (unsigned long)(arg2); \ |
| 820 | _argvec[3] = (unsigned long)(arg3); \ |
| 821 | _argvec[4] = (unsigned long)(arg4); \ |
| 822 | _argvec[5] = (unsigned long)(arg5); \ |
| 823 | _argvec[6] = (unsigned long)(arg6); \ |
| 824 | _argvec[7] = (unsigned long)(arg7); \ |
| 825 | _argvec[8] = (unsigned long)(arg8); \ |
| 826 | _argvec[9] = (unsigned long)(arg9); \ |
| 827 | _argvec[10] = (unsigned long)(arg10); \ |
| 828 | _argvec[11] = (unsigned long)(arg11); \ |
| 829 | _argvec[12] = (unsigned long)(arg12); \ |
| 830 | __asm__ volatile( \ |
| 831 | "pushl 48(%%eax)\n\t" \ |
| 832 | "pushl 44(%%eax)\n\t" \ |
| 833 | "pushl 40(%%eax)\n\t" \ |
| 834 | "pushl 36(%%eax)\n\t" \ |
| 835 | "pushl 32(%%eax)\n\t" \ |
| 836 | "pushl 28(%%eax)\n\t" \ |
| 837 | "pushl 24(%%eax)\n\t" \ |
| 838 | "pushl 20(%%eax)\n\t" \ |
| 839 | "pushl 16(%%eax)\n\t" \ |
| 840 | "pushl 12(%%eax)\n\t" \ |
| 841 | "pushl 8(%%eax)\n\t" \ |
| 842 | "pushl 4(%%eax)\n\t" \ |
| 843 | "movl (%%eax), %%eax\n\t" /* target->%eax */ \ |
| 844 | VALGRIND_CALL_NOREDIR_EAX \ |
| 845 | "addl $48, %%esp\n" \ |
| 846 | : /*out*/ "=a" (_res) \ |
| 847 | : /*in*/ "a" (&_argvec[0]) \ |
| 848 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 849 | ); \ |
| 850 | lval = (__typeof__(lval)) _res; \ |
| 851 | } while (0) |
| 852 | |
| 853 | #endif /* ARCH_x86 */ |
| 854 | |
| 855 | /* --------------------------- amd64 --------------------------- */ |
| 856 | |
| 857 | #if defined(ARCH_amd64) |
| 858 | |
| 859 | /* ARGREGS: rdi rsi rdx rcx r8 r9 (the rest on stack in R-to-L order) */ |
| 860 | |
| 861 | /* These regs are trashed by the hidden call. */ |
| 862 | #define __CALLER_SAVED_REGS /*"rax",*/ "rcx", "rdx", "rsi", \ |
| 863 | "rdi", "r8", "r9", "r10", "r11" |
| 864 | |
| 865 | /* These CALL_FN_ macros assume that on amd64-linux, sizeof(unsigned |
| 866 | long) == 8. */ |
| 867 | |
sewardj | c885844 | 2006-01-20 15:17:20 +0000 | [diff] [blame] | 868 | #define CALL_FN_W_v(lval, orig) \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 869 | do { \ |
sewardj | c885844 | 2006-01-20 15:17:20 +0000 | [diff] [blame] | 870 | volatile OrigFn _orig = (orig); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 871 | volatile unsigned long _argvec[1]; \ |
| 872 | volatile unsigned long _res; \ |
sewardj | c885844 | 2006-01-20 15:17:20 +0000 | [diff] [blame] | 873 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 874 | __asm__ volatile( \ |
| 875 | "movq (%%rax), %%rax\n\t" /* target->%rax */ \ |
| 876 | VALGRIND_CALL_NOREDIR_RAX \ |
| 877 | : /*out*/ "=a" (_res) \ |
| 878 | : /*in*/ "a" (&_argvec[0]) \ |
| 879 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 880 | ); \ |
| 881 | lval = (__typeof__(lval)) _res; \ |
| 882 | } while (0) |
| 883 | |
sewardj | c885844 | 2006-01-20 15:17:20 +0000 | [diff] [blame] | 884 | #define CALL_FN_W_W(lval, orig, arg1) \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 885 | do { \ |
sewardj | c885844 | 2006-01-20 15:17:20 +0000 | [diff] [blame] | 886 | volatile OrigFn _orig = (orig); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 887 | volatile unsigned long _argvec[2]; \ |
| 888 | volatile unsigned long _res; \ |
sewardj | c885844 | 2006-01-20 15:17:20 +0000 | [diff] [blame] | 889 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 890 | _argvec[1] = (unsigned long)(arg1); \ |
| 891 | __asm__ volatile( \ |
| 892 | "movq 8(%%rax), %%rdi\n\t" \ |
| 893 | "movq (%%rax), %%rax\n\t" /* target->%rax */ \ |
| 894 | VALGRIND_CALL_NOREDIR_RAX \ |
| 895 | : /*out*/ "=a" (_res) \ |
| 896 | : /*in*/ "a" (&_argvec[0]) \ |
| 897 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 898 | ); \ |
| 899 | lval = (__typeof__(lval)) _res; \ |
| 900 | } while (0) |
| 901 | |
sewardj | c885844 | 2006-01-20 15:17:20 +0000 | [diff] [blame] | 902 | #define CALL_FN_W_WW(lval, orig, arg1,arg2) \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 903 | do { \ |
sewardj | c885844 | 2006-01-20 15:17:20 +0000 | [diff] [blame] | 904 | volatile OrigFn _orig = (orig); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 905 | volatile unsigned long _argvec[3]; \ |
| 906 | volatile unsigned long _res; \ |
sewardj | c885844 | 2006-01-20 15:17:20 +0000 | [diff] [blame] | 907 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 908 | _argvec[1] = (unsigned long)(arg1); \ |
| 909 | _argvec[2] = (unsigned long)(arg2); \ |
| 910 | __asm__ volatile( \ |
| 911 | "movq 16(%%rax), %%rsi\n\t" \ |
| 912 | "movq 8(%%rax), %%rdi\n\t" \ |
| 913 | "movq (%%rax), %%rax\n\t" /* target->%rax */ \ |
| 914 | VALGRIND_CALL_NOREDIR_RAX \ |
| 915 | : /*out*/ "=a" (_res) \ |
| 916 | : /*in*/ "a" (&_argvec[0]) \ |
| 917 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 918 | ); \ |
| 919 | lval = (__typeof__(lval)) _res; \ |
| 920 | } while (0) |
| 921 | |
sewardj | a50f9dc | 2006-03-11 16:19:14 +0000 | [diff] [blame^] | 922 | #define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \ |
| 923 | do { \ |
| 924 | volatile OrigFn _orig = (orig); \ |
| 925 | volatile unsigned long _argvec[4]; \ |
| 926 | volatile unsigned long _res; \ |
| 927 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
| 928 | _argvec[1] = (unsigned long)(arg1); \ |
| 929 | _argvec[2] = (unsigned long)(arg2); \ |
| 930 | _argvec[3] = (unsigned long)(arg3); \ |
| 931 | __asm__ volatile( \ |
| 932 | "movq 24(%%rax), %%rdx\n\t" \ |
| 933 | "movq 16(%%rax), %%rsi\n\t" \ |
| 934 | "movq 8(%%rax), %%rdi\n\t" \ |
| 935 | "movq (%%rax), %%rax\n\t" /* target->%rax */ \ |
| 936 | VALGRIND_CALL_NOREDIR_RAX \ |
| 937 | : /*out*/ "=a" (_res) \ |
| 938 | : /*in*/ "a" (&_argvec[0]) \ |
| 939 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 940 | ); \ |
| 941 | lval = (__typeof__(lval)) _res; \ |
| 942 | } while (0) |
| 943 | |
| 944 | #define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \ |
| 945 | do { \ |
| 946 | volatile OrigFn _orig = (orig); \ |
| 947 | volatile unsigned long _argvec[5]; \ |
| 948 | volatile unsigned long _res; \ |
| 949 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
| 950 | _argvec[1] = (unsigned long)(arg1); \ |
| 951 | _argvec[2] = (unsigned long)(arg2); \ |
| 952 | _argvec[3] = (unsigned long)(arg3); \ |
| 953 | _argvec[4] = (unsigned long)(arg4); \ |
| 954 | __asm__ volatile( \ |
| 955 | "movq 32(%%rax), %%rcx\n\t" \ |
| 956 | "movq 24(%%rax), %%rdx\n\t" \ |
| 957 | "movq 16(%%rax), %%rsi\n\t" \ |
| 958 | "movq 8(%%rax), %%rdi\n\t" \ |
| 959 | "movq (%%rax), %%rax\n\t" /* target->%rax */ \ |
| 960 | VALGRIND_CALL_NOREDIR_RAX \ |
| 961 | : /*out*/ "=a" (_res) \ |
| 962 | : /*in*/ "a" (&_argvec[0]) \ |
| 963 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 964 | ); \ |
| 965 | lval = (__typeof__(lval)) _res; \ |
| 966 | } while (0) |
| 967 | |
| 968 | #define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \ |
| 969 | do { \ |
| 970 | volatile OrigFn _orig = (orig); \ |
| 971 | volatile unsigned long _argvec[6]; \ |
| 972 | volatile unsigned long _res; \ |
| 973 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
| 974 | _argvec[1] = (unsigned long)(arg1); \ |
| 975 | _argvec[2] = (unsigned long)(arg2); \ |
| 976 | _argvec[3] = (unsigned long)(arg3); \ |
| 977 | _argvec[4] = (unsigned long)(arg4); \ |
| 978 | _argvec[5] = (unsigned long)(arg5); \ |
| 979 | __asm__ volatile( \ |
| 980 | "movq 40(%%rax), %%r8\n\t" \ |
| 981 | "movq 32(%%rax), %%rcx\n\t" \ |
| 982 | "movq 24(%%rax), %%rdx\n\t" \ |
| 983 | "movq 16(%%rax), %%rsi\n\t" \ |
| 984 | "movq 8(%%rax), %%rdi\n\t" \ |
| 985 | "movq (%%rax), %%rax\n\t" /* target->%rax */ \ |
| 986 | VALGRIND_CALL_NOREDIR_RAX \ |
| 987 | : /*out*/ "=a" (_res) \ |
| 988 | : /*in*/ "a" (&_argvec[0]) \ |
| 989 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 990 | ); \ |
| 991 | lval = (__typeof__(lval)) _res; \ |
| 992 | } while (0) |
| 993 | |
| 994 | #define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \ |
| 995 | do { \ |
| 996 | volatile OrigFn _orig = (orig); \ |
| 997 | volatile unsigned long _argvec[7]; \ |
| 998 | volatile unsigned long _res; \ |
| 999 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
| 1000 | _argvec[1] = (unsigned long)(arg1); \ |
| 1001 | _argvec[2] = (unsigned long)(arg2); \ |
| 1002 | _argvec[3] = (unsigned long)(arg3); \ |
| 1003 | _argvec[4] = (unsigned long)(arg4); \ |
| 1004 | _argvec[5] = (unsigned long)(arg5); \ |
| 1005 | _argvec[6] = (unsigned long)(arg6); \ |
| 1006 | __asm__ volatile( \ |
| 1007 | "movq 48(%%rax), %%r9\n\t" \ |
| 1008 | "movq 40(%%rax), %%r8\n\t" \ |
| 1009 | "movq 32(%%rax), %%rcx\n\t" \ |
| 1010 | "movq 24(%%rax), %%rdx\n\t" \ |
| 1011 | "movq 16(%%rax), %%rsi\n\t" \ |
| 1012 | "movq 8(%%rax), %%rdi\n\t" \ |
| 1013 | "movq (%%rax), %%rax\n\t" /* target->%rax */ \ |
| 1014 | VALGRIND_CALL_NOREDIR_RAX \ |
| 1015 | : /*out*/ "=a" (_res) \ |
| 1016 | : /*in*/ "a" (&_argvec[0]) \ |
| 1017 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 1018 | ); \ |
| 1019 | lval = (__typeof__(lval)) _res; \ |
| 1020 | } while (0) |
| 1021 | |
| 1022 | #define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ |
| 1023 | arg7) \ |
| 1024 | do { \ |
| 1025 | volatile OrigFn _orig = (orig); \ |
| 1026 | volatile unsigned long _argvec[8]; \ |
| 1027 | volatile unsigned long _res; \ |
| 1028 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
| 1029 | _argvec[1] = (unsigned long)(arg1); \ |
| 1030 | _argvec[2] = (unsigned long)(arg2); \ |
| 1031 | _argvec[3] = (unsigned long)(arg3); \ |
| 1032 | _argvec[4] = (unsigned long)(arg4); \ |
| 1033 | _argvec[5] = (unsigned long)(arg5); \ |
| 1034 | _argvec[6] = (unsigned long)(arg6); \ |
| 1035 | _argvec[7] = (unsigned long)(arg7); \ |
| 1036 | __asm__ volatile( \ |
| 1037 | "pushq 56(%%rax)\n\t" \ |
| 1038 | "movq 48(%%rax), %%r9\n\t" \ |
| 1039 | "movq 40(%%rax), %%r8\n\t" \ |
| 1040 | "movq 32(%%rax), %%rcx\n\t" \ |
| 1041 | "movq 24(%%rax), %%rdx\n\t" \ |
| 1042 | "movq 16(%%rax), %%rsi\n\t" \ |
| 1043 | "movq 8(%%rax), %%rdi\n\t" \ |
| 1044 | "movq (%%rax), %%rax\n\t" /* target->%rax */ \ |
| 1045 | VALGRIND_CALL_NOREDIR_RAX \ |
| 1046 | "addq $8, %%rsp\n" \ |
| 1047 | : /*out*/ "=a" (_res) \ |
| 1048 | : /*in*/ "a" (&_argvec[0]) \ |
| 1049 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 1050 | ); \ |
| 1051 | lval = (__typeof__(lval)) _res; \ |
| 1052 | } while (0) |
| 1053 | |
| 1054 | #define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ |
| 1055 | arg7,arg8) \ |
| 1056 | do { \ |
| 1057 | volatile OrigFn _orig = (orig); \ |
| 1058 | volatile unsigned long _argvec[9]; \ |
| 1059 | volatile unsigned long _res; \ |
| 1060 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
| 1061 | _argvec[1] = (unsigned long)(arg1); \ |
| 1062 | _argvec[2] = (unsigned long)(arg2); \ |
| 1063 | _argvec[3] = (unsigned long)(arg3); \ |
| 1064 | _argvec[4] = (unsigned long)(arg4); \ |
| 1065 | _argvec[5] = (unsigned long)(arg5); \ |
| 1066 | _argvec[6] = (unsigned long)(arg6); \ |
| 1067 | _argvec[7] = (unsigned long)(arg7); \ |
| 1068 | _argvec[8] = (unsigned long)(arg8); \ |
| 1069 | __asm__ volatile( \ |
| 1070 | "pushq 64(%%rax)\n\t" \ |
| 1071 | "pushq 56(%%rax)\n\t" \ |
| 1072 | "movq 48(%%rax), %%r9\n\t" \ |
| 1073 | "movq 40(%%rax), %%r8\n\t" \ |
| 1074 | "movq 32(%%rax), %%rcx\n\t" \ |
| 1075 | "movq 24(%%rax), %%rdx\n\t" \ |
| 1076 | "movq 16(%%rax), %%rsi\n\t" \ |
| 1077 | "movq 8(%%rax), %%rdi\n\t" \ |
| 1078 | "movq (%%rax), %%rax\n\t" /* target->%rax */ \ |
| 1079 | VALGRIND_CALL_NOREDIR_RAX \ |
| 1080 | "addq $16, %%rsp\n" \ |
| 1081 | : /*out*/ "=a" (_res) \ |
| 1082 | : /*in*/ "a" (&_argvec[0]) \ |
| 1083 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 1084 | ); \ |
| 1085 | lval = (__typeof__(lval)) _res; \ |
| 1086 | } while (0) |
| 1087 | |
| 1088 | #define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ |
| 1089 | arg7,arg8,arg9) \ |
| 1090 | do { \ |
| 1091 | volatile OrigFn _orig = (orig); \ |
| 1092 | volatile unsigned long _argvec[10]; \ |
| 1093 | volatile unsigned long _res; \ |
| 1094 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
| 1095 | _argvec[1] = (unsigned long)(arg1); \ |
| 1096 | _argvec[2] = (unsigned long)(arg2); \ |
| 1097 | _argvec[3] = (unsigned long)(arg3); \ |
| 1098 | _argvec[4] = (unsigned long)(arg4); \ |
| 1099 | _argvec[5] = (unsigned long)(arg5); \ |
| 1100 | _argvec[6] = (unsigned long)(arg6); \ |
| 1101 | _argvec[7] = (unsigned long)(arg7); \ |
| 1102 | _argvec[8] = (unsigned long)(arg8); \ |
| 1103 | _argvec[9] = (unsigned long)(arg9); \ |
| 1104 | __asm__ volatile( \ |
| 1105 | "pushq 72(%%rax)\n\t" \ |
| 1106 | "pushq 64(%%rax)\n\t" \ |
| 1107 | "pushq 56(%%rax)\n\t" \ |
| 1108 | "movq 48(%%rax), %%r9\n\t" \ |
| 1109 | "movq 40(%%rax), %%r8\n\t" \ |
| 1110 | "movq 32(%%rax), %%rcx\n\t" \ |
| 1111 | "movq 24(%%rax), %%rdx\n\t" \ |
| 1112 | "movq 16(%%rax), %%rsi\n\t" \ |
| 1113 | "movq 8(%%rax), %%rdi\n\t" \ |
| 1114 | "movq (%%rax), %%rax\n\t" /* target->%rax */ \ |
| 1115 | VALGRIND_CALL_NOREDIR_RAX \ |
| 1116 | "addq $24, %%rsp\n" \ |
| 1117 | : /*out*/ "=a" (_res) \ |
| 1118 | : /*in*/ "a" (&_argvec[0]) \ |
| 1119 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 1120 | ); \ |
| 1121 | lval = (__typeof__(lval)) _res; \ |
| 1122 | } while (0) |
| 1123 | |
| 1124 | #define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ |
| 1125 | arg7,arg8,arg9,arg10) \ |
| 1126 | do { \ |
| 1127 | volatile OrigFn _orig = (orig); \ |
| 1128 | volatile unsigned long _argvec[11]; \ |
| 1129 | volatile unsigned long _res; \ |
| 1130 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
| 1131 | _argvec[1] = (unsigned long)(arg1); \ |
| 1132 | _argvec[2] = (unsigned long)(arg2); \ |
| 1133 | _argvec[3] = (unsigned long)(arg3); \ |
| 1134 | _argvec[4] = (unsigned long)(arg4); \ |
| 1135 | _argvec[5] = (unsigned long)(arg5); \ |
| 1136 | _argvec[6] = (unsigned long)(arg6); \ |
| 1137 | _argvec[7] = (unsigned long)(arg7); \ |
| 1138 | _argvec[8] = (unsigned long)(arg8); \ |
| 1139 | _argvec[9] = (unsigned long)(arg9); \ |
| 1140 | _argvec[10] = (unsigned long)(arg10); \ |
| 1141 | __asm__ volatile( \ |
| 1142 | "pushq 80(%%rax)\n\t" \ |
| 1143 | "pushq 72(%%rax)\n\t" \ |
| 1144 | "pushq 64(%%rax)\n\t" \ |
| 1145 | "pushq 56(%%rax)\n\t" \ |
| 1146 | "movq 48(%%rax), %%r9\n\t" \ |
| 1147 | "movq 40(%%rax), %%r8\n\t" \ |
| 1148 | "movq 32(%%rax), %%rcx\n\t" \ |
| 1149 | "movq 24(%%rax), %%rdx\n\t" \ |
| 1150 | "movq 16(%%rax), %%rsi\n\t" \ |
| 1151 | "movq 8(%%rax), %%rdi\n\t" \ |
| 1152 | "movq (%%rax), %%rax\n\t" /* target->%rax */ \ |
| 1153 | VALGRIND_CALL_NOREDIR_RAX \ |
| 1154 | "addq $32, %%rsp\n" \ |
| 1155 | : /*out*/ "=a" (_res) \ |
| 1156 | : /*in*/ "a" (&_argvec[0]) \ |
| 1157 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 1158 | ); \ |
| 1159 | lval = (__typeof__(lval)) _res; \ |
| 1160 | } while (0) |
| 1161 | |
| 1162 | #define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ |
| 1163 | arg7,arg8,arg9,arg10,arg11) \ |
| 1164 | do { \ |
| 1165 | volatile OrigFn _orig = (orig); \ |
| 1166 | volatile unsigned long _argvec[12]; \ |
| 1167 | volatile unsigned long _res; \ |
| 1168 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
| 1169 | _argvec[1] = (unsigned long)(arg1); \ |
| 1170 | _argvec[2] = (unsigned long)(arg2); \ |
| 1171 | _argvec[3] = (unsigned long)(arg3); \ |
| 1172 | _argvec[4] = (unsigned long)(arg4); \ |
| 1173 | _argvec[5] = (unsigned long)(arg5); \ |
| 1174 | _argvec[6] = (unsigned long)(arg6); \ |
| 1175 | _argvec[7] = (unsigned long)(arg7); \ |
| 1176 | _argvec[8] = (unsigned long)(arg8); \ |
| 1177 | _argvec[9] = (unsigned long)(arg9); \ |
| 1178 | _argvec[10] = (unsigned long)(arg10); \ |
| 1179 | _argvec[11] = (unsigned long)(arg11); \ |
| 1180 | __asm__ volatile( \ |
| 1181 | "pushq 88(%%rax)\n\t" \ |
| 1182 | "pushq 80(%%rax)\n\t" \ |
| 1183 | "pushq 72(%%rax)\n\t" \ |
| 1184 | "pushq 64(%%rax)\n\t" \ |
| 1185 | "pushq 56(%%rax)\n\t" \ |
| 1186 | "movq 48(%%rax), %%r9\n\t" \ |
| 1187 | "movq 40(%%rax), %%r8\n\t" \ |
| 1188 | "movq 32(%%rax), %%rcx\n\t" \ |
| 1189 | "movq 24(%%rax), %%rdx\n\t" \ |
| 1190 | "movq 16(%%rax), %%rsi\n\t" \ |
| 1191 | "movq 8(%%rax), %%rdi\n\t" \ |
| 1192 | "movq (%%rax), %%rax\n\t" /* target->%rax */ \ |
| 1193 | VALGRIND_CALL_NOREDIR_RAX \ |
| 1194 | "addq $40, %%rsp\n" \ |
| 1195 | : /*out*/ "=a" (_res) \ |
| 1196 | : /*in*/ "a" (&_argvec[0]) \ |
| 1197 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 1198 | ); \ |
| 1199 | lval = (__typeof__(lval)) _res; \ |
| 1200 | } while (0) |
| 1201 | |
| 1202 | #define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ |
| 1203 | arg7,arg8,arg9,arg10,arg11,arg12) \ |
| 1204 | do { \ |
| 1205 | volatile OrigFn _orig = (orig); \ |
| 1206 | volatile unsigned long _argvec[13]; \ |
| 1207 | volatile unsigned long _res; \ |
| 1208 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
| 1209 | _argvec[1] = (unsigned long)(arg1); \ |
| 1210 | _argvec[2] = (unsigned long)(arg2); \ |
| 1211 | _argvec[3] = (unsigned long)(arg3); \ |
| 1212 | _argvec[4] = (unsigned long)(arg4); \ |
| 1213 | _argvec[5] = (unsigned long)(arg5); \ |
| 1214 | _argvec[6] = (unsigned long)(arg6); \ |
| 1215 | _argvec[7] = (unsigned long)(arg7); \ |
| 1216 | _argvec[8] = (unsigned long)(arg8); \ |
| 1217 | _argvec[9] = (unsigned long)(arg9); \ |
| 1218 | _argvec[10] = (unsigned long)(arg10); \ |
| 1219 | _argvec[11] = (unsigned long)(arg11); \ |
| 1220 | _argvec[12] = (unsigned long)(arg12); \ |
| 1221 | __asm__ volatile( \ |
| 1222 | "pushq 96(%%rax)\n\t" \ |
| 1223 | "pushq 88(%%rax)\n\t" \ |
| 1224 | "pushq 80(%%rax)\n\t" \ |
| 1225 | "pushq 72(%%rax)\n\t" \ |
| 1226 | "pushq 64(%%rax)\n\t" \ |
| 1227 | "pushq 56(%%rax)\n\t" \ |
| 1228 | "movq 48(%%rax), %%r9\n\t" \ |
| 1229 | "movq 40(%%rax), %%r8\n\t" \ |
| 1230 | "movq 32(%%rax), %%rcx\n\t" \ |
| 1231 | "movq 24(%%rax), %%rdx\n\t" \ |
| 1232 | "movq 16(%%rax), %%rsi\n\t" \ |
| 1233 | "movq 8(%%rax), %%rdi\n\t" \ |
| 1234 | "movq (%%rax), %%rax\n\t" /* target->%rax */ \ |
| 1235 | VALGRIND_CALL_NOREDIR_RAX \ |
| 1236 | "addq $48, %%rsp\n" \ |
| 1237 | : /*out*/ "=a" (_res) \ |
| 1238 | : /*in*/ "a" (&_argvec[0]) \ |
| 1239 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 1240 | ); \ |
| 1241 | lval = (__typeof__(lval)) _res; \ |
| 1242 | } while (0) |
| 1243 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1244 | #endif /* ARCH_amd64 */ |
| 1245 | |
| 1246 | /* --------------------------- ppc32 --------------------------- */ |
| 1247 | |
| 1248 | #if defined(ARCH_ppc32) |
| 1249 | |
| 1250 | /* ARGREGS: r3 r4 r5 r6 r7 r8 r9 r10 (the rest on stack somewhere) */ |
| 1251 | |
| 1252 | /* These regs are trashed by the hidden call. */ |
| 1253 | #define __CALLER_SAVED_REGS "lr", \ |
| 1254 | "r0", "r2", "r3", "r4", "r5", "r6", \ |
| 1255 | "r7", "r8", "r9", "r10", "r11", "r12" |
| 1256 | |
| 1257 | /* These CALL_FN_ macros assume that on ppc32-linux, sizeof(unsigned |
| 1258 | long) == 4. */ |
| 1259 | |
sewardj | 38de099 | 2006-01-20 16:46:34 +0000 | [diff] [blame] | 1260 | #define CALL_FN_W_v(lval, orig) \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1261 | do { \ |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 1262 | volatile OrigFn _orig = (orig); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1263 | volatile unsigned long _argvec[1]; \ |
| 1264 | volatile unsigned long _res; \ |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 1265 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1266 | __asm__ volatile( \ |
| 1267 | "mr 11,%1\n\t" \ |
| 1268 | "lwz 11,0(11)\n\t" /* target->r11 */ \ |
| 1269 | VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ |
| 1270 | "mr %0,3" \ |
| 1271 | : /*out*/ "=r" (_res) \ |
| 1272 | : /*in*/ "r" (&_argvec[0]) \ |
| 1273 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 1274 | ); \ |
| 1275 | lval = (__typeof__(lval)) _res; \ |
| 1276 | } while (0) |
| 1277 | |
sewardj | 38de099 | 2006-01-20 16:46:34 +0000 | [diff] [blame] | 1278 | #define CALL_FN_W_W(lval, orig, arg1) \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1279 | do { \ |
sewardj | 38de099 | 2006-01-20 16:46:34 +0000 | [diff] [blame] | 1280 | volatile OrigFn _orig = (orig); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1281 | volatile unsigned long _argvec[2]; \ |
| 1282 | volatile unsigned long _res; \ |
sewardj | 38de099 | 2006-01-20 16:46:34 +0000 | [diff] [blame] | 1283 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1284 | _argvec[1] = (unsigned long)arg1; \ |
| 1285 | __asm__ volatile( \ |
| 1286 | "mr 11,%1\n\t" \ |
| 1287 | "lwz 3,4(11)\n\t" /* arg1->r3 */ \ |
| 1288 | "lwz 11,0(11)\n\t" /* target->r11 */ \ |
| 1289 | VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ |
| 1290 | "mr %0,3" \ |
| 1291 | : /*out*/ "=r" (_res) \ |
| 1292 | : /*in*/ "r" (&_argvec[0]) \ |
| 1293 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 1294 | ); \ |
| 1295 | lval = (__typeof__(lval)) _res; \ |
| 1296 | } while (0) |
| 1297 | |
sewardj | 38de099 | 2006-01-20 16:46:34 +0000 | [diff] [blame] | 1298 | #define CALL_FN_W_WW(lval, orig, arg1,arg2) \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1299 | do { \ |
sewardj | 38de099 | 2006-01-20 16:46:34 +0000 | [diff] [blame] | 1300 | volatile OrigFn _orig = (orig); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1301 | volatile unsigned long _argvec[3]; \ |
| 1302 | volatile unsigned long _res; \ |
sewardj | 38de099 | 2006-01-20 16:46:34 +0000 | [diff] [blame] | 1303 | _argvec[0] = (unsigned long)_orig.nraddr; \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1304 | _argvec[1] = (unsigned long)arg1; \ |
| 1305 | _argvec[2] = (unsigned long)arg2; \ |
| 1306 | __asm__ volatile( \ |
| 1307 | "mr 11,%1\n\t" \ |
| 1308 | "lwz 3,4(11)\n\t" /* arg1->r3 */ \ |
| 1309 | "lwz 4,8(11)\n\t" \ |
| 1310 | "lwz 11,0(11)\n\t" /* target->r11 */ \ |
| 1311 | VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ |
| 1312 | "mr %0,3" \ |
| 1313 | : /*out*/ "=r" (_res) \ |
| 1314 | : /*in*/ "r" (&_argvec[0]) \ |
| 1315 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 1316 | ); \ |
| 1317 | lval = (__typeof__(lval)) _res; \ |
| 1318 | } while (0) |
| 1319 | |
| 1320 | #endif /* ARCH_ppc32 */ |
| 1321 | |
| 1322 | /* --------------------------- ppc64 --------------------------- */ |
| 1323 | |
sewardj | 9734b20 | 2006-01-17 01:49:37 +0000 | [diff] [blame] | 1324 | #if defined(ARCH_ppc64) |
| 1325 | |
| 1326 | /* ARGREGS: r3 r4 r5 r6 r7 r8 r9 r10 (the rest on stack somewhere) */ |
| 1327 | |
| 1328 | /* These regs are trashed by the hidden call. */ |
| 1329 | #define __CALLER_SAVED_REGS "lr", \ |
| 1330 | "r0", "r2", "r3", "r4", "r5", "r6", \ |
| 1331 | "r7", "r8", "r9", "r10", "r11", "r12" |
| 1332 | |
| 1333 | /* These CALL_FN_ macros assume that on ppc64-linux, sizeof(unsigned |
| 1334 | long) == 8. */ |
| 1335 | |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 1336 | #define CALL_FN_W_v(lval, orig) \ |
sewardj | 9734b20 | 2006-01-17 01:49:37 +0000 | [diff] [blame] | 1337 | do { \ |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 1338 | volatile OrigFn _orig = (orig); \ |
| 1339 | volatile unsigned long _argvec[3+0]; \ |
sewardj | 9734b20 | 2006-01-17 01:49:37 +0000 | [diff] [blame] | 1340 | volatile unsigned long _res; \ |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 1341 | /* _argvec[0] holds current r2 across the call */ \ |
| 1342 | _argvec[1] = (unsigned long)_orig.r2; \ |
| 1343 | _argvec[2] = (unsigned long)_orig.nraddr; \ |
sewardj | 9734b20 | 2006-01-17 01:49:37 +0000 | [diff] [blame] | 1344 | __asm__ volatile( \ |
| 1345 | "mr 11,%1\n\t" \ |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 1346 | "std 2,-16(11)\n\t" /* save tocptr */ \ |
| 1347 | "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ |
| 1348 | "ld 11, 0(11)\n\t" /* target->r11 */ \ |
sewardj | 9734b20 | 2006-01-17 01:49:37 +0000 | [diff] [blame] | 1349 | VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ |
| 1350 | "mr 11,%1\n\t" \ |
| 1351 | "mr %0,3\n\t" \ |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 1352 | "ld 2,-16(11)" /* restore tocptr */ \ |
sewardj | 9734b20 | 2006-01-17 01:49:37 +0000 | [diff] [blame] | 1353 | : /*out*/ "=r" (_res) \ |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 1354 | : /*in*/ "r" (&_argvec[2]) \ |
sewardj | 9734b20 | 2006-01-17 01:49:37 +0000 | [diff] [blame] | 1355 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 1356 | ); \ |
| 1357 | lval = (__typeof__(lval)) _res; \ |
| 1358 | } while (0) |
| 1359 | |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 1360 | #define CALL_FN_W_W(lval, orig, arg1) \ |
sewardj | 9734b20 | 2006-01-17 01:49:37 +0000 | [diff] [blame] | 1361 | do { \ |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 1362 | volatile OrigFn _orig = (orig); \ |
| 1363 | volatile unsigned long _argvec[3+1]; \ |
sewardj | 9734b20 | 2006-01-17 01:49:37 +0000 | [diff] [blame] | 1364 | volatile unsigned long _res; \ |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 1365 | /* _argvec[0] holds current r2 across the call */ \ |
| 1366 | _argvec[1] = (unsigned long)_orig.r2; \ |
| 1367 | _argvec[2] = (unsigned long)_orig.nraddr; \ |
| 1368 | _argvec[2+1] = (unsigned long)arg1; \ |
sewardj | 9734b20 | 2006-01-17 01:49:37 +0000 | [diff] [blame] | 1369 | __asm__ volatile( \ |
| 1370 | "mr 11,%1\n\t" \ |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 1371 | "std 2,-16(11)\n\t" /* save tocptr */ \ |
| 1372 | "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ |
| 1373 | "ld 3, 8(11)\n\t" /* arg1->r3 */ \ |
| 1374 | "ld 11, 0(11)\n\t" /* target->r11 */ \ |
sewardj | 9734b20 | 2006-01-17 01:49:37 +0000 | [diff] [blame] | 1375 | VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ |
| 1376 | "mr 11,%1\n\t" \ |
| 1377 | "mr %0,3\n\t" \ |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 1378 | "ld 2,-16(11)" /* restore tocptr */ \ |
sewardj | 9734b20 | 2006-01-17 01:49:37 +0000 | [diff] [blame] | 1379 | : /*out*/ "=r" (_res) \ |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 1380 | : /*in*/ "r" (&_argvec[2]) \ |
sewardj | 9734b20 | 2006-01-17 01:49:37 +0000 | [diff] [blame] | 1381 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 1382 | ); \ |
| 1383 | lval = (__typeof__(lval)) _res; \ |
| 1384 | } while (0) |
| 1385 | |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 1386 | #define CALL_FN_W_WW(lval, orig, arg1,arg2) \ |
sewardj | 9734b20 | 2006-01-17 01:49:37 +0000 | [diff] [blame] | 1387 | do { \ |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 1388 | volatile OrigFn _orig = (orig); \ |
| 1389 | volatile unsigned long _argvec[3+2]; \ |
sewardj | 9734b20 | 2006-01-17 01:49:37 +0000 | [diff] [blame] | 1390 | volatile unsigned long _res; \ |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 1391 | /* _argvec[0] holds current r2 across the call */ \ |
| 1392 | _argvec[1] = (unsigned long)_orig.r2; \ |
| 1393 | _argvec[2] = (unsigned long)_orig.nraddr; \ |
| 1394 | _argvec[2+1] = (unsigned long)arg1; \ |
| 1395 | _argvec[2+2] = (unsigned long)arg2; \ |
sewardj | 9734b20 | 2006-01-17 01:49:37 +0000 | [diff] [blame] | 1396 | __asm__ volatile( \ |
| 1397 | "mr 11,%1\n\t" \ |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 1398 | "std 2,-16(11)\n\t" /* save tocptr */ \ |
| 1399 | "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \ |
| 1400 | "ld 3, 8(11)\n\t" /* arg1->r3 */ \ |
| 1401 | "ld 4, 16(11)\n\t" /* arg1->r4 */ \ |
| 1402 | "ld 11, 0(11)\n\t" /* target->r11 */ \ |
sewardj | 9734b20 | 2006-01-17 01:49:37 +0000 | [diff] [blame] | 1403 | VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \ |
| 1404 | "mr 11,%1\n\t" \ |
| 1405 | "mr %0,3\n\t" \ |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 1406 | "ld 2,-16(11)" /* restore tocptr */ \ |
sewardj | 9734b20 | 2006-01-17 01:49:37 +0000 | [diff] [blame] | 1407 | : /*out*/ "=r" (_res) \ |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 1408 | : /*in*/ "r" (&_argvec[2]) \ |
sewardj | 9734b20 | 2006-01-17 01:49:37 +0000 | [diff] [blame] | 1409 | : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS \ |
| 1410 | ); \ |
| 1411 | lval = (__typeof__(lval)) _res; \ |
| 1412 | } while (0) |
| 1413 | |
| 1414 | #endif /* ARCH_ppc64 */ |
| 1415 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1416 | |
| 1417 | /* ------------------------------------------------------------------ */ |
| 1418 | /* ARCHITECTURE INDEPENDENT MACROS for CLIENT REQUESTS. */ |
| 1419 | /* */ |
njn | 30d76c6 | 2005-06-18 15:07:39 +0000 | [diff] [blame] | 1420 | /* ------------------------------------------------------------------ */ |
| 1421 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1422 | /* Some request codes. There are many more of these, but most are not |
| 1423 | exposed to end-user view. These are the public ones, all of the |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1424 | form 0x1000 + small_number. |
njn | d799418 | 2003-10-02 13:44:04 +0000 | [diff] [blame] | 1425 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1426 | Core ones are in the range 0x00000000--0x0000ffff. The non-public |
| 1427 | ones start at 0x2000. |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1428 | */ |
| 1429 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1430 | /* These macros are used by tools -- they must be public, but don't |
| 1431 | embed them into other programs. */ |
njn | fc26ff9 | 2004-11-22 19:12:49 +0000 | [diff] [blame] | 1432 | #define VG_USERREQ_TOOL_BASE(a,b) \ |
njn | 4c79121 | 2003-05-02 17:53:54 +0000 | [diff] [blame] | 1433 | ((unsigned int)(((a)&0xff) << 24 | ((b)&0xff) << 16)) |
njn | fc26ff9 | 2004-11-22 19:12:49 +0000 | [diff] [blame] | 1434 | #define VG_IS_TOOL_USERREQ(a, b, v) \ |
| 1435 | (VG_USERREQ_TOOL_BASE(a,b) == ((v) & 0xffff0000)) |
sewardj | 3404251 | 2002-10-22 04:14:35 +0000 | [diff] [blame] | 1436 | |
sewardj | 5ce4b15 | 2006-03-11 12:57:41 +0000 | [diff] [blame] | 1437 | /* !! ABIWARNING !! ABIWARNING !! ABIWARNING !! ABIWARNING !! |
| 1438 | This enum comprises an ABI exported by Valgrind to programs |
| 1439 | which use client requests. DO NOT CHANGE THE ORDER OF THESE |
| 1440 | ENTRIES, NOR DELETE ANY -- add new ones at the end. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1441 | typedef |
njn | 4c79121 | 2003-05-02 17:53:54 +0000 | [diff] [blame] | 1442 | enum { VG_USERREQ__RUNNING_ON_VALGRIND = 0x1001, |
| 1443 | VG_USERREQ__DISCARD_TRANSLATIONS = 0x1002, |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1444 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1445 | /* These allow any function to be called from the simulated |
| 1446 | CPU but run on the real CPU. Nb: the first arg passed to |
| 1447 | the function is always the ThreadId of the running |
| 1448 | thread! So CLIENT_CALL0 actually requires a 1 arg |
njn | d4795be | 2004-11-24 11:57:51 +0000 | [diff] [blame] | 1449 | function, etc. */ |
njn | 4c79121 | 2003-05-02 17:53:54 +0000 | [diff] [blame] | 1450 | VG_USERREQ__CLIENT_CALL0 = 0x1101, |
| 1451 | VG_USERREQ__CLIENT_CALL1 = 0x1102, |
| 1452 | VG_USERREQ__CLIENT_CALL2 = 0x1103, |
| 1453 | VG_USERREQ__CLIENT_CALL3 = 0x1104, |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1454 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1455 | /* Can be useful in regression testing suites -- eg. can |
| 1456 | send Valgrind's output to /dev/null and still count |
| 1457 | errors. */ |
njn | 4c79121 | 2003-05-02 17:53:54 +0000 | [diff] [blame] | 1458 | VG_USERREQ__COUNT_ERRORS = 0x1201, |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 1459 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1460 | /* These are useful and can be interpreted by any tool that |
| 1461 | tracks malloc() et al, by using vg_replace_malloc.c. */ |
njn | d799418 | 2003-10-02 13:44:04 +0000 | [diff] [blame] | 1462 | VG_USERREQ__MALLOCLIKE_BLOCK = 0x1301, |
| 1463 | VG_USERREQ__FREELIKE_BLOCK = 0x1302, |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 1464 | /* Memory pool support. */ |
| 1465 | VG_USERREQ__CREATE_MEMPOOL = 0x1303, |
| 1466 | VG_USERREQ__DESTROY_MEMPOOL = 0x1304, |
| 1467 | VG_USERREQ__MEMPOOL_ALLOC = 0x1305, |
| 1468 | VG_USERREQ__MEMPOOL_FREE = 0x1306, |
njn | d799418 | 2003-10-02 13:44:04 +0000 | [diff] [blame] | 1469 | |
fitzhardinge | 39de4b4 | 2003-10-31 07:12:21 +0000 | [diff] [blame] | 1470 | /* Allow printfs to valgrind log. */ |
njn | 30d76c6 | 2005-06-18 15:07:39 +0000 | [diff] [blame] | 1471 | VG_USERREQ__PRINTF = 0x1401, |
rjwalsh | 0140af5 | 2005-06-04 20:42:33 +0000 | [diff] [blame] | 1472 | VG_USERREQ__PRINTF_BACKTRACE = 0x1402, |
| 1473 | |
| 1474 | /* Stack support. */ |
| 1475 | VG_USERREQ__STACK_REGISTER = 0x1501, |
| 1476 | VG_USERREQ__STACK_DEREGISTER = 0x1502, |
| 1477 | VG_USERREQ__STACK_CHANGE = 0x1503, |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1478 | } Vg_ClientRequest; |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1479 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1480 | #if !defined(__GNUC__) |
| 1481 | # define __extension__ /* */ |
mueller | c9b3655 | 2003-12-31 14:32:23 +0000 | [diff] [blame] | 1482 | #endif |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1483 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1484 | /* Returns the number of Valgrinds this code is running under. That |
| 1485 | is, 0 if running natively, 1 if running under Valgrind, 2 if |
| 1486 | running under Valgrind which is running under another Valgrind, |
| 1487 | etc. */ |
| 1488 | #define RUNNING_ON_VALGRIND __extension__ \ |
| 1489 | ({unsigned int _qzz_res; \ |
| 1490 | VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0 /* if not */, \ |
| 1491 | VG_USERREQ__RUNNING_ON_VALGRIND, \ |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 1492 | 0, 0, 0, 0, 0); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1493 | _qzz_res; \ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1494 | }) |
| 1495 | |
| 1496 | |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1497 | /* Discard translation of code in the range [_qzz_addr .. _qzz_addr + |
| 1498 | _qzz_len - 1]. Useful if you are debugging a JITter or some such, |
| 1499 | since it provides a way to make sure valgrind will retranslate the |
| 1500 | invalidated area. Returns no value. */ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1501 | #define VALGRIND_DISCARD_TRANSLATIONS(_qzz_addr,_qzz_len) \ |
| 1502 | {unsigned int _qzz_res; \ |
| 1503 | VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0, \ |
| 1504 | VG_USERREQ__DISCARD_TRANSLATIONS, \ |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 1505 | _qzz_addr, _qzz_len, 0, 0, 0); \ |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1506 | } |
| 1507 | |
njn | 26aba4d | 2005-05-16 13:31:23 +0000 | [diff] [blame] | 1508 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1509 | /* These requests are for getting Valgrind itself to print something. |
| 1510 | Possibly with a backtrace. This is a really ugly hack. */ |
| 1511 | |
| 1512 | #if defined(NVALGRIND) |
| 1513 | |
| 1514 | # define VALGRIND_PRINTF(...) |
| 1515 | # define VALGRIND_PRINTF_BACKTRACE(...) |
njn | 26aba4d | 2005-05-16 13:31:23 +0000 | [diff] [blame] | 1516 | |
| 1517 | #else /* NVALGRIND */ |
fitzhardinge | 39de4b4 | 2003-10-31 07:12:21 +0000 | [diff] [blame] | 1518 | |
fitzhardinge | a09a1b5 | 2003-11-07 23:09:48 +0000 | [diff] [blame] | 1519 | int VALGRIND_PRINTF(const char *format, ...) |
| 1520 | __attribute__((format(__printf__, 1, 2))); |
fitzhardinge | 39de4b4 | 2003-10-31 07:12:21 +0000 | [diff] [blame] | 1521 | __attribute__((weak)) |
| 1522 | int |
fitzhardinge | a09a1b5 | 2003-11-07 23:09:48 +0000 | [diff] [blame] | 1523 | VALGRIND_PRINTF(const char *format, ...) |
fitzhardinge | 39de4b4 | 2003-10-31 07:12:21 +0000 | [diff] [blame] | 1524 | { |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1525 | unsigned long _qzz_res; |
fitzhardinge | 39de4b4 | 2003-10-31 07:12:21 +0000 | [diff] [blame] | 1526 | va_list vargs; |
| 1527 | va_start(vargs, format); |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1528 | VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0, VG_USERREQ__PRINTF, |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 1529 | (unsigned long)format, (unsigned long)vargs, |
| 1530 | 0, 0, 0); |
fitzhardinge | 39de4b4 | 2003-10-31 07:12:21 +0000 | [diff] [blame] | 1531 | va_end(vargs); |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1532 | return (int)_qzz_res; |
fitzhardinge | 39de4b4 | 2003-10-31 07:12:21 +0000 | [diff] [blame] | 1533 | } |
| 1534 | |
fitzhardinge | a09a1b5 | 2003-11-07 23:09:48 +0000 | [diff] [blame] | 1535 | int VALGRIND_PRINTF_BACKTRACE(const char *format, ...) |
| 1536 | __attribute__((format(__printf__, 1, 2))); |
fitzhardinge | 39de4b4 | 2003-10-31 07:12:21 +0000 | [diff] [blame] | 1537 | __attribute__((weak)) |
| 1538 | int |
fitzhardinge | a09a1b5 | 2003-11-07 23:09:48 +0000 | [diff] [blame] | 1539 | VALGRIND_PRINTF_BACKTRACE(const char *format, ...) |
fitzhardinge | 39de4b4 | 2003-10-31 07:12:21 +0000 | [diff] [blame] | 1540 | { |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1541 | unsigned long _qzz_res; |
fitzhardinge | 39de4b4 | 2003-10-31 07:12:21 +0000 | [diff] [blame] | 1542 | va_list vargs; |
| 1543 | va_start(vargs, format); |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1544 | VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0, VG_USERREQ__PRINTF_BACKTRACE, |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 1545 | (unsigned long)format, (unsigned long)vargs, |
| 1546 | 0, 0, 0); |
fitzhardinge | 39de4b4 | 2003-10-31 07:12:21 +0000 | [diff] [blame] | 1547 | va_end(vargs); |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1548 | return (int)_qzz_res; |
fitzhardinge | 39de4b4 | 2003-10-31 07:12:21 +0000 | [diff] [blame] | 1549 | } |
| 1550 | |
fitzhardinge | 39de4b4 | 2003-10-31 07:12:21 +0000 | [diff] [blame] | 1551 | #endif /* NVALGRIND */ |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1552 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1553 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1554 | /* These requests allow control to move from the simulated CPU to the |
| 1555 | real CPU, calling an arbitary function */ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1556 | #define VALGRIND_NON_SIMD_CALL0(_qyy_fn) \ |
| 1557 | ({unsigned long _qyy_res; \ |
| 1558 | VALGRIND_DO_CLIENT_REQUEST(_qyy_res, 0 /* default return */, \ |
| 1559 | VG_USERREQ__CLIENT_CALL0, \ |
| 1560 | _qyy_fn, \ |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 1561 | 0, 0, 0, 0); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1562 | _qyy_res; \ |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1563 | }) |
| 1564 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1565 | #define VALGRIND_NON_SIMD_CALL1(_qyy_fn, _qyy_arg1) \ |
| 1566 | ({unsigned long _qyy_res; \ |
| 1567 | VALGRIND_DO_CLIENT_REQUEST(_qyy_res, 0 /* default return */, \ |
| 1568 | VG_USERREQ__CLIENT_CALL1, \ |
| 1569 | _qyy_fn, \ |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 1570 | _qyy_arg1, 0, 0, 0); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1571 | _qyy_res; \ |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1572 | }) |
| 1573 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1574 | #define VALGRIND_NON_SIMD_CALL2(_qyy_fn, _qyy_arg1, _qyy_arg2) \ |
| 1575 | ({unsigned long _qyy_res; \ |
| 1576 | VALGRIND_DO_CLIENT_REQUEST(_qyy_res, 0 /* default return */, \ |
| 1577 | VG_USERREQ__CLIENT_CALL2, \ |
| 1578 | _qyy_fn, \ |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 1579 | _qyy_arg1, _qyy_arg2, 0, 0); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1580 | _qyy_res; \ |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1581 | }) |
| 1582 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1583 | #define VALGRIND_NON_SIMD_CALL3(_qyy_fn, _qyy_arg1, _qyy_arg2, _qyy_arg3) \ |
| 1584 | ({unsigned long _qyy_res; \ |
| 1585 | VALGRIND_DO_CLIENT_REQUEST(_qyy_res, 0 /* default return */, \ |
| 1586 | VG_USERREQ__CLIENT_CALL3, \ |
| 1587 | _qyy_fn, \ |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 1588 | _qyy_arg1, _qyy_arg2, \ |
| 1589 | _qyy_arg3, 0); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1590 | _qyy_res; \ |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1591 | }) |
| 1592 | |
| 1593 | |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 1594 | /* Counts the number of errors that have been recorded by a tool. Nb: |
| 1595 | the tool must record the errors with VG_(maybe_record_error)() or |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 1596 | VG_(unique_error)() for them to be counted. */ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1597 | #define VALGRIND_COUNT_ERRORS \ |
| 1598 | ({unsigned int _qyy_res; \ |
| 1599 | VALGRIND_DO_CLIENT_REQUEST(_qyy_res, 0 /* default return */, \ |
| 1600 | VG_USERREQ__COUNT_ERRORS, \ |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 1601 | 0, 0, 0, 0, 0); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1602 | _qyy_res; \ |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 1603 | }) |
| 1604 | |
njn | d799418 | 2003-10-02 13:44:04 +0000 | [diff] [blame] | 1605 | /* Mark a block of memory as having been allocated by a malloc()-like |
| 1606 | function. `addr' is the start of the usable block (ie. after any |
| 1607 | redzone) `rzB' is redzone size if the allocator can apply redzones; |
| 1608 | use '0' if not. Adding redzones makes it more likely Valgrind will spot |
| 1609 | block overruns. `is_zeroed' indicates if the memory is zeroed, as it is |
| 1610 | for calloc(). Put it immediately after the point where a block is |
| 1611 | allocated. |
| 1612 | |
| 1613 | If you're allocating memory via superblocks, and then handing out small |
| 1614 | chunks of each superblock, if you don't have redzones on your small |
| 1615 | blocks, it's worth marking the superblock with VALGRIND_MAKE_NOACCESS |
| 1616 | when it's created, so that block overruns are detected. But if you can |
| 1617 | put redzones on, it's probably better to not do this, so that messages |
| 1618 | for small overruns are described in terms of the small block rather than |
| 1619 | the superblock (but if you have a big overrun that skips over a redzone, |
| 1620 | you could miss an error this way). See memcheck/tests/custom_alloc.c |
| 1621 | for an example. |
| 1622 | |
| 1623 | Nb: block must be freed via a free()-like function specified |
| 1624 | with VALGRIND_FREELIKE_BLOCK or mismatch errors will occur. */ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1625 | #define VALGRIND_MALLOCLIKE_BLOCK(addr, sizeB, rzB, is_zeroed) \ |
| 1626 | {unsigned int _qzz_res; \ |
| 1627 | VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0, \ |
| 1628 | VG_USERREQ__MALLOCLIKE_BLOCK, \ |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 1629 | addr, sizeB, rzB, is_zeroed, 0); \ |
njn | d799418 | 2003-10-02 13:44:04 +0000 | [diff] [blame] | 1630 | } |
| 1631 | |
| 1632 | /* Mark a block of memory as having been freed by a free()-like function. |
| 1633 | `rzB' is redzone size; it must match that given to |
| 1634 | VALGRIND_MALLOCLIKE_BLOCK. Memory not freed will be detected by the leak |
| 1635 | checker. Put it immediately after the point where the block is freed. */ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1636 | #define VALGRIND_FREELIKE_BLOCK(addr, rzB) \ |
| 1637 | {unsigned int _qzz_res; \ |
| 1638 | VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0, \ |
| 1639 | VG_USERREQ__FREELIKE_BLOCK, \ |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 1640 | addr, rzB, 0, 0, 0); \ |
njn | d799418 | 2003-10-02 13:44:04 +0000 | [diff] [blame] | 1641 | } |
| 1642 | |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 1643 | /* Create a memory pool. */ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1644 | #define VALGRIND_CREATE_MEMPOOL(pool, rzB, is_zeroed) \ |
| 1645 | {unsigned int _qzz_res; \ |
| 1646 | VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0, \ |
| 1647 | VG_USERREQ__CREATE_MEMPOOL, \ |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 1648 | pool, rzB, is_zeroed, 0, 0); \ |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 1649 | } |
| 1650 | |
| 1651 | /* Destroy a memory pool. */ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1652 | #define VALGRIND_DESTROY_MEMPOOL(pool) \ |
| 1653 | {unsigned int _qzz_res; \ |
| 1654 | VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0, \ |
| 1655 | VG_USERREQ__DESTROY_MEMPOOL, \ |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 1656 | pool, 0, 0, 0, 0); \ |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | /* Associate a piece of memory with a memory pool. */ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1660 | #define VALGRIND_MEMPOOL_ALLOC(pool, addr, size) \ |
| 1661 | {unsigned int _qzz_res; \ |
| 1662 | VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0, \ |
| 1663 | VG_USERREQ__MEMPOOL_ALLOC, \ |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 1664 | pool, addr, size, 0, 0); \ |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | /* Disassociate a piece of memory from a memory pool. */ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1668 | #define VALGRIND_MEMPOOL_FREE(pool, addr) \ |
| 1669 | {unsigned int _qzz_res; \ |
| 1670 | VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0, \ |
| 1671 | VG_USERREQ__MEMPOOL_FREE, \ |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 1672 | pool, addr, 0, 0, 0); \ |
rjwalsh | bc0bb83 | 2004-06-19 18:12:36 +0000 | [diff] [blame] | 1673 | } |
| 1674 | |
rjwalsh | 0140af5 | 2005-06-04 20:42:33 +0000 | [diff] [blame] | 1675 | /* Mark a piece of memory as being a stack. Returns a stack id. */ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1676 | #define VALGRIND_STACK_REGISTER(start, end) \ |
| 1677 | ({unsigned int _qzz_res; \ |
| 1678 | VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0, \ |
| 1679 | VG_USERREQ__STACK_REGISTER, \ |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 1680 | start, end, 0, 0, 0); \ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1681 | _qzz_res; \ |
rjwalsh | 0140af5 | 2005-06-04 20:42:33 +0000 | [diff] [blame] | 1682 | }) |
| 1683 | |
| 1684 | /* Unmark the piece of memory associated with a stack id as being a |
| 1685 | stack. */ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1686 | #define VALGRIND_STACK_DEREGISTER(id) \ |
| 1687 | {unsigned int _qzz_res; \ |
| 1688 | VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0, \ |
| 1689 | VG_USERREQ__STACK_DEREGISTER, \ |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 1690 | id, 0, 0, 0, 0); \ |
rjwalsh | 0140af5 | 2005-06-04 20:42:33 +0000 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | /* Change the start and end address of the stack id. */ |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1694 | #define VALGRIND_STACK_CHANGE(id, start, end) \ |
| 1695 | {unsigned int _qzz_res; \ |
| 1696 | VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0, \ |
| 1697 | VG_USERREQ__STACK_CHANGE, \ |
sewardj | 9af10a1 | 2006-02-01 14:59:42 +0000 | [diff] [blame] | 1698 | id, start, end, 0, 0); \ |
rjwalsh | 0140af5 | 2005-06-04 20:42:33 +0000 | [diff] [blame] | 1699 | } |
| 1700 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1701 | |
| 1702 | #undef ARCH_x86 |
| 1703 | #undef ARCH_amd64 |
| 1704 | #undef ARCH_ppc32 |
| 1705 | #undef ARCH_ppc64 |
| 1706 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1707 | #endif /* __VALGRIND_H */ |