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

svn path=/trunk/; revision=38960
This commit is contained in:
Stefan Ginsberg 2009-01-19 23:22:22 +00:00
parent ec8a8e45f6
commit dc7184e73f
12 changed files with 12 additions and 27 deletions

View file

@ -231,7 +231,7 @@ KdPortInitialize(
return FALSE; return FALSE;
/* set global info */ /* set global info */
*KdComPortInUse = (PUCHAR)DefaultPort.BaseAddress; KdComPortInUse = (PUCHAR)DefaultPort.BaseAddress;
return TRUE; return TRUE;
} }

View file

@ -402,7 +402,7 @@ AcpiCheckIfIsSerialDebugPort(
case io: case io:
{ {
IO_RESOURCE *io_data = (IO_RESOURCE*) &resource->data; 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); ExFreePool(Buffer.pointer);
return TRUE; return TRUE;

View file

@ -223,7 +223,8 @@ SerialPnpStartDevice(
ComPortBase = ULongToPtr(DeviceExtension->BaseAddress); ComPortBase = ULongToPtr(DeviceExtension->BaseAddress);
/* Test if we are trying to start the serial port used for debugging */ /* 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"); INFO_(SERIAL, "Failing IRP_MN_START_DEVICE as this serial port is used for debugging\n");
return STATUS_INSUFFICIENT_RESOURCES; return STATUS_INSUFFICIENT_RESOURCES;

View file

@ -27,7 +27,7 @@
/* DATA **********************************************************************/ /* DATA **********************************************************************/
ULONG _KdComPortInUse = 0; PUCHAR KdComPortInUse;
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/

View file

@ -78,7 +78,7 @@
@ stdcall IoSetPartitionInformation(ptr long long long) HalpSetPartitionInformation @ stdcall IoSetPartitionInformation(ptr long long long) HalpSetPartitionInformation
@ stdcall IoWritePartitionTable(ptr long long long ptr) HalpWritePartitionTable @ stdcall IoWritePartitionTable(ptr long long long ptr) HalpWritePartitionTable
@ stdcall KeAcquireSpinLock(ptr ptr) @ stdcall KeAcquireSpinLock(ptr ptr)
@ extern KdComPortInUse _KdComPortInUse @ extern KdComPortInUse
@ stdcall KeFlushWriteBuffer() @ stdcall KeFlushWriteBuffer()
@ stdcall KeGetCurrentIrql() @ stdcall KeGetCurrentIrql()
@ stdcall KeLowerIrql(long) @ stdcall KeLowerIrql(long)

View file

@ -27,7 +27,7 @@
/* DATA **********************************************************************/ /* DATA **********************************************************************/
ULONG HalpCurrentTimeIncrement, HalpNextTimeIncrement, HalpNextIntervalCount; ULONG HalpCurrentTimeIncrement, HalpNextTimeIncrement, HalpNextIntervalCount;
ULONG _KdComPortInUse = 0; PUCHAR KdComPortInUse;
ULONG HalpIrqlTable[HIGH_LEVEL + 1] = ULONG HalpIrqlTable[HIGH_LEVEL + 1] =
{ {

View file

@ -14,9 +14,4 @@
#include <peripherals/pl190.h> #include <peripherals/pl190.h>
#include <peripherals/sp804.h> #include <peripherals/sp804.h>
//
// WDK Hack
//
#define KdComPortInUse _KdComPortInUse
#endif /* __INTERNAL_HAL_HAL_H */ #endif /* __INTERNAL_HAL_HAL_H */

View file

@ -12,8 +12,7 @@
#define NDEBUG #define NDEBUG
#include <debug.h> #include <debug.h>
#define KdComPortInUse _KdComPortInUse PUCHAR KdComPortInUse;
ULONG KdComPortInUse = 0;
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/

View file

@ -8,9 +8,6 @@
/* Temporary hack */ /* Temporary hack */
#define KPCR_BASE 0xFF000000 #define KPCR_BASE 0xFF000000
/* WDK Hack */
#define KdComPortInUse _KdComPortInUse
#define HAL_APC_REQUEST 0 #define HAL_APC_REQUEST 0
#define HAL_DPC_REQUEST 1 #define HAL_DPC_REQUEST 1

View file

@ -12,12 +12,7 @@
#define NDEBUG #define NDEBUG
#include <debug.h> #include <debug.h>
#ifdef __GNUC__ PUCHAR KdComPortInUse;
static PUCHAR realKdComPortInUse = 0;
PUCHAR *_KdComPortInUse = &realKdComPortInUse;
#else
PUCHAR _KdComPortInUse = 0;
#endif
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/

View file

@ -223,9 +223,7 @@ extern NTSYSAPI HAL_PRIVATE_DISPATCH HalPrivateDispatchTable;
// //
// HAL Exports // HAL Exports
// //
#ifndef _NTHAL_ extern PUCHAR NTHALAPI KdComPortInUse;
extern NTHALAPI PUCHAR *KdComPortInUse;
#endif
#endif #endif
#endif #endif

View file

@ -97,7 +97,7 @@ KdpInitDebugLog(PKD_DISPATCH_TABLE DispatchTable,
if (BootPhase == 0) if (BootPhase == 0)
{ {
*KdComPortInUse = NULL; KdComPortInUse = NULL;
/* Write out the functions that we support for now */ /* Write out the functions that we support for now */
DispatchTable->KdpInitRoutine = KdpInitDebugLog; DispatchTable->KdpInitRoutine = KdpInitDebugLog;
@ -182,7 +182,7 @@ KdpSerialInit(PKD_DISPATCH_TABLE DispatchTable,
KdpDebugMode.Serial = FALSE; KdpDebugMode.Serial = FALSE;
return; return;
} }
*KdComPortInUse = (PUCHAR)(ULONG_PTR)SerialPortInfo.BaseAddress; KdComPortInUse = (PUCHAR)(ULONG_PTR)SerialPortInfo.BaseAddress;
/* Register as a Provider */ /* Register as a Provider */
InsertTailList(&KdProviders, &DispatchTable->KdProvidersList); InsertTailList(&KdProviders, &DispatchTable->KdProvidersList);