blob: 286e3560b68c59fac7f14f7c153cc9c41af77f89 [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{
46 int setbrk; /* INPUT: if true, set the brk segment base */
47 addr_t map_base; /* INPUT: if non-zero, base address of mappings */
48
49 addr_t exe_base; /* INOUT: lowest (allowed) address of exe */
50 addr_t exe_end; /* INOUT: highest (allowed) address */
51
52 addr_t phdr; /* address phdr was mapped at */
53 int phnum; /* number of phdrs */
54 addr_t interp_base; /* where interpreter (ld.so) was mapped */
55 addr_t entry; /* entrypoint in main executable */
56 addr_t init_eip; /* initial eip */
57 addr_t brkbase; /* base address of brk segment */
58
59 /* these are the extra args added by #! scripts */
nethercote71980f02004-01-24 18:18:54 +000060 char *argv0; /* INPUT: the interpreter name */
61 char *argv1; /* INPUT: the args for the interpreter */
fitzhardinge7e343cd2003-12-16 02:14:00 +000062
nethercote71980f02004-01-24 18:18:54 +000063 char **argv; /* INPUT: the original argv */
fitzhardinge7e343cd2003-12-16 02:14:00 +000064};
65
66int do_exec(const char *exe, struct exeinfo *info);
67
68void foreach_map(int (*fn)(void *start, void *end,
69 const char *perm, off_t offset,
70 int maj, int min, int ino));
71void as_pad(void *start, void *end);
72void as_unpad(void *start, void *end);
73void as_closepadfile(void);
74int as_getpadfd(void);
75void as_setpadfd(int);
76
77struct elfinfo
78{
79 ESZ(Ehdr) e;
80 ESZ(Phdr) *p;
81 int fd;
82};
83
84struct elfinfo *readelf(int fd, const char *filename);
85ESZ(Addr) mapelf(struct elfinfo *e, ESZ(Addr) base, int setbrk);
86
87struct ume_auxv
88{
89 int a_type;
90 union {
91 void *a_ptr;
92 int a_val;
93 void (*a_fcn)(void);
mueller5ed88f22004-01-06 16:02:29 +000094 } u;
fitzhardinge7e343cd2003-12-16 02:14:00 +000095};
96
97struct ume_auxv *find_auxv(int *orig_esp);
98
99/* Our private auxv entries */
100#define AT_UME_PADFD 0xff01 /* padding file fd */
101#define AT_UME_EXECFD 0xff02 /* stage1 executable fd */
102
103#endif /* _COREGRIND_UME_H */