blob: e0bbfdc9b5de57ebacc4f238393aa215914c1d36 [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
sewardj9ebd6e02007-01-08 06:01:59 +000010 Copyright (C) 2000-2007 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/*------------------------------------------------------------*/
40/*--- Loading ELF files ---*/
41/*------------------------------------------------------------*/
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 {
47 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
sewardj13247ca2005-12-30 22:52:20 +000052 Addr phdr; // OUT: address phdr was mapped at
53 Int phnum; // OUT: number of phdrs
54 Addr interp_base; // OUT: where interpreter (ld.so) was mapped
55 Addr entry; // OUT: entrypoint in main executable
56 Addr init_ip; // OUT: address of first instruction to execute
57 Addr brkbase; // OUT: base address of brk segment
58 Addr init_toc; // OUT: address of table-of-contents, on
59 // platforms for which that makes sense
60 // (ppc64-linux only)
fitzhardinge7e343cd2003-12-16 02:14:00 +000061
sewardj13247ca2005-12-30 22:52:20 +000062 // These are the extra args added by #! scripts
63 HChar* interp_name; // OUT: the interpreter name
64 HChar* interp_args; // OUT: the args for the interpreter
65 }
66 ExeInfo;
fitzhardinge7e343cd2003-12-16 02:14:00 +000067
njn73750612005-10-14 03:11:30 +000068// Do a number of appropriate checks to see if the file looks executable by
69// the kernel: ie. it's a file, it's readable and executable, and it's in
70// either ELF or "#!" format. On success, 'out_fd' gets the fd of the file
71// if it's non-NULL. Otherwise the fd is closed.
sewardj13247ca2005-12-30 22:52:20 +000072extern SysRes VG_(pre_exec_check)(const HChar* exe_name, Int* out_fd);
njn73750612005-10-14 03:11:30 +000073
nethercoteea147e72004-07-26 15:43:57 +000074// Does everything short of actually running 'exe': finds the file,
75// checks execute permissions, sets up interpreter if program is a script,
76// reads headers, maps file into memory, and returns important info about
77// the program.
sewardj13247ca2005-12-30 22:52:20 +000078extern Int VG_(do_exec)(const HChar* exe, ExeInfo* info);
fitzhardinge7e343cd2003-12-16 02:14:00 +000079
nethercote1fe54502004-07-26 15:28:33 +000080/*------------------------------------------------------------*/
nethercote1fe54502004-07-26 15:28:33 +000081/*--- Finding and dealing with auxv ---*/
82/*------------------------------------------------------------*/
fitzhardinge7e343cd2003-12-16 02:14:00 +000083
84struct ume_auxv
85{
sewardjb9bca7c2005-03-02 14:04:19 +000086 Word a_type;
fitzhardinge7e343cd2003-12-16 02:14:00 +000087 union {
88 void *a_ptr;
sewardjb9bca7c2005-03-02 14:04:19 +000089 Word a_val;
mueller5ed88f22004-01-06 16:02:29 +000090 } u;
fitzhardinge7e343cd2003-12-16 02:14:00 +000091};
92
njn62ff0f22005-06-21 23:03:36 +000093extern struct ume_auxv *VG_(find_auxv)(UWord* orig_esp);
fitzhardinge7e343cd2003-12-16 02:14:00 +000094
njn08a2e172005-06-21 22:47:54 +000095#endif /* __PUB_CORE_UME_H */
nethercote1fe54502004-07-26 15:28:33 +000096
97/*--------------------------------------------------------------------*/
njn08a2e172005-06-21 22:47:54 +000098/*--- end ---*/
nethercote1fe54502004-07-26 15:28:33 +000099/*--------------------------------------------------------------------*/