winpr: rework alignment functions

_align_XXX functions aren't widely available depending on the C runtime. That causes
problems with mingw where we can easily have some runtime mixes (which lead to mysterious
segfaults most of the time). This patch introduce winpr_aligned_XXX functions that will
either use the function available, or use an emulation layer.
This commit is contained in:
David Fort 2022-05-11 11:28:55 +02:00 committed by akallabeth
parent 82092f6752
commit 77413f49b2
38 changed files with 242 additions and 201 deletions

View File

@ -847,7 +847,7 @@ static UINT printer_free(DEVICE* device)
CloseHandle(printer_dev->thread);
CloseHandle(printer_dev->stopEvent);
CloseHandle(printer_dev->event);
_aligned_free(printer_dev->pIrpList);
winpr_aligned_free(printer_dev->pIrpList);
if (printer_dev->printer)
printer_dev->printer->ReleaseRef(printer_dev->printer);
@ -887,7 +887,7 @@ static UINT printer_register(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, rdpPrint
printer_dev->device.Free = printer_free;
printer_dev->rdpcontext = pEntryPoints->rdpcontext;
printer_dev->printer = printer;
printer_dev->pIrpList = (WINPR_PSLIST_HEADER)_aligned_malloc(sizeof(WINPR_SLIST_HEADER),
printer_dev->pIrpList = (WINPR_PSLIST_HEADER)winpr_aligned_malloc(sizeof(WINPR_SLIST_HEADER),
MEMORY_ALLOCATION_ALIGNMENT);
if (!printer_dev->pIrpList)

View File

@ -48,7 +48,7 @@ static UINT irp_free(IRP* irp)
Stream_Free(irp->input, TRUE);
Stream_Free(irp->output, TRUE);
_aligned_free(irp);
winpr_aligned_free(irp);
return CHANNEL_RC_OK;
}
@ -102,7 +102,7 @@ IRP* irp_new(DEVMAN* devman, wStream* s, UINT* error)
return NULL;
}
irp = (IRP*)_aligned_malloc(sizeof(IRP), MEMORY_ALLOCATION_ALIGNMENT);
irp = (IRP*)winpr_aligned_malloc(sizeof(IRP), MEMORY_ALLOCATION_ALIGNMENT);
if (!irp)
{
@ -127,7 +127,7 @@ IRP* irp_new(DEVMAN* devman, wStream* s, UINT* error)
if (!irp->output)
{
WLog_ERR(TAG, "Stream_New failed!");
_aligned_free(irp);
winpr_aligned_free(irp);
if (error)
*error = CHANNEL_RC_NO_MEMORY;
return NULL;
@ -136,7 +136,7 @@ IRP* irp_new(DEVMAN* devman, wStream* s, UINT* error)
if (!rdpdr_write_iocompletion_header(irp->output, DeviceId, irp->CompletionId, 0))
{
Stream_Free(irp->output, TRUE);
_aligned_free(irp);
winpr_aligned_free(irp);
if (error)
*error = CHANNEL_RC_NO_MEMORY;
return NULL;

View File

@ -40,7 +40,7 @@ static BOOL wlf_Pointer_New(rdpContext* context, rdpPointer* pointer)
return FALSE;
ptr->size = pointer->width * pointer->height * 4ULL;
ptr->data = _aligned_malloc(ptr->size, 16);
ptr->data = winpr_aligned_malloc(ptr->size, 16);
if (!ptr->data)
return FALSE;
@ -50,7 +50,7 @@ static BOOL wlf_Pointer_New(rdpContext* context, rdpPointer* pointer)
pointer->xorMaskData, pointer->lengthXorMask, pointer->andMaskData,
pointer->lengthAndMask, pointer->xorBpp, &context->gdi->palette))
{
_aligned_free(ptr->data);
winpr_aligned_free(ptr->data);
return FALSE;
}
@ -63,7 +63,7 @@ static void wlf_Pointer_Free(rdpContext* context, rdpPointer* pointer)
WINPR_UNUSED(context);
if (ptr)
_aligned_free(ptr->data);
winpr_aligned_free(ptr->data);
}
static BOOL wlf_Pointer_Set(rdpContext* context, rdpPointer* pointer)

View File

@ -126,7 +126,7 @@ static void wf_Bitmap_Free(rdpContext* context, rdpBitmap* bitmap)
DeleteObject(wf_bitmap->bitmap);
DeleteDC(wf_bitmap->hdc);
_aligned_free(wf_bitmap->_bitmap.data);
winpr_aligned_free(wf_bitmap->_bitmap.data);
wf_bitmap->_bitmap.data = NULL;
}
}
@ -210,7 +210,7 @@ static BOOL wf_Pointer_New(rdpContext* context, const rdpPointer* pointer)
if ((pointer->lengthAndMask > 0) || (pointer->lengthXorMask > 0))
{
pdata = (BYTE*)_aligned_malloc(pointer->lengthAndMask + pointer->lengthXorMask, 16);
pdata = (BYTE*)winpr_aligned_malloc(pointer->lengthAndMask + pointer->lengthXorMask, 16);
if (!pdata)
goto fail;
@ -219,7 +219,7 @@ static BOOL wf_Pointer_New(rdpContext* context, const rdpPointer* pointer)
CopyMemory(pdata, pointer->andMaskData, pointer->lengthAndMask);
CopyMemory(pdata + pointer->lengthAndMask, pointer->xorMaskData, pointer->lengthXorMask);
info.hbmMask = CreateBitmap(pointer->width, pointer->height * 2, 1, 1, pdata);
_aligned_free(pdata);
winpr_aligned_free(pdata);
info.hbmColor = NULL;
}
else
@ -229,7 +229,7 @@ static BOOL wf_Pointer_New(rdpContext* context, const rdpPointer* pointer)
if (pointer->lengthAndMask > 0)
{
pdata = (BYTE*)_aligned_malloc(pointer->lengthAndMask, 16);
pdata = (BYTE*)winpr_aligned_malloc(pointer->lengthAndMask, 16);
if (!pdata)
goto fail;
@ -237,7 +237,7 @@ static BOOL wf_Pointer_New(rdpContext* context, const rdpPointer* pointer)
}
info.hbmMask = CreateBitmap(pointer->width, pointer->height, 1, 1, pdata);
_aligned_free(pdata);
winpr_aligned_free(pdata);
/* currently color xorBpp is only 24 per [T128] section 8.14.3 */
srcFormat = gdi_get_pixel_format(pointer->xorBpp);

View File

@ -236,7 +236,7 @@ static Pixmap xf_brush_new(xfContext* xfc, UINT32 width, UINT32 height, UINT32 b
if (data)
{
brushFormat = gdi_get_pixel_format(bpp);
cdata = (BYTE*)_aligned_malloc(width * height * 4ULL, 16);
cdata = (BYTE*)winpr_aligned_malloc(width * height * 4ULL, 16);
freerdp_image_copy(cdata, gdi->dstFormat, 0, 0, 0, width, height, data, brushFormat, 0, 0,
0, &gdi->palette, FREERDP_FLIP_NONE);
image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0, (char*)cdata, width,
@ -249,7 +249,7 @@ static Pixmap xf_brush_new(xfContext* xfc, UINT32 width, UINT32 height, UINT32 b
XDestroyImage(image);
if (cdata != data)
_aligned_free(cdata);
winpr_aligned_free(cdata);
XFreeGC(xfc->display, gc);
}

View File

@ -305,7 +305,7 @@ static UINT xf_CreateSurface(RdpgfxClientContext* context,
surface->gdi.scanline = surface->gdi.width * FreeRDPGetBytesPerPixel(surface->gdi.format);
surface->gdi.scanline = x11_pad_scanline(surface->gdi.scanline, xfc->scanline_pad);
size = surface->gdi.scanline * surface->gdi.height * 1ULL;
surface->gdi.data = (BYTE*)_aligned_malloc(size, 16);
surface->gdi.data = (BYTE*)winpr_aligned_malloc(size, 16);
if (!surface->gdi.data)
{
@ -329,7 +329,7 @@ static UINT xf_CreateSurface(RdpgfxClientContext* context,
surface->stageScanline = width * bytes;
surface->stageScanline = x11_pad_scanline(surface->stageScanline, xfc->scanline_pad);
size = surface->stageScanline * surface->gdi.height * 1ULL;
surface->stage = (BYTE*)_aligned_malloc(size, 16);
surface->stage = (BYTE*)winpr_aligned_malloc(size, 16);
if (!surface->stage)
{
@ -366,9 +366,9 @@ error_set_surface_data:
surface->image->data = NULL;
XDestroyImage(surface->image);
error_surface_image:
_aligned_free(surface->stage);
winpr_aligned_free(surface->stage);
out_free_gdidata:
_aligned_free(surface->gdi.data);
winpr_aligned_free(surface->gdi.data);
out_free:
free(surface);
return ret;
@ -398,8 +398,8 @@ static UINT xf_DeleteSurface(RdpgfxClientContext* context,
#endif
surface->image->data = NULL;
XDestroyImage(surface->image);
_aligned_free(surface->gdi.data);
_aligned_free(surface->stage);
winpr_aligned_free(surface->gdi.data);
winpr_aligned_free(surface->stage);
region16_uninit(&surface->gdi.invalidRegion);
codecs = surface->gdi.codecs;
free(surface);

View File

@ -124,18 +124,18 @@ static BOOL xf_Bitmap_New(rdpContext* context, rdpBitmap* bitmap)
if ((INT64)depth != xfc->depth)
{
if (!(data = _aligned_malloc(bitmap->width * bitmap->height * 4ULL, 16)))
if (!(data = winpr_aligned_malloc(bitmap->width * bitmap->height * 4ULL, 16)))
goto unlock;
if (!freerdp_image_copy(data, gdi->dstFormat, 0, 0, 0, bitmap->width, bitmap->height,
bitmap->data, bitmap->format, 0, 0, 0, &context->gdi->palette,
FREERDP_FLIP_NONE))
{
_aligned_free(data);
winpr_aligned_free(data);
goto unlock;
}
_aligned_free(bitmap->data);
winpr_aligned_free(bitmap->data);
bitmap->data = data;
bitmap->format = gdi->dstFormat;
}
@ -183,7 +183,7 @@ static void xf_Bitmap_Free(rdpContext* context, rdpBitmap* bitmap)
}
xf_unlock_x11(xfc);
_aligned_free(bitmap->data);
winpr_aligned_free(bitmap->data);
free(xbitmap);
}
@ -312,7 +312,7 @@ static BOOL _xf_Pointer_GetCursorForCurrentScale(rdpContext* context, rdpPointer
ci.yhot = pointer->yPos * yscale;
size = ci.height * ci.width * FreeRDPGetBytesPerPixel(CursorFormat) * 1ULL;
tmp = _aligned_malloc(size, 16);
tmp = winpr_aligned_malloc(size, 16);
if (!tmp)
{
xf_unlock_x11(xfc);
@ -326,7 +326,7 @@ static BOOL _xf_Pointer_GetCursorForCurrentScale(rdpContext* context, rdpPointer
(BYTE*)xpointer->cursorPixels, CursorFormat, 0, 0, 0,
pointer->width, pointer->height))
{
_aligned_free(tmp);
winpr_aligned_free(tmp);
xf_unlock_x11(xfc);
return FALSE;
}
@ -342,7 +342,7 @@ static BOOL _xf_Pointer_GetCursorForCurrentScale(rdpContext* context, rdpPointer
xpointer->cursors[cursorIndex] = XcursorImageLoadCursor(xfc->display, &ci);
xpointer->nCursors += 1;
_aligned_free(tmp);
winpr_aligned_free(tmp);
xf_unlock_x11(xfc);
}
@ -401,7 +401,7 @@ static BOOL xf_Pointer_New(rdpContext* context, rdpPointer* pointer)
size = pointer->height * pointer->width * FreeRDPGetBytesPerPixel(CursorFormat) * 1ULL;
if (!(xpointer->cursorPixels = (XcursorPixel*)_aligned_malloc(size, 16)))
if (!(xpointer->cursorPixels = (XcursorPixel*)winpr_aligned_malloc(size, 16)))
return FALSE;
if (!freerdp_image_copy_from_pointer_data(
@ -409,7 +409,7 @@ static BOOL xf_Pointer_New(rdpContext* context, rdpPointer* pointer)
pointer->xorMaskData, pointer->lengthXorMask, pointer->andMaskData,
pointer->lengthAndMask, pointer->xorBpp, &context->gdi->palette))
{
_aligned_free(xpointer->cursorPixels);
winpr_aligned_free(xpointer->cursorPixels);
return FALSE;
}
@ -428,7 +428,7 @@ static void xf_Pointer_Free(rdpContext* context, rdpPointer* pointer)
xf_lock_x11(xfc);
_aligned_free(xpointer->cursorPixels);
winpr_aligned_free(xpointer->cursorPixels);
free(xpointer->cursorWidths);
free(xpointer->cursorHeights);

View File

@ -274,8 +274,8 @@ extern "C"
* @param height height to copy in pixels
* @param data source buffer, must be (nWidth + 7) / 8 bytes long
*
* @return A buffer allocated with _aligned_malloc(width * height, 16)
* if successufl, NULL otherwise.
* @return A buffer allocated with winpr_aligned_malloc(width * height, 16)
* if successful, NULL otherwise.
*/
FREERDP_API BYTE* freerdp_glyph_convert(UINT32 width, UINT32 height, const BYTE* data);

View File

@ -402,10 +402,6 @@ if (WITH_LIBRARY_VERSIONING)
set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${FREERDP_VERSION} SOVERSION ${FREERDP_API_VERSION})
endif()
if (MINGW)
freerdp_library_add(ucrt)
endif()
target_link_libraries(${MODULE_NAME} PRIVATE ${LIBFREERDP_LIBS} winpr)
install(TARGETS ${MODULE_NAME} COMPONENT libraries EXPORT FreeRDPTargets

View File

@ -54,7 +54,7 @@ BYTE* freerdp_glyph_convert(UINT32 width, UINT32 height, const BYTE* data)
* means of accessing individual pixels in blitting operations
*/
scanline = (width + 7) / 8;
dstData = (BYTE*)_aligned_malloc(width * height * 1ULL, 16);
dstData = (BYTE*)winpr_aligned_malloc(width * height * 1ULL, 16);
if (!dstData)
return NULL;

View File

@ -72,8 +72,8 @@ BOOL avc420_ensure_buffer(H264_CONTEXT* h264, UINT32 stride, UINT32 width, UINT3
for (x = 0; x < 3; x++)
{
BYTE* tmp1 = _aligned_recalloc(h264->pYUVData[x], h264->iStride[x], pheight, 16);
BYTE* tmp2 = _aligned_recalloc(h264->pOldYUVData[x], h264->iStride[x], pheight, 16);
BYTE* tmp1 = winpr_aligned_recalloc(h264->pYUVData[x], h264->iStride[x], pheight, 16);
BYTE* tmp2 = winpr_aligned_recalloc(h264->pOldYUVData[x], h264->iStride[x], pheight, 16);
if (tmp1)
h264->pYUVData[x] = tmp1;
if (tmp2)
@ -415,10 +415,10 @@ static BOOL avc444_ensure_buffer(H264_CONTEXT* h264, DWORD nDstHeight)
BYTE* tmp2;
piDstStride[x] = piMainStride[0];
piDstSize[x] = piDstStride[x] * padDstHeight;
tmp1 = _aligned_recalloc(ppYUVDstData[x], piDstSize[x], 1, 16);
tmp1 = winpr_aligned_recalloc(ppYUVDstData[x], piDstSize[x], 1, 16);
if (tmp1)
ppYUVDstData[x] = tmp1;
tmp2 = _aligned_recalloc(ppOldYUVDstData[x], piDstSize[x], 1, 16);
tmp2 = winpr_aligned_recalloc(ppOldYUVDstData[x], piDstSize[x], 1, 16);
if (tmp2)
ppOldYUVDstData[x] = tmp2;
if (!tmp1 || !tmp2)
@ -426,7 +426,7 @@ static BOOL avc444_ensure_buffer(H264_CONTEXT* h264, DWORD nDstHeight)
}
{
BYTE* tmp = _aligned_recalloc(h264->lumaData, piDstSize[0], 4, 16);
BYTE* tmp = winpr_aligned_recalloc(h264->lumaData, piDstSize[0], 4, 16);
if (!tmp)
goto fail;
h264->lumaData = tmp;
@ -696,13 +696,13 @@ void h264_context_free(H264_CONTEXT* h264)
{
if (h264->Compressor)
{
_aligned_free(h264->pYUVData[x]);
_aligned_free(h264->pOldYUVData[x]);
winpr_aligned_free(h264->pYUVData[x]);
winpr_aligned_free(h264->pOldYUVData[x]);
}
_aligned_free(h264->pYUV444Data[x]);
_aligned_free(h264->pOldYUV444Data[x]);
winpr_aligned_free(h264->pYUV444Data[x]);
winpr_aligned_free(h264->pOldYUV444Data[x]);
}
_aligned_free(h264->lumaData);
winpr_aligned_free(h264->lumaData);
yuv_context_free(h264->yuv);
free(h264);

View File

@ -441,7 +441,7 @@ static void mf_uninit(H264_CONTEXT* h264)
}
for (x = 0; x < sizeof(h264->pYUVData) / sizeof(h264->pYUVData[0]); x++)
_aligned_free(h264->pYUVData[x]);
winpr_aligned_free(h264->pYUVData[x]);
memset(h264->pYUVData, 0, sizeof(h264->pYUVData));
memset(h264->iStride, 0, sizeof(h264->iStride));

View File

@ -376,7 +376,7 @@ BOOL interleaved_decompress(BITMAP_INTERLEAVED_CONTEXT* interleaved, const BYTE*
if (BufferSize > interleaved->TempSize)
{
interleaved->TempBuffer = _aligned_realloc(interleaved->TempBuffer, BufferSize, 16);
interleaved->TempBuffer = winpr_aligned_realloc(interleaved->TempBuffer, BufferSize, 16);
interleaved->TempSize = BufferSize;
}
@ -504,7 +504,7 @@ BITMAP_INTERLEAVED_CONTEXT* bitmap_interleaved_context_new(BOOL Compressor)
if (interleaved)
{
interleaved->TempSize = 64 * 64 * 4;
interleaved->TempBuffer = _aligned_malloc(interleaved->TempSize, 16);
interleaved->TempBuffer = winpr_aligned_malloc(interleaved->TempSize, 16);
if (!interleaved->TempBuffer)
{
@ -517,7 +517,7 @@ BITMAP_INTERLEAVED_CONTEXT* bitmap_interleaved_context_new(BOOL Compressor)
if (!interleaved->bts)
{
_aligned_free(interleaved->TempBuffer);
winpr_aligned_free(interleaved->TempBuffer);
free(interleaved);
WLog_ERR(TAG, "Stream_New failed!");
return NULL;
@ -532,7 +532,7 @@ void bitmap_interleaved_context_free(BITMAP_INTERLEAVED_CONTEXT* interleaved)
if (!interleaved)
return;
_aligned_free(interleaved->TempBuffer);
winpr_aligned_free(interleaved->TempBuffer);
Stream_Free(interleaved->bts, TRUE);
free(interleaved);
}

View File

@ -376,9 +376,9 @@ static void progressive_tile_free(RFX_PROGRESSIVE_TILE* tile)
{
if (tile)
{
_aligned_free(tile->sign);
_aligned_free(tile->current);
_aligned_free(tile->data);
winpr_aligned_free(tile->sign);
winpr_aligned_free(tile->current);
winpr_aligned_free(tile->data);
}
}
@ -418,19 +418,19 @@ static INLINE BOOL progressive_tile_allocate(RFX_PROGRESSIVE_TILE* tile)
{
size_t dataLen = tile->stride * tile->height * 1ULL;
tile->data = (BYTE*)_aligned_malloc(dataLen, 16);
tile->data = (BYTE*)winpr_aligned_malloc(dataLen, 16);
if (tile->data)
memset(tile->data, 0xFF, dataLen);
}
{
size_t signLen = (8192 + 32) * 3;
tile->sign = (BYTE*)_aligned_malloc(signLen, 16);
tile->sign = (BYTE*)winpr_aligned_malloc(signLen, 16);
}
{
size_t currentLen = (8192 + 32) * 3;
tile->current = (BYTE*)_aligned_malloc(currentLen, 16);
tile->current = (BYTE*)winpr_aligned_malloc(currentLen, 16);
}
rc = tile->data && tile->sign && tile->current;

View File

@ -167,7 +167,7 @@ static void* rfx_decoder_tile_new(const void* val)
if (!(tile = (RFX_TILE*)calloc(1, sizeof(RFX_TILE))))
return NULL;
if (!(tile->data = (BYTE*)_aligned_malloc(size, 16)))
if (!(tile->data = (BYTE*)winpr_aligned_malloc(size, 16)))
{
free(tile);
return NULL;
@ -184,7 +184,7 @@ static void rfx_decoder_tile_free(void* obj)
if (tile)
{
if (tile->allocated)
_aligned_free(tile->data);
winpr_aligned_free(tile->data);
free(tile);
}

View File

@ -962,7 +962,7 @@ static int test_progressive_ms_sample(char* ms_sample_path)
count = 4;
progressive = progressive_context_new(FALSE);
g_DstData = _aligned_malloc(g_DstStep * g_Height, 16);
g_DstData = winpr_aligned_malloc(g_DstStep * g_Height, 16);
progressive_create_surface_context(progressive, 0, g_Width, g_Height);
/* image 1 */
@ -1015,7 +1015,7 @@ static int test_progressive_ms_sample(char* ms_sample_path)
}
}
_aligned_free(g_DstData);
winpr_aligned_free(g_DstData);
return 0;
}

View File

@ -98,7 +98,7 @@ UINT32 gdi_SetPixel(HGDI_DC hdc, UINT32 X, UINT32 Y, UINT32 crColor)
HGDI_BITMAP gdi_CreateBitmap(UINT32 nWidth, UINT32 nHeight, UINT32 format, BYTE* data)
{
return gdi_CreateBitmapEx(nWidth, nHeight, format, 0, data, _aligned_free);
return gdi_CreateBitmapEx(nWidth, nHeight, format, 0, data, winpr_aligned_free);
}
/**
@ -156,8 +156,8 @@ HGDI_BITMAP gdi_CreateCompatibleBitmap(HGDI_DC hdc, UINT32 nWidth, UINT32 nHeigh
hBitmap->width = nWidth;
hBitmap->height = nHeight;
hBitmap->data =
_aligned_malloc(nWidth * nHeight * FreeRDPGetBytesPerPixel(hBitmap->format) * 1ULL, 16);
hBitmap->free = _aligned_free;
winpr_aligned_malloc(nWidth * nHeight * FreeRDPGetBytesPerPixel(hBitmap->format) * 1ULL, 16);
hBitmap->free = winpr_aligned_free;
if (!hBitmap->data)
{

View File

@ -868,7 +868,7 @@ static BOOL gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
{
HGDI_BITMAP hBmp;
UINT32 brushFormat;
BYTE* data = (BYTE*)_aligned_malloc(
BYTE* data = (BYTE*)winpr_aligned_malloc(
8 * 8 * FreeRDPGetBytesPerPixel(gdi->drawing->hdc->format), 16);
if (!data)
@ -891,7 +891,7 @@ static BOOL gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
brushFormat, 0, 0, 0, &gdi->palette, FREERDP_FLIP_NONE))
{
ret = FALSE;
_aligned_free(data);
winpr_aligned_free(data);
goto out_fail;
}
}
@ -902,7 +902,7 @@ static BOOL gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
&gdi->palette))
{
ret = FALSE;
_aligned_free(data);
winpr_aligned_free(data);
goto out_fail;
}
}
@ -912,7 +912,7 @@ static BOOL gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
if (!hBmp)
{
ret = FALSE;
_aligned_free(data);
winpr_aligned_free(data);
goto out_fail;
}
@ -1271,7 +1271,7 @@ BOOL gdi_resize_ex(rdpGdi* gdi, UINT32 width, UINT32 height, UINT32 stride, UINT
*/
BOOL gdi_init(freerdp* instance, UINT32 format)
{
return gdi_init_ex(instance, format, 0, NULL, _aligned_free);
return gdi_init_ex(instance, format, 0, NULL, winpr_aligned_free);
}
BOOL gdi_init_ex(freerdp* instance, UINT32 format, UINT32 stride, BYTE* buffer,

View File

@ -1123,7 +1123,7 @@ static UINT gdi_CreateSurface(RdpgfxClientContext* context,
}
surface->scanline = gfx_align_scanline(surface->width * 4UL, 16);
surface->data = (BYTE*)_aligned_malloc(surface->scanline * surface->height * 1ULL, 16);
surface->data = (BYTE*)winpr_aligned_malloc(surface->scanline * surface->height * 1ULL, 16);
if (!surface->data)
{
@ -1166,7 +1166,7 @@ static UINT gdi_DeleteSurface(RdpgfxClientContext* context,
#endif
region16_uninit(&surface->invalidRegion);
codecs = surface->codecs;
_aligned_free(surface->data);
winpr_aligned_free(surface->data);
free(surface);
}

View File

@ -50,7 +50,7 @@ HGDI_BITMAP gdi_create_bitmap(rdpGdi* gdi, UINT32 nWidth, UINT32 nHeight, UINT32
return NULL;
nDstStep = nWidth * FreeRDPGetBytesPerPixel(gdi->dstFormat);
pDstData = _aligned_malloc(nHeight * nDstStep * 1ULL, 16);
pDstData = winpr_aligned_malloc(nHeight * nDstStep * 1ULL, 16);
if (!pDstData)
return NULL;
@ -61,7 +61,7 @@ HGDI_BITMAP gdi_create_bitmap(rdpGdi* gdi, UINT32 nWidth, UINT32 nHeight, UINT32
if (!freerdp_image_copy(pDstData, gdi->dstFormat, nDstStep, 0, 0, nWidth, nHeight, pSrcData,
SrcFormat, nSrcStep, 0, 0, &gdi->palette, FREERDP_FLIP_NONE))
{
_aligned_free(pDstData);
winpr_aligned_free(pDstData);
return NULL;
}
@ -112,7 +112,7 @@ static void gdi_Bitmap_Free(rdpContext* context, rdpBitmap* bitmap)
gdi_DeleteObject((HGDIOBJECT)gdi_bitmap->bitmap);
gdi_DeleteDC(gdi_bitmap->hdc);
_aligned_free(bitmap->data);
winpr_aligned_free(bitmap->data);
}
free(bitmap);
@ -144,7 +144,7 @@ static BOOL gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, const
size *= FreeRDPGetBytesPerPixel(bitmap->format);
bitmap->length = size;
bitmap->data = (BYTE*)_aligned_malloc(bitmap->length, 16);
bitmap->data = (BYTE*)winpr_aligned_malloc(bitmap->length, 16);
if (!bitmap->data)
return FALSE;
@ -242,7 +242,7 @@ static BOOL gdi_Glyph_New(rdpContext* context, rdpGlyph* glyph)
if (!gdi_glyph->bitmap)
{
gdi_DeleteDC(gdi_glyph->hdc);
_aligned_free(data);
winpr_aligned_free(data);
return FALSE;
}

View File

@ -92,7 +92,7 @@ static int test_gdi_CreateBitmap(void)
width = 32;
height = 16;
if (!(data = (BYTE*)_aligned_malloc(width * height * 4, 16)))
if (!(data = (BYTE*)winpr_aligned_malloc(width * height * 4, 16)))
{
printf("failed to allocate aligned bitmap data memory\n");
return -1;

View File

@ -30,7 +30,7 @@ HGDI_BITMAP test_convert_to_bitmap(const BYTE* src, UINT32 SrcFormat, UINT32 Src
if (DstStride == 0)
DstStride = nWidth * FreeRDPGetBytesPerPixel(DstFormat);
data = _aligned_malloc(DstStride * nHeight, 16);
data = winpr_aligned_malloc(DstStride * nHeight, 16);
if (!data)
return NULL;
@ -38,7 +38,7 @@ HGDI_BITMAP test_convert_to_bitmap(const BYTE* src, UINT32 SrcFormat, UINT32 Src
if (!freerdp_image_copy(data, DstFormat, DstStride, xDst, yDst, nWidth, nHeight, src, SrcFormat,
SrcStride, xSrc, ySrc, hPalette, FREERDP_FLIP_NONE))
{
_aligned_free(data);
winpr_aligned_free(data);
return NULL;
}
@ -46,7 +46,7 @@ HGDI_BITMAP test_convert_to_bitmap(const BYTE* src, UINT32 SrcFormat, UINT32 Src
if (!bmp)
{
_aligned_free(data);
winpr_aligned_free(data);
return NULL;
}

View File

@ -194,7 +194,7 @@ VideoSurface* VideoClient_CreateCommonContext(size_t size, UINT32 x, UINT32 y, U
ret->alignedHeight = ret->h + 32 - ret->h % 16;
ret->scanline = ret->alignedWidth * FreeRDPGetBytesPerPixel(ret->format);
ret->data = _aligned_malloc(ret->scanline * ret->alignedHeight * 1ULL, 64);
ret->data = winpr_aligned_malloc(ret->scanline * ret->alignedHeight * 1ULL, 64);
if (!ret->data)
goto fail;
return ret;
@ -207,6 +207,6 @@ void VideoClient_DestroyCommonContext(VideoSurface* surface)
{
if (!surface)
return;
_aligned_free(surface->data);
winpr_aligned_free(surface->data);
free(surface);
}

View File

@ -36,11 +36,11 @@ static BOOL test_RGBToRGB_16s8u_P3AC4R_func(prim_size_t roi, DWORD DstFormat)
PROFILER_DEFINE(optProf)
PROFILER_CREATE(genericProf, "RGBToRGB_16s8u_P3AC4R-GENERIC")
PROFILER_CREATE(optProf, "RGBToRGB_16s8u_P3AC4R-OPTIMIZED")
r = _aligned_recalloc(NULL, 1, rgbStride * roi.height, 16);
g = _aligned_recalloc(NULL, 1, rgbStride * roi.height, 16);
b = _aligned_recalloc(NULL, 1, rgbStride * roi.height, 16);
out1 = _aligned_recalloc(NULL, 1, dstStride * roi.height, 16);
out2 = _aligned_recalloc(NULL, 1, dstStride * roi.height, 16);
r = winpr_aligned_recalloc(NULL, 1, rgbStride * roi.height, 16);
g = winpr_aligned_recalloc(NULL, 1, rgbStride * roi.height, 16);
b = winpr_aligned_recalloc(NULL, 1, rgbStride * roi.height, 16);
out1 = winpr_aligned_recalloc(NULL, 1, dstStride * roi.height, 16);
out2 = winpr_aligned_recalloc(NULL, 1, dstStride * roi.height, 16);
if (!r || !g || !b || !out1 || !out2)
goto fail;
@ -108,11 +108,11 @@ static BOOL test_RGBToRGB_16s8u_P3AC4R_func(prim_size_t roi, DWORD DstFormat)
fail:
PROFILER_FREE(genericProf)
PROFILER_FREE(optProf)
_aligned_free(r);
_aligned_free(g);
_aligned_free(b);
_aligned_free(out1);
_aligned_free(out2);
winpr_aligned_free(r);
winpr_aligned_free(g);
winpr_aligned_free(b);
winpr_aligned_free(out1);
winpr_aligned_free(out2);
return !failed;
}

View File

@ -1586,8 +1586,8 @@ static int test_PrimitivesYCbCr(const primitives_t* prims, UINT32 format, prim_s
PROFILER_DEFINE(prof2)
// return test_YCbCr_pixels();
actual = _aligned_malloc(dstSize, 16);
actual1 = _aligned_malloc(dstSize, 16);
actual = winpr_aligned_malloc(dstSize, 16);
actual1 = winpr_aligned_malloc(dstSize, 16);
PROFILER_CREATE(prof, "yCbCrToRGB_16s8u")
PROFILER_CREATE(prof1, "yCbCrToRGB16s16s")
PROFILER_CREATE(prof2, "RGBToRGB_16s8u")
@ -1597,9 +1597,9 @@ static int test_PrimitivesYCbCr(const primitives_t* prims, UINT32 format, prim_s
ZeroMemory(actual, dstSize);
ZeroMemory(actual1, dstSize);
pYCbCr[0] = _aligned_malloc(srcSize, 16);
pYCbCr[1] = _aligned_malloc(srcSize, 16);
pYCbCr[2] = _aligned_malloc(srcSize, 16);
pYCbCr[0] = winpr_aligned_malloc(srcSize, 16);
pYCbCr[1] = winpr_aligned_malloc(srcSize, 16);
pYCbCr[2] = winpr_aligned_malloc(srcSize, 16);
if (!pYCbCr[0] || !pYCbCr[1] || !pYCbCr[2])
goto fail;
@ -1628,9 +1628,9 @@ static int test_PrimitivesYCbCr(const primitives_t* prims, UINT32 format, prim_s
{
INT16* pSrcDst[3];
pSrcDst[0] = _aligned_malloc(srcSize, 16);
pSrcDst[1] = _aligned_malloc(srcSize, 16);
pSrcDst[2] = _aligned_malloc(srcSize, 16);
pSrcDst[0] = winpr_aligned_malloc(srcSize, 16);
pSrcDst[1] = winpr_aligned_malloc(srcSize, 16);
pSrcDst[2] = winpr_aligned_malloc(srcSize, 16);
CopyMemory(pSrcDst[0], pYCbCr[0], srcSize);
CopyMemory(pSrcDst[1], pYCbCr[1], srcSize);
CopyMemory(pSrcDst[2], pYCbCr[2], srcSize);
@ -1646,9 +1646,9 @@ static int test_PrimitivesYCbCr(const primitives_t* prims, UINT32 format, prim_s
status = prims->RGBToRGB_16s8u_P3AC4R(cnv.cpi, srcStride, actual1, dstStride, format, &roi);
PROFILER_EXIT(prof2)
fail2:
_aligned_free(pSrcDst[0]);
_aligned_free(pSrcDst[1]);
_aligned_free(pSrcDst[2]);
winpr_aligned_free(pSrcDst[0]);
winpr_aligned_free(pSrcDst[1]);
winpr_aligned_free(pSrcDst[2]);
if (status != PRIMITIVES_SUCCESS)
goto fail;
@ -1705,11 +1705,11 @@ static int test_PrimitivesYCbCr(const primitives_t* prims, UINT32 format, prim_s
PROFILER_PRINT(prof2)
PROFILER_PRINT_FOOTER
fail:
_aligned_free((BYTE*)pYCbCr[0]);
_aligned_free((BYTE*)pYCbCr[1]);
_aligned_free((BYTE*)pYCbCr[2]);
_aligned_free(actual);
_aligned_free(actual1);
winpr_aligned_free((BYTE*)pYCbCr[0]);
winpr_aligned_free((BYTE*)pYCbCr[1]);
winpr_aligned_free((BYTE*)pYCbCr[2]);
winpr_aligned_free(actual);
winpr_aligned_free(actual1);
PROFILER_FREE(prof)
PROFILER_FREE(prof1)
PROFILER_FREE(prof2)

View File

@ -36,9 +36,9 @@ static BOOL test_YCoCgRToRGB_8u_AC4R_func(UINT32 width, UINT32 height)
PIXEL_FORMAT_RGBX32, PIXEL_FORMAT_BGRA32, PIXEL_FORMAT_BGRX32 };
PROFILER_DEFINE(genericProf)
PROFILER_DEFINE(optProf)
in = _aligned_recalloc(NULL, 1, size, 16);
out_c = _aligned_recalloc(NULL, 1, size, 16);
out_sse = _aligned_recalloc(NULL, 1, size, 16);
in = winpr_aligned_recalloc(NULL, 1, size, 16);
out_c = winpr_aligned_recalloc(NULL, 1, size, 16);
out_sse = winpr_aligned_recalloc(NULL, 1, size, 16);
if (!in || !out_c || !out_sse)
goto fail;
@ -101,9 +101,9 @@ static BOOL test_YCoCgRToRGB_8u_AC4R_func(UINT32 width, UINT32 height)
}
fail:
_aligned_free(in);
_aligned_free(out_c);
_aligned_free(out_sse);
winpr_aligned_free(in);
winpr_aligned_free(out_c);
winpr_aligned_free(out_sse);
return status == PRIMITIVES_SUCCESS;
}

View File

@ -140,7 +140,7 @@ static void* set_padding(size_t size, size_t padding)
{
size_t halfPad = (padding + 1) / 2;
BYTE* psrc;
BYTE* src = _aligned_malloc(size + 2 * halfPad, 16);
BYTE* src = winpr_aligned_malloc(size + 2 * halfPad, 16);
if (!src)
return NULL;
@ -152,7 +152,7 @@ static void* set_padding(size_t size, size_t padding)
if (!check_padding(psrc, size, padding, "init"))
{
_aligned_free(src);
winpr_aligned_free(src);
return NULL;
}
@ -167,7 +167,7 @@ static void free_padding(void* src, size_t padding)
return;
ptr = ((BYTE*)src) - (padding + 1) / 2;
_aligned_free(ptr);
winpr_aligned_free(ptr);
}
/* Create 2 pseudo YUV420 frames of same size.

View File

@ -1320,7 +1320,7 @@ static int x11_shadow_subsystem_init(rdpShadowSubsystem* sub)
subsystem->cursorMaxWidth = 256;
subsystem->cursorMaxHeight = 256;
subsystem->cursorPixels =
_aligned_malloc(subsystem->cursorMaxWidth * subsystem->cursorMaxHeight * 4, 16);
winpr_aligned_malloc(subsystem->cursorMaxWidth * subsystem->cursorMaxHeight * 4, 16);
if (!subsystem->cursorPixels)
return -1;
@ -1394,7 +1394,7 @@ static int x11_shadow_subsystem_uninit(rdpShadowSubsystem* sub)
if (subsystem->cursorPixels)
{
_aligned_free(subsystem->cursorPixels);
winpr_aligned_free(subsystem->cursorPixels);
subsystem->cursorPixels = NULL;
}

View File

@ -125,6 +125,8 @@ extern "C"
}
#endif
#endif /* _WIN32 */
/* Data Alignment */
#if defined(__clang__)
@ -146,19 +148,7 @@ extern "C"
{
#endif
WINPR_API void* _aligned_malloc(size_t size, size_t alignment);
WINPR_API void* _aligned_realloc(void* memblock, size_t size, size_t alignment);
WINPR_API void* _aligned_recalloc(void* memblock, size_t num, size_t size, size_t alignment);
WINPR_API void* _aligned_offset_malloc(size_t size, size_t alignment, size_t offset);
WINPR_API void* _aligned_offset_realloc(void* memblock, size_t size, size_t alignment,
size_t offset);
WINPR_API void* _aligned_offset_recalloc(void* memblock, size_t num, size_t size,
size_t alignment, size_t offset);
WINPR_API size_t _aligned_msize(void* memblock, size_t alignment, size_t offset);
WINPR_API void _aligned_free(void* memblock);
#ifndef _WIN32
/* Data Conversion */
@ -169,11 +159,69 @@ extern "C"
WINPR_API errno_t memmove_s(void* dest, size_t numberOfElements, const void* src, size_t count);
WINPR_API errno_t wmemmove_s(WCHAR* dest, size_t numberOfElements, const WCHAR* src,
size_t count);
#ifdef __cplusplus
}
#endif
#endif /* _WIN32 */
#if !defined(_WIN32) || (defined(__MINGW32__) && ! defined(_UCRT))
/* note: we use our own implementation of _aligned_XXX function when:
* - it's not win32
* - it's mingw with native libs (not ucrt64) because we didn't managed to have it working
* and not have C runtime deadly mixes
*/
#if WINPR_MSVCR_ALIGNMENT_EMULATE
#define _aligned_malloc winpr_aligned_malloc
#define _aligned_realloc winpr_aligned_realloc
#define _aligned_recalloc winpr_aligned_recalloc
#define _aligned_offset_malloc winpr_aligned_offset_malloc
#define _aligned_offset_realloc winpr_aligned_offset_realloc
#define _aligned_offset_recalloc winpr_aligned_offset_recalloc
#define _aligned_msize winpr_aligned_msize
#define _aligned_free winpr_aligned_free
#endif
#ifdef __cplusplus
extern "C"
{
#endif
WINPR_API void* winpr_aligned_malloc(size_t size, size_t alignment);
WINPR_API void* winpr_aligned_realloc(void* memblock, size_t size, size_t alignment);
WINPR_API void* winpr_aligned_recalloc(void* memblock, size_t num, size_t size, size_t alignment);
WINPR_API void* winpr_aligned_offset_malloc(size_t size, size_t alignment, size_t offset);
WINPR_API void* winpr_aligned_offset_realloc(void* memblock, size_t size, size_t alignment,
size_t offset);
WINPR_API void* winpr_aligned_offset_recalloc(void* memblock, size_t num, size_t size,
size_t alignment, size_t offset);
WINPR_API size_t winpr_aligned_msize(void* memblock, size_t alignment, size_t offset);
WINPR_API void winpr_aligned_free(void* memblock);
#ifdef __cplusplus
}
#endif
#else
#define winpr_aligned_malloc _aligned_malloc
#define winpr_aligned_realloc _aligned_realloc
#define winpr_aligned_recalloc _aligned_recalloc
#define winpr_aligned_offset_malloc _aligned_offset_malloc
#define winpr_aligned_offset_realloc _aligned_offset_realloc
#define winpr_aligned_offset_recalloc _aligned_offset_recalloc
#define winpr_aligned_msize _aligned_msize
#define winpr_aligned_free _aligned_free
#endif /* !defined(_WIN32) || (defined(__MINGW32__) ... */
#endif /* WINPR_CRT_H */

View File

@ -23,7 +23,7 @@
/* Data Alignment: http://msdn.microsoft.com/en-us/library/fs9stz4e/ */
#ifndef _WIN32
#if !defined(_WIN32) || (defined(__MINGW32__) && ! defined(_UCRT))
#include <stdint.h>
#include <limits.h>
@ -54,22 +54,22 @@ struct winpr_aligned_mem
};
typedef struct winpr_aligned_mem WINPR_ALIGNED_MEM;
void* _aligned_malloc(size_t size, size_t alignment)
void* winpr_aligned_malloc(size_t size, size_t alignment)
{
return _aligned_offset_malloc(size, alignment, 0);
return winpr_aligned_offset_malloc(size, alignment, 0);
}
void* _aligned_realloc(void* memblock, size_t size, size_t alignment)
void* winpr_aligned_realloc(void* memblock, size_t size, size_t alignment)
{
return _aligned_offset_realloc(memblock, size, alignment, 0);
return winpr_aligned_offset_realloc(memblock, size, alignment, 0);
}
void* _aligned_recalloc(void* memblock, size_t num, size_t size, size_t alignment)
void* winpr_aligned_recalloc(void* memblock, size_t num, size_t size, size_t alignment)
{
return _aligned_offset_recalloc(memblock, num, size, alignment, 0);
return winpr_aligned_offset_recalloc(memblock, num, size, alignment, 0);
}
void* _aligned_offset_malloc(size_t size, size_t alignment, size_t offset)
void* winpr_aligned_offset_malloc(size_t size, size_t alignment, size_t offset)
{
size_t header, alignsize;
uintptr_t basesize;
@ -121,7 +121,7 @@ void* _aligned_offset_malloc(size_t size, size_t alignment, size_t offset)
return memblock;
}
void* _aligned_offset_realloc(void* memblock, size_t size, size_t alignment, size_t offset)
void* winpr_aligned_offset_realloc(void* memblock, size_t size, size_t alignment, size_t offset)
{
size_t copySize;
void* newMemblock;
@ -129,7 +129,7 @@ void* _aligned_offset_realloc(void* memblock, size_t size, size_t alignment, siz
WINPR_ALIGNED_MEM* pNewMem;
if (!memblock)
return _aligned_offset_malloc(size, alignment, offset);
return winpr_aligned_offset_malloc(size, alignment, offset);
pMem = WINPR_ALIGNED_MEM_STRUCT_FROM_PTR(memblock);
@ -142,11 +142,11 @@ void* _aligned_offset_realloc(void* memblock, size_t size, size_t alignment, siz
if (size == 0)
{
_aligned_free(memblock);
winpr_aligned_free(memblock);
return NULL;
}
newMemblock = _aligned_offset_malloc(size, alignment, offset);
newMemblock = winpr_aligned_offset_malloc(size, alignment, offset);
if (!newMemblock)
return NULL;
@ -154,7 +154,7 @@ void* _aligned_offset_realloc(void* memblock, size_t size, size_t alignment, siz
pNewMem = WINPR_ALIGNED_MEM_STRUCT_FROM_PTR(newMemblock);
copySize = (pNewMem->size < pMem->size) ? pNewMem->size : pMem->size;
CopyMemory(newMemblock, memblock, copySize);
_aligned_free(memblock);
winpr_aligned_free(memblock);
return newMemblock;
}
@ -165,7 +165,7 @@ static INLINE size_t cMIN(size_t a, size_t b)
return a;
}
void* _aligned_offset_recalloc(void* memblock, size_t num, size_t size, size_t alignment,
void* winpr_aligned_offset_recalloc(void* memblock, size_t num, size_t size, size_t alignment,
size_t offset)
{
char* newMemblock = NULL;
@ -174,7 +174,7 @@ void* _aligned_offset_recalloc(void* memblock, size_t num, size_t size, size_t a
if (!memblock)
{
newMemblock = _aligned_offset_malloc(size * num, alignment, offset);
newMemblock = winpr_aligned_offset_malloc(size * num, alignment, offset);
if (newMemblock)
{
@ -197,7 +197,7 @@ void* _aligned_offset_recalloc(void* memblock, size_t num, size_t size, size_t a
if (size == 0)
goto fail;
newMemblock = _aligned_offset_malloc(size * num, alignment, offset);
newMemblock = winpr_aligned_offset_malloc(size * num, alignment, offset);
if (!newMemblock)
goto fail;
@ -209,11 +209,11 @@ void* _aligned_offset_recalloc(void* memblock, size_t num, size_t size, size_t a
ZeroMemory(newMemblock + csize, pNewMem->size - csize);
}
fail:
_aligned_free(memblock);
winpr_aligned_free(memblock);
return newMemblock;
}
size_t _aligned_msize(void* memblock, size_t alignment, size_t offset)
size_t winpr_aligned_msize(void* memblock, size_t alignment, size_t offset)
{
WINPR_ALIGNED_MEM* pMem;
@ -231,7 +231,7 @@ size_t _aligned_msize(void* memblock, size_t alignment, size_t offset)
return pMem->size;
}
void _aligned_free(void* memblock)
void winpr_aligned_free(void* memblock)
{
WINPR_ALIGNED_MEM* pMem;

View File

@ -19,7 +19,7 @@ int TestAlignment(int argc, char* argv[])
/* _aligned_malloc */
ptr = _aligned_malloc(100, alignment);
ptr = winpr_aligned_malloc(100, alignment);
if (ptr == NULL)
{
@ -35,7 +35,7 @@ int TestAlignment(int argc, char* argv[])
/* _aligned_realloc */
ptr = _aligned_realloc(ptr, 200, alignment);
ptr = winpr_aligned_realloc(ptr, 200, alignment);
if (((size_t)ptr % alignment) != 0)
{
@ -43,11 +43,11 @@ int TestAlignment(int argc, char* argv[])
return -1;
}
_aligned_free(ptr);
winpr_aligned_free(ptr);
/* _aligned_offset_malloc */
ptr = _aligned_offset_malloc(200, alignment, offset);
ptr = winpr_aligned_offset_malloc(200, alignment, offset);
if (ptr == NULL)
{
@ -64,7 +64,7 @@ int TestAlignment(int argc, char* argv[])
/* _aligned_offset_realloc */
ptr = _aligned_offset_realloc(ptr, 200, alignment, offset);
ptr = winpr_aligned_offset_realloc(ptr, 200, alignment, offset);
if (ptr == NULL)
{
@ -81,7 +81,7 @@ int TestAlignment(int argc, char* argv[])
/* _aligned_free works for both _aligned_malloc and _aligned_offset_malloc. free() should not be
* used. */
_aligned_free(ptr);
winpr_aligned_free(ptr);
return 0;
}

View File

@ -83,7 +83,7 @@ int TestErrorSetLastError(int argc, char* argv[])
return -1;
}
pLoopCount = _aligned_malloc(sizeof(LONG), sizeof(LONG));
pLoopCount = winpr_aligned_malloc(sizeof(LONG), sizeof(LONG));
if (!pLoopCount)
{
printf("Unable to allocate memory\n");
@ -130,6 +130,7 @@ int TestErrorSetLastError(int argc, char* argv[])
}
printf("Completed %" PRId32 " iterations.\n", *pLoopCount);
winpr_aligned_free(pLoopCount);
return status;
}

View File

@ -16,7 +16,7 @@ int TestInterlockedAccess(int argc, char* argv[])
WINPR_UNUSED(argv);
/* InterlockedIncrement */
Addend = _aligned_malloc(sizeof(LONG), sizeof(LONG));
Addend = winpr_aligned_malloc(sizeof(LONG), sizeof(LONG));
if (!Addend)
{
printf("Failed to allocate memory\n");
@ -47,7 +47,7 @@ int TestInterlockedAccess(int argc, char* argv[])
/* InterlockedExchange */
Target = _aligned_malloc(sizeof(LONG), sizeof(LONG));
Target = winpr_aligned_malloc(sizeof(LONG), sizeof(LONG));
if (!Target)
{
@ -91,7 +91,7 @@ int TestInterlockedAccess(int argc, char* argv[])
/* InterlockedCompareExchange (*Destination == Comparand) */
Destination = _aligned_malloc(sizeof(LONG), sizeof(LONG));
Destination = winpr_aligned_malloc(sizeof(LONG), sizeof(LONG));
if (!Destination)
{
printf("Failed to allocate memory\n");
@ -142,7 +142,7 @@ int TestInterlockedAccess(int argc, char* argv[])
/* InterlockedCompareExchange64 (*Destination == Comparand) */
Destination64 = _aligned_malloc(sizeof(LONGLONG), sizeof(LONGLONG));
Destination64 = winpr_aligned_malloc(sizeof(LONGLONG), sizeof(LONGLONG));
if (!Destination64)
{
printf("Failed to allocate memory\n");
@ -192,10 +192,10 @@ int TestInterlockedAccess(int argc, char* argv[])
return -1;
}
_aligned_free(Addend);
_aligned_free(Target);
_aligned_free(Destination);
_aligned_free(Destination64);
winpr_aligned_free(Addend);
winpr_aligned_free(Target);
winpr_aligned_free(Destination);
winpr_aligned_free(Destination64);
return 0;
}

View File

@ -19,7 +19,7 @@ int TestInterlockedDList(int argc, char* argv[])
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
pListHead =
(WINPR_PLIST_ENTRY)_aligned_malloc(sizeof(WINPR_LIST_ENTRY), MEMORY_ALLOCATION_ALIGNMENT);
(WINPR_PLIST_ENTRY)winpr_aligned_malloc(sizeof(WINPR_LIST_ENTRY), MEMORY_ALLOCATION_ALIGNMENT);
if (!pListHead)
{
@ -41,7 +41,7 @@ int TestInterlockedDList(int argc, char* argv[])
for (Count = 1; Count <= 10; Count += 1)
{
pListItem = (PLIST_ITEM)_aligned_malloc(sizeof(LIST_ITEM), MEMORY_ALLOCATION_ALIGNMENT);
pListItem = (PLIST_ITEM)winpr_aligned_malloc(sizeof(LIST_ITEM), MEMORY_ALLOCATION_ALIGNMENT);
pListItem->Signature = Count;
InsertHeadList(pListHead, &(pListItem->ItemEntry));
}
@ -50,7 +50,7 @@ int TestInterlockedDList(int argc, char* argv[])
{
pListEntry = RemoveHeadList(pListHead);
pListItem = (PLIST_ITEM)pListEntry;
_aligned_free(pListItem);
winpr_aligned_free(pListItem);
}
/* InsertTailList / RemoveTailList */
@ -59,7 +59,7 @@ int TestInterlockedDList(int argc, char* argv[])
for (Count = 1; Count <= 10; Count += 1)
{
pListItem = (PLIST_ITEM)_aligned_malloc(sizeof(LIST_ITEM), MEMORY_ALLOCATION_ALIGNMENT);
pListItem = (PLIST_ITEM)winpr_aligned_malloc(sizeof(LIST_ITEM), MEMORY_ALLOCATION_ALIGNMENT);
pListItem->Signature = Count;
InsertTailList(pListHead, &(pListItem->ItemEntry));
}
@ -68,10 +68,10 @@ int TestInterlockedDList(int argc, char* argv[])
{
pListEntry = RemoveTailList(pListHead);
pListItem = (PLIST_ITEM)pListEntry;
_aligned_free(pListItem);
winpr_aligned_free(pListItem);
}
_aligned_free(pListHead);
winpr_aligned_free(pListHead);
return 0;
}

View File

@ -18,7 +18,7 @@ int TestInterlockedSList(int argc, char* argv[])
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
/* Initialize the list header to a MEMORY_ALLOCATION_ALIGNMENT boundary. */
pListHead = (WINPR_PSLIST_HEADER)_aligned_malloc(sizeof(WINPR_SLIST_HEADER),
pListHead = (WINPR_PSLIST_HEADER)winpr_aligned_malloc(sizeof(WINPR_SLIST_HEADER),
MEMORY_ALLOCATION_ALIGNMENT);
if (!pListHead)
@ -33,7 +33,7 @@ int TestInterlockedSList(int argc, char* argv[])
for (Count = 1; Count <= 10; Count += 1)
{
PPROGRAM_ITEM pProgramItem =
(PPROGRAM_ITEM)_aligned_malloc(sizeof(PROGRAM_ITEM), MEMORY_ALLOCATION_ALIGNMENT);
(PPROGRAM_ITEM)winpr_aligned_malloc(sizeof(PROGRAM_ITEM), MEMORY_ALLOCATION_ALIGNMENT);
if (!pProgramItem)
{
@ -67,7 +67,7 @@ int TestInterlockedSList(int argc, char* argv[])
* of the structure before calling the free function.
*/
_aligned_free(pListEntry);
winpr_aligned_free(pListEntry);
}
/* Flush the list and verify that the items are gone. */
@ -79,7 +79,7 @@ int TestInterlockedSList(int argc, char* argv[])
return -1;
}
_aligned_free(pListHead);
winpr_aligned_free(pListHead);
return 0;
}

View File

@ -18,10 +18,6 @@ create_test_sourcelist(${MODULE_PREFIX}_SRCS
add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
target_link_libraries(${MODULE_NAME} winpr)
if (MINGW)
target_link_libraries(${MODULE_NAME} ucrt)
endif()
set_target_properties(${MODULE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}")

View File

@ -75,10 +75,10 @@ int TestSynchInit(int argc, char* argv[])
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
pErrors = _aligned_malloc(sizeof(LONG), sizeof(LONG));
pTestThreadFunctionCalls = _aligned_malloc(sizeof(LONG), sizeof(LONG));
pTestOnceFunctionCalls = _aligned_malloc(sizeof(LONG), sizeof(LONG));
pInitOnceExecuteOnceCalls = _aligned_malloc(sizeof(LONG), sizeof(LONG));
pErrors = winpr_aligned_malloc(sizeof(LONG), sizeof(LONG));
pTestThreadFunctionCalls = winpr_aligned_malloc(sizeof(LONG), sizeof(LONG));
pTestOnceFunctionCalls = winpr_aligned_malloc(sizeof(LONG), sizeof(LONG));
pInitOnceExecuteOnceCalls = winpr_aligned_malloc(sizeof(LONG), sizeof(LONG));
if (!pErrors || !pTestThreadFunctionCalls || !pTestOnceFunctionCalls ||
!pInitOnceExecuteOnceCalls)
@ -141,10 +141,10 @@ out:
fprintf(stderr, "TestOnceFunctionCalls: %" PRId32 "\n",
pTestOnceFunctionCalls ? *pTestOnceFunctionCalls : -1);
_aligned_free(pErrors);
_aligned_free(pTestThreadFunctionCalls);
_aligned_free(pTestOnceFunctionCalls);
_aligned_free(pInitOnceExecuteOnceCalls);
winpr_aligned_free(pErrors);
winpr_aligned_free(pTestThreadFunctionCalls);
winpr_aligned_free(pTestOnceFunctionCalls);
winpr_aligned_free(pInitOnceExecuteOnceCalls);
CloseHandle(hStartEvent);

View File

@ -92,7 +92,7 @@ static BOOL BufferPool_ShiftAvailable(wBufferPool* pool, size_t index, int count
SSIZE_T newCapacity = pool->aCapacity * 2;
if (pool->alignment > 0)
newArray = (wBufferPoolItem*)_aligned_realloc(
newArray = (wBufferPoolItem*)winpr_aligned_realloc(
pool->aArray, sizeof(wBufferPoolItem) * newCapacity, pool->alignment);
else
newArray =
@ -125,7 +125,7 @@ static BOOL BufferPool_ShiftUsed(wBufferPool* pool, SSIZE_T index, SSIZE_T count
SSIZE_T newUCapacity = pool->uCapacity * 2;
wBufferPoolItem* newUArray;
if (pool->alignment > 0)
newUArray = (wBufferPoolItem*)_aligned_realloc(
newUArray = (wBufferPoolItem*)winpr_aligned_realloc(
pool->uArray, sizeof(wBufferPoolItem) * newUCapacity, pool->alignment);
else
newUArray =
@ -238,7 +238,7 @@ void* BufferPool_Take(wBufferPool* pool, SSIZE_T size)
if (!buffer)
{
if (pool->alignment)
buffer = _aligned_malloc(pool->fixedSize, pool->alignment);
buffer = winpr_aligned_malloc(pool->fixedSize, pool->alignment);
else
buffer = malloc(pool->fixedSize);
}
@ -285,7 +285,7 @@ void* BufferPool_Take(wBufferPool* pool, SSIZE_T size)
else
{
if (pool->alignment)
buffer = _aligned_malloc(size, pool->alignment);
buffer = winpr_aligned_malloc(size, pool->alignment);
else
buffer = malloc(size);
@ -301,7 +301,7 @@ void* BufferPool_Take(wBufferPool* pool, SSIZE_T size)
{
void* newBuffer;
if (pool->alignment)
newBuffer = _aligned_realloc(buffer, size, pool->alignment);
newBuffer = winpr_aligned_realloc(buffer, size, pool->alignment);
else
newBuffer = realloc(buffer, size);
@ -341,7 +341,7 @@ void* BufferPool_Take(wBufferPool* pool, SSIZE_T size)
out_error:
if (pool->alignment)
_aligned_free(buffer);
winpr_aligned_free(buffer);
else
free(buffer);
out_error_no_free:
@ -442,7 +442,7 @@ void BufferPool_Clear(wBufferPool* pool)
(pool->size)--;
if (pool->alignment)
_aligned_free(pool->array[pool->size]);
winpr_aligned_free(pool->array[pool->size]);
else
free(pool->array[pool->size]);
}
@ -456,7 +456,7 @@ void BufferPool_Clear(wBufferPool* pool)
(pool->aSize)--;
if (pool->alignment)
_aligned_free(pool->aArray[pool->aSize].buffer);
winpr_aligned_free(pool->aArray[pool->aSize].buffer);
else
free(pool->aArray[pool->aSize].buffer);
}
@ -466,7 +466,7 @@ void BufferPool_Clear(wBufferPool* pool)
(pool->uSize)--;
if (pool->alignment)
_aligned_free(pool->uArray[pool->uSize].buffer);
winpr_aligned_free(pool->uArray[pool->uSize].buffer);
else
free(pool->uArray[pool->uSize].buffer);
}