@@ -35,6 +35,12 @@ extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__));
35
35
extern " C" void __cxa_deleted_virtual (void ) __attribute__ ((__noreturn__));
36
36
37
37
38
+ #if DEV_DEBUG_ABI_CPP
39
+ extern " C" void _dbg_abi_print_pstr (const char * op, const char *function_name, const void * caller);
40
+ #define DEBUG_NEW_OP_PRINTF () _dbg_abi_print_pstr(" new_op" , __PRETTY_FUNCTION__, NULL )
41
+ #else
42
+ #define DEBUG_NEW_OP_PRINTF () do { } while (false )
43
+ #endif
38
44
/*
39
45
This is what I perceived to be the intent of the original code.
40
46
@@ -79,10 +85,12 @@ static void* _heap_new_align(std::size_t size, std::size_t alignment, const void
79
85
"alignment - specifies the alignment. Must be a valid alignment
80
86
supported by the implementation."
81
87
82
- I leave the validation to the umm_malloc library. See umm_memalign() for
83
- details. Generally speaking, zero is handled as default and the default
84
- is sizeof(umm_block), 8-bytes.
85
- */
88
+ I left the validation to the umm_malloc library. See umm_memalign() for
89
+ details. Generally speaking, zero is handled as default, and the default
90
+ is sizeof(umm_block), 8 bytes. Since the default is 8 bytes, the
91
+ umm_malloc library is less strict about checking alignments less than 8
92
+ bytes.
93
+ */
86
94
87
95
void * p;
88
96
@@ -101,18 +109,24 @@ static void* _heap_new_align(std::size_t size, std::size_t alignment, const void
101
109
// new_opa
102
110
void * operator new (std::size_t size, std::align_val_t alignment)
103
111
{
112
+ DEBUG_NEW_OP_PRINTF ();
113
+
104
114
return _heap_new_align (size, std::size_t (alignment), __builtin_return_address (0 ));
105
115
}
106
116
107
117
// new_opva
108
118
void * operator new [] (std::size_t size, std::align_val_t alignment)
109
119
{
120
+ DEBUG_NEW_OP_PRINTF ();
121
+
110
122
return _heap_new_align (size, std::size_t (alignment), __builtin_return_address (0 ));
111
123
}
112
124
113
125
// new_opant
114
126
void * operator new (std::size_t size, std::align_val_t alignment, const std::nothrow_t &) noexcept
115
127
{
128
+ DEBUG_NEW_OP_PRINTF ();
129
+
116
130
__try {
117
131
return _heap_new_align (size, std::size_t (alignment), __builtin_return_address (0 ));
118
132
}
@@ -124,6 +138,8 @@ void* operator new (std::size_t size, std::align_val_t alignment, const std::not
124
138
// new_opvant
125
139
void * operator new [] (std::size_t size, std::align_val_t alignment, const std::nothrow_t &) noexcept
126
140
{
141
+ DEBUG_NEW_OP_PRINTF ();
142
+
127
143
__try {
128
144
return _heap_new_align (size, std::size_t (alignment), __builtin_return_address (0 ));
129
145
}
@@ -135,18 +151,24 @@ void* operator new[] (std::size_t size, std::align_val_t alignment, const std::n
135
151
// new_op
136
152
void * operator new (std::size_t size)
137
153
{
154
+ DEBUG_NEW_OP_PRINTF ();
155
+
138
156
return _heap_new_align (size, __STDCPP_DEFAULT_NEW_ALIGNMENT__, __builtin_return_address (0 ));
139
157
}
140
158
141
159
// new_opv
142
160
void * operator new [] (std::size_t size)
143
161
{
162
+ DEBUG_NEW_OP_PRINTF ();
163
+
144
164
return _heap_new_align (size, __STDCPP_DEFAULT_NEW_ALIGNMENT__, __builtin_return_address (0 ));
145
165
}
146
166
147
167
// new_opnt
148
168
void * operator new (size_t size, const std::nothrow_t &) noexcept
149
169
{
170
+ DEBUG_NEW_OP_PRINTF ();
171
+
150
172
__try {
151
173
return _heap_new_align (size, __STDCPP_DEFAULT_NEW_ALIGNMENT__, __builtin_return_address (0 ));
152
174
}
@@ -158,6 +180,8 @@ void* operator new (size_t size, const std::nothrow_t&) noexcept
158
180
// new_opvnt
159
181
void * operator new [] (size_t size, const std::nothrow_t &) noexcept
160
182
{
183
+ DEBUG_NEW_OP_PRINTF ();
184
+
161
185
__try {
162
186
return _heap_new_align (size, __STDCPP_DEFAULT_NEW_ALIGNMENT__, __builtin_return_address (0 ));
163
187
}
@@ -188,16 +212,22 @@ static void* _heap_new(std::size_t size, const void* caller)
188
212
189
213
void * operator new (std::size_t size)
190
214
{
215
+ DEBUG_NEW_OP_PRINTF ();
216
+
191
217
return _heap_new (size, __builtin_return_address (0 ));
192
218
}
193
219
194
220
void * operator new [] (std::size_t size)
195
221
{
222
+ DEBUG_NEW_OP_PRINTF ();
223
+
196
224
return _heap_new (size, __builtin_return_address (0 ));
197
225
}
198
226
199
227
void * operator new (size_t size, const std::nothrow_t &) noexcept
200
228
{
229
+ DEBUG_NEW_OP_PRINTF ();
230
+
201
231
__try {
202
232
return _heap_new (size, __builtin_return_address (0 ));
203
233
}
@@ -208,6 +238,8 @@ void* operator new (size_t size, const std::nothrow_t&) noexcept
208
238
209
239
void * operator new [] (size_t size, const std::nothrow_t &) noexcept
210
240
{
241
+ DEBUG_NEW_OP_PRINTF ();
242
+
211
243
__try {
212
244
return _heap_new (size, __builtin_return_address (0 ));
213
245
}
@@ -230,41 +262,57 @@ void* operator new[] (size_t size, const std::nothrow_t&) noexcept
230
262
231
263
void * operator new (size_t size, std::align_val_t alignment)
232
264
{
265
+ DEBUG_NEW_OP_PRINTF ();
266
+
233
267
return _heap_abi_memalign (std::size_t (alignment), size, true , __builtin_return_address (0 ));
234
268
}
235
269
236
270
void * operator new [] (size_t size, std::align_val_t alignment)
237
271
{
272
+ DEBUG_NEW_OP_PRINTF ();
273
+
238
274
return _heap_abi_memalign (std::size_t (alignment), size, true , __builtin_return_address (0 ));
239
275
}
240
276
241
277
void * operator new (size_t size, std::align_val_t alignment, const std::nothrow_t &)
242
278
{
279
+ DEBUG_NEW_OP_PRINTF ();
280
+
243
281
return _heap_abi_memalign (std::size_t (alignment), size, false , __builtin_return_address (0 ));
244
282
}
245
283
246
284
void * operator new [] (size_t size, std::align_val_t alignment, const std::nothrow_t &)
247
285
{
286
+ DEBUG_NEW_OP_PRINTF ();
287
+
248
288
return _heap_abi_memalign (std::size_t (alignment), size, false , __builtin_return_address (0 ));
249
289
}
250
290
251
291
void * operator new (size_t size)
252
292
{
293
+ DEBUG_NEW_OP_PRINTF ();
294
+
253
295
return _heap_abi_memalign (__STDCPP_DEFAULT_NEW_ALIGNMENT__, size, true , __builtin_return_address (0 ));
254
296
}
255
297
256
298
void * operator new [] (size_t size)
257
299
{
300
+ DEBUG_NEW_OP_PRINTF ();
301
+
258
302
return _heap_abi_memalign (__STDCPP_DEFAULT_NEW_ALIGNMENT__, size, true , __builtin_return_address (0 ));
259
303
}
260
304
261
305
void * operator new (size_t size, const std::nothrow_t &)
262
306
{
307
+ DEBUG_NEW_OP_PRINTF ();
308
+
263
309
return _heap_abi_memalign (__STDCPP_DEFAULT_NEW_ALIGNMENT__, size, false , __builtin_return_address (0 ));
264
310
}
265
311
266
312
void * operator new [] (size_t size, const std::nothrow_t &)
267
313
{
314
+ DEBUG_NEW_OP_PRINTF ();
315
+
268
316
return _heap_abi_memalign (__STDCPP_DEFAULT_NEW_ALIGNMENT__, size, false , __builtin_return_address (0 ));
269
317
}
270
318
@@ -275,32 +323,43 @@ void* operator new[] (size_t size, const std::nothrow_t&)
275
323
276
324
void * operator new (size_t size)
277
325
{
326
+ DEBUG_NEW_OP_PRINTF ();
327
+
278
328
return _heap_abi_malloc (size, true , __builtin_return_address (0 ));
279
329
}
280
330
281
331
void * operator new [] (size_t size)
282
332
{
333
+ DEBUG_NEW_OP_PRINTF ();
334
+
283
335
return _heap_abi_malloc (size, true , __builtin_return_address (0 ));
284
336
}
285
337
286
338
void * operator new (size_t size, const std::nothrow_t &)
287
339
{
340
+ DEBUG_NEW_OP_PRINTF ();
341
+
288
342
return _heap_abi_malloc (size, false , __builtin_return_address (0 ));
289
343
}
290
344
291
345
void * operator new [] (size_t size, const std::nothrow_t &)
292
346
{
347
+ DEBUG_NEW_OP_PRINTF ();
348
+
293
349
return _heap_abi_malloc (size, false , __builtin_return_address (0 ));
294
350
}
295
351
#endif // #elif !defined(__cpp_exceptions) #if defined(UMM_ENABLE_MEMALIGN)
296
352
#else
297
353
/*
298
- Using weaklink C++ Exception handlers in libstdc
299
- The "new" operators that express alignment should work through libstdc via
300
- memalign() in the umm_malloc library.
354
+ Using weaklink C++ Exception handlers in libstdc. The "new" operators that
355
+ express alignment should work through libstdc via memalign() in the umm_malloc
356
+ library.
357
+
358
+ Note that libstdc will fail errors in alignment value early. Thus, the
359
+ UMM_STATS_FULL alignment error count will be zero.
301
360
302
- This saves 20 bytes in the UMM_ENABLE_MEMALIGN=1 case and 32 bytes when
303
- UMM_ENABLE_MEMALIGN=0.
361
+ This saves about 20 bytes in the UMM_ENABLE_MEMALIGN=1 case and 32 bytes when
362
+ UMM_ENABLE_MEMALIGN=0.
304
363
305
364
*/
306
365
// D <<
0 commit comments