exec.h revision 1549
11543Srgrimes/*- 21543Srgrimes * Copyright (c) 1992, 1993 31543Srgrimes * The Regents of the University of California. All rights reserved. 41543Srgrimes * 51543Srgrimes * Redistribution and use in source and binary forms, with or without 61543Srgrimes * modification, are permitted provided that the following conditions 71543Srgrimes * are met: 81543Srgrimes * 1. Redistributions of source code must retain the above copyright 91543Srgrimes * notice, this list of conditions and the following disclaimer. 101543Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111543Srgrimes * notice, this list of conditions and the following disclaimer in the 121543Srgrimes * documentation and/or other materials provided with the distribution. 131543Srgrimes * 3. All advertising materials mentioning features or use of this software 141543Srgrimes * must display the following acknowledgement: 151543Srgrimes * This product includes software developed by the University of 161543Srgrimes * California, Berkeley and its contributors. 171543Srgrimes * 4. Neither the name of the University nor the names of its contributors 181543Srgrimes * may be used to endorse or promote products derived from this software 191543Srgrimes * without specific prior written permission. 201543Srgrimes * 211543Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221543Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231543Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241543Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251543Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261543Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271543Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281543Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291543Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301543Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311543Srgrimes * SUCH DAMAGE. 321543Srgrimes * 331543Srgrimes * @(#)exec.h 8.1 (Berkeley) 6/11/93 341543Srgrimes */ 351543Srgrimes 361549Srgrimes#ifndef _EXEC_H_ 371549Srgrimes#define _EXEC_H_ 381549Srgrimes 391543Srgrimes#define __LDPGSZ 4096 401543Srgrimes 411543Srgrimes/* Valid magic number check. */ 421543Srgrimes#define N_BADMAG(ex) \ 431549Srgrimes (N_GETMAGIC(ex) != OMAGIC && N_GETMAGIC(ex) != NMAGIC && \ 441549Srgrimes N_GETMAGIC(ex) != ZMAGIC && N_GETMAGIC(ex) != QMAGIC && \ 451549Srgrimes N_GETMAGIC_NET(ex) != OMAGIC && N_GETMAGIC_NET(ex) != NMAGIC && \ 461549Srgrimes N_GETMAGIC_NET(ex) != ZMAGIC && N_GETMAGIC_NET(ex) != QMAGIC) 471543Srgrimes 481549Srgrimes#define N_ALIGN(ex,x) \ 491549Srgrimes (N_GETMAGIC(ex) == ZMAGIC || N_GETMAGIC(ex) == QMAGIC || \ 501549Srgrimes N_GETMAGIC_NET(ex) == ZMAGIC || N_GETMAGIC_NET(ex) == QMAGIC ? \ 511549Srgrimes ((x) + __LDPGSZ - 1) & ~(__LDPGSZ - 1) : (x)) 521549Srgrimes 531543Srgrimes/* Address of the bottom of the text segment. */ 541549Srgrimes#define N_TXTADDR(ex) \ 551549Srgrimes ((N_GETMAGIC(ex) == OMAGIC || N_GETMAGIC(ex) == NMAGIC || \ 561549Srgrimes N_GETMAGIC(ex) == ZMAGIC) ? 0 : __LDPGSZ) 571543Srgrimes 581543Srgrimes/* Address of the bottom of the data segment. */ 591543Srgrimes#define N_DATADDR(ex) \ 601549Srgrimes N_ALIGN(ex, N_TXTADDR(ex) + (ex).a_text) 611543Srgrimes 621549Srgrimes#define N_GETMAGIC(ex) \ 631549Srgrimes ( (ex).a_midmag & 0xffff ) 641549Srgrimes#define N_GETMID(ex) \ 651549Srgrimes ( (N_GETMAGIC_NET(ex) == ZMAGIC) ? N_GETMID_NET(ex) : \ 661549Srgrimes ((ex).a_midmag >> 16) & 0x03ff ) 671549Srgrimes#define N_GETFLAG(ex) \ 681549Srgrimes ( (N_GETMAGIC_NET(ex) == ZMAGIC) ? N_GETFLAG_NET(ex) : \ 691549Srgrimes ((ex).a_midmag >> 26) & 0x3f ) 701549Srgrimes#define N_SETMAGIC(ex,mag,mid,flag) \ 711549Srgrimes ( (ex).a_midmag = (((flag) & 0x3f) <<26) | (((mid) & 0x03ff) << 16) | \ 721549Srgrimes ((mag) & 0xffff) ) 731549Srgrimes 741549Srgrimes#define N_GETMAGIC_NET(ex) \ 751549Srgrimes (ntohl((ex).a_midmag) & 0xffff) 761549Srgrimes#define N_GETMID_NET(ex) \ 771549Srgrimes ((ntohl((ex).a_midmag) >> 16) & 0x03ff) 781549Srgrimes#define N_GETFLAG_NET(ex) \ 791549Srgrimes ((ntohl((ex).a_midmag) >> 26) & 0x3f) 801549Srgrimes#define N_SETMAGIC_NET(ex,mag,mid,flag) \ 811549Srgrimes ( (ex).a_midmag = htonl( (((flag)&0x3f)<<26) | (((mid)&0x03ff)<<16) | \ 821549Srgrimes (((mag)&0xffff)) ) ) 831549Srgrimes 841543Srgrimes/* Text segment offset. */ 851543Srgrimes#define N_TXTOFF(ex) \ 861549Srgrimes (N_GETMAGIC(ex) == ZMAGIC ? __LDPGSZ : (N_GETMAGIC(ex) == QMAGIC || \ 871549Srgrimes N_GETMAGIC_NET(ex) == ZMAGIC) ? 0 : sizeof(struct exec)) 881543Srgrimes 891543Srgrimes/* Data segment offset. */ 901543Srgrimes#define N_DATOFF(ex) \ 911549Srgrimes N_ALIGN(ex, N_TXTOFF(ex) + (ex).a_text) 921543Srgrimes 931549Srgrimes/* Relocation table offset. */ 941549Srgrimes#define N_RELOFF(ex) \ 951549Srgrimes N_ALIGN(ex, N_DATOFF(ex) + (ex).a_data) 961549Srgrimes 971543Srgrimes/* Symbol table offset. */ 981543Srgrimes#define N_SYMOFF(ex) \ 991549Srgrimes (N_RELOFF(ex) + (ex).a_trsize + (ex).a_drsize) 1001543Srgrimes 1011543Srgrimes/* String table offset. */ 1021543Srgrimes#define N_STROFF(ex) (N_SYMOFF(ex) + (ex).a_syms) 1031543Srgrimes 1041549Srgrimes/* 1051549Srgrimes * Header prepended to each a.out file. 1061549Srgrimes * only manipulate the a_midmag field via the 1071549Srgrimes * N_SETMAGIC/N_GET{MAGIC,MID,FLAG} macros in a.out.h 1081549Srgrimes */ 1091549Srgrimes 1101543Srgrimesstruct exec { 1111549Srgrimesunsigned long a_midmag; /* htonl(flags<<26 | mid<<16 | magic) */ 1121549Srgrimesunsigned long a_text; /* text segment size */ 1131549Srgrimesunsigned long a_data; /* initialized data size */ 1141549Srgrimesunsigned long a_bss; /* uninitialized data size */ 1151549Srgrimesunsigned long a_syms; /* symbol table size */ 1161549Srgrimesunsigned long a_entry; /* entry point */ 1171549Srgrimesunsigned long a_trsize; /* text relocation size */ 1181549Srgrimesunsigned long a_drsize; /* data relocation size */ 1191549Srgrimes}; 1201549Srgrimes#define a_magic a_midmag /* XXX Hack to work with current kern_execve.c */ 1211543Srgrimes 1221549Srgrimes/* a_magic */ 1231549Srgrimes#define OMAGIC 0407 /* old impure format */ 1241549Srgrimes#define NMAGIC 0410 /* read-only text */ 1251549Srgrimes#define ZMAGIC 0413 /* demand load format */ 1261549Srgrimes#define QMAGIC 0314 /* "compact" demand load format */ 1271549Srgrimes 1281549Srgrimes#endif /* !_EXEC_H_ */ 129