1*bbb9625bSryo /* $NetBSD: linux_exec.h,v 1.55 2021/11/26 08:56:28 ryo Exp $ */ 22637ab65Serh 32637ab65Serh /*- 48096c25aSfvdl * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc. 52637ab65Serh * All rights reserved. 62637ab65Serh * 72637ab65Serh * This code is derived from software contributed to The NetBSD Foundation 88096c25aSfvdl * by Frank van der Linden and Eric Haszlakiewicz. 92637ab65Serh * 102637ab65Serh * Redistribution and use in source and binary forms, with or without 112637ab65Serh * modification, are permitted provided that the following conditions 122637ab65Serh * are met: 132637ab65Serh * 1. Redistributions of source code must retain the above copyright 142637ab65Serh * notice, this list of conditions and the following disclaimer. 152637ab65Serh * 2. Redistributions in binary form must reproduce the above copyright 162637ab65Serh * notice, this list of conditions and the following disclaimer in the 172637ab65Serh * documentation and/or other materials provided with the distribution. 182637ab65Serh * 192637ab65Serh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 202637ab65Serh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 212637ab65Serh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 222637ab65Serh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 232637ab65Serh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 242637ab65Serh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 252637ab65Serh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 262637ab65Serh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 272637ab65Serh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 282637ab65Serh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 292637ab65Serh * POSSIBILITY OF SUCH DAMAGE. 302637ab65Serh */ 313bf459f3Sfvdl 32908291d2Schristos #ifndef _LINUX_EXEC_H 33908291d2Schristos #define _LINUX_EXEC_H 343bf459f3Sfvdl 357bb407d6Smatt #if defined(EXEC_AOUT) 367bb407d6Smatt #include <sys/exec_aout.h> 377bb407d6Smatt #endif 387bb407d6Smatt 39ee0c5b44Smanu #if defined(EXEC_ELF32) || defined(EXEC_ELF64) 40ee0c5b44Smanu #include <sys/exec_elf.h> 41ee0c5b44Smanu #endif 42ee0c5b44Smanu 43908291d2Schristos #if defined(__i386__) 44908291d2Schristos #include <compat/linux/arch/i386/linux_exec.h> 450c080222Sitohy #elif defined(__m68k__) 460c080222Sitohy #include <compat/linux/arch/m68k/linux_exec.h> 47908291d2Schristos #elif defined(__alpha__) 48908291d2Schristos #include <compat/linux/arch/alpha/linux_exec.h> 49cac0b393Smanu #elif defined(__powerpc__) 50cac0b393Smanu #include <compat/linux/arch/powerpc/linux_exec.h> 51e302bb5bSmanu #elif defined(__mips__) 52e302bb5bSmanu #include <compat/linux/arch/mips/linux_exec.h> 53abbc8a65Sryo #elif defined(__aarch64__) 54abbc8a65Sryo #include <compat/linux/arch/aarch64/linux_exec.h> 5564625064Sbjh21 #elif defined(__arm__) 5664625064Sbjh21 #include <compat/linux/arch/arm/linux_exec.h> 5789647c7cSmanu #elif defined(__amd64__) 5889647c7cSmanu #include <compat/linux/arch/amd64/linux_exec.h> 59908291d2Schristos #endif 60908291d2Schristos 613bf459f3Sfvdl 622637ab65Serh /* Defines for a.out executables */ 633bf459f3Sfvdl #define LINUX_AOUT_HDR_SIZE (sizeof (struct exec)) 64f49c9159Schs #define LINUX_AOUT_AUX_ARGSIZ 8 653bf459f3Sfvdl 663bf459f3Sfvdl #define LINUX_N_MAGIC(ep) ((ep)->a_midmag & 0xffff) 673bf459f3Sfvdl #define LINUX_N_MACHTYPE(ep) (((ep)->a_midmag >> 16) & 0xff) 683bf459f3Sfvdl 693bf459f3Sfvdl #define LINUX_N_TXTOFF(x,m) \ 703bf459f3Sfvdl ((m) == ZMAGIC ? 1024 : ((m) == QMAGIC ? 0 : sizeof (struct exec))) 713bf459f3Sfvdl 723bf459f3Sfvdl #define LINUX_N_DATOFF(x,m) (LINUX_N_TXTOFF(x,m) + (x).a_text) 733bf459f3Sfvdl 743bf459f3Sfvdl #define LINUX_N_TXTADDR(x,m) ((m) == QMAGIC ? PAGE_SIZE : 0) 753bf459f3Sfvdl 765051d1c5Sthorpej #define LINUX__N_SEGMENT_ROUND(x) (((x) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1)) 773bf459f3Sfvdl 783bf459f3Sfvdl #define LINUX__N_TXTENDADDR(x,m) (LINUX_N_TXTADDR(x,m)+(x).a_text) 793bf459f3Sfvdl 803bf459f3Sfvdl #define LINUX_N_DATADDR(x,m) \ 813bf459f3Sfvdl ((m)==OMAGIC? (LINUX__N_TXTENDADDR(x,m)) \ 823bf459f3Sfvdl : (LINUX__N_SEGMENT_ROUND (LINUX__N_TXTENDADDR(x,m)))) 833bf459f3Sfvdl 843bf459f3Sfvdl #define LINUX_N_BSSADDR(x,m) (LINUX_N_DATADDR(x,m) + (x).a_data) 853bf459f3Sfvdl 860a624a0cSjdolecek #ifndef LINUX_MACHDEP_ELF_COPYARGS 87c23f9377Smaxv /* Counted from linux_exec_elf32.c */ 882084516cSchs #define LINUX_ELF_AUX_ENTRIES 14 89cee43b67Sjdolecek #endif 90cee43b67Sjdolecek 91cac0b393Smanu /* 92cac0b393Smanu * From Linux's include/linux/elf.h 93cac0b393Smanu */ 94cac0b393Smanu #define LINUX_AT_UID 11 /* real uid */ 95cac0b393Smanu #define LINUX_AT_EUID 12 /* effective uid */ 96cac0b393Smanu #define LINUX_AT_GID 13 /* real gid */ 97cac0b393Smanu #define LINUX_AT_EGID 14 /* effective gid */ 9850981e06Schristos #define LINUX_AT_PLATFORM 15 /* CPU string for optimizations */ 9950981e06Schristos #define LINUX_AT_HWCAP 16 /* arch dependent CPU capabilities */ 10050981e06Schristos #define LINUX_AT_CLKTCK 17 /* frequency times() increments */ 10189647c7cSmanu #define LINUX_AT_SECURE 23 /* secure mode boolean */ 1022084516cSchs #define LINUX_AT_RANDOM 25 /* address of 16 random bytes */ 103ee0c5b44Smanu #define LINUX_AT_SYSINFO 32 /* pointer to __kernel_vsyscall */ 104ee0c5b44Smanu #define LINUX_AT_SYSINFO_EHDR 33 /* pointer to ELF header */ 10550981e06Schristos 106e5a75de9Schs #define LINUX_RANDOM_BYTES 16 /* 16 bytes for AT_RANDOM */ 107e5a75de9Schs 10850981e06Schristos /* 10950981e06Schristos * Emulation specific sysctls. 11050981e06Schristos */ 11150981e06Schristos #define EMUL_LINUX_KERN 1 11250981e06Schristos 11350981e06Schristos #define EMUL_LINUX_KERN_OSTYPE 1 11450981e06Schristos #define EMUL_LINUX_KERN_OSRELEASE 2 11550981e06Schristos #define EMUL_LINUX_KERN_VERSION 3 116cac0b393Smanu 1172637ab65Serh #ifdef _KERNEL 1182637ab65Serh __BEGIN_DECLS 11992ce8c6aSad extern struct emul emul_linux; 120baae0324Sjdolecek 121f2af9174Sdsl int linux_sysctl(int *, u_int, void *, size_t *, void *, size_t, 122f2af9174Sdsl struct lwp *); 1236a9e4e8eSmatt void linux_setregs(struct lwp *, struct exec_package *, vaddr_t); 1247bb407d6Smatt #ifdef EXEC_AOUT 125f2af9174Sdsl int exec_linux_aout_makecmds(struct lwp *, struct exec_package *); 126f2af9174Sdsl int linux_aout_copyargs(struct lwp *, struct exec_package *, 127f2af9174Sdsl struct ps_strings *, char **, void *); 1287bb407d6Smatt #endif 129f2af9174Sdsl void linux_trapsignal(struct lwp *, ksiginfo_t *); 130f2af9174Sdsl int linux_usertrap(struct lwp *, vaddr_t, void *); 13133fa5ccbSchs int linux_lwp_setprivate(struct lwp *, void *); 13233fa5ccbSchs 13333fa5ccbSchs void linux_e_proc_exec(struct proc *, struct exec_package *); 13433fa5ccbSchs void linux_e_proc_fork(struct proc *, struct lwp *, int); 13533fa5ccbSchs void linux_e_proc_exit(struct proc *); 13633fa5ccbSchs void linux_e_lwp_fork(struct lwp *, struct lwp *); 13733fa5ccbSchs void linux_e_lwp_exit(struct lwp *); 1383bf459f3Sfvdl 1392637ab65Serh #ifdef EXEC_ELF32 140f2af9174Sdsl int linux_elf32_probe(struct lwp *, struct exec_package *, void *, 141f2af9174Sdsl char *, vaddr_t *); 142f2af9174Sdsl int linux_elf32_copyargs(struct lwp *, struct exec_package *, 143f2af9174Sdsl struct ps_strings *, char **, void *); 144f2af9174Sdsl int linux_elf32_signature(struct lwp *, struct exec_package *, 145f2af9174Sdsl Elf32_Ehdr *, char *); 146ee0c5b44Smanu #ifdef LINUX_GCC_SIGNATURE 147f2af9174Sdsl int linux_elf32_gcc_signature(struct lwp *l, 148f2af9174Sdsl struct exec_package *, Elf32_Ehdr *); 149ee0c5b44Smanu #endif 15005c8a1b8Smanu #ifdef LINUX_DEBUGLINK_SIGNATURE 151f2af9174Sdsl int linux_elf32_debuglink_signature(struct lwp *l, 152f2af9174Sdsl struct exec_package *, Elf32_Ehdr *); 15305c8a1b8Smanu #endif 154ee0c5b44Smanu #ifdef LINUX_ATEXIT_SIGNATURE 155f2af9174Sdsl int linux_elf32_atexit_signature(struct lwp *l, 156f2af9174Sdsl struct exec_package *, Elf32_Ehdr *); 157ee0c5b44Smanu #endif 158*bbb9625bSryo #ifdef LINUX_GO_RT0_SIGNATURE 159*bbb9625bSryo int linux_elf32_go_rt0_signature(struct lwp *l, 160*bbb9625bSryo struct exec_package *, Elf32_Ehdr *); 161*bbb9625bSryo #endif 1622637ab65Serh #endif 1632637ab65Serh #ifdef EXEC_ELF64 164f2af9174Sdsl int linux_elf64_probe(struct lwp *, struct exec_package *, void *, 165f2af9174Sdsl char *, vaddr_t *); 166f2af9174Sdsl int linux_elf64_copyargs(struct lwp *, struct exec_package *, 167f2af9174Sdsl struct ps_strings *, char **, void *); 168f2af9174Sdsl int linux_elf64_signature(struct lwp *, struct exec_package *, 169f2af9174Sdsl Elf64_Ehdr *, char *); 170ee0c5b44Smanu #ifdef LINUX_GCC_SIGNATURE 171f2af9174Sdsl int linux_elf64_gcc_signature(struct lwp *l, 172f2af9174Sdsl struct exec_package *, Elf64_Ehdr *); 173ee0c5b44Smanu #endif 17405c8a1b8Smanu #ifdef LINUX_DEBUGLINK_SIGNATURE 175f2af9174Sdsl int linux_elf64_debuglink_signature(struct lwp *l, 176f2af9174Sdsl struct exec_package *, Elf64_Ehdr *); 17705c8a1b8Smanu #endif 178ee0c5b44Smanu #ifdef LINUX_ATEXIT_SIGNATURE 179f2af9174Sdsl int linux_elf64_atexit_signature(struct lwp *l, 180f2af9174Sdsl struct exec_package *, Elf64_Ehdr *); 181ee0c5b44Smanu #endif 182*bbb9625bSryo #ifdef LINUX_GO_RT0_SIGNATURE 183*bbb9625bSryo int linux_elf64_go_rt0_signature(struct lwp *l, 184*bbb9625bSryo struct exec_package *, Elf64_Ehdr *); 185*bbb9625bSryo #endif 1862637ab65Serh #endif 1872637ab65Serh __END_DECLS 1882637ab65Serh #endif /* !_KERNEL */ 189c4aaa600Sfvdl 190908291d2Schristos #endif /* !_LINUX_EXEC_H */ 191