diff --git a/dlls/msvcr100/msvcr100.c b/dlls/msvcr100/msvcr100.c index f571aee0235..aeab2ad8084 100644 --- a/dlls/msvcr100/msvcr100.c +++ b/dlls/msvcr100/msvcr100.c @@ -483,6 +483,26 @@ int CDECL _get_timezone(LONG *timezone) return 0; } +/* copied from dlls/msvcrt/heap.c */ +#define SAVED_PTR(x) ((void *)((DWORD_PTR)((char *)x - sizeof(void *)) & \ + ~(sizeof(void *) - 1))) + +/********************************************************************* + * _aligned_msize (MSVCR100.@) + */ +size_t CDECL _aligned_msize(void *p, size_t alignment, size_t offset) +{ + void **alloc_ptr; + + if(!CHECK_PMT(p)) return -1; + + if(alignment < sizeof(void*)) + alignment = sizeof(void*); + + alloc_ptr = SAVED_PTR(p); + return _msize(*alloc_ptr)-alignment-sizeof(void*); +} + /********************************************************************* * DllMain (MSVCR100.@) */ diff --git a/dlls/msvcr100/msvcr100.spec b/dlls/msvcr100/msvcr100.spec index 38ae28af4f0..a09b142429e 100644 --- a/dlls/msvcr100/msvcr100.spec +++ b/dlls/msvcr100/msvcr100.spec @@ -678,7 +678,7 @@ @ extern _acmdln msvcrt._acmdln @ cdecl _aligned_free(ptr) msvcrt._aligned_free @ cdecl _aligned_malloc(long long) msvcrt._aligned_malloc -@ stub _aligned_msize +@ cdecl _aligned_msize(ptr long long) @ cdecl _aligned_offset_malloc(long long long) msvcrt._aligned_offset_malloc @ cdecl _aligned_offset_realloc(ptr long long long) msvcrt._aligned_offset_realloc @ stub _aligned_offset_recalloc diff --git a/dlls/msvcr100/tests/msvcr100.c b/dlls/msvcr100/tests/msvcr100.c index 143979d3ee1..99834dd34cc 100644 --- a/dlls/msvcr100/tests/msvcr100.c +++ b/dlls/msvcr100/tests/msvcr100.c @@ -72,6 +72,9 @@ static int (__cdecl *p_wmemmove_s)(wchar_t *dest, size_t numberOfElements, const static FILE* (__cdecl *p_fopen)(const char*,const char*); static int (__cdecl *p_fclose)(FILE*); static size_t (__cdecl *p_fread_s)(void*,size_t,size_t,size_t,FILE*); +static void* (__cdecl *p__aligned_offset_malloc)(size_t, size_t, size_t); +static void (__cdecl *p__aligned_free)(void*); +static size_t (__cdecl *p__aligned_msize)(void*, size_t, size_t); /* make sure we use the correct errno */ #undef errno @@ -98,6 +101,9 @@ static BOOL init(void) SET(p_fopen, "fopen"); SET(p_fclose, "fclose"); SET(p_fread_s, "fread_s"); + SET(p__aligned_offset_malloc, "_aligned_offset_malloc"); + SET(p__aligned_free, "_aligned_free"); + SET(p__aligned_msize, "_aligned_msize"); return TRUE; } @@ -326,6 +332,32 @@ static void test_fread_s(void) unlink(test_file); } +static void test__aligned_msize(void) +{ + void *mem; + int ret; + + mem = p__aligned_offset_malloc(23, 16, 7); + ret = p__aligned_msize(mem, 16, 7); + ok(ret == 23, "_aligned_msize returned %d\n", ret); + ret = p__aligned_msize(mem, 15, 7); + ok(ret == 24, "_aligned_msize returned %d\n", ret); + ret = p__aligned_msize(mem, 11, 7); + ok(ret == 28, "_aligned_msize returned %d\n", ret); + ret = p__aligned_msize(mem, 1, 7); + ok(ret == 39-sizeof(void*), "_aligned_msize returned %d\n", ret); + ret = p__aligned_msize(mem, 8, 0); + todo_wine ok(ret == 32, "_aligned_msize returned %d\n", ret); + p__aligned_free(mem); + + mem = p__aligned_offset_malloc(3, 16, 0); + ret = p__aligned_msize(mem, 16, 0); + ok(ret == 3, "_aligned_msize returned %d\n", ret); + ret = p__aligned_msize(mem, 11, 0); + ok(ret == 8, "_aligned_msize returned %d\n", ret); + p__aligned_free(mem); +} + START_TEST(msvcr100) { if (!init()) @@ -334,4 +366,5 @@ START_TEST(msvcr100) test_wmemcpy_s(); test_wmemmove_s(); test_fread_s(); + test__aligned_msize(); } diff --git a/dlls/msvcr80/msvcr80.spec b/dlls/msvcr80/msvcr80.spec index c9469e7d587..4457c2c7751 100644 --- a/dlls/msvcr80/msvcr80.spec +++ b/dlls/msvcr80/msvcr80.spec @@ -334,7 +334,7 @@ @ extern _aexit_rtn msvcrt._aexit_rtn @ cdecl _aligned_free(ptr) msvcrt._aligned_free @ cdecl _aligned_malloc(long long) msvcrt._aligned_malloc -@ stub _aligned_msize +@ cdecl _aligned_msize(ptr long long) msvcr100._aligned_msize @ cdecl _aligned_offset_malloc(long long long) msvcrt._aligned_offset_malloc @ cdecl _aligned_offset_realloc(ptr long long long) msvcrt._aligned_offset_realloc @ stub _aligned_offset_recalloc diff --git a/dlls/msvcr90/msvcr90.spec b/dlls/msvcr90/msvcr90.spec index bf54f0af919..c20c5fd4828 100644 --- a/dlls/msvcr90/msvcr90.spec +++ b/dlls/msvcr90/msvcr90.spec @@ -326,7 +326,7 @@ @ extern _aexit_rtn msvcrt._aexit_rtn @ cdecl _aligned_free(ptr) msvcrt._aligned_free @ cdecl _aligned_malloc(long long) msvcrt._aligned_malloc -@ stub _aligned_msize +@ cdecl _aligned_msize(ptr long long) msvcr100._aligned_msize @ cdecl _aligned_offset_malloc(long long long) msvcrt._aligned_offset_malloc @ cdecl _aligned_offset_realloc(ptr long long long) msvcrt._aligned_offset_realloc @ stub _aligned_offset_recalloc