summaryrefslogtreecommitdiffstats
path: root/private/crt32/winheap
diff options
context:
space:
mode:
Diffstat (limited to 'private/crt32/winheap')
-rw-r--r--private/crt32/winheap/calloc.c81
-rw-r--r--private/crt32/winheap/delete.cxx28
-rw-r--r--private/crt32/winheap/expand.c92
-rw-r--r--private/crt32/winheap/handler.cxx53
-rw-r--r--private/crt32/winheap/heapchk.c131
-rw-r--r--private/crt32/winheap/heapinit.c52
-rw-r--r--private/crt32/winheap/heapmin.c73
-rw-r--r--private/crt32/winheap/heapwalk.c101
-rw-r--r--private/crt32/winheap/hpabort.c47
-rw-r--r--private/crt32/winheap/makefile7
-rw-r--r--private/crt32/winheap/malloc.c104
-rw-r--r--private/crt32/winheap/msize.c49
-rw-r--r--private/crt32/winheap/new.cxx28
-rw-r--r--private/crt32/winheap/realloc.c85
-rw-r--r--private/crt32/winheap/sources51
15 files changed, 982 insertions, 0 deletions
diff --git a/private/crt32/winheap/calloc.c b/private/crt32/winheap/calloc.c
new file mode 100644
index 000000000..ad93d8c55
--- /dev/null
+++ b/private/crt32/winheap/calloc.c
@@ -0,0 +1,81 @@
+/***
+*calloc.c - Win32 calloc heap routines
+*
+* Copyright (c) 1991-1992, Microsoft Corporation. All rights reserved.
+*
+*Purpose:
+*
+*Revision History:
+* 01-10-92 JCR Module created.
+* 02-04-92 GJF Replaced windows.h with oscalls.h.
+* 05-06-92 DJM POSIX support.
+* 06-15-92 KRS Enable C++ support.
+* 09-09-92 SRW _POSIX_ not even close.
+* 09-23-92 SRW Change winheap code to call NT directly always
+* 10-28-92 SRW Change winheap code to call Heap????Ex calls
+* 11-05-92 SKS Change name of variable "CrtHeap" to "_crtheap"
+* 11-07-92 SRW _NTIDW340 replaced by linkopts\betacmp.c
+* 11-16-92 SRW Heap???Ex functions renamed to Heap???
+*
+*******************************************************************************/
+
+#include <malloc.h>
+#include <winheap.h>
+#include <os2dll.h>
+#include <oscalls.h>
+
+#ifndef _POSIX_
+#include <new.h>
+extern _PNH _pnhHeap;
+#endif
+
+/***
+*void *calloc(size_t num, size_t size) - allocate storage for an array from
+* the heap
+*
+*Purpose:
+* Allocate a block of memory from heap big enough for an array of num
+* elements of size bytes each, initialize all bytes in the block to 0
+* and return a pointer to it.
+*
+*Entry:
+* size_t num - number of elements in the array
+* size_t size - size of each element
+*
+*Exit:
+* Success: void pointer to allocated block block
+* Failure: NULL
+*
+*Uses:
+*
+*Exceptions:
+*
+*******************************************************************************/
+
+void * _CALLTYPE1 calloc ( num, size )
+size_t num;
+size_t size;
+
+{
+ HANDLE h;
+ size_t n;
+
+ if (!(n = num * size)) n = 1;
+
+#ifndef _POSIX_
+ for (;;) {
+#endif /* ndef _POSIX_ */
+
+ h = HeapAlloc(_crtheap,
+ HEAP_ZERO_MEMORY,
+ n
+ );
+#ifndef _POSIX_
+ if ((h != 0) || (_pnhHeap == NULL) || (*_pnhHeap)(n) == 0)
+#endif /* ndef _POSIX_ */
+ return((void *)h);
+
+#ifndef _POSIX_
+ }
+#endif /* ndef _POSIX_ */
+}
diff --git a/private/crt32/winheap/delete.cxx b/private/crt32/winheap/delete.cxx
new file mode 100644
index 000000000..bc2d73e7a
--- /dev/null
+++ b/private/crt32/winheap/delete.cxx
@@ -0,0 +1,28 @@
+/***
+*delete.cxx - defines C++ delete routine
+*
+* Copyright (c) 1990-1992, Microsoft Corporation. All rights reserved.
+*
+*Purpose:
+* Defines C++ delete routine.
+*
+*Revision History:
+* 05-07-90 WAJ Initial version.
+* 08-30-90 WAJ new now takes unsigned ints.
+* 08-08-91 JCR call _halloc/_hfree, not halloc/hfree
+* 08-13-91 KRS Change new.hxx to new.h. Fix copyright.
+* 08-13-91 JCR ANSI-compatible _set_new_handler names
+* 10-30-91 JCR Split new, delete, and handler into seperate sources
+* 11-13-91 JCR 32-bit version
+*
+*******************************************************************************/
+
+#include <cruntime.h>
+#include <malloc.h>
+#include <new.h>
+
+
+void operator delete( void * p )
+{
+ free( p );
+}
diff --git a/private/crt32/winheap/expand.c b/private/crt32/winheap/expand.c
new file mode 100644
index 000000000..8b142e194
--- /dev/null
+++ b/private/crt32/winheap/expand.c
@@ -0,0 +1,92 @@
+/***
+*expand.c - Win32 expand heap routine
+*
+* Copyright (c) 1991-1992, Microsoft Corporation. All rights reserved.
+*
+*Purpose:
+*
+*Revision History:
+* 01-15-92 JCR Module created.
+* 02-04-92 GJF Replaced windows.h with oscalls.h.
+* 05-06-92 DJM ifndef out of POSIX build.
+* 09-23-92 SRW Change winheap code to call NT directly always
+* 10-15-92 SKS Removed the ill-named HEAP_GROWTH_ALLOWED flag
+* which was causing a bug: _expand was behaving like
+* realloc(), by moving the block when it could not be
+* grown in place. _expand() must NEVER move the block.
+* Also added a safety check to work around a bug in
+* HeapReAlloc, where it returns success even
+* when it fails to grow the block in place.
+* 10-28-92 SRW Change winheap code to call Heap????Ex calls
+* 11-05-92 SKS Change name of variable "CrtHeap" to "_crtheap"
+* 11-07-92 SRW _NTIDW340 replaced by linkopts\betacmp.c
+* 11-16-92 SRW Heap???Ex functions renamed to Heap???
+*
+*******************************************************************************/
+
+#ifndef _POSIX_
+
+#include <cruntime.h>
+#include <malloc.h>
+#include <winheap.h>
+#include <oscalls.h>
+
+/***
+*void *_expand(void *pblck, size_t newsize) - expand/contract a block of memory
+* in the heap
+*
+*Purpose:
+* Resizes a block in the heap to newsize bytes. newsize may be either
+* greater (expansion) or less (contraction) than the original size of
+* the block. The block is NOT moved.
+*
+* NOTES:
+*
+* (1) In this implementation, if the block cannot be grown to the
+* desired size, the resulting block will NOT be grown to the max
+* possible size. (That is, either it works or it doesn't.)
+*
+* (2) Unlike other implementations, you can NOT pass a previously
+* freed block to this routine and expect it to work.
+*
+*Entry:
+* void *pblck - pointer to block in the heap previously allocated
+* by a call to malloc(), realloc() or _expand().
+*
+* size_t newsize - requested size for the resized block
+*
+*Exit:
+* Success: Pointer to the resized memory block (i.e., pblck)
+* Failure: NULL
+*
+*Uses:
+*
+*Exceptions:
+* If pblck does not point to a valid allocation block in the heap,
+* _expand() will behave unpredictably and probably corrupt the heap.
+*
+*******************************************************************************/
+
+void * _CALLTYPE1 _expand(pblock, n)
+void * pblock;
+size_t n;
+
+{
+ void * p;
+
+ p = HeapReAlloc(_crtheap,
+ HEAP_REALLOC_IN_PLACE_ONLY,
+ pblock,
+ n ? n : 1
+ );
+
+ /**
+ * Temporary BUG work-around:
+ * HeapReAlloc sometimes (often?) returns success
+ * even when there has been a failure to grow in place.
+ * This conditional will recognize this case and handle it.
+ **/
+ return ( p == pblock ) && ( _msize(pblock) >= n ) ? pblock : NULL;
+}
+
+#endif /* !_POSIX_ */
diff --git a/private/crt32/winheap/handler.cxx b/private/crt32/winheap/handler.cxx
new file mode 100644
index 000000000..91db57522
--- /dev/null
+++ b/private/crt32/winheap/handler.cxx
@@ -0,0 +1,53 @@
+/***
+*handler.cxx - defines C++ setHandler routine
+*
+* Copyright (c) 1990-1992, Microsoft Corporation. All rights reserved.
+*
+*Purpose:
+* Defines C++ setHandler routine.
+*
+*Revision History:
+* 05-07-90 WAJ Initial version.
+* 08-30-90 WAJ new now takes unsigned ints.
+* 08-08-91 JCR call _halloc/_hfree, not halloc/hfree
+* 08-13-91 KRS Change new.hxx to new.h. Fix copyright.
+* 08-13-91 JCR ANSI-compatible _set_new_handler names
+* 10-30-91 JCR Split new, delete, and handler into seperate sources
+* 11-13-91 JCR 32-bit version
+* 06-15-92 KRS Break MTHREAD support for NT BETA
+*
+*******************************************************************************/
+
+#include <cruntime.h>
+#include <os2dll.h>
+#include <new.h>
+
+/* Warning! MTHREAD is broken! */
+/* Warning! MTHREAD is broken! */
+/* Warning! MTHREAD is broken! */
+
+/* #ifndef MTHREAD */
+/* pointer to C++ new handler */
+extern "C" _PNH _pnhHeap;
+/* #endif */
+
+_PNH _set_new_handler( _PNH pnh )
+{
+_PNH pnhOld;
+
+/* #ifdef MTHREAD
+
+ _pptiddata tdata;
+ tdata = _getptd();
+ pnhOld = ((*tdata)->_tpnhHeap);
+ ((*tdata)->_tpnhHeap) = pnh;
+
+#else */ /* ndef MTHREAD */
+
+ pnhOld = _pnhHeap;
+ _pnhHeap = pnh;
+
+/* #endif */
+
+ return(pnhOld);
+}
diff --git a/private/crt32/winheap/heapchk.c b/private/crt32/winheap/heapchk.c
new file mode 100644
index 000000000..e1479827b
--- /dev/null
+++ b/private/crt32/winheap/heapchk.c
@@ -0,0 +1,131 @@
+/***
+*heapchk.c - perform a consistency check on the heap
+*
+* Copyright (c) 1989-1991, Microsoft Corporation. All rights reserved.
+*
+*Purpose:
+* Defines the _heapchk() and _heapset() functions
+*
+*Revision History:
+* 06-30-89 JCR Module created.
+* 07-28-89 GJF Added check for free block preceding the rover
+* 11-13-89 GJF Added MTHREAD support, also fixed copyright
+* 12-13-89 GJF Added check for descriptor order, did some tuning,
+* changed header file name to heap.h
+* 12-15-89 GJF Purged DEBUG286 stuff. Also added explicit _cdecl to
+* function definitions.
+* 12-19-89 GJF Got rid of checks involving plastdesc (revised check
+* of proverdesc and DEBUG errors accordingly)
+* 03-09-90 GJF Replaced _cdecl with _CALLTYPE1, added #include
+* <cruntime.h> and removed #include <register.h>.
+* 03-29-90 GJF Made _heap_checkset() _CALLTYPE4.
+* 09-27-90 GJF New-style function declarators.
+* 03-05-91 GJF Changed strategy for rover - old version available
+* by #define-ing _OLDROVER_.
+* 06-27-94 SRW Ported to Win32 Heap API
+* 07-06-94 SRW Chicago compatibility changes.
+*
+*******************************************************************************/
+
+#include <cruntime.h>
+#include <oscalls.h>
+#include <malloc.h>
+#include <os2dll.h>
+#include <stddef.h>
+#include <string.h>
+
+#ifndef _POSIX_
+
+/***
+*int _heapchk() - Validate the heap
+*int _heapset(_fill) - Validate the heap and fill in free entries
+*
+*Purpose:
+* Performs a consistency check on the heap.
+*
+*Entry:
+* For heapchk()
+* No arguments
+* For heapset()
+* int _fill - value to be used as filler in free entries
+*
+*Exit:
+* Returns one of the following values:
+*
+* _HEAPOK - completed okay
+* _HEAPEMPTY - heap not initialized
+* _HEAPBADBEGIN - can't find initial header info
+* _HEAPBADNODE - malformed node somewhere
+*
+* Debug version prints out a diagnostic message if an error is found
+* (see errmsg[] above).
+*
+* NOTE: Add code to support memory regions.
+*
+*Uses:
+*
+*Exceptions:
+*
+*******************************************************************************/
+
+int _CALLTYPE1 _heapchk(void)
+{
+ if (!HeapValidate( GetProcessHeap(), 0, NULL )) {
+ return _HEAPBADNODE;
+ }
+ else {
+ return _HEAPOK;
+ }
+}
+
+/******************************************************************************/
+
+int _CALLTYPE1 _heapset (
+ unsigned int _fill
+ )
+{
+ int _retval = _HEAPOK;
+ PROCESS_HEAP_ENTRY Entry;
+
+ if (!HeapValidate( GetProcessHeap(), 0, NULL )) {
+ return _HEAPBADNODE;
+ }
+
+ if (!HeapLock( GetProcessHeap() )) {
+ return _HEAPBADBEGIN;
+ }
+
+ Entry.lpData = NULL;
+ try {
+ while (TRUE) {
+ if (!HeapWalk( GetProcessHeap(), &Entry )) {
+ if (GetLastError() != ERROR_NO_MORE_ITEMS) {
+ _retval = _HEAPBADNODE;
+ }
+
+ break;
+ }
+
+ if (Entry.wFlags & (PROCESS_HEAP_REGION | PROCESS_HEAP_UNCOMMITTED_RANGE)) {
+ continue;
+ }
+
+
+ if (!(Entry.wFlags & PROCESS_HEAP_ENTRY_BUSY)) {
+ try {
+ memset( Entry.lpData, _fill, Entry.cbData );
+ }
+ except( EXCEPTION_EXECUTE_HANDLER ) {
+ // Chicago free blocks may contain uncommitted pages. Punt
+ }
+ }
+ }
+ }
+ finally {
+ HeapUnlock( GetProcessHeap() );
+ }
+
+ return _retval;
+}
+
+#endif /* !_POSIX_ */
diff --git a/private/crt32/winheap/heapinit.c b/private/crt32/winheap/heapinit.c
new file mode 100644
index 000000000..775317c9c
--- /dev/null
+++ b/private/crt32/winheap/heapinit.c
@@ -0,0 +1,52 @@
+/***
+*heapinit.c - Initialze the heap
+*
+* Copyright (c) 1989-1991, Microsoft Corporation. All rights reserved.
+*
+*Purpose:
+*
+*Revision History:
+* 01-10-92 JCR Module created.
+* 05-12-92 DJM POSIX calls RtlProcessHeap.
+* 09-23-92 SRW Change winheap code to call NT directly always
+* 10-28-92 SRW Change winheap code to call Heap????Ex calls
+* 11-05-92 SKS Change name of variable "CrtHeap" to "_crtheap"
+* 11-07-92 SRW _NTIDW340 replaced by linkopts\betacmp.c
+*
+*******************************************************************************/
+
+#include <cruntime.h>
+#include <malloc.h>
+#include <winheap.h>
+
+HANDLE _crtheap;
+
+/***
+*_heap_init() - Initialize the heap
+*
+*Purpose:
+* Setup the initial C library heap.
+*
+* NOTES:
+* (1) This routine should only be called once!
+* (2) This routine must be called before any other heap requests.
+* (3) NOTHING TO DO FOR THIS WIN32 HEAP!
+*
+*Entry:
+* <void>
+*Exit:
+* <void>
+*
+*Exceptions:
+* If heap cannot be initialized, the program will be terminated
+* with a fatal runtime error.
+*
+*******************************************************************************/
+
+void _CALLTYPE1 _heap_init (
+ void
+ )
+{
+ _crtheap = GetProcessHeap();
+ return;
+}
diff --git a/private/crt32/winheap/heapmin.c b/private/crt32/winheap/heapmin.c
new file mode 100644
index 000000000..6073adf21
--- /dev/null
+++ b/private/crt32/winheap/heapmin.c
@@ -0,0 +1,73 @@
+/***
+*heapmin.c - Minimize the heap
+*
+* Copyright (c) 1989-1991, Microsoft Corporation. All rights reserved.
+*
+*Purpose:
+* Minimize the heap freeing as much memory as possible back
+* to the OS.
+*
+*Revision History:
+* 08-28-89 JCR Module created.
+* 11-06-89 JCR Improved, partitioned
+* 11-13-89 GJF Added MTHREAD support, also fixed copyright
+* 12-14-89 GJF Couple of bug fixes, some tuning, cleaned up the
+* formatting a bit and changed header file name to
+* heap.h
+* 12-20-89 GJF Removed references to plastdesc
+* 03-11-90 GJF Replaced _cdecl with _CALLTYPE1, added #include
+* <cruntime.h> and removed #include <register.h>.
+* 03-29-90 GJF Made _heapmin_region() and _free_partial_region()
+* _CALLTYPE4.
+* 07-24-90 SBM Compiles cleanly with -W3 (tentatively removed
+* unreferenced labels and unreachable code), removed
+* '32' from API names
+* 09-28-90 GJF New-style function declarators. Also, rewrote expr.
+* to avoid using cast as lvalue.
+* 12-04-90 SRW Changed to include <oscalls.h> instead of <doscalls.h>
+* 12-06-90 SRW Added _CRUISER_ and _WIN32 conditionals.
+* 12-28-90 SRW Added cast of void * to char * for Mips C Compiler
+* 03-05-91 GJF Changed strategy for rover - old version available
+* by #define-ing _OLDROVER_.
+* 06-27-94 SRW Ported to Win32 Heap API
+*
+*******************************************************************************/
+
+#include <cruntime.h>
+#include <oscalls.h>
+#include <malloc.h>
+#include <os2dll.h>
+#include <stdlib.h>
+
+#ifndef _POSIX_
+
+/***
+*_heapmin() - Minimize the heap
+*
+*Purpose:
+* Minimize the heap freeing as much memory as possible back
+* to the OS.
+*
+*Entry:
+* (void)
+*
+*Exit:
+*
+* 0 = no error has occurred
+* -1 = an error has occurred (errno is set)
+*
+*Exceptions:
+*
+*******************************************************************************/
+
+int _CALLTYPE1 _heapmin(void)
+{
+ if (HeapCompact( GetProcessHeap(), 0 ) == 0) {
+ return -1;
+ }
+ else {
+ return 0;
+ }
+}
+
+#endif /* !_POSIX_ */
diff --git a/private/crt32/winheap/heapwalk.c b/private/crt32/winheap/heapwalk.c
new file mode 100644
index 000000000..4d2175299
--- /dev/null
+++ b/private/crt32/winheap/heapwalk.c
@@ -0,0 +1,101 @@
+/***
+*heapwalk.c - walk the heap
+*
+* Copyright (c) 1989-1991, Microsoft Corporation. All rights reserved.
+*
+*Purpose:
+* Defines the _heapwalk() function
+*
+*Revision History:
+* 07-05-89 JCR Module created.
+* 11-13-89 GJF Added MTHREAD support, also fixed copyright.
+* 11-14-89 JCR Fixed bug -- returned address was off by HDRSIZE
+* 12-18-89 GJF Removed DEBUG286 stuff, also some tuning, cleaned up
+* format a bit, changed header file name to heap.h, added
+* explicit _cdecl to function definition
+* 12-20-89 GJF Removed references to plastdesc
+* 03-11-90 GJF Replaced _cdecl with _CALLTYPE1, added #include
+* <cruntime.h> and removed #include <register.h>.
+* 09-28-90 GJF New-style function declarator.
+* 06-27-94 SRW Ported to Win32 Heap API
+*
+*******************************************************************************/
+
+#include <cruntime.h>
+#include <oscalls.h>
+#include <malloc.h>
+#include <os2dll.h>
+#include <stddef.h>
+
+#ifndef _POSIX_
+
+/***
+*int _heapwalk() - Walk the heap
+*
+*Purpose:
+* Walk the heap returning information on one entry at a time.
+*
+*Entry:
+* struct _heapinfo {
+* int * _pentry; heap entry pointer
+* size_t size; size of heap entry
+* int _useflag; free/inuse flag
+* } *entry;
+*
+*Exit:
+* Returns one of the following values:
+*
+* _HEAPOK - completed okay
+* _HEAPEMPTY - heap not initialized
+* _HEAPBADPTR - _pentry pointer is bogus
+* _HEAPBADBEGIN - can't find initial header info
+* _HEAPBADNODE - malformed node somewhere
+* _HEAPEND - end of heap successfully reached
+*
+*Uses:
+*
+*Exceptions:
+*
+*******************************************************************************/
+
+int _CALLTYPE1 _heapwalk (
+ struct _heapinfo *_entry
+ )
+{
+ PROCESS_HEAP_ENTRY Entry;
+ int retval = _HEAPOK;
+
+ Entry.wFlags = 0;
+ Entry.iRegionIndex = 0;
+ if ((Entry.lpData = _entry->_pentry) == NULL) {
+ if (!HeapWalk( GetProcessHeap(), &Entry )) {
+ return _HEAPBADBEGIN;
+ }
+ }
+ else {
+ if (_entry->_useflag == _USEDENTRY) {
+ Entry.wFlags = PROCESS_HEAP_ENTRY_BUSY;
+ }
+nextBlock:
+ if (!HeapWalk( GetProcessHeap(), &Entry )) {
+ return _HEAPBADNODE;
+ }
+ }
+
+ if (Entry.wFlags & (PROCESS_HEAP_REGION | PROCESS_HEAP_UNCOMMITTED_RANGE)) {
+ goto nextBlock;
+ }
+
+ _entry->_pentry = Entry.lpData;
+ _entry->_size = Entry.cbData;
+ if (Entry.wFlags & PROCESS_HEAP_ENTRY_BUSY) {
+ _entry->_useflag = _USEDENTRY;
+ }
+ else {
+ _entry->_useflag = _FREEENTRY;
+ }
+
+ return(retval);
+}
+
+#endif /* !_POSIX_ */
diff --git a/private/crt32/winheap/hpabort.c b/private/crt32/winheap/hpabort.c
new file mode 100644
index 000000000..9227a5b4b
--- /dev/null
+++ b/private/crt32/winheap/hpabort.c
@@ -0,0 +1,47 @@
+/***
+* hpabort.c - Abort process due to fatal heap error
+*
+* Copyright (c) 1988-1991, Microsoft Corporation. All rights reserved.
+*
+*Purpose:
+*
+*Revision History:
+* 11-13-89 JCR Module created
+* 12-18-89 GJF #include-ed heap.h, also added explicit _cdecl to
+* function definition.
+* 03-11-90 GJF Replaced _cdecl with _CALLTYPE1 and added #include
+* <cruntime.h>.
+* 10-03-90 GJF New-style function declarator.
+* 10-11-90 GJF Changed interface to _amsg_exit().
+*
+*******************************************************************************/
+
+#include <cruntime.h>
+#include <heap.h>
+#include <internal.h>
+#include <rterr.h>
+
+
+/***
+* _heap_abort() - Abort process due to fatal heap error
+*
+*Purpose:
+* Terminate the process and output a heap error message
+*
+*Entry:
+* Void
+*
+*Exit:
+* Never returns
+*
+*Exceptions:
+*
+*******************************************************************************/
+
+void _CALLTYPE1 _heap_abort (
+ void
+ )
+{
+ _amsg_exit(_RT_HEAP); /* heap error */
+ /*** PROCESS TERMINATED ***/
+}
diff --git a/private/crt32/winheap/makefile b/private/crt32/winheap/makefile
new file mode 100644
index 000000000..9e18c9a05
--- /dev/null
+++ b/private/crt32/winheap/makefile
@@ -0,0 +1,7 @@
+#
+# DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source
+# file to this component. This file merely indirects to the real make file
+# that is shared by all the components of NT OS/2
+#
+BLDCRT=1
+!INCLUDE $(NTMAKEENV)\makefile.def
diff --git a/private/crt32/winheap/malloc.c b/private/crt32/winheap/malloc.c
new file mode 100644
index 000000000..ae3907656
--- /dev/null
+++ b/private/crt32/winheap/malloc.c
@@ -0,0 +1,104 @@
+/***
+*malloc.c - Win32 malloc/free heap routines
+*
+* Copyright (c) 1991-1992, Microsoft Corporation. All rights reserved.
+*
+*Purpose:
+*
+*Revision History:
+* 01-10-92 JCR Module created.
+* 02-04-92 GJF Replaced windows.h with oscalls.h.
+* 05-06-92 DJM POSIX support.
+* 06-15-92 KRS Enable C++ support.
+* 09-09-92 SRW _POSIX_ not even close.
+* 09-23-92 SRW Change winheap code to call NT directly always
+* 10-28-92 SRW Change winheap code to call Heap????Ex calls
+* 11-05-92 SKS Change name of variable "CrtHeap" to "_crtheap"
+* 11-07-92 SRW _NTIDW340 replaced by linkopts\betacmp.c
+* 11-16-92 SRW Heap???Ex functions renamed to Heap???
+*
+*******************************************************************************/
+
+#include <cruntime.h>
+#include <malloc.h>
+#include <winheap.h>
+#include <os2dll.h>
+#include <oscalls.h>
+
+#ifndef _POSIX_
+#include <new.h>
+_PNH _pnhHeap = NULL;
+#endif
+
+/***
+*void *malloc(size_t size) - Get a block of memory from the heap
+*
+*Purpose:
+* Allocate of block of memory of at least size bytes from the heap and
+* return a pointer to it.
+*
+*Entry:
+* size_t size - size of block requested
+*
+*Exit:
+* Success: Pointer to memory block
+* Failure: NULL (or some error value)
+*
+*Uses:
+*
+*Exceptions:
+*
+*******************************************************************************/
+
+void * _CALLTYPE1 malloc(n)
+size_t n;
+
+{
+ HANDLE h;
+ n = (n ? n : 1); /* if n == 0, n = 1 */
+
+#ifndef _POSIX_
+ for (;;) {
+#endif /* ndef _POSIX_ */
+
+ h = HeapAlloc(_crtheap,
+ 0,
+ n
+ );
+#ifndef _POSIX_
+ if ((h != 0) || (_pnhHeap == NULL) || (*_pnhHeap)(n) == 0)
+#endif /* ndef _POSIX_ */
+ return((void *)h);
+
+#ifndef _POSIX_
+ }
+#endif /* ndef _POSIX_ */
+}
+
+/***
+*void free(pblock) - free a block in the heap
+*
+*Purpose:
+* Free a memory block in the heap.
+*
+* Special ANSI Requirements:
+*
+* (1) free(NULL) is benign.
+*
+*Entry:
+* void *pblock - pointer to a memory block in the heap
+*
+*Return:
+* <void>
+*
+*******************************************************************************/
+
+void _CALLTYPE1 free(pblock)
+void * pblock;
+
+{
+ HeapFree(_crtheap,
+ 0,
+ pblock
+ );
+}
diff --git a/private/crt32/winheap/msize.c b/private/crt32/winheap/msize.c
new file mode 100644
index 000000000..37752cf46
--- /dev/null
+++ b/private/crt32/winheap/msize.c
@@ -0,0 +1,49 @@
+/***
+*msize.c - Win32 malloc/free heap routines
+*
+* Copyright (c) 1991-1992, Microsoft Corporation. All rights reserved.
+*
+*Purpose:
+*
+*Revision History:
+* 01-10-92 JCR Module created.
+* 02-04-92 GJF Replaced windows.h with oscalls.h.
+* 05-06-92 DJM ifndef out for POSIX.
+* 09-23-92 SRW Change winheap code to call NT directly always
+* 10-28-92 SRW Change winheap code to call Heap????Ex calls
+* 11-05-92 SKS Change name of variable "CrtHeap" to "_crtheap"
+* 11-07-92 SRW _NTIDW340 replaced by linkopts\betacmp.c
+* 11-16-92 SRW Heap???Ex functions renamed to Heap???
+* 12-02-94 MJB POSIX back in.
+*
+*******************************************************************************/
+
+#include <cruntime.h>
+#include <malloc.h>
+#include <winheap.h>
+#include <oscalls.h>
+
+/***
+*size_t _msize(pblock) - calculate the size of specified block in the heap
+*
+*Purpose:
+* Calculates the size of memory block (in the heap) pointed to by
+* pblock.
+*
+*Entry:
+* void *p - pointer to a memory block in the heap
+*
+*Return:
+* size of the block
+*
+*******************************************************************************/
+
+size_t _CALLTYPE1 _msize(pblock)
+void * pblock;
+
+{
+ return((size_t)HeapSize(_crtheap,
+ 0,
+ pblock
+ ));
+}
diff --git a/private/crt32/winheap/new.cxx b/private/crt32/winheap/new.cxx
new file mode 100644
index 000000000..4a47fb1c5
--- /dev/null
+++ b/private/crt32/winheap/new.cxx
@@ -0,0 +1,28 @@
+/***
+*new.cxx - defines C++ new routine
+*
+* Copyright (c) 1990-1992, Microsoft Corporation. All rights reserved.
+*
+*Purpose:
+* Defines C++ new routine.
+*
+*Revision History:
+* 05-07-90 WAJ Initial version.
+* 08-30-90 WAJ new now takes unsigned ints.
+* 08-08-91 JCR call _halloc/_hfree, not halloc/hfree
+* 08-13-91 KRS Change new.hxx to new.h. Fix copyright.
+* 08-13-91 JCR ANSI-compatible _set_new_handler names
+* 10-30-91 JCR Split new, delete, and handler into seperate sources
+* 11-13-91 JCR 32-bit version
+*
+*******************************************************************************/
+
+#include <cruntime.h>
+#include <malloc.h>
+#include <new.h>
+
+
+void * operator new( unsigned int cb )
+{
+ return malloc( cb );
+}
diff --git a/private/crt32/winheap/realloc.c b/private/crt32/winheap/realloc.c
new file mode 100644
index 000000000..ac66611a4
--- /dev/null
+++ b/private/crt32/winheap/realloc.c
@@ -0,0 +1,85 @@
+/***
+*realloc.c - Win32 realloc heap routine
+*
+* Copyright (c) 1991-1992, Microsoft Corporation. All rights reserved.
+*
+*Purpose:
+*
+*Revision History:
+* 01-10-92 JCR Module created.
+* 02-04-92 GJF Replaced windows.h with oscalls.h.
+* 05-06-92 DJM POSIX support.
+* 09-09-92 SRW Fixed _POSIX_ to allow movement when growing.
+* 09-23-92 SRW Change winheap code to call NT directly always
+* 10-28-92 SRW Change winheap code to call Heap????Ex calls
+* 11-05-92 SKS Change name of variable "CrtHeap" to "_crtheap"
+* 11-07-92 SRW _NTIDW340 replaced by linkopts\betacmp.c
+* 11-16-92 SRW Heap???Ex functions renamed to Heap???
+*
+*******************************************************************************/
+
+#include <cruntime.h>
+#include <malloc.h>
+#include <winheap.h>
+#include <oscalls.h>
+
+/***
+*void *realloc(void *pblock, size_t newsize) - reallocate a block of memory in
+* the heap
+*
+*Purpose:
+* Re-allocates a block in the heap to newsize bytes. newsize may be
+* either greater or less than the original size of the block. The
+* re-allocation may result in moving the block as well as changing
+* the size. If the block is moved, the contents of the original block
+* are copied over.
+*
+* Special ANSI Requirements:
+*
+* (1) realloc(NULL, newsize) is equivalent to malloc(newsize)
+*
+* (2) realloc(pblock, 0) is equivalent to free(pblock) (except that
+* NULL is returned)
+*
+* (3) if the realloc() fails, the object pointed to by pblock is left
+* unchanged
+*
+*Entry:
+* void *pblock - pointer to block in the heap previously allocated
+* by a call to malloc(), realloc() or _expand().
+*
+* size_t newsize - requested size for the re-allocated block
+*
+*Exit:
+* Success: Pointer to the re-allocated memory block
+* Failure: NULL
+*
+*Uses:
+*
+*Exceptions:
+* If pblock does not point to a valid allocation block in the heap,
+* realloc() will behave unpredictably and probably corrupt the heap.
+*
+*******************************************************************************/
+
+void * _CALLTYPE1 realloc(pblock, n)
+void * pblock;
+size_t n;
+
+{
+ /* if ptr is NULL, call malloc */
+ if (pblock == (void *) NULL)
+ return(malloc(n));
+
+ /* if ptr is !NULL and size is 0, call free and return NULL */
+ if (n == 0) {
+ free(pblock);
+ return((void *) NULL);
+ }
+
+ return HeapReAlloc(_crtheap,
+ 0,
+ pblock,
+ n
+ );
+}
diff --git a/private/crt32/winheap/sources b/private/crt32/winheap/sources
new file mode 100644
index 000000000..add361dd9
--- /dev/null
+++ b/private/crt32/winheap/sources
@@ -0,0 +1,51 @@
+!IF 0
+
+Copyright (c) 1989 - 1992, Microsoft Corporation. All rights reserved.
+
+Module Name:
+
+ sources.
+
+Abstract:
+
+ This file specifies the target component being built and the list of
+ sources files needed to build that component. Also specifies optional
+ compiler switches and libraries that are unique for the component being
+ built.
+
+ Set MAKEFILE. for BLDCRT=1 definition that forces use of MS C8 C++ compiler
+ for all platforms to compile these files.
+
+Author:
+
+ Steve Wood (stevewo) 12-Apr-1990
+ jeffrob 29-sep-1990, use crt32.def
+ karlsi 15-Jun-92, added new.cxx/delete.cxx/handler.cxx.
+
+NOTE: Commented description of this file is in \nt\bak\bin\sources.tpl
+
+!ENDIF
+
+MAJORCOMP=crt
+MINORCOMP=winheap
+
+TARGETNAME=winheap
+TARGETPATH=..\obj
+TARGETTYPE=LIBRARY
+386_STDCALL=0
+
+!INCLUDE ..\crt32.def
+
+SOURCES=calloc.c \
+ delete.cxx \
+ expand.c \
+ handler.cxx \
+ heapinit.c \
+ heapchk.c \
+ heapmin.c \
+ heapwalk.c \
+ hpabort.c \
+ malloc.c \
+ msize.c \
+ new.cxx \
+ realloc.c