_elftc.h
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 2495 2012-04-23 05:31:56Z 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 /* --QUEUE-MACROS-- [[ */ 45 46 /* 47 * Supply macros missing from <sys/queue.h> 48 */ 49 50 /* 51 * Copyright (c) 1991, 1993 52 * The Regents of the University of California. All rights reserved. 53 * 54 * Redistribution and use in source and binary forms, with or without 55 * modification, are permitted provided that the following conditions 56 * are met: 57 * 1. Redistributions of source code must retain the above copyright 58 * notice, this list of conditions and the following disclaimer. 59 * 2. Redistributions in binary form must reproduce the above copyright 60 * notice, this list of conditions and the following disclaimer in the 61 * documentation and/or other materials provided with the distribution. 62 * 3. Neither the name of the University nor the names of its contributors 63 * may be used to endorse or promote products derived from this software 64 * without specific prior written permission. 65 * 66 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 67 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 68 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 69 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 70 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 71 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 72 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 73 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 74 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 75 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 76 * SUCH DAMAGE. 77 */ 78 79 #ifndef STAILQ_CONCAT 80 #define STAILQ_CONCAT(head1, head2) do { \ 81 if (!STAILQ_EMPTY((head2))) { \ 82 *(head1)->stqh_last = (head2)->stqh_first; \ 83 (head1)->stqh_last = (head2)->stqh_last; \ 84 STAILQ_INIT((head2)); \ 85 } \ 86 } while (/*CONSTCOND*/0) 87 #endif 88 89 #ifndef STAILQ_EMPTY 90 #define STAILQ_EMPTY(head) ((head)->stqh_first == NULL) 91 #endif 92 93 #ifndef STAILQ_ENTRY 94 #define STAILQ_ENTRY(type) \ 95 struct { \ 96 struct type *stqe_next; /* next element */ \ 97 } 98 #endif 99 100 #ifndef STAILQ_FIRST 101 #define STAILQ_FIRST(head) ((head)->stqh_first) 102 #endif 103 104 #ifndef STAILQ_HEAD 105 #define STAILQ_HEAD(name, type) \ 106 struct name { \ 107 struct type *stqh_first; /* first element */ \ 108 struct type **stqh_last; /* addr of last next element */ \ 109 } 110 #endif 111 112 #ifndef STAILQ_HEAD_INITIALIZER 113 #define STAILQ_HEAD_INITIALIZER(head) \ 114 { NULL, &(head).stqh_first } 115 #endif 116 117 #ifndef STAILQ_FOREACH 118 #define STAILQ_FOREACH(var, head, field) \ 119 for ((var) = ((head)->stqh_first); \ 120 (var); \ 121 (var) = ((var)->field.stqe_next)) 122 #endif 123 124 #ifndef STAILQ_FOREACH_SAFE 125 #define STAILQ_FOREACH_SAFE(var, head, field, tvar) \ 126 for ((var) = STAILQ_FIRST((head)); \ 127 (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \ 128 (var) = (tvar)) 129 #endif 130 131 #ifndef STAILQ_INIT 132 #define STAILQ_INIT(head) do { \ 133 (head)->stqh_first = NULL; \ 134 (head)->stqh_last = &(head)->stqh_first; \ 135 } while (/*CONSTCOND*/0) 136 #endif 137 138 #ifndef STAILQ_INSERT_HEAD 139 #define STAILQ_INSERT_HEAD(head, elm, field) do { \ 140 if (((elm)->field.stqe_next = (head)->stqh_first) == NULL) \ 141 (head)->stqh_last = &(elm)->field.stqe_next; \ 142 (head)->stqh_first = (elm); \ 143 } while (/*CONSTCOND*/0) 144 #endif 145 146 #ifndef STAILQ_INSERT_TAIL 147 #define STAILQ_INSERT_TAIL(head, elm, field) do { \ 148 (elm)->field.stqe_next = NULL; \ 149 *(head)->stqh_last = (elm); \ 150 (head)->stqh_last = &(elm)->field.stqe_next; \ 151 } while (/*CONSTCOND*/0) 152 #endif 153 154 #ifndef STAILQ_INSERT_AFTER 155 #define STAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ 156 if (((elm)->field.stqe_next = (listelm)->field.stqe_next) == NULL)\ 157 (head)->stqh_last = &(elm)->field.stqe_next; \ 158 (listelm)->field.stqe_next = (elm); \ 159 } while (/*CONSTCOND*/0) 160 #endif 161 162 #ifndef STAILQ_LAST 163 #define STAILQ_LAST(head, type, field) \ 164 (STAILQ_EMPTY((head)) ? \ 165 NULL : ((struct type *)(void *) \ 166 ((char *)((head)->stqh_last) - offsetof(struct type, field)))) 167 #endif 168 169 #ifndef STAILQ_NEXT 170 #define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next) 171 #endif 172 173 #ifndef STAILQ_REMOVE 174 #define STAILQ_REMOVE(head, elm, type, field) do { \ 175 if ((head)->stqh_first == (elm)) { \ 176 STAILQ_REMOVE_HEAD((head), field); \ 177 } else { \ 178 struct type *curelm = (head)->stqh_first; \ 179 while (curelm->field.stqe_next != (elm)) \ 180 curelm = curelm->field.stqe_next; \ 181 if ((curelm->field.stqe_next = \ 182 curelm->field.stqe_next->field.stqe_next) == NULL) \ 183 (head)->stqh_last = &(curelm)->field.stqe_next; \ 184 } \ 185 } while (/*CONSTCOND*/0) 186 #endif 187 188 #ifndef STAILQ_REMOVE_HEAD 189 #define STAILQ_REMOVE_HEAD(head, field) do { \ 190 if (((head)->stqh_first = (head)->stqh_first->field.stqe_next) == \ 191 NULL) \ 192 (head)->stqh_last = &(head)->stqh_first; \ 193 } while (/*CONSTCOND*/0) 194 #endif 195 196 #ifndef TAILQ_FOREACH_SAFE 197 #define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ 198 for ((var) = TAILQ_FIRST((head)); \ 199 (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \ 200 (var) = (tvar)) 201 #endif 202 203 /* ]] --QUEUE-MACROS-- */ 204 205 /* 206 * VCS Ids. 207 */ 208 209 #ifndef ELFTC_VCSID 210 211 #if defined(__DragonFly__) 212 #define ELFTC_VCSID(ID) __RCSID(ID) 213 #endif 214 215 #if defined(__FreeBSD__) 216 #define ELFTC_VCSID(ID) __FBSDID(ID) 217 #endif 218 219 #if defined(__linux__) || defined(__GNU__) || defined(__GLIBC__) || defined(__APPLE__) 220 #if defined(__GNUC__) 221 #define ELFTC_VCSID(ID) __asm__(".ident\t\"" ID "\"") 222 #else 223 #define ELFTC_VCSID(ID) /**/ 224 #endif 225 #endif 226 227 #if defined(__minix) 228 #if defined(__GNUC__) 229 #define ELFTC_VCSID(ID) __asm__(".ident\t\"" ID "\"") 230 #else 231 #define ELFTC_VCSID(ID) /**/ 232 #endif /* __GNU__ */ 233 #endif 234 235 #if defined(__NetBSD__) 236 #define ELFTC_VCSID(ID) __RCSID(ID) 237 #endif 238 239 #if defined(__OpenBSD__) 240 #if defined(__GNUC__) 241 #define ELFTC_VCSID(ID) __asm__(".ident\t\"" ID "\"") 242 #else 243 #define ELFTC_VCSID(ID) /**/ 244 #endif /* __GNUC__ */ 245 #endif 246 247 #endif /* ELFTC_VCSID */ 248 249 /* 250 * Provide an equivalent for getprogname(3). 251 */ 252 253 #ifndef ELFTC_GETPROGNAME 254 255 #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__minix) || \ 256 defined(__NetBSD__) || defined(__APPLE__) 257 258 #include <stdlib.h> 259 260 #define ELFTC_GETPROGNAME() getprogname() 261 262 #endif /* __DragonFly__ || __FreeBSD__ || __minix || __NetBSD__ */ 263 264 265 #if defined(__GLIBC__) 266 267 /* 268 * GLIBC based systems have a global 'char *' pointer referencing 269 * the executable's name. 270 */ 271 272 /* XXX: defined in errno.h 273 extern const char *program_invocation_short_name; 274 */ 275 276 #define ELFTC_GETPROGNAME() program_invocation_short_name 277 278 #endif /* __GLIBC__ */ 279 280 281 #if defined(__OpenBSD__) 282 283 extern const char *__progname; 284 285 #define ELFTC_GETPROGNAME() __progname 286 287 #endif /* __OpenBSD__ */ 288 289 #endif /* ELFTC_GETPROGNAME */ 290 291 292 /** 293 ** Per-OS configuration. 294 **/ 295 296 #if defined(__DragonFly__) 297 298 #include <osreldate.h> 299 #include <sys/endian.h> 300 301 #define ELFTC_BYTE_ORDER _BYTE_ORDER 302 #define ELFTC_BYTE_ORDER_LITTLE_ENDIAN _LITTLE_ENDIAN 303 #define ELFTC_BYTE_ORDER_BIG_ENDIAN _BIG_ENDIAN 304 305 #define ELFTC_HAVE_MMAP 1 306 307 #endif 308 309 #if defined(__GLIBC__) 310 311 #include <endian.h> 312 313 #define ELFTC_BYTE_ORDER __BYTE_ORDER 314 #define ELFTC_BYTE_ORDER_LITTLE_ENDIAN __LITTLE_ENDIAN 315 #define ELFTC_BYTE_ORDER_BIG_ENDIAN __BIG_ENDIAN 316 317 #define ELFTC_HAVE_MMAP 1 318 319 /* 320 * Debian GNU/Linux and Debian GNU/kFreeBSD do not have strmode(3). 321 */ 322 #define ELFTC_HAVE_STRMODE 0 323 324 /* Whether we need to supply {be,le}32dec. */ 325 #define ELFTC_NEED_BYTEORDER_EXTENSIONS 1 326 327 #define roundup2 roundup 328 329 #endif /* __GLIBC__ */ 330 331 332 #if defined(__FreeBSD__) 333 334 #include <osreldate.h> 335 #include <sys/endian.h> 336 337 #define ELFTC_BYTE_ORDER _BYTE_ORDER 338 #define ELFTC_BYTE_ORDER_LITTLE_ENDIAN _LITTLE_ENDIAN 339 #define ELFTC_BYTE_ORDER_BIG_ENDIAN _BIG_ENDIAN 340 341 #define ELFTC_HAVE_MMAP 1 342 #define ELFTC_HAVE_STRMODE 1 343 #if __FreeBSD_version <= 900000 344 #define ELFTC_BROKEN_YY_NO_INPUT 1 345 #endif 346 #endif /* __FreeBSD__ */ 347 348 349 #if defined(__minix) 350 #define ELFTC_HAVE_MMAP 0 351 #endif /* __minix */ 352 353 354 #if defined(__NetBSD__) || defined(__APPLE__) 355 356 #include <sys/param.h> 357 #ifndef __APPLE__ 358 #include <sys/endian.h> 359 #else 360 #include <machine/endian.h> 361 #define roundup2 roundup 362 #endif 363 364 #define ELFTC_BYTE_ORDER _BYTE_ORDER 365 #define ELFTC_BYTE_ORDER_LITTLE_ENDIAN _LITTLE_ENDIAN 366 #define ELFTC_BYTE_ORDER_BIG_ENDIAN _BIG_ENDIAN 367 368 #define ELFTC_HAVE_MMAP 1 369 #define ELFTC_HAVE_STRMODE 1 370 #if __NetBSD_Version__ <= 599002100 371 /* from src/doc/CHANGES: flex(1): Import flex-2.5.35 [christos 20091025] */ 372 /* and 5.99.21 was from Wed Oct 21 21:28:36 2009 UTC */ 373 # define ELFTC_BROKEN_YY_NO_INPUT 1 374 #endif 375 #endif /* __NetBSD __ */ 376 377 378 #if defined(__OpenBSD__) 379 380 #include <sys/param.h> 381 #include <sys/endian.h> 382 383 #define ELFTC_BYTE_ORDER _BYTE_ORDER 384 #define ELFTC_BYTE_ORDER_LITTLE_ENDIAN _LITTLE_ENDIAN 385 #define ELFTC_BYTE_ORDER_BIG_ENDIAN _BIG_ENDIAN 386 387 #define ELFTC_HAVE_MMAP 1 388 #define ELFTC_HAVE_STRMODE 1 389 390 #define ELFTC_NEED_BYTEORDER_EXTENSIONS 1 391 #define roundup2 roundup 392 393 #endif /* __OpenBSD__ */ 394 395 #endif /* _ELFTC_H */