[4/4] msvcirt: Implement ios static locking
Iván Matellanes
matellanesivan at gmail.com
Tue Jul 7 14:00:48 CDT 2015
---
dlls/msvcirt/msvcirt.c | 18 ++++++++++++++++--
dlls/msvcirt/msvcirt.spec | 2 +-
dlls/msvcirt/tests/msvcirt.c | 19 +++++++++++++++++--
dlls/msvcrt20/msvcrt20.spec | 2 +-
dlls/msvcrt40/msvcrt40.spec | 2 +-
5 files changed, 36 insertions(+), 7 deletions(-)
diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c
index 92ae0f8..38e5f66 100644
--- a/dlls/msvcirt/msvcirt.c
+++ b/dlls/msvcirt/msvcirt.c
@@ -31,6 +31,9 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcirt);
#define RESERVE_SIZE 512
+/* ?x_lockc at ios@@0U_CRT_CRITICAL_SECTION@@A */
+CRITICAL_SECTION ios_static_lock;
+
/* class streambuf */
typedef struct {
const vtable_ptr *vtable;
@@ -997,7 +1000,8 @@ void __cdecl ios_lockbuf(ios *this)
/* ?lockc at ios@@KAXXZ */
void __cdecl ios_lockc(void)
{
- FIXME("() stub\n");
+ TRACE("()\n");
+ EnterCriticalSection(&ios_static_lock);
}
/* ?lockptr at ios@@IAEPAU_CRT_CRITICAL_SECTION@@XZ */
@@ -1132,7 +1136,8 @@ void __cdecl ios_unlockbuf(ios *this)
/* ?unlockc at ios@@KAXXZ */
void __cdecl ios_unlockc(void)
{
- FIXME("() stub\n");
+ TRACE("()\n");
+ LeaveCriticalSection(&ios_static_lock);
}
/* ?unsetf at ios@@QAEJJ at Z */
@@ -1316,6 +1321,12 @@ static void init_io(void *base)
init_streambuf_rtti(base);
init_ios_rtti(base);
#endif
+ InitializeCriticalSection(&ios_static_lock);
+}
+
+static void free_io(void)
+{
+ DeleteCriticalSection(&ios_static_lock);
}
BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
@@ -1330,6 +1341,9 @@ BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
init_io(inst);
DisableThreadLibraryCalls( inst );
break;
+ case DLL_PROCESS_DETACH:
+ free_io();
+ break;
}
return TRUE;
}
diff --git a/dlls/msvcirt/msvcirt.spec b/dlls/msvcirt/msvcirt.spec
index dc66bfa..8d26652 100644
--- a/dlls/msvcirt/msvcirt.spec
+++ b/dlls/msvcirt/msvcirt.spec
@@ -777,7 +777,7 @@
@ stub -arch=win32 ?ws@@YAAAVistream@@AAV1@@Z # class istream & __cdecl ws(class istream &)
@ stub -arch=win64 ?ws@@YAAEAVistream@@AEAV1@@Z
# @ extern ?x_curindex at ios@@0HA # static int ios::x_curindex
-# @ extern ?x_lockc at ios@@0U_CRT_CRITICAL_SECTION@@A # static struct _CRT_CRITICAL_SECTION ios::x_lockc
+@ extern ?x_lockc at ios@@0U_CRT_CRITICAL_SECTION@@A ios_static_lock
# @ extern ?x_maxbit at ios@@0JA # static long ios::x_maxbit
# @ extern ?x_statebuf at ios@@0PAJA # static long * ios::x_statebuf
@ cdecl ?xalloc at ios@@SAHXZ() ios_xalloc
diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c
index b748965..76d3776 100644
--- a/dlls/msvcirt/tests/msvcirt.c
+++ b/dlls/msvcirt/tests/msvcirt.c
@@ -134,6 +134,9 @@ static void (*__cdecl p_ios_lock)(ios*);
static void (*__cdecl p_ios_unlock)(ios*);
static void (*__cdecl p_ios_lockbuf)(ios*);
static void (*__cdecl p_ios_unlockbuf)(ios*);
+static CRITICAL_SECTION *p_ios_static_lock;
+static void (*__cdecl p_ios_lockc)(void);
+static void (*__cdecl p_ios_unlockc)(void);
/* Emulate a __thiscall */
#ifdef __i386__
@@ -281,6 +284,9 @@ static BOOL init(void)
SET(p_ios_lockbuf, "?lockbuf at ios@@QAAXXZ");
SET(p_ios_unlockbuf, "?unlockbuf at ios@@QAAXXZ");
}
+ SET(p_ios_static_lock, "?x_lockc at ios@@0U_CRT_CRITICAL_SECTION@@A");
+ SET(p_ios_lockc, "?lockc at ios@@KAXXZ");
+ SET(p_ios_unlockc, "?unlockc at ios@@KAXXZ");
init_thiscall_thunk();
return TRUE;
@@ -827,7 +833,7 @@ struct ios_lock_arg
{
ios *ios_obj;
HANDLE lock;
- HANDLE release[2];
+ HANDLE release[3];
};
static DWORD WINAPI lock_ios(void *arg)
@@ -835,10 +841,13 @@ static DWORD WINAPI lock_ios(void *arg)
struct ios_lock_arg *lock_arg = arg;
p_ios_lock(lock_arg->ios_obj);
p_ios_lockbuf(lock_arg->ios_obj);
+ p_ios_lockc();
SetEvent(lock_arg->lock);
WaitForSingleObject(lock_arg->release[0], INFINITE);
- p_ios_unlockbuf(lock_arg->ios_obj);
+ p_ios_unlockc();
WaitForSingleObject(lock_arg->release[1], INFINITE);
+ p_ios_unlockbuf(lock_arg->ios_obj);
+ WaitForSingleObject(lock_arg->release[2], INFINITE);
p_ios_unlock(lock_arg->ios_obj);
return 0;
}
@@ -960,6 +969,8 @@ static void test_ios(void)
ok(lock_arg.release[0] != NULL, "CreateEventW failed\n");
lock_arg.release[1] = CreateEventW(NULL, FALSE, FALSE, NULL);
ok(lock_arg.release[1] != NULL, "CreateEventW failed\n");
+ lock_arg.release[2] = CreateEventW(NULL, FALSE, FALSE, NULL);
+ ok(lock_arg.release[2] != NULL, "CreateEventW failed\n");
thread = CreateThread(NULL, 0, lock_ios, (void*)&lock_arg, 0, NULL);
ok(thread != NULL, "CreateThread failed\n");
WaitForSingleObject(lock_arg.lock, INFINITE);
@@ -968,9 +979,12 @@ static void test_ios(void)
ok(locked == 0, "the ios object was not locked before\n");
locked = TryEnterCriticalSection(&ios_obj.sb->lock);
ok(locked == 0, "the streambuf was not locked before\n");
+ locked = TryEnterCriticalSection(p_ios_static_lock);
+ ok(locked == 0, "the static critical section was not locked before\n");
SetEvent(lock_arg.release[0]);
SetEvent(lock_arg.release[1]);
+ SetEvent(lock_arg.release[2]);
WaitForSingleObject(thread, INFINITE);
ios_obj.delbuf = 1;
@@ -979,6 +993,7 @@ static void test_ios(void)
CloseHandle(lock_arg.lock);
CloseHandle(lock_arg.release[0]);
CloseHandle(lock_arg.release[1]);
+ CloseHandle(lock_arg.release[2]);
CloseHandle(thread);
}
diff --git a/dlls/msvcrt20/msvcrt20.spec b/dlls/msvcrt20/msvcrt20.spec
index 13b965c..b76b1d0 100644
--- a/dlls/msvcrt20/msvcrt20.spec
+++ b/dlls/msvcrt20/msvcrt20.spec
@@ -765,7 +765,7 @@
@ stub -arch=win32 ?ws@@YAAAVistream@@AAV1@@Z
@ stub -arch=win64 ?ws@@YAAEAVistream@@AEAV1@@Z
# @ extern ?x_curindex at ios@@0HA
-# @ extern ?x_lockc at ios@@0U_RTL_CRITICAL_SECTION@@A
+@ extern ?x_lockc at ios@@0U_CRT_CRITICAL_SECTION@@A msvcirt.?x_lockc at ios@@0U_CRT_CRITICAL_SECTION@@A
# @ extern ?x_maxbit at ios@@0JA
# @ extern ?x_statebuf at ios@@0QAJA
@ cdecl ?xalloc at ios@@SAHXZ() msvcirt.?xalloc at ios@@SAHXZ
diff --git a/dlls/msvcrt40/msvcrt40.spec b/dlls/msvcrt40/msvcrt40.spec
index 924cd02..cfe2fea 100644
--- a/dlls/msvcrt40/msvcrt40.spec
+++ b/dlls/msvcrt40/msvcrt40.spec
@@ -839,7 +839,7 @@
@ stub -arch=win32 ?ws@@YAAAVistream@@AAV1@@Z
@ stub -arch=win64 ?ws@@YAAEAVistream@@AEAV1@@Z
# @ extern ?x_curindex at ios@@0HA
-# @ extern ?x_lockc at ios@@0U_CRT_CRITICAL_SECTION@@A
+@ extern ?x_lockc at ios@@0U_CRT_CRITICAL_SECTION@@A msvcirt.?x_lockc at ios@@0U_CRT_CRITICAL_SECTION@@A
# @ extern ?x_maxbit at ios@@0JA
# @ extern ?x_statebuf at ios@@0PAJA
@ cdecl ?xalloc at ios@@SAHXZ() msvcirt.?xalloc at ios@@SAHXZ
--
2.1.4
More information about the wine-patches
mailing list