diff options
| author | Jon Ashburn <jon@lunarg.com> | 2016-01-07 15:21:14 -0700 |
|---|---|---|
| committer | Jon Ashburn <jon@lunarg.com> | 2016-01-07 15:22:56 -0700 |
| commit | 465f5eefb1935edc6aef8dd6eba24e040d22f14f (patch) | |
| tree | d5fbc1e33bffe57155d382aae2281ad1b2d06499 | |
| parent | 0ed2bbf5ff017ad96fadf2b18dce08d13e04dd8b (diff) | |
| download | usermoji-465f5eefb1935edc6aef8dd6eba24e040d22f14f.tar.xz | |
misc: make sure host memory alignment is a power of two
Use sizeof(int) as a default generally. Is that reasonable?
| -rw-r--r-- | icd/common/icd-enumerate-drm.c | 2 | ||||
| -rw-r--r-- | icd/common/icd-instance.c | 6 | ||||
| -rw-r--r-- | loader/debug_report.c | 2 | ||||
| -rw-r--r-- | loader/loader.c | 6 | ||||
| -rw-r--r-- | loader/trampoline.c | 2 |
5 files changed, 10 insertions, 8 deletions
diff --git a/icd/common/icd-enumerate-drm.c b/icd/common/icd-enumerate-drm.c index 857088b4..9f684551 100644 --- a/icd/common/icd-enumerate-drm.c +++ b/icd/common/icd-enumerate-drm.c @@ -123,7 +123,7 @@ static struct icd_drm_device *probe_syspath(const struct icd_instance *instance, return devices; } else { - dev = icd_instance_alloc(instance, sizeof(*dev), 0, + dev = icd_instance_alloc(instance, sizeof(*dev), sizeof(int), VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); if (!dev) return devices; diff --git a/icd/common/icd-instance.c b/icd/common/icd-instance.c index 0219a771..e89f0eaf 100644 --- a/icd/common/icd-instance.c +++ b/icd/common/icd-instance.c @@ -78,7 +78,7 @@ struct icd_instance *icd_instance_create(const VkApplicationInfo *app_info, if (!alloc_cb) alloc_cb = &default_alloc_cb; - instance = alloc_cb->pfnAllocation(alloc_cb->pUserData, sizeof(*instance), 0, + instance = alloc_cb->pfnAllocation(alloc_cb->pUserData, sizeof(*instance), sizeof(int), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); if (!instance) return NULL; @@ -87,7 +87,7 @@ struct icd_instance *icd_instance_create(const VkApplicationInfo *app_info, name = (app_info && app_info->pApplicationName) ? app_info->pApplicationName : "unnamed"; len = strlen(name); - instance->name = alloc_cb->pfnAllocation(alloc_cb->pUserData, len + 1, 0, + instance->name = alloc_cb->pfnAllocation(alloc_cb->pUserData, len + 1, sizeof(int), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); if (!instance->name) { alloc_cb->pfnFree(alloc_cb->pUserData, instance); @@ -130,7 +130,7 @@ VkResult icd_instance_create_logger( // return VK_ERROR_INVALID_POINTER; // } - logger = icd_instance_alloc(instance, sizeof(*logger), 0, + logger = icd_instance_alloc(instance, sizeof(*logger), sizeof(int), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (!logger) return VK_ERROR_OUT_OF_HOST_MEMORY; diff --git a/loader/debug_report.c b/loader/debug_report.c index ebb1ae29..4065fb03 100644 --- a/loader/debug_report.c +++ b/loader/debug_report.c @@ -74,7 +74,7 @@ VkResult util_CreateDebugReportCallback( { VkLayerDbgFunctionNode *pNewDbgFuncNode; if (pAllocator != NULL) { - pNewDbgFuncNode = (VkLayerDbgFunctionNode *) pAllocator->pfnAllocation(pAllocator->pUserData, sizeof(VkLayerDbgFunctionNode), sizeof(uint32_t), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); + pNewDbgFuncNode = (VkLayerDbgFunctionNode *) pAllocator->pfnAllocation(pAllocator->pUserData, sizeof(VkLayerDbgFunctionNode), sizeof(int *), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); } else { pNewDbgFuncNode = (VkLayerDbgFunctionNode *) loader_heap_alloc(inst, sizeof(VkLayerDbgFunctionNode), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); } diff --git a/loader/loader.c b/loader/loader.c index 79ed84ba..81c805ab 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -152,7 +152,7 @@ void* loader_heap_alloc( { if (instance && instance->alloc_callbacks.pfnAllocation) { /* TODO: What should default alignment be? 1, 4, 8, other? */ - return instance->alloc_callbacks.pfnAllocation(instance->alloc_callbacks.pUserData, size, 4, alloc_scope); + return instance->alloc_callbacks.pfnAllocation(instance->alloc_callbacks.pUserData, size, sizeof(int), alloc_scope); } return malloc(size); } @@ -182,12 +182,14 @@ void* loader_heap_realloc( loader_heap_free(instance, pMemory); return NULL; } + //TODO use the callback realloc function if (instance && instance->alloc_callbacks.pfnAllocation) { if (size <= orig_size) { memset(((uint8_t *)pMemory) + size, 0, orig_size - size); return pMemory; } - void *new_ptr = instance->alloc_callbacks.pfnAllocation(instance->alloc_callbacks.pUserData, size, 4, alloc_scope); + /* TODO: What should default alignment be? 1, 4, 8, other? */ + void *new_ptr = instance->alloc_callbacks.pfnAllocation(instance->alloc_callbacks.pUserData, size, sizeof(int), alloc_scope); if (!new_ptr) return NULL; memcpy(new_ptr, pMemory, orig_size); diff --git a/loader/trampoline.c b/loader/trampoline.c index 6d68166e..6a81cafd 100644 --- a/loader/trampoline.c +++ b/loader/trampoline.c @@ -53,7 +53,7 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance( ptr_instance = (struct loader_instance *) pAllocator->pfnAllocation( pAllocator->pUserData, sizeof(struct loader_instance), - sizeof(VkInstance), + sizeof(int *), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); } else { ptr_instance = (struct loader_instance *) malloc(sizeof(struct loader_instance)); |
