blob: 574d07d8d8c6ba26322051a8dbc4ecbdaff4e15c [file] [log] [blame]
sewardj17c11042006-10-15 01:26:40 +00001
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
sewardj03f8d3f2012-08-05 15:46:46 +000011 Copyright (C) 2006-2012 OpenWorks LLP
sewardj17c11042006-10-15 01:26:40 +000012 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
sewardjf9d2f9b2006-11-17 20:00:57 +000035
sewardj17c11042006-10-15 01:26:40 +000036//--------------------------------------------------------------------
37// PURPOSE: Map the client executable into memory, then set up its
38// stack, environment and data section, ready for execution. Quite a
sewardj6e9de462011-06-28 07:25:29 +000039// lot of work on Linux (ELF).
sewardj17c11042006-10-15 01:26:40 +000040//--------------------------------------------------------------------
41
sewardjf9d2f9b2006-11-17 20:00:57 +000042/* These are OS-specific and defined below. */
43typedef struct _IICreateImageInfo IICreateImageInfo;
44typedef 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: */
51extern
52IIFinaliseImageInfo 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). */
59extern
60void VG_(ii_finalise_image)( IIFinaliseImageInfo );
61
sewardjf9d2f9b2006-11-17 20:00:57 +000062/* 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
sewardj17c11042006-10-15 01:26:40 +000068#if defined(VGO_linux)
sewardjf9d2f9b2006-11-17 20:00:57 +000069
70struct _IICreateImageInfo {
71 /* ------ Mandatory fields ------ */
florian19f91bb2012-11-10 22:29:54 +000072 const HChar* toolname;
sewardjf9d2f9b2006-11-17 20:00:57 +000073 Addr sp_at_startup;
74 Addr clstack_top;
75 /* ------ Per-OS fields ------ */
76 HChar** argv;
77 HChar** envp;
78};
79
80struct _IIFinaliseImageInfo {
81 /* ------ Mandatory fields ------ */
82 SizeT clstack_max_size;
sewardjf9d2f9b2006-11-17 20:00:57 +000083 Addr initial_client_SP;
sewardj738d36a2006-11-18 14:32:30 +000084 /* ------ Per-OS fields ------ */
sewardjf9d2f9b2006-11-17 20:00:57 +000085 Addr initial_client_IP;
86 Addr initial_client_TOC;
87 UInt* client_auxv;
88};
89
njnf76d27a2009-05-28 01:53:07 +000090/* ------------------------- Darwin ------------------------- */
91
92#elif defined(VGO_darwin)
93
94struct _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
111struct _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
sewardj17c11042006-10-15 01:26:40 +0000120#else
sewardjf9d2f9b2006-11-17 20:00:57 +0000121# error "Unknown OS"
sewardj17c11042006-10-15 01:26:40 +0000122#endif
123
sewardj17c11042006-10-15 01:26:40 +0000124
125#endif // __PUB_CORE_INITIMG_H
126
127/*--------------------------------------------------------------------*/
128/*--- end ---*/
129/*--------------------------------------------------------------------*/