[ros-diffs] [sginsberg] 38960: Fix the completely retarded implementation of KdComPortInUse. The original definition of this variable seems to have been based on the retarded type in the serial.sys source sample, which defines it as: extern PUCHAR *KdComPortInUse; This, somehow, works in MSVC, but gcc complains about the lack of import specifier (KdComPortInUse is exported by HAL). This was 'fixed' by adding the import specifier to ros. So instead of: PUCHAR *KdComPortInUse; We ended up with: NTHALAPI PUCHAR *KdComPortInUse; Which becomes 3 dereferences instead of 2, which is incorrect. This was 'fixed' by hacking the variable in HAL too. Use "extern PUCHAR NTHALAPI KdComPortInUse" to be compatible with both compilers, remove the HAL hacks, and fix the usage of the variable. Fixes the serial.sys crash when booted with _WINKD_ + kdcom from Windows 2003, as kdcom would (due to the HAL hack) set the internal 'pointer' to the port value, and serial would end up dereferencing the port address

sginsberg at svn.reactos.org sginsberg at svn.reactos.org
Tue Jan 20 00:22:22 CET 2009


Author: sginsberg
Date: Mon Jan 19 17:22:22 2009
New Revision: 38960

URL: http://svn.reactos.org/svn/reactos?rev=38960&view=rev
Log:
Fix the completely retarded implementation of KdComPortInUse.
The original definition of this variable seems to have been based on the retarded type in the serial.sys source sample, which defines it as:

extern PUCHAR *KdComPortInUse;

This, somehow, works in MSVC, but gcc complains about the lack of import specifier (KdComPortInUse is exported by HAL).
This was 'fixed' by adding the import specifier to ros.
So instead of: PUCHAR *KdComPortInUse;
We ended up with: NTHALAPI PUCHAR *KdComPortInUse;
Which becomes 3 dereferences instead of 2, which is incorrect. This was 'fixed' by hacking the variable in HAL too.
Use "extern PUCHAR NTHALAPI KdComPortInUse" to be compatible with both compilers, remove the HAL hacks, and fix the usage of the variable.

Fixes the serial.sys crash when booted with _WINKD_ + kdcom from Windows 2003, as kdcom would (due to the HAL hack) set the internal 'pointer' to the port value, and serial would end up dereferencing the port address

Modified:
    trunk/reactos/drivers/base/kdcom/i386/kdbg.c
    trunk/reactos/drivers/bus/acpi/ospm/fdo.c
    trunk/reactos/drivers/serial/serial/pnp.c
    trunk/reactos/hal/hal/hal.c
    trunk/reactos/hal/hal/hal.pspec
    trunk/reactos/hal/halarm/generic/hal.c
    trunk/reactos/hal/halarm/include/halp.h
    trunk/reactos/hal/halppc/generic/sysinfo.c
    trunk/reactos/hal/halppc/include/halp.h
    trunk/reactos/hal/halx86/generic/sysinfo.c
    trunk/reactos/include/ndk/haltypes.h
    trunk/reactos/ntoskrnl/kd/kdio.c

Modified: trunk/reactos/drivers/base/kdcom/i386/kdbg.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/base/kdcom/i386/kdbg.c?rev=38960&r1=38959&r2=38960&view=diff
==============================================================================
--- trunk/reactos/drivers/base/kdcom/i386/kdbg.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/base/kdcom/i386/kdbg.c [iso-8859-1] Mon Jan 19 17:22:22 2009
@@ -231,7 +231,7 @@
         return FALSE;
 
     /* set global info */
-    *KdComPortInUse = (PUCHAR)DefaultPort.BaseAddress;
+    KdComPortInUse = (PUCHAR)DefaultPort.BaseAddress;
 
     return TRUE;
 }

Modified: trunk/reactos/drivers/bus/acpi/ospm/fdo.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/bus/acpi/ospm/fdo.c?rev=38960&r1=38959&r2=38960&view=diff
==============================================================================
--- trunk/reactos/drivers/bus/acpi/ospm/fdo.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/bus/acpi/ospm/fdo.c [iso-8859-1] Mon Jan 19 17:22:22 2009
@@ -402,7 +402,7 @@
       case io:
       {
         IO_RESOURCE *io_data = (IO_RESOURCE*) &resource->data;
-        if (*KdComPortInUse == ULongToPtr(io_data->min_base_address))
+        if (KdComPortInUse == (PUCHAR)io_data->min_base_address)
         {
           ExFreePool(Buffer.pointer);
           return TRUE;

Modified: trunk/reactos/drivers/serial/serial/pnp.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/serial/serial/pnp.c?rev=38960&r1=38959&r2=38960&view=diff
==============================================================================
--- trunk/reactos/drivers/serial/serial/pnp.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/serial/serial/pnp.c [iso-8859-1] Mon Jan 19 17:22:22 2009
@@ -223,7 +223,8 @@
 	ComPortBase = ULongToPtr(DeviceExtension->BaseAddress);
 
 	/* Test if we are trying to start the serial port used for debugging */
-	if (*KdComPortInUse == ULongToPtr(DeviceExtension->BaseAddress))
+    DPRINT1("Comparing addresses: KdComPortInUse: %p, ComPortBase: %p\n", KdComPortInUse, ComPortBase);
+	if (KdComPortInUse == ComPortBase)
 	{
 		INFO_(SERIAL, "Failing IRP_MN_START_DEVICE as this serial port is used for debugging\n");
 		return STATUS_INSUFFICIENT_RESOURCES;

Modified: trunk/reactos/hal/hal/hal.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/hal/hal/hal.c?rev=38960&r1=38959&r2=38960&view=diff
==============================================================================
--- trunk/reactos/hal/hal/hal.c [iso-8859-1] (original)
+++ trunk/reactos/hal/hal/hal.c [iso-8859-1] Mon Jan 19 17:22:22 2009
@@ -27,7 +27,7 @@
 
 /* DATA **********************************************************************/
 
-ULONG _KdComPortInUse = 0;
+PUCHAR KdComPortInUse;
 
 /* FUNCTIONS *****************************************************************/
 

Modified: trunk/reactos/hal/hal/hal.pspec
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/hal/hal/hal.pspec?rev=38960&r1=38959&r2=38960&view=diff
==============================================================================
--- trunk/reactos/hal/hal/hal.pspec [iso-8859-1] (original)
+++ trunk/reactos/hal/hal/hal.pspec [iso-8859-1] Mon Jan 19 17:22:22 2009
@@ -78,7 +78,7 @@
 @ stdcall IoSetPartitionInformation(ptr long long long) HalpSetPartitionInformation
 @ stdcall IoWritePartitionTable(ptr long long long ptr) HalpWritePartitionTable
 @ stdcall KeAcquireSpinLock(ptr ptr)
-@ extern KdComPortInUse _KdComPortInUse
+@ extern KdComPortInUse
 @ stdcall KeFlushWriteBuffer()
 @ stdcall KeGetCurrentIrql()
 @ stdcall KeLowerIrql(long)

Modified: trunk/reactos/hal/halarm/generic/hal.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halarm/generic/hal.c?rev=38960&r1=38959&r2=38960&view=diff
==============================================================================
--- trunk/reactos/hal/halarm/generic/hal.c [iso-8859-1] (original)
+++ trunk/reactos/hal/halarm/generic/hal.c [iso-8859-1] Mon Jan 19 17:22:22 2009
@@ -27,7 +27,7 @@
 /* DATA **********************************************************************/
 
 ULONG HalpCurrentTimeIncrement, HalpNextTimeIncrement, HalpNextIntervalCount;
-ULONG _KdComPortInUse = 0;
+PUCHAR KdComPortInUse;
 
 ULONG HalpIrqlTable[HIGH_LEVEL + 1] =
 {

Modified: trunk/reactos/hal/halarm/include/halp.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halarm/include/halp.h?rev=38960&r1=38959&r2=38960&view=diff
==============================================================================
--- trunk/reactos/hal/halarm/include/halp.h [iso-8859-1] (original)
+++ trunk/reactos/hal/halarm/include/halp.h [iso-8859-1] Mon Jan 19 17:22:22 2009
@@ -14,9 +14,4 @@
 #include <peripherals/pl190.h>
 #include <peripherals/sp804.h>
 
-//
-// WDK Hack
-//
-#define KdComPortInUse          _KdComPortInUse
-
 #endif /* __INTERNAL_HAL_HAL_H */

Modified: trunk/reactos/hal/halppc/generic/sysinfo.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halppc/generic/sysinfo.c?rev=38960&r1=38959&r2=38960&view=diff
==============================================================================
--- trunk/reactos/hal/halppc/generic/sysinfo.c [iso-8859-1] (original)
+++ trunk/reactos/hal/halppc/generic/sysinfo.c [iso-8859-1] Mon Jan 19 17:22:22 2009
@@ -12,8 +12,7 @@
 #define NDEBUG
 #include <debug.h>
 
-#define KdComPortInUse _KdComPortInUse
-ULONG KdComPortInUse = 0;
+PUCHAR KdComPortInUse;
 
 /* FUNCTIONS *****************************************************************/
 

Modified: trunk/reactos/hal/halppc/include/halp.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halppc/include/halp.h?rev=38960&r1=38959&r2=38960&view=diff
==============================================================================
--- trunk/reactos/hal/halppc/include/halp.h [iso-8859-1] (original)
+++ trunk/reactos/hal/halppc/include/halp.h [iso-8859-1] Mon Jan 19 17:22:22 2009
@@ -7,9 +7,6 @@
 
 /* Temporary hack */
 #define KPCR_BASE   0xFF000000
-
-/* WDK Hack */
-#define KdComPortInUse          _KdComPortInUse
 
 #define HAL_APC_REQUEST         0
 #define HAL_DPC_REQUEST         1

Modified: trunk/reactos/hal/halx86/generic/sysinfo.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halx86/generic/sysinfo.c?rev=38960&r1=38959&r2=38960&view=diff
==============================================================================
--- trunk/reactos/hal/halx86/generic/sysinfo.c [iso-8859-1] (original)
+++ trunk/reactos/hal/halx86/generic/sysinfo.c [iso-8859-1] Mon Jan 19 17:22:22 2009
@@ -12,12 +12,7 @@
 #define NDEBUG
 #include <debug.h>
 
-#ifdef __GNUC__
-static PUCHAR realKdComPortInUse = 0;
-PUCHAR *_KdComPortInUse = &realKdComPortInUse;
-#else
-PUCHAR _KdComPortInUse = 0;
-#endif
+PUCHAR KdComPortInUse;
 
 /* FUNCTIONS *****************************************************************/
 

Modified: trunk/reactos/include/ndk/haltypes.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/haltypes.h?rev=38960&r1=38959&r2=38960&view=diff
==============================================================================
--- trunk/reactos/include/ndk/haltypes.h [iso-8859-1] (original)
+++ trunk/reactos/include/ndk/haltypes.h [iso-8859-1] Mon Jan 19 17:22:22 2009
@@ -223,12 +223,10 @@
 //
 // HAL Exports
 //
-#ifndef _NTHAL_
-extern NTHALAPI PUCHAR *KdComPortInUse;
-#endif
-
-#endif
-#endif
-
-
-
+extern PUCHAR NTHALAPI KdComPortInUse;
+
+#endif
+#endif
+
+
+

Modified: trunk/reactos/ntoskrnl/kd/kdio.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/kd/kdio.c?rev=38960&r1=38959&r2=38960&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/kd/kdio.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/kd/kdio.c [iso-8859-1] Mon Jan 19 17:22:22 2009
@@ -97,7 +97,7 @@
 
     if (BootPhase == 0)
     {
-        *KdComPortInUse = NULL;
+        KdComPortInUse = NULL;
 
         /* Write out the functions that we support for now */
         DispatchTable->KdpInitRoutine = KdpInitDebugLog;
@@ -182,7 +182,7 @@
             KdpDebugMode.Serial = FALSE;
             return;
         }
-        *KdComPortInUse = (PUCHAR)(ULONG_PTR)SerialPortInfo.BaseAddress;
+        KdComPortInUse = (PUCHAR)(ULONG_PTR)SerialPortInfo.BaseAddress;
 
         /* Register as a Provider */
         InsertTailList(&KdProviders, &DispatchTable->KdProvidersList);



More information about the Ros-diffs mailing list