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 | |
sewardj | 4d474d0 | 2008-02-11 11:34:59 +0000 | [diff] [blame] | 10 | Copyright (C) 2000-2008 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 |
sewardj | ec7be9c | 2006-10-17 01:59:30 +0000 | [diff] [blame] | 36 | // and exec'ing. |
njn | 08a2e17 | 2005-06-21 22:47:54 +0000 | [diff] [blame] | 37 | //-------------------------------------------------------------------- |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 38 | |
nethercote | 107e1c0 | 2004-10-13 17:55:31 +0000 | [diff] [blame] | 39 | /*------------------------------------------------------------*/ |
| 40 | /*--- Loading ELF files ---*/ |
| 41 | /*------------------------------------------------------------*/ |
| 42 | |
nethercote | ea147e7 | 2004-07-26 15:43:57 +0000 | [diff] [blame] | 43 | // Info needed to load and run a program. IN/INOUT/OUT refers to the |
| 44 | // inputs/outputs of do_exec(). |
sewardj | 13247ca | 2005-12-30 22:52:20 +0000 | [diff] [blame] | 45 | typedef |
| 46 | struct { |
| 47 | HChar** argv; // IN: the original argv |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 48 | |
sewardj | 13247ca | 2005-12-30 22:52:20 +0000 | [diff] [blame] | 49 | Addr exe_base; // INOUT: lowest (allowed) address of exe |
| 50 | Addr exe_end; // INOUT: highest (allowed) address |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 51 | |
sewardj | 13247ca | 2005-12-30 22:52:20 +0000 | [diff] [blame] | 52 | Addr phdr; // OUT: address phdr was mapped at |
| 53 | Int phnum; // OUT: number of phdrs |
| 54 | Addr interp_base; // OUT: where interpreter (ld.so) was mapped |
| 55 | Addr entry; // OUT: entrypoint in main executable |
| 56 | Addr init_ip; // OUT: address of first instruction to execute |
| 57 | Addr brkbase; // OUT: base address of brk segment |
| 58 | Addr init_toc; // OUT: address of table-of-contents, on |
| 59 | // platforms for which that makes sense |
| 60 | // (ppc64-linux only) |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 61 | |
sewardj | 13247ca | 2005-12-30 22:52:20 +0000 | [diff] [blame] | 62 | // These are the extra args added by #! scripts |
| 63 | HChar* interp_name; // OUT: the interpreter name |
| 64 | HChar* interp_args; // OUT: the args for the interpreter |
| 65 | } |
| 66 | ExeInfo; |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 67 | |
njn | 7375061 | 2005-10-14 03:11:30 +0000 | [diff] [blame] | 68 | // Do a number of appropriate checks to see if the file looks executable by |
| 69 | // the kernel: ie. it's a file, it's readable and executable, and it's in |
| 70 | // either ELF or "#!" format. On success, 'out_fd' gets the fd of the file |
| 71 | // if it's non-NULL. Otherwise the fd is closed. |
sewardj | c74b3ba | 2007-11-17 21:11:57 +0000 | [diff] [blame] | 72 | extern SysRes VG_(pre_exec_check)(const HChar* exe_name, Int* out_fd, |
| 73 | Bool allow_setuid); |
njn | 7375061 | 2005-10-14 03:11:30 +0000 | [diff] [blame] | 74 | |
nethercote | ea147e7 | 2004-07-26 15:43:57 +0000 | [diff] [blame] | 75 | // Does everything short of actually running 'exe': finds the file, |
| 76 | // checks execute permissions, sets up interpreter if program is a script, |
| 77 | // reads headers, maps file into memory, and returns important info about |
| 78 | // the program. |
sewardj | 13247ca | 2005-12-30 22:52:20 +0000 | [diff] [blame] | 79 | extern Int VG_(do_exec)(const HChar* exe, ExeInfo* info); |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 80 | |
nethercote | 1fe5450 | 2004-07-26 15:28:33 +0000 | [diff] [blame] | 81 | /*------------------------------------------------------------*/ |
nethercote | 1fe5450 | 2004-07-26 15:28:33 +0000 | [diff] [blame] | 82 | /*--- Finding and dealing with auxv ---*/ |
| 83 | /*------------------------------------------------------------*/ |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 84 | |
| 85 | struct ume_auxv |
| 86 | { |
sewardj | b9bca7c | 2005-03-02 14:04:19 +0000 | [diff] [blame] | 87 | Word a_type; |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 88 | union { |
| 89 | void *a_ptr; |
sewardj | b9bca7c | 2005-03-02 14:04:19 +0000 | [diff] [blame] | 90 | Word a_val; |
mueller | 5ed88f2 | 2004-01-06 16:02:29 +0000 | [diff] [blame] | 91 | } u; |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
njn | 62ff0f2 | 2005-06-21 23:03:36 +0000 | [diff] [blame] | 94 | extern struct ume_auxv *VG_(find_auxv)(UWord* orig_esp); |
fitzhardinge | 7e343cd | 2003-12-16 02:14:00 +0000 | [diff] [blame] | 95 | |
njn | 08a2e17 | 2005-06-21 22:47:54 +0000 | [diff] [blame] | 96 | #endif /* __PUB_CORE_UME_H */ |
nethercote | 1fe5450 | 2004-07-26 15:28:33 +0000 | [diff] [blame] | 97 | |
| 98 | /*--------------------------------------------------------------------*/ |
njn | 08a2e17 | 2005-06-21 22:47:54 +0000 | [diff] [blame] | 99 | /*--- end ---*/ |
nethercote | 1fe5450 | 2004-07-26 15:28:33 +0000 | [diff] [blame] | 100 | /*--------------------------------------------------------------------*/ |