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>
diff --git a/mingw-w64-crt/misc/mingw-aligned-malloc.c b/mingw-w64-crt/misc/mingw-aligned-malloc.c
index 5029b60..be07ed6 100644
--- a/mingw-w64-crt/misc/mingw-aligned-malloc.c
+++ b/mingw-w64-crt/misc/mingw-aligned-malloc.c
@@ -118,3 +118,28 @@
 {
   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 *));
+}
diff --git a/mingw-w64-headers/crt/malloc.h b/mingw-w64-headers/crt/malloc.h
index cc72d4c..81d70ca 100644
--- a/mingw-w64-headers/crt/malloc.h
+++ b/mingw-w64-headers/crt/malloc.h
@@ -133,6 +133,7 @@
 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. */