From: Nicholas Nethercote Date: Mon, 1 Nov 2004 18:22:05 +0000 (+0000) Subject: - Make find_auxv() word-size independent. X-Git-Tag: svn/VALGRIND_3_0_0~1411 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e0ff83bc39e04bb11a31cf2968a58f331e7cb245;p=thirdparty%2Fvalgrind.git - 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 --- diff --git a/coregrind/ume.c b/coregrind/ume.c index bc973a8bb2..aedbbadfe6 100644 --- a/coregrind/ume.c +++ b/coregrind/ume.c @@ -115,19 +115,19 @@ void foreach_map(int (*fn)(char *start, char *end, /*--- 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 a015ff07d8..873b930367 100644 --- a/coregrind/ume.h +++ b/coregrind/ume.h @@ -35,6 +35,8 @@ #include #include +#include "basic_types.h" + /*------------------------------------------------------------*/ /*--- General stuff ---*/ /*------------------------------------------------------------*/ @@ -104,7 +106,7 @@ struct ume_auxv } 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 cbe991f4c9..d7b4f00493 100644 --- a/coregrind/vg_main.c +++ b/coregrind/vg_main.c @@ -362,7 +362,7 @@ static void newpid(ThreadId unused) /* 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 f9974627b5..aba50fe518 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -9,6 +9,7 @@ EXTRA_DIST = \ 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 0000000000..07643151b4 --- /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 5830494c8b..34a135eb1d 100644 --- a/include/tool.h.base +++ b/include/tool.h.base @@ -34,50 +34,11 @@ #include /* ANSI varargs stuff */ #include /* 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 84ca3910e1..dc9acadbd1 100644 --- a/memcheck/tests/vgtest_ume.c +++ b/memcheck/tests/vgtest_ume.c @@ -51,7 +51,7 @@ static void test__find_auxv(void) 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 @@ static void test__find_auxv(void) 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 d6290424d3..354a5c65d5 100644 --- a/valgrind.spec.in +++ b/valgrind.spec.in @@ -36,6 +36,7 @@ make install DESTDIR=$RPM_BUILD_ROOT /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