]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Get rid of endianness assumptions in the PRRAn macro, which is
authorJulian Seward <jseward@acm.org>
Sun, 10 Jul 2005 00:55:26 +0000 (00:55 +0000)
committerJulian Seward <jseward@acm.org>
Sun, 10 Jul 2005 00:55:26 +0000 (00:55 +0000)
important for doing checks of scalar syscall args.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@4143

coregrind/m_syswrap/priv_types_n_macros.h

index f85cfae8372123afddbfe27e8e2a254ab623bc30..140a0c576f8cc37884a9f7140b739188573e23ed 100644 (file)
@@ -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; \