• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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-2011 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 
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 //--------------------------------------------------------------------
41 
42 /* These are OS-specific and defined below. */
43 typedef  struct _IICreateImageInfo    IICreateImageInfo;
44 typedef  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: */
51 extern
52 IIFinaliseImageInfo 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). */
59 extern
60 void VG_(ii_finalise_image)( IIFinaliseImageInfo );
61 
62 /* 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 
68 #if defined(VGO_linux)
69 
70 struct _IICreateImageInfo {
71    /* ------ Mandatory fields ------ */
72    HChar*  toolname;
73    Addr    sp_at_startup;
74    Addr    clstack_top;
75    /* ------ Per-OS fields ------ */
76    HChar** argv;
77    HChar** envp;
78 };
79 
80 struct _IIFinaliseImageInfo {
81    /* ------ Mandatory fields ------ */
82    SizeT clstack_max_size;
83    Addr  initial_client_SP;
84    /* ------ Per-OS fields ------ */
85    Addr  initial_client_IP;
86    Addr  initial_client_TOC;
87    UInt* client_auxv;
88 };
89 
90 /* ------------------------- Darwin ------------------------- */
91 
92 #elif defined(VGO_darwin)
93 
94 struct _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 
111 struct _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 
120 #else
121 #  error "Unknown OS"
122 #endif
123 
124 
125 #endif   // __PUB_CORE_INITIMG_H
126 
127 /*--------------------------------------------------------------------*/
128 /*--- end                                                          ---*/
129 /*--------------------------------------------------------------------*/
130