[1/4] msvcirt: Implement ios static locking (try 4)
Iván Matellanes
matellanesivan at gmail.com
Thu Jul 16 05:29:20 CDT 2015
Try 4: use extern in critical section declaration
---
dlls/msvcirt/msvcirt.c | 24 ++++++++++++++++++++++--
dlls/msvcirt/msvcirt.spec | 2 +-
dlls/msvcirt/tests/msvcirt.c | 19 +++++++++++++++++--
dlls/msvcrt20/msvcrt20.spec | 2 +-
dlls/msvcrt40/msvcrt40.spec | 2 +-
5 files changed, 42 insertions(+), 7 deletions(-)
diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c
index 9c6b991..401e750 100644
--- a/dlls/msvcirt/msvcirt.c
+++ b/dlls/msvcirt/msvcirt.c
@@ -31,6 +31,16 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcirt);
#define RESERVE_SIZE 512
+/* ?x_lockc at ios@@0U_CRT_CRITICAL_SECTION@@A */
+extern CRITICAL_SECTION ios_static_lock;
+CRITICAL_SECTION_DEBUG ios_static_lock_debug =
+{
+ 0, 0, &ios_static_lock,
+ { &ios_static_lock_debug.ProcessLocksList, &ios_static_lock_debug.ProcessLocksList },
+ 0, 0, { (DWORD_PTR)(__FILE__ ": ios_static_lock") }
+};
+CRITICAL_SECTION ios_static_lock = { &ios_static_lock_debug, -1, 0, 0, 0, 0 };
+
/* class streambuf */
typedef struct {
const vtable_ptr *vtable;
@@ -1001,7 +1011,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 */
@@ -1138,7 +1149,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 */
@@ -1324,6 +1336,11 @@ static void init_io(void *base)
#endif
}
+static void free_io(void)
+{
+ DeleteCriticalSection(&ios_static_lock);
+}
+
BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
{
switch (reason)
@@ -1336,6 +1353,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 944c024..523fb45 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;
}
@@ -962,6 +971,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);
@@ -970,9 +981,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;
@@ -981,6 +995,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