1 /* 2 * 3 * honggfuzz - core macros and helpers 4 * ----------------------------------------- 5 * 6 * Author: Robert Swiecki <swiecki@google.com> 7 * 8 * Copyright 2010-2018 by Google Inc. All Rights Reserved. 9 * 10 * Licensed under the Apache License, Version 2.0 (the "License"); you may 11 * not use this file except in compliance with the License. You may obtain 12 * a copy of the License at 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 16 * Unless required by applicable law or agreed to in writing, software 17 * distributed under the License is distributed on an "AS IS" BASIS, 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 19 * implied. See the License for the specific language governing 20 * permissions and limitations under the License. 21 * 22 */ 23 24 #ifndef _HF_COMMON_COMMON_H_ 25 #define _HF_COMMON_COMMON_H_ 26 27 #include <stdlib.h> 28 #include <unistd.h> 29 30 /* Stringify */ 31 #define HF__XSTR(x) #x 32 #define HF_XSTR(x) HF__XSTR(x) 33 34 #define HF_ATTR_UNUSED __attribute__((unused)) 35 36 #ifndef ARRAYSIZE 37 #define ARRAYSIZE(x) (sizeof(x) / sizeof(*x)) 38 #endif /* ifndef ARRAYSIZE */ 39 40 /* Memory barriers */ 41 #define rmb() __asm__ __volatile__("" ::: "memory") 42 #define wmb() __sync_synchronize() 43 44 /* TEMP_FAILURE_RETRY, but for all OSes */ 45 #ifndef TEMP_FAILURE_RETRY 46 #define TEMP_FAILURE_RETRY(exp) \ 47 ({ \ 48 __typeof(exp) _rc; \ 49 do { \ 50 _rc = (exp); \ 51 } while (_rc == -1 && errno == EINTR); \ 52 _rc; \ 53 }) 54 #endif /* ifndef TEMP_FAILURE_RETRY */ 55 56 #define HF_ATTR_NO_SANITIZE_ADDRESS 57 #ifdef __has_feature 58 #if __has_feature(address_sanitizer) 59 #undef HF_ATTR_NO_SANITIZE_ADDRESS 60 #define HF_ATTR_NO_SANITIZE_ADDRESS __attribute__((no_sanitize("address"))) 61 #endif /* if __has_feature(address_sanitizer) */ 62 #endif /* ifdef __has_feature */ 63 64 #define HF_ATTR_NO_SANITIZE_MEMORY 65 #ifdef __has_feature 66 #if __has_feature(memory_sanitizer) 67 #undef HF_ATTR_NO_SANITIZE_MEMORY 68 #define HF_ATTR_NO_SANITIZE_MEMORY __attribute__((no_sanitize("memory"))) 69 #endif /* if __has_feature(memory_sanitizer) */ 70 #endif /* ifdef __has_feature */ 71 72 #endif /* ifndef _HF_COMMON_COMMON_H_ */ 73