|
From: Jakub B. <ber...@gm...> - 2016-10-21 21:26:46
|
Hello,
is it possible to pass more than 3 parameters to (dirty) helper calls
during instrumentation?
When I used VG_REGPARM(4), Valgrind crashed on assert that requires the
regparm count to be >=0 and <= 3 (I understand why is it so, it's probably
hard to pass more than 3 parameters in registers on x86 etc.).
I tried instead to create a vector of several integers and add it to the
argument vector, but Valgrind didn't like that either (it crashed during
ppIRExpr).
// this didn't work
IRExpr** args = mkIRExprVec_3(
mkIRExpr_HWord(exprType),
addr,
mkIRExprVec_2(mkIRExpr_HWord(i1), mkIRExpr_HWord(i2))
);
IRDirty* di = unsafeIRDirty_0_N(3, name, VG_(fnptr_to_fnentry)(fn), args);
Am I doing it wrong or is this something that is not supported at all in
Valgrind?
Thanks,
Kuba Beranek
|
|
From: Julian S. <js...@ac...> - 2016-10-22 05:16:19
|
On 21/10/16 23:26, Jakub Beránek wrote: > Hello, > > is it possible to pass more than 3 parameters to (dirty) helper calls > during instrumentation? Yes. amd64 (64-bit x86) supports up to 6 word sized args and x86 (32-bit x86) supports at least 5. Look for the call to x86g_calculate_condition made in VEX/priv/guest_x86_toIR.c. > When I used VG_REGPARM(4), Valgrind crashed on assert that requires the > regparm count to be >=0 and <= 3 (I understand why is it so, it's probably > hard to pass more than 3 parameters in registers on x86 etc.). VG_REGPARM says how many args are to be passed in registers on x86-ELF, up to a maximum of 3. You can't set it higher than 3. That doesn't mean that you can't pass more than 3 args, though. > I tried instead to create a vector of several integers and add it to the > argument vector, but Valgrind didn't like that either (it crashed during > ppIRExpr). Yes, that won't work. You need to create a single flat vector containing all the args you want. If you want this to work on all platforms, I think you need to keep to a maximum of 4 word-sized args, since at least for arm32, the back end only knows how to generate code for calls with at most 4 word sized args. J |
|
From: Jakub B. <ber...@gm...> - 2016-10-23 23:13:20
|
Thank you, using VG_REGPARM(3) and passing 4 parameters did the trick. Valgrind is a great tool, thanks for making it :-) All the best Kuba Beranek Dne 22. 10. 2016 7:16 napsal uživatel "Julian Seward" <js...@ac...>: > On 21/10/16 23:26, Jakub Beránek wrote: > > Hello, > > > > is it possible to pass more than 3 parameters to (dirty) helper calls > > during instrumentation? > > Yes. amd64 (64-bit x86) supports up to 6 word sized args and x86 (32-bit > x86) supports at least 5. Look for the call to x86g_calculate_condition > made in VEX/priv/guest_x86_toIR.c. > > > When I used VG_REGPARM(4), Valgrind crashed on assert that requires the > > regparm count to be >=0 and <= 3 (I understand why is it so, it's > probably > > hard to pass more than 3 parameters in registers on x86 etc.). > > VG_REGPARM says how many args are to be passed in registers on x86-ELF, > up to a maximum of 3. You can't set it higher than 3. That doesn't mean > that you can't pass more than 3 args, though. > > > I tried instead to create a vector of several integers and add it to the > > argument vector, but Valgrind didn't like that either (it crashed during > > ppIRExpr). > > Yes, that won't work. You need to create a single flat vector containing > all the args you want. > > If you want this to work on all platforms, I think you need to keep to a > maximum of 4 word-sized args, since at least for arm32, the back end only > knows how to generate code for calls with at most 4 word sized args. > > J > > |