blob: 428b0c204bad4d5a23d77b7a5eaccfa95145b87a [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
sewardj0f157dd2013-10-18 14:27:36 +000011 Copyright (C) 2006-2013 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
florian535fb1b2013-09-15 13:54:34 +000035#include "pub_core_basics.h" // Addr
carll52b284b2015-04-09 16:23:20 +000036#include "libvex.h"
sewardjf9d2f9b2006-11-17 20:00:57 +000037
sewardj17c11042006-10-15 01:26:40 +000038//--------------------------------------------------------------------
39// PURPOSE: Map the client executable into memory, then set up its
40// stack, environment and data section, ready for execution. Quite a
sewardj6e9de462011-06-28 07:25:29 +000041// lot of work on Linux (ELF).
sewardj17c11042006-10-15 01:26:40 +000042//--------------------------------------------------------------------
43
sewardjf9d2f9b2006-11-17 20:00:57 +000044/* These are OS-specific and defined below. */
45typedef struct _IICreateImageInfo IICreateImageInfo;
46typedef 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: */
53extern
carll52b284b2015-04-09 16:23:20 +000054IIFinaliseImageInfo VG_(ii_create_image)( IICreateImageInfo,
55 const VexArchInfo* vex_archinfo );
sewardjf9d2f9b2006-11-17 20:00:57 +000056
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). */
62extern
63void VG_(ii_finalise_image)( IIFinaliseImageInfo );
64
sewardjf9d2f9b2006-11-17 20:00:57 +000065/* 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
sewardj17c11042006-10-15 01:26:40 +000071#if defined(VGO_linux)
sewardjf9d2f9b2006-11-17 20:00:57 +000072
73struct _IICreateImageInfo {
74 /* ------ Mandatory fields ------ */
florian19f91bb2012-11-10 22:29:54 +000075 const HChar* toolname;
sewardjf9d2f9b2006-11-17 20:00:57 +000076 Addr sp_at_startup;
philippe38a74d22014-08-29 22:53:19 +000077 Addr clstack_end; // Highest stack addressable byte
sewardjf9d2f9b2006-11-17 20:00:57 +000078 /* ------ Per-OS fields ------ */
79 HChar** argv;
80 HChar** envp;
81};
82
83struct _IIFinaliseImageInfo {
84 /* ------ Mandatory fields ------ */
85 SizeT clstack_max_size;
sewardjf9d2f9b2006-11-17 20:00:57 +000086 Addr initial_client_SP;
sewardj738d36a2006-11-18 14:32:30 +000087 /* ------ Per-OS fields ------ */
sewardjf9d2f9b2006-11-17 20:00:57 +000088 Addr initial_client_IP;
89 Addr initial_client_TOC;
90 UInt* client_auxv;
91};
92
njnf76d27a2009-05-28 01:53:07 +000093/* ------------------------- Darwin ------------------------- */
94
95#elif defined(VGO_darwin)
96
97struct _IICreateImageInfo {
98 /* ------ Mandatory fields ------ */
floriane07cbb32013-01-15 03:19:54 +000099 const HChar* toolname;
njnf76d27a2009-05-28 01:53:07 +0000100 Addr sp_at_startup;
philippe38a74d22014-08-29 22:53:19 +0000101 Addr clstack_end; // highest stack addressable byte
njnf76d27a2009-05-28 01:53:07 +0000102 /* ------ Per-OS fields ------ */
103 HChar** argv;
104 HChar** envp;
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() */
112};
113
114struct _IIFinaliseImageInfo {
115 /* ------ Mandatory fields ------ */
116 SizeT clstack_max_size;
117 Addr initial_client_SP;
118 /* ------ Per-OS fields ------ */
119 Addr initial_client_IP;
120};
121
122
sewardj17c11042006-10-15 01:26:40 +0000123#else
sewardjf9d2f9b2006-11-17 20:00:57 +0000124# error "Unknown OS"
sewardj17c11042006-10-15 01:26:40 +0000125#endif
126
sewardj17c11042006-10-15 01:26:40 +0000127
128#endif // __PUB_CORE_INITIMG_H
129
130/*--------------------------------------------------------------------*/
131/*--- end ---*/
132/*--------------------------------------------------------------------*/