00001 /* 00002 * PSP Software Development Kit - http://www.pspdev.org 00003 * ----------------------------------------------------------------------- 00004 * Licensed under the BSD license, see LICENSE in PSPSDK root for details. 00005 * 00006 * malloc.h 00007 * 00008 * Copyright (c) 2002-2004 PS2DEV 00009 * Copyright (c) 2005 Marcus R. Brown <mrbrown@ocgnet.org> 00010 * Copyright (c) 2005 James Forshaw <tyranid@gmail.com> 00011 * Copyright (c) 2005 John Kelley <ps2dev@kelley.ca> 00012 * 00013 * $Id: malloc.h 1095 2005-09-27 21:02:16Z jim $ 00014 */ 00015 00016 #ifndef _MALLOC_H 00017 #define _MALLOC_H 00018 00019 #include <pspkernel.h> 00020 #include <stddef.h> 00021 #include <stdarg.h> 00022 00023 #ifdef __cplusplus 00024 extern "C" { 00025 #endif 00026 00027 /* stdlib/malloc */ 00028 void * malloc(size_t size); 00029 void * realloc(void *ptr, size_t size); 00030 void * calloc(size_t n, size_t size); 00031 void * memalign(size_t align, size_t size); 00032 void free(void * ptr); 00033 00034 /* Memory walkers. Used for debugging/profiling purposes. */ 00035 void * __mem_walk_begin(void); 00036 void __mem_walk_read(void * token, u32 * size, void ** ptr, int * valid); 00037 void * __mem_walk_inc(void * token); 00038 int __mem_walk_end(void * token); 00039 00040 /* Example of use: 00041 00042 void * i; 00043 00044 for (i = __mem_walk_begin(); !__mem_walk_end(i); i = __mem_walk_inc(i)) { 00045 u32 block_size; 00046 void * block_ptr; 00047 int valid; 00048 00049 __mem_walk_read(i, &block_size, &block_ptr, &valid); 00050 if (!valid) { 00051 fprintf(stderr, "Block at token %p is invalid.\n", i); 00052 break; 00053 } 00054 printf("Block at token %p points at a memory block of %i bytes at %p.\n", i, block_size, block_ptr); 00055 } 00056 00057 note that 'valid' will be always true if DEBUG_ALLOC was not defined when alloc.c got compiled. 00058 00059 */ 00060 00061 #ifdef __cplusplus 00062 } 00063 #endif 00064 00065 #endif // _MALLOC_H 00066