blob: fc3c43317f3ffc46db80945c1d265dceb8e27cd8 [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
sewardj9ebd6e02007-01-08 06:01:59 +000011 Copyright (C) 2006-2007 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
39// lot of work on Linux (ELF) but nearly a no-op on AIX (XCOFF) since
40// the AIX kernel does most of the work for us.
41//--------------------------------------------------------------------
42
sewardjf9d2f9b2006-11-17 20:00:57 +000043/* 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
64/* Note that both IICreateImageInfo and IIFinaliseImageInfo are
65 OS-specific. We now go on to give instantiations of them
66 for supported OSes. */
67
68/* ------------------------- Linux ------------------------- */
69
sewardj17c11042006-10-15 01:26:40 +000070#if defined(VGO_linux)
sewardjf9d2f9b2006-11-17 20:00:57 +000071
72struct _IICreateImageInfo {
73 /* ------ Mandatory fields ------ */
74 HChar* toolname;
75 Addr sp_at_startup;
76 Addr clstack_top;
77 /* ------ Per-OS fields ------ */
78 HChar** argv;
79 HChar** envp;
80};
81
82struct _IIFinaliseImageInfo {
83 /* ------ Mandatory fields ------ */
84 SizeT clstack_max_size;
sewardjf9d2f9b2006-11-17 20:00:57 +000085 Addr initial_client_SP;
sewardj738d36a2006-11-18 14:32:30 +000086 /* ------ Per-OS fields ------ */
sewardjf9d2f9b2006-11-17 20:00:57 +000087 Addr initial_client_IP;
88 Addr initial_client_TOC;
89 UInt* client_auxv;
90};
91
92
93/* ------------------------- AIX5 ------------------------- */
sewardj17c11042006-10-15 01:26:40 +000094
95#elif defined(VGO_aix5)
sewardjf9d2f9b2006-11-17 20:00:57 +000096
97/* First we need to define this auxiliary structure. */
sewardj17c11042006-10-15 01:26:40 +000098typedef
99 struct {
100 /* NOTE: VG_(ppc32/64_aix5_do_preloads_then_start_client) has
101 these offsets hardwired in. Do not change them without
102 changing it too. */
103 /* system call numbers */
104 /* 0 */ UInt nr_load; /* is __NR___loadx for 32-bit,
105 __NR_kload for 64 */
106 /* 4 */ UInt nr_kwrite;
107 /* 8 */ UInt nr__exit;
108 /* offset/length of error message, if the preloads fail */
109 /* 12 */ UInt off_errmsg;
110 /* 16 */ UInt len_errmsg;
111 /* offsets from start of this struct to the the preload file
112 names */
113 /* 20 */ UInt off_preloadcorename;
114 /* 24 */ UInt off_preloadtoolname;
115 /* 28 */ UInt off_ld_preloadname;
116 /* Once the preloading is done, we'll need to restore the guest
117 state to what it needs to be at client startup. Here's the
118 relevant info. Are ULongs; for 32-bit the data is at the
119 lsb (high addressed) end. */
120 /* 32 */ ULong client_start;
121 /* 40 */ ULong r2;
122 /* 48 */ ULong r3;
123 /* 56 */ ULong r4;
124 /* 64 */ ULong r5;
125 /* 72 */ ULong r6;
126 /* 80 */ ULong r7;
127 /* 88 */ ULong r8;
128 /* 96 */ ULong r9;
129 /* 104 */ ULong r10;
130 /* If the loading fails, we'll want to call a diagnostic
131 function in C to figure out what happened. Here's it's
132 function descriptor. Note, this runs on the simd cpu
sewardjf9d2f9b2006-11-17 20:00:57 +0000133 (a kludge, and will segfault in 64-bit mode). */
sewardj17c11042006-10-15 01:26:40 +0000134 /* 112 */ void* p_diagnose_load_failure;
135 }
136 AIX5PreloadPage;
137
sewardjf9d2f9b2006-11-17 20:00:57 +0000138struct _IICreateImageInfo {
139 /* ------ Mandatory fields ------ */
140 HChar* toolname;
141 Addr sp_at_startup; /* Not used on AIX. */
142 Addr clstack_top; /* Not used on AIX. */
143 /* ------ Per-OS fields ------ */
144 /* Initial values for guest int registers (GPR0 .. GPR31, PC, CR,
145 LR, CTR, XER). Passed to us from the launcher. */
146 ULong* intregs37;
147 /* AIX5Bootblock*, really */
148 void* bootblock;
149 /* Adler32 checksum of uncompressed data of compressed page. */
150 UInt adler32_exp;
151};
152
153struct _IIFinaliseImageInfo {
154 /* ------ Mandatory fields ------ */
155 SizeT clstack_max_size;
sewardj738d36a2006-11-18 14:32:30 +0000156 /* Initial value for SP (which is merely a copy of r1's value,
157 intregs37[1]). */
158 Addr initial_client_SP;
sewardjf9d2f9b2006-11-17 20:00:57 +0000159 /* ------ Per-OS fields ------ */
160 /* Pointer to the preload page. The preload page and this pointer
161 to it are set up by VG_(ii_create_image). */
162 AIX5PreloadPage* preloadpage;
163 /* Initial values for guest int registers (GPR0 .. GPR31, PC,
164 CR, LR, CTR, XER). Copied from the CII. */
165 ULong* intregs37;
sewardjf9d2f9b2006-11-17 20:00:57 +0000166 /* Address of the page compressed by the launcher. */
167 Addr compressed_page;
168 /* Adler32 checksum of uncompressed data of said page. */
169 UInt adler32_exp;
170};
sewardj17c11042006-10-15 01:26:40 +0000171
172#else
sewardjf9d2f9b2006-11-17 20:00:57 +0000173# error "Unknown OS"
sewardj17c11042006-10-15 01:26:40 +0000174#endif
175
sewardj17c11042006-10-15 01:26:40 +0000176
177#endif // __PUB_CORE_INITIMG_H
178
179/*--------------------------------------------------------------------*/
180/*--- end ---*/
181/*--------------------------------------------------------------------*/