blob: 6e7c1caca713c10ddbd5e98b4f630541060d9ab5 [file] [log] [blame]
jseward2886b0e2004-01-04 03:46:11 +00001
nethercote1fe54502004-07-26 15:28:33 +00002/*--------------------------------------------------------------------*/
3/*--- A header file used by both stage1 and stage2. ---*/
4/*--- ume.h ---*/
5/*--------------------------------------------------------------------*/
6
jseward2886b0e2004-01-04 03:46:11 +00007/*
njnb9c427c2004-12-01 14:14:42 +00008 This file is part of Valgrind, a dynamic binary instrumentation
9 framework.
jseward2886b0e2004-01-04 03:46:11 +000010
11 Copyright (C) 2000-2004 Julian Seward
12 jseward@acm.org
13
14 This program is free software; you can redistribute it and/or
15 modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation; either version 2 of the
17 License, or (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27 02111-1307, USA.
28
29 The GNU General Public License is contained in the file COPYING.
30*/
31
fitzhardinge7e343cd2003-12-16 02:14:00 +000032#ifndef _COREGRIND_UME_H
33#define _COREGRIND_UME_H
34
35#include <elf.h>
36#include <sys/types.h>
37
nethercoteebf1d862004-11-01 18:22:05 +000038#include "basic_types.h"
39
nethercote1fe54502004-07-26 15:28:33 +000040/*------------------------------------------------------------*/
41/*--- General stuff ---*/
42/*------------------------------------------------------------*/
43
nethercote969ecf12004-10-13 17:29:01 +000044void foreach_map(int (*fn)(char *start, char *end,
45 const char *perm, off_t offset,
46 int maj, int min, int ino, void* extra),
47 void* extra);
48
njnead61122004-11-29 17:59:00 +000049// Jump to a new 'ip' with the stack 'sp'. This is intended
50// to simulate the initial CPU state when the kernel starts an program
51// after exec; and so should clear all the other registers.
nethercotea3c3cf22004-11-01 18:38:00 +000052void jmp_with_stack(Addr ip, Addr sp) __attribute__((noreturn));
nethercote107e1c02004-10-13 17:55:31 +000053
nethercote107e1c02004-10-13 17:55:31 +000054/*------------------------------------------------------------*/
55/*--- Loading ELF files ---*/
56/*------------------------------------------------------------*/
57
nethercoteea147e72004-07-26 15:43:57 +000058// Info needed to load and run a program. IN/INOUT/OUT refers to the
59// inputs/outputs of do_exec().
fitzhardinge7e343cd2003-12-16 02:14:00 +000060struct exeinfo
61{
nethercotea3c3cf22004-11-01 18:38:00 +000062 Addr map_base; // IN: if non-zero, base address of mappings
nethercoteea147e72004-07-26 15:43:57 +000063 char** argv; // IN: the original argv
fitzhardinge7e343cd2003-12-16 02:14:00 +000064
nethercotea3c3cf22004-11-01 18:38:00 +000065 Addr exe_base; // INOUT: lowest (allowed) address of exe
66 Addr exe_end; // INOUT: highest (allowed) address
fitzhardinge7e343cd2003-12-16 02:14:00 +000067
nethercotea3c3cf22004-11-01 18:38:00 +000068 Addr phdr; // OUT: address phdr was mapped at
69 int phnum; // OUT: number of phdrs
70 Addr interp_base; // OUT: where interpreter (ld.so) was mapped
71 Addr entry; // OUT: entrypoint in main executable
72 Addr init_eip; // OUT: initial eip
73 Addr brkbase; // OUT: base address of brk segment
fitzhardinge7e343cd2003-12-16 02:14:00 +000074
nethercote1fe54502004-07-26 15:28:33 +000075 // These are the extra args added by #! scripts
nethercoteea147e72004-07-26 15:43:57 +000076 char* interp_name; // OUT: the interpreter name
77 char* interp_args; // OUT: the args for the interpreter
fitzhardinge7e343cd2003-12-16 02:14:00 +000078};
79
nethercoteea147e72004-07-26 15:43:57 +000080// Does everything short of actually running 'exe': finds the file,
81// checks execute permissions, sets up interpreter if program is a script,
82// reads headers, maps file into memory, and returns important info about
83// the program.
fitzhardinge7e343cd2003-12-16 02:14:00 +000084int do_exec(const char *exe, struct exeinfo *info);
85
nethercote1fe54502004-07-26 15:28:33 +000086/*------------------------------------------------------------*/
nethercote1fe54502004-07-26 15:28:33 +000087/*--- Finding and dealing with auxv ---*/
88/*------------------------------------------------------------*/
fitzhardinge7e343cd2003-12-16 02:14:00 +000089
90struct ume_auxv
91{
92 int a_type;
93 union {
94 void *a_ptr;
95 int a_val;
96 void (*a_fcn)(void);
mueller5ed88f22004-01-06 16:02:29 +000097 } u;
fitzhardinge7e343cd2003-12-16 02:14:00 +000098};
99
nethercoteebf1d862004-11-01 18:22:05 +0000100struct ume_auxv *find_auxv(UWord* orig_esp);
fitzhardinge7e343cd2003-12-16 02:14:00 +0000101
102/* Our private auxv entries */
103#define AT_UME_PADFD 0xff01 /* padding file fd */
104#define AT_UME_EXECFD 0xff02 /* stage1 executable fd */
105
106#endif /* _COREGRIND_UME_H */
nethercote1fe54502004-07-26 15:28:33 +0000107
108/*--------------------------------------------------------------------*/
109/*--- end ume.h ---*/
110/*--------------------------------------------------------------------*/