1 /* internal.h 2 3 Internal definitions used by Expat. This is not needed to compile 4 client code. 5 6 The following calling convention macros are defined for frequently 7 called functions: 8 9 inline - Used for selected internal functions for which inlining 10 may improve performance on some platforms. 11 12 Note: Use of these macros is based on judgement, not hard rules, 13 and therefore subject to change. 14 __ __ _ 15 ___\ \/ /_ __ __ _| |_ 16 / _ \\ /| '_ \ / _` | __| 17 | __// \| |_) | (_| | |_ 18 \___/_/\_\ .__/ \__,_|\__| 19 |_| XML parser 20 21 Copyright (c) 2002-2003 Fred L. Drake, Jr. <fdrake (at) users.sourceforge.net> 22 Copyright (c) 2002-2006 Karl Waclawek <karl (at) waclawek.net> 23 Copyright (c) 2003 Greg Stein <gstein (at) users.sourceforge.net> 24 Copyright (c) 2016-2026 Sebastian Pipping <sebastian (at) pipping.org> 25 Copyright (c) 2018 Yury Gribov <tetra2005 (at) gmail.com> 26 Copyright (c) 2019 David Loffredo <loffredo (at) steptools.com> 27 Copyright (c) 2023-2024 Sony Corporation / Snild Dolkow <snild (at) sony.com> 28 Copyright (c) 2024 Taichi Haradaguchi <20001722 (at) ymail.ne.jp> 29 Copyright (c) 2026 Matthew Wozniczka <mattheww (at) simba.com> 30 Copyright (c) 2026 Braian Plaku <braianplaku (at) gmail.com> 31 Copyright (c) 2026 Florian Schmaus <florian.schmaus (at) codasip.com> 32 Licensed under the MIT license: 33 34 Permission is hereby granted, free of charge, to any person obtaining 35 a copy of this software and associated documentation files (the 36 "Software"), to deal in the Software without restriction, including 37 without limitation the rights to use, copy, modify, merge, publish, 38 distribute, sublicense, and/or sell copies of the Software, and to permit 39 persons to whom the Software is furnished to do so, subject to the 40 following conditions: 41 42 The above copyright notice and this permission notice shall be included 43 in all copies or substantial portions of the Software. 44 45 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 46 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 47 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 48 NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 49 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 50 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 51 USE OR OTHER DEALINGS IN THE SOFTWARE. 52 53 SPDX-License-Identifier: MIT 54 */ 55 56 #if ! defined(INTERNAL_H) 57 # define INTERNAL_H 1 58 59 # ifndef XML_MIN_SIZE 60 # if ! defined(inline) 61 # ifdef __GNUC__ 62 # define inline __inline 63 # endif /* __GNUC__ */ 64 # endif 65 # endif /* XML_MIN_SIZE */ 66 67 # ifndef inline 68 # define inline 69 # endif 70 71 # if ! defined(XML_NONTESTING_STATIC) 72 # if defined(XML_TESTING) 73 # define XML_NONTESTING_STATIC // empty i.e. not static 74 # else 75 # define XML_NONTESTING_STATIC static 76 # endif 77 # endif 78 79 # include <limits.h> // ULONG_MAX 80 # include <stddef.h> // size_t 81 82 # if defined(_WIN32) \ 83 && (! defined(__USE_MINGW_ANSI_STDIO) \ 84 || (1 - __USE_MINGW_ANSI_STDIO - 1 == 0)) 85 # define EXPAT_FMT_LLX(midpart) "%" midpart "I64x" 86 # define EXPAT_FMT_ULL(midpart) "%" midpart "I64u" 87 # if defined(_WIN64) // Note: modifiers "td" and "zu" do not work for MinGW 88 # define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "I64d" 89 # define EXPAT_FMT_SIZE_T(midpart) "%" midpart "I64u" 90 # else 91 # define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "d" 92 # define EXPAT_FMT_SIZE_T(midpart) "%" midpart "u" 93 # endif 94 # else 95 # include <inttypes.h> // PRIdPTR, PRIuPTR 96 # define EXPAT_FMT_LLX(midpart) "%" midpart "llx" 97 # define EXPAT_FMT_ULL(midpart) "%" midpart "llu" 98 # define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart PRIdPTR 99 # define EXPAT_FMT_SIZE_T(midpart) "%" midpart PRIuPTR 100 # endif 101 102 # ifndef UNUSED_P 103 # define UNUSED_P(p) (void)p 104 # endif 105 106 /* NOTE BEGIN If you ever patch these defaults to greater values 107 for non-attack XML payload in your environment, 108 please file a bug report with libexpat. Thank you! 109 */ 110 # define EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT \ 111 100.0f 112 # define EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT \ 113 8388608 // 8 MiB, 2^23 114 115 # define EXPAT_ALLOC_TRACKER_MAXIMUM_AMPLIFICATION_DEFAULT 100.0f 116 # define EXPAT_ALLOC_TRACKER_ACTIVATION_THRESHOLD_DEFAULT \ 117 67108864 // 64 MiB, 2^26 118 119 // NOTE: If function expat_alloc was user facing, EXPAT_MALLOC_ALIGNMENT would 120 // have to take sizeof(long double) into account 121 union expat_align { 122 long long l; 123 void *p; 124 }; 125 # define EXPAT_MALLOC_ALIGNMENT sizeof(union expat_align) 126 # define EXPAT_MALLOC_PADDING ((EXPAT_MALLOC_ALIGNMENT) - sizeof(size_t)) 127 128 /* NOTE END */ 129 130 # include "expat.h" // so we can use type XML_Parser below 131 132 void _INTERNAL_trim_to_complete_utf8_characters(const char *from, 133 const char **fromLimRef); 134 135 # if defined(XML_GE) && XML_GE == 1 136 unsigned long long testingAccountingGetCountBytesDirect(XML_Parser parser); 137 unsigned long long testingAccountingGetCountBytesIndirect(XML_Parser parser); 138 const char *unsignedCharToPrintable(unsigned char c); 139 # endif 140 141 extern 142 # if ! defined(XML_TESTING) 143 const 144 # endif 145 XML_Bool g_reparseDeferralEnabledDefault; // written ONLY in runtests.c 146 # if defined(XML_TESTING) 147 148 int xmlSetHashSalt(XML_Parser parser, unsigned long hash_salt); 149 150 void *expat_malloc(XML_Parser parser, size_t size, int sourceLine); 151 void expat_free(XML_Parser parser, void *ptr, int sourceLine); 152 void *expat_realloc(XML_Parser parser, void *ptr, size_t size, int sourceLine); 153 extern unsigned int g_bytesScanned; // used for testing only 154 # endif 155 156 #endif // not defined INTERNAL_H 157