blob: 91a29ec08e87a7749f72da0e035cb2858545d9c0 [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
njn53612422005-03-12 16:22:54 +000010 Copyright (C) 2000-2005 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
36// and exec'ing. It is shared between stage1 and stage2.
37//--------------------------------------------------------------------
fitzhardinge7e343cd2003-12-16 02:14:00 +000038
39#include <elf.h>
40#include <sys/types.h>
41
nethercote1fe54502004-07-26 15:28:33 +000042/*------------------------------------------------------------*/
43/*--- General stuff ---*/
44/*------------------------------------------------------------*/
45
njn08a2e172005-06-21 22:47:54 +000046/* This is only here so it can be shared between stage1 and stage2 */
sewardjb5f6f512005-03-10 23:59:00 +000047extern
njn62ff0f22005-06-21 23:03:36 +000048void VG_(foreach_map)(int (*fn)(char *start, char *end,
49 const char *perm, off_t offset,
50 int maj, int min, int ino, void* extra),
51 void* extra);
nethercote969ecf12004-10-13 17:29:01 +000052
sewardj7f082a62005-03-22 01:55:35 +000053/* Jump to 'dst', but first set the stack pointer to 'stack'. Also,
54 clear all the integer registers before entering 'dst'. It's
55 important that the stack pointer is set to exactly 'stack' and not
56 (eg) stack - apparently_harmless_looking_small_offset. Basically
57 because the code at 'dst' might be wanting to scan the area above
58 'stack' (viz, the auxv array), and putting spurious words on the
59 stack confuses it.
njnfcb7c3e2005-06-18 15:54:25 +000060
61 This is only exported so that vgtest_ume.c can use it.
sewardj7f082a62005-03-22 01:55:35 +000062*/
sewardjb5f6f512005-03-10 23:59:00 +000063extern
64__attribute__((noreturn))
njn62ff0f22005-06-21 23:03:36 +000065void VG_(jump_and_switch_stacks) ( Addr stack, Addr dst );
nethercote107e1c02004-10-13 17:55:31 +000066
sewardj0c1a5962005-03-22 00:19:55 +000067
nethercote107e1c02004-10-13 17:55:31 +000068/*------------------------------------------------------------*/
69/*--- Loading ELF files ---*/
70/*------------------------------------------------------------*/
71
nethercoteea147e72004-07-26 15:43:57 +000072// Info needed to load and run a program. IN/INOUT/OUT refers to the
73// inputs/outputs of do_exec().
fitzhardinge7e343cd2003-12-16 02:14:00 +000074struct exeinfo
75{
nethercotea3c3cf22004-11-01 18:38:00 +000076 Addr map_base; // IN: if non-zero, base address of mappings
nethercoteea147e72004-07-26 15:43:57 +000077 char** argv; // IN: the original argv
fitzhardinge7e343cd2003-12-16 02:14:00 +000078
nethercotea3c3cf22004-11-01 18:38:00 +000079 Addr exe_base; // INOUT: lowest (allowed) address of exe
80 Addr exe_end; // INOUT: highest (allowed) address
fitzhardinge7e343cd2003-12-16 02:14:00 +000081
nethercotea3c3cf22004-11-01 18:38:00 +000082 Addr phdr; // OUT: address phdr was mapped at
83 int phnum; // OUT: number of phdrs
84 Addr interp_base; // OUT: where interpreter (ld.so) was mapped
85 Addr entry; // OUT: entrypoint in main executable
86 Addr init_eip; // OUT: initial eip
87 Addr brkbase; // OUT: base address of brk segment
fitzhardinge7e343cd2003-12-16 02:14:00 +000088
nethercote1fe54502004-07-26 15:28:33 +000089 // These are the extra args added by #! scripts
nethercoteea147e72004-07-26 15:43:57 +000090 char* interp_name; // OUT: the interpreter name
91 char* interp_args; // OUT: the args for the interpreter
fitzhardinge7e343cd2003-12-16 02:14:00 +000092};
93
nethercoteea147e72004-07-26 15:43:57 +000094// Does everything short of actually running 'exe': finds the file,
95// checks execute permissions, sets up interpreter if program is a script,
96// reads headers, maps file into memory, and returns important info about
97// the program.
njn62ff0f22005-06-21 23:03:36 +000098extern int VG_(do_exec)(const char *exe, struct exeinfo *info);
fitzhardinge7e343cd2003-12-16 02:14:00 +000099
nethercote1fe54502004-07-26 15:28:33 +0000100/*------------------------------------------------------------*/
nethercote1fe54502004-07-26 15:28:33 +0000101/*--- Finding and dealing with auxv ---*/
102/*------------------------------------------------------------*/
fitzhardinge7e343cd2003-12-16 02:14:00 +0000103
104struct ume_auxv
105{
sewardjb9bca7c2005-03-02 14:04:19 +0000106 Word a_type;
fitzhardinge7e343cd2003-12-16 02:14:00 +0000107 union {
108 void *a_ptr;
sewardjb9bca7c2005-03-02 14:04:19 +0000109 Word a_val;
mueller5ed88f22004-01-06 16:02:29 +0000110 } u;
fitzhardinge7e343cd2003-12-16 02:14:00 +0000111};
112
njn62ff0f22005-06-21 23:03:36 +0000113extern struct ume_auxv *VG_(find_auxv)(UWord* orig_esp);
fitzhardinge7e343cd2003-12-16 02:14:00 +0000114
115/* Our private auxv entries */
116#define AT_UME_PADFD 0xff01 /* padding file fd */
117#define AT_UME_EXECFD 0xff02 /* stage1 executable fd */
118
njn08a2e172005-06-21 22:47:54 +0000119#endif /* __PUB_CORE_UME_H */
nethercote1fe54502004-07-26 15:28:33 +0000120
121/*--------------------------------------------------------------------*/
njn08a2e172005-06-21 22:47:54 +0000122/*--- end ---*/
nethercote1fe54502004-07-26 15:28:33 +0000123/*--------------------------------------------------------------------*/