X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Futil%2Fralloc.c;h=0d20223d98f8a9d8c128913267b46ea503fb8244;hb=aee004a7c8900938d1c17f0ac299d40001b383b0;hp=745b4cf1226c93f126832a803edf86fec675815a;hpb=7e3748c268cd817b1b91f403baa7677db82ce1c1;p=mesa.git diff --git a/src/util/ralloc.c b/src/util/ralloc.c index 745b4cf1226..0d20223d98f 100644 --- a/src/util/ralloc.c +++ b/src/util/ralloc.c @@ -197,6 +197,21 @@ reralloc_size(const void *ctx, void *ptr, size_t size) return resize(ptr, size); } +void * +rerzalloc_size(const void *ctx, void *ptr, size_t old_size, size_t new_size) +{ + if (unlikely(ptr == NULL)) + return rzalloc_size(ctx, new_size); + + assert(ralloc_parent(ptr) == ctx); + ptr = resize(ptr, new_size); + + if (new_size > old_size) + memset((char *)ptr + old_size, 0, new_size - old_size); + + return ptr; +} + void * ralloc_array_size(const void *ctx, size_t size, unsigned count) { @@ -224,6 +239,16 @@ reralloc_array_size(const void *ctx, void *ptr, size_t size, unsigned count) return reralloc_size(ctx, ptr, size * count); } +void * +rerzalloc_array_size(const void *ctx, void *ptr, size_t size, + unsigned old_count, unsigned new_count) +{ + if (new_count > SIZE_MAX/size) + return NULL; + + return rerzalloc_size(ctx, ptr, size * old_count, size * new_count); +} + void ralloc_free(void *ptr) { @@ -552,10 +577,18 @@ ralloc_vasprintf_rewrite_tail(char **str, size_t *start, const char *fmt, */ #define MIN_LINEAR_BUFSIZE 2048 -#define SUBALLOC_ALIGNMENT sizeof(uintptr_t) +#define SUBALLOC_ALIGNMENT 8 #define LMAGIC 0x87b9c7d3 -struct linear_header { +struct +#ifdef _MSC_VER + __declspec(align(8)) +#elif defined(__LP64__) + __attribute__((aligned(16))) +#else + __attribute__((aligned(8))) +#endif + linear_header { #ifndef NDEBUG unsigned magic; /* for debugging */ #endif @@ -647,6 +680,8 @@ linear_alloc_child(void *parent, unsigned size) ptr = (linear_size_chunk *)((char*)&latest[1] + latest->offset); ptr->size = size; latest->offset += full_size; + + assert((uintptr_t)&ptr[1] % SUBALLOC_ALIGNMENT == 0); return &ptr[1]; }