1
0
mirror of https://git.code.sf.net/p/mingw-w64/mingw-w64 synced 2025-04-18 17:44:18 +03:00

crt: Implement __mingw_aligned_msize() function

Its API is same as MS CRT _aligned_msize() function.

It can be used only on the memory allocated and returned by the
__mingw_aligned_offset_malloc() and __mingw_aligned_offset_realloc()
functions.

Signed-off-by: Martin Storsjö <martin@martin.st>
This commit is contained in:
Pali Rohár 2025-04-08 00:20:44 +02:00 committed by Martin Storsjö
parent a91e27b3d9
commit b4722cedb3
2 changed files with 26 additions and 0 deletions

View File

@ -118,3 +118,28 @@ __mingw_aligned_realloc (void *memblock, size_t size, size_t alignment)
{
return __mingw_aligned_offset_realloc (memblock, size, alignment, 0);
}
size_t
__mingw_aligned_msize (void *memblock, size_t alignment, size_t offset)
{
void *p0;
if (!memblock || NOT_POWER_OF_TWO (alignment))
{
errno = EINVAL;
return (size_t)-1;
}
if (alignment < sizeof (void *))
alignment = sizeof (void *);
p0 = ORIG_PTR (memblock);
/* It is an error if the alignment or offset does not match. */
if (memblock != PTR_ALIGN (p0, alignment, offset))
{
errno = EINVAL;
return (size_t)-1;
}
return _msize (p0) - (alignment + sizeof (void *));
}

View File

@ -133,6 +133,7 @@ void __mingw_aligned_free (void *_Memory);
void * __mingw_aligned_offset_realloc (void *_Memory, size_t _Size, size_t _Alignment, size_t _Offset);
void * __mingw_aligned_offset_malloc (size_t, size_t, size_t);
void * __mingw_aligned_realloc (void *_Memory, size_t _Size, size_t _Offset);
size_t __mingw_aligned_msize (void *memblock, size_t alignment, size_t offset);
#if defined(__x86_64__) || defined(__i386__)
/* Get the compiler's definition of _mm_malloc and _mm_free. */