jseward | 2886b0e | 2004-01-04 03:46:11 +0000 | [diff] [blame] | 1 | |
nethercote | 1fe5450 | 2004-07-26 15:28:33 +0000 | [diff] [blame] | 2 | /*--------------------------------------------------------------------*/ |
njn | 08a2e17 | 2005-06-21 22:47:54 +0000 | [diff] [blame] | 3 | /*--- User-mode execve. pub_core_ume.h ---*/ |
nethercote | 1fe5450 | 2004-07-26 15:28:33 +0000 | [diff] [blame] | 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
jseward | 2886b0e | 2004-01-04 03:46:11 +0000 | [diff] [blame] | 6 | /* |
njn | b9c427c | 2004-12-01 14:14:42 +0000 | [diff] [blame] | 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
jseward | 2886b0e | 2004-01-04 03:46:11 +0000 | [diff] [blame] | 9 | |
njn | 5361242 | 2005-03-12 16:22:54 +0000 | [diff] [blame] | 10 | Copyright (C) 2000-2005 Julian Seward |
jseward | 2886b0e | 2004-01-04 03:46:11 +0000 | [diff] [blame] | 11 | jseward@acm.org |
| 12 | |
| 13 | This program is free software; you can redistribute it and/or |
| 14 | modify it under the terms of the GNU General Public License as |
| 15 | published by the Free Software Foundation; either version 2 of the |
| 16 | License, or (at your option) any later version. |
| 17 | |
| 18 | This program is distributed in the hope that it will be useful, but |
| 19 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | General Public License for more details. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with this program; if not, write to the Free Software |
| 25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 26 | 02111-1307, USA. |
| 27 | |
| 28 | The GNU General Public License is contained in the file COPYING. |
| 29 | */ |
| 30 | |
njn | 08a2e17 | 2005-06-21 22:47:54 +0000 | [diff] [blame] | 31 | #ifndef __PUB_CORE_UME_H |
| 32 | #define __PUB_CORE_UME_H |
| 33 | |
| 34 | //-------------------------------------------------------------------- |
| 35 | // PURPOSE: This module implements user-mode execve, ie. program loading |
| 36 | // and exec'ing. It is shared between stage1 and stage2. |
| 37 | //-------------------------------------------------------------------- |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 38 | |
| 39 | #include <elf.h> |
| 40 | #include <sys/types.h> |
| 41 | |
nethercote | 1fe5450 | 2004-07-26 15:28:33 +0000 | [diff] [blame] | 42 | /*------------------------------------------------------------*/ |
| 43 | /*--- General stuff ---*/ |
| 44 | /*------------------------------------------------------------*/ |
| 45 | |
njn | 08a2e17 | 2005-06-21 22:47:54 +0000 | [diff] [blame] | 46 | /* This is only here so it can be shared between stage1 and stage2 */ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 47 | extern |
njn | 62ff0f2 | 2005-06-21 23:03:36 +0000 | [diff] [blame] | 48 | void VG_(foreach_map)(int (*fn)(char *start, char *end, |
| 49 | const char *perm, off_t offset, |
| 50 | int maj, int min, int ino, void* extra), |
| 51 | void* extra); |
nethercote | 969ecf1 | 2004-10-13 17:29:01 +0000 | [diff] [blame] | 52 | |
sewardj | 7f082a6 | 2005-03-22 01:55:35 +0000 | [diff] [blame] | 53 | /* Jump to 'dst', but first set the stack pointer to 'stack'. Also, |
| 54 | clear all the integer registers before entering 'dst'. It's |
| 55 | important that the stack pointer is set to exactly 'stack' and not |
| 56 | (eg) stack - apparently_harmless_looking_small_offset. Basically |
| 57 | because the code at 'dst' might be wanting to scan the area above |
| 58 | 'stack' (viz, the auxv array), and putting spurious words on the |
| 59 | stack confuses it. |
njn | fcb7c3e | 2005-06-18 15:54:25 +0000 | [diff] [blame] | 60 | |
| 61 | This is only exported so that vgtest_ume.c can use it. |
sewardj | 7f082a6 | 2005-03-22 01:55:35 +0000 | [diff] [blame] | 62 | */ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 63 | extern |
| 64 | __attribute__((noreturn)) |
njn | 62ff0f2 | 2005-06-21 23:03:36 +0000 | [diff] [blame] | 65 | void VG_(jump_and_switch_stacks) ( Addr stack, Addr dst ); |
nethercote | 107e1c0 | 2004-10-13 17:55:31 +0000 | [diff] [blame] | 66 | |
sewardj | 0c1a596 | 2005-03-22 00:19:55 +0000 | [diff] [blame] | 67 | |
nethercote | 107e1c0 | 2004-10-13 17:55:31 +0000 | [diff] [blame] | 68 | /*------------------------------------------------------------*/ |
| 69 | /*--- Loading ELF files ---*/ |
| 70 | /*------------------------------------------------------------*/ |
| 71 | |
nethercote | ea147e7 | 2004-07-26 15:43:57 +0000 | [diff] [blame] | 72 | // Info needed to load and run a program. IN/INOUT/OUT refers to the |
| 73 | // inputs/outputs of do_exec(). |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 74 | struct exeinfo |
| 75 | { |
nethercote | a3c3cf2 | 2004-11-01 18:38:00 +0000 | [diff] [blame] | 76 | Addr map_base; // IN: if non-zero, base address of mappings |
nethercote | ea147e7 | 2004-07-26 15:43:57 +0000 | [diff] [blame] | 77 | char** argv; // IN: the original argv |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 78 | |
nethercote | a3c3cf2 | 2004-11-01 18:38:00 +0000 | [diff] [blame] | 79 | Addr exe_base; // INOUT: lowest (allowed) address of exe |
| 80 | Addr exe_end; // INOUT: highest (allowed) address |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 81 | |
nethercote | a3c3cf2 | 2004-11-01 18:38:00 +0000 | [diff] [blame] | 82 | Addr phdr; // OUT: address phdr was mapped at |
| 83 | int phnum; // OUT: number of phdrs |
| 84 | Addr interp_base; // OUT: where interpreter (ld.so) was mapped |
| 85 | Addr entry; // OUT: entrypoint in main executable |
| 86 | Addr init_eip; // OUT: initial eip |
| 87 | Addr brkbase; // OUT: base address of brk segment |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 88 | |
nethercote | 1fe5450 | 2004-07-26 15:28:33 +0000 | [diff] [blame] | 89 | // These are the extra args added by #! scripts |
nethercote | ea147e7 | 2004-07-26 15:43:57 +0000 | [diff] [blame] | 90 | char* interp_name; // OUT: the interpreter name |
| 91 | char* interp_args; // OUT: the args for the interpreter |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
nethercote | ea147e7 | 2004-07-26 15:43:57 +0000 | [diff] [blame] | 94 | // 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. |
njn | 62ff0f2 | 2005-06-21 23:03:36 +0000 | [diff] [blame] | 98 | extern int VG_(do_exec)(const char *exe, struct exeinfo *info); |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 99 | |
nethercote | 1fe5450 | 2004-07-26 15:28:33 +0000 | [diff] [blame] | 100 | /*------------------------------------------------------------*/ |
nethercote | 1fe5450 | 2004-07-26 15:28:33 +0000 | [diff] [blame] | 101 | /*--- Finding and dealing with auxv ---*/ |
| 102 | /*------------------------------------------------------------*/ |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 103 | |
| 104 | struct ume_auxv |
| 105 | { |
sewardj | b9bca7c | 2005-03-02 14:04:19 +0000 | [diff] [blame] | 106 | Word a_type; |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 107 | union { |
| 108 | void *a_ptr; |
sewardj | b9bca7c | 2005-03-02 14:04:19 +0000 | [diff] [blame] | 109 | Word a_val; |
mueller | 5ed88f2 | 2004-01-06 16:02:29 +0000 | [diff] [blame] | 110 | } u; |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 111 | }; |
| 112 | |
njn | 62ff0f2 | 2005-06-21 23:03:36 +0000 | [diff] [blame] | 113 | extern struct ume_auxv *VG_(find_auxv)(UWord* orig_esp); |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 114 | |
| 115 | /* Our private auxv entries */ |
| 116 | #define AT_UME_PADFD 0xff01 /* padding file fd */ |
| 117 | #define AT_UME_EXECFD 0xff02 /* stage1 executable fd */ |
| 118 | |
njn | 08a2e17 | 2005-06-21 22:47:54 +0000 | [diff] [blame] | 119 | #endif /* __PUB_CORE_UME_H */ |
nethercote | 1fe5450 | 2004-07-26 15:28:33 +0000 | [diff] [blame] | 120 | |
| 121 | /*--------------------------------------------------------------------*/ |
njn | 08a2e17 | 2005-06-21 22:47:54 +0000 | [diff] [blame] | 122 | /*--- end ---*/ |
nethercote | 1fe5450 | 2004-07-26 15:28:33 +0000 | [diff] [blame] | 123 | /*--------------------------------------------------------------------*/ |