1 
2 /*--------------------------------------------------------------------*/
3 /*--- User-mode execve.                             pub_core_ume.h ---*/
4 /*--------------------------------------------------------------------*/
5 
6 /*
7    This file is part of Valgrind, a dynamic binary instrumentation
8    framework.
9 
10    Copyright (C) 2000-2015 Julian Seward
11       jseward@acm.org
12 
13    This program is free software; you can redistribute it and/or
14    modify it under the terms of the GNU General Public License as
15    published by the Free Software Foundation; either version 2 of the
16    License, or (at your option) any later version.
17 
18    This program is distributed in the hope that it will be useful, but
19    WITHOUT ANY WARRANTY; without even the implied warranty of
20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21    General Public License for more details.
22 
23    You should have received a copy of the GNU General Public License
24    along with this program; if not, write to the Free Software
25    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26    02111-1307, USA.
27 
28    The GNU General Public License is contained in the file COPYING.
29 */
30 
31 #ifndef __PUB_CORE_UME_H
32 #define __PUB_CORE_UME_H
33 
34 #include "pub_core_basics.h"   // VG_ macro
35 
36 //--------------------------------------------------------------------
37 // PURPOSE: This module implements user-mode execve, ie. program loading
38 // and exec'ing.
39 //--------------------------------------------------------------------
40 
41 /*------------------------------------------------------------*/
42 /*--- Loading files                                        ---*/
43 /*------------------------------------------------------------*/
44 
45 // Info needed to load and run a program.  IN/INOUT/OUT refers to the
46 // inputs/outputs of do_exec().
47 typedef
48    struct {
49       const HChar** argv;   // IN: the original argv
50 
51       Addr exe_base;     // INOUT: lowest (allowed) address of exe
52       Addr exe_end;      // INOUT: highest (allowed) address
53 
54 #if !defined(VGO_darwin)
55       Addr     phdr;          // OUT: address phdr was mapped at
56       Int      phnum;         // OUT: number of phdrs
57       UInt     stack_prot;    // OUT: stack permissions
58       PtrdiffT interp_offset; // OUT: relocation offset for ld.so
59 #else
60       Addr  stack_start;      // OUT: address of start of stack segment (hot)
61       Addr  stack_end;        // OUT: address of end of stack segment (cold)
62       Addr  text;             // OUT: address of executable's Mach header
63       Bool  dynamic;          // OUT: False iff executable is static
64       HChar* executable_path; // OUT: path passed to execve()
65 #endif
66 
67 #if defined(VGO_solaris)
68       Addr  init_thrptr;       // OUT: architecture-specific user per-thread location
69       Bool  real_phdr_present; // OUT: PT_PHDR found, include phdr in auxv
70       Bool  ldsoexec;          // OUT: the program is the runtime linker itself
71 #endif
72 
73       Addr entry;        // OUT: entrypoint in main executable
74       Addr init_ip;      // OUT: address of first instruction to execute
75       Addr brkbase;      // OUT: base address of brk segment
76       Addr init_toc;     // OUT: address of table-of-contents, on
77                          // platforms for which that makes sense
78                          // (ppc64-linux only)
79 
80       // These are the extra args added by #! scripts
81       HChar*  interp_name;  // OUT: the interpreter name
82       HChar*  interp_args;  // OUT: the args for the interpreter
83    }
84    ExeInfo;
85 
86 // Do a number of appropriate checks to see if the file looks executable by
87 // the kernel: ie. it's a file, it's readable and executable, and it's in
88 // either binary or "#!" format.  On success, 'out_fd' gets the fd of the file
89 // if it's non-NULL.  Otherwise the fd is closed.
90 extern SysRes VG_(pre_exec_check)(const HChar* exe_name, Int* out_fd,
91                                   Bool allow_setuid);
92 
93 // Does everything short of actually running 'exe': finds the file,
94 // checks execute permissions, sets up interpreter if program is a script,
95 // reads headers, maps file into memory, and returns important info about
96 // the program.
97 extern Int VG_(do_exec)(const HChar* exe, ExeInfo* info);
98 
99 #endif /* __PUB_CORE_UME_H */
100 
101 /*--------------------------------------------------------------------*/
102 /*--- end                                                          ---*/
103 /*--------------------------------------------------------------------*/
104