|
|
@@ -104,6 +104,8 @@ _mesa_align_malloc(size_t bytes, unsigned long alignment) |
|
|
|
|
|
|
|
(void) posix_memalign(& mem, alignment, bytes); |
|
|
|
return mem; |
|
|
|
#elif defined(_WIN32) && defined(_MSC_VER) |
|
|
|
return _aligned_malloc(bytes, alignment); |
|
|
|
#else |
|
|
|
uintptr_t ptr, buf; |
|
|
|
|
|
|
@@ -143,6 +145,15 @@ _mesa_align_calloc(size_t bytes, unsigned long alignment) |
|
|
|
(void) memset(mem, 0, bytes); |
|
|
|
} |
|
|
|
|
|
|
|
return mem; |
|
|
|
#elif defined(_WIN32) && defined(_MSC_VER) |
|
|
|
void *mem; |
|
|
|
|
|
|
|
mem = _aligned_malloc(bytes, alignment); |
|
|
|
if (mem != NULL) { |
|
|
|
(void) memset(mem, 0, bytes); |
|
|
|
} |
|
|
|
|
|
|
|
return mem; |
|
|
|
#else |
|
|
|
uintptr_t ptr, buf; |
|
|
@@ -180,6 +191,8 @@ _mesa_align_free(void *ptr) |
|
|
|
{ |
|
|
|
#if defined(HAVE_POSIX_MEMALIGN) |
|
|
|
free(ptr); |
|
|
|
#elif defined(_WIN32) && defined(_MSC_VER) |
|
|
|
_aligned_free(ptr); |
|
|
|
#else |
|
|
|
void **cubbyHole = (void **) ((char *) ptr - sizeof(void *)); |
|
|
|
void *realAddr = *cubbyHole; |
|
|
@@ -194,6 +207,10 @@ void * |
|
|
|
_mesa_align_realloc(void *oldBuffer, size_t oldSize, size_t newSize, |
|
|
|
unsigned long alignment) |
|
|
|
{ |
|
|
|
#if defined(_WIN32) && defined(_MSC_VER) |
|
|
|
(void) oldSize; |
|
|
|
return _aligned_realloc(oldBuffer, newSize, alignment); |
|
|
|
#else |
|
|
|
const size_t copySize = (oldSize < newSize) ? oldSize : newSize; |
|
|
|
void *newBuf = _mesa_align_malloc(newSize, alignment); |
|
|
|
if (newBuf && oldBuffer && copySize > 0) { |
|
|
@@ -202,6 +219,7 @@ _mesa_align_realloc(void *oldBuffer, size_t oldSize, size_t newSize, |
|
|
|
if (oldBuffer) |
|
|
|
_mesa_align_free(oldBuffer); |
|
|
|
return newBuf; |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
|