|
From: Yakir B. S. <Yak...@mo...> - 2014-12-24 15:09:02
|
Hi,
I moving my code from 32bit to 64bit and the pointers changed from 4
bytes to 8 bytes.
I try to you valgrind function VALGRIND_DO_CLIENT_REQUEST .
my code send to this function void*.
It failed on cast from 8 bytes of pointer to unsigned int (4 bytes).
my code :
void markAsUnaccessible(void* address, size_t size)
{
VALGRIND3_DISCARD(VALGRIND3_MAKE_NOACCESS(address,size));
}
#define VALGRIND3_DISCARD(_qzz_blkindex) \
(__extension__ ({unsigned int _qzz_res; \
VALGRIND3_DO_CLIENT_REQUEST(_qzz_res, 0 /* default return */, \
VG3_USERREQ__DISCARD, \
0, _qzz_blkindex, 0, 0, 0); \
_qzz_res; \
}))
#define VALGRIND3_DO_CLIENT_REQUEST( \
_zzq_rlval, _zzq_default, _zzq_request, \
_zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
{ volatile unsigned int _zzq_args[6]; \
volatile unsigned int _zzq_result; \
_zzq_args[0] = (unsigned int)(_zzq_request); \
_zzq_args[1] = (unsigned int)(_zzq_arg1); \
_zzq_args[2] = (unsigned int)(_zzq_arg2); \
_zzq_args[3] = (unsigned int)(_zzq_arg3); \
_zzq_args[4] = (unsigned int)(_zzq_arg4); \
_zzq_args[5] = (unsigned int)(_zzq_arg5); \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* %EDX = client_request ( %EAX ) */ \
"xchgl %%ebx,%%ebx" \
: "=d" (_zzq_result) \
: "a" (&_zzq_args[0]), "0" (_zzq_default) \
: "cc", "memory" \
); \
_zzq_rlval = _zzq_result; \
}
can you help?
I try find solution over the internet and i see that many users have -
VALGRIND_DO_CLIENT_REQUEST
as this code :
#define VALGRIND_DO_CLIENT_REQUEST( \
_zzq_rlval, _zzq_default, _zzq_request, \
_zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
- { volatile unsigned long long int _zzq_args[6]; \
- volatile unsigned long long int _zzq_result; \
- _zzq_args[0] = (unsigned long long int)(_zzq_request); \
- _zzq_args[1] = (unsigned long long int)(_zzq_arg1); \
- _zzq_args[2] = (unsigned long long int)(_zzq_arg2); \
- _zzq_args[3] = (unsigned long long int)(_zzq_arg3); \
- _zzq_args[4] = (unsigned long long int)(_zzq_arg4); \
- _zzq_args[5] = (unsigned long long int)(_zzq_arg5); \
+ { volatile uint64_t _zzq_args[6]; \
+ volatile uint64_t _zzq_result; \
+ _zzq_args[0] = (uint64_t)(_zzq_request); \
+ _zzq_args[1] = (uint64_t)(_zzq_arg1); \
+ _zzq_args[2] = (uint64_t)(_zzq_arg2); \
+ _zzq_args[3] = (uint64_t)(_zzq_arg3); \
+ _zzq_args[4] = (uint64_t)(_zzq_arg4); \
+ _zzq_args[5] = (uint64_t)(_zzq_arg5); \
but this only handle 64bit, i need solulition that work both ways when i
compile to 32bit/64bit executable
thanks,
yakir
This mail was sent via Mail-SeCure system.
************************************************************************************
This footnote confirms that this email message has been scanned by
PineApp Mail-SeCure for the presence of malicious code, vandals & computer viruses.
************************************************************************************
|
|
From: John R. <jr...@bi...> - 2014-12-24 16:20:42
|
> #define VALGRIND_DO_CLIENT_REQUEST( \
> _zzq_rlval, _zzq_default, _zzq_request, \
> _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
> - { volatile unsigned long long int _zzq_args[6]; \
> - volatile unsigned long long int _zzq_result; \
> - _zzq_args[0] = (unsigned long long int)(_zzq_request); \
> - _zzq_args[1] = (unsigned long long int)(_zzq_arg1); \
[[snip]]
> + { volatile uint64_t _zzq_args[6]; \
> + volatile uint64_t _zzq_result; \
> + _zzq_args[0] = (uint64_t)(_zzq_request); \
> + _zzq_args[1] = (uint64_t)(_zzq_arg1); \
[[snip]]
>
> but this only handle 64bit, i need solulition that work both ways when i compile to 32bit/64bit executable
Use "void *" to handle the native width:
volatile void *_zzq_args[6];
volatile void *_zzq_result;
_zzq_args[0] = (void *)(unsigned long)(_zzq_request);
_zzq_args[1] = (void *)(unsigned long)(_zzq_arg1);
[[snip]]
The cast to "(unsigned long)" is required to avoid the complaint from gcc:
cast to pointer from integer of different size [-Wint-to-pointer-cast]
when -m64 and _zzq_arg1 is only an 'int'. This solution depends on
sizeof(void *) <= sizeof(unsigned long)
for which the only important exception is Microsoft C in 64-bit mode.
[MSVC chooses 4==sizeof(long) in *ALL* cases.]
Note that the producer and the consumer must agree on the actual type
of each argument, particularly 'unsigned' or not, and 'long' or not.
Otherwise it is impossible to choose a type for casting the pass-through
arguments that conveys the correct value in all cases of mismatched
expectations.
|
|
From: Philippe W. <phi...@sk...> - 2014-12-29 01:13:58
|
On Wed, 2014-12-24 at 16:42 +0200, Yakir Ben Senyur wrote:
> Hi,
> I moving my code from 32bit to 64bit and the pointers changed from 4
> bytes to 8 bytes.
> I try to you valgrind function VALGRIND_DO_CLIENT_REQUEST .
> my code send to this function void*.
> It failed on cast from 8 bytes of pointer to unsigned int (4 bytes).
> my code :
> void markAsUnaccessible(void* address, size_t size)
> {
> VALGRIND3_DISCARD(VALGRIND3_MAKE_NOACCESS(address,size));
> }
It looks like you are having problems because of local
redefinitions of valgrind requests.
The usual way to do is to just include valgrind.h or memcheck.h or ...
and then use the requests defined in these files.
E.g.
...
char magic_foople_zone[0x1000];
...
(void) VALGRIND_MAKE_MEM_NOACCESS(magic_foople_zone, 0x1000)
A.o., the valgrind regression test testing such requests
have no special thing to do to compile cleanly in 32 bits or 64 bits.
Using the include files provided in valgrind will also work in the
(unlikely) case the 'magic' instructions of a client request would
change in a newer valgrind version.
Philippe
|