2 /*--------------------------------------------------------------------*/
3 /*--- Create initial process image on for the client ---*/
4 /*--- pub_core_initimg.h ---*/
5 /*--------------------------------------------------------------------*/
8 This file is part of Valgrind, a dynamic binary instrumentation
11 Copyright (C) 2006-2017 OpenWorks LLP
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.
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.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, see <http://www.gnu.org/licenses/>.
27 The GNU General Public License is contained in the file COPYING.
30 #ifndef __PUB_CORE_INITIMG_H
31 #define __PUB_CORE_INITIMG_H
33 #include "pub_core_basics.h" // Addr
36 //--------------------------------------------------------------------
37 // PURPOSE: Map the client executable into memory, then set up its
38 // stack, environment and data section, ready for execution. Quite a
39 // lot of work on Linux (ELF).
40 //--------------------------------------------------------------------
42 /* These are OS-specific and defined below. */
43 typedef struct _IICreateImageInfo IICreateImageInfo
;
44 typedef struct _IIFinaliseImageInfo IIFinaliseImageInfo
;
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: */
52 IIFinaliseImageInfo
VG_(ii_create_image
)( IICreateImageInfo
,
53 const VexArchInfo
* vex_archinfo
);
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). */
61 void VG_(ii_finalise_image
)( IIFinaliseImageInfo
);
63 /* Note that both IICreateImageInfo and IIFinaliseImageInfo are
64 OS-specific. We now go on to give instantiations of them
65 for supported OSes. */
67 /* ------------------------- Linux ------------------------- */
69 #if defined(VGO_linux)
71 struct _IICreateImageInfo
{
72 /* ------ Mandatory fields ------ */
73 const HChar
* toolname
;
75 Addr clstack_end
; // Highest stack addressable byte
76 /* ------ Per-OS fields ------ */
81 struct _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
;
89 /* ------ Arch-specific ELF loading state ------ */
90 struct vki_arch_elf_state arch_elf_state
;
93 /* ------------------------- Darwin ------------------------- */
95 #elif defined(VGO_darwin)
97 struct _IICreateImageInfo
{
98 /* ------ Mandatory fields ------ */
99 const HChar
* toolname
;
101 Addr clstack_end
; // highest stack addressable byte
102 /* ------ Per-OS fields ------ */
105 Addr entry
; /* &_start */
106 Addr init_ip
; /* &__dyld_start, or copy of entry */
107 Addr stack_start
; /* stack segment hot */
108 Addr stack_end
; /* stack segment cold */
109 Addr text
; /* executable's Mach header */
110 Bool dynamic
; /* False iff executable is static */
111 HChar
* executable_path
; /* path passed to execve() */
114 struct _IIFinaliseImageInfo
{
115 /* ------ Mandatory fields ------ */
116 SizeT clstack_max_size
;
117 Addr initial_client_SP
;
118 /* ------ Per-OS fields ------ */
119 Addr initial_client_IP
;
122 /* ------------------------- Solaris ------------------------- */
124 #elif defined(VGO_solaris)
126 struct _IICreateImageInfo
{
127 /* ------ Mandatory fields ------ */
128 const HChar
* toolname
;
130 Addr clstack_end
; /* highest stack addressable byte */
131 /* ------ Per-OS fields ------ */
136 struct _IIFinaliseImageInfo
{
137 /* ------ Mandatory fields ------ */
138 SizeT clstack_max_size
;
139 Addr initial_client_SP
;
140 /* ------ Per-OS fields ------ */
141 Addr initial_client_IP
;
142 Addr initial_client_TOC
;
144 Addr initial_client_TP
; /* thread pointer */
152 #endif // __PUB_CORE_INITIMG_H
154 /*--------------------------------------------------------------------*/
156 /*--------------------------------------------------------------------*/