- Make find_auxv() word-size independent.
- Introduced a new file, basic_types.h, for the basic types (eg. Int, Word).


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2896 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/ume.c b/coregrind/ume.c
index bc973a8..aedbbad 100644
--- a/coregrind/ume.c
+++ b/coregrind/ume.c
@@ -115,19 +115,19 @@
 /*--- Finding auxv on the stack                            ---*/
 /*------------------------------------------------------------*/
 
-struct ume_auxv *find_auxv(int *esp)
+struct ume_auxv *find_auxv(UWord* sp)
 {
-   esp++;			/* skip argc */
+   sp++;                // skip argc (Nb: is word-sized, not int-sized!)
 
-   while(*esp != 0)		/* skip argv */
-      esp++;
-   esp++;
+   while (*sp != 0)     // skip argv
+      sp++;
+   sp++;
 
-   while(*esp != 0)		/* skip env */
-      esp++;
-   esp++;
+   while (*sp != 0)     // skip env
+      sp++;
+   sp++;
    
-   return (struct ume_auxv *)esp;
+   return (struct ume_auxv *)sp;
 }
 
 /*------------------------------------------------------------*/
diff --git a/coregrind/ume.h b/coregrind/ume.h
index a015ff0..873b930 100644
--- a/coregrind/ume.h
+++ b/coregrind/ume.h
@@ -35,6 +35,8 @@
 #include <elf.h>
 #include <sys/types.h>
 
+#include "basic_types.h"
+
 /*------------------------------------------------------------*/
 /*--- General stuff                                        ---*/
 /*------------------------------------------------------------*/
@@ -104,7 +106,7 @@
    } u;
 };
 
-struct ume_auxv *find_auxv(int *orig_esp);
+struct ume_auxv *find_auxv(UWord* orig_esp);
 
 /* Our private auxv entries */
 #define AT_UME_PADFD	0xff01	/* padding file fd */
diff --git a/coregrind/vg_main.c b/coregrind/vg_main.c
index cbe991f..d7b4f00 100644
--- a/coregrind/vg_main.c
+++ b/coregrind/vg_main.c
@@ -362,7 +362,7 @@
 /* Look for our AUXV table */
 int scan_auxv(void* init_sp)
 {
-   const struct ume_auxv *auxv = find_auxv((int *)init_sp);
+   const struct ume_auxv *auxv = find_auxv((UWord*)init_sp);
    int padfile = -1, found = 0;
 
    for (; auxv->a_type != AT_NULL; auxv++)
diff --git a/include/Makefile.am b/include/Makefile.am
index f997462..aba50fe 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -9,6 +9,7 @@
 incincdir = $(includedir)/valgrind
 
 incinc_HEADERS = \
+	basic_types.c \
 	tool.h \
 	tool_asm.h \
 	valgrind.h \
diff --git a/include/basic_types.h b/include/basic_types.h
new file mode 100644
index 0000000..0764315
--- /dev/null
+++ b/include/basic_types.h
@@ -0,0 +1,72 @@
+
+/*--------------------------------------------------------------------*/
+/*--- Basic types                                    basic_types.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+   This file is part of Valgrind, an extensible x86 protected-mode
+   emulator for monitoring program execution on x86-Unixes.
+
+   Copyright (C) 2000-2004 Julian Seward 
+      jseward@acm.org
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307, USA.
+
+   The GNU General Public License is contained in the file COPYING.
+*/
+
+#ifndef __BASIC_TYPES_H
+#define __BASIC_TYPES_H
+
+/* ---------------------------------------------------------------------
+   Basic types
+   ------------------------------------------------------------------ */
+
+// By choosing the right types, we can get these right for 32-bit and 64-bit
+// platforms without having to do any conditional compilation or anything.
+//
+// Size in bits on:                          32-bit archs   64-bit archs
+//                                           ------------   ------------
+typedef unsigned char          UChar;     //  8              8
+typedef unsigned short         UShort;    // 16             16
+typedef unsigned int           UInt;      // 32             32
+typedef unsigned long          UWord;     // 32             64
+typedef unsigned long long     ULong;     // 64             64
+
+typedef signed char            Char;      //  8              8
+typedef signed short           Short;     // 16             16
+typedef signed int             Int;       // 32             32
+typedef signed long            Word;      // 32             64
+typedef signed long long       Long;      // 64             64
+
+typedef UWord                  Addr;      // 32             64
+
+typedef UChar                  Bool;      //  8              8
+#define False                  ((Bool)0)
+#define True                   ((Bool)1)
+
+/* ---------------------------------------------------------------------
+   Where to send bug reports to.
+   ------------------------------------------------------------------ */
+
+#define VG_BUGS_TO "valgrind.kde.org"
+
+
+#endif /* __BASIC_TYPES_H */
+
+/*--------------------------------------------------------------------*/
+/*--- end                                                          ---*/
+/*--------------------------------------------------------------------*/
diff --git a/include/tool.h.base b/include/tool.h.base
index 5830494..34a135e 100644
--- a/include/tool.h.base
+++ b/include/tool.h.base
@@ -34,50 +34,11 @@
 #include <stdarg.h>       /* ANSI varargs stuff  */
 #include <setjmp.h>       /* for jmp_buf         */
 
+#include "basic_types.h"
 #include "tool_asm.h"           // asm stuff
-
-/*====================================================================*/
-/*=== Basic types                                                  ===*/
-/*====================================================================*/
-
-// By choosing the right types, we can get these right for 32-bit and 64-bit
-// platforms without having to do any conditional compilation or anything.
-//
-// Size in bits on:                          32-bit archs   64-bit archs
-//                                           ------------   ------------
-typedef unsigned char          UChar;     //  8              8
-typedef unsigned short         UShort;    // 16             16
-typedef unsigned int           UInt;      // 32             32
-typedef unsigned long          UWord;     // 32             64
-typedef unsigned long long     ULong;     // 64             64
-
-typedef signed char            Char;      //  8              8
-typedef signed short           Short;     // 16             16
-typedef signed int             Int;       // 32             32
-typedef signed long            Word;      // 32             64
-typedef signed long long       Long;      // 64             64
-
-typedef UWord                  Addr;      // 32             64
-
-typedef UChar                  Bool;      //  8              8
-#define False                  ((Bool)0)
-#define True                   ((Bool)1)
-
-/* ---------------------------------------------------------------------
-   Now the basic types are set up, we can haul in the kernel-interface
-   definitions and tool_arch.h
-   ------------------------------------------------------------------ */
-
 #include "tool_arch.h"          // arch-specific tool stuff
 #include "vki.h"
 
-/* ---------------------------------------------------------------------
-   Where to send bug reports to.
-   ------------------------------------------------------------------ */
-
-#define VG_BUGS_TO "valgrind.kde.org"
-
-
 /*====================================================================*/
 /*=== Build options and table sizes.                               ===*/
 /*====================================================================*/
diff --git a/memcheck/tests/vgtest_ume.c b/memcheck/tests/vgtest_ume.c
index 84ca391..dc9acad 100644
--- a/memcheck/tests/vgtest_ume.c
+++ b/memcheck/tests/vgtest_ume.c
@@ -51,7 +51,7 @@
    assert(init_sp != NULL);
    
    fprintf(stderr, "Calling find_auxv()\n");
-   auxv = find_auxv((int*)init_sp);
+   auxv = find_auxv((UWord*)init_sp);
 
    // Check the auxv value looks sane
    assert((void*)auxv > (void*)init_sp);
@@ -65,6 +65,7 @@
          break;
    
       default:
+         fprintf(stderr, "auxv->a_type = %d\n", auxv->a_type);
          assert(0);
       }
    }
diff --git a/valgrind.spec.in b/valgrind.spec.in
index d629042..354a5c6 100644
--- a/valgrind.spec.in
+++ b/valgrind.spec.in
@@ -36,6 +36,7 @@
 /usr/include/valgrind/valgrind.h
 /usr/include/valgrind/memcheck.h
 /usr/include/valgrind/helgrind.h
+/usr/include/valgrind/basic_types.h
 /usr/include/valgrind/tool.h
 /usr/include/valgrind/tool_asm.h
 /usr/include/valgrind/vg_skin.h