summaryrefslogtreecommitdiff
path: root/exec/exec.h
blob: bed5edc9bab3503cb9a2f9a9a8f1e0a0bb544af1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/* Program execution for Emacs.

Copyright (C) 2023-2024 Free Software Foundation, Inc.

This file is part of GNU Emacs.

GNU Emacs is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.

GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */



#ifndef _EXEC_H_
#define _EXEC_H_

#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif /* HAVE_STDINT_H */

#include <sys/types.h>

#include USER_HEADER

/* Define a replacement for `uint64_t' if it's not present in the C
   library.  */

#ifndef UINT64_MAX

typedef struct
{
  uint32_t word1;
  uint32_t word2;
} xint64_t;

#else /* UINT64_MAX */
typedef uint64_t xint64_t;
#endif /* !UINT64_MAX */



/* 32-bit ELF headers.  */

struct elf_header_32
{
  unsigned char e_ident[16];
  uint16_t      e_type;
  uint16_t      e_machine;
  uint32_t      e_version;
  uint32_t      e_entry;
  uint32_t      e_phoff;
  uint32_t      e_shoff;
  uint32_t      e_flags;
  uint16_t      e_ehsize;
  uint16_t      e_phentsize;
  uint16_t      e_phnum;
  uint16_t      e_shentsize;
  uint16_t      e_shnum;
  uint16_t      e_shstrndx;
};

struct program_header_32
{
  uint32_t p_type;
  uint32_t p_offset;
  uint32_t p_vaddr;
  uint32_t p_paddr;
  uint32_t p_filesz;
  uint32_t p_memsz;
  uint32_t p_flags;
  uint32_t p_align;
};

struct dt_entry_32
{
  uint32_t d_tag;
  uint32_t d_val;
};



struct elf_header_64
{
  unsigned char e_ident[16];
  uint16_t      e_type;
  uint16_t      e_machine;
  uint32_t      e_version;
  xint64_t      e_entry;
  xint64_t      e_phoff;
  xint64_t      e_shoff;
  uint32_t      e_flags;
  uint16_t      e_ehsize;
  uint16_t      e_phentsize;
  uint16_t      e_phnum;
  uint16_t      e_shentsize;
  uint16_t      e_shnum;
  uint16_t      e_shstrndx;
};

struct program_header_64
{
  uint32_t p_type;
  uint32_t p_flags;
  xint64_t p_offset;
  xint64_t p_vaddr;
  xint64_t p_paddr;
  xint64_t p_filesz;
  xint64_t p_memsz;
  xint64_t p_align;
};

struct dt_entry_64
{
  xint64_t d_tag;
  xint64_t d_val;
};



/* Define some types to the correct values.  */

#ifdef EXEC_64
typedef struct elf_header_64 elf_header;
typedef struct program_header_64 program_header;
typedef struct dt_entry_64 dt_entry;
#else /* !EXEC_64 */
typedef struct elf_header_32 elf_header;
typedef struct program_header_32 program_header;
typedef struct dt_entry_32 dt_entry;
#endif /* EXEC_64 */



/* Defined in trace.c.  */

/* Structure describing a process being traced.  */

struct exec_tracee
{
  /* The next process being traced.  */
  struct exec_tracee *next;

  /* The thread ID of this process.  */
  pid_t pid;

  /* Whether or not the tracee is currently waiting for a system call
     to complete.  */
  bool waiting_for_syscall : 1;

  /* Whether or not the tracee has been created but is not yet
     processed by `handle_clone'.  */
  bool new_child : 1;

#ifndef REENTRANT
  /* Name of the executable being run.  */
  char *exec_file;
#endif /* !REENTRANT */
};



#ifdef __aarch64__

extern int aarch64_get_regs (pid_t, USER_REGS_STRUCT *);
extern int aarch64_set_regs (pid_t, USER_REGS_STRUCT *, bool);

#endif /* __aarch64__ */



extern USER_WORD user_alloca (struct exec_tracee *, USER_REGS_STRUCT *,
			      USER_REGS_STRUCT *, USER_WORD);
extern int user_copy (struct exec_tracee *, const unsigned char *,
		      USER_WORD, USER_WORD);
extern void exec_init (const char *);



extern int tracing_execve (const char *, char *const *,
			   char *const *);
extern int after_fork (pid_t);
extern pid_t exec_waitpid (pid_t, int *, int);



/* Defined in exec.c.  */

extern char *exec_0 (char *, struct exec_tracee *,
		     size_t *, USER_REGS_STRUCT *);



#endif /* _EXEC_H_ */