Disallow disabling DisableDebuggerAttachment on runnning Tor
[tor.git] / src / common / torint.h
blobaf975471f1c36e4207e1e9b7b9639ebee0767ce4
1 /* Copyright (c) 2003, Roger Dingledine
2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3 * Copyright (c) 2007-2011, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
6 /**
7 * \file torint.h
8 * \brief Header file to define uint32_t and friends
9 **/
11 #ifndef _TOR_TORINT_H
12 #define _TOR_TORINT_H
14 #include "orconfig.h"
16 #ifdef HAVE_STDINT_H
17 #include <stdint.h>
18 #endif
19 #ifdef HAVE_SYS_TYPES_H
20 #include <sys/types.h>
21 #endif
22 #ifdef HAVE_LIMITS_H
23 #include <limits.h>
24 #endif
25 #ifdef HAVE_SYS_LIMITS_H
26 #include <sys/limits.h>
27 #endif
28 #ifdef HAVE_MACHINE_LIMITS_H
29 #if !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__)
30 /* FreeBSD has a bug where it complains that this file is obsolete,
31 and I should migrate to using sys/limits. It complains even when
32 I include both.
33 __FreeBSD_kernel__ is defined by Debian GNU/kFreeBSD which
34 does the same thing (but doesn't defined __FreeBSD__).
36 #include <machine/limits.h>
37 #endif
38 #endif
39 #ifdef HAVE_INTTYPES_H
40 #include <inttypes.h>
41 #endif
43 #if (SIZEOF_INT8_T != 0)
44 #define HAVE_INT8_T
45 #endif
46 #if (SIZEOF_INT16_T != 0)
47 #define HAVE_INT16_T
48 #endif
49 #if (SIZEOF_INT32_T != 0)
50 #define HAVE_INT32_T
51 #endif
52 #if (SIZEOF_INT64_T != 0)
53 #define HAVE_INT64_T
54 #endif
55 #if (SIZEOF_UINT8_T != 0)
56 #define HAVE_UINT8_T
57 #endif
58 #if (SIZEOF_UINT16_T != 0)
59 #define HAVE_UINT16_T
60 #endif
61 #if (SIZEOF_UINT32_T != 0)
62 #define HAVE_UINT32_T
63 #endif
64 #if (SIZEOF_UINT64_T != 0)
65 #define HAVE_UINT64_T
66 #endif
67 #if (SIZEOF_INTPTR_T != 0)
68 #define HAVE_INTPTR_T
69 #endif
70 #if (SIZEOF_UINTPTR_T != 0)
71 #define HAVE_UINTPTR_T
72 #endif
74 #if (SIZEOF_CHAR == 1)
75 #ifndef HAVE_INT8_T
76 typedef signed char int8_t;
77 #define HAVE_INT8_T
78 #endif
79 #ifndef HAVE_UINT8_T
80 typedef unsigned char uint8_t;
81 #define HAVE_UINT8_T
82 #endif
83 #endif
85 #if (SIZEOF_SHORT == 2)
86 #ifndef HAVE_INT16_T
87 typedef signed short int16_t;
88 #define HAVE_INT16_T
89 #endif
90 #ifndef HAVE_UINT16_T
91 typedef unsigned short uint16_t;
92 #define HAVE_UINT16_T
93 #endif
94 #endif
96 #if (SIZEOF_INT == 2)
97 #ifndef HAVE_INT16_T
98 typedef signed int int16_t;
99 #define HAVE_INT16_T
100 #endif
101 #ifndef HAVE_UINT16_T
102 typedef unsigned int uint16_t;
103 #define HAVE_UINT16_T
104 #endif
105 #elif (SIZEOF_INT == 4)
106 #ifndef HAVE_INT32_T
107 typedef signed int int32_t;
108 #define HAVE_INT32_T
109 #endif
110 #ifndef HAVE_UINT32_T
111 typedef unsigned int uint32_t;
112 #define HAVE_UINT32_T
113 #endif
114 #ifndef UINT16_MAX
115 #define UINT16_MAX 0xffffu
116 #endif
117 #ifndef INT16_MAX
118 #define INT16_MAX 0x7fff
119 #endif
120 #ifndef INT16_MIN
121 #define INT16_MIN (-INT16_MAX-1)
122 #endif
123 #ifndef UINT32_MAX
124 #define UINT32_MAX 0xffffffffu
125 #endif
126 #ifndef INT32_MAX
127 #define INT32_MAX 0x7fffffff
128 #endif
129 #ifndef INT32_MIN
130 #define INT32_MIN (-2147483647-1)
131 #endif
132 #endif
134 #if (SIZEOF_LONG == 4)
135 #ifndef HAVE_INT32_T
136 typedef signed long int32_t;
137 #define HAVE_INT32_T
138 #endif
139 #ifndef HAVE_UINT32_T
140 typedef unsigned long uint32_t;
141 #define HAVE_UINT32_T
142 #ifndef UINT32_MAX
143 #define UINT32_MAX 0xfffffffful
144 #endif
145 #endif
146 #elif (SIZEOF_LONG == 8)
147 #ifndef HAVE_INT64_T
148 typedef signed long int64_t;
149 #define HAVE_INT64_T
150 #endif
151 #ifndef HAVE_UINT32_T
152 typedef unsigned long uint64_t;
153 #define HAVE_UINT32_T
154 #endif
155 #ifndef UINT64_MAX
156 #define UINT64_MAX 0xfffffffffffffffful
157 #endif
158 #endif
160 #if (SIZEOF_LONG_LONG == 8)
161 #ifndef HAVE_INT64_T
162 typedef signed long long int64_t;
163 #define HAVE_INT64_T
164 #endif
165 #ifndef HAVE_UINT64_T
166 typedef unsigned long long uint64_t;
167 #define HAVE_UINT64_T
168 #endif
169 #ifndef UINT64_MAX
170 #define UINT64_MAX 0xffffffffffffffffull
171 #endif
172 #ifndef INT64_MAX
173 #define INT64_MAX 0x7fffffffffffffffll
174 #endif
175 #endif
177 #if (SIZEOF___INT64 == 8)
178 #ifndef HAVE_INT64_T
179 typedef signed __int64 int64_t;
180 #define HAVE_INT64_T
181 #endif
182 #ifndef HAVE_UINT64_T
183 typedef unsigned __int64 uint64_t;
184 #define HAVE_UINT64_T
185 #endif
186 #ifndef UINT64_MAX
187 #define UINT64_MAX 0xffffffffffffffffui64
188 #endif
189 #ifndef INT64_MAX
190 #define INT64_MAX 0x7fffffffffffffffi64
191 #endif
192 #endif
194 #ifndef HAVE_SSIZE_T
195 #if SIZEOF_SIZE_T == 8
196 typedef int64_t ssize_t;
197 #elif SIZEOF_SIZE_T == 4
198 typedef int32_t ssize_t;
199 #else
200 #error "Can't define ssize_t."
201 #endif
202 #endif
204 #if (SIZEOF_VOID_P > 4 && SIZEOF_VOID_P <= 8)
205 #ifndef HAVE_INTPTR_T
206 typedef int64_t intptr_t;
207 #endif
208 #ifndef HAVE_UINTPTR_T
209 typedef uint64_t uintptr_t;
210 #endif
211 #elif (SIZEOF_VOID_P > 2 && SIZEOF_VOID_P <= 4)
212 #ifndef HAVE_INTPTR_T
213 typedef int32_t intptr_t;
214 #endif
215 #ifndef HAVE_UINTPTR_T
216 typedef uint32_t uintptr_t;
217 #endif
218 #else
219 #error "void * is either >8 bytes or <= 2. In either case, I am confused."
220 #endif
222 #ifndef HAVE_INT8_T
223 #error "Missing type int8_t"
224 #endif
225 #ifndef HAVE_UINT8_T
226 #error "Missing type uint8_t"
227 #endif
228 #ifndef HAVE_INT16_T
229 #error "Missing type int16_t"
230 #endif
231 #ifndef HAVE_UINT16_T
232 #error "Missing type uint16_t"
233 #endif
234 #ifndef HAVE_INT32_T
235 #error "Missing type int32_t"
236 #endif
237 #ifndef HAVE_UINT32_T
238 #error "Missing type uint32_t"
239 #endif
240 #ifndef HAVE_INT64_T
241 #error "Missing type int64_t"
242 #endif
243 #ifndef HAVE_UINT64_T
244 #error "Missing type uint64_t"
245 #endif
247 /* This assumes a sane (2's-complement) representation. But if you
248 * aren't 2's complement, and you don't define LONG_MAX, then you're so
249 * bizarre that I want nothing to do with you. */
250 #ifndef USING_TWOS_COMPLEMENT
251 #error "Seems that your platform doesn't use 2's complement arithmetic. Argh."
252 #endif
253 #ifndef LONG_MAX
254 #if (SIZEOF_LONG == 4)
255 #define LONG_MAX 0x7fffffffL
256 #elif (SIZEOF_LONG == 8)
257 #define LONG_MAX 0x7fffffffffffffffL
258 #else
259 #error "Can't define LONG_MAX"
260 #endif
261 #endif
263 #ifndef INT_MAX
264 #if (SIZEOF_INT == 4)
265 #define INT_MAX 0x7fffffffL
266 #elif (SIZEOF_INT == 8)
267 #define INT_MAX 0x7fffffffffffffffL
268 #else
269 #error "Can't define INT_MAX"
270 #endif
271 #endif
273 #ifndef UINT_MAX
274 #if (SIZEOF_INT == 2)
275 #define UINT_MAX 0xffffu
276 #elif (SIZEOF_INT == 4)
277 #define UINT_MAX 0xffffffffu
278 #elif (SIZEOF_INT == 8)
279 #define UINT_MAX 0xffffffffffffffffu
280 #else
281 #error "Can't define UINT_MAX"
282 #endif
283 #endif
285 #ifndef SHORT_MAX
286 #if (SIZEOF_SHORT == 2)
287 #define SHORT_MAX 0x7fff
288 #elif (SIZEOF_SHORT == 4)
289 #define SHORT_MAX 0x7fffffff
290 #else
291 #error "Can't define SHORT_MAX"
292 #endif
293 #endif
295 #ifndef TIME_MAX
297 #ifdef TIME_T_IS_SIGNED
299 #if (SIZEOF_TIME_T == SIZEOF_INT)
300 #define TIME_MAX ((time_t)INT_MAX)
301 #elif (SIZEOF_TIME_T == SIZEOF_LONG)
302 #define TIME_MAX ((time_t)LONG_MAX)
303 #elif (SIZEOF_TIME_T == 8)
304 #define TIME_MAX ((time_t)INT64_MAX)
305 #else
306 #error "Can't define (signed) TIME_MAX"
307 #endif
309 #else
310 /* Unsigned case */
311 #if (SIZEOF_TIME_T == 4)
312 #define TIME_MAX ((time_t)UINT32_MAX)
313 #elif (SIZEOF_TIME_T == 8)
314 #define TIME_MAX ((time_t)UINT64_MAX)
315 #else
316 #error "Can't define (unsigned) TIME_MAX"
317 #endif
318 #endif /* time_t_is_signed */
319 #endif /* ifndef(TIME_MAX) */
321 #ifndef SIZE_T_MAX
322 #if (SIZEOF_SIZE_T == 4)
323 #define SIZE_T_MAX UINT32_MAX
324 #elif (SIZEOF_SIZE_T == 8)
325 #define SIZE_T_MAX UINT64_MAX
326 #else
327 #error "Can't define SIZE_T_MAX"
328 #endif
329 #endif
331 #ifndef SSIZE_T_MAX
332 #if (SIZEOF_SIZE_T == 4)
333 #define SSIZE_T_MAX INT32_MAX
334 #elif (SIZEOF_SIZE_T == 8)
335 #define SSIZE_T_MAX INT64_MAX
336 #else
337 #error "Can't define SSIZE_T_MAX"
338 #endif
339 #endif
341 /** Any ssize_t larger than this amount is likely to be an underflow. */
342 #define SSIZE_T_CEILING ((ssize_t)(SSIZE_T_MAX-16))
343 /** Any size_t larger than this amount is likely to be an underflow. */
344 #define SIZE_T_CEILING ((size_t)(SSIZE_T_MAX-16))
346 #endif /* __TORINT_H */