Path: blob/21.2-virgl/src/vulkan/util/vk_alloc.c
7141 views
/*1* Copyright 2021 Google LLC2* SPDX-License-Identifier: MIT3*/45#include "vk_alloc.h"67#include <stdlib.h>89#if __STDC_VERSION__ >= 201112L && !defined(_MSC_VER)10#include <stddef.h>11#define MAX_ALIGN alignof(max_align_t)12#else13/* long double might be 128-bit, but our callers do not need that anyway(?) */14#include <stdint.h>15#define MAX_ALIGN alignof(uint64_t)16#endif1718static VKAPI_ATTR void * VKAPI_CALL19vk_default_alloc(void *pUserData,20size_t size,21size_t alignment,22VkSystemAllocationScope allocationScope)23{24assert(MAX_ALIGN % alignment == 0);25return malloc(size);26}2728static VKAPI_ATTR void * VKAPI_CALL29vk_default_realloc(void *pUserData,30void *pOriginal,31size_t size,32size_t alignment,33VkSystemAllocationScope allocationScope)34{35assert(MAX_ALIGN % alignment == 0);36return realloc(pOriginal, size);37}3839static VKAPI_ATTR void VKAPI_CALL40vk_default_free(void *pUserData, void *pMemory)41{42free(pMemory);43}4445const VkAllocationCallbacks *46vk_default_allocator(void)47{48static const VkAllocationCallbacks allocator = {49.pfnAllocation = vk_default_alloc,50.pfnReallocation = vk_default_realloc,51.pfnFree = vk_default_free,52};53return &allocator;54}555657