xref: /dflybsd-src/contrib/expat/lib/internal.h (revision f0e06f680b0e050b5ef51c84848092142c41acbb)
1fb9a9224SMatthew Dillon /* internal.h
2fb9a9224SMatthew Dillon 
3fb9a9224SMatthew Dillon    Internal definitions used by Expat.  This is not needed to compile
4fb9a9224SMatthew Dillon    client code.
5fb9a9224SMatthew Dillon 
6fb9a9224SMatthew Dillon    The following calling convention macros are defined for frequently
7fb9a9224SMatthew Dillon    called functions:
8fb9a9224SMatthew Dillon 
9fb9a9224SMatthew Dillon    FASTCALL    - Used for those internal functions that have a simple
10fb9a9224SMatthew Dillon                  body and a low number of arguments and local variables.
11fb9a9224SMatthew Dillon 
12fb9a9224SMatthew Dillon    PTRCALL     - Used for functions called though function pointers.
13fb9a9224SMatthew Dillon 
14fb9a9224SMatthew Dillon    PTRFASTCALL - Like PTRCALL, but for low number of arguments.
15fb9a9224SMatthew Dillon 
16fb9a9224SMatthew Dillon    inline      - Used for selected internal functions for which inlining
17fb9a9224SMatthew Dillon                  may improve performance on some platforms.
18fb9a9224SMatthew Dillon 
19fb9a9224SMatthew Dillon    Note: Use of these macros is based on judgement, not hard rules,
20fb9a9224SMatthew Dillon          and therefore subject to change.
21*0c65ac1dSAntonio Huete Jimenez                             __  __            _
22*0c65ac1dSAntonio Huete Jimenez                          ___\ \/ /_ __   __ _| |_
23*0c65ac1dSAntonio Huete Jimenez                         / _ \\  /| '_ \ / _` | __|
24*0c65ac1dSAntonio Huete Jimenez                        |  __//  \| |_) | (_| | |_
25*0c65ac1dSAntonio Huete Jimenez                         \___/_/\_\ .__/ \__,_|\__|
26*0c65ac1dSAntonio Huete Jimenez                                  |_| XML parser
27*0c65ac1dSAntonio Huete Jimenez 
28*0c65ac1dSAntonio Huete Jimenez    Copyright (c) 2002-2003 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
29*0c65ac1dSAntonio Huete Jimenez    Copyright (c) 2002-2006 Karl Waclawek <karl@waclawek.net>
30*0c65ac1dSAntonio Huete Jimenez    Copyright (c) 2003      Greg Stein <gstein@users.sourceforge.net>
31*0c65ac1dSAntonio Huete Jimenez    Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org>
32*0c65ac1dSAntonio Huete Jimenez    Copyright (c) 2018      Yury Gribov <tetra2005@gmail.com>
33*0c65ac1dSAntonio Huete Jimenez    Copyright (c) 2019      David Loffredo <loffredo@steptools.com>
34*0c65ac1dSAntonio Huete Jimenez    Licensed under the MIT license:
35*0c65ac1dSAntonio Huete Jimenez 
36*0c65ac1dSAntonio Huete Jimenez    Permission is  hereby granted,  free of charge,  to any  person obtaining
37*0c65ac1dSAntonio Huete Jimenez    a  copy  of  this  software   and  associated  documentation  files  (the
38*0c65ac1dSAntonio Huete Jimenez    "Software"),  to  deal in  the  Software  without restriction,  including
39*0c65ac1dSAntonio Huete Jimenez    without  limitation the  rights  to use,  copy,  modify, merge,  publish,
40*0c65ac1dSAntonio Huete Jimenez    distribute, sublicense, and/or sell copies of the Software, and to permit
41*0c65ac1dSAntonio Huete Jimenez    persons  to whom  the Software  is  furnished to  do so,  subject to  the
42*0c65ac1dSAntonio Huete Jimenez    following conditions:
43*0c65ac1dSAntonio Huete Jimenez 
44*0c65ac1dSAntonio Huete Jimenez    The above copyright  notice and this permission notice  shall be included
45*0c65ac1dSAntonio Huete Jimenez    in all copies or substantial portions of the Software.
46*0c65ac1dSAntonio Huete Jimenez 
47*0c65ac1dSAntonio Huete Jimenez    THE  SOFTWARE  IS  PROVIDED  "AS  IS",  WITHOUT  WARRANTY  OF  ANY  KIND,
48*0c65ac1dSAntonio Huete Jimenez    EXPRESS  OR IMPLIED,  INCLUDING  BUT  NOT LIMITED  TO  THE WARRANTIES  OF
49*0c65ac1dSAntonio Huete Jimenez    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
50*0c65ac1dSAntonio Huete Jimenez    NO EVENT SHALL THE AUTHORS OR  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
51*0c65ac1dSAntonio Huete Jimenez    DAMAGES OR  OTHER LIABILITY, WHETHER  IN AN  ACTION OF CONTRACT,  TORT OR
52*0c65ac1dSAntonio Huete Jimenez    OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
53*0c65ac1dSAntonio Huete Jimenez    USE OR OTHER DEALINGS IN THE SOFTWARE.
54fb9a9224SMatthew Dillon */
55fb9a9224SMatthew Dillon 
56fb9a9224SMatthew Dillon #if defined(__GNUC__) && defined(__i386__) && ! defined(__MINGW32__)
57fb9a9224SMatthew Dillon /* We'll use this version by default only where we know it helps.
58fb9a9224SMatthew Dillon 
59fb9a9224SMatthew Dillon    regparm() generates warnings on Solaris boxes.   See SF bug #692878.
60fb9a9224SMatthew Dillon 
61fb9a9224SMatthew Dillon    Instability reported with egcs on a RedHat Linux 7.3.
62fb9a9224SMatthew Dillon    Let's comment out:
63fb9a9224SMatthew Dillon    #define FASTCALL __attribute__((stdcall, regparm(3)))
64fb9a9224SMatthew Dillon    and let's try this:
65fb9a9224SMatthew Dillon */
66fb9a9224SMatthew Dillon #  define FASTCALL __attribute__((regparm(3)))
67fb9a9224SMatthew Dillon #  define PTRFASTCALL __attribute__((regparm(3)))
68fb9a9224SMatthew Dillon #endif
69fb9a9224SMatthew Dillon 
70fb9a9224SMatthew Dillon /* Using __fastcall seems to have an unexpected negative effect under
71fb9a9224SMatthew Dillon    MS VC++, especially for function pointers, so we won't use it for
72fb9a9224SMatthew Dillon    now on that platform. It may be reconsidered for a future release
73fb9a9224SMatthew Dillon    if it can be made more effective.
74fb9a9224SMatthew Dillon    Likely reason: __fastcall on Windows is like stdcall, therefore
75fb9a9224SMatthew Dillon    the compiler cannot perform stack optimizations for call clusters.
76fb9a9224SMatthew Dillon */
77fb9a9224SMatthew Dillon 
78fb9a9224SMatthew Dillon /* Make sure all of these are defined if they aren't already. */
79fb9a9224SMatthew Dillon 
80fb9a9224SMatthew Dillon #ifndef FASTCALL
81fb9a9224SMatthew Dillon #  define FASTCALL
82fb9a9224SMatthew Dillon #endif
83fb9a9224SMatthew Dillon 
84fb9a9224SMatthew Dillon #ifndef PTRCALL
85fb9a9224SMatthew Dillon #  define PTRCALL
86fb9a9224SMatthew Dillon #endif
87fb9a9224SMatthew Dillon 
88fb9a9224SMatthew Dillon #ifndef PTRFASTCALL
89fb9a9224SMatthew Dillon #  define PTRFASTCALL
90fb9a9224SMatthew Dillon #endif
91fb9a9224SMatthew Dillon 
92fb9a9224SMatthew Dillon #ifndef XML_MIN_SIZE
93fb9a9224SMatthew Dillon #  if ! defined(__cplusplus) && ! defined(inline)
94fb9a9224SMatthew Dillon #    ifdef __GNUC__
95fb9a9224SMatthew Dillon #      define inline __inline
96fb9a9224SMatthew Dillon #    endif /* __GNUC__ */
97fb9a9224SMatthew Dillon #  endif
98fb9a9224SMatthew Dillon #endif /* XML_MIN_SIZE */
99fb9a9224SMatthew Dillon 
100fb9a9224SMatthew Dillon #ifdef __cplusplus
101fb9a9224SMatthew Dillon #  define inline inline
102fb9a9224SMatthew Dillon #else
103fb9a9224SMatthew Dillon #  ifndef inline
104fb9a9224SMatthew Dillon #    define inline
105fb9a9224SMatthew Dillon #  endif
106fb9a9224SMatthew Dillon #endif
107*0c65ac1dSAntonio Huete Jimenez 
108*0c65ac1dSAntonio Huete Jimenez #include <limits.h> // ULONG_MAX
109*0c65ac1dSAntonio Huete Jimenez 
110*0c65ac1dSAntonio Huete Jimenez #if defined(_WIN32)                                                            \
111*0c65ac1dSAntonio Huete Jimenez     && (! defined(__USE_MINGW_ANSI_STDIO)                                      \
112*0c65ac1dSAntonio Huete Jimenez         || (1 - __USE_MINGW_ANSI_STDIO - 1 == 0))
113*0c65ac1dSAntonio Huete Jimenez #  define EXPAT_FMT_ULL(midpart) "%" midpart "I64u"
114*0c65ac1dSAntonio Huete Jimenez #  if defined(_WIN64) // Note: modifiers "td" and "zu" do not work for MinGW
115*0c65ac1dSAntonio Huete Jimenez #    define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "I64d"
116*0c65ac1dSAntonio Huete Jimenez #    define EXPAT_FMT_SIZE_T(midpart) "%" midpart "I64u"
117*0c65ac1dSAntonio Huete Jimenez #  else
118*0c65ac1dSAntonio Huete Jimenez #    define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "d"
119*0c65ac1dSAntonio Huete Jimenez #    define EXPAT_FMT_SIZE_T(midpart) "%" midpart "u"
120*0c65ac1dSAntonio Huete Jimenez #  endif
121*0c65ac1dSAntonio Huete Jimenez #else
122*0c65ac1dSAntonio Huete Jimenez #  define EXPAT_FMT_ULL(midpart) "%" midpart "llu"
123*0c65ac1dSAntonio Huete Jimenez #  if ! defined(ULONG_MAX)
124*0c65ac1dSAntonio Huete Jimenez #    error Compiler did not define ULONG_MAX for us
125*0c65ac1dSAntonio Huete Jimenez #  elif ULONG_MAX == 18446744073709551615u // 2^64-1
126*0c65ac1dSAntonio Huete Jimenez #    define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "ld"
127*0c65ac1dSAntonio Huete Jimenez #    define EXPAT_FMT_SIZE_T(midpart) "%" midpart "lu"
128*0c65ac1dSAntonio Huete Jimenez #  else
129*0c65ac1dSAntonio Huete Jimenez #    define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "d"
130*0c65ac1dSAntonio Huete Jimenez #    define EXPAT_FMT_SIZE_T(midpart) "%" midpart "u"
131*0c65ac1dSAntonio Huete Jimenez #  endif
132*0c65ac1dSAntonio Huete Jimenez #endif
133*0c65ac1dSAntonio Huete Jimenez 
134*0c65ac1dSAntonio Huete Jimenez #ifndef UNUSED_P
135*0c65ac1dSAntonio Huete Jimenez #  define UNUSED_P(p) (void)p
136*0c65ac1dSAntonio Huete Jimenez #endif
137*0c65ac1dSAntonio Huete Jimenez 
138*0c65ac1dSAntonio Huete Jimenez /* NOTE BEGIN If you ever patch these defaults to greater values
139*0c65ac1dSAntonio Huete Jimenez               for non-attack XML payload in your environment,
140*0c65ac1dSAntonio Huete Jimenez               please file a bug report with libexpat.  Thank you!
141*0c65ac1dSAntonio Huete Jimenez */
142*0c65ac1dSAntonio Huete Jimenez #define EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT   \
143*0c65ac1dSAntonio Huete Jimenez   100.0f
144*0c65ac1dSAntonio Huete Jimenez #define EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT    \
145*0c65ac1dSAntonio Huete Jimenez   8388608 // 8 MiB, 2^23
146*0c65ac1dSAntonio Huete Jimenez /* NOTE END */
147*0c65ac1dSAntonio Huete Jimenez 
148*0c65ac1dSAntonio Huete Jimenez #include "expat.h" // so we can use type XML_Parser below
149*0c65ac1dSAntonio Huete Jimenez 
150*0c65ac1dSAntonio Huete Jimenez #ifdef __cplusplus
151*0c65ac1dSAntonio Huete Jimenez extern "C" {
152*0c65ac1dSAntonio Huete Jimenez #endif
153*0c65ac1dSAntonio Huete Jimenez 
154*0c65ac1dSAntonio Huete Jimenez void _INTERNAL_trim_to_complete_utf8_characters(const char *from,
155*0c65ac1dSAntonio Huete Jimenez                                                 const char **fromLimRef);
156*0c65ac1dSAntonio Huete Jimenez 
157*0c65ac1dSAntonio Huete Jimenez #if defined(XML_DTD)
158*0c65ac1dSAntonio Huete Jimenez unsigned long long testingAccountingGetCountBytesDirect(XML_Parser parser);
159*0c65ac1dSAntonio Huete Jimenez unsigned long long testingAccountingGetCountBytesIndirect(XML_Parser parser);
160*0c65ac1dSAntonio Huete Jimenez const char *unsignedCharToPrintable(unsigned char c);
161*0c65ac1dSAntonio Huete Jimenez #endif
162*0c65ac1dSAntonio Huete Jimenez 
163*0c65ac1dSAntonio Huete Jimenez #ifdef __cplusplus
164*0c65ac1dSAntonio Huete Jimenez }
165*0c65ac1dSAntonio Huete Jimenez #endif
166