--- /dev/null
+/*
+ * alloca.h
+ *
+ * Declarations for the alloca() function API, conforming to both GNU and
+ * Microsoft's implementation conventions.
+ *
+ *
+ * $Id$
+ *
+ * Written by Keith Marshall <keith@users.osdn.me>
+ * Copyright (C) 2018, MinGW.org Project.
+ *
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ */
+#ifndef _ALLOCA_H
+#define _ALLOCA_H
+/* Microsoft requires the alloca() API to be declared in <malloc.h>;
+ * GNU declares it in <alloca.h>, with default inclusion by <stdlib.h>
+ * when !__STRICT_ANSI__. To achieve compatibility with both, we will
+ * define it in the GNU manner, conditionally including this file when
+ * reading <stdlib.h>, and UNCONDITIONALLY including it in <malloc.h>
+ */
+#ifdef __GNUC__
+#pragma GCC system_header
+/* This implementation is unsupported, for any compiler other than GCC,
+ * (which is the standard MinGW compiler, in any case); all MinGW source
+ * may assume that <_mingw.h> has been included, so ensure that it is.
+ */
+#include <_mingw.h>
+
+/* We must also ensure that the "size_t" type definition is in scope;
+ * we may guarantee this, by selective inclusion from <stddef.h>
+ */
+#define __need_size_t
+#include <stddef.h>
+
+_BEGIN_C_DECLS
+
+#if defined _GNU_SOURCE || ! defined _NO_OLDNAMES
+/* This is the GNU standard API; it is also compatible with Microsoft's
+ * original, but now deprecated, naming convention.
+ */
+__CRT_ALIAS void *alloca( size_t __n ){ return __builtin_alloca( __n ); }
+#endif /* _GNU_SOURCE || !_NO_OLDNAMES */
+
+/* This represents the same API, but conforms to Microsoft's currently
+ * preferred naming convention.
+ */
+__CRT_ALIAS void *_alloca( size_t __n ){ return __builtin_alloca( __n ); }
+
+_END_C_DECLS
+
+#endif /* __GNUC__ */
+#endif /* !_ALLOCA_H: $RCSfile$: end of file */
/*
* malloc.h
- * This file has no copyright assigned and is placed in the Public Domain.
- * This file is a part of the mingw-runtime package.
- * No warranty is given; refer to the file DISCLAIMER within the package.
*
- * Support for programs which want to use malloc.h to get memory management
- * functions. Unless you absolutely need some of these functions and they are
- * not in the ANSI headers you should use the ANSI standard header files
- * instead.
+ * Declarations for non-standard heap management, and memory allocation
+ * functions. These augment the standard functions, which are declared
+ * in <stdlib.h>
+ *
+ * $Id$
+ *
+ * Written by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
+ * Copyright (C) 1997-1999, 2001-2005, 2007, 2018, MinGW.org Project.
+ *
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice, this permission notice, and the following
+ * disclaimer, shall be included in all copies or substantial portions of
+ * the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER
+ * DEALINGS IN THE SOFTWARE.
*
*/
+#ifndef _MALLOC_H
+#pragma GCC system_header
+#define _MALLOC_H
-#ifndef _MALLOC_H_
-#define _MALLOC_H_
-
-/* All the headers include this file. */
-#include <_mingw.h>
-
+/* All MinGW headers assume that <_mingw.h> is included; including
+ * <stdlib.h>, which we also need here, is sufficient to make it so.
+ */
#include <stdlib.h>
#ifndef RC_INVOKED
-/*
- * The structure used to walk through the heap with _heapwalk.
+/* Microsoft stipulate that the alloca() API should be defined in this
+ * header, whereas GNU specify it in its own dedicated header file; to
+ * comply with both, we adopt the GNU stratagem, and then include the
+ * GNU style dedicated header file here.
*/
-typedef struct _heapinfo
-{
- int* _pentry;
- size_t _size;
- int _useflag;
+#include "alloca.h"
+
+typedef
+struct _heapinfo
+{ /* The structure used to control operation, and return information,
+ * when walking the heap using the _heapwalk() function.
+ */
+ int *_pentry;
+ size_t _size;
+ int _useflag;
} _HEAPINFO;
-/* Values for _heapinfo.useflag */
-#define _FREEENTRY 0
-#define _USEDENTRY 1
+/* Status codes returned by _heapwalk()
+ */
+#define _HEAPEMPTY (-1)
+#define _HEAPOK (-2)
+#define _HEAPBADBEGIN (-3)
+#define _HEAPBADNODE (-4)
+#define _HEAPEND (-5)
+#define _HEAPBADPTR (-6)
+
+/* Values returned by _heapwalk(), in the _HEAPINFO.useflag
+ */
+#define _FREEENTRY (0)
+#define _USEDENTRY (1)
-/* Return codes for _heapwalk() */
-#define _HEAPEMPTY (-1)
-#define _HEAPOK (-2)
-#define _HEAPBADBEGIN (-3)
-#define _HEAPBADNODE (-4)
-#define _HEAPEND (-5)
-#define _HEAPBADPTR (-6)
+/* Maximum size permitted for a heap memory allocation request
+ */
+#define _HEAP_MAXREQ (0xFFFFFFE0)
-/* maximum size of a user request for memory */
-#define _HEAP_MAXREQ 0xFFFFFFE0
+_BEGIN_C_DECLS
-#ifdef __cplusplus
-extern "C" {
-#endif
-/*
- The _heap* memory allocation functions are supported on NT
- but not W9x. On latter, they always set errno to ENOSYS.
-*/
-_CRTIMP int __cdecl __MINGW_NOTHROW _heapwalk (_HEAPINFO*);
-#ifdef __GNUC__
-#define _alloca(x) __builtin_alloca((x))
-#endif
-
-#ifndef _NO_OLDNAMES
-_CRTIMP int __cdecl __MINGW_NOTHROW heapwalk (_HEAPINFO*);
-#ifdef __GNUC__
-#define alloca(x) __builtin_alloca((x))
-#endif
-#endif /* Not _NO_OLDNAMES */
-
-_CRTIMP int __cdecl __MINGW_NOTHROW _heapchk (void); /* Verify heap integrety. */
-_CRTIMP int __cdecl __MINGW_NOTHROW _heapmin (void); /* Return unused heap to the OS. */
-_CRTIMP int __cdecl __MINGW_NOTHROW _heapset (unsigned int);
-
-_CRTIMP size_t __cdecl __MINGW_NOTHROW _msize (void*);
-_CRTIMP size_t __cdecl __MINGW_NOTHROW _get_sbh_threshold (void);
-_CRTIMP int __cdecl __MINGW_NOTHROW _set_sbh_threshold (size_t);
-_CRTIMP void* __cdecl __MINGW_NOTHROW _expand (void*, size_t);
-
-/* These require msvcr70.dll or higher. */
-#if __MSVCRT_VERSION__ >= 0x0700
-_CRTIMP void * __cdecl __MINGW_NOTHROW _aligned_offset_malloc(size_t, size_t, size_t);
-_CRTIMP void * __cdecl __MINGW_NOTHROW _aligned_offset_realloc(void*, size_t, size_t, size_t);
-_CRTIMP void * __cdecl __MINGW_NOTHROW _aligned_offset_recalloc(void*, size_t, size_t, size_t, size_t);
-
-_CRTIMP void * __cdecl __MINGW_NOTHROW _aligned_malloc (size_t, size_t);
-_CRTIMP void * __cdecl __MINGW_NOTHROW _aligned_realloc (void*, size_t, size_t);
-_CRTIMP void* __cdecl __MINGW_NOTHROW _aligned_recalloc(void*, size_t, size_t, size_t);
-_CRTIMP void __cdecl __MINGW_NOTHROW _aligned_free (void*);
-#endif /* __MSVCRT_VERSION__ >= 0x0700 */
-
-/* These require libmingwex.a. */
-void * __cdecl __MINGW_NOTHROW __mingw_aligned_offset_malloc (size_t, size_t, size_t);
-void * __cdecl __MINGW_NOTHROW __mingw_aligned_offset_realloc (void*, size_t, size_t, size_t);
-
-void * __cdecl __MINGW_NOTHROW __mingw_aligned_malloc (size_t, size_t);
-void * __cdecl __MINGW_NOTHROW __mingw_aligned_realloc (void*, size_t, size_t);
-void __cdecl __MINGW_NOTHROW __mingw_aligned_free (void*);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* RC_INVOKED */
-
-#endif /* Not _MALLOC_H_ */
+/* The _heap memory allocation functions are supported on WinNT, but not on
+ * Win9X, (on which they always simply set errno to ENOSYS).
+ */
+_CRTIMP __cdecl __MINGW_NOTHROW int _heapwalk (_HEAPINFO *);
+
+_CRTIMP __cdecl __MINGW_NOTHROW int _heapchk (void);
+_CRTIMP __cdecl __MINGW_NOTHROW int _heapmin (void);
+
+_CRTIMP __cdecl __MINGW_NOTHROW int _heapset (unsigned int);
+
+_CRTIMP __cdecl __MINGW_NOTHROW size_t _msize (void *);
+_CRTIMP __cdecl __MINGW_NOTHROW size_t _get_sbh_threshold (void);
+_CRTIMP __cdecl __MINGW_NOTHROW int _set_sbh_threshold (size_t);
+_CRTIMP __cdecl __MINGW_NOTHROW void *_expand (void *, size_t);
+
+#ifndef _NO_OLDNAMES
+/* Legacy versions of Microsoft runtimes may have supported this alternative
+ * name for the _heapwalk() API.
+ */
+_CRTIMP __cdecl __MINGW_NOTHROW int heapwalk (_HEAPINFO *);
+#endif /* !_NO_OLDNAMES */
+
+#if __MSVCRT_VERSION__ >= __MSVCR70_DLL
+/* First introduced in non-free MSVCR70.DLL, the following were subsequently
+ * made available from MSVCRT.DLL, from the release of WinXP onwards; however,
+ * we choose to declare them only for the non-free case, preferring to emulate
+ * them, in terms of libmingwex.a replacement implementations, for consistent
+ * behaviour across ALL MSVCRT.DLL versions.
+ */
+_CRTIMP __cdecl __MINGW_NOTHROW
+void *_aligned_offset_malloc (size_t, size_t, size_t);
+
+_CRTIMP __cdecl __MINGW_NOTHROW
+void *_aligned_offset_realloc (void *, size_t, size_t, size_t);
+
+_CRTIMP __cdecl __MINGW_NOTHROW void *_aligned_malloc (size_t, size_t);
+_CRTIMP __cdecl __MINGW_NOTHROW void *_aligned_realloc (void *, size_t, size_t);
+_CRTIMP __cdecl __MINGW_NOTHROW void _aligned_free (void *);
+
+/* Curiously, there are no "calloc()" alike variants of the following pair of
+ * "recalloc()" alike functions; furthermore, neither of these is provided by
+ * any version of pseudo-free MSVCRT.DLL
+ */
+_CRTIMP __cdecl __MINGW_NOTHROW
+void *_aligned_recalloc (void *, size_t, size_t, size_t);
+
+_CRTIMP __cdecl __MINGW_NOTHROW
+void *_aligned_offset_recalloc (void *, size_t, size_t, size_t, size_t);
+
+#endif /* Non-free MSVCR70.DLL, or later */
+
+/* The following emulations are provided in libmingwex.a; they are suitable
+ * for use on any Windows version, irrespective of the limited availability
+ * of the preceding Microsoft implementations.
+ */
+__cdecl __MINGW_NOTHROW
+void *__mingw_aligned_malloc (size_t, size_t);
+
+__cdecl __MINGW_NOTHROW
+void *__mingw_aligned_offset_malloc (size_t, size_t, size_t);
+
+__cdecl __MINGW_NOTHROW
+void *__mingw_aligned_offset_realloc (void *, size_t, size_t, size_t);
+
+__cdecl __MINGW_NOTHROW
+void *__mingw_aligned_realloc (void *, size_t, size_t);
+
+__cdecl __MINGW_NOTHROW
+void __mingw_aligned_free (void *);
+
+_END_C_DECLS
+
+#endif /* ! RC_INVOKED */
+#endif /* !_MALLOC_H: $RCSfile$: end of file */