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 | |
Elliott Hughes | ed39800 | 2017-06-21 14:41:24 -0700 | [diff] [blame^] | 11 | Copyright (C) 2006-2017 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 | |
florian | 535fb1b | 2013-09-15 13:54:34 +0000 | [diff] [blame] | 35 | #include "pub_core_basics.h" // Addr |
carll | 52b284b | 2015-04-09 16:23:20 +0000 | [diff] [blame] | 36 | #include "libvex.h" |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 37 | |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 38 | //-------------------------------------------------------------------- |
| 39 | // PURPOSE: Map the client executable into memory, then set up its |
| 40 | // stack, environment and data section, ready for execution. Quite a |
sewardj | 6e9de46 | 2011-06-28 07:25:29 +0000 | [diff] [blame] | 41 | // lot of work on Linux (ELF). |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 42 | //-------------------------------------------------------------------- |
| 43 | |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 44 | /* These are OS-specific and defined below. */ |
| 45 | typedef struct _IICreateImageInfo IICreateImageInfo; |
| 46 | typedef struct _IIFinaliseImageInfo IIFinaliseImageInfo; |
| 47 | |
| 48 | /* This is a two stage process. The first stage, which is most of the |
| 49 | work, creates the initial image in memory to the extent possible. |
| 50 | To do this it takes a bundle of information in an IICreateImageInfo |
| 51 | structure, which is gathered in an OS-specific way at startup. |
| 52 | This returns an IIFinaliseImageInfo structure: */ |
| 53 | extern |
carll | 52b284b | 2015-04-09 16:23:20 +0000 | [diff] [blame] | 54 | IIFinaliseImageInfo VG_(ii_create_image)( IICreateImageInfo, |
| 55 | const VexArchInfo* vex_archinfo ); |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 56 | |
| 57 | /* Just before starting the client, we may need to make final |
| 58 | adjustments to its initial image. Also we need to set up the VEX |
| 59 | guest state for thread 1 (the root thread) and copy in essential |
| 60 | starting values. This is handed the IIFinaliseImageInfo created by |
| 61 | VG_(ii_create_image). */ |
| 62 | extern |
| 63 | void VG_(ii_finalise_image)( IIFinaliseImageInfo ); |
| 64 | |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 65 | /* Note that both IICreateImageInfo and IIFinaliseImageInfo are |
| 66 | OS-specific. We now go on to give instantiations of them |
| 67 | for supported OSes. */ |
| 68 | |
| 69 | /* ------------------------- Linux ------------------------- */ |
| 70 | |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 71 | #if defined(VGO_linux) |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 72 | |
| 73 | struct _IICreateImageInfo { |
| 74 | /* ------ Mandatory fields ------ */ |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 75 | const HChar* toolname; |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 76 | Addr sp_at_startup; |
philippe | 38a74d2 | 2014-08-29 22:53:19 +0000 | [diff] [blame] | 77 | Addr clstack_end; // Highest stack addressable byte |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 78 | /* ------ Per-OS fields ------ */ |
| 79 | HChar** argv; |
| 80 | HChar** envp; |
| 81 | }; |
| 82 | |
| 83 | struct _IIFinaliseImageInfo { |
| 84 | /* ------ Mandatory fields ------ */ |
| 85 | SizeT clstack_max_size; |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 86 | Addr initial_client_SP; |
sewardj | 738d36a | 2006-11-18 14:32:30 +0000 | [diff] [blame] | 87 | /* ------ Per-OS fields ------ */ |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 88 | Addr initial_client_IP; |
| 89 | Addr initial_client_TOC; |
| 90 | UInt* client_auxv; |
Elliott Hughes | a0664b9 | 2017-04-18 17:46:52 -0700 | [diff] [blame] | 91 | /* ------ Arch-specific ELF loading state ------ */ |
| 92 | struct vki_arch_elf_state arch_elf_state; |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 95 | /* ------------------------- Darwin ------------------------- */ |
| 96 | |
| 97 | #elif defined(VGO_darwin) |
| 98 | |
| 99 | struct _IICreateImageInfo { |
| 100 | /* ------ Mandatory fields ------ */ |
florian | e07cbb3 | 2013-01-15 03:19:54 +0000 | [diff] [blame] | 101 | const HChar* toolname; |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 102 | Addr sp_at_startup; |
philippe | 38a74d2 | 2014-08-29 22:53:19 +0000 | [diff] [blame] | 103 | Addr clstack_end; // highest stack addressable byte |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 104 | /* ------ Per-OS fields ------ */ |
| 105 | HChar** argv; |
| 106 | HChar** envp; |
| 107 | Addr entry; /* &_start */ |
| 108 | Addr init_ip; /* &__dyld_start, or copy of entry */ |
| 109 | Addr stack_start; /* stack segment hot */ |
| 110 | Addr stack_end; /* stack segment cold */ |
| 111 | Addr text; /* executable's Mach header */ |
| 112 | Bool dynamic; /* False iff executable is static */ |
| 113 | HChar* executable_path; /* path passed to execve() */ |
| 114 | }; |
| 115 | |
| 116 | struct _IIFinaliseImageInfo { |
| 117 | /* ------ Mandatory fields ------ */ |
| 118 | SizeT clstack_max_size; |
| 119 | Addr initial_client_SP; |
| 120 | /* ------ Per-OS fields ------ */ |
| 121 | Addr initial_client_IP; |
| 122 | }; |
| 123 | |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 124 | /* ------------------------- Solaris ------------------------- */ |
| 125 | |
| 126 | #elif defined(VGO_solaris) |
| 127 | |
| 128 | struct _IICreateImageInfo { |
| 129 | /* ------ Mandatory fields ------ */ |
| 130 | const HChar* toolname; |
| 131 | Addr sp_at_startup; |
| 132 | Addr clstack_end; /* highest stack addressable byte */ |
| 133 | /* ------ Per-OS fields ------ */ |
| 134 | HChar** argv; |
| 135 | HChar** envp; |
| 136 | }; |
| 137 | |
| 138 | struct _IIFinaliseImageInfo { |
| 139 | /* ------ Mandatory fields ------ */ |
| 140 | SizeT clstack_max_size; |
| 141 | Addr initial_client_SP; |
| 142 | /* ------ Per-OS fields ------ */ |
| 143 | Addr initial_client_IP; |
| 144 | Addr initial_client_TOC; |
| 145 | UInt* client_auxv; |
| 146 | Addr initial_client_TP; /* thread pointer */ |
| 147 | }; |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 148 | |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 149 | #else |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 150 | # error "Unknown OS" |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 151 | #endif |
| 152 | |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 153 | |
| 154 | #endif // __PUB_CORE_INITIMG_H |
| 155 | |
| 156 | /*--------------------------------------------------------------------*/ |
| 157 | /*--- end ---*/ |
| 158 | /*--------------------------------------------------------------------*/ |