blob: 76f4ef5514f22ca01c2ebfcc591845df6f214091 [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
nethercote969ecf12004-10-13 17:29:01 +000042void foreach_map(int (*fn)(char *start, char *end,
43 const char *perm, off_t offset,
44 int maj, int min, int ino, void* extra),
45 void* extra);
46
fitzhardinge7e343cd2003-12-16 02:14:00 +000047#if ELFSZ == 64
48#define ESZ(x) Elf64_##x
49#elif ELFSZ == 32
50#define ESZ(x) Elf32_##x
51#else
52#error ELFSZ needs to ==32 or ==64
53#endif
54
55/* Integer type the same size as a pointer */
56typedef ESZ(Addr) addr_t;
57
nethercote107e1c02004-10-13 17:55:31 +000058extern void *ume_exec_esp; /* esp on entry at exec time */
59
60// Jump to a new 'ip' with the stack 'sp'.
61void jmp_with_stack(addr_t ip, addr_t sp) __attribute__((noreturn));
62
63void foreach_map(int (*fn)(char *start, char *end,
64 const char *perm, off_t offset,
65 int maj, int min, int ino, void* extra),
66 void* extra);
67
68/*------------------------------------------------------------*/
69/*--- Loading ELF files ---*/
70/*------------------------------------------------------------*/
71
nethercoteea147e72004-07-26 15:43:57 +000072// Info needed to load and run a program. IN/INOUT/OUT refers to the
73// inputs/outputs of do_exec().
fitzhardinge7e343cd2003-12-16 02:14:00 +000074struct exeinfo
75{
nethercoteea147e72004-07-26 15:43:57 +000076 addr_t map_base; // IN: if non-zero, base address of mappings
77 char** argv; // IN: the original argv
fitzhardinge7e343cd2003-12-16 02:14:00 +000078
nethercote1fe54502004-07-26 15:28:33 +000079 addr_t exe_base; // INOUT: lowest (allowed) address of exe
80 addr_t exe_end; // INOUT: highest (allowed) address
fitzhardinge7e343cd2003-12-16 02:14:00 +000081
nethercoteea147e72004-07-26 15:43:57 +000082 addr_t phdr; // OUT: address phdr was mapped at
83 int phnum; // OUT: number of phdrs
84 addr_t interp_base; // OUT: where interpreter (ld.so) was mapped
85 addr_t entry; // OUT: entrypoint in main executable
86 addr_t init_eip; // OUT: initial eip
87 addr_t brkbase; // OUT: base address of brk segment
fitzhardinge7e343cd2003-12-16 02:14:00 +000088
nethercote1fe54502004-07-26 15:28:33 +000089 // These are the extra args added by #! scripts
nethercoteea147e72004-07-26 15:43:57 +000090 char* interp_name; // OUT: the interpreter name
91 char* interp_args; // OUT: the args for the interpreter
fitzhardinge7e343cd2003-12-16 02:14:00 +000092};
93
nethercoteea147e72004-07-26 15:43:57 +000094// Does everything short of actually running 'exe': finds the file,
95// checks execute permissions, sets up interpreter if program is a script,
96// reads headers, maps file into memory, and returns important info about
97// the program.
fitzhardinge7e343cd2003-12-16 02:14:00 +000098int do_exec(const char *exe, struct exeinfo *info);
99
nethercote1fe54502004-07-26 15:28:33 +0000100/*------------------------------------------------------------*/
nethercote1fe54502004-07-26 15:28:33 +0000101/*--- Finding and dealing with auxv ---*/
102/*------------------------------------------------------------*/
fitzhardinge7e343cd2003-12-16 02:14:00 +0000103
104struct ume_auxv
105{
106 int a_type;
107 union {
108 void *a_ptr;
109 int a_val;
110 void (*a_fcn)(void);
mueller5ed88f22004-01-06 16:02:29 +0000111 } u;
fitzhardinge7e343cd2003-12-16 02:14:00 +0000112};
113
114struct ume_auxv *find_auxv(int *orig_esp);
115
116/* Our private auxv entries */
117#define AT_UME_PADFD 0xff01 /* padding file fd */
118#define AT_UME_EXECFD 0xff02 /* stage1 executable fd */
119
120#endif /* _COREGRIND_UME_H */
nethercote1fe54502004-07-26 15:28:33 +0000121
122/*--------------------------------------------------------------------*/
123/*--- end ume.h ---*/
124/*--------------------------------------------------------------------*/