Back to index

lightning-sunbird  0.9+nobinonly
libmalloc.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is mozilla.org code.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 1999
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Kipp E.B. Hickman <kipp@netscape.com> (original author)
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef libmalloc_h___
00039 #define libmalloc_h___
00040 
00041 #include <sys/types.h>
00042 #include <malloc.h>
00043 
00044 #ifdef __cplusplus
00045 extern "C" {
00046 #endif
00047 
00048 #include "config.h"
00049 
00050 typedef unsigned long u_long;
00051 
00052 // Format of a malloc log entry. This is whats written out to the
00053 // "malloc-log" file.
00054 struct malloc_log_entry {
00055   u_long type;
00056   u_long address;
00057   u_long size;
00058   u_long oldaddress;
00059   u_long numpcs;
00060   char* pcs[MAX_STACK_CRAWL];
00061 };
00062 
00063 // type's
00064 #define malloc_log_malloc  0
00065 #define malloc_log_realloc 1
00066 #define malloc_log_free    2
00067 #define malloc_log_new     3
00068 #define malloc_log_delete  4
00069 #define malloc_log_addref  5
00070 #define malloc_log_release 6
00071 
00072 // Format of a malloc map entry; after this struct is nameLen+1 bytes of
00073 // name data.
00074 struct malloc_map_entry {
00075   u_long nameLen;
00076   u_long address;           // base address
00077 };
00078 
00079 // A method that can be called if you want to programmatically control
00080 // the malloc logging. Note that you must link with the library to do
00081 // this (or use dlsym after dynamically loading the library...)
00082 extern u_long SetMallocFlags(u_long flags);
00083 
00084 // The environment variable LIBMALLOC_LOG should be set to an integer
00085 // value whose meaning is as follows:
00086 
00087 // Enable logging
00088 #define LIBMALLOC_LOG    0x1
00089 
00090 // Don't free memory when set
00091 #define LIBMALLOC_NOFREE 0x2
00092 
00093 // Check heap for corruption after every malloc/free/realloc
00094 #define LIBMALLOC_CHECK  0x4
00095 
00096 // Log reference count calls (addref/release)
00097 #define LIBMALLOC_LOG_RC 0x8
00098 
00099 void __log_addref(void* p, int oldrc, int newrc);
00100 void __log_release(void* p, int oldrc, int newrc);
00101 
00102 #ifdef __cplusplus
00103 }; /* end of extern "C" */
00104 #endif
00105 
00106 #endif /* libmalloc_h___ */