18a1362adSmaya/************************************************************************** 28a1362adSmaya * 38a1362adSmaya * Copyright 2008-2010 VMware, Inc. 48a1362adSmaya * All Rights Reserved. 58a1362adSmaya * 68a1362adSmaya * Permission is hereby granted, free of charge, to any person obtaining a 78a1362adSmaya * copy of this software and associated documentation files (the 88a1362adSmaya * "Software"), to deal in the Software without restriction, including 98a1362adSmaya * without limitation the rights to use, copy, modify, merge, publish, 108a1362adSmaya * distribute, sub license, and/or sell copies of the Software, and to 118a1362adSmaya * permit persons to whom the Software is furnished to do so, subject to 128a1362adSmaya * the following conditions: 138a1362adSmaya * 148a1362adSmaya * The above copyright notice and this permission notice (including the 158a1362adSmaya * next paragraph) shall be included in all copies or substantial portions 168a1362adSmaya * of the Software. 178a1362adSmaya * 188a1362adSmaya * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 198a1362adSmaya * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 208a1362adSmaya * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 218a1362adSmaya * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 228a1362adSmaya * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 238a1362adSmaya * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 248a1362adSmaya * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 258a1362adSmaya * 268a1362adSmaya **************************************************************************/ 278a1362adSmaya 288a1362adSmaya 298a1362adSmaya/* 308a1362adSmaya * Debugging wrappers for OS memory management abstractions. 318a1362adSmaya */ 328a1362adSmaya 338a1362adSmaya 348a1362adSmaya#ifndef _OS_MEMORY_H_ 358a1362adSmaya#error "Must not be included directly. Include os_memory.h instead" 368a1362adSmaya#endif 378a1362adSmaya 388a1362adSmaya 398a1362adSmaya#ifdef __cplusplus 408a1362adSmayaextern "C" { 418a1362adSmaya#endif 428a1362adSmaya 438a1362adSmaya 448a1362adSmayavoid * 458a1362adSmayadebug_malloc(const char *file, unsigned line, const char *function, 468a1362adSmaya size_t size); 478a1362adSmaya 488a1362adSmayavoid * 498a1362adSmayadebug_calloc(const char *file, unsigned line, const char *function, 508a1362adSmaya size_t count, size_t size ); 518a1362adSmaya 528a1362adSmayavoid 538a1362adSmayadebug_free(const char *file, unsigned line, const char *function, 548a1362adSmaya void *ptr); 558a1362adSmaya 568a1362adSmayavoid * 578a1362adSmayadebug_realloc(const char *file, unsigned line, const char *function, 588a1362adSmaya void *old_ptr, size_t old_size, size_t new_size ); 598a1362adSmaya 607ec681f3Smrgunsigned long 617ec681f3Smrgdebug_memory_begin(void); 627ec681f3Smrg 637ec681f3Smrgvoid 647ec681f3Smrgdebug_memory_end(unsigned long start_no); 657ec681f3Smrg 668a1362adSmayavoid 678a1362adSmayadebug_memory_tag(void *ptr, unsigned tag); 688a1362adSmaya 698a1362adSmayavoid 708a1362adSmayadebug_memory_check_block(void *ptr); 718a1362adSmaya 728a1362adSmayavoid 738a1362adSmayadebug_memory_check(void); 748a1362adSmaya 758a1362adSmaya 768a1362adSmaya#ifdef __cplusplus 778a1362adSmaya} 788a1362adSmaya#endif 798a1362adSmaya 808a1362adSmaya 818a1362adSmaya#ifndef DEBUG_MEMORY_IMPLEMENTATION 828a1362adSmaya 838a1362adSmaya#define os_malloc( _size ) \ 848a1362adSmaya debug_malloc( __FILE__, __LINE__, __FUNCTION__, _size ) 858a1362adSmaya#define os_calloc( _count, _size ) \ 868a1362adSmaya debug_calloc(__FILE__, __LINE__, __FUNCTION__, _count, _size ) 878a1362adSmaya#define os_free( _ptr ) \ 888a1362adSmaya debug_free( __FILE__, __LINE__, __FUNCTION__, _ptr ) 898a1362adSmaya#define os_realloc( _ptr, _old_size, _new_size ) \ 908a1362adSmaya debug_realloc( __FILE__, __LINE__, __FUNCTION__, _ptr, _old_size, _new_size ) 918a1362adSmaya 928a1362adSmaya/* TODO: wrap os_malloc_aligned() and os_free_aligned() too */ 938a1362adSmaya#include "os_memory_aligned.h" 948a1362adSmaya 958a1362adSmaya#endif /* !DEBUG_MEMORY_IMPLEMENTATION */ 96