blob: e1ab47ba28055aa7cfc35994fa5428e5239076a3 [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
sewardj03f8d3f2012-08-05 15:46:46 +000010 Copyright (C) 2000-2012 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
34//--------------------------------------------------------------------
35// PURPOSE: This module implements user-mode execve, ie. program loading
sewardjec7be9c2006-10-17 01:59:30 +000036// and exec'ing.
njn08a2e172005-06-21 22:47:54 +000037//--------------------------------------------------------------------
fitzhardinge7e343cd2003-12-16 02:14:00 +000038
nethercote107e1c02004-10-13 17:55:31 +000039/*------------------------------------------------------------*/
njn91772d12009-01-21 02:26:56 +000040/*--- Loading files ---*/
nethercote107e1c02004-10-13 17:55:31 +000041/*------------------------------------------------------------*/
42
nethercoteea147e72004-07-26 15:43:57 +000043// Info needed to load and run a program. IN/INOUT/OUT refers to the
44// inputs/outputs of do_exec().
sewardj13247ca2005-12-30 22:52:20 +000045typedef
46 struct {
florian3e798632012-11-24 19:41:54 +000047 const HChar** argv; // IN: the original argv
fitzhardinge7e343cd2003-12-16 02:14:00 +000048
sewardj13247ca2005-12-30 22:52:20 +000049 Addr exe_base; // INOUT: lowest (allowed) address of exe
50 Addr exe_end; // INOUT: highest (allowed) address
fitzhardinge7e343cd2003-12-16 02:14:00 +000051
njnf76d27a2009-05-28 01:53:07 +000052#if !defined(VGO_darwin)
sewardj13247ca2005-12-30 22:52:20 +000053 Addr phdr; // OUT: address phdr was mapped at
54 Int phnum; // OUT: number of phdrs
55 Addr interp_base; // OUT: where interpreter (ld.so) was mapped
njnf76d27a2009-05-28 01:53:07 +000056#else
57 Addr stack_start; // OUT: address of start of stack segment (hot)
58 Addr stack_end; // OUT: address of end of stack segment (cold)
59 Addr text; // OUT: address of executable's Mach header
60 Bool dynamic; // OUT: False iff executable is static
61 char* executable_path; // OUT: path passed to execve()
62#endif
63
sewardj13247ca2005-12-30 22:52:20 +000064 Addr entry; // OUT: entrypoint in main executable
65 Addr init_ip; // OUT: address of first instruction to execute
66 Addr brkbase; // OUT: base address of brk segment
67 Addr init_toc; // OUT: address of table-of-contents, on
68 // platforms for which that makes sense
69 // (ppc64-linux only)
fitzhardinge7e343cd2003-12-16 02:14:00 +000070
sewardj13247ca2005-12-30 22:52:20 +000071 // These are the extra args added by #! scripts
72 HChar* interp_name; // OUT: the interpreter name
73 HChar* interp_args; // OUT: the args for the interpreter
74 }
75 ExeInfo;
fitzhardinge7e343cd2003-12-16 02:14:00 +000076
njn73750612005-10-14 03:11:30 +000077// Do a number of appropriate checks to see if the file looks executable by
78// the kernel: ie. it's a file, it's readable and executable, and it's in
njn91772d12009-01-21 02:26:56 +000079// either binary or "#!" format. On success, 'out_fd' gets the fd of the file
njn73750612005-10-14 03:11:30 +000080// if it's non-NULL. Otherwise the fd is closed.
sewardjc74b3ba2007-11-17 21:11:57 +000081extern SysRes VG_(pre_exec_check)(const HChar* exe_name, Int* out_fd,
82 Bool allow_setuid);
njn73750612005-10-14 03:11:30 +000083
nethercoteea147e72004-07-26 15:43:57 +000084// Does everything short of actually running 'exe': finds the file,
85// checks execute permissions, sets up interpreter if program is a script,
86// reads headers, maps file into memory, and returns important info about
87// the program.
sewardj13247ca2005-12-30 22:52:20 +000088extern Int VG_(do_exec)(const HChar* exe, ExeInfo* info);
fitzhardinge7e343cd2003-12-16 02:14:00 +000089
njn08a2e172005-06-21 22:47:54 +000090#endif /* __PUB_CORE_UME_H */
nethercote1fe54502004-07-26 15:28:33 +000091
92/*--------------------------------------------------------------------*/
njn08a2e172005-06-21 22:47:54 +000093/*--- end ---*/
nethercote1fe54502004-07-26 15:28:33 +000094/*--------------------------------------------------------------------*/