xref: /netbsd-src/sys/compat/linux/common/linux_exec.h (revision 2e31951ce35b19b425cc71066afbe82e73ab68f4)
1 /*	$NetBSD: linux_exec.h,v 1.45 2008/11/19 18:36:03 ad 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_ELF32) || defined(EXEC_ELF64)
36 #include <sys/exec_elf.h>
37 #endif
38 
39 #if defined(__i386__)
40 #include <compat/linux/arch/i386/linux_exec.h>
41 #elif defined(__m68k__)
42 #include <compat/linux/arch/m68k/linux_exec.h>
43 #elif defined(__alpha__)
44 #include <compat/linux/arch/alpha/linux_exec.h>
45 #elif defined(__powerpc__)
46 #include <compat/linux/arch/powerpc/linux_exec.h>
47 #elif defined(__mips__)
48 #include <compat/linux/arch/mips/linux_exec.h>
49 #elif defined(__arm__)
50 #include <compat/linux/arch/arm/linux_exec.h>
51 #elif defined(__amd64__)
52 #include <compat/linux/arch/amd64/linux_exec.h>
53 #endif
54 
55 
56 /* Defines for a.out executables */
57 #define LINUX_AOUT_HDR_SIZE (sizeof (struct exec))
58 #define	LINUX_AOUT_AUX_ARGSIZ	2
59 
60 #define LINUX_N_MAGIC(ep)    ((ep)->a_midmag & 0xffff)
61 #define LINUX_N_MACHTYPE(ep) (((ep)->a_midmag >> 16) & 0xff)
62 
63 #define LINUX_N_TXTOFF(x,m) \
64  ((m) == ZMAGIC ? 1024 : ((m) == QMAGIC ? 0 : sizeof (struct exec)))
65 
66 #define LINUX_N_DATOFF(x,m) (LINUX_N_TXTOFF(x,m) + (x).a_text)
67 
68 #define LINUX_N_TXTADDR(x,m) ((m) == QMAGIC ? PAGE_SIZE : 0)
69 
70 #define LINUX__N_SEGMENT_ROUND(x) (((x) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
71 
72 #define LINUX__N_TXTENDADDR(x,m) (LINUX_N_TXTADDR(x,m)+(x).a_text)
73 
74 #define LINUX_N_DATADDR(x,m) \
75     ((m)==OMAGIC? (LINUX__N_TXTENDADDR(x,m)) \
76      : (LINUX__N_SEGMENT_ROUND (LINUX__N_TXTENDADDR(x,m))))
77 
78 #define LINUX_N_BSSADDR(x,m) (LINUX_N_DATADDR(x,m) + (x).a_data)
79 
80 #ifndef LINUX_MACHDEP_ELF_COPYARGS
81 #define LINUX_ELF_AUX_ENTRIES	13	/* we push 13 parameters */
82 #endif
83 
84 /*
85  * From Linux's include/linux/elf.h
86  */
87 #define LINUX_AT_UID		11	/* real uid */
88 #define LINUX_AT_EUID		12	/* effective uid */
89 #define LINUX_AT_GID		13	/* real gid */
90 #define LINUX_AT_EGID		14	/* effective gid */
91 #define LINUX_AT_PLATFORM	15	/* CPU string for optimizations */
92 #define LINUX_AT_HWCAP		16	/* arch dependent CPU capabilities */
93 #define LINUX_AT_CLKTCK		17	/* frequency times() increments */
94 #define LINUX_AT_SECURE		23	/* secure mode boolean */
95 #define LINUX_AT_SYSINFO	32	/* pointer to __kernel_vsyscall */
96 #define LINUX_AT_SYSINFO_EHDR	33	/* pointer to ELF header */
97 
98 /*
99  * Emulation specific sysctls.
100  */
101 #define EMUL_LINUX_KERN			1
102 #define EMUL_LINUX_MAXID		2
103 
104 #define EMUL_LINUX_NAMES { \
105 	{ 0, 0 }, \
106 	{ "kern", CTLTYPE_NODE }, \
107 }
108 
109 #define EMUL_LINUX_KERN_OSTYPE		1
110 #define EMUL_LINUX_KERN_OSRELEASE	2
111 #define EMUL_LINUX_KERN_VERSION		3
112 #define EMUL_LINUX_KERN_MAXID		4
113 
114 #define EMUL_LINUX_KERN_NAMES { \
115 	{ 0, 0 }, \
116 	{ "ostype", CTLTYPE_STRING }, \
117 	{ "osrelease", CTLTYPE_STRING }, \
118 	{ "osversion", CTLTYPE_STRING }, \
119 }
120 
121 #ifdef _KERNEL
122 __BEGIN_DECLS
123 extern struct emul emul_linux;
124 
125 int linux_sysctl(int *, u_int, void *, size_t *, void *, size_t,
126     struct lwp *);
127 void linux_setregs(struct lwp *, struct exec_package *, u_long);
128 int exec_linux_aout_makecmds(struct lwp *, struct exec_package *);
129 int linux_aout_copyargs(struct lwp *, struct exec_package *,
130     struct ps_strings *, char **, void *);
131 void linux_trapsignal(struct lwp *, ksiginfo_t *);
132 int linux_usertrap(struct lwp *, vaddr_t, void *);
133 #ifdef LINUX_NPTL
134 void linux_nptl_proc_fork(struct proc *, struct proc *, void (luserret)(void));
135 void linux_nptl_proc_exit(struct proc *);
136 void linux_nptl_proc_init(struct proc *, struct proc *);
137 int  linux_init_thread_area(struct lwp *, struct lwp *);
138 #endif
139 
140 #ifdef EXEC_ELF32
141 int linux_elf32_probe(struct lwp *, struct exec_package *, void *,
142     char *, vaddr_t *);
143 int linux_elf32_copyargs(struct lwp *, struct exec_package *,
144     struct ps_strings *, char **, void *);
145 int linux_elf32_signature(struct lwp *, struct exec_package *,
146         Elf32_Ehdr *, char *);
147 #ifdef LINUX_GCC_SIGNATURE
148 int linux_elf32_gcc_signature(struct lwp *l,
149         struct exec_package *, Elf32_Ehdr *);
150 #endif
151 #ifdef LINUX_DEBUGLINK_SIGNATURE
152 int linux_elf32_debuglink_signature(struct lwp *l,
153         struct exec_package *, Elf32_Ehdr *);
154 #endif
155 #ifdef LINUX_ATEXIT_SIGNATURE
156 int linux_elf32_atexit_signature(struct lwp *l,
157         struct exec_package *, Elf32_Ehdr *);
158 #endif
159 #endif
160 #ifdef EXEC_ELF64
161 int linux_elf64_probe(struct lwp *, struct exec_package *, void *,
162     char *, vaddr_t *);
163 int linux_elf64_copyargs(struct lwp *, struct exec_package *,
164     struct ps_strings *, char **, void *);
165 int linux_elf64_signature(struct lwp *, struct exec_package *,
166         Elf64_Ehdr *, char *);
167 #ifdef LINUX_GCC_SIGNATURE
168 int linux_elf64_gcc_signature(struct lwp *l,
169         struct exec_package *, Elf64_Ehdr *);
170 #endif
171 #ifdef LINUX_DEBUGLINK_SIGNATURE
172 int linux_elf64_debuglink_signature(struct lwp *l,
173         struct exec_package *, Elf64_Ehdr *);
174 #endif
175 #ifdef LINUX_ATEXIT_SIGNATURE
176 int linux_elf64_atexit_signature(struct lwp *l,
177         struct exec_package *, Elf64_Ehdr *);
178 #endif
179 #endif
180 __END_DECLS
181 #endif /* !_KERNEL */
182 
183 #endif /* !_LINUX_EXEC_H */
184