OLD | NEW |
(Empty) | |
| 1 /* |
| 2 american fuzzy lop - type definitions and minor macros |
| 3 ------------------------------------------------------ |
| 4 |
| 5 Written and maintained by Michal Zalewski <lcamtuf@google.com> |
| 6 |
| 7 Copyright 2013, 2014, 2015 Google Inc. All rights reserved. |
| 8 |
| 9 Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 you may not use this file except in compliance with the License. |
| 11 You may obtain a copy of the License at: |
| 12 |
| 13 http://www.apache.org/licenses/LICENSE-2.0 |
| 14 |
| 15 */ |
| 16 |
| 17 #ifndef _HAVE_TYPES_H |
| 18 #define _HAVE_TYPES_H |
| 19 |
| 20 #include <stdint.h> |
| 21 #include <stdlib.h> |
| 22 |
| 23 typedef uint8_t u8; |
| 24 typedef uint16_t u16; |
| 25 typedef uint32_t u32; |
| 26 |
| 27 /* |
| 28 |
| 29 Ugh. There is an unintended compiler / glibc #include glitch caused by |
| 30 combining the u64 type an %llu in format strings, necessitating a workaround. |
| 31 |
| 32 In essence, the compiler is always looking for 'unsigned long long' for %llu. |
| 33 On 32-bit systems, the u64 type (aliased to uint64_t) is expanded to |
| 34 'unsigned long long' in <bits/types.h>, so everything checks out. |
| 35 |
| 36 But on 64-bit systems, it is #ifdef'ed in the same file as 'unsigned long'. |
| 37 Now, it only happens in circumstances where the type happens to have the |
| 38 expected bit width, *but* the compiler does not know that... and complains |
| 39 about 'unsigned long' being unsafe to pass to %llu. |
| 40 |
| 41 */ |
| 42 |
| 43 #ifdef __x86_64__ |
| 44 typedef unsigned long long u64; |
| 45 #else |
| 46 typedef uint64_t u64; |
| 47 #endif /* ^sizeof(...) */ |
| 48 |
| 49 typedef int8_t s8; |
| 50 typedef int16_t s16; |
| 51 typedef int32_t s32; |
| 52 typedef int64_t s64; |
| 53 |
| 54 #ifndef MIN |
| 55 # define MIN(_a,_b) ((_a) > (_b) ? (_b) : (_a)) |
| 56 # define MAX(_a,_b) ((_a) > (_b) ? (_a) : (_b)) |
| 57 #endif /* !MIN */ |
| 58 |
| 59 #define SWAP16(_x) ({ \ |
| 60 u16 _ret = (_x); \ |
| 61 (u16)((_ret << 8) | (_ret >> 8)); \ |
| 62 }) |
| 63 |
| 64 #define SWAP32(_x) ({ \ |
| 65 u32 _ret = (_x); \ |
| 66 (u32)((_ret << 24) | (_ret >> 24) | \ |
| 67 ((_ret << 8) & 0x00FF0000) | \ |
| 68 ((_ret >> 8) & 0x0000FF00)); \ |
| 69 }) |
| 70 |
| 71 #define R(x) (random() % (x)) |
| 72 |
| 73 #define STRINGIFY_INTERNAL(x) #x |
| 74 #define STRINGIFY(x) STRINGIFY_INTERNAL(x) |
| 75 |
| 76 #define MEM_BARRIER() \ |
| 77 asm volatile("" ::: "memory") |
| 78 |
| 79 #endif /* ! _HAVE_TYPES_H */ |
OLD | NEW |