| 480 | } |
| 481 | |
| 482 | void* TCMalloc_SystemAlloc(size_t size, size_t *actual_size, |
| 483 | size_t alignment) { |
| 484 | // Discard requests that overflow |
| 485 | if (size + alignment < size) return NULL; |
| 486 | |
| 487 | SpinLockHolder lock_holder(&spinlock); |
| 488 | |
| 489 | if (!system_alloc_inited) { |
| 490 | InitSystemAllocators(); |
| 491 | system_alloc_inited = true; |
| 492 | } |
| 493 | |
| 494 | // Enforce minimum alignment |
| 495 | if (alignment < sizeof(MemoryAligner)) alignment = sizeof(MemoryAligner); |
| 496 | |
| 497 | void* result = sys_alloc->Alloc(size, actual_size, alignment); |
| 498 | if (result != NULL) { |
| 499 | if (actual_size) { |
| 500 | CheckAddressBits<kAddressBits>( |
| 501 | reinterpret_cast<uintptr_t>(result) + *actual_size - 1); |
| 502 | TCMalloc_SystemTaken += *actual_size; |
| 503 | } else { |
| 504 | CheckAddressBits<kAddressBits>( |
| 505 | reinterpret_cast<uintptr_t>(result) + size - 1); |
| 506 | TCMalloc_SystemTaken += size; |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | //printf("Allocated from %08X to %08X\n", result, (void*)((char*)result + (int)*actual_size)); |
| 511 | |
| 512 | return result; |
| 513 | } |
| 514 | |
| 515 | bool TCMalloc_CanRelease() |
| 516 | { |
no test coverage detected