/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#if defined(DEBUG)
#include "debug_util.h"
#define DMEM_MIN(a,b) (a) < (b) ? (a) : (b)
#define DMEM_MAX(a,b) (a) > (b) ? (a) : (b)
typedef char byte_t;
enum {
};
/* Debug Info Header to precede allocated block */
typedef struct MemoryBlockHeader {
/* Tail to follow allocated block */
typedef struct MemoryBlockTail {
/* Linked list of allocated memory blocks */
typedef struct MemoryListLink {
int freed;
/**************************************************
* Global Data structures
*/
/**************************************************/
/*************************************************
* Client callback invocation functions
*/
}
}
}
}
}
}
/**************************************************/
/*************************************************
* Debug Memory Manager implementation
*/
}
return link;
}
int nbyte;
return FALSE;
}
}
return TRUE;
}
DASSERTMSG( header->linenumber > 0 && header->linenumber < MAX_LINENUM, "Header corruption, bad line number" );
DASSERTMSG( header->size <= DMemGlobalState.biggestBlock, "Header corruption, block size is too large");
DASSERTMSG( header->order <= DMemGlobalState.totalAllocs, "Header corruption, block order out of range");
}
DASSERTMSG( DMem_ClientCheckPtr(tail, sizeof(MemoryBlockTail)), "Tail corruption, invalid pointer");
}
/* check if the pointer is valid */
/* check if the block header is valid */
/* check that the memory itself is valid */
DASSERTMSG( DMem_ClientCheckPtr(memptr, DMEM_MIN(MAX_CHECK_BYTES,header->size)), "Block memory invalid" );
/* check that the pointer to the alloc list is valid */
DASSERTMSG( DMem_ClientCheckPtr(header->listEnter, sizeof(MemoryListLink)), "Header corruption, alloc list pointer invalid" );
/* check the tail of the block for overruns */
return header;
}
return header;
}
/*
* Should be called before any other DMem_XXX function
*/
void DMem_Initialize() {
DMemMutex = DMutex_Create();
}
void DMem_Shutdown() {
}
/*
* Allocates a block of memory, reserving extra space at the start and end of the
* block to store debug info on where the block was allocated, it's size, and
* 'guard' areas to catch overwrite/underwrite bugs
*/
if (DMemGlobalState.failNextAlloc) {
/* force an allocation failure if so ordered */
goto Exit;
}
/* allocate a block large enough to hold extra debug info */
goto Exit;
}
/* add block to list of allocated memory */
goto Exit;
}
/* store size of requested block */
/* update maximum block size */
/* update used memory total */
/* store filename and linenumber where allocation routine was called */
/* store the order the block was allocated in */
/* initialize memory to a recognizable 'inited' value */
/* put guard area before block */
/* put guard area after block */
Exit:
return memptr;
}
/*
* Frees block of memory allocated with DMem_AllocateBlock
*/
goto Exit;
}
/* get the debug block header preceding the allocated memory */
/* fill memory with recognizable 'freed' value */
/* mark block as freed */
/* update used memory total */
Exit:
}
static const char * reportFormat =
"file: %s, line %d\n"
"size: %d bytes\n"
"order: %d\n"
"-------";
}
/*
* Call this function at shutdown time to report any leaked blocks
*/
void DMem_ReportLeaks() {
/* Force memory leaks to be output regardless of trace settings */
DTRACE_PRINTLN("--------------------------");
DTRACE_PRINTLN("Debug Memory Manager Leaks");
DTRACE_PRINTLN("--------------------------");
/* walk through allocated list and dump any blocks not marked as freed */
}
}
}
}
}
}
void DMem_DisableMutex() {
}
#endif /* defined(DEBUG) */
/* The following line is only here to prevent compiler warnings
* on release (non-debug) builds
*/
static int dummyVariable = 0;