From a29f606e08d702ffe0cf6487105427b1dec02bff Mon Sep 17 00:00:00 2001 From: Daniel Lehman Date: Mon, 2 Nov 2020 20:12:08 -0800 Subject: [PATCH] msvcr110: Add _Context::_CurrentContext. Signed-off-by: Daniel Lehman Signed-off-by: Piotr Caban Signed-off-by: Alexandre Julliard --- dlls/concrt140/concrt140.spec | 2 +- dlls/msvcr110/msvcr110.spec | 2 +- dlls/msvcr110/tests/msvcr110.c | 39 +++++++++++++++++++++++++++++ dlls/msvcr120/msvcr120.spec | 2 +- dlls/msvcr120_app/msvcr120_app.spec | 2 +- dlls/msvcrt/scheduler.c | 14 +++++++++++ 6 files changed, 57 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@details@Concurrency@@YAXHPEB_WZZ @ stub -arch=i386 ?_Confirm_cancel@_Cancellation_beacon@details@Concurrency@@QAE_NXZ @ stub -arch=win64 ?_Confirm_cancel@_Cancellation_beacon@details@Concurrency@@QEAA_NXZ -@ stub ?_CurrentContext@_Context@details@Concurrency@@SA?AV123@XZ +@ cdecl ?_CurrentContext@_Context@details@Concurrency@@SA?AV123@XZ() msvcr120.?_CurrentContext@_Context@details@Concurrency@@SA?AV123@XZ @ stub ?_Current_node@location@Concurrency@@SA?AV12@XZ @ stub -arch=i386 ?_Destroy@_AsyncTaskCollection@details@Concurrency@@EAEXXZ @ stub -arch=win64 ?_Destroy@_AsyncTaskCollection@details@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@exception@std@@AAAXPBD@Z @ stub -arch=i386 ?_Copy_str@exception@std@@AAEXPBD@Z @ stub -arch=win64 ?_Copy_str@exception@std@@AEAAXPEBD@Z -@ stub ?_CurrentContext@_Context@details@Concurrency@@SA?AV123@XZ +@ cdecl ?_CurrentContext@_Context@details@Concurrency@@SA?AV123@XZ(ptr) _Context__CurrentContext @ stub ?_Current_node@location@Concurrency@@SA?AV12@XZ @ stub -arch=arm ?_DeregisterCallback@_CancellationTokenState@details@Concurrency@@QAAXPAV_CancellationTokenRegistration@23@@Z @ stub -arch=i386 ?_DeregisterCallback@_CancellationTokenState@details@Concurrency@@QAEXPAV_CancellationTokenRegistration@23@@Z diff --git a/dlls/msvcr110/tests/msvcr110.c b/dlls/msvcr110/tests/msvcr110.c index 364dd26aa82..f88e3122ac9 100644 --- a/dlls/msvcr110/tests/msvcr110.c +++ b/dlls/msvcr110/tests/msvcr110.c @@ -31,6 +31,16 @@ #include +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@CurrentScheduler@Concurrency@@SAIXZ"); SET(p__CurrentScheduler__Id, "?_Id@_CurrentScheduler@details@Concurrency@@SAIXZ"); + SET(p__Context__CurrentContext, "?_CurrentContext@_Context@details@Concurrency@@SA?AV123@XZ"); + + if(sizeof(void*) == 8) + { + SET(p_Context_CurrentContext, "?CurrentContext@Context@Concurrency@@SAPEAV12@XZ"); + } + else + { + SET(p_Context_CurrentContext, "?CurrentContext@Context@Concurrency@@SAPAV12@XZ"); + } + return TRUE; } @@ -146,10 +170,25 @@ static void test___strncnt(void) } } +static void test_CurrentContext(void) +{ + _Context _ctx, *ret; + Context *ctx; + + ctx = p_Context_CurrentContext(); + ok(!!ctx, "got NULL\n"); + + memset(&_ctx, 0xcc, sizeof(_ctx)); + ret = p__Context__CurrentContext(&_ctx); + ok(_ctx.ctx == ctx, "expected %p, got %p\n", ctx, _ctx.ctx); + ok(ret == &_ctx, "expected %p, got %p\n", &_ctx, ret); +} + 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@exception@std@@AAAXPBD@Z @ stub -arch=i386 ?_Copy_str@exception@std@@AAEXPBD@Z @ stub -arch=win64 ?_Copy_str@exception@std@@AEAAXPEBD@Z -@ stub ?_CurrentContext@_Context@details@Concurrency@@SA?AV123@XZ +@ cdecl ?_CurrentContext@_Context@details@Concurrency@@SA?AV123@XZ() _Context__CurrentContext @ stub ?_Current_node@location@Concurrency@@SA?AV12@XZ @ stub -arch=arm ?_Destroy@_AsyncTaskCollection@details@Concurrency@@EAAXXZ @ stub -arch=i386 ?_Destroy@_AsyncTaskCollection@details@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@exception@std@@AAAXPBD@Z @ stub -arch=i386 ?_Copy_str@exception@std@@AAEXPBD@Z @ stub -arch=win64 ?_Copy_str@exception@std@@AEAAXPEBD@Z -@ stub ?_CurrentContext@_Context@details@Concurrency@@SA?AV123@XZ +@ cdecl ?_CurrentContext@_Context@details@Concurrency@@SA?AV123@XZ() msvcr120.?_CurrentContext@_Context@details@Concurrency@@SA?AV123@XZ @ stub ?_Current_node@location@Concurrency@@SA?AV12@XZ @ stub -arch=arm ?_Destroy@_AsyncTaskCollection@details@Concurrency@@EAAXXZ @ stub -arch=i386 ?_Destroy@_AsyncTaskCollection@details@Concurrency@@EAEXXZ diff --git a/dlls/msvcrt/scheduler.c b/dlls/msvcrt/scheduler.c index 59e177b5aec..0701839a9dc 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@_Context@details@Concurrency@@SA?AV123@XZ */ +_Context *__cdecl _Context__CurrentContext(_Context *ret) +{ + TRACE("(%p)\n", ret); + ret->context = Context_CurrentContext(); + return ret; +} +#endif + DEFINE_THISCALL_WRAPPER(ExternalContextBase_GetId, 4) unsigned int __thiscall ExternalContextBase_GetId(const ExternalContextBase *this) {