mhd_debug_funcs.c (2890B)
1 /* 2 This file is part of GNU libmicrohttpd 3 Copyright (C) 2022 Evgeny Grin (Karlson2k) 4 5 GNU libmicrohttpd is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Lesser General Public 7 License as published by the Free Software Foundation; either 8 version 2.1 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with GNU libmicrohttpd. 17 If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 /** 21 * @file testzzuf/mhd_debug_funcs.c 22 * @brief Implementations of MHD private debug functions 23 * @author Karlson2k (Evgeny Grin) 24 */ 25 26 #include "mhd_debug_funcs.h" 27 #include "internal.h" 28 #include "mhd_sockets.h" 29 30 /** 31 * Checks whether MHD can use accept() syscall and 32 * avoid accept4() syscall. 33 * @return non-zero if accept() is possible, 34 * zero if accept4() is always used by MHD 35 */ 36 int 37 MHD_is_avoid_accept4_possible_ (void) 38 { 39 #if ! defined(USE_ACCEPT4) 40 return ! 0; 41 #else /* ! USE_ACCEPT4 */ 42 return (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_DEBUG_BUILD)) ? 43 ! 0 : 0; 44 #endif /* ! USE_ACCEPT4 */ 45 } 46 47 48 /** 49 * Switch MHD daemon to use accept() syscalls for new connections. 50 * @param daemon the daemon to operate 51 */ 52 void 53 MHD_avoid_accept4_ (struct MHD_Daemon *daemon) 54 { 55 (void) daemon; /* Mute compiler warning */ 56 #ifdef USE_ACCEPT4 57 #ifdef _DEBUG 58 daemon->avoid_accept4 = true; 59 #else /* ! _DEBUG */ 60 abort (); 61 #endif /* ! _DEBUG */ 62 #endif /* USE_ACCEPT4 */ 63 } 64 65 #ifdef MHD_ASAN_ACTIVE 66 #define MHD_ASAN_ENABLED_ 1 67 #else /* ! MHD_ASAN_ACTIVE */ 68 #ifdef __SANITIZE_ADDRESS__ 69 #define MHD_ASAN_ENABLED_ 1 70 #else /* ! __SANITIZE_ADDRESS__ */ 71 #if defined(__has_feature) 72 #if __has_feature(address_sanitizer) 73 #define MHD_ASAN_ENABLED_ 1 74 #endif /* __has_feature(address_sanitizer) */ 75 #endif /* __has_feature */ 76 #endif /* ! __SANITIZE_ADDRESS__ */ 77 #endif /* ! MHD_ASAN_ACTIVE */ 78 /** 79 * Checks whether any know sanitizer is enabled for this build. 80 * zzuf does not work together with sanitizers as both are intercepting 81 * standard library calls. 82 * @return non-zero if any sanitizer is enabled, 83 * zero otherwise 84 */ 85 int 86 MHD_are_sanitizers_enabled_ (void) 87 { 88 int ret = 0; 89 #ifdef MHD_ASAN_ENABLED_ 90 ++ret; 91 #endif /* ! MHD_ASAN_ENABLED_ */ 92 #if defined(__has_feature) 93 #if __has_feature(thread_sanitizer) 94 ++ret; 95 #endif 96 #if __has_feature(memory_sanitizer) 97 ++ret; 98 #endif 99 #if __has_feature(dataflow_sanitizer) 100 ++ret; 101 #endif 102 #else /* ! defined(__has_feature) */ 103 #ifdef __SANITIZE_THREAD__ 104 ++ret; 105 #endif 106 #endif /* ! defined(__has_feature) */ 107 return ret; 108 }