[PATCH 1/4] msvcr110/tests: Use macro to get function address.
Signed-off-by: Daniel Lehman <dlehman25(a)gmail.com> --- dlls/msvcr110/tests/msvcr110.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/dlls/msvcr110/tests/msvcr110.c b/dlls/msvcr110/tests/msvcr110.c index 09876131f07..364dd26aa82 100644 --- a/dlls/msvcr110/tests/msvcr110.c +++ b/dlls/msvcr110/tests/msvcr110.c @@ -39,6 +39,9 @@ static unsigned int (CDECL *p__CurrentScheduler__GetNumberOfVirtualProcessors)(v static unsigned int (CDECL *p_CurrentScheduler_Id)(void); static unsigned int (CDECL *p__CurrentScheduler__Id)(void); +#define SETNOFAIL(x,y) x = (void*)GetProcAddress(module,y) +#define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0) + static BOOL init(void) { HMODULE module; @@ -50,12 +53,12 @@ static BOOL init(void) return FALSE; } - p_setlocale = (void*)GetProcAddress(module, "setlocale"); - p___strncnt = (void*)GetProcAddress(module, "__strncnt"); - p_CurrentScheduler_GetNumberOfVirtualProcessors = (void*)GetProcAddress(module, "?GetNumberOfVirtualProcessors(a)CurrentScheduler@Concurrency@@SAIXZ"); - p__CurrentScheduler__GetNumberOfVirtualProcessors = (void*)GetProcAddress(module, "?_GetNumberOfVirtualProcessors(a)_CurrentScheduler@details(a)Concurrency@@SAIXZ"); - p_CurrentScheduler_Id = (void*)GetProcAddress(module, "?Id(a)CurrentScheduler@Concurrency@@SAIXZ"); - p__CurrentScheduler__Id = (void*)GetProcAddress(module, "?_Id(a)_CurrentScheduler@details(a)Concurrency@@SAIXZ"); + SET(p_setlocale, "setlocale"); + SET(p___strncnt, "__strncnt"); + SET(p_CurrentScheduler_GetNumberOfVirtualProcessors, "?GetNumberOfVirtualProcessors(a)CurrentScheduler@Concurrency@@SAIXZ"); + SET(p__CurrentScheduler__GetNumberOfVirtualProcessors, "?_GetNumberOfVirtualProcessors(a)_CurrentScheduler@details(a)Concurrency@@SAIXZ"); + SET(p_CurrentScheduler_Id, "?Id(a)CurrentScheduler@Concurrency@@SAIXZ"); + SET(p__CurrentScheduler__Id, "?_Id(a)_CurrentScheduler@details(a)Concurrency@@SAIXZ"); return TRUE; } -- 2.25.1
Signed-off-by: Daniel Lehman <dlehman25(a)gmail.com> --- dlls/concrt140/concrt140.spec | 2 +- dlls/msvcr110/msvcr110.spec | 2 +- dlls/msvcr110/tests/msvcr110.c | 42 +++++++++++++++++++++++++++++ dlls/msvcr120/msvcr120.spec | 2 +- dlls/msvcr120_app/msvcr120_app.spec | 2 +- dlls/msvcrt/scheduler.c | 14 ++++++++++ 6 files changed, 60 insertions(+), 4 deletions(-) diff --git a/dlls/concrt140/concrt140.spec b/dlls/concrt140/concrt140.spec index 9a8ef13aaeb..ea8a3e00dc5 100644 --- a/dlls/concrt140/concrt140.spec +++ b/dlls/concrt140/concrt140.spec @@ -327,7 +327,7 @@ @ stub -arch=win64 ?_ConcRT_Trace(a)details@Concurrency@@YAXHPEB_WZZ @ stub -arch=i386 ?_Confirm_cancel(a)_Cancellation_beacon@details(a)Concurrency@@QAE_NXZ @ stub -arch=win64 ?_Confirm_cancel(a)_Cancellation_beacon@details(a)Concurrency@@QEAA_NXZ -@ stub ?_CurrentContext(a)_Context@details(a)Concurrency@@SA?AV123(a)XZ +@ cdecl ?_CurrentContext(a)_Context@details(a)Concurrency@@SA?AV123(a)XZ() msvcr120.?_CurrentContext(a)_Context@details(a)Concurrency@@SA?AV123(a)XZ @ stub ?_Current_node(a)location@Concurrency@@SA?AV12(a)XZ @ stub -arch=i386 ?_Destroy(a)_AsyncTaskCollection@details(a)Concurrency@@EAEXXZ @ stub -arch=win64 ?_Destroy(a)_AsyncTaskCollection@details(a)Concurrency@@EEAAXXZ diff --git a/dlls/msvcr110/msvcr110.spec b/dlls/msvcr110/msvcr110.spec index 425bdfdc21a..54196f63690 100644 --- a/dlls/msvcr110/msvcr110.spec +++ b/dlls/msvcr110/msvcr110.spec @@ -513,7 +513,7 @@ @ stub -arch=arm ?_Copy_str(a)exception@std@@AAAXPBD(a)Z @ stub -arch=i386 ?_Copy_str(a)exception@std@@AAEXPBD(a)Z @ stub -arch=win64 ?_Copy_str(a)exception@std@@AEAAXPEBD(a)Z -@ stub ?_CurrentContext(a)_Context@details(a)Concurrency@@SA?AV123(a)XZ +@ cdecl ?_CurrentContext(a)_Context@details(a)Concurrency@@SA?AV123(a)XZ(ptr) _Context__CurrentContext @ stub ?_Current_node(a)location@Concurrency@@SA?AV12(a)XZ @ stub -arch=arm ?_DeregisterCallback(a)_CancellationTokenState@details(a)Concurrency@@QAAXPAV_CancellationTokenRegistration(a)23@@Z @ stub -arch=i386 ?_DeregisterCallback(a)_CancellationTokenState@details(a)Concurrency@@QAEXPAV_CancellationTokenRegistration(a)23@@Z diff --git a/dlls/msvcr110/tests/msvcr110.c b/dlls/msvcr110/tests/msvcr110.c index 364dd26aa82..8d3b85bfbcf 100644 --- a/dlls/msvcr110/tests/msvcr110.c +++ b/dlls/msvcr110/tests/msvcr110.c @@ -31,6 +31,16 @@ #include <locale.h> +typedef void (*vtable_ptr)(void); + +typedef struct { + const vtable_ptr *vtable; +} Context; + +typedef struct { + Context *ctx; +} _Context; + static char* (CDECL *p_setlocale)(int category, const char* locale); static size_t (CDECL *p___strncnt)(const char *str, size_t count); @@ -39,6 +49,9 @@ static unsigned int (CDECL *p__CurrentScheduler__GetNumberOfVirtualProcessors)(v static unsigned int (CDECL *p_CurrentScheduler_Id)(void); static unsigned int (CDECL *p__CurrentScheduler__Id)(void); +static Context* (__cdecl *p_Context_CurrentContext)(void); +static _Context* (__cdecl *p__Context__CurrentContext)(_Context*); + #define SETNOFAIL(x,y) x = (void*)GetProcAddress(module,y) #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0) @@ -60,6 +73,17 @@ static BOOL init(void) SET(p_CurrentScheduler_Id, "?Id(a)CurrentScheduler@Concurrency@@SAIXZ"); SET(p__CurrentScheduler__Id, "?_Id(a)_CurrentScheduler@details(a)Concurrency@@SAIXZ"); + SET(p__Context__CurrentContext, "?_CurrentContext(a)_Context@details(a)Concurrency@@SA?AV123(a)XZ"); + + if(sizeof(void*) == 8) + { + SET(p_Context_CurrentContext, "?CurrentContext(a)Context@Concurrency@@SAPEAV12(a)XZ"); + } + else + { + SET(p_Context_CurrentContext, "?CurrentContext(a)Context@Concurrency@@SAPAV12(a)XZ"); + } + return TRUE; } @@ -146,10 +170,28 @@ static void test___strncnt(void) } } +static void test_CurrentContext(void) +{ + _Context _ctx, *_pctx; + Context *ctx; + + ctx = p_Context_CurrentContext(); + ok(!!ctx, "got NULL\n"); + + if (0) /* crash Windows */ + p__Context__CurrentContext(NULL); + + memset(&_ctx, 0xcc, sizeof(_ctx)); + _pctx = p__Context__CurrentContext(&_ctx); + ok(_ctx.ctx == ctx, "expected %p, got %p\n", ctx, _ctx.ctx); + ok(_pctx == &_ctx, "expected %p, got %p\n", &_ctx, _pctx); +} + START_TEST(msvcr110) { if (!init()) return; test_CurrentScheduler(); /* MUST be first (at least among Concurrency tests) */ test_setlocale(); test___strncnt(); + test_CurrentContext(); } diff --git a/dlls/msvcr120/msvcr120.spec b/dlls/msvcr120/msvcr120.spec index 368f376939d..f1e6fe210a7 100644 --- a/dlls/msvcr120/msvcr120.spec +++ b/dlls/msvcr120/msvcr120.spec @@ -509,7 +509,7 @@ @ stub -arch=arm ?_Copy_str(a)exception@std@@AAAXPBD(a)Z @ stub -arch=i386 ?_Copy_str(a)exception@std@@AAEXPBD(a)Z @ stub -arch=win64 ?_Copy_str(a)exception@std@@AEAAXPEBD(a)Z -@ stub ?_CurrentContext(a)_Context@details(a)Concurrency@@SA?AV123(a)XZ +@ cdecl ?_CurrentContext(a)_Context@details(a)Concurrency@@SA?AV123(a)XZ() _Context__CurrentContext @ stub ?_Current_node(a)location@Concurrency@@SA?AV12(a)XZ @ stub -arch=arm ?_Destroy(a)_AsyncTaskCollection@details(a)Concurrency@@EAAXXZ @ stub -arch=i386 ?_Destroy(a)_AsyncTaskCollection@details(a)Concurrency@@EAEXXZ diff --git a/dlls/msvcr120_app/msvcr120_app.spec b/dlls/msvcr120_app/msvcr120_app.spec index 54a02bb0a90..87a55210951 100644 --- a/dlls/msvcr120_app/msvcr120_app.spec +++ b/dlls/msvcr120_app/msvcr120_app.spec @@ -505,7 +505,7 @@ @ stub -arch=arm ?_Copy_str(a)exception@std@@AAAXPBD(a)Z @ stub -arch=i386 ?_Copy_str(a)exception@std@@AAEXPBD(a)Z @ stub -arch=win64 ?_Copy_str(a)exception@std@@AEAAXPEBD(a)Z -@ stub ?_CurrentContext(a)_Context@details(a)Concurrency@@SA?AV123(a)XZ +@ cdecl ?_CurrentContext(a)_Context@details(a)Concurrency@@SA?AV123(a)XZ() msvcr120.?_CurrentContext(a)_Context@details(a)Concurrency@@SA?AV123(a)XZ @ stub ?_Current_node(a)location@Concurrency@@SA?AV12(a)XZ @ stub -arch=arm ?_Destroy(a)_AsyncTaskCollection@details(a)Concurrency@@EAAXXZ @ stub -arch=i386 ?_Destroy(a)_AsyncTaskCollection@details(a)Concurrency@@EAEXXZ diff --git a/dlls/msvcrt/scheduler.c b/dlls/msvcrt/scheduler.c index 59e177b5aec..317d0de18c7 100644 --- a/dlls/msvcrt/scheduler.c +++ b/dlls/msvcrt/scheduler.c @@ -68,6 +68,10 @@ typedef struct { #define call_Context_dtor(this, flags) CALL_VTBL_FUNC(this, 20, \ Context*, (Context*, unsigned int), (this, flags)) +typedef struct { + Context *context; +} _Context; + union allocator_cache_entry { struct _free { int depth; @@ -278,6 +282,16 @@ unsigned int __cdecl Context_VirtualProcessorId(void) return ctx ? call_Context_GetVirtualProcessorId(ctx) : -1; } +#if _MSVCR_VER > 100 +/* ?_CurrentContext(a)_Context@details(a)Concurrency@@SA?AV123(a)XZ */ +_Context *__cdecl _Context__CurrentContext(_Context *ctx) +{ + TRACE("(%p)\n", ctx); + ctx->context = Context_CurrentContext(); + return ctx; +} +#endif + DEFINE_THISCALL_WRAPPER(ExternalContextBase_GetId, 4) unsigned int __thiscall ExternalContextBase_GetId(const ExternalContextBase *this) { -- 2.25.1
Hi Daniel, On 11/2/20 5:21 AM, Daniel Lehman wrote:
+ if (0) /* crash Windows */ + p__Context__CurrentContext(NULL); It's not possible to call it with NULL argument using proper compiler/headers. Please remove the test.
+#if _MSVCR_VER > 100 +/* ?_CurrentContext(a)_Context@details(a)Concurrency@@SA?AV123(a)XZ */ +_Context *__cdecl _Context__CurrentContext(_Context *ctx) Could you please rename the ctx argument to ret? I was trying to always name it this way to mark structures returned in memory.
Thanks, Piotr
Signed-off-by: Daniel Lehman <dlehman25(a)gmail.com> --- dlls/msvcr120/tests/msvcr120.c | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/dlls/msvcr120/tests/msvcr120.c b/dlls/msvcr120/tests/msvcr120.c index a055feeac91..f5aea64f2e7 100644 --- a/dlls/msvcr120/tests/msvcr120.c +++ b/dlls/msvcr120/tests/msvcr120.c @@ -157,6 +157,16 @@ typedef struct double i; } _Dcomplex; +typedef void (*vtable_ptr)(void); + +typedef struct { + const vtable_ptr *vtable; +} Context; + +typedef struct { + Context *ctx; +} _Context; + static char* (CDECL *p_setlocale)(int category, const char* locale); static struct MSVCRT_lconv* (CDECL *p_localeconv)(void); static size_t (CDECL *p_wcstombs_s)(size_t *ret, char* dest, size_t sz, const wchar_t* src, size_t max); @@ -208,6 +218,9 @@ static MSVCRT_bool (__thiscall *p__Condition_variable_wait_for)(_Condition_varia static void (__thiscall *p__Condition_variable_notify_one)(_Condition_variable*); static void (__thiscall *p__Condition_variable_notify_all)(_Condition_variable*); +static Context* (__cdecl *p_Context_CurrentContext)(void); +static _Context* (__cdecl *p__Context__CurrentContext)(_Context*); + #define SETNOFAIL(x,y) x = (void*)GetProcAddress(module,y) #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0) @@ -250,6 +263,7 @@ static BOOL init(void) SET(p_nexttowardl, "nexttowardl"); SET(p_wctrans, "wctrans"); SET(p_towctrans, "towctrans"); + SET(p__Context__CurrentContext, "?_CurrentContext(a)_Context@details(a)Concurrency@@SA?AV123(a)XZ"); if(sizeof(void*) == 8) { /* 64-bit initialization */ SET(p_critical_section_ctor, "??0critical_section(a)Concurrency@@QEAA(a)XZ"); @@ -281,6 +295,8 @@ static BOOL init(void) "?notify_one(a)_Condition_variable@details(a)Concurrency@@QEAAXXZ"); SET(p__Condition_variable_notify_all, "?notify_all(a)_Condition_variable@details(a)Concurrency@@QEAAXXZ"); + SET(p_Context_CurrentContext, + "?CurrentContext(a)Context@Concurrency@@SAPEAV12(a)XZ"); } else { #ifdef __arm__ SET(p_critical_section_ctor, @@ -345,6 +361,8 @@ static BOOL init(void) SET(p__Condition_variable_notify_all, "?notify_all(a)_Condition_variable@details(a)Concurrency@@QAEXXZ"); #endif + SET(p_Context_CurrentContext, + "?CurrentContext(a)Context@Concurrency@@SAPAV12(a)XZ"); } init_thiscall_thunk(); @@ -1065,6 +1083,23 @@ static void test_towctrans(void) ok(ret == 'T', "towctrans('T', 1) returned %c, expected T\n", ret); } +static void test_CurrentContext(void) +{ + _Context _ctx, *_pctx; + Context *ctx; + + ctx = p_Context_CurrentContext(); + ok(!!ctx, "got NULL\n"); + + if (0) /* crash Windows */ + p__Context__CurrentContext(NULL); + + memset(&_ctx, 0xcc, sizeof(_ctx)); + _pctx = p__Context__CurrentContext(&_ctx); + ok(_ctx.ctx == ctx, "expected %p, got %p\n", ctx, _ctx.ctx); + ok(_pctx == &_ctx, "expected %p, got %p\n", &_ctx, _pctx); +} + START_TEST(msvcr120) { if (!init()) return; @@ -1086,4 +1121,5 @@ START_TEST(msvcr120) test__Cbuild(); test_nexttoward(); test_towctrans(); + test_CurrentContext(); } -- 2.25.1
Signed-off-by: Daniel Lehman <dlehman25(a)gmail.com> --- configure.ac | 1 + dlls/concrt140/tests/Makefile.in | 4 ++ dlls/concrt140/tests/concrt140.c | 82 ++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 dlls/concrt140/tests/Makefile.in create mode 100644 dlls/concrt140/tests/concrt140.c diff --git a/configure.ac b/configure.ac index 2f81fd22610..06031352866 100644 --- a/configure.ac +++ b/configure.ac @@ -3106,6 +3106,7 @@ WINE_CONFIG_MAKEFILE(dlls/compstui) WINE_CONFIG_MAKEFILE(dlls/comsvcs) WINE_CONFIG_MAKEFILE(dlls/comsvcs/tests) WINE_CONFIG_MAKEFILE(dlls/concrt140) +WINE_CONFIG_MAKEFILE(dlls/concrt140/tests) WINE_CONFIG_MAKEFILE(dlls/connect) WINE_CONFIG_MAKEFILE(dlls/credui) WINE_CONFIG_MAKEFILE(dlls/credui/tests) diff --git a/dlls/concrt140/tests/Makefile.in b/dlls/concrt140/tests/Makefile.in new file mode 100644 index 00000000000..e36fc37eb86 --- /dev/null +++ b/dlls/concrt140/tests/Makefile.in @@ -0,0 +1,4 @@ +TESTDLL = concrt140.dll + +C_SRCS = \ + concrt140.c diff --git a/dlls/concrt140/tests/concrt140.c b/dlls/concrt140/tests/concrt140.c new file mode 100644 index 00000000000..e450024adee --- /dev/null +++ b/dlls/concrt140/tests/concrt140.c @@ -0,0 +1,82 @@ +/* + * Copyright 2020 Daniel Lehman + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "wine/test.h" + +typedef void (*vtable_ptr)(void); + +typedef struct { + const vtable_ptr *vtable; +} Context; + +typedef struct { + Context *ctx; +} _Context; + +static Context* (__cdecl *p_Context_CurrentContext)(void); +static _Context* (__cdecl *p__Context__CurrentContext)(_Context*); + +#define SETNOFAIL(x,y) x = (void*)GetProcAddress(module,y) +#define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0) + +static BOOL init(void) +{ + HMODULE module; + + module = LoadLibraryA("concrt140.dll"); + if (!module) + { + win_skip("concrt140.dll not installed\n"); + return FALSE; + } + + SET(p__Context__CurrentContext, + "?_CurrentContext(a)_Context@details(a)Concurrency@@SA?AV123(a)XZ"); + if(sizeof(void*) == 8) { /* 64-bit initialization */ + SET(p_Context_CurrentContext, + "?CurrentContext(a)Context@Concurrency@@SAPEAV12(a)XZ"); + } else { + SET(p_Context_CurrentContext, + "?CurrentContext(a)Context@Concurrency@@SAPAV12(a)XZ"); + } + + return TRUE; +} + +static void test_CurrentContext(void) +{ + _Context _ctx, *_pctx; + Context *ctx; + + ctx = p_Context_CurrentContext(); + ok(!!ctx, "got NULL\n"); + + if (0) /* crash Windows */ + p__Context__CurrentContext(NULL); + + memset(&_ctx, 0xcc, sizeof(_ctx)); + _pctx = p__Context__CurrentContext(&_ctx); + ok(_ctx.ctx == ctx, "expected %p, got %p\n", ctx, _ctx.ctx); + ok(_pctx == &_ctx, "expected %p, got %p\n", &_ctx, _pctx); +} + +START_TEST(concrt140) +{ + if (!init()) return; + test_CurrentContext(); +} -- 2.25.1
participants (2)
-
Daniel Lehman -
Piotr Caban