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 11 Copyright (C) 2006-2013 OpenWorks LLP 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 35#include "pub_core_basics.h" // Addr 36 37//-------------------------------------------------------------------- 38// PURPOSE: Map the client executable into memory, then set up its 39// stack, environment and data section, ready for execution. Quite a 40// lot of work on Linux (ELF). 41//-------------------------------------------------------------------- 42 43/* These are OS-specific and defined below. */ 44typedef struct _IICreateImageInfo IICreateImageInfo; 45typedef struct _IIFinaliseImageInfo IIFinaliseImageInfo; 46 47/* This is a two stage process. The first stage, which is most of the 48 work, creates the initial image in memory to the extent possible. 49 To do this it takes a bundle of information in an IICreateImageInfo 50 structure, which is gathered in an OS-specific way at startup. 51 This returns an IIFinaliseImageInfo structure: */ 52extern 53IIFinaliseImageInfo VG_(ii_create_image)( IICreateImageInfo ); 54 55/* Just before starting the client, we may need to make final 56 adjustments to its initial image. Also we need to set up the VEX 57 guest state for thread 1 (the root thread) and copy in essential 58 starting values. This is handed the IIFinaliseImageInfo created by 59 VG_(ii_create_image). */ 60extern 61void VG_(ii_finalise_image)( IIFinaliseImageInfo ); 62 63/* Note that both IICreateImageInfo and IIFinaliseImageInfo are 64 OS-specific. We now go on to give instantiations of them 65 for supported OSes. */ 66 67/* ------------------------- Linux ------------------------- */ 68 69#if defined(VGO_linux) 70 71struct _IICreateImageInfo { 72 /* ------ Mandatory fields ------ */ 73 const HChar* toolname; 74 Addr sp_at_startup; 75 Addr clstack_top; 76 /* ------ Per-OS fields ------ */ 77 HChar** argv; 78 HChar** envp; 79}; 80 81struct _IIFinaliseImageInfo { 82 /* ------ Mandatory fields ------ */ 83 SizeT clstack_max_size; 84 Addr initial_client_SP; 85 /* ------ Per-OS fields ------ */ 86 Addr initial_client_IP; 87 Addr initial_client_TOC; 88 UInt* client_auxv; 89}; 90 91/* ------------------------- Darwin ------------------------- */ 92 93#elif defined(VGO_darwin) 94 95struct _IICreateImageInfo { 96 /* ------ Mandatory fields ------ */ 97 const HChar* toolname; 98 Addr sp_at_startup; 99 Addr clstack_top; 100 /* ------ Per-OS fields ------ */ 101 HChar** argv; 102 HChar** envp; 103 Addr entry; /* &_start */ 104 Addr init_ip; /* &__dyld_start, or copy of entry */ 105 Addr stack_start; /* stack segment hot */ 106 Addr stack_end; /* stack segment cold */ 107 Addr text; /* executable's Mach header */ 108 Bool dynamic; /* False iff executable is static */ 109 HChar* executable_path; /* path passed to execve() */ 110}; 111 112struct _IIFinaliseImageInfo { 113 /* ------ Mandatory fields ------ */ 114 SizeT clstack_max_size; 115 Addr initial_client_SP; 116 /* ------ Per-OS fields ------ */ 117 Addr initial_client_IP; 118}; 119 120 121#else 122# error "Unknown OS" 123#endif 124 125 126#endif // __PUB_CORE_INITIMG_H 127 128/*--------------------------------------------------------------------*/ 129/*--- end ---*/ 130/*--------------------------------------------------------------------*/ 131