xref: /netbsd-src/sys/compat/linux/common/linux_exec.h (revision eaac9e3d28859567590b7fef63a96c293f76dbf9)
1 /*	$NetBSD: linux_exec.h,v 1.49 2013/11/18 01:32:22 chs Exp $	*/
2 
3 /*-
4  * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Frank van der Linden and Eric Haszlakiewicz.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _LINUX_EXEC_H
33 #define _LINUX_EXEC_H
34 
35 #if defined(EXEC_AOUT)
36 #include <sys/exec_aout.h>
37 #endif
38 
39 #if defined(EXEC_ELF32) || defined(EXEC_ELF64)
40 #include <sys/exec_elf.h>
41 #endif
42 
43 #if defined(__i386__)
44 #include <compat/linux/arch/i386/linux_exec.h>
45 #elif defined(__m68k__)
46 #include <compat/linux/arch/m68k/linux_exec.h>
47 #elif defined(__alpha__)
48 #include <compat/linux/arch/alpha/linux_exec.h>
49 #elif defined(__powerpc__)
50 #include <compat/linux/arch/powerpc/linux_exec.h>
51 #elif defined(__mips__)
52 #include <compat/linux/arch/mips/linux_exec.h>
53 #elif defined(__arm__)
54 #include <compat/linux/arch/arm/linux_exec.h>
55 #elif defined(__amd64__)
56 #include <compat/linux/arch/amd64/linux_exec.h>
57 #endif
58 
59 
60 /* Defines for a.out executables */
61 #define LINUX_AOUT_HDR_SIZE (sizeof (struct exec))
62 #define	LINUX_AOUT_AUX_ARGSIZ	2
63 
64 #define LINUX_N_MAGIC(ep)    ((ep)->a_midmag & 0xffff)
65 #define LINUX_N_MACHTYPE(ep) (((ep)->a_midmag >> 16) & 0xff)
66 
67 #define LINUX_N_TXTOFF(x,m) \
68  ((m) == ZMAGIC ? 1024 : ((m) == QMAGIC ? 0 : sizeof (struct exec)))
69 
70 #define LINUX_N_DATOFF(x,m) (LINUX_N_TXTOFF(x,m) + (x).a_text)
71 
72 #define LINUX_N_TXTADDR(x,m) ((m) == QMAGIC ? PAGE_SIZE : 0)
73 
74 #define LINUX__N_SEGMENT_ROUND(x) (((x) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
75 
76 #define LINUX__N_TXTENDADDR(x,m) (LINUX_N_TXTADDR(x,m)+(x).a_text)
77 
78 #define LINUX_N_DATADDR(x,m) \
79     ((m)==OMAGIC? (LINUX__N_TXTENDADDR(x,m)) \
80      : (LINUX__N_SEGMENT_ROUND (LINUX__N_TXTENDADDR(x,m))))
81 
82 #define LINUX_N_BSSADDR(x,m) (LINUX_N_DATADDR(x,m) + (x).a_data)
83 
84 #ifndef LINUX_MACHDEP_ELF_COPYARGS
85 #define LINUX_ELF_AUX_ENTRIES	14
86 #endif
87 
88 /*
89  * From Linux's include/linux/elf.h
90  */
91 #define LINUX_AT_UID		11	/* real uid */
92 #define LINUX_AT_EUID		12	/* effective uid */
93 #define LINUX_AT_GID		13	/* real gid */
94 #define LINUX_AT_EGID		14	/* effective gid */
95 #define LINUX_AT_PLATFORM	15	/* CPU string for optimizations */
96 #define LINUX_AT_HWCAP		16	/* arch dependent CPU capabilities */
97 #define LINUX_AT_CLKTCK		17	/* frequency times() increments */
98 #define LINUX_AT_SECURE		23	/* secure mode boolean */
99 #define LINUX_AT_RANDOM		25	/* address of 16 random bytes */
100 #define LINUX_AT_SYSINFO	32	/* pointer to __kernel_vsyscall */
101 #define LINUX_AT_SYSINFO_EHDR	33	/* pointer to ELF header */
102 
103 /*
104  * Emulation specific sysctls.
105  */
106 #define EMUL_LINUX_KERN			1
107 #define EMUL_LINUX_MAXID		2
108 
109 #define EMUL_LINUX_NAMES { \
110 	{ 0, 0 }, \
111 	{ "kern", CTLTYPE_NODE }, \
112 }
113 
114 #define EMUL_LINUX_KERN_OSTYPE		1
115 #define EMUL_LINUX_KERN_OSRELEASE	2
116 #define EMUL_LINUX_KERN_VERSION		3
117 #define EMUL_LINUX_KERN_MAXID		4
118 
119 #define EMUL_LINUX_KERN_NAMES { \
120 	{ 0, 0 }, \
121 	{ "ostype", CTLTYPE_STRING }, \
122 	{ "osrelease", CTLTYPE_STRING }, \
123 	{ "osversion", CTLTYPE_STRING }, \
124 }
125 
126 #ifdef _KERNEL
127 __BEGIN_DECLS
128 extern struct emul emul_linux;
129 
130 int linux_sysctl(int *, u_int, void *, size_t *, void *, size_t,
131     struct lwp *);
132 void linux_setregs(struct lwp *, struct exec_package *, vaddr_t);
133 #ifdef EXEC_AOUT
134 int exec_linux_aout_makecmds(struct lwp *, struct exec_package *);
135 int linux_aout_copyargs(struct lwp *, struct exec_package *,
136     struct ps_strings *, char **, void *);
137 #endif
138 void linux_trapsignal(struct lwp *, ksiginfo_t *);
139 int linux_usertrap(struct lwp *, vaddr_t, void *);
140 int linux_lwp_setprivate(struct lwp *, void *);
141 
142 void linux_e_proc_exec(struct proc *, struct exec_package *);
143 void linux_e_proc_fork(struct proc *, struct lwp *, int);
144 void linux_e_proc_exit(struct proc *);
145 void linux_e_lwp_fork(struct lwp *, struct lwp *);
146 void linux_e_lwp_exit(struct lwp *);
147 
148 #ifdef EXEC_ELF32
149 int linux_elf32_probe(struct lwp *, struct exec_package *, void *,
150     char *, vaddr_t *);
151 int linux_elf32_copyargs(struct lwp *, struct exec_package *,
152     struct ps_strings *, char **, void *);
153 int linux_elf32_signature(struct lwp *, struct exec_package *,
154         Elf32_Ehdr *, char *);
155 #ifdef LINUX_GCC_SIGNATURE
156 int linux_elf32_gcc_signature(struct lwp *l,
157         struct exec_package *, Elf32_Ehdr *);
158 #endif
159 #ifdef LINUX_DEBUGLINK_SIGNATURE
160 int linux_elf32_debuglink_signature(struct lwp *l,
161         struct exec_package *, Elf32_Ehdr *);
162 #endif
163 #ifdef LINUX_ATEXIT_SIGNATURE
164 int linux_elf32_atexit_signature(struct lwp *l,
165         struct exec_package *, Elf32_Ehdr *);
166 #endif
167 #endif
168 #ifdef EXEC_ELF64
169 int linux_elf64_probe(struct lwp *, struct exec_package *, void *,
170     char *, vaddr_t *);
171 int linux_elf64_copyargs(struct lwp *, struct exec_package *,
172     struct ps_strings *, char **, void *);
173 int linux_elf64_signature(struct lwp *, struct exec_package *,
174         Elf64_Ehdr *, char *);
175 #ifdef LINUX_GCC_SIGNATURE
176 int linux_elf64_gcc_signature(struct lwp *l,
177         struct exec_package *, Elf64_Ehdr *);
178 #endif
179 #ifdef LINUX_DEBUGLINK_SIGNATURE
180 int linux_elf64_debuglink_signature(struct lwp *l,
181         struct exec_package *, Elf64_Ehdr *);
182 #endif
183 #ifdef LINUX_ATEXIT_SIGNATURE
184 int linux_elf64_atexit_signature(struct lwp *l,
185         struct exec_package *, Elf64_Ehdr *);
186 #endif
187 #endif
188 __END_DECLS
189 #endif /* !_KERNEL */
190 
191 #endif /* !_LINUX_EXEC_H */
192