Module: wine Branch: master Commit: d25e7429ccd7ddd30cdfc29cd565b9160e90101d URL: https://source.winehq.org/git/wine.git/?a=commit;h=d25e7429ccd7ddd30cdfc29cd...
Author: Arkadiusz Hiler ahiler@codeweavers.com Date: Fri Sep 4 17:16:19 2020 +0300
msvcirt: Implement _mtlock() and _mtunlock().
Looks like they are just cdecl wrappers around stdcall EnterCriticalSection() and LeaveCriticalSection().
The game TRON 2.0 was crashing on the stubs. Now it makes it a bit further.
Signed-off-by: Arkadiusz Hiler ahiler@codeweavers.com Signed-off-by: Piotr Caban piotr@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/msvcirt/msvcirt.c | 12 +++++++++++ dlls/msvcirt/msvcirt.spec | 4 ++-- dlls/msvcirt/tests/msvcirt.c | 49 ++++++++++++++++++++++++++++++++++++++++++++ dlls/msvcrt20/msvcrt20.spec | 4 ++-- dlls/msvcrt40/msvcrt40.spec | 4 ++-- 5 files changed, 67 insertions(+), 6 deletions(-)
diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c index 6bd910e9a8..b5fd19c39e 100644 --- a/dlls/msvcirt/msvcirt.c +++ b/dlls/msvcirt/msvcirt.c @@ -4723,6 +4723,18 @@ DEFINE_VTBL_WRAPPER(56); void* (__cdecl *MSVCRT_operator_new)(SIZE_T); void (__cdecl *MSVCRT_operator_delete)(void*);
+void __cdecl _mtlock(CRITICAL_SECTION *crit) +{ + TRACE("(%p)\n", crit); + EnterCriticalSection(crit); +} + +void __cdecl _mtunlock(CRITICAL_SECTION *crit) +{ + TRACE("(%p)\n", crit); + LeaveCriticalSection(crit); +} + static void init_cxx_funcs(void) { HMODULE hmod = GetModuleHandleA("msvcrt.dll"); diff --git a/dlls/msvcirt/msvcirt.spec b/dlls/msvcirt/msvcirt.spec index c2b4b9d30e..4e8f221b2c 100644 --- a/dlls/msvcirt/msvcirt.spec +++ b/dlls/msvcirt/msvcirt.spec @@ -786,5 +786,5 @@ @ thiscall -arch=win32 ?xsputn@streambuf@@UAEHPBDH@Z(ptr ptr long) streambuf_xsputn @ cdecl -arch=win64 ?xsputn@streambuf@@UEAAHPEBDH@Z(ptr ptr long) streambuf_xsputn @ stub __dummy_export -@ stub _mtlock -@ stub _mtunlock +@ cdecl _mtlock(ptr) +@ cdecl _mtunlock(ptr) diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c index e1a6296783..b87bd42266 100644 --- a/dlls/msvcirt/tests/msvcirt.c +++ b/dlls/msvcirt/tests/msvcirt.c @@ -447,6 +447,10 @@ static const char* (*__thiscall p_exception_what)(exception*); static logic_error* (*__thiscall p_logic_error_ctor)(logic_error*, const char**); static void (*__thiscall p_logic_error_dtor)(logic_error*);
+/* locking */ +static void (*__cdecl p__mtlock)(CRITICAL_SECTION *); +static void (*__cdecl p__mtunlock)(CRITICAL_SECTION *); + /* Predefined streams */ static istream *p_cin; static ostream *p_cout, *p_cerr, *p_clog; @@ -1005,6 +1009,9 @@ static BOOL init(void) SET(p_cerr, "?cerr@@3Vostream_withassign@@A"); SET(p_clog, "?clog@@3Vostream_withassign@@A");
+ SET(p__mtlock, "_mtlock"); + SET(p__mtunlock, "_mtunlock"); + init_thiscall_thunk(); return TRUE; } @@ -7957,6 +7964,47 @@ static void test_exception(void) call_func1(p_logic_error_dtor, (void*) &le); }
+static DWORD WINAPI _try_enter_critical(void *crit) +{ + BOOL ret = TryEnterCriticalSection(crit); + + if (ret) + LeaveCriticalSection(crit); + + return ret; +} + +static void test_mtlock_mtunlock(void) +{ + CRITICAL_SECTION crit; + HANDLE thread; + DWORD exit_code, ret; + + InitializeCriticalSection(&crit); + + p__mtlock(&crit); + + thread = CreateThread(NULL, 0, _try_enter_critical, &crit, 0, NULL); + ok(thread != NULL, "failed to create a thread, error: %x\n", GetLastError()); + ret = WaitForSingleObject(thread, 1000); + ok(ret == WAIT_OBJECT_0, "failed to wait for the thread, ret: %d, error: %x\n", ret, GetLastError()); + ok(GetExitCodeThread(thread, &exit_code), "failed to get exit code of the thread\n"); + ok(exit_code == FALSE, "the thread entered critical section\n"); + ret = CloseHandle(thread); + ok(ret, "failed to close thread's handle, error: %x\n", GetLastError()); + + p__mtunlock(&crit); + + thread = CreateThread(NULL, 0, _try_enter_critical, &crit, 0, NULL); + ok(thread != NULL, "failed to create a thread, error: %x\n", GetLastError()); + ret = WaitForSingleObject(thread, 1000); + ok(ret == WAIT_OBJECT_0, "failed to wait for the thread, ret: %d, error: %x\n", ret, GetLastError()); + ok(GetExitCodeThread(thread, &exit_code), "failed to get exit code of the thread\n"); + ok(exit_code == TRUE, "the thread was not able to enter critical section\n"); + ret = CloseHandle(thread); + ok(ret, "failed to close thread's handle, error: %x\n", GetLastError()); +} + START_TEST(msvcirt) { if(!init()) @@ -7984,6 +8032,7 @@ START_TEST(msvcirt) test_Iostream_init(); test_std_streams(); test_exception(); + test_mtlock_mtunlock();
FreeLibrary(msvcrt); FreeLibrary(msvcirt); diff --git a/dlls/msvcrt20/msvcrt20.spec b/dlls/msvcrt20/msvcrt20.spec index 2ce72c6b13..b791202470 100644 --- a/dlls/msvcrt20/msvcrt20.spec +++ b/dlls/msvcrt20/msvcrt20.spec @@ -1072,8 +1072,8 @@ @ cdecl _mkdir(str) msvcrt._mkdir @ cdecl _mktemp(str) msvcrt._mktemp @ cdecl _msize(ptr) msvcrt._msize -@ stub _mtlock -@ stub _mtunlock +@ cdecl _mtlock(ptr) msvcirt._mtlock +@ cdecl _mtunlock(ptr) msvcirt._mtunlock @ cdecl _nextafter(double double) msvcrt._nextafter @ cdecl _onexit(ptr) msvcrt._onexit @ varargs _open(str long) msvcrt._open diff --git a/dlls/msvcrt40/msvcrt40.spec b/dlls/msvcrt40/msvcrt40.spec index efa3e3251d..3f4f2f90e1 100644 --- a/dlls/msvcrt40/msvcrt40.spec +++ b/dlls/msvcrt40/msvcrt40.spec @@ -1163,8 +1163,8 @@ @ cdecl _mkdir(str) msvcrt._mkdir @ cdecl _mktemp(str) msvcrt._mktemp @ cdecl _msize(ptr) msvcrt._msize -@ stub _mtlock -@ stub _mtunlock +@ cdecl _mtlock(ptr) msvcirt._mtlock +@ cdecl _mtunlock(ptr) msvcirt._mtunlock @ cdecl _nextafter(double double) msvcrt._nextafter @ cdecl _onexit(ptr) msvcrt._onexit @ varargs _open(str long) msvcrt._open