- 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
This commit is contained in:
Nicholas Nethercote 2004-11-01 18:22:05 +00:00
parent 6318f7c944
commit e0ff83bc39
8 changed files with 90 additions and 52 deletions

View File

@ -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;
}
/*------------------------------------------------------------*/

View File

@ -35,6 +35,8 @@
#include <elf.h>
#include <sys/types.h>
#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 */

View File

@ -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++)

View File

@ -9,6 +9,7 @@ EXTRA_DIST = \
incincdir = $(includedir)/valgrind
incinc_HEADERS = \
basic_types.c \
tool.h \
tool_asm.h \
valgrind.h \

72
include/basic_types.h Normal file
View File

@ -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 ---*/
/*--------------------------------------------------------------------*/

View File

@ -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. ===*/
/*====================================================================*/

View File

@ -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);
}
}

View File

@ -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