blob: 4762f9869965920becf68d9c019cdd96efb5f4d6 [file] [log] [blame]
jseward2886b0e2004-01-04 03:46:11 +00001
2/*
3 This file is part of Valgrind, an extensible x86 protected-mode
4 emulator for monitoring program execution on x86-Unixes.
5
6 Copyright (C) 2000-2004 Julian Seward
7 jseward@acm.org
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 02111-1307, USA.
23
24 The GNU General Public License is contained in the file COPYING.
25*/
26
fitzhardinge7e343cd2003-12-16 02:14:00 +000027#ifndef _COREGRIND_UME_H
28#define _COREGRIND_UME_H
29
30#include <elf.h>
31#include <sys/types.h>
32
33#if ELFSZ == 64
34#define ESZ(x) Elf64_##x
35#elif ELFSZ == 32
36#define ESZ(x) Elf32_##x
37#else
38#error ELFSZ needs to ==32 or ==64
39#endif
40
41/* Integer type the same size as a pointer */
42typedef ESZ(Addr) addr_t;
43
44struct exeinfo
45{
fitzhardinge7e343cd2003-12-16 02:14:00 +000046 addr_t map_base; /* INPUT: if non-zero, base address of mappings */
47
48 addr_t exe_base; /* INOUT: lowest (allowed) address of exe */
49 addr_t exe_end; /* INOUT: highest (allowed) address */
50
51 addr_t phdr; /* address phdr was mapped at */
52 int phnum; /* number of phdrs */
53 addr_t interp_base; /* where interpreter (ld.so) was mapped */
54 addr_t entry; /* entrypoint in main executable */
55 addr_t init_eip; /* initial eip */
56 addr_t brkbase; /* base address of brk segment */
57
58 /* these are the extra args added by #! scripts */
nethercote71980f02004-01-24 18:18:54 +000059 char *argv0; /* INPUT: the interpreter name */
60 char *argv1; /* INPUT: the args for the interpreter */
fitzhardinge7e343cd2003-12-16 02:14:00 +000061
nethercote71980f02004-01-24 18:18:54 +000062 char **argv; /* INPUT: the original argv */
fitzhardinge7e343cd2003-12-16 02:14:00 +000063};
64
65int do_exec(const char *exe, struct exeinfo *info);
66
67void foreach_map(int (*fn)(void *start, void *end,
68 const char *perm, off_t offset,
69 int maj, int min, int ino));
70void as_pad(void *start, void *end);
71void as_unpad(void *start, void *end);
72void as_closepadfile(void);
73int as_getpadfd(void);
74void as_setpadfd(int);
75
76struct elfinfo
77{
78 ESZ(Ehdr) e;
79 ESZ(Phdr) *p;
80 int fd;
81};
82
83struct elfinfo *readelf(int fd, const char *filename);
fitzhardingeb50068f2004-02-24 23:42:55 +000084ESZ(Addr) mapelf(struct elfinfo *e, ESZ(Addr) base);
fitzhardinge7e343cd2003-12-16 02:14:00 +000085
86struct ume_auxv
87{
88 int a_type;
89 union {
90 void *a_ptr;
91 int a_val;
92 void (*a_fcn)(void);
mueller5ed88f22004-01-06 16:02:29 +000093 } u;
fitzhardinge7e343cd2003-12-16 02:14:00 +000094};
95
96struct ume_auxv *find_auxv(int *orig_esp);
97
98/* Our private auxv entries */
99#define AT_UME_PADFD 0xff01 /* padding file fd */
100#define AT_UME_EXECFD 0xff02 /* stage1 executable fd */
101
102#endif /* _COREGRIND_UME_H */