1 /* 2 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 3 * 4 * This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, you can obtain one at https://mozilla.org/MPL/2.0/. 7 * 8 * See the COPYRIGHT file distributed with this work for additional 9 * information regarding copyright ownership. 10 */ 11 12 #pragma once 13 14 #if HAVE_FUNC_ATTRIBUTE_NORETURN 15 #define ISC_NORETURN __attribute__((noreturn)) 16 #else 17 #define ISC_NORETURN 18 #endif 19 20 #if HAVE_FUNC_ATTRIBUTE_RETURNS_NONNULL 21 #define ISC_ATTR_RETURNS_NONNULL __attribute__((returns_nonnull)) 22 #else 23 #define ISC_ATTR_RETURNS_NONNULL 24 #endif 25 26 #ifdef HAVE_FUNC_ATTRIBUTE_MALLOC 27 /* 28 * Indicates that a function is malloc-like, i.e., that the 29 * pointer P returned by the function cannot alias any other 30 * pointer valid when the function returns. 31 */ 32 #define ISC_ATTR_MALLOC __attribute__((malloc)) 33 #if HAVE_MALLOC_EXT_ATTR 34 /* 35 * Associates deallocator as a suitable deallocation function 36 * for pointers returned from the function marked with the attribute. 37 */ 38 #define ISC_ATTR_DEALLOCATOR(deallocator) __attribute__((malloc(deallocator))) 39 /* 40 * Similar to ISC_ATTR_DEALLOCATOR, but allows to speficy an index "idx", 41 * which denotes the positional argument to which when the pointer is passed 42 * in calls to deallocator has the effect of deallocating it. 43 */ 44 #define ISC_ATTR_DEALLOCATOR_IDX(deallocator, idx) \ 45 __attribute__((malloc(deallocator, idx))) 46 /* 47 * Combines both ISC_ATTR_MALLOC and ISC_ATTR_DEALLOCATOR attributes. 48 */ 49 #define ISC_ATTR_MALLOC_DEALLOCATOR(deallocator) \ 50 __attribute__((malloc, malloc(deallocator))) 51 /* 52 * Similar to ISC_ATTR_MALLOC_DEALLOCATOR, but allows to speficy an index "idx", 53 * which denotes the positional argument to which when the pointer is passed 54 * in calls to deallocator has the effect of deallocating it. 55 */ 56 #define ISC_ATTR_MALLOC_DEALLOCATOR_IDX(deallocator, idx) \ 57 __attribute__((malloc, malloc(deallocator, idx))) 58 #else /* #ifdef HAVE_MALLOC_EXT_ATTR */ 59 /* 60 * There is support for malloc attribute but not for 61 * extended attributes, so macros that combine attribute malloc 62 * with a deallocator will only expand to malloc attribute. 63 */ 64 #define ISC_ATTR_DEALLOCATOR(deallocator) 65 #define ISC_ATTR_DEALLOCATOR_IDX(deallocator, idx) 66 #define ISC_ATTR_MALLOC_DEALLOCATOR(deallocator) ISC_ATTR_MALLOC 67 #define ISC_ATTR_MALLOC_DEALLOCATOR_IDX(deallocator, idx) ISC_ATTR_MALLOC 68 #endif 69 #else /* #ifdef HAVE_FUNC_ATTRIBUTE_MALLOC */ 70 /* 71 * There is no support for malloc attribute. 72 */ 73 #define ISC_ATTR_MALLOC 74 #define ISC_ATTR_DEALLOCATOR(deallocator) 75 #define ISC_ATTR_DEALLOCATOR_IDX(deallocator, idx) 76 #define ISC_ATTR_MALLOC_DEALLOCATOR(deallocator) 77 #define ISC_ATTR_MALLOC_DEALLOCATOR_IDX(deallocator, idx) 78 #endif /* HAVE_FUNC_ATTRIBUTE_MALLOC */ 79