Skip to content
Snippets Groups Projects
valgrind.h 273 KiB
Newer Older
  • Learn to ignore specific revisions
  • toole1's avatar
    toole1 committed
    4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792
             VG_EXPAND_FRAME_BY_trashes_r3(512)                       \
             "std  2,-16(11)\n\t" /* save tocptr */                   \
             "ld   2,-8(11)\n\t"  /* use nraddr's tocptr */           \
             "ld   3, 8(11)\n\t"  /* arg1->r3 */                      \
             "ld   4, 16(11)\n\t" /* arg2->r4 */                      \
             "ld   5, 24(11)\n\t" /* arg3->r5 */                      \
             "ld   6, 32(11)\n\t" /* arg4->r6 */                      \
             "ld   7, 40(11)\n\t" /* arg5->r7 */                      \
             "ld   8, 48(11)\n\t" /* arg6->r8 */                      \
             "ld   9, 56(11)\n\t" /* arg7->r9 */                      \
             "ld  10, 64(11)\n\t" /* arg8->r10 */                     \
             "ld  11, 0(11)\n\t"  /* target->r11 */                   \
             VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11                  \
             "mr 11,%1\n\t"                                           \
             "mr %0,3\n\t"                                            \
             "ld  2,-16(11)\n\t" /* restore tocptr */                 \
             VG_CONTRACT_FRAME_BY(512)                                \
             : /*out*/   "=r" (_res)                                  \
             : /*in*/    "r" (&_argvec[2])                            \
             : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS          \
          );                                                          \
          lval = (__typeof__(lval)) _res;                             \
       } while (0)
    
    #define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6,   \
                                     arg7,arg8,arg9)                  \
       do {                                                           \
          volatile OrigFn        _orig = (orig);                      \
          volatile unsigned long _argvec[3+9];                        \
          volatile unsigned long _res;                                \
          /* _argvec[0] holds current r2 across the call */           \
          _argvec[1]   = (unsigned long)_orig.r2;                     \
          _argvec[2]   = (unsigned long)_orig.nraddr;                 \
          _argvec[2+1] = (unsigned long)arg1;                         \
          _argvec[2+2] = (unsigned long)arg2;                         \
          _argvec[2+3] = (unsigned long)arg3;                         \
          _argvec[2+4] = (unsigned long)arg4;                         \
          _argvec[2+5] = (unsigned long)arg5;                         \
          _argvec[2+6] = (unsigned long)arg6;                         \
          _argvec[2+7] = (unsigned long)arg7;                         \
          _argvec[2+8] = (unsigned long)arg8;                         \
          _argvec[2+9] = (unsigned long)arg9;                         \
          __asm__ volatile(                                           \
             "mr 11,%1\n\t"                                           \
             VG_EXPAND_FRAME_BY_trashes_r3(512)                       \
             "std  2,-16(11)\n\t" /* save tocptr */                   \
             "ld   2,-8(11)\n\t"  /* use nraddr's tocptr */           \
             VG_EXPAND_FRAME_BY_trashes_r3(128)                       \
             /* arg9 */                                               \
             "ld  3,72(11)\n\t"                                       \
             "std 3,112(1)\n\t"                                       \
             /* args1-8 */                                            \
             "ld   3, 8(11)\n\t"  /* arg1->r3 */                      \
             "ld   4, 16(11)\n\t" /* arg2->r4 */                      \
             "ld   5, 24(11)\n\t" /* arg3->r5 */                      \
             "ld   6, 32(11)\n\t" /* arg4->r6 */                      \
             "ld   7, 40(11)\n\t" /* arg5->r7 */                      \
             "ld   8, 48(11)\n\t" /* arg6->r8 */                      \
             "ld   9, 56(11)\n\t" /* arg7->r9 */                      \
             "ld  10, 64(11)\n\t" /* arg8->r10 */                     \
             "ld  11, 0(11)\n\t"  /* target->r11 */                   \
             VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11                  \
             "mr 11,%1\n\t"                                           \
             "mr %0,3\n\t"                                            \
             "ld  2,-16(11)\n\t" /* restore tocptr */                 \
             VG_CONTRACT_FRAME_BY(128)                                \
             VG_CONTRACT_FRAME_BY(512)                                \
             : /*out*/   "=r" (_res)                                  \
             : /*in*/    "r" (&_argvec[2])                            \
             : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS          \
          );                                                          \
          lval = (__typeof__(lval)) _res;                             \
       } while (0)
    
    #define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6,  \
                                      arg7,arg8,arg9,arg10)           \
       do {                                                           \
          volatile OrigFn        _orig = (orig);                      \
          volatile unsigned long _argvec[3+10];                       \
          volatile unsigned long _res;                                \
          /* _argvec[0] holds current r2 across the call */           \
          _argvec[1]   = (unsigned long)_orig.r2;                     \
          _argvec[2]   = (unsigned long)_orig.nraddr;                 \
          _argvec[2+1] = (unsigned long)arg1;                         \
          _argvec[2+2] = (unsigned long)arg2;                         \
          _argvec[2+3] = (unsigned long)arg3;                         \
          _argvec[2+4] = (unsigned long)arg4;                         \
          _argvec[2+5] = (unsigned long)arg5;                         \
          _argvec[2+6] = (unsigned long)arg6;                         \
          _argvec[2+7] = (unsigned long)arg7;                         \
          _argvec[2+8] = (unsigned long)arg8;                         \
          _argvec[2+9] = (unsigned long)arg9;                         \
          _argvec[2+10] = (unsigned long)arg10;                       \
          __asm__ volatile(                                           \
             "mr 11,%1\n\t"                                           \
             VG_EXPAND_FRAME_BY_trashes_r3(512)                       \
             "std  2,-16(11)\n\t" /* save tocptr */                   \
             "ld   2,-8(11)\n\t"  /* use nraddr's tocptr */           \
             VG_EXPAND_FRAME_BY_trashes_r3(128)                       \
             /* arg10 */                                              \
             "ld  3,80(11)\n\t"                                       \
             "std 3,120(1)\n\t"                                       \
             /* arg9 */                                               \
             "ld  3,72(11)\n\t"                                       \
             "std 3,112(1)\n\t"                                       \
             /* args1-8 */                                            \
             "ld   3, 8(11)\n\t"  /* arg1->r3 */                      \
             "ld   4, 16(11)\n\t" /* arg2->r4 */                      \
             "ld   5, 24(11)\n\t" /* arg3->r5 */                      \
             "ld   6, 32(11)\n\t" /* arg4->r6 */                      \
             "ld   7, 40(11)\n\t" /* arg5->r7 */                      \
             "ld   8, 48(11)\n\t" /* arg6->r8 */                      \
             "ld   9, 56(11)\n\t" /* arg7->r9 */                      \
             "ld  10, 64(11)\n\t" /* arg8->r10 */                     \
             "ld  11, 0(11)\n\t"  /* target->r11 */                   \
             VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11                  \
             "mr 11,%1\n\t"                                           \
             "mr %0,3\n\t"                                            \
             "ld  2,-16(11)\n\t" /* restore tocptr */                 \
             VG_CONTRACT_FRAME_BY(128)                                \
             VG_CONTRACT_FRAME_BY(512)                                \
             : /*out*/   "=r" (_res)                                  \
             : /*in*/    "r" (&_argvec[2])                            \
             : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS          \
          );                                                          \
          lval = (__typeof__(lval)) _res;                             \
       } while (0)
    
    #define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6,  \
                                      arg7,arg8,arg9,arg10,arg11)     \
       do {                                                           \
          volatile OrigFn        _orig = (orig);                      \
          volatile unsigned long _argvec[3+11];                       \
          volatile unsigned long _res;                                \
          /* _argvec[0] holds current r2 across the call */           \
          _argvec[1]   = (unsigned long)_orig.r2;                     \
          _argvec[2]   = (unsigned long)_orig.nraddr;                 \
          _argvec[2+1] = (unsigned long)arg1;                         \
          _argvec[2+2] = (unsigned long)arg2;                         \
          _argvec[2+3] = (unsigned long)arg3;                         \
          _argvec[2+4] = (unsigned long)arg4;                         \
          _argvec[2+5] = (unsigned long)arg5;                         \
          _argvec[2+6] = (unsigned long)arg6;                         \
          _argvec[2+7] = (unsigned long)arg7;                         \
          _argvec[2+8] = (unsigned long)arg8;                         \
          _argvec[2+9] = (unsigned long)arg9;                         \
          _argvec[2+10] = (unsigned long)arg10;                       \
          _argvec[2+11] = (unsigned long)arg11;                       \
          __asm__ volatile(                                           \
             "mr 11,%1\n\t"                                           \
             VG_EXPAND_FRAME_BY_trashes_r3(512)                       \
             "std  2,-16(11)\n\t" /* save tocptr */                   \
             "ld   2,-8(11)\n\t"  /* use nraddr's tocptr */           \
             VG_EXPAND_FRAME_BY_trashes_r3(144)                       \
             /* arg11 */                                              \
             "ld  3,88(11)\n\t"                                       \
             "std 3,128(1)\n\t"                                       \
             /* arg10 */                                              \
             "ld  3,80(11)\n\t"                                       \
             "std 3,120(1)\n\t"                                       \
             /* arg9 */                                               \
             "ld  3,72(11)\n\t"                                       \
             "std 3,112(1)\n\t"                                       \
             /* args1-8 */                                            \
             "ld   3, 8(11)\n\t"  /* arg1->r3 */                      \
             "ld   4, 16(11)\n\t" /* arg2->r4 */                      \
             "ld   5, 24(11)\n\t" /* arg3->r5 */                      \
             "ld   6, 32(11)\n\t" /* arg4->r6 */                      \
             "ld   7, 40(11)\n\t" /* arg5->r7 */                      \
             "ld   8, 48(11)\n\t" /* arg6->r8 */                      \
             "ld   9, 56(11)\n\t" /* arg7->r9 */                      \
             "ld  10, 64(11)\n\t" /* arg8->r10 */                     \
             "ld  11, 0(11)\n\t"  /* target->r11 */                   \
             VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11                  \
             "mr 11,%1\n\t"                                           \
             "mr %0,3\n\t"                                            \
             "ld  2,-16(11)\n\t" /* restore tocptr */                 \
             VG_CONTRACT_FRAME_BY(144)                                \
             VG_CONTRACT_FRAME_BY(512)                                \
             : /*out*/   "=r" (_res)                                  \
             : /*in*/    "r" (&_argvec[2])                            \
             : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS          \
          );                                                          \
          lval = (__typeof__(lval)) _res;                             \
       } while (0)
    
    #define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6,  \
                                    arg7,arg8,arg9,arg10,arg11,arg12) \
       do {                                                           \
          volatile OrigFn        _orig = (orig);                      \
          volatile unsigned long _argvec[3+12];                       \
          volatile unsigned long _res;                                \
          /* _argvec[0] holds current r2 across the call */           \
          _argvec[1]   = (unsigned long)_orig.r2;                     \
          _argvec[2]   = (unsigned long)_orig.nraddr;                 \
          _argvec[2+1] = (unsigned long)arg1;                         \
          _argvec[2+2] = (unsigned long)arg2;                         \
          _argvec[2+3] = (unsigned long)arg3;                         \
          _argvec[2+4] = (unsigned long)arg4;                         \
          _argvec[2+5] = (unsigned long)arg5;                         \
          _argvec[2+6] = (unsigned long)arg6;                         \
          _argvec[2+7] = (unsigned long)arg7;                         \
          _argvec[2+8] = (unsigned long)arg8;                         \
          _argvec[2+9] = (unsigned long)arg9;                         \
          _argvec[2+10] = (unsigned long)arg10;                       \
          _argvec[2+11] = (unsigned long)arg11;                       \
          _argvec[2+12] = (unsigned long)arg12;                       \
          __asm__ volatile(                                           \
             "mr 11,%1\n\t"                                           \
             VG_EXPAND_FRAME_BY_trashes_r3(512)                       \
             "std  2,-16(11)\n\t" /* save tocptr */                   \
             "ld   2,-8(11)\n\t"  /* use nraddr's tocptr */           \
             VG_EXPAND_FRAME_BY_trashes_r3(144)                       \
             /* arg12 */                                              \
             "ld  3,96(11)\n\t"                                       \
             "std 3,136(1)\n\t"                                       \
             /* arg11 */                                              \
             "ld  3,88(11)\n\t"                                       \
             "std 3,128(1)\n\t"                                       \
             /* arg10 */                                              \
             "ld  3,80(11)\n\t"                                       \
             "std 3,120(1)\n\t"                                       \
             /* arg9 */                                               \
             "ld  3,72(11)\n\t"                                       \
             "std 3,112(1)\n\t"                                       \
             /* args1-8 */                                            \
             "ld   3, 8(11)\n\t"  /* arg1->r3 */                      \
             "ld   4, 16(11)\n\t" /* arg2->r4 */                      \
             "ld   5, 24(11)\n\t" /* arg3->r5 */                      \
             "ld   6, 32(11)\n\t" /* arg4->r6 */                      \
             "ld   7, 40(11)\n\t" /* arg5->r7 */                      \
             "ld   8, 48(11)\n\t" /* arg6->r8 */                      \
             "ld   9, 56(11)\n\t" /* arg7->r9 */                      \
             "ld  10, 64(11)\n\t" /* arg8->r10 */                     \
             "ld  11, 0(11)\n\t"  /* target->r11 */                   \
             VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11                  \
             "mr 11,%1\n\t"                                           \
             "mr %0,3\n\t"                                            \
             "ld  2,-16(11)\n\t" /* restore tocptr */                 \
             VG_CONTRACT_FRAME_BY(144)                                \
             VG_CONTRACT_FRAME_BY(512)                                \
             : /*out*/   "=r" (_res)                                  \
             : /*in*/    "r" (&_argvec[2])                            \
             : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS          \
          );                                                          \
          lval = (__typeof__(lval)) _res;                             \
       } while (0)
    
    #endif /* PLAT_ppc64_aix5 */
    
    
    /* ------------------------------------------------------------------ */
    /* ARCHITECTURE INDEPENDENT MACROS for CLIENT REQUESTS.               */
    /*                                                                    */
    /* ------------------------------------------------------------------ */
    
    /* Some request codes.  There are many more of these, but most are not
       exposed to end-user view.  These are the public ones, all of the
       form 0x1000 + small_number.
    
       Core ones are in the range 0x00000000--0x0000ffff.  The non-public
       ones start at 0x2000.
    */
    
    /* These macros are used by tools -- they must be public, but don't
       embed them into other programs. */
    #define VG_USERREQ_TOOL_BASE(a,b) \
       ((unsigned int)(((a)&0xff) << 24 | ((b)&0xff) << 16))
    #define VG_IS_TOOL_USERREQ(a, b, v) \
       (VG_USERREQ_TOOL_BASE(a,b) == ((v) & 0xffff0000))
    
    /* !! ABIWARNING !! ABIWARNING !! ABIWARNING !! ABIWARNING !! 
       This enum comprises an ABI exported by Valgrind to programs
       which use client requests.  DO NOT CHANGE THE ORDER OF THESE
       ENTRIES, NOR DELETE ANY -- add new ones at the end. */
    typedef
       enum { VG_USERREQ__RUNNING_ON_VALGRIND  = 0x1001,
              VG_USERREQ__DISCARD_TRANSLATIONS = 0x1002,
    
              /* These allow any function to be called from the simulated
                 CPU but run on the real CPU.  Nb: the first arg passed to
                 the function is always the ThreadId of the running
                 thread!  So CLIENT_CALL0 actually requires a 1 arg
                 function, etc. */
              VG_USERREQ__CLIENT_CALL0 = 0x1101,
              VG_USERREQ__CLIENT_CALL1 = 0x1102,
              VG_USERREQ__CLIENT_CALL2 = 0x1103,
              VG_USERREQ__CLIENT_CALL3 = 0x1104,
    
              /* Can be useful in regression testing suites -- eg. can
                 send Valgrind's output to /dev/null and still count
                 errors. */
              VG_USERREQ__COUNT_ERRORS = 0x1201,
    
              /* These are useful and can be interpreted by any tool that
                 tracks malloc() et al, by using vg_replace_malloc.c. */
              VG_USERREQ__MALLOCLIKE_BLOCK = 0x1301,
              VG_USERREQ__FREELIKE_BLOCK   = 0x1302,
              /* Memory pool support. */
              VG_USERREQ__CREATE_MEMPOOL   = 0x1303,
              VG_USERREQ__DESTROY_MEMPOOL  = 0x1304,
              VG_USERREQ__MEMPOOL_ALLOC    = 0x1305,
              VG_USERREQ__MEMPOOL_FREE     = 0x1306,
              VG_USERREQ__MEMPOOL_TRIM     = 0x1307,
              VG_USERREQ__MOVE_MEMPOOL     = 0x1308,
              VG_USERREQ__MEMPOOL_CHANGE   = 0x1309,
              VG_USERREQ__MEMPOOL_EXISTS   = 0x130a,
    
              /* Allow printfs to valgrind log. */
              /* The first two pass the va_list argument by value, which
                 assumes it is the same size as or smaller than a UWord,
                 which generally isn't the case.  Hence are deprecated.
                 The second two pass the vargs by reference and so are
                 immune to this problem. */
              /* both :: char* fmt, va_list vargs (DEPRECATED) */
              VG_USERREQ__PRINTF           = 0x1401,
              VG_USERREQ__PRINTF_BACKTRACE = 0x1402,
              /* both :: char* fmt, va_list* vargs */
              VG_USERREQ__PRINTF_VALIST_BY_REF = 0x1403,
              VG_USERREQ__PRINTF_BACKTRACE_VALIST_BY_REF = 0x1404,
    
              /* Stack support. */
              VG_USERREQ__STACK_REGISTER   = 0x1501,
              VG_USERREQ__STACK_DEREGISTER = 0x1502,
              VG_USERREQ__STACK_CHANGE     = 0x1503,
    
              /* Wine support */
              VG_USERREQ__LOAD_PDB_DEBUGINFO = 0x1601,
    
              /* Querying of debug info. */
              VG_USERREQ__MAP_IP_TO_SRCLOC = 0x1701
       } Vg_ClientRequest;
    
    #if !defined(__GNUC__)
    #  define __extension__ /* */
    #endif
    
    
    /*
     * VALGRIND_DO_CLIENT_REQUEST_EXPR(): a C expression that invokes a Valgrind
     * client request and whose value equals the client request result.
     */
    
    #if defined(NVALGRIND)
    
    #define VALGRIND_DO_CLIENT_REQUEST_EXPR(                               \
            _zzq_default, _zzq_request,                                    \
            _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5)         \
       (_zzq_default)
    
    #else /*defined(NVALGRIND)*/
    
    #if defined(_MSC_VER)
    
    #define VALGRIND_DO_CLIENT_REQUEST_EXPR(                                \
            _zzq_default, _zzq_request,                                     \
            _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5)          \
       (vg_VALGRIND_DO_CLIENT_REQUEST_EXPR((uintptr_t)(_zzq_default),       \
            (_zzq_request), (uintptr_t)(_zzq_arg1), (uintptr_t)(_zzq_arg2), \
            (uintptr_t)(_zzq_arg3), (uintptr_t)(_zzq_arg4),                 \
            (uintptr_t)(_zzq_arg5)))
    
    static __inline unsigned
    vg_VALGRIND_DO_CLIENT_REQUEST_EXPR(uintptr_t _zzq_default,
                                       unsigned _zzq_request, uintptr_t _zzq_arg1,
                                       uintptr_t _zzq_arg2, uintptr_t _zzq_arg3,
                                       uintptr_t _zzq_arg4, uintptr_t _zzq_arg5)
    {
        unsigned _zzq_rlval;
        VALGRIND_DO_CLIENT_REQUEST(_zzq_rlval, _zzq_default, _zzq_request,
                          _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5);
        return _zzq_rlval;
    }
    
    #else /*defined(_MSC_VER)*/
    
    #define VALGRIND_DO_CLIENT_REQUEST_EXPR(                               \
            _zzq_default, _zzq_request,                                    \
            _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5)         \
       (__extension__({unsigned int _zzq_rlval;                            \
        VALGRIND_DO_CLIENT_REQUEST(_zzq_rlval, _zzq_default, _zzq_request, \
                    _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
        _zzq_rlval;                                                        \
       }))
    
    #endif /*defined(_MSC_VER)*/
    
    #endif /*defined(NVALGRIND)*/
    
    
    /* Returns the number of Valgrinds this code is running under.  That
       is, 0 if running natively, 1 if running under Valgrind, 2 if
       running under Valgrind which is running under another Valgrind,
       etc. */
    #define RUNNING_ON_VALGRIND                                           \
        VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* if not */,                   \
                                        VG_USERREQ__RUNNING_ON_VALGRIND,  \
                                        0, 0, 0, 0, 0)                    \
    
    
    /* Discard translation of code in the range [_qzz_addr .. _qzz_addr +
       _qzz_len - 1].  Useful if you are debugging a JITter or some such,
       since it provides a way to make sure valgrind will retranslate the
       invalidated area.  Returns no value. */
    #define VALGRIND_DISCARD_TRANSLATIONS(_qzz_addr,_qzz_len)         \
       {unsigned int _qzz_res;                                        \
        VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0,                       \
                                   VG_USERREQ__DISCARD_TRANSLATIONS,  \
                                   _qzz_addr, _qzz_len, 0, 0, 0);     \
       }
    
    
    /* These requests are for getting Valgrind itself to print something.
       Possibly with a backtrace.  This is a really ugly hack.  The return value
       is the number of characters printed, excluding the "**<pid>** " part at the
       start and the backtrace (if present). */
    
    #if defined(NVALGRIND)
    
    #  define VALGRIND_PRINTF(...)
    #  define VALGRIND_PRINTF_BACKTRACE(...)
    
    #else /* NVALGRIND */
    
    #if !defined(_MSC_VER)
    /* Modern GCC will optimize the static routine out if unused,
       and unused attribute will shut down warnings about it.  */
    static int VALGRIND_PRINTF(const char *format, ...)
       __attribute__((format(__printf__, 1, 2), __unused__));
    #endif
    static int
    #if defined(_MSC_VER)
    __inline
    #endif
    VALGRIND_PRINTF(const char *format, ...)
    {
       unsigned long _qzz_res;
       va_list vargs;
       va_start(vargs, format);
    #if defined(_MSC_VER)
       VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0,
                                  VG_USERREQ__PRINTF_VALIST_BY_REF,
                                  (uintptr_t)format,
                                  (uintptr_t)&vargs,
                                  0, 0, 0);
    #else
       VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0,
                                  VG_USERREQ__PRINTF_VALIST_BY_REF,
                                  (unsigned long)format,
                                  (unsigned long)&vargs, 
                                  0, 0, 0);
    #endif
       va_end(vargs);
       return (int)_qzz_res;
    }
    
    #if !defined(_MSC_VER)
    static int VALGRIND_PRINTF_BACKTRACE(const char *format, ...)
       __attribute__((format(__printf__, 1, 2), __unused__));
    #endif
    static int
    #if defined(_MSC_VER)
    __inline
    #endif
    VALGRIND_PRINTF_BACKTRACE(const char *format, ...)
    {
       unsigned long _qzz_res;
       va_list vargs;
       va_start(vargs, format);
    #if defined(_MSC_VER)
       VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0,
                                  VG_USERREQ__PRINTF_BACKTRACE_VALIST_BY_REF,
                                  (uintptr_t)format,
                                  (uintptr_t)&vargs,
                                  0, 0, 0);
    #else
       VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0,
                                  VG_USERREQ__PRINTF_BACKTRACE_VALIST_BY_REF,
                                  (unsigned long)format,
                                  (unsigned long)&vargs, 
                                  0, 0, 0);
    #endif
       va_end(vargs);
       return (int)_qzz_res;
    }
    
    #endif /* NVALGRIND */
    
    
    /* These requests allow control to move from the simulated CPU to the
       real CPU, calling an arbitary function.
       
       Note that the current ThreadId is inserted as the first argument.
       So this call:
    
         VALGRIND_NON_SIMD_CALL2(f, arg1, arg2)
    
       requires f to have this signature:
    
         Word f(Word tid, Word arg1, Word arg2)
    
       where "Word" is a word-sized type.
    
       Note that these client requests are not entirely reliable.  For example,
       if you call a function with them that subsequently calls printf(),
       there's a high chance Valgrind will crash.  Generally, your prospects of
       these working are made higher if the called function does not refer to
       any global variables, and does not refer to any libc or other functions
       (printf et al).  Any kind of entanglement with libc or dynamic linking is
       likely to have a bad outcome, for tricky reasons which we've grappled
       with a lot in the past.
    */
    #define VALGRIND_NON_SIMD_CALL0(_qyy_fn)                          \
       __extension__                                                  \
       ({unsigned long _qyy_res;                                      \
        VALGRIND_DO_CLIENT_REQUEST(_qyy_res, 0 /* default return */,  \
                                   VG_USERREQ__CLIENT_CALL0,          \
                                   _qyy_fn,                           \
                                   0, 0, 0, 0);                       \
        _qyy_res;                                                     \
       })
    
    #define VALGRIND_NON_SIMD_CALL1(_qyy_fn, _qyy_arg1)               \
       __extension__                                                  \
       ({unsigned long _qyy_res;                                      \
        VALGRIND_DO_CLIENT_REQUEST(_qyy_res, 0 /* default return */,  \
                                   VG_USERREQ__CLIENT_CALL1,          \
                                   _qyy_fn,                           \
                                   _qyy_arg1, 0, 0, 0);               \
        _qyy_res;                                                     \
       })
    
    #define VALGRIND_NON_SIMD_CALL2(_qyy_fn, _qyy_arg1, _qyy_arg2)    \
       __extension__                                                  \
       ({unsigned long _qyy_res;                                      \
        VALGRIND_DO_CLIENT_REQUEST(_qyy_res, 0 /* default return */,  \
                                   VG_USERREQ__CLIENT_CALL2,          \
                                   _qyy_fn,                           \
                                   _qyy_arg1, _qyy_arg2, 0, 0);       \
        _qyy_res;                                                     \
       })
    
    #define VALGRIND_NON_SIMD_CALL3(_qyy_fn, _qyy_arg1, _qyy_arg2, _qyy_arg3) \
       __extension__                                                  \
       ({unsigned long _qyy_res;                                      \
        VALGRIND_DO_CLIENT_REQUEST(_qyy_res, 0 /* default return */,  \
                                   VG_USERREQ__CLIENT_CALL3,          \
                                   _qyy_fn,                           \
                                   _qyy_arg1, _qyy_arg2,              \
                                   _qyy_arg3, 0);                     \
        _qyy_res;                                                     \
       })
    
    
    /* Counts the number of errors that have been recorded by a tool.  Nb:
       the tool must record the errors with VG_(maybe_record_error)() or
       VG_(unique_error)() for them to be counted. */
    #define VALGRIND_COUNT_ERRORS                                     \
       __extension__                                                  \
       ({unsigned int _qyy_res;                                       \
        VALGRIND_DO_CLIENT_REQUEST(_qyy_res, 0 /* default return */,  \
                                   VG_USERREQ__COUNT_ERRORS,          \
                                   0, 0, 0, 0, 0);                    \
        _qyy_res;                                                     \
       })
    
    /* Several Valgrind tools (Memcheck, Massif, Helgrind, DRD) rely on knowing
       when heap blocks are allocated in order to give accurate results.  This
       happens automatically for the standard allocator functions such as
       malloc(), calloc(), realloc(), memalign(), new, new[], free(), delete,
       delete[], etc.
    
       But if your program uses a custom allocator, this doesn't automatically
       happen, and Valgrind will not do as well.  For example, if you allocate
       superblocks with mmap() and then allocates chunks of the superblocks, all
       Valgrind's observations will be at the mmap() level and it won't know that
       the chunks should be considered separate entities.  In Memcheck's case,
       that means you probably won't get heap block overrun detection (because
       there won't be redzones marked as unaddressable) and you definitely won't
       get any leak detection.
    
       The following client requests allow a custom allocator to be annotated so
       that it can be handled accurately by Valgrind.
    
       VALGRIND_MALLOCLIKE_BLOCK marks a region of memory as having been allocated
       by a malloc()-like function.  For Memcheck (an illustrative case), this
       does two things:
    
       - It records that the block has been allocated.  This means any addresses
         within the block mentioned in error messages will be
         identified as belonging to the block.  It also means that if the block
         isn't freed it will be detected by the leak checker.
    
       - It marks the block as being addressable and undefined (if 'is_zeroed' is
         not set), or addressable and defined (if 'is_zeroed' is set).  This
         controls how accesses to the block by the program are handled.
       
       'addr' is the start of the usable block (ie. after any
       redzone), 'sizeB' is its size.  'rzB' is the redzone size if the allocator
       can apply redzones -- these are blocks of padding at the start and end of
       each block.  Adding redzones is recommended as it makes it much more likely
       Valgrind will spot block overruns.  `is_zeroed' indicates if the memory is
       zeroed (or filled with another predictable value), as is the case for
       calloc().
       
       VALGRIND_MALLOCLIKE_BLOCK should be put immediately after the point where a
       heap block -- that will be used by the client program -- is allocated.
       It's best to put it at the outermost level of the allocator if possible;
       for example, if you have a function my_alloc() which calls
       internal_alloc(), and the client request is put inside internal_alloc(),
       stack traces relating to the heap block will contain entries for both
       my_alloc() and internal_alloc(), which is probably not what you want.
    
       For Memcheck users: if you use VALGRIND_MALLOCLIKE_BLOCK to carve out
       custom blocks from within a heap block, B, that has been allocated with
       malloc/calloc/new/etc, then block B will be *ignored* during leak-checking
       -- the custom blocks will take precedence.
    
       VALGRIND_FREELIKE_BLOCK is the partner to VALGRIND_MALLOCLIKE_BLOCK.  For
       Memcheck, it does two things:
    
       - It records that the block has been deallocated.  This assumes that the
         block was annotated as having been allocated via
         VALGRIND_MALLOCLIKE_BLOCK.  Otherwise, an error will be issued.
    
       - It marks the block as being unaddressable.
    
       VALGRIND_FREELIKE_BLOCK should be put immediately after the point where a
       heap block is deallocated.
    
       In many cases, these two client requests will not be enough to get your
       allocator working well with Memcheck.  More specifically, if your allocator
       writes to freed blocks in any way then a VALGRIND_MAKE_MEM_UNDEFINED call
       will be necessary to mark the memory as addressable just before the zeroing
       occurs, otherwise you'll get a lot of invalid write errors.  For example,
       you'll need to do this if your allocator recycles freed blocks, but it
       zeroes them before handing them back out (via VALGRIND_MALLOCLIKE_BLOCK).
       Alternatively, if your allocator reuses freed blocks for allocator-internal
       data structures, VALGRIND_MAKE_MEM_UNDEFINED calls will also be necessary.
    
       Really, what's happening is a blurring of the lines between the client
       program and the allocator... after VALGRIND_FREELIKE_BLOCK is called, the
       memory should be considered unaddressable to the client program, but the
       allocator knows more than the rest of the client program and so may be able
       to safely access it.  Extra client requests are necessary for Valgrind to
       understand the distinction between the allocator and the rest of the
       program.
    
       Note: there is currently no VALGRIND_REALLOCLIKE_BLOCK client request;  it
       has to be emulated with MALLOCLIKE/FREELIKE and memory copying.
       
       Ignored if addr == 0.
    */
    #define VALGRIND_MALLOCLIKE_BLOCK(addr, sizeB, rzB, is_zeroed)    \
       {unsigned int _qzz_res;                                        \
        VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0,                       \
                                   VG_USERREQ__MALLOCLIKE_BLOCK,      \
                                   addr, sizeB, rzB, is_zeroed, 0);   \
       }
    
    /* See the comment for VALGRIND_MALLOCLIKE_BLOCK for details.
       Ignored if addr == 0.
    */
    #define VALGRIND_FREELIKE_BLOCK(addr, rzB)                        \
       {unsigned int _qzz_res;                                        \
        VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0,                       \
                                   VG_USERREQ__FREELIKE_BLOCK,        \
                                   addr, rzB, 0, 0, 0);               \
       }
    
    /* Create a memory pool. */
    #define VALGRIND_CREATE_MEMPOOL(pool, rzB, is_zeroed)             \
       {unsigned int _qzz_res;                                        \
        VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0,                       \
                                   VG_USERREQ__CREATE_MEMPOOL,        \
                                   pool, rzB, is_zeroed, 0, 0);       \
       }
    
    /* Destroy a memory pool. */
    #define VALGRIND_DESTROY_MEMPOOL(pool)                            \
       {unsigned int _qzz_res;                                        \
        VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0,                       \
                                   VG_USERREQ__DESTROY_MEMPOOL,       \
                                   pool, 0, 0, 0, 0);                 \
       }
    
    /* Associate a piece of memory with a memory pool. */
    #define VALGRIND_MEMPOOL_ALLOC(pool, addr, size)                  \
       {unsigned int _qzz_res;                                        \
        VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0,                       \
                                   VG_USERREQ__MEMPOOL_ALLOC,         \
                                   pool, addr, size, 0, 0);           \
       }
    
    /* Disassociate a piece of memory from a memory pool. */
    #define VALGRIND_MEMPOOL_FREE(pool, addr)                         \
       {unsigned int _qzz_res;                                        \
        VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0,                       \
                                   VG_USERREQ__MEMPOOL_FREE,          \
                                   pool, addr, 0, 0, 0);              \
       }
    
    /* Disassociate any pieces outside a particular range. */
    #define VALGRIND_MEMPOOL_TRIM(pool, addr, size)                   \
       {unsigned int _qzz_res;                                        \
        VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0,                       \
                                   VG_USERREQ__MEMPOOL_TRIM,          \
                                   pool, addr, size, 0, 0);           \
       }
    
    /* Resize and/or move a piece associated with a memory pool. */
    #define VALGRIND_MOVE_MEMPOOL(poolA, poolB)                       \
       {unsigned int _qzz_res;                                        \
        VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0,                       \
                                   VG_USERREQ__MOVE_MEMPOOL,          \
                                   poolA, poolB, 0, 0, 0);            \
       }
    
    /* Resize and/or move a piece associated with a memory pool. */
    #define VALGRIND_MEMPOOL_CHANGE(pool, addrA, addrB, size)         \
       {unsigned int _qzz_res;                                        \
        VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0,                       \
                                   VG_USERREQ__MEMPOOL_CHANGE,        \
                                   pool, addrA, addrB, size, 0);      \
       }
    
    /* Return 1 if a mempool exists, else 0. */
    #define VALGRIND_MEMPOOL_EXISTS(pool)                             \
       __extension__                                                  \
       ({unsigned int _qzz_res;                                       \
        VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0,                       \
                                   VG_USERREQ__MEMPOOL_EXISTS,        \
                                   pool, 0, 0, 0, 0);                 \
        _qzz_res;                                                     \
       })
    
    /* Mark a piece of memory as being a stack. Returns a stack id. */
    #define VALGRIND_STACK_REGISTER(start, end)                       \
       __extension__                                                  \
       ({unsigned int _qzz_res;                                       \
        VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0,                       \
                                   VG_USERREQ__STACK_REGISTER,        \
                                   start, end, 0, 0, 0);              \
        _qzz_res;                                                     \
       })
    
    /* Unmark the piece of memory associated with a stack id as being a
       stack. */
    #define VALGRIND_STACK_DEREGISTER(id)                             \
       {unsigned int _qzz_res;                                        \
        VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0,                       \
                                   VG_USERREQ__STACK_DEREGISTER,      \
                                   id, 0, 0, 0, 0);                   \
       }
    
    /* Change the start and end address of the stack id. */
    #define VALGRIND_STACK_CHANGE(id, start, end)                     \
       {unsigned int _qzz_res;                                        \
        VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0,                       \
                                   VG_USERREQ__STACK_CHANGE,          \
                                   id, start, end, 0, 0);             \
       }
    
    /* Load PDB debug info for Wine PE image_map. */
    #define VALGRIND_LOAD_PDB_DEBUGINFO(fd, ptr, total_size, delta)   \
       {unsigned int _qzz_res;                                        \
        VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0,                       \
                                   VG_USERREQ__LOAD_PDB_DEBUGINFO,    \
                                   fd, ptr, total_size, delta, 0);    \
       }
    
    /* Map a code address to a source file name and line number.  buf64
       must point to a 64-byte buffer in the caller's address space.  The
       result will be dumped in there and is guaranteed to be zero
       terminated.  If no info is found, the first byte is set to zero. */
    #define VALGRIND_MAP_IP_TO_SRCLOC(addr, buf64)                    \
       {unsigned int _qzz_res;                                        \
        VALGRIND_DO_CLIENT_REQUEST(_qzz_res, 0,                       \
                                   VG_USERREQ__MAP_IP_TO_SRCLOC,      \
                                   addr, buf64, 0, 0, 0);             \
       }
    
    
    #undef PLAT_x86_linux
    #undef PLAT_amd64_linux
    #undef PLAT_ppc32_linux
    #undef PLAT_ppc64_linux
    #undef PLAT_arm_linux
    #undef PLAT_ppc32_aix5
    #undef PLAT_ppc64_aix5
    
    #endif   /* __VALGRIND_H */