]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/smartall.h
crypto: convert EVP_PKEY access and remainings bits for OpenSSL 1.1
[bacula/bacula] / bacula / src / lib / smartall.h
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2017 Kern Sibbald
5
6    The original author of Bacula is Kern Sibbald, with contributions
7    from many others, a complete list can be found in the file AUTHORS.
8
9    You may use this file and others of this release according to the
10    license defined in the LICENSE file, which includes the Affero General
11    Public License, v3.0 ("AGPLv3") and some additional permissions and
12    terms pursuant to its AGPLv3 Section 7.
13
14    This notice must be preserved when any source code is 
15    conveyed and/or propagated.
16
17    Bacula(R) is a registered trademark of Kern Sibbald.
18 */
19 /*
20
21         Definitions for the smart memory allocator
22
23 */
24
25 #ifndef SMARTALLOC_H
26 #define SMARTALLOC_H
27
28 extern uint64_t DLL_IMP_EXP sm_max_bytes;
29 extern uint64_t DLL_IMP_EXP sm_bytes;
30 extern uint32_t DLL_IMP_EXP sm_max_buffers;
31 extern uint32_t DLL_IMP_EXP sm_buffers;
32
33 #ifdef  SMARTALLOC
34 #undef  SMARTALLOC
35 #define SMARTALLOC SMARTALLOC
36
37
38 /* Avoid aggressive GCC optimization */
39 extern void *bmemset(void *s, int c, size_t n);
40
41 extern void *sm_malloc(const char *fname, int lineno, unsigned int nbytes),
42             *sm_calloc(const char *fname, int lineno,
43                 unsigned int nelem, unsigned int elsize),
44             *sm_realloc(const char *fname, int lineno, void *ptr, unsigned int size),
45             *actuallymalloc(unsigned int size),
46             *actuallycalloc(unsigned int nelem, unsigned int elsize),
47             *actuallyrealloc(void *ptr, unsigned int size);
48 extern void sm_free(const char *fname, int lineno, void *fp);
49 extern void actuallyfree(void *cp),
50             sm_dump(bool bufdump, bool in_use=false), sm_static(int mode);
51 extern void sm_new_owner(const char *fname, int lineno, char *buf);
52
53 #ifdef SMCHECK
54 #define Dsm_check(lvl) if ((lvl)<=debug_level) sm_check(__FILE__, __LINE__, true)
55 extern void sm_check(const char *fname, int lineno, bool bufdump);
56 extern int sm_check_rtn(const char *fname, int lineno, bool bufdump);
57 #else
58 #define Dsm_check(lvl)
59 #define sm_check(f, l, fl)
60 #define sm_check_rtn(f, l, fl) 1
61 #endif
62
63
64 /* Redefine standard memory allocator calls to use our routines
65    instead. */
66
67 #define free(x)        sm_free(__FILE__, __LINE__, (void *)(x))
68 #define cfree(x)       sm_free(__FILE__, __LINE__, (void *)(x))
69 #define malloc(x)      sm_malloc(__FILE__, __LINE__, (x))
70 #define calloc(n,e)    sm_calloc(__FILE__, __LINE__, (n), (e))
71 #define realloc(p,x)   sm_realloc(__FILE__, __LINE__, (p), (x))
72
73 #else
74
75 /* If SMARTALLOC is disabled, define its special calls to default to
76    the standard routines.  */
77
78 #define actuallyfree(x)      free(x)
79 #define actuallymalloc(x)    malloc(x)
80 #define actuallycalloc(x,y)  calloc(x,y)
81 #define actuallyrealloc(x,y) realloc(x,y)
82 inline void sm_dump(int x, int y=0) {} /* with default arguments, we can't use a #define */
83 #define sm_static(x)
84 #define sm_new_owner(a, b, c)
85 #define sm_malloc(f, l, n)     malloc(n)
86 #define sm_free(f, l, n)       free(n)
87 #define sm_check(f, l, fl)
88 #define sm_check_rtn(f, l, fl) 1
89
90 extern void *b_malloc(const char *file, int line, size_t size);
91 #define malloc(x) b_malloc(__FILE__, __LINE__, (x))
92
93 #define Dsm_check(lvl)
94 #define sm_check(f, l, fl)
95 #define sm_check_rtn(f, l, fl) 1
96
97 #endif
98
99 #ifdef SMARTALLOC
100
101 #define New(type) new(__FILE__, __LINE__) type
102
103 /* We do memset(0) because it's not possible to memset a class when
104  * using subclass with virtual functions
105  */
106
107 class SMARTALLOC
108 {
109 public:
110
111 void *operator new(size_t s, const char *fname, int line)
112 {
113    size_t size =  s > sizeof(int) ? (unsigned int)s : sizeof(int);
114    void *p = sm_malloc(fname, line, size);
115    return bmemset(p, 0, size);   /* return memset() result to avoid GCC 6.1 issue */
116 }
117 void *operator new[](size_t s, const char *fname, int line)
118 {
119    size_t size =  s > sizeof(int) ? (unsigned int)s : sizeof(int);
120    void *p = sm_malloc(fname, line, size);
121    return bmemset(p, 0, size);  /* return memset() result to avoid GCC 6.1 issue */
122 }
123
124 void  operator delete(void *ptr)
125 {
126    free(ptr);
127 }
128 void  operator delete[](void *ptr, size_t /*i*/)
129 {
130    free(ptr);
131 }
132
133 void  operator delete(void *ptr, const char * /*fname*/, int /*line*/)
134 {
135    free(ptr);
136 }
137 void  operator delete[](void *ptr, size_t /*i*/,
138                         const char * /*fname*/, int /*line*/)
139 {
140    free(ptr);
141 }
142
143 private:
144 void *operator new(size_t s) throw() { (void)s; return 0; }
145 void *operator new[](size_t s) throw() { (void)s; return 0; }
146 };
147
148 #else
149
150 #define New(type) new type
151
152 class SMARTALLOC
153 {
154    public:
155       void *operator new(size_t s) {
156          void *p = malloc(s);
157          bmemset(p, 0, s);
158          return p;
159       }
160       void *operator new[](size_t s) {
161          void *p = malloc(s);
162          bmemset(p, 0, s);
163          return p;
164       }
165       void  operator delete(void *ptr) {
166           free(ptr);
167       }
168       void  operator delete[](void *ptr, size_t i) {
169           free(ptr);
170       }
171 };
172 #endif  /* SMARTALLOC */
173 #endif  /* !SMARTALLOC_H */