os/os_memory_aligned.h: fix memory allocation alignment for 64 bits

Based on Andreia Gaita <shana@jitted.com>'s patch.
This commit is contained in:
José Fonseca 2010-02-04 18:06:55 +00:00
parent 3aba0a2875
commit 24ea02553e
2 changed files with 3 additions and 3 deletions

View File

@ -58,7 +58,7 @@ void *
os_realloc(void *ptr, size_t old_size, size_t new_size);
void *
os_malloc_aligned(size_t size, uint alignment);
os_malloc_aligned(size_t size, size_t alignment);
void
os_free_aligned(void *ptr);

View File

@ -43,7 +43,7 @@
* Return memory on given byte alignment
*/
static INLINE void *
os_malloc_aligned(size_t size, uint alignment)
os_malloc_aligned(size_t size, size_t alignment)
{
char *ptr, *buf;
@ -51,7 +51,7 @@ os_malloc_aligned(size_t size, uint alignment)
if (!ptr)
return NULL;
buf = (char *)(((uintptr_t)ptr + sizeof(void *) + alignment - 1) & ~(alignment - 1));
buf = (char *)(((uintptr_t)ptr + sizeof(void *) + alignment - 1) & ~((uintptr_t)(alignment - 1)));
*(char **)(buf - sizeof(void *)) = ptr;
return buf;