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 | /* |
njn | b9c427c | 2004-12-01 14:14:42 +0000 | [diff] [blame] | 8 | This file is part of Valgrind, a dynamic binary instrumentation |
| 9 | framework. |
jseward | 2886b0e | 2004-01-04 03:46:11 +0000 | [diff] [blame] | 10 | |
njn | 5361242 | 2005-03-12 16:22:54 +0000 | [diff] [blame] | 11 | Copyright (C) 2000-2005 Julian Seward |
jseward | 2886b0e | 2004-01-04 03:46:11 +0000 | [diff] [blame] | 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 | ebf1d86 | 2004-11-01 18:22:05 +0000 | [diff] [blame] | 38 | #include "basic_types.h" |
| 39 | |
nethercote | 1fe5450 | 2004-07-26 15:28:33 +0000 | [diff] [blame] | 40 | /*------------------------------------------------------------*/ |
| 41 | /*--- General stuff ---*/ |
| 42 | /*------------------------------------------------------------*/ |
| 43 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 44 | extern |
nethercote | 969ecf1 | 2004-10-13 17:29:01 +0000 | [diff] [blame] | 45 | void foreach_map(int (*fn)(char *start, char *end, |
| 46 | const char *perm, off_t offset, |
| 47 | int maj, int min, int ino, void* extra), |
| 48 | void* extra); |
| 49 | |
njn | ead6112 | 2004-11-29 17:59:00 +0000 | [diff] [blame] | 50 | // Jump to a new 'ip' with the stack 'sp'. This is intended |
| 51 | // to simulate the initial CPU state when the kernel starts an program |
| 52 | // after exec; and so should clear all the other registers. |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 53 | extern |
| 54 | __attribute__((noreturn)) |
| 55 | void jmp_with_stack(void (*eip)(void), Addr sp); |
nethercote | 107e1c0 | 2004-10-13 17:55:31 +0000 | [diff] [blame] | 56 | |
sewardj | 0c1a596 | 2005-03-22 00:19:55 +0000 | [diff] [blame^] | 57 | |
| 58 | /* Call f(), but first switch stacks, using 'stack' as the new stack, |
| 59 | and use 'retaddr' as f's return-to address. Also, clear all the |
| 60 | integer registers before entering f. */ |
| 61 | extern |
| 62 | __attribute__((noreturn)) |
| 63 | void call_on_new_stack_0_0 ( Addr stack, |
| 64 | Addr retaddr, |
| 65 | void (*f)(void) ); |
| 66 | |
| 67 | /* Call f(arg1), but first switch stacks, using 'stack' as the new |
| 68 | stack, and use 'retaddr' as f's return-to address. Also, clear all |
| 69 | the integer registers before entering f.*/ |
| 70 | extern |
| 71 | __attribute__((noreturn)) |
| 72 | void call_on_new_stack_0_1 ( Addr stack, |
| 73 | Addr retaddr, |
| 74 | void (*f)(Word), |
| 75 | Word arg1 ); |
| 76 | |
| 77 | |
nethercote | 107e1c0 | 2004-10-13 17:55:31 +0000 | [diff] [blame] | 78 | /*------------------------------------------------------------*/ |
| 79 | /*--- Loading ELF files ---*/ |
| 80 | /*------------------------------------------------------------*/ |
| 81 | |
nethercote | ea147e7 | 2004-07-26 15:43:57 +0000 | [diff] [blame] | 82 | // Info needed to load and run a program. IN/INOUT/OUT refers to the |
| 83 | // inputs/outputs of do_exec(). |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 84 | struct exeinfo |
| 85 | { |
nethercote | a3c3cf2 | 2004-11-01 18:38:00 +0000 | [diff] [blame] | 86 | Addr map_base; // IN: if non-zero, base address of mappings |
nethercote | ea147e7 | 2004-07-26 15:43:57 +0000 | [diff] [blame] | 87 | char** argv; // IN: the original argv |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 88 | |
nethercote | a3c3cf2 | 2004-11-01 18:38:00 +0000 | [diff] [blame] | 89 | Addr exe_base; // INOUT: lowest (allowed) address of exe |
| 90 | Addr exe_end; // INOUT: highest (allowed) address |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 91 | |
nethercote | a3c3cf2 | 2004-11-01 18:38:00 +0000 | [diff] [blame] | 92 | Addr phdr; // OUT: address phdr was mapped at |
| 93 | int phnum; // OUT: number of phdrs |
| 94 | Addr interp_base; // OUT: where interpreter (ld.so) was mapped |
| 95 | Addr entry; // OUT: entrypoint in main executable |
| 96 | Addr init_eip; // OUT: initial eip |
| 97 | Addr brkbase; // OUT: base address of brk segment |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 98 | |
nethercote | 1fe5450 | 2004-07-26 15:28:33 +0000 | [diff] [blame] | 99 | // These are the extra args added by #! scripts |
nethercote | ea147e7 | 2004-07-26 15:43:57 +0000 | [diff] [blame] | 100 | char* interp_name; // OUT: the interpreter name |
| 101 | char* interp_args; // OUT: the args for the interpreter |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 102 | }; |
| 103 | |
nethercote | ea147e7 | 2004-07-26 15:43:57 +0000 | [diff] [blame] | 104 | // Does everything short of actually running 'exe': finds the file, |
| 105 | // checks execute permissions, sets up interpreter if program is a script, |
| 106 | // reads headers, maps file into memory, and returns important info about |
| 107 | // the program. |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 108 | extern int do_exec(const char *exe, struct exeinfo *info); |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 109 | |
nethercote | 1fe5450 | 2004-07-26 15:28:33 +0000 | [diff] [blame] | 110 | /*------------------------------------------------------------*/ |
nethercote | 1fe5450 | 2004-07-26 15:28:33 +0000 | [diff] [blame] | 111 | /*--- Finding and dealing with auxv ---*/ |
| 112 | /*------------------------------------------------------------*/ |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 113 | |
| 114 | struct ume_auxv |
| 115 | { |
sewardj | b9bca7c | 2005-03-02 14:04:19 +0000 | [diff] [blame] | 116 | Word a_type; |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 117 | union { |
| 118 | void *a_ptr; |
sewardj | b9bca7c | 2005-03-02 14:04:19 +0000 | [diff] [blame] | 119 | Word a_val; |
mueller | 5ed88f2 | 2004-01-06 16:02:29 +0000 | [diff] [blame] | 120 | } u; |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 121 | }; |
| 122 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 123 | extern struct ume_auxv *find_auxv(UWord* orig_esp); |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 124 | |
| 125 | /* Our private auxv entries */ |
| 126 | #define AT_UME_PADFD 0xff01 /* padding file fd */ |
| 127 | #define AT_UME_EXECFD 0xff02 /* stage1 executable fd */ |
| 128 | |
| 129 | #endif /* _COREGRIND_UME_H */ |
nethercote | 1fe5450 | 2004-07-26 15:28:33 +0000 | [diff] [blame] | 130 | |
| 131 | /*--------------------------------------------------------------------*/ |
| 132 | /*--- end ume.h ---*/ |
| 133 | /*--------------------------------------------------------------------*/ |