jseward | 2886b0e | 2004-01-04 03:46:11 +0000 | [diff] [blame] | 1 | |
nethercote | 1fe5450 | 2004-07-26 15:28:33 +0000 | [diff] [blame] | 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- A header file used by both stage1 and stage2. ---*/ |
| 4 | /*--- ume.h ---*/ |
| 5 | /*--------------------------------------------------------------------*/ |
| 6 | |
jseward | 2886b0e | 2004-01-04 03:46:11 +0000 | [diff] [blame] | 7 | /* |
| 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 | |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 32 | #ifndef _COREGRIND_UME_H |
| 33 | #define _COREGRIND_UME_H |
| 34 | |
| 35 | #include <elf.h> |
| 36 | #include <sys/types.h> |
| 37 | |
nethercote | 1fe5450 | 2004-07-26 15:28:33 +0000 | [diff] [blame] | 38 | /*------------------------------------------------------------*/ |
| 39 | /*--- General stuff ---*/ |
| 40 | /*------------------------------------------------------------*/ |
| 41 | |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 42 | #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 */ |
| 51 | typedef ESZ(Addr) addr_t; |
| 52 | |
nethercote | 1fe5450 | 2004-07-26 15:28:33 +0000 | [diff] [blame] | 53 | /*------------------------------------------------------------*/ |
| 54 | /*--- Loading ELF files ---*/ |
| 55 | /*------------------------------------------------------------*/ |
| 56 | |
nethercote | ea147e7 | 2004-07-26 15:43:57 +0000 | [diff] [blame^] | 57 | // Info needed to load and run a program. IN/INOUT/OUT refers to the |
| 58 | // inputs/outputs of do_exec(). |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 59 | struct exeinfo |
| 60 | { |
nethercote | ea147e7 | 2004-07-26 15:43:57 +0000 | [diff] [blame^] | 61 | addr_t map_base; // IN: if non-zero, base address of mappings |
| 62 | char** argv; // IN: the original argv |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 63 | |
nethercote | 1fe5450 | 2004-07-26 15:28:33 +0000 | [diff] [blame] | 64 | addr_t exe_base; // INOUT: lowest (allowed) address of exe |
| 65 | addr_t exe_end; // INOUT: highest (allowed) address |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 66 | |
nethercote | ea147e7 | 2004-07-26 15:43:57 +0000 | [diff] [blame^] | 67 | addr_t phdr; // OUT: address phdr was mapped at |
| 68 | int phnum; // OUT: number of phdrs |
| 69 | addr_t interp_base; // OUT: where interpreter (ld.so) was mapped |
| 70 | addr_t entry; // OUT: entrypoint in main executable |
| 71 | addr_t init_eip; // OUT: initial eip |
| 72 | addr_t brkbase; // OUT: base address of brk segment |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 73 | |
nethercote | 1fe5450 | 2004-07-26 15:28:33 +0000 | [diff] [blame] | 74 | // These are the extra args added by #! scripts |
nethercote | ea147e7 | 2004-07-26 15:43:57 +0000 | [diff] [blame^] | 75 | char* interp_name; // OUT: the interpreter name |
| 76 | char* interp_args; // OUT: the args for the interpreter |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 77 | }; |
| 78 | |
nethercote | ea147e7 | 2004-07-26 15:43:57 +0000 | [diff] [blame^] | 79 | // Does everything short of actually running 'exe': finds the file, |
| 80 | // checks execute permissions, sets up interpreter if program is a script, |
| 81 | // reads headers, maps file into memory, and returns important info about |
| 82 | // the program. |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 83 | int do_exec(const char *exe, struct exeinfo *info); |
| 84 | |
nethercote | 1fe5450 | 2004-07-26 15:28:33 +0000 | [diff] [blame] | 85 | /*------------------------------------------------------------*/ |
| 86 | /*--- Address space padding ---*/ |
| 87 | /*------------------------------------------------------------*/ |
| 88 | |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 89 | void foreach_map(int (*fn)(void *start, void *end, |
| 90 | const char *perm, off_t offset, |
| 91 | int maj, int min, int ino)); |
nethercote | 1fe5450 | 2004-07-26 15:28:33 +0000 | [diff] [blame] | 92 | |
nethercote | ea147e7 | 2004-07-26 15:43:57 +0000 | [diff] [blame^] | 93 | // Padding functions used at startup to force things where we want them. |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 94 | void as_pad(void *start, void *end); |
| 95 | void as_unpad(void *start, void *end); |
| 96 | void as_closepadfile(void); |
| 97 | int as_getpadfd(void); |
| 98 | void as_setpadfd(int); |
| 99 | |
nethercote | 1fe5450 | 2004-07-26 15:28:33 +0000 | [diff] [blame] | 100 | /*------------------------------------------------------------*/ |
| 101 | /*--- Finding and dealing with auxv ---*/ |
| 102 | /*------------------------------------------------------------*/ |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 103 | |
| 104 | struct ume_auxv |
| 105 | { |
| 106 | int a_type; |
| 107 | union { |
| 108 | void *a_ptr; |
| 109 | int a_val; |
| 110 | void (*a_fcn)(void); |
mueller | 5ed88f2 | 2004-01-06 16:02:29 +0000 | [diff] [blame] | 111 | } u; |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | struct 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 */ |
nethercote | 1fe5450 | 2004-07-26 15:28:33 +0000 | [diff] [blame] | 121 | |
| 122 | /*--------------------------------------------------------------------*/ |
| 123 | /*--- end ume.h ---*/ |
| 124 | /*--------------------------------------------------------------------*/ |