Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3584 sourcerer 1
/** \file
2
 * Heap debugging functions (interface).
3
 *
4
 * Based on memdebug.h from curl (see below), with the following modifications:
5
 *
6
 * - renamed functions from curl_ to memdebug_
7
 * - added memdebug_strndup
8
 * - added guard bytes before and after each block to help detect overflows
9
 * - if a guard byte is corrupted during free, dumps the DA to file
10
 */
11
 
12
/***************************************************************************
13
 *                                  _   _ ____  _
14
 *  Project                     ___| | | |  _ \| |
15
 *                             / __| | | | |_) | |
16
 *                            | (__| |_| |  _ <| |___
17
 *                             \___|\___/|_| \_\_____|
18
 *
19
 * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al.
20
 *
21
 * This software is licensed as described in the file COPYING, which
22
 * you should have received as part of this distribution. The terms
23
 * are also available at http://curl.haxx.se/docs/copyright.html.
24
 *
25
 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
26
 * copies of the Software, and permit persons to whom the Software is
27
 * furnished to do so, under the terms of the COPYING file.
28
 *
29
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
30
 * KIND, either express or implied.
31
 *
32
 * $Id: memdebug.h,v 1.1 2004/07/28 22:35:02 bursa Exp $
33
 ***************************************************************************/
34
 
35
#ifndef _MEMDEBUG_H_
36
#define _MEMDEBUG_H_
37
 
38
#include 
39
#include 
40
#include 
41
#include 
42
#include 
43
 
44
#define logfile memdebug_debuglogfile
45
 
46
extern FILE *logfile;
47
 
48
/* memory functions */
49
void *memdebug_malloc(size_t size, int line, const char *source);
50
void *memdebug_calloc(size_t elements, size_t size, int line, const char *source);
51
void *memdebug_realloc(void *ptr, size_t size, int line, const char *source);
52
void memdebug_free(void *ptr, int line, const char *source);
53
char *memdebug_strdup(const char *str, int line, const char *source);
54
char *memdebug_strndup(const char *str, size_t size, int line, const char *source);
55
void memdebug_memdebug(const char *logname);
56
void memdebug_memlimit(long limit);
57
 
58
/* file descriptor manipulators */
59
int memdebug_socket(int domain, int type, int protocol, int line , const char *);
60
int memdebug_sclose(int sockfd, int, const char *source);
61
int memdebug_accept(int s, void *addr, void *addrlen,
62
                int line, const char *source);
63
 
64
/* FILE functions */
65
FILE *memdebug_fopen(const char *file, const char *mode, int line,
66
                 const char *source);
67
int memdebug_fclose(FILE *file, int line, const char *source);
68
 
69
#ifndef MEMDEBUG_NODEFINES
70
 
71
#undef strdup
72
#define strdup(ptr) memdebug_strdup(ptr, __LINE__, __FILE__)
73
#define strndup(ptr,size) memdebug_strndup(ptr, size, __LINE__, __FILE__)
74
#define malloc(size) memdebug_malloc(size, __LINE__, __FILE__)
75
#define calloc(nbelem,size) memdebug_calloc(nbelem, size, __LINE__, __FILE__)
76
#define realloc(ptr,size) memdebug_realloc(ptr, size, __LINE__, __FILE__)
77
#define free(ptr) memdebug_free(ptr, __LINE__, __FILE__)
78
 
79
#define socket(domain,type,protocol)\
80
 memdebug_socket(domain,type,protocol,__LINE__,__FILE__)
81
#undef accept /* for those with accept as a macro */
82
#define accept(sock,addr,len)\
83
 memdebug_accept(sock,addr,len,__LINE__,__FILE__)
84
 
85
#define getaddrinfo(host,serv,hint,res) \
86
  memdebug_getaddrinfo(host,serv,hint,res,__LINE__,__FILE__)
87
#define getnameinfo(sa,salen,host,hostlen,serv,servlen,flags) \
88
  memdebug_getnameinfo(sa,salen,host,hostlen,serv,servlen,flags, __LINE__, \
89
  __FILE__)
90
#define freeaddrinfo(data) \
91
  memdebug_freeaddrinfo(data,__LINE__,__FILE__)
92
 
93
/* sclose is probably already defined, redefine it! */
94
#undef sclose
95
#define sclose(sockfd) memdebug_sclose(sockfd,__LINE__,__FILE__)
96
/* ares-adjusted define: */
97
#undef closesocket
98
#define closesocket(sockfd) memdebug_sclose(sockfd,__LINE__,__FILE__)
99
 
100
#undef fopen
101
#define fopen(file,mode) memdebug_fopen(file,mode,__LINE__,__FILE__)
102
#define fclose(file) memdebug_fclose(file,__LINE__,__FILE__)
103
 
104
#endif /* MEMDEBUG_NODEFINES */
105
 
106
#endif