Arkadiusz Hiler : msvcirt: Implement _mtlock() and _mtunlock().

Alexandre Julliard julliard at winehq.org
Tue Mar 23 15:07:44 CDT 2021


Module: wine
Branch: oldstable
Commit: 27d20384c875cb1c8ab5a0ba21ba8701a77bb84f
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=27d20384c875cb1c8ab5a0ba21ba8701a77bb84f

Author: Arkadiusz Hiler <ahiler at 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 at codeweavers.com>
Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
(cherry picked from commit d25e7429ccd7ddd30cdfc29cd565b9160e90101d)
Signed-off-by: Michael Stefaniuc <mstefani at 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 8663181c99d..dfebe495e62 100644
--- a/dlls/msvcirt/msvcirt.c
+++ b/dlls/msvcirt/msvcirt.c
@@ -4678,6 +4678,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 75ae312b486..77a8f9477ef 100644
--- a/dlls/msvcirt/msvcirt.spec
+++ b/dlls/msvcirt/msvcirt.spec
@@ -786,5 +786,5 @@
 @ thiscall -arch=win32 ?xsputn at streambuf@@UAEHPBDH at Z(ptr ptr long) streambuf_xsputn
 @ cdecl -arch=win64 ?xsputn at streambuf@@UEAAHPEBDH at 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 12a2c7bc0f0..69b8728ddb6 100644
--- a/dlls/msvcirt/tests/msvcirt.c
+++ b/dlls/msvcirt/tests/msvcirt.c
@@ -446,6 +446,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;
@@ -1002,6 +1006,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;
 }
@@ -7763,6 +7770,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())
@@ -7790,6 +7838,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 1f0e5b70ae8..afa6f3b56f6 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 ef18eb672da..695144d3a5d 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




More information about the wine-cvs mailing list