a.out.h revision 1.13 1 /*-
2 * Copyright (c) 1993 Theo de Raadt
3 * Copyright (c) 1991 The Regents of the University of California.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by the University of
17 * California, Berkeley and its contributors.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * from: @(#)a.out.h 5.6 (Berkeley) 4/30/91
35 * $Id: a.out.h,v 1.13 1994/04/07 06:34:03 deraadt Exp $
36 */
37
38 #ifndef _AOUT_H_
39 #define _AOUT_H_
40
41 #include <sys/exec.h>
42 #include <machine/exec.h>
43
44
45 #ifndef N_PAGSIZ
46 #define N_PAGSIZ(ex) (__LDPGSZ)
47 #endif
48
49 /*
50 * The a.out structure's a_midmag field is a network-byteorder encoding
51 * of this int
52 * FFFFFFmmmmmmmmmmMMMMMMMMMMMMMMMM
53 * Where `F' is 6 bits of flag like EX_DYNAMIC,
54 * `m' is 10 bits of machine-id like MID_I386, and
55 * `M' is 16 bits worth of magic number, ie. ZMAGIC.
56 * The macros below will set/get the needed fields.
57 */
58 #define N_GETMAGIC(ex) \
59 ( (((ex).a_midmag)&0xffff0000) ? (ntohl(((ex).a_midmag))&0xffff) : ((ex).a_midmag))
60 #define N_GETMAGIC2(ex) \
61 ( (((ex).a_midmag)&0xffff0000) ? (ntohl(((ex).a_midmag))&0xffff) : \
62 (((ex).a_midmag) | 0x10000) )
63 #define N_GETMID(ex) \
64 ( (((ex).a_midmag)&0xffff0000) ? ((ntohl(((ex).a_midmag))>>16)&0x03ff) : MID_ZERO )
65 #define N_GETFLAG(ex) \
66 ( (((ex).a_midmag)&0xffff0000) ? ((ntohl(((ex).a_midmag))>>26)&0x3f) : 0 )
67 #define N_SETMAGIC(ex,mag,mid,flag) \
68 ( (ex).a_midmag = htonl( (((flag)&0x3f)<<26) | (((mid)&0x03ff)<<16) | \
69 (((mag)&0xffff)) ) )
70
71 #define N_ALIGN(ex,x) \
72 (N_GETMAGIC(ex) == ZMAGIC || N_GETMAGIC(ex) == QMAGIC ? \
73 ((x) + __LDPGSZ - 1) & ~(__LDPGSZ - 1) : (x))
74
75 /* Valid magic number check. */
76 #define N_BADMAG(ex) \
77 (N_GETMAGIC(ex) != NMAGIC && N_GETMAGIC(ex) != OMAGIC && \
78 N_GETMAGIC(ex) != ZMAGIC && N_GETMAGIC(ex) != QMAGIC)
79
80 /* Address of the bottom of the text segment. */
81 #define N_TXTADDR(ex) (N_GETMAGIC2(ex) == (ZMAGIC|0x10000) ? 0 : __LDPGSZ)
82
83 /* Address of the bottom of the data segment. */
84 #define N_DATADDR(ex) \
85 (N_GETMAGIC(ex) == OMAGIC ? N_TXTADDR(ex) + (ex).a_text : \
86 (N_TXTADDR(ex) + (ex).a_text + __LDPGSZ - 1) & ~(__LDPGSZ - 1))
87
88 /* Address of the bottom of the bss segment. */
89 #define N_BSSADDR(ex) \
90 (N_DATADDR(ex) + (ex).a_data)
91
92 /* Text segment offset. */
93 #define N_TXTOFF(ex) \
94 ( N_GETMAGIC2(ex)==ZMAGIC || N_GETMAGIC2(ex)==(QMAGIC|0x10000) ? \
95 0 : (N_GETMAGIC2(ex)==(ZMAGIC|0x10000) ? __LDPGSZ : \
96 sizeof(struct exec)) )
97
98 /* Data segment offset. */
99 #define N_DATOFF(ex) \
100 N_ALIGN(ex, N_TXTOFF(ex) + (ex).a_text)
101
102 /* Text relocation table offset. */
103 #define N_TRELOFF(ex) \
104 (N_DATOFF(ex) + (ex).a_data)
105
106 /* Data relocation table offset. */
107 #define N_DRELOFF(ex) \
108 (N_TRELOFF(ex) + (ex).a_trsize)
109
110 /* Symbol table offset. */
111 #define N_SYMOFF(ex) \
112 (N_DRELOFF(ex) + (ex).a_drsize)
113
114 /* String table offset. */
115 #define N_STROFF(ex) \
116 (N_SYMOFF(ex) + (ex).a_syms)
117
118 #define _AOUT_INCLUDE_
119 #include <nlist.h>
120
121 #endif /* !_AOUT_H_ */
122