blob: 7bf70c61af12df3c3029e3d80502642e6805e266 [file] [log] [blame]
jseward2886b0e2004-01-04 03:46:11 +00001
nethercote1fe54502004-07-26 15:28:33 +00002/*--------------------------------------------------------------------*/
njn08a2e172005-06-21 22:47:54 +00003/*--- User-mode execve. pub_core_ume.h ---*/
nethercote1fe54502004-07-26 15:28:33 +00004/*--------------------------------------------------------------------*/
5
jseward2886b0e2004-01-04 03:46:11 +00006/*
njnb9c427c2004-12-01 14:14:42 +00007 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
jseward2886b0e2004-01-04 03:46:11 +00009
Elliott Hughesed398002017-06-21 14:41:24 -070010 Copyright (C) 2000-2017 Julian Seward
jseward2886b0e2004-01-04 03:46:11 +000011 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
njn08a2e172005-06-21 22:47:54 +000031#ifndef __PUB_CORE_UME_H
32#define __PUB_CORE_UME_H
33
florian535fb1b2013-09-15 13:54:34 +000034#include "pub_core_basics.h" // VG_ macro
35
njn08a2e172005-06-21 22:47:54 +000036//--------------------------------------------------------------------
37// PURPOSE: This module implements user-mode execve, ie. program loading
sewardjec7be9c2006-10-17 01:59:30 +000038// and exec'ing.
njn08a2e172005-06-21 22:47:54 +000039//--------------------------------------------------------------------
fitzhardinge7e343cd2003-12-16 02:14:00 +000040
nethercote107e1c02004-10-13 17:55:31 +000041/*------------------------------------------------------------*/
njn91772d12009-01-21 02:26:56 +000042/*--- Loading files ---*/
nethercote107e1c02004-10-13 17:55:31 +000043/*------------------------------------------------------------*/
44
nethercoteea147e72004-07-26 15:43:57 +000045// Info needed to load and run a program. IN/INOUT/OUT refers to the
46// inputs/outputs of do_exec().
sewardj13247ca2005-12-30 22:52:20 +000047typedef
48 struct {
florian3e798632012-11-24 19:41:54 +000049 const HChar** argv; // IN: the original argv
fitzhardinge7e343cd2003-12-16 02:14:00 +000050
sewardj13247ca2005-12-30 22:52:20 +000051 Addr exe_base; // INOUT: lowest (allowed) address of exe
52 Addr exe_end; // INOUT: highest (allowed) address
fitzhardinge7e343cd2003-12-16 02:14:00 +000053
njnf76d27a2009-05-28 01:53:07 +000054#if !defined(VGO_darwin)
tom3d241352014-01-07 22:27:57 +000055 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
njnf76d27a2009-05-28 01:53:07 +000059#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
floriandc240c82014-08-09 16:55:59 +000064 HChar* executable_path; // OUT: path passed to execve()
njnf76d27a2009-05-28 01:53:07 +000065#endif
66
sewardj8eb8bab2015-07-21 14:44:28 +000067#if defined(VGO_solaris)
iraisr358f27c2015-08-17 19:13:12 +000068 Addr init_thrptr; // OUT: architecture-specific user per-thread location
69 Bool real_phdr_present; // OUT: PT_PHDR found, include phdr in auxv
iraisrbcfaeed2015-08-22 22:08:43 +000070 Bool ldsoexec; // OUT: the program is the runtime linker itself
sewardj8eb8bab2015-07-21 14:44:28 +000071#endif
72
Elliott Hughesa0664b92017-04-18 17:46:52 -070073#if defined(VGO_linux)
74 // INOUT: architecture-specific ELF loading state
75 struct vki_arch_elf_state *arch_elf_state;
76#endif
77
sewardj13247ca2005-12-30 22:52:20 +000078 Addr entry; // OUT: entrypoint in main executable
79 Addr init_ip; // OUT: address of first instruction to execute
80 Addr brkbase; // OUT: base address of brk segment
81 Addr init_toc; // OUT: address of table-of-contents, on
82 // platforms for which that makes sense
83 // (ppc64-linux only)
fitzhardinge7e343cd2003-12-16 02:14:00 +000084
sewardj13247ca2005-12-30 22:52:20 +000085 // These are the extra args added by #! scripts
86 HChar* interp_name; // OUT: the interpreter name
87 HChar* interp_args; // OUT: the args for the interpreter
88 }
89 ExeInfo;
fitzhardinge7e343cd2003-12-16 02:14:00 +000090
njn73750612005-10-14 03:11:30 +000091// Do a number of appropriate checks to see if the file looks executable by
92// the kernel: ie. it's a file, it's readable and executable, and it's in
njn91772d12009-01-21 02:26:56 +000093// either binary or "#!" format. On success, 'out_fd' gets the fd of the file
njn73750612005-10-14 03:11:30 +000094// if it's non-NULL. Otherwise the fd is closed.
sewardjc74b3ba2007-11-17 21:11:57 +000095extern SysRes VG_(pre_exec_check)(const HChar* exe_name, Int* out_fd,
96 Bool allow_setuid);
njn73750612005-10-14 03:11:30 +000097
nethercoteea147e72004-07-26 15:43:57 +000098// Does everything short of actually running 'exe': finds the file,
99// checks execute permissions, sets up interpreter if program is a script,
100// reads headers, maps file into memory, and returns important info about
101// the program.
sewardj13247ca2005-12-30 22:52:20 +0000102extern Int VG_(do_exec)(const HChar* exe, ExeInfo* info);
fitzhardinge7e343cd2003-12-16 02:14:00 +0000103
njn08a2e172005-06-21 22:47:54 +0000104#endif /* __PUB_CORE_UME_H */
nethercote1fe54502004-07-26 15:28:33 +0000105
106/*--------------------------------------------------------------------*/
njn08a2e172005-06-21 22:47:54 +0000107/*--- end ---*/
nethercote1fe54502004-07-26 15:28:33 +0000108/*--------------------------------------------------------------------*/