imgact_aout.h revision 331722
189857Sobrien/*- 289857Sobrien * Copyright (c) 1992, 1993 360484Sobrien * The Regents of the University of California. All rights reserved. 460484Sobrien * 560484Sobrien * Redistribution and use in source and binary forms, with or without 660484Sobrien * modification, are permitted provided that the following conditions 760484Sobrien * are met: 860484Sobrien * 1. Redistributions of source code must retain the above copyright 960484Sobrien * notice, this list of conditions and the following disclaimer. 1060484Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1160484Sobrien * notice, this list of conditions and the following disclaimer in the 1260484Sobrien * documentation and/or other materials provided with the distribution. 1360484Sobrien * 4. Neither the name of the University nor the names of its contributors 1460484Sobrien * may be used to endorse or promote products derived from this software 1560484Sobrien * without specific prior written permission. 1660484Sobrien * 1760484Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1860484Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19218822Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20218822Sdim * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2160484Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2260484Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2360484Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2460484Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2560484Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2660484Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2760484Sobrien * SUCH DAMAGE. 2860484Sobrien * 2960484Sobrien * from: @(#)exec.h 8.1 (Berkeley) 6/11/93 3077298Sobrien * $FreeBSD: stable/11/sys/sys/imgact_aout.h 331722 2018-03-29 02:50:57Z eadler $ 3177298Sobrien */ 3277298Sobrien 3377298Sobrien#ifndef _IMGACT_AOUT_H_ 3460484Sobrien#define _IMGACT_AOUT_H_ 3560484Sobrien 3660484Sobrien#define N_GETMAGIC(ex) \ 37218822Sdim ( le32toh((ex).a_midmag) & 0xffff ) 3877298Sobrien#define N_GETMID(ex) \ 3960484Sobrien ( (N_GETMAGIC_NET(ex) == ZMAGIC) ? N_GETMID_NET(ex) : \ 4060484Sobrien ((ex).a_midmag >> 16) & 0x03ff ) 4160484Sobrien#define N_GETFLAG(ex) \ 4260484Sobrien ( (N_GETMAGIC_NET(ex) == ZMAGIC) ? N_GETFLAG_NET(ex) : \ 43218822Sdim ((ex).a_midmag >> 26) & 0x3f ) 4460484Sobrien#define N_SETMAGIC(ex,mag,mid,flag) \ 4560484Sobrien ( (ex).a_midmag = htole32((((flag) & 0x3f) <<26) | \ 4660484Sobrien (((mid) & 0x03ff) << 16) | \ 4760484Sobrien ((mag) & 0xffff)) ) 4860484Sobrien 4960484Sobrien#define N_GETMAGIC_NET(ex) \ 5060484Sobrien (ntohl((ex).a_midmag) & 0xffff) 5160484Sobrien#define N_GETMID_NET(ex) \ 5260484Sobrien ((ntohl((ex).a_midmag) >> 16) & 0x03ff) 5360484Sobrien#define N_GETFLAG_NET(ex) \ 5460484Sobrien ((ntohl((ex).a_midmag) >> 26) & 0x3f) 5560484Sobrien#define N_SETMAGIC_NET(ex,mag,mid,flag) \ 5660484Sobrien ( (ex).a_midmag = htonl( (((flag)&0x3f)<<26) | (((mid)&0x03ff)<<16) \ 5760484Sobrien | (((mag)&0xffff)) ) ) 5860484Sobrien 5960484Sobrien#define N_ALIGN(ex,x) \ 6060484Sobrien (N_GETMAGIC(ex) == ZMAGIC || N_GETMAGIC(ex) == QMAGIC || \ 6160484Sobrien N_GETMAGIC_NET(ex) == ZMAGIC || N_GETMAGIC_NET(ex) == QMAGIC ? \ 6260484Sobrien ((x) + __LDPGSZ - 1) & ~(uint32_t)(__LDPGSZ - 1) : (x)) 6360484Sobrien 64218822Sdim/* Valid magic number check. */ 6560484Sobrien#define N_BADMAG(ex) \ 6660484Sobrien (N_GETMAGIC(ex) != OMAGIC && N_GETMAGIC(ex) != NMAGIC && \ 6760484Sobrien N_GETMAGIC(ex) != ZMAGIC && N_GETMAGIC(ex) != QMAGIC && \ 6860484Sobrien N_GETMAGIC_NET(ex) != OMAGIC && N_GETMAGIC_NET(ex) != NMAGIC && \ 6960484Sobrien N_GETMAGIC_NET(ex) != ZMAGIC && N_GETMAGIC_NET(ex) != QMAGIC) 7060484Sobrien 7160484Sobrien 7260484Sobrien/* Address of the bottom of the text segment. */ 7360484Sobrien/* 7460484Sobrien * This can not be done right. Abuse a_entry in some cases to handle kernels. 75218822Sdim */ 7660484Sobrien#define N_TXTADDR(ex) \ 7760484Sobrien ((N_GETMAGIC(ex) == OMAGIC || N_GETMAGIC(ex) == NMAGIC || \ 7860484Sobrien N_GETMAGIC(ex) == ZMAGIC) ? \ 7960484Sobrien (le32toh((ex).a_entry) < le32toh((ex).a_text) ? 0 : \ 8060484Sobrien le32toh((ex).a_entry) & ~__LDPGSZ) : __LDPGSZ) 8160484Sobrien 8260484Sobrien/* Address of the bottom of the data segment. */ 8360484Sobrien#define N_DATADDR(ex) \ 8460484Sobrien N_ALIGN(ex, N_TXTADDR(ex) + le32toh((ex).a_text)) 8560484Sobrien 8660484Sobrien/* Text segment offset. */ 8760484Sobrien#define N_TXTOFF(ex) \ 8860484Sobrien (N_GETMAGIC(ex) == ZMAGIC ? __LDPGSZ : (N_GETMAGIC(ex) == QMAGIC || \ 8960484Sobrien N_GETMAGIC_NET(ex) == ZMAGIC) ? 0 : sizeof(struct exec)) 9060484Sobrien 9160484Sobrien/* Data segment offset. */ 9260484Sobrien#define N_DATOFF(ex) \ 9360484Sobrien N_ALIGN(ex, N_TXTOFF(ex) + le32toh((ex).a_text)) 9460484Sobrien 9560484Sobrien/* Relocation table offset. */ 9660484Sobrien#define N_RELOFF(ex) \ 9760484Sobrien N_ALIGN(ex, N_DATOFF(ex) + le32toh((ex).a_data)) 9860484Sobrien 9960484Sobrien/* Symbol table offset. */ 10060484Sobrien#define N_SYMOFF(ex) \ 10160484Sobrien (N_RELOFF(ex) + le32toh((ex).a_trsize) + le32toh((ex).a_drsize)) 10260484Sobrien 10360484Sobrien/* String table offset. */ 10460484Sobrien#define N_STROFF(ex) (N_SYMOFF(ex) + le32toh((ex).a_syms)) 10560484Sobrien 10660484Sobrien/* 10760484Sobrien * Header prepended to each a.out file. 10860484Sobrien * Only manipulate the a_midmag field via the 10960484Sobrien * N_SETMAGIC/N_GET{MAGIC,MID,FLAG} macros. 11060484Sobrien */ 11160484Sobrien 11260484Sobrienstruct exec { 11360484Sobrien uint32_t a_midmag; /* flags<<26 | mid<<16 | magic */ 11460484Sobrien uint32_t a_text; /* text segment size */ 11560484Sobrien uint32_t a_data; /* initialized data size */ 11660484Sobrien uint32_t a_bss; /* uninitialized data size */ 11760484Sobrien uint32_t a_syms; /* symbol table size */ 11860484Sobrien uint32_t a_entry; /* entry point */ 11960484Sobrien uint32_t a_trsize; /* text relocation size */ 12060484Sobrien uint32_t a_drsize; /* data relocation size */ 12160484Sobrien}; 12260484Sobrien#define a_magic a_midmag /* Hack for emulators */ 12360484Sobrien 124218822Sdim/* a_magic */ 12560484Sobrien#define OMAGIC 0407 /* old impure format */ 12677298Sobrien#define NMAGIC 0410 /* read-only text */ 12777298Sobrien#define ZMAGIC 0413 /* demand load format */ 12860484Sobrien#define QMAGIC 0314 /* "compact" demand load format */ 12960484Sobrien 13060484Sobrien/* a_mid */ 13160484Sobrien#define MID_ZERO 0 /* unknown - implementation dependent */ 13260484Sobrien#define MID_SUN010 1 /* sun 68010/68020 binary */ 13360484Sobrien#define MID_SUN020 2 /* sun 68020-only binary */ 13460484Sobrien#define MID_I386 134 /* i386 BSD binary */ 13560484Sobrien#define MID_SPARC 138 /* sparc */ 13660484Sobrien#define MID_ARM6 143 /* ARM6 */ 13760484Sobrien#define MID_HP200 200 /* hp200 (68010) BSD binary */ 13860484Sobrien#define MID_HP300 300 /* hp300 (68020+68881) BSD binary */ 13960484Sobrien#define MID_HPUX 0x20C /* hp200/300 HP-UX binary */ 140218822Sdim#define MID_HPUX800 0x20B /* hp800 HP-UX binary */ 14160484Sobrien 14260484Sobrien/* 14360484Sobrien * a_flags 14460484Sobrien */ 14560484Sobrien#define EX_PIC 0x10 /* contains position independent code */ 14660484Sobrien#define EX_DYNAMIC 0x20 /* contains run-time link-edit info */ 14760484Sobrien#define EX_DPMASK 0x30 /* mask for the above */ 14860484Sobrien 14960484Sobrien#ifdef _KERNEL 15060484Sobrienstruct thread; 15160484Sobrienstruct vnode; 15260484Sobrien 15360484Sobrienint aout_coredump(struct thread *td, struct vnode *vp, off_t limit, 15460484Sobrien int flags); 15560484Sobrien#endif 15660484Sobrien 15760484Sobrien#endif /* !_IMGACT_AOUT_H_ */ 15860484Sobrien