msvcr100: Added _aligned_msize implementation.

This commit is contained in:
Piotr Caban 2012-12-21 13:38:34 +01:00 committed by Alexandre Julliard
parent dfca87db71
commit 6e38d5beef
5 changed files with 56 additions and 3 deletions

View File

@ -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.@)
*/

View File

@ -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

View File

@ -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();
}

View File

@ -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

View File

@ -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