From: Julian Seward Date: Sun, 10 Jul 2005 00:55:26 +0000 (+0000) Subject: Get rid of endianness assumptions in the PRRAn macro, which is X-Git-Tag: svn/VALGRIND_3_0_0~175 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cc206745a812cd625f59d92f10a6d84a86e7241b;p=thirdparty%2Fvalgrind.git Get rid of endianness assumptions in the PRRAn macro, which is important for doing checks of scalar syscall args. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@4143 --- diff --git a/coregrind/m_syswrap/priv_types_n_macros.h b/coregrind/m_syswrap/priv_types_n_macros.h index f85cfae837..140a0c576f 100644 --- a/coregrind/m_syswrap/priv_types_n_macros.h +++ b/coregrind/m_syswrap/priv_types_n_macros.h @@ -252,6 +252,7 @@ static inline UWord getRES ( SyscallStatus* st ) { } + /* Set the current result status/value in various ways. */ #define SET_STATUS_Success(zzz) \ do { status->what = SsSuccess; \ @@ -281,6 +282,7 @@ static inline UWord getRES ( SyscallStatus* st ) { VG_(printf)(format, ## args) + /* Macros used to tell tools about uses of scalar arguments. Note, these assume little-endianness. These can only be used in pre-wrappers, and they refer to the layout parameter passed in. */ @@ -288,12 +290,58 @@ static inline UWord getRES ( SyscallStatus* st ) { PRRSN == "pre-register-read-syscall" */ +/* Tell the tool that the syscall number is being read. */ #define PRRSN \ VG_(tdict).track_pre_reg_read(Vg_CoreSysCall, tid, "(syscallno)", \ layout->o_sysno, sizeof(UWord)); -#define PRRAn(n,s,t,a) \ - VG_(tdict).track_pre_reg_read(Vg_CoreSysCall, tid, s"("#a")", \ - layout->o_arg##n, sizeof(t)); + + +/* PRRAn: Tell the tool that the register holding the n-th syscall + argument is being read, at type 't' which must be at most the size + of a register but can be smaller. In the latter case we need to be + careful about endianness. */ + +/* little-endian: the part of the guest state being read is + let here = offset_of_reg + in [here .. here + sizeof(t) - 1] + since the least significant parts of the guest register are stored + in memory at the lowest address. +*/ +#define PRRAn_LE(n,s,t,a) \ + do { \ + Int here = layout->o_arg##n; \ + vg_assert(sizeof(t) <= sizeof(UWord)); \ + VG_(tdict).track_pre_reg_read( \ + Vg_CoreSysCall, tid, s"("#a")", \ + here, sizeof(t) \ + ); \ + } while (0) + +/* big-endian: the part of the guest state being read is + let next = offset_of_reg + sizeof(reg) + in [next - sizeof(t) .. next - 1] + since the least significant parts of the guest register are stored + in memory at the highest address. +*/ +#define PRRAn_BE(n,s,t,a) \ + do { \ + Int next = layout->o_arg##n + sizeof(UWord); \ + vg_assert(sizeof(t) <= sizeof(UWord)); \ + VG_(tdict).track_pre_reg_read( \ + Vg_CoreSysCall, tid, s"("#a")", \ + next-sizeof(t), sizeof(t) \ + ); \ + } while (0) + +#if defined(VG_BIGENDIAN) +# define PRRAn(n,s,t,a) PRRAn_BE(n,s,t,a) +#elif defined(VG_LITTLEENDIAN) +# define PRRAn(n,s,t,a) PRRAn_LE(n,s,t,a) +#else +# error "Unknown endianness" +#endif + + #define PRE_REG_READ0(tr, s) \ if (VG_(tdict).track_pre_reg_read) { \ PRRSN; \