VM: simplify slab allocator
[minix.git] / lib / libelf / _elftc.h
blob63baa44a81d830190eb7b7ba47539742110b1c3e
1 /*-
2 * Copyright (c) 2009 Joseph Koshy
3 * All rights reserved.
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.
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.
26 * $Id$
29 /**
30 ** Miscellanous definitions needed by multiple components.
31 **/
33 #ifndef _ELFTC_H
34 #define _ELFTC_H
36 #ifndef NULL
37 #define NULL ((void *) 0)
38 #endif
40 #ifndef offsetof
41 #define offsetof(T, M) ((int) &((T*) 0) -> M)
42 #endif
45 * Supply macros missing from <sys/queue.h>
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
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
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
71 * VCS Ids.
74 #ifndef ELFTC_VCSID
76 #if defined(__FreeBSD__)
77 #define ELFTC_VCSID(ID) __FBSDID(ID)
78 #endif
80 #if defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)
81 #define ELFTC_VCSID(ID) /**/
82 #endif
84 #if defined(__NetBSD__)
85 #define ELFTC_VCSID(ID) __RCSID(ID)
86 #endif
88 #endif /* ELFTC_VCSID */
91 * Provide an equivalent for getprogname(3).
94 #ifndef ELFTC_GETPROGNAME
96 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__minix)
98 #include <stdlib.h>
100 #define ELFTC_GETPROGNAME() getprogname()
102 #endif /* defined(__FreeBSD__) || defined(__NetBSD__) || defined(__minix) */
105 #if defined(__linux__)
108 * GLIBC based systems have a global 'char *' pointer referencing
109 * the executable's name.
111 extern const char *program_invocation_short_name;
113 #define ELFTC_GETPROGNAME() program_invocation_short_name
115 #endif /* __linux__ */
117 #endif /* ELFTC_GETPROGNAME */
120 ** Per-OS configuration.
123 #if defined(__linux__)
125 #include <endian.h>
127 #define ELFTC_BYTE_ORDER __BYTE_ORDER
128 #define ELFTC_BYTE_ORDER_LITTLE_ENDIAN __LITTLE_ENDIAN
129 #define ELFTC_BYTE_ORDER_BIG_ENDIAN __BIG_ENDIAN
132 * Debian GNU/Linux is missing strmode(3).
134 #define ELFTC_HAVE_STRMODE 0
136 /* Whether we need to supply {be,le}32dec. */
137 #define ELFTC_NEED_BYTEORDER_EXTENSIONS 1
139 #define roundup2 roundup
141 #endif /* __linux__ */
144 #if defined(__FreeBSD__)
146 #include <sys/endian.h>
148 #define ELFTC_BYTE_ORDER _BYTE_ORDER
149 #define ELFTC_BYTE_ORDER_LITTLE_ENDIAN _LITTLE_ENDIAN
150 #define ELFTC_BYTE_ORDER_BIG_ENDIAN _BIG_ENDIAN
152 #define ELFTC_HAVE_STRMODE 1
153 #endif /* __FreeBSD__ */
156 #if defined(__NetBSD__) || defined(__minix)
158 #include <sys/endian.h>
160 #define ELFTC_BYTE_ORDER _BYTE_ORDER
161 #define ELFTC_BYTE_ORDER_LITTLE_ENDIAN _LITTLE_ENDIAN
162 #define ELFTC_BYTE_ORDER_BIG_ENDIAN _BIG_ENDIAN
164 #define ELFTC_HAVE_STRMODE 1
165 #endif /* __NetBSD __ || __minix */
167 #endif /* _ELFTC_H */