1 | /*- |
---|
2 | * Copyright (c) 2009 Joseph Koshy |
---|
3 | * All rights reserved. |
---|
4 | * |
---|
5 | * Redistribution and use in source and binary forms, with or without |
---|
6 | * modification, are permitted provided that the following conditions |
---|
7 | * are met: |
---|
8 | * 1. Redistributions of source code must retain the above copyright |
---|
9 | * notice, this list of conditions and the following disclaimer. |
---|
10 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
11 | * notice, this list of conditions and the following disclaimer in the |
---|
12 | * documentation and/or other materials provided with the distribution. |
---|
13 | * |
---|
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
---|
15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
---|
18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
24 | * SUCH DAMAGE. |
---|
25 | * |
---|
26 | * $Id: _elftc.h 2064 2011-10-26 15:12:32Z jkoshy $ |
---|
27 | */ |
---|
28 | |
---|
29 | /** |
---|
30 | ** Miscellanous definitions needed by multiple components. |
---|
31 | **/ |
---|
32 | |
---|
33 | #ifndef _ELFTC_H |
---|
34 | #define _ELFTC_H |
---|
35 | |
---|
36 | #ifndef NULL |
---|
37 | #define NULL ((void *) 0) |
---|
38 | #endif |
---|
39 | |
---|
40 | #ifndef offsetof |
---|
41 | #define offsetof(T, M) ((int) &((T*) 0) -> M) |
---|
42 | #endif |
---|
43 | |
---|
44 | /* |
---|
45 | * Supply macros missing from <sys/queue.h> |
---|
46 | */ |
---|
47 | |
---|
48 | #ifndef STAILQ_FOREACH_SAFE |
---|
49 | #define STAILQ_FOREACH_SAFE(var, head, field, tvar) \ |
---|
50 | for ((var) = STAILQ_FIRST((head)); \ |
---|
51 | (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \ |
---|
52 | (var) = (tvar)) |
---|
53 | #endif |
---|
54 | |
---|
55 | #ifndef STAILQ_LAST |
---|
56 | #define STAILQ_LAST(head, type, field) \ |
---|
57 | (STAILQ_EMPTY((head)) ? \ |
---|
58 | NULL : \ |
---|
59 | ((struct type *)(void *) \ |
---|
60 | ((char *)((head)->stqh_last) - offsetof(struct type, field)))) |
---|
61 | #endif |
---|
62 | |
---|
63 | #ifndef TAILQ_FOREACH_SAFE |
---|
64 | #define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ |
---|
65 | for ((var) = TAILQ_FIRST((head)); \ |
---|
66 | (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \ |
---|
67 | (var) = (tvar)) |
---|
68 | #endif |
---|
69 | |
---|
70 | /* |
---|
71 | * VCS Ids. |
---|
72 | */ |
---|
73 | |
---|
74 | #ifndef ELFTC_VCSID |
---|
75 | |
---|
76 | #if defined(__FreeBSD__) |
---|
77 | #define ELFTC_VCSID(ID) __FBSDID(ID) |
---|
78 | #endif |
---|
79 | |
---|
80 | #if defined(__linux__) || defined(__GNU__) || defined(__GLIBC__) |
---|
81 | #if defined(__GNUC__) |
---|
82 | #define ELFTC_VCSID(ID) __asm__(".ident\t\"" ID "\"") |
---|
83 | #else |
---|
84 | #define ELFTC_VCSID(ID) /**/ |
---|
85 | #endif |
---|
86 | #endif |
---|
87 | |
---|
88 | #if defined(__NetBSD__) |
---|
89 | #define ELFTC_VCSID(ID) __RCSID(ID) |
---|
90 | #endif |
---|
91 | |
---|
92 | #endif /* ELFTC_VCSID */ |
---|
93 | |
---|
94 | /* |
---|
95 | * Provide an equivalent for getprogname(3). |
---|
96 | */ |
---|
97 | |
---|
98 | #ifndef ELFTC_GETPROGNAME |
---|
99 | |
---|
100 | #if defined(__FreeBSD__) || defined(__NetBSD__) |
---|
101 | |
---|
102 | #include <stdlib.h> |
---|
103 | |
---|
104 | #define ELFTC_GETPROGNAME() getprogname() |
---|
105 | |
---|
106 | #endif /* defined(__FreeBSD__) || defined(__NetBSD__) */ |
---|
107 | |
---|
108 | |
---|
109 | #if defined(__linux__) |
---|
110 | |
---|
111 | /* |
---|
112 | * GLIBC based systems have a global 'char *' pointer referencing |
---|
113 | * the executable's name. |
---|
114 | */ |
---|
115 | extern const char *program_invocation_short_name; |
---|
116 | |
---|
117 | #define ELFTC_GETPROGNAME() program_invocation_short_name |
---|
118 | |
---|
119 | #endif /* __linux__ */ |
---|
120 | |
---|
121 | #endif /* ELFTC_GETPROGNAME */ |
---|
122 | |
---|
123 | /** |
---|
124 | ** Per-OS configuration. |
---|
125 | **/ |
---|
126 | |
---|
127 | #if defined(__linux__) |
---|
128 | |
---|
129 | #include <endian.h> |
---|
130 | |
---|
131 | #define ELFTC_BYTE_ORDER __BYTE_ORDER |
---|
132 | #define ELFTC_BYTE_ORDER_LITTLE_ENDIAN __LITTLE_ENDIAN |
---|
133 | #define ELFTC_BYTE_ORDER_BIG_ENDIAN __BIG_ENDIAN |
---|
134 | |
---|
135 | /* |
---|
136 | * Debian GNU/Linux is missing strmode(3). |
---|
137 | */ |
---|
138 | #define ELFTC_HAVE_STRMODE 0 |
---|
139 | |
---|
140 | /* Whether we need to supply {be,le}32dec. */ |
---|
141 | #define ELFTC_NEED_BYTEORDER_EXTENSIONS 1 |
---|
142 | |
---|
143 | #define roundup2 roundup |
---|
144 | |
---|
145 | #endif /* __linux__ */ |
---|
146 | |
---|
147 | |
---|
148 | #if defined(__FreeBSD__) |
---|
149 | |
---|
150 | #include <osreldate.h> |
---|
151 | #include <sys/endian.h> |
---|
152 | |
---|
153 | #define ELFTC_BYTE_ORDER _BYTE_ORDER |
---|
154 | #define ELFTC_BYTE_ORDER_LITTLE_ENDIAN _LITTLE_ENDIAN |
---|
155 | #define ELFTC_BYTE_ORDER_BIG_ENDIAN _BIG_ENDIAN |
---|
156 | |
---|
157 | #define ELFTC_HAVE_STRMODE 1 |
---|
158 | #if __FreeBSD_version <= 900000 |
---|
159 | #define ELFTC_BROKEN_YY_NO_INPUT 1 |
---|
160 | #endif |
---|
161 | #endif /* __FreeBSD__ */ |
---|
162 | |
---|
163 | |
---|
164 | #if defined(__NetBSD__) |
---|
165 | |
---|
166 | #include <sys/endian.h> |
---|
167 | |
---|
168 | #define ELFTC_BYTE_ORDER _BYTE_ORDER |
---|
169 | #define ELFTC_BYTE_ORDER_LITTLE_ENDIAN _LITTLE_ENDIAN |
---|
170 | #define ELFTC_BYTE_ORDER_BIG_ENDIAN _BIG_ENDIAN |
---|
171 | |
---|
172 | #define ELFTC_HAVE_STRMODE 1 |
---|
173 | #define ELFTC_BROKEN_YY_NO_INPUT 1 |
---|
174 | #endif /* __NetBSD __ */ |
---|
175 | |
---|
176 | #endif /* _ELFTC_H */ |
---|