sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- Create initial process image on for the client ---*/ |
| 4 | /*--- pub_core_initimg.h ---*/ |
| 5 | /*--------------------------------------------------------------------*/ |
| 6 | |
| 7 | /* |
| 8 | This file is part of Valgrind, a dynamic binary instrumentation |
| 9 | framework. |
| 10 | |
sewardj | 03f8d3f | 2012-08-05 15:46:46 +0000 | [diff] [blame] | 11 | Copyright (C) 2006-2012 OpenWorks LLP |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 12 | info@open-works.co.uk |
| 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 | |
| 32 | #ifndef __PUB_CORE_INITIMG_H |
| 33 | #define __PUB_CORE_INITIMG_H |
| 34 | |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 35 | |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 36 | //-------------------------------------------------------------------- |
| 37 | // PURPOSE: Map the client executable into memory, then set up its |
| 38 | // stack, environment and data section, ready for execution. Quite a |
sewardj | 6e9de46 | 2011-06-28 07:25:29 +0000 | [diff] [blame] | 39 | // lot of work on Linux (ELF). |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 40 | //-------------------------------------------------------------------- |
| 41 | |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 42 | /* These are OS-specific and defined below. */ |
| 43 | typedef struct _IICreateImageInfo IICreateImageInfo; |
| 44 | typedef struct _IIFinaliseImageInfo IIFinaliseImageInfo; |
| 45 | |
| 46 | /* This is a two stage process. The first stage, which is most of the |
| 47 | work, creates the initial image in memory to the extent possible. |
| 48 | To do this it takes a bundle of information in an IICreateImageInfo |
| 49 | structure, which is gathered in an OS-specific way at startup. |
| 50 | This returns an IIFinaliseImageInfo structure: */ |
| 51 | extern |
| 52 | IIFinaliseImageInfo VG_(ii_create_image)( IICreateImageInfo ); |
| 53 | |
| 54 | /* Just before starting the client, we may need to make final |
| 55 | adjustments to its initial image. Also we need to set up the VEX |
| 56 | guest state for thread 1 (the root thread) and copy in essential |
| 57 | starting values. This is handed the IIFinaliseImageInfo created by |
| 58 | VG_(ii_create_image). */ |
| 59 | extern |
| 60 | void VG_(ii_finalise_image)( IIFinaliseImageInfo ); |
| 61 | |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 62 | /* Note that both IICreateImageInfo and IIFinaliseImageInfo are |
| 63 | OS-specific. We now go on to give instantiations of them |
| 64 | for supported OSes. */ |
| 65 | |
| 66 | /* ------------------------- Linux ------------------------- */ |
| 67 | |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 68 | #if defined(VGO_linux) |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 69 | |
| 70 | struct _IICreateImageInfo { |
| 71 | /* ------ Mandatory fields ------ */ |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 72 | const HChar* toolname; |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 73 | Addr sp_at_startup; |
| 74 | Addr clstack_top; |
| 75 | /* ------ Per-OS fields ------ */ |
| 76 | HChar** argv; |
| 77 | HChar** envp; |
| 78 | }; |
| 79 | |
| 80 | struct _IIFinaliseImageInfo { |
| 81 | /* ------ Mandatory fields ------ */ |
| 82 | SizeT clstack_max_size; |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 83 | Addr initial_client_SP; |
sewardj | 738d36a | 2006-11-18 14:32:30 +0000 | [diff] [blame] | 84 | /* ------ Per-OS fields ------ */ |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 85 | Addr initial_client_IP; |
| 86 | Addr initial_client_TOC; |
| 87 | UInt* client_auxv; |
| 88 | }; |
| 89 | |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 90 | /* ------------------------- Darwin ------------------------- */ |
| 91 | |
| 92 | #elif defined(VGO_darwin) |
| 93 | |
| 94 | struct _IICreateImageInfo { |
| 95 | /* ------ Mandatory fields ------ */ |
| 96 | HChar* toolname; |
| 97 | Addr sp_at_startup; |
| 98 | Addr clstack_top; |
| 99 | /* ------ Per-OS fields ------ */ |
| 100 | HChar** argv; |
| 101 | HChar** envp; |
| 102 | Addr entry; /* &_start */ |
| 103 | Addr init_ip; /* &__dyld_start, or copy of entry */ |
| 104 | Addr stack_start; /* stack segment hot */ |
| 105 | Addr stack_end; /* stack segment cold */ |
| 106 | Addr text; /* executable's Mach header */ |
| 107 | Bool dynamic; /* False iff executable is static */ |
| 108 | HChar* executable_path; /* path passed to execve() */ |
| 109 | }; |
| 110 | |
| 111 | struct _IIFinaliseImageInfo { |
| 112 | /* ------ Mandatory fields ------ */ |
| 113 | SizeT clstack_max_size; |
| 114 | Addr initial_client_SP; |
| 115 | /* ------ Per-OS fields ------ */ |
| 116 | Addr initial_client_IP; |
| 117 | }; |
| 118 | |
| 119 | |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 120 | #else |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 121 | # error "Unknown OS" |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 122 | #endif |
| 123 | |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 124 | |
| 125 | #endif // __PUB_CORE_INITIMG_H |
| 126 | |
| 127 | /*--------------------------------------------------------------------*/ |
| 128 | /*--- end ---*/ |
| 129 | /*--------------------------------------------------------------------*/ |