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>
This commit is contained in:
Arkadiusz Hiler 2020-09-04 17:16:19 +03:00 committed by Alexandre Julliard
parent e7b8911695
commit d25e7429cc
5 changed files with 67 additions and 6 deletions

View file

@ -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");

View file

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

View file

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

View file

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

View file

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