diff --git a/win32ss/drivers/font/ftfd/rosglue.c b/win32ss/drivers/font/ftfd/rosglue.c index eb2d4b8a675..8d5c66cee6a 100644 --- a/win32ss/drivers/font/ftfd/rosglue.c +++ b/win32ss/drivers/font/ftfd/rosglue.c @@ -36,43 +36,54 @@ DbgPrint(IN PCCH Format, IN ...) * buffer (need to copy the old contents to the new buffer). So, allocate * extra space for a size_t, store the allocated size in there and return * the address just past it as the allocated buffer. + * On win64 we need to align the allocation to 16 bytes, otherwise 8 bytes. */ +typedef struct _MALLOC_HEADER +{ + SIZE_T Size; + SIZE_T Alignment; +} MALLOC_HEADER, * PMALLOC_HEADER; void * malloc(size_t Size) { - void *Object; + PMALLOC_HEADER Header; - Object = EngAllocMem(0, sizeof(size_t) + Size, TAG_FREETYPE); - if (Object != NULL) + Header = EngAllocMem(0, sizeof(MALLOC_HEADER) + Size, TAG_FREETYPE); + if (Header == NULL) { - *((size_t *)Object) = Size; - Object = (void *)((size_t *)Object + 1); + return NULL; } - return Object; + Header->Size = Size; + Header->Alignment = -1; + return (Header + 1); } void * realloc(void *Object, size_t Size) { - void *NewObject; + PVOID NewObject; + PMALLOC_HEADER OldHeader; size_t CopySize; - NewObject = EngAllocMem(0, sizeof(size_t) + Size, TAG_FREETYPE); - if (NewObject != NULL) + NewObject = malloc(Size); + if (NewObject == NULL) { - *((size_t *)NewObject) = Size; - NewObject = (void *)((size_t *)NewObject + 1); - CopySize = *((size_t *)Object - 1); - if (Size < CopySize) - { - CopySize = Size; - } - memcpy(NewObject, Object, CopySize); - EngFreeMem((size_t *)Object - 1); + return NULL; } + if (Object == NULL) + { + return NewObject; + } + + OldHeader = (PMALLOC_HEADER)Object - 1; + CopySize = min(OldHeader->Size, Size); + memcpy(NewObject, Object, CopySize); + + free(Object); + return NewObject; } @@ -81,7 +92,7 @@ free(void *Object) { if (Object != NULL) { - EngFreeMem((size_t *)Object - 1); + EngFreeMem((PMALLOC_HEADER)Object - 1); } }