blob: 39818e204d6a07c4e09da814ac8b548556ccdba9 [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
njn53612422005-03-12 16:22:54 +000011 Copyright (C) 2000-2005 Julian Seward
jseward2886b0e2004-01-04 03:46:11 +000012 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
sewardjb5f6f512005-03-10 23:59:00 +000044extern
nethercote969ecf12004-10-13 17:29:01 +000045void foreach_map(int (*fn)(char *start, char *end,
46 const char *perm, off_t offset,
47 int maj, int min, int ino, void* extra),
48 void* extra);
49
sewardj7f082a62005-03-22 01:55:35 +000050/* Jump to 'dst', but first set the stack pointer to 'stack'. Also,
51 clear all the integer registers before entering 'dst'. It's
52 important that the stack pointer is set to exactly 'stack' and not
53 (eg) stack - apparently_harmless_looking_small_offset. Basically
54 because the code at 'dst' might be wanting to scan the area above
55 'stack' (viz, the auxv array), and putting spurious words on the
56 stack confuses it.
57*/
sewardjb5f6f512005-03-10 23:59:00 +000058extern
59__attribute__((noreturn))
sewardj7f082a62005-03-22 01:55:35 +000060void jump_and_switch_stacks ( Addr stack, Addr dst );
nethercote107e1c02004-10-13 17:55:31 +000061
sewardj0c1a5962005-03-22 00:19:55 +000062
sewardj0c1a5962005-03-22 00:19:55 +000063/* Call f(arg1), but first switch stacks, using 'stack' as the new
64 stack, and use 'retaddr' as f's return-to address. Also, clear all
65 the integer registers before entering f.*/
66extern
67__attribute__((noreturn))
68void call_on_new_stack_0_1 ( Addr stack,
69 Addr retaddr,
70 void (*f)(Word),
71 Word arg1 );
72
73
nethercote107e1c02004-10-13 17:55:31 +000074/*------------------------------------------------------------*/
75/*--- Loading ELF files ---*/
76/*------------------------------------------------------------*/
77
nethercoteea147e72004-07-26 15:43:57 +000078// Info needed to load and run a program. IN/INOUT/OUT refers to the
79// inputs/outputs of do_exec().
fitzhardinge7e343cd2003-12-16 02:14:00 +000080struct exeinfo
81{
nethercotea3c3cf22004-11-01 18:38:00 +000082 Addr map_base; // IN: if non-zero, base address of mappings
nethercoteea147e72004-07-26 15:43:57 +000083 char** argv; // IN: the original argv
fitzhardinge7e343cd2003-12-16 02:14:00 +000084
nethercotea3c3cf22004-11-01 18:38:00 +000085 Addr exe_base; // INOUT: lowest (allowed) address of exe
86 Addr exe_end; // INOUT: highest (allowed) address
fitzhardinge7e343cd2003-12-16 02:14:00 +000087
nethercotea3c3cf22004-11-01 18:38:00 +000088 Addr phdr; // OUT: address phdr was mapped at
89 int phnum; // OUT: number of phdrs
90 Addr interp_base; // OUT: where interpreter (ld.so) was mapped
91 Addr entry; // OUT: entrypoint in main executable
92 Addr init_eip; // OUT: initial eip
93 Addr brkbase; // OUT: base address of brk segment
fitzhardinge7e343cd2003-12-16 02:14:00 +000094
nethercote1fe54502004-07-26 15:28:33 +000095 // These are the extra args added by #! scripts
nethercoteea147e72004-07-26 15:43:57 +000096 char* interp_name; // OUT: the interpreter name
97 char* interp_args; // OUT: the args for the interpreter
fitzhardinge7e343cd2003-12-16 02:14:00 +000098};
99
nethercoteea147e72004-07-26 15:43:57 +0000100// Does everything short of actually running 'exe': finds the file,
101// checks execute permissions, sets up interpreter if program is a script,
102// reads headers, maps file into memory, and returns important info about
103// the program.
sewardjb5f6f512005-03-10 23:59:00 +0000104extern int do_exec(const char *exe, struct exeinfo *info);
fitzhardinge7e343cd2003-12-16 02:14:00 +0000105
nethercote1fe54502004-07-26 15:28:33 +0000106/*------------------------------------------------------------*/
nethercote1fe54502004-07-26 15:28:33 +0000107/*--- Finding and dealing with auxv ---*/
108/*------------------------------------------------------------*/
fitzhardinge7e343cd2003-12-16 02:14:00 +0000109
110struct ume_auxv
111{
sewardjb9bca7c2005-03-02 14:04:19 +0000112 Word a_type;
fitzhardinge7e343cd2003-12-16 02:14:00 +0000113 union {
114 void *a_ptr;
sewardjb9bca7c2005-03-02 14:04:19 +0000115 Word a_val;
mueller5ed88f22004-01-06 16:02:29 +0000116 } u;
fitzhardinge7e343cd2003-12-16 02:14:00 +0000117};
118
sewardjb5f6f512005-03-10 23:59:00 +0000119extern struct ume_auxv *find_auxv(UWord* orig_esp);
fitzhardinge7e343cd2003-12-16 02:14:00 +0000120
121/* Our private auxv entries */
122#define AT_UME_PADFD 0xff01 /* padding file fd */
123#define AT_UME_EXECFD 0xff02 /* stage1 executable fd */
124
125#endif /* _COREGRIND_UME_H */
nethercote1fe54502004-07-26 15:28:33 +0000126
127/*--------------------------------------------------------------------*/
128/*--- end ume.h ---*/
129/*--------------------------------------------------------------------*/