jseward | 2886b0e | 2004-01-04 03:46:11 +0000 | [diff] [blame] | 1 | |
| 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 | |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 27 | #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 */ |
| 42 | typedef ESZ(Addr) addr_t; |
| 43 | |
| 44 | struct 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 */ |
| 60 | char *argv0; /* the interpreter name */ |
| 61 | char *argv1; /* the args for the interpreter */ |
| 62 | |
| 63 | char **argv; /* the original argv */ |
| 64 | }; |
| 65 | |
| 66 | int do_exec(const char *exe, struct exeinfo *info); |
| 67 | |
| 68 | void foreach_map(int (*fn)(void *start, void *end, |
| 69 | const char *perm, off_t offset, |
| 70 | int maj, int min, int ino)); |
| 71 | void as_pad(void *start, void *end); |
| 72 | void as_unpad(void *start, void *end); |
| 73 | void as_closepadfile(void); |
| 74 | int as_getpadfd(void); |
| 75 | void as_setpadfd(int); |
| 76 | |
| 77 | struct elfinfo |
| 78 | { |
| 79 | ESZ(Ehdr) e; |
| 80 | ESZ(Phdr) *p; |
| 81 | int fd; |
| 82 | }; |
| 83 | |
| 84 | struct elfinfo *readelf(int fd, const char *filename); |
| 85 | ESZ(Addr) mapelf(struct elfinfo *e, ESZ(Addr) base, int setbrk); |
| 86 | |
| 87 | struct ume_auxv |
| 88 | { |
| 89 | int a_type; |
| 90 | union { |
| 91 | void *a_ptr; |
| 92 | int a_val; |
| 93 | void (*a_fcn)(void); |
mueller | 5ed88f2 | 2004-01-06 16:02:29 +0000 | [diff] [blame^] | 94 | } u; |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | struct 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 */ |