10b0e7057128c213bee8d2158b976869475f7cb42José Fonseca/**************************************************************************
20b0e7057128c213bee8d2158b976869475f7cb42José Fonseca *
30b0e7057128c213bee8d2158b976869475f7cb42José Fonseca * Copyright 2008-2010 VMware, Inc.
40b0e7057128c213bee8d2158b976869475f7cb42José Fonseca * All Rights Reserved.
50b0e7057128c213bee8d2158b976869475f7cb42José Fonseca *
60b0e7057128c213bee8d2158b976869475f7cb42José Fonseca * Permission is hereby granted, free of charge, to any person obtaining a
70b0e7057128c213bee8d2158b976869475f7cb42José Fonseca * copy of this software and associated documentation files (the
80b0e7057128c213bee8d2158b976869475f7cb42José Fonseca * "Software"), to deal in the Software without restriction, including
90b0e7057128c213bee8d2158b976869475f7cb42José Fonseca * without limitation the rights to use, copy, modify, merge, publish,
100b0e7057128c213bee8d2158b976869475f7cb42José Fonseca * distribute, sub license, and/or sell copies of the Software, and to
110b0e7057128c213bee8d2158b976869475f7cb42José Fonseca * permit persons to whom the Software is furnished to do so, subject to
120b0e7057128c213bee8d2158b976869475f7cb42José Fonseca * the following conditions:
130b0e7057128c213bee8d2158b976869475f7cb42José Fonseca *
140b0e7057128c213bee8d2158b976869475f7cb42José Fonseca * The above copyright notice and this permission notice (including the
150b0e7057128c213bee8d2158b976869475f7cb42José Fonseca * next paragraph) shall be included in all copies or substantial portions
160b0e7057128c213bee8d2158b976869475f7cb42José Fonseca * of the Software.
170b0e7057128c213bee8d2158b976869475f7cb42José Fonseca *
180b0e7057128c213bee8d2158b976869475f7cb42José Fonseca * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
190b0e7057128c213bee8d2158b976869475f7cb42José Fonseca * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
200b0e7057128c213bee8d2158b976869475f7cb42José Fonseca * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
210b0e7057128c213bee8d2158b976869475f7cb42José Fonseca * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
220b0e7057128c213bee8d2158b976869475f7cb42José Fonseca * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
230b0e7057128c213bee8d2158b976869475f7cb42José Fonseca * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
240b0e7057128c213bee8d2158b976869475f7cb42José Fonseca * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
250b0e7057128c213bee8d2158b976869475f7cb42José Fonseca *
260b0e7057128c213bee8d2158b976869475f7cb42José Fonseca **************************************************************************/
270b0e7057128c213bee8d2158b976869475f7cb42José Fonseca
280b0e7057128c213bee8d2158b976869475f7cb42José Fonseca
290b0e7057128c213bee8d2158b976869475f7cb42José Fonseca/*
300b0e7057128c213bee8d2158b976869475f7cb42José Fonseca * Debugging wrappers for OS memory management abstractions.
310b0e7057128c213bee8d2158b976869475f7cb42José Fonseca */
320b0e7057128c213bee8d2158b976869475f7cb42José Fonseca
330b0e7057128c213bee8d2158b976869475f7cb42José Fonseca
340b0e7057128c213bee8d2158b976869475f7cb42José Fonseca#ifndef _OS_MEMORY_H_
350b0e7057128c213bee8d2158b976869475f7cb42José Fonseca#error "Must not be included directly. Include os_memory.h instead"
360b0e7057128c213bee8d2158b976869475f7cb42José Fonseca#endif
370b0e7057128c213bee8d2158b976869475f7cb42José Fonseca
380b0e7057128c213bee8d2158b976869475f7cb42José Fonseca
390b0e7057128c213bee8d2158b976869475f7cb42José Fonseca#include "pipe/p_compiler.h"
400b0e7057128c213bee8d2158b976869475f7cb42José Fonseca
410b0e7057128c213bee8d2158b976869475f7cb42José Fonseca
420b0e7057128c213bee8d2158b976869475f7cb42José Fonseca#ifdef __cplusplus
430b0e7057128c213bee8d2158b976869475f7cb42José Fonsecaextern "C" {
440b0e7057128c213bee8d2158b976869475f7cb42José Fonseca#endif
450b0e7057128c213bee8d2158b976869475f7cb42José Fonseca
460b0e7057128c213bee8d2158b976869475f7cb42José Fonseca
470b0e7057128c213bee8d2158b976869475f7cb42José Fonsecavoid *
480b0e7057128c213bee8d2158b976869475f7cb42José Fonsecadebug_malloc(const char *file, unsigned line, const char *function,
490b0e7057128c213bee8d2158b976869475f7cb42José Fonseca             size_t size);
500b0e7057128c213bee8d2158b976869475f7cb42José Fonseca
510b0e7057128c213bee8d2158b976869475f7cb42José Fonsecavoid *
520b0e7057128c213bee8d2158b976869475f7cb42José Fonsecadebug_calloc(const char *file, unsigned line, const char *function,
530b0e7057128c213bee8d2158b976869475f7cb42José Fonseca             size_t count, size_t size );
540b0e7057128c213bee8d2158b976869475f7cb42José Fonseca
550b0e7057128c213bee8d2158b976869475f7cb42José Fonsecavoid
560b0e7057128c213bee8d2158b976869475f7cb42José Fonsecadebug_free(const char *file, unsigned line, const char *function,
570b0e7057128c213bee8d2158b976869475f7cb42José Fonseca           void *ptr);
580b0e7057128c213bee8d2158b976869475f7cb42José Fonseca
590b0e7057128c213bee8d2158b976869475f7cb42José Fonsecavoid *
600b0e7057128c213bee8d2158b976869475f7cb42José Fonsecadebug_realloc(const char *file, unsigned line, const char *function,
610b0e7057128c213bee8d2158b976869475f7cb42José Fonseca              void *old_ptr, size_t old_size, size_t new_size );
620b0e7057128c213bee8d2158b976869475f7cb42José Fonseca
630b0e7057128c213bee8d2158b976869475f7cb42José Fonseca
640b0e7057128c213bee8d2158b976869475f7cb42José Fonseca#ifdef __cplusplus
650b0e7057128c213bee8d2158b976869475f7cb42José Fonseca}
660b0e7057128c213bee8d2158b976869475f7cb42José Fonseca#endif
670b0e7057128c213bee8d2158b976869475f7cb42José Fonseca
680b0e7057128c213bee8d2158b976869475f7cb42José Fonseca
690b0e7057128c213bee8d2158b976869475f7cb42José Fonseca#ifndef DEBUG_MEMORY_IMPLEMENTATION
700b0e7057128c213bee8d2158b976869475f7cb42José Fonseca
710b0e7057128c213bee8d2158b976869475f7cb42José Fonseca#define os_malloc( _size ) \
720b0e7057128c213bee8d2158b976869475f7cb42José Fonseca   debug_malloc( __FILE__, __LINE__, __FUNCTION__, _size )
730b0e7057128c213bee8d2158b976869475f7cb42José Fonseca#define os_calloc( _count, _size ) \
740b0e7057128c213bee8d2158b976869475f7cb42José Fonseca   debug_calloc(__FILE__, __LINE__, __FUNCTION__, _count, _size )
750b0e7057128c213bee8d2158b976869475f7cb42José Fonseca#define os_free( _ptr ) \
760b0e7057128c213bee8d2158b976869475f7cb42José Fonseca   debug_free( __FILE__, __LINE__, __FUNCTION__,  _ptr )
770b0e7057128c213bee8d2158b976869475f7cb42José Fonseca#define os_realloc( _ptr, _old_size, _new_size ) \
780b0e7057128c213bee8d2158b976869475f7cb42José Fonseca   debug_realloc( __FILE__, __LINE__, __FUNCTION__,  _ptr, _old_size, _new_size )
790b0e7057128c213bee8d2158b976869475f7cb42José Fonseca
800b0e7057128c213bee8d2158b976869475f7cb42José Fonseca/* TODO: wrap os_malloc_aligned() and os_free_aligned() too */
810b0e7057128c213bee8d2158b976869475f7cb42José Fonseca#include "os_memory_aligned.h"
820b0e7057128c213bee8d2158b976869475f7cb42José Fonseca
830b0e7057128c213bee8d2158b976869475f7cb42José Fonseca#endif /* !DEBUG_MEMORY_IMPLEMENTATION */
84