Added protected memory allocation to stacktrace
[runtime.git] / lib / silcutil / stacktrace.h
1 /*
2
3   stacktrace.h 
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2002 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 #ifndef STACKTRACE_H
21 #define STACKTRACE_H
22
23 #ifndef SILCMEMORY_H
24 #error "Do not include internal header file directly"
25 #endif
26
27 #if (defined(__GNUC__) && defined(HAVE_EXECINFO_H) &&                   \
28      defined(HAVE_BACKTRACE)) || defined(__SILC_ENABLE_STACKTRACE)
29
30 #undef strdup
31 #define silc_malloc(s)      silc_st_malloc((s), __FILE__, __LINE__)
32 #define silc_calloc(i, s)   silc_st_calloc((i), (s), __FILE__, __LINE__)
33 #define silc_realloc(p, s)  silc_st_realloc((p), (s), __FILE__, __LINE__)
34 #define silc_free(p)        silc_st_free((p), __FILE__, __LINE__)
35 #define silc_memdup(p, s)   silc_st_memdup((p), (s), __FILE__, __LINE__)
36 #define silc_strdup(s)      silc_st_strdup((s), __FILE__, __LINE__)
37 #define strdup(s)           silc_st_strdup((s), __FILE__, __LINE__)
38
39 void *silc_st_malloc(size_t size, const char *file, int line);
40 void *silc_st_calloc(size_t items, size_t size, const char *file, int line);
41 void *silc_st_realloc(void *ptr, size_t size, const char *file, int line);
42 void silc_st_free(void *ptr, const char *file, int line);
43 void *silc_st_memdup(const void *ptr, size_t size, const char *file, int line);
44 void *silc_st_strdup(const char *string, const char *file, int line);
45 void silc_st_dump(void);
46
47 #else
48 #error "memory allocation stack trace not supported on this platform"
49 #endif /* __GNUC__ && HAVE_EXECINFO_H && HAVE_BACKTRACE */
50
51 #endif /* STACKTRACE_H */