qxl-wddm-dod/qxldod/compat.cpp
Frediano Ziglio de8062e7b6 Use MmMapIoSpaceEx instead of MmMapIoSpace
Disable execution bit on mapping improving security.

MmMapIoSpaceEx is available only in Windows 10 so
to provide binary compatibility detect the new
function dynamically.
Added a separate compatibility file.

Based on a patch by Sandy Stutsman <sstutsma@redhat.com>

Signed-off-by: Sameeh Jubran <sameeh@daynix.com>
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2016-10-19 17:39:42 +01:00

63 lines
1.7 KiB
C++

#include "driver.h"
#include "compat.h"
static MapIoSpaceFunc DetectMapIoSpace;
MapIoSpaceFunc *MapIoSpace = DetectMapIoSpace;
typedef NTKERNELAPI PVOID MmMapIoSpaceExFunc(
_In_ PHYSICAL_ADDRESS PhysicalAddress,
_In_ SIZE_T NumberOfBytes,
_In_ ULONG Protect
);
static MmMapIoSpaceExFunc *pMmMapIoSpaceEx;
// all functions in this module are paged
#pragma code_seg("PAGE")
// we call MmMapIoSpace only if MmMapIoSpaceEx is not present
// so disable the warning
#pragma warning(push)
#pragma warning(disable:30029)
static PVOID OldMapIoSpace(
_In_ PHYSICAL_ADDRESS PhysicalAddress,
_In_ SIZE_T NumberOfBytes,
_In_ MEMORY_CACHING_TYPE CacheType,
_In_ ULONG Protect
)
{
PAGED_CODE();
return MmMapIoSpace(PhysicalAddress, NumberOfBytes, CacheType);
}
#pragma warning(pop)
static PVOID NewMapIoSpace(
_In_ PHYSICAL_ADDRESS PhysicalAddress,
_In_ SIZE_T NumberOfBytes,
_In_ MEMORY_CACHING_TYPE CacheType,
_In_ ULONG Protect
)
{
PAGED_CODE();
return pMmMapIoSpaceEx(PhysicalAddress, NumberOfBytes, Protect);
}
static PVOID DetectMapIoSpace(
_In_ PHYSICAL_ADDRESS PhysicalAddress,
_In_ SIZE_T NumberOfBytes,
_In_ MEMORY_CACHING_TYPE CacheType,
_In_ ULONG Protect
)
{
PAGED_CODE();
UNICODE_STRING name;
RtlInitUnicodeString(&name, L"MmMapIoSpaceEx");
pMmMapIoSpaceEx = (MmMapIoSpaceExFunc*)MmGetSystemRoutineAddress(&name);
if (pMmMapIoSpaceEx) {
MapIoSpace = NewMapIoSpace;
} else {
MapIoSpace = OldMapIoSpace;
}
return MapIoSpace(PhysicalAddress, NumberOfBytes, CacheType, Protect);
}