| 1 |
/* sysprof-macros.h |
| 2 |
* |
| 3 |
* Copyright 2020 Endless OS Foundation |
| 4 |
* |
| 5 |
* Author: |
| 6 |
* - Philip Withnall <[email protected]> |
| 7 |
* |
| 8 |
* Redistribution and use in source and binary forms, with or without |
| 9 |
* modification, are permitted provided that the following conditions are |
| 10 |
* met: |
| 11 |
* |
| 12 |
* 1. Redistributions of source code must retain the above copyright notice, |
| 13 |
* this list of conditions and the following disclaimer. |
| 14 |
* |
| 15 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 16 |
* notice, this list of conditions and the following disclaimer in the |
| 17 |
* documentation and/or other materials provided with the distribution. |
| 18 |
* |
| 19 |
* Subject to the terms and conditions of this license, each copyright holder |
| 20 |
* and contributor hereby grants to those receiving rights under this license |
| 21 |
* a perpetual, worldwide, non-exclusive, no-charge, royalty-free, |
| 22 |
* irrevocable (except for failure to satisfy the conditions of this license) |
| 23 |
* patent license to make, have made, use, offer to sell, sell, import, and |
| 24 |
* otherwise transfer this software, where such license applies only to those |
| 25 |
* patent claims, already acquired or hereafter acquired, licensable by such |
| 26 |
* copyright holder or contributor that are necessarily infringed by: |
| 27 |
* |
| 28 |
* (a) their Contribution(s) (the licensed copyrights of copyright holders |
| 29 |
* and non-copyrightable additions of contributors, in source or binary |
| 30 |
* form) alone; or |
| 31 |
* |
| 32 |
* (b) combination of their Contribution(s) with the work of authorship to |
| 33 |
* which such Contribution(s) was added by such copyright holder or |
| 34 |
* contributor, if, at the time the Contribution is added, such addition |
| 35 |
* causes such combination to be necessarily infringed. The patent license |
| 36 |
* shall not apply to any other combinations which include the |
| 37 |
* Contribution. |
| 38 |
* |
| 39 |
* Except as expressly stated above, no rights or licenses from any copyright |
| 40 |
* holder or contributor is granted under this license, whether expressly, by |
| 41 |
* implication, estoppel or otherwise. |
| 42 |
* |
| 43 |
* DISCLAIMER |
| 44 |
* |
| 45 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 46 |
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 47 |
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 48 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR |
| 49 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 50 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 51 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 52 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 53 |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 54 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 55 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 56 |
* |
| 57 |
* SPDX-License-Identifier: BSD-2-Clause-Patent |
| 58 |
*/ |
| 59 |
|
| 60 |
#pragma once |
| 61 |
|
| 62 |
#include <limits.h> |
| 63 |
|
| 64 |
#ifdef __GNUC__ |
| 65 |
#define SYSPROF_GNUC_CHECK_VERSION(major, minor) \ |
| 66 |
((__GNUC__ > (major)) || \ |
| 67 |
((__GNUC__ == (major)) && \ |
| 68 |
(__GNUC_MINOR__ >= (minor)))) |
| 69 |
#else |
| 70 |
#define SYSPROF_GNUC_CHECK_VERSION(major, minor) 0 |
| 71 |
#endif |
| 72 |
|
| 73 |
#ifdef __cpp_static_assert |
| 74 |
# define SYSPROF_STATIC_ASSERT(expr, msg) static_assert(expr, msg) |
| 75 |
#elif SYSPROF_GNUC_CHECK_VERSION(4, 6) |
| 76 |
# define SYSPROF_STATIC_ASSERT(expr, msg) _Static_assert(expr, msg) |
| 77 |
#else |
| 78 |
# define _SYSPROF_STATIC_ASSERT2(expr, msg, id) typedef char __static_assert_##id[(expr) ? 0 : -1]; |
| 79 |
# define _SYSPROF_STATIC_ASSERT(expr, msg, id) _SYSPROF_STATIC_ASSERT2(expr, msg, id) |
| 80 |
# define SYSPROF_STATIC_ASSERT(expr, msg) _SYSPROF_STATIC_ASSERT(expr, msg, __COUNTER__) |
| 81 |
#endif |
| 82 |
|
| 83 |
#if INT_MAX == LONG_MAX |
| 84 |
#define SYSPROF_INT64_CONSTANT(x) x##ULL |
| 85 |
#define SYSPROF_UINT64_CONSTANT(x) x##LL |
| 86 |
#else |
| 87 |
#define SYSPROF_INT64_CONSTANT(x) x##UL |
| 88 |
#define SYSPROF_UINT64_CONSTANT(x) x##L |
| 89 |
#endif |
| 90 |
|
| 91 |
#ifdef __cplusplus |
| 92 |
#define SYSPROF_BEGIN_DECLS extern "C" { |
| 93 |
#define SYSPROF_END_DECLS } |
| 94 |
#define SYSPROF_RESTRICT /* nothing */ |
| 95 |
#else |
| 96 |
#define SYSPROF_BEGIN_DECLS |
| 97 |
#define SYSPROF_END_DECLS |
| 98 |
# ifndef __GI_SCANNER__ |
| 99 |
# define SYSPROF_RESTRICT restrict |
| 100 |
# else |
| 101 |
# define SYSPROF_RESTRICT /* nothing */ |
| 102 |
# endif |
| 103 |
#endif |
| 104 |
|
| 105 |
#if defined (__GNUC__) |
| 106 |
#define SYSPROF_INTERNAL __attribute__((visibility("hidden"))) |
| 107 |
#else |
| 108 |
#define SYSPROF_INTERNAL |
| 109 |
#endif |
| 110 |
|
| 111 |
#if defined(__GNUC__) |
| 112 |
#define SYSPROF_LIKELY(expr) (__builtin_expect (!!(expr), 1)) |
| 113 |
#define SYSPROF_UNLIKELY(expr) (__builtin_expect (!!(expr), 0)) |
| 114 |
#else |
| 115 |
#define SYSPROF_LIKELY(expr) (expr) |
| 116 |
#define SYSPROF_UNLIKELY(expr) (expr) |
| 117 |
#endif |
| 118 |
|
| 119 |
#if defined(__GNUC__) |
| 120 |
#define SYSPROF_PRINTF(format_idx, arg_idx) __attribute__((format(printf, format_idx, arg_idx))) |
| 121 |
#else |
| 122 |
#define SYSPROF_PRINTF(format_idx, arg_idx) |
| 123 |
#endif |