blob: 118119e79d15bfc7a61d9165172851fd83166068 [file] [log] [blame]
jseward2886b0e2004-01-04 03:46:11 +00001
nethercote1fe54502004-07-26 15:28:33 +00002/*--------------------------------------------------------------------*/
3/*--- A header file used by both stage1 and stage2. ---*/
4/*--- ume.h ---*/
5/*--------------------------------------------------------------------*/
6
jseward2886b0e2004-01-04 03:46:11 +00007/*
8 This file is part of Valgrind, an extensible x86 protected-mode
9 emulator for monitoring program execution on x86-Unixes.
10
11 Copyright (C) 2000-2004 Julian Seward
12 jseward@acm.org
13
14 This program is free software; you can redistribute it and/or
15 modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation; either version 2 of the
17 License, or (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27 02111-1307, USA.
28
29 The GNU General Public License is contained in the file COPYING.
30*/
31
fitzhardinge7e343cd2003-12-16 02:14:00 +000032#ifndef _COREGRIND_UME_H
33#define _COREGRIND_UME_H
34
35#include <elf.h>
36#include <sys/types.h>
37
nethercote1fe54502004-07-26 15:28:33 +000038/*------------------------------------------------------------*/
39/*--- General stuff ---*/
40/*------------------------------------------------------------*/
41
fitzhardinge7e343cd2003-12-16 02:14:00 +000042#if ELFSZ == 64
43#define ESZ(x) Elf64_##x
44#elif ELFSZ == 32
45#define ESZ(x) Elf32_##x
46#else
47#error ELFSZ needs to ==32 or ==64
48#endif
49
50/* Integer type the same size as a pointer */
51typedef ESZ(Addr) addr_t;
52
nethercote1fe54502004-07-26 15:28:33 +000053/*------------------------------------------------------------*/
54/*--- Loading ELF files ---*/
55/*------------------------------------------------------------*/
56
fitzhardinge7e343cd2003-12-16 02:14:00 +000057struct exeinfo
58{
nethercote1fe54502004-07-26 15:28:33 +000059 addr_t map_base; // INPUT: if non-zero, base address of mappings
60 char** argv; // INPUT: the original argv
fitzhardinge7e343cd2003-12-16 02:14:00 +000061
nethercote1fe54502004-07-26 15:28:33 +000062 addr_t exe_base; // INOUT: lowest (allowed) address of exe
63 addr_t exe_end; // INOUT: highest (allowed) address
fitzhardinge7e343cd2003-12-16 02:14:00 +000064
nethercote1fe54502004-07-26 15:28:33 +000065 addr_t phdr; // address phdr was mapped at
66 int phnum; // number of phdrs
67 addr_t interp_base; // where interpreter (ld.so) was mapped
68 addr_t entry; // entrypoint in main executable
69 addr_t init_eip; // initial eip
70 addr_t brkbase; // base address of brk segment
fitzhardinge7e343cd2003-12-16 02:14:00 +000071
nethercote1fe54502004-07-26 15:28:33 +000072 // These are the extra args added by #! scripts
73 char* argv0; // INPUT: the interpreter name
74 char* argv1; // INPUT: the args for the interpreter
fitzhardinge7e343cd2003-12-16 02:14:00 +000075};
76
77int do_exec(const char *exe, struct exeinfo *info);
78
nethercote1fe54502004-07-26 15:28:33 +000079/*------------------------------------------------------------*/
80/*--- Address space padding ---*/
81/*------------------------------------------------------------*/
82
fitzhardinge7e343cd2003-12-16 02:14:00 +000083void foreach_map(int (*fn)(void *start, void *end,
84 const char *perm, off_t offset,
85 int maj, int min, int ino));
nethercote1fe54502004-07-26 15:28:33 +000086
fitzhardinge7e343cd2003-12-16 02:14:00 +000087void as_pad(void *start, void *end);
88void as_unpad(void *start, void *end);
89void as_closepadfile(void);
90int as_getpadfd(void);
91void as_setpadfd(int);
92
nethercote1fe54502004-07-26 15:28:33 +000093/*------------------------------------------------------------*/
94/*--- Finding and dealing with auxv ---*/
95/*------------------------------------------------------------*/
fitzhardinge7e343cd2003-12-16 02:14:00 +000096
97struct ume_auxv
98{
99 int a_type;
100 union {
101 void *a_ptr;
102 int a_val;
103 void (*a_fcn)(void);
mueller5ed88f22004-01-06 16:02:29 +0000104 } u;
fitzhardinge7e343cd2003-12-16 02:14:00 +0000105};
106
107struct ume_auxv *find_auxv(int *orig_esp);
108
109/* Our private auxv entries */
110#define AT_UME_PADFD 0xff01 /* padding file fd */
111#define AT_UME_EXECFD 0xff02 /* stage1 executable fd */
112
113#endif /* _COREGRIND_UME_H */
nethercote1fe54502004-07-26 15:28:33 +0000114
115/*--------------------------------------------------------------------*/
116/*--- end ume.h ---*/
117/*--------------------------------------------------------------------*/