|
13 | 13 | * - calloc()
|
14 | 14 | * - free()
|
15 | 15 | * - malloc()
|
16 |
| - * - malloc_usable_size() |
| 16 | + * - malloc_usable_size() for Linux or _msize() for Windows |
17 | 17 | * - realloc()
|
| 18 | + * |
| 19 | + * Additionally for Windows only: |
| 20 | + * - _aligned_malloc() |
| 21 | + * - _aligned_realloc() |
| 22 | + * - _aligned_recalloc() |
| 23 | + * - _aligned_msize() |
| 24 | + * - _aligned_free() |
| 25 | + * - _aligned_offset_malloc() |
| 26 | + * - _aligned_offset_realloc() |
| 27 | + * - _aligned_offset_recalloc() |
18 | 28 | */
|
19 | 29 |
|
20 | 30 | #if (defined PROXY_LIB_USES_JEMALLOC_POOL)
|
@@ -254,13 +264,6 @@ void free(void *ptr) {
|
254 | 264 | return;
|
255 | 265 | }
|
256 | 266 |
|
257 |
| -#ifdef _WIN32 |
258 |
| -void _free_dbg(void *userData, int blockType) { |
259 |
| - (void)blockType; // unused |
260 |
| - free(userData); |
261 |
| -} |
262 |
| -#endif |
263 |
| - |
264 | 267 | void *realloc(void *ptr, size_t size) {
|
265 | 268 | if (ptr == NULL) {
|
266 | 269 | return malloc(size);
|
@@ -318,3 +321,60 @@ size_t malloc_usable_size(void *ptr) {
|
318 | 321 |
|
319 | 322 | return 0; // unsupported in this case
|
320 | 323 | }
|
| 324 | + |
| 325 | +// Add Microsoft aligned variants |
| 326 | +#ifdef _WIN32 |
| 327 | + |
| 328 | +void *_aligned_malloc(size_t size, size_t alignment) { |
| 329 | + return aligned_alloc(alignment, size); |
| 330 | +} |
| 331 | + |
| 332 | +void *_aligned_realloc(void *ptr, size_t size, size_t alignment) { |
| 333 | + if (alignment == 0) { |
| 334 | + return realloc(ptr, size); |
| 335 | + } |
| 336 | + return NULL; // not supported in this case |
| 337 | +} |
| 338 | + |
| 339 | +void *_aligned_recalloc(void *ptr, size_t num, size_t size, size_t alignment) { |
| 340 | + (void)ptr; // unused |
| 341 | + (void)num; // unused |
| 342 | + (void)size; // unused |
| 343 | + (void)alignment; // unused |
| 344 | + return NULL; // not supported |
| 345 | +} |
| 346 | + |
| 347 | +size_t _aligned_msize(void *ptr, size_t alignment, size_t offset) { |
| 348 | + (void)alignment; // unused |
| 349 | + (void)offset; // unused |
| 350 | + return _msize(ptr); |
| 351 | +} |
| 352 | + |
| 353 | +void _aligned_free(void *ptr) { free(ptr); } |
| 354 | + |
| 355 | +void *_aligned_offset_malloc(size_t size, size_t alignment, size_t offset) { |
| 356 | + if (offset == 0) { |
| 357 | + return aligned_alloc(alignment, size); |
| 358 | + } |
| 359 | + return NULL; // not supported in this case |
| 360 | +} |
| 361 | + |
| 362 | +void *_aligned_offset_realloc(void *ptr, size_t size, size_t alignment, |
| 363 | + size_t offset) { |
| 364 | + if (alignment == 0 && offset == 0) { |
| 365 | + return realloc(ptr, size); |
| 366 | + } |
| 367 | + return NULL; // not supported in this case |
| 368 | +} |
| 369 | + |
| 370 | +void *_aligned_offset_recalloc(void *ptr, size_t num, size_t size, |
| 371 | + size_t alignment, size_t offset) { |
| 372 | + (void)ptr; // unused |
| 373 | + (void)num; // unused |
| 374 | + (void)size; // unused |
| 375 | + (void)alignment; // unused |
| 376 | + (void)offset; // unused |
| 377 | + return NULL; // not supported |
| 378 | +} |
| 379 | + |
| 380 | +#endif |
0 commit comments