[Wine-patches] [eterhack] parport fixes

Alexander Morozov amorozov на etersoft.ru
Ср Дек 29 18:01:37 MSK 2010


----------- следующая часть -----------
From ceed0a5fa40c1f7315a98b9668ca225baf9799e5 Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov на etersoft.ru>
Date: Wed, 29 Dec 2010 16:25:30 +0300
Subject: [eterhack 1/3] ntoskrnl.exe: Synchronization is not needed in this case.

---
 dlls/ntoskrnl.exe/instr.c |   33 ++++++++++-----------------------
 1 files changed, 10 insertions(+), 23 deletions(-)

diff --git a/dlls/ntoskrnl.exe/instr.c b/dlls/ntoskrnl.exe/instr.c
index f20663f..773522f 100644
--- a/dlls/ntoskrnl.exe/instr.c
+++ b/dlls/ntoskrnl.exe/instr.c
@@ -39,16 +39,6 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(int);
 
-static CRITICAL_SECTION pp_section;
-static CRITICAL_SECTION_DEBUG critsect_debug =
-{
-    0, 0, &pp_section,
-    { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
-      0, 0, { (DWORD_PTR)(__FILE__ ": pp_section") }
-};
-static CRITICAL_SECTION pp_section = { &critsect_debug, -1, 0, 0, 0, 0 };
-
-static int parport_flag;
 static UCHAR (CDECL *pp_read)( UCHAR* );
 static void (CDECL *pp_write)( UCHAR*, UCHAR );
 
@@ -277,20 +267,13 @@ static void init_parport(void)
 {
     static const WCHAR parportW[] = {'p','a','r','p','o','r','t','.','s','y','s',0};
 
-    static HMODULE parport;
+    HMODULE parport = GetModuleHandleW( parportW );
 
-    RtlEnterCriticalSection( &pp_section );
-    if (!parport_flag)
+    if (parport)
     {
-        parport = GetModuleHandleW( parportW );
-        if (parport)
-        {
-            pp_read = (void *)GetProcAddress( parport, "__wine_read_parport" );
-            pp_write = (void *)GetProcAddress( parport, "__wine_write_parport" );
-        }
-        parport_flag = 1;
+        pp_read = (void *)GetProcAddress( parport, "__wine_read_parport" );
+        pp_write = (void *)GetProcAddress( parport, "__wine_write_parport" );
     }
-    RtlLeaveCriticalSection( &pp_section );
 }
 
 
@@ -301,13 +284,14 @@ static void init_parport(void)
  */
 static DWORD INSTR_inport( WORD port, int size )
 {
-    if (!parport_flag) init_parport();
     if (size == 1)
     {
         DEFETER_FUNC( etersoft_read_port );
         LOADETER_FUNC( etersoft_read_port );
         if (etersoft_read_port)
             return etersoft_read_port( (UCHAR *)(int)port );
+        if (!pp_read)
+            init_parport();
         if (pp_read)
             return pp_read( (UCHAR *)(int)port );
     }
@@ -322,7 +306,6 @@ static DWORD INSTR_inport( WORD port, int size )
  */
 static void INSTR_outport( WORD port, int size, DWORD val )
 {
-    if (!parport_flag) init_parport();
     if (size == 1)
     {
         DEFETER_FUNC( etersoft_write_port );
@@ -330,8 +313,12 @@ static void INSTR_outport( WORD port, int size, DWORD val )
         if (etersoft_write_port)
             etersoft_write_port( (UCHAR *)(int)port, val );
         else
+        {
+            if (!pp_write)
+                init_parport();
             if (pp_write)
                 pp_write( (UCHAR *)(int)port, val );
+        }
     }
 }
 
-- 
1.7.3.4

----------- следующая часть -----------
From 780588f35a5d87f093e7383c99c3879f1e1c6772 Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov на etersoft.ru>
Date: Wed, 29 Dec 2010 16:35:55 +0300
Subject: [eterhack 2/3] hal: Load parport functions dynamically.

---
 dlls/hal/Makefile.in |    1 -
 dlls/hal/hal.c       |   31 +++++++++++++++++++++++++++++--
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/dlls/hal/Makefile.in b/dlls/hal/Makefile.in
index 5e1f9e2..7db7a5c 100644
--- a/dlls/hal/Makefile.in
+++ b/dlls/hal/Makefile.in
@@ -1,5 +1,4 @@
 MODULE    = hal.dll
-IMPORTS   = parport.sys
 
 C_SRCS = \
 	hal.c
diff --git a/dlls/hal/hal.c b/dlls/hal/hal.c
index 3bc02ed..d12fe5d 100644
--- a/dlls/hal/hal.c
+++ b/dlls/hal/hal.c
@@ -31,6 +31,7 @@
 #define WIN32_NO_STATUS
 #include "windef.h"
 #include "winternl.h"
+#include "winbase.h"
 #include "excpt.h"
 #include "ddk/ntddk.h"
 #include "wine/debug.h"
@@ -57,6 +58,9 @@ WINE_DEFAULT_DEBUG_CHANNEL(ntoskrnl);
 extern UCHAR CDECL __wine_read_parport( UCHAR *port );
 extern void CDECL __wine_write_parport( UCHAR *port, UCHAR value );
 
+static UCHAR (CDECL *pp_read)( UCHAR* );
+static void (CDECL *pp_write)( UCHAR*, UCHAR );
+
 #ifdef DEFINE_FASTCALL1_ENTRYPOINT
 DEFINE_FASTCALL1_ENTRYPOINT( ExAcquireFastMutex )
 VOID WINAPI __regs_ExAcquireFastMutex(PFAST_MUTEX FastMutex)
@@ -191,14 +195,37 @@ void WINAPI KeStallExecutionProcessor(ULONG MicroSeconds)
     nanosleep( &ts, NULL );
 }
 
+static void init_parport(void)
+{
+    static const WCHAR parportW[] = {'p','a','r','p','o','r','t','.','s','y','s',0};
+
+    HMODULE parport = GetModuleHandleW( parportW );
+
+    if (parport)
+    {
+        pp_read = (void *)GetProcAddress( parport, "__wine_read_parport" );
+        pp_write = (void *)GetProcAddress( parport, "__wine_write_parport" );
+    }
+}
+
 UCHAR WINAPI READ_PORT_UCHAR(PUCHAR Port)
 {
     TRACE( "(%p)\n", Port );
-    return __wine_read_parport( Port );
+
+    if (!pp_read)
+        init_parport();
+    if (pp_read)
+        return pp_read( Port );
+    else
+        return 0xff;
 }
 
 void WINAPI WRITE_PORT_UCHAR(PUCHAR Port, UCHAR Value)
 {
     TRACE( "(%p %u)\n", Port, Value );
-    __wine_write_parport( Port, Value );
+
+    if (!pp_write)
+        init_parport();
+    if (pp_write)
+        pp_write( Port, Value );
 }
-- 
1.7.3.4

----------- следующая часть -----------
From 9f54fb879e9de8039cf06668a188f76703a7d5dd Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov на etersoft.ru>
Date: Wed, 29 Dec 2010 16:46:25 +0300
Subject: [eterhack 3/3] Print an error if failed to load parport functions.

---
 dlls/hal/hal.c            |    2 ++
 dlls/ntoskrnl.exe/instr.c |    2 ++
 2 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/dlls/hal/hal.c b/dlls/hal/hal.c
index d12fe5d..6ef1a67 100644
--- a/dlls/hal/hal.c
+++ b/dlls/hal/hal.c
@@ -206,6 +206,8 @@ static void init_parport(void)
         pp_read = (void *)GetProcAddress( parport, "__wine_read_parport" );
         pp_write = (void *)GetProcAddress( parport, "__wine_write_parport" );
     }
+    if (!pp_read || !pp_write)
+        ERR( "failed to load parport functions\n" );
 }
 
 UCHAR WINAPI READ_PORT_UCHAR(PUCHAR Port)
diff --git a/dlls/ntoskrnl.exe/instr.c b/dlls/ntoskrnl.exe/instr.c
index 773522f..9caf529 100644
--- a/dlls/ntoskrnl.exe/instr.c
+++ b/dlls/ntoskrnl.exe/instr.c
@@ -274,6 +274,8 @@ static void init_parport(void)
         pp_read = (void *)GetProcAddress( parport, "__wine_read_parport" );
         pp_write = (void *)GetProcAddress( parport, "__wine_write_parport" );
     }
+    if (!pp_read || !pp_write)
+        ERR( "failed to load parport functions\n" );
 }
 
 
-- 
1.7.3.4



Подробная информация о списке рассылки Wine-patches