From 04145051ba62227a6e1ccb3a48994f367937b004 Mon Sep 17 00:00:00 2001 From: faust3 Date: Mon, 17 Sep 2007 21:12:29 +0000 Subject: [PATCH] =?UTF-8?q?-=20make=20dhahelperwin=20compile=20with=20ming?= =?UTF-8?q?w=20-=20add=20dhahelper.rc=20based=20on=20code=20by=20Kevin=20K?= =?UTF-8?q?ofler=20and=20Romain=20Li=C3=A9vin=20?= =?UTF-8?q?=20from=20the=20tilp=20project=20http://svn.tilp.info/cgi-bin/v?= =?UTF-8?q?iewcvs.cgi/libticables/trunk/src/win32/dha/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@24561 b3059339-0415-0410-9bf9-f77b7e298cf2 --- vidix/dhahelperwin/Makefile | 42 +++++++ vidix/dhahelperwin/SOURCES | 2 +- vidix/dhahelperwin/common.ver | 207 ++++++++++++++++++++++++++++++++ vidix/dhahelperwin/dhahelper.c | 53 ++++++-- vidix/dhahelperwin/dhahelper.rc | 17 +++ vidix/dhahelperwin/ntverp.h | 151 +++++++++++++++++++++++ 6 files changed, 459 insertions(+), 13 deletions(-) create mode 100644 vidix/dhahelperwin/Makefile create mode 100644 vidix/dhahelperwin/common.ver create mode 100644 vidix/dhahelperwin/dhahelper.rc create mode 100644 vidix/dhahelperwin/ntverp.h diff --git a/vidix/dhahelperwin/Makefile b/vidix/dhahelperwin/Makefile new file mode 100644 index 0000000000..4ce2af98a7 --- /dev/null +++ b/vidix/dhahelperwin/Makefile @@ -0,0 +1,42 @@ +include ../../config.mak + +all: dhasetup.exe dhahelper.sys + +dhasetup.exe: dhasetup.c + $(CC) -o dhasetup.exe dhasetup.c + +dhahelper.o: dhahelper.c dhahelper.h + $(CC) -Wall -Os -c dhahelper.c -o dhahelper.o + +dhahelper-rc.o: dhahelper.rc common.ver ntverp.h + windres -I. dhahelper.rc $@ + +base.tmp: dhahelper.o dhahelper-rc.o + $(CC) -Wl,--base-file,base.tmp \ + -Wl,--entry,_DriverEntry@8 \ + -nostartfiles -nostdlib \ + -o junk.tmp \ + dhahelper.o dhahelper-rc.o \ + -lntoskrnl + -rm -f junk.tmp + +temp.exp: base.tmp + dlltool --dllname dhahelper.sys --base-file base.tmp --output-exp temp.exp + +dhahelper.sys: dhahelper.o dhahelper-rc.o temp.exp + $(CC) -Wl,--subsystem,native \ + -Wl,--image-base,0x10000 \ + -Wl,--file-alignment,0x1000 \ + -Wl,--section-alignment,0x1000 \ + -Wl,--entry,_DriverEntry@8 \ + -Wl,temp.exp \ + -mdll -nostartfiles -nostdlib \ + -o dhahelper.sys \ + dhahelper.o dhahelper-rc.o \ + -lntoskrnl + strip dhahelper.sys + +clean: + rm -f *.o *~ dhahelper.sys dhasetup.exe base.tmp temp.exp + +distclean: clean diff --git a/vidix/dhahelperwin/SOURCES b/vidix/dhahelperwin/SOURCES index e44aa06971..c1adcc37f4 100644 --- a/vidix/dhahelperwin/SOURCES +++ b/vidix/dhahelperwin/SOURCES @@ -3,4 +3,4 @@ TARGETPATH=. TARGETTYPE=DRIVER NTDEBUG=ntsd -SOURCES= dhahelper.c +SOURCES= dhahelper.c dhahelper.rc diff --git a/vidix/dhahelperwin/common.ver b/vidix/dhahelperwin/common.ver new file mode 100644 index 0000000000..3295b44320 --- /dev/null +++ b/vidix/dhahelperwin/common.ver @@ -0,0 +1,207 @@ +/* + * PROJECT: ReactOS + * LICENSE: GPL - See COPYING in the top level directory + * FILE: include/psdk/common.ver + * PURPOSE: Common Version File. + * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org) + */ + +// +// Copyright Year +// +#ifndef VER_LEGALCOPYRIGHT_YEARS +#define VER_LEGALCOPYRIGHT_YEARS "2007" +#endif + +// +// Copyright String +// +#ifndef VER_LEGALCOPYRIGHT_STR +#if defined(RC_INVOKED) && !defined(WIN16) +#define VER_LEGALCOPYRIGHT_STR L"\251 ReactOS Foundation. All rights reserved." +#else +#define VER_LEGALCOPYRIGHT_STR "Copyright (c) ReactOS Foundation. All rights reserved." +#endif +#endif + +// +// Product Name String +// +#ifndef VER_PRODUCTNAME_STR +#ifdef RC_INVOKED +#define VER_PRODUCTNAME_STR L"ReactOS\256 Operating System" +#else +#define VER_PRODUCTNAME_STR "ReactOS (R) Operating System" +#endif +#endif + +// +// The File Version is the same as the Product Version +// +#ifndef VER_FILEVERSION +#define VER_FILEVERSION VER_PRODUCTVERSION +#endif +#ifndef VER_FILEVERSION_STR +#define VER_FILEVERSION_STR VER_PRODUCTVERSION_STR +#endif + +// +// If no Original Name was given, use the Internal NAme +// +#ifndef VER_ORIGINALFILENAME_STR +#define VER_ORIGINALFILENAME_STR VER_INTERNALNAME_STR +#endif + +// +// Allow tagging a Build by Machine/Date +// +#if defined(__BUILDMACHINE__) +#if defined(__BUILDDATE__) +#define B2(x,y) " (" #x "." #y ")" +#define B1(x,y) B2(x, y) +#define BUILD_MACHINE_TAG B1(__BUILDMACHINE__, __BUILDDATE__) +#else +#define B2(x) " built by: " #x +#define B1(x) B2(x) +#define BUILD_MACHINE_TAG B1(__BUILDMACHINE__) +#endif +#if defined(__BUILDMACHINE_LEN__) +#if __BUILDMACHINE_LEN__ >= 25 +#define BUILD_MACHINE_TAG_PADDED BUILD_MACHINE_TAG +#elif __BUILDMACHINE_LEN__ == 24 +#define BUILD_MACHINE_TAG_PADDED BUILD_MACHINE_TAG " " +#elif __BUILDMACHINE_LEN__ == 23 +#define BUILD_MACHINE_TAG_PADDED BUILD_MACHINE_TAG " " +#elif __BUILDMACHINE_LEN__ == 22 +#define BUILD_MACHINE_TAG_PADDED BUILD_MACHINE_TAG " " +#elif __BUILDMACHINE_LEN__ == 21 +#define BUILD_MACHINE_TAG_PADDED BUILD_MACHINE_TAG " " +#elif __BUILDMACHINE_LEN__ == 20 +#define BUILD_MACHINE_TAG_PADDED BUILD_MACHINE_TAG " " +#elif __BUILDMACHINE_LEN__ == 19 +#define BUILD_MACHINE_TAG_PADDED BUILD_MACHINE_TAG " " +#elif __BUILDMACHINE_LEN__ == 18 +#define BUILD_MACHINE_TAG_PADDED BUILD_MACHINE_TAG " " +#elif __BUILDMACHINE_LEN__ == 17 +#define BUILD_MACHINE_TAG_PADDED BUILD_MACHINE_TAG " " +#elif __BUILDMACHINE_LEN__ == 16 +#define BUILD_MACHINE_TAG_PADDED BUILD_MACHINE_TAG " " +#elif __BUILDMACHINE_LEN__ == 15 +#define BUILD_MACHINE_TAG_PADDED BUILD_MACHINE_TAG " " +#elif __BUILDMACHINE_LEN__ == 14 +#define BUILD_MACHINE_TAG_PADDED BUILD_MACHINE_TAG " " +#elif __BUILDMACHINE_LEN__ == 13 +#define BUILD_MACHINE_TAG_PADDED BUILD_MACHINE_TAG " " +#elif __BUILDMACHINE_LEN__ == 12 +#define BUILD_MACHINE_TAG_PADDED BUILD_MACHINE_TAG " " +#elif __BUILDMACHINE_LEN__ == 11 +#define BUILD_MACHINE_TAG_PADDED BUILD_MACHINE_TAG " " +#elif __BUILDMACHINE_LEN__ == 10 +#define BUILD_MACHINE_TAG_PADDED BUILD_MACHINE_TAG " " +#elif __BUILDMACHINE_LEN__ == 9 +#define BUILD_MACHINE_TAG_PADDED BUILD_MACHINE_TAG " " +#elif __BUILDMACHINE_LEN__ == 8 +#define BUILD_MACHINE_TAG_PADDED BUILD_MACHINE_TAG " " +#elif __BUILDMACHINE_LEN__ == 7 +#define BUILD_MACHINE_TAG_PADDED BUILD_MACHINE_TAG " " +#elif __BUILDMACHINE_LEN__ == 6 +#define BUILD_MACHINE_TAG_PADDED BUILD_MACHINE_TAG " " +#elif __BUILDMACHINE_LEN__ == 5 +#define BUILD_MACHINE_TAG_PADDED BUILD_MACHINE_TAG " " +#elif __BUILDMACHINE_LEN__ == 4 +#define BUILD_MACHINE_TAG_PADDED BUILD_MACHINE_TAG " " +#elif __BUILDMACHINE_LEN__ == 3 +#define BUILD_MACHINE_TAG_PADDED BUILD_MACHINE_TAG " " +#elif __BUILDMACHINE_LEN__ == 2 +#define BUILD_MACHINE_TAG_PADDED BUILD_MACHINE_TAG " " +#elif __BUILDMACHINE_LEN__ == 1 +#define BUILD_MACHINE_TAG_PADDED BUILD_MACHINE_TAG " " +#else +#define BUILD_MACHINE_TAG_PADDED BUILD_MACHINE_TAG +#endif +#else +#define BUILD_MACHINE_TAG_PADDED BUILD_MACHINE_TAG +#endif +#else +#define BUILD_MACHINE_TAG +#define BUILD_MACHINE_TAG_PADDED +#endif + +// +// Set default neutral Unicode Language ID +// +#ifndef VER_VERSION_UNICODE_LANG +#define VER_VERSION_UNICODE_LANG "000004B0" +#endif + +// +// Set default netural ANSI Language ID +// +#ifndef VER_VERSION_ANSI_LANG +#define VER_VERSION_ANSI_LANG "000004E4" +#endif + +// +// Set default netural translation ID +// +#ifndef VER_VERSION_TRANSLATION +#define VER_VERSION_TRANSLATION 0x0000, 0x04B0 +#endif + +// +// Make sure the Resource Compiler called us. +// If so, then build the actual version resource. +// +#ifdef RC_INVOKED + +VS_VERSION_INFO VERSIONINFO +FILEVERSION VER_FILEVERSION +PRODUCTVERSION VER_PRODUCTVERSION +FILEFLAGSMASK VER_FILEFLAGSMASK +FILEFLAGS VER_FILEFLAGS +FILEOS VER_FILEOS +FILETYPE VER_FILETYPE +FILESUBTYPE VER_FILESUBTYPE +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK VER_VERSION_UNICODE_LANG + BEGIN + VALUE "CompanyName", VER_COMPANYNAME_STR + VALUE "FileDescription", VER_FILEDESCRIPTION_STR + VALUE "FileVersion", VER_FILEVERSION_STR BUILD_MACHINE_TAG_PADDED + VALUE "InternalName", VER_INTERNALNAME_STR + VALUE "LegalCopyright", VER_LEGALCOPYRIGHT_STR + VALUE "OriginalFilename",VER_ORIGINALFILENAME_STR + VALUE "ProductName", VER_PRODUCTNAME_STR + VALUE "ProductVersion", VER_PRODUCTVERSION_STR +#ifdef VER_OLESELFREGISTER + VALUE "OleSelfRegister", "\0" +#endif + END + +#ifdef VER_ANSICP + BLOCK VER_VERSION_ANSI_LANG + BEGIN + VALUE "CompanyName", VER_COMPANYNAME_STR + VALUE "FileDescription", VER_FILEDESCRIPTION_STR EXPORT_TAG + VALUE "FileVersion", VER_FILEVERSION_STR + VALUE "InternalName", VER_INTERNALNAME_STR + VALUE "LegalCopyright", VER_LEGALCOPYRIGHT_STR + VALUE "OriginalFilename",VER_ORIGINALFILENAME_STR + VALUE "ProductName", VER_PRODUCTNAME_STR + VALUE "ProductVersion", VER_PRODUCTVERSION_STR +#ifdef VER_OLESELFREGISTER + VALUE "OleSelfRegister", "\0" +#endif + END +#endif + END + + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", VER_VERSION_TRANSLATION + END +END + +#endif diff --git a/vidix/dhahelperwin/dhahelper.c b/vidix/dhahelperwin/dhahelper.c index 04eb0c2c5d..b68f397c6d 100644 --- a/vidix/dhahelperwin/dhahelper.c +++ b/vidix/dhahelperwin/dhahelper.c @@ -1,6 +1,8 @@ /****************************************************************************** * dhahelper.c: direct hardware access under Windows NT/2000/XP * Copyright (c) 2004 Sascha Sommer . + * Patched to compile with MinGW by Kevin Kofler: + * Copyright (c) 2007 Kevin Kofler * * This file is part of MPlayer. * @@ -21,7 +23,18 @@ *****************************************************************************/ +#if defined(_MSC_VER) #include +#ifndef STDCALL +#define STDCALL /* nothing */ +#endif +#elif defined(__MINGW32__) +#include +#define NO_SEH /* FIXME */ +#else +#error Unsupported compiler. This driver requires MSVC+DDK or MinGW to build. +#endif + #include "dhahelper.h" #define OutputDebugString DbgPrint @@ -47,20 +60,20 @@ static unsigned int alloccount=0; -static NTSTATUS dhahelperdispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp); -static void dhahelperunload(IN PDRIVER_OBJECT DriverObject); -static NTSTATUS UnmapPhysicalMemory(PVOID UserVirtualAddress); -static NTSTATUS MapPhysicalMemoryToLinearSpace(PVOID pPhysAddress,ULONG PhysMemSizeInBytes,PVOID *PhysMemLin); +static STDCALL NTSTATUS dhahelperdispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp); +static STDCALL void dhahelperunload(IN PDRIVER_OBJECT DriverObject); +static STDCALL NTSTATUS UnmapPhysicalMemory(PVOID UserVirtualAddress); +static STDCALL NTSTATUS MapPhysicalMemoryToLinearSpace(PVOID pPhysAddress,ULONG PhysMemSizeInBytes,PVOID *PhysMemLin); -void Ke386SetIoAccessMap(int, IOPM *); -void Ke386QueryIoAccessMap(int, IOPM *); -void Ke386IoSetAccessProcess(PEPROCESS, int); +void STDCALL Ke386SetIoAccessMap(int, IOPM *); +void STDCALL Ke386QueryIoAccessMap(int, IOPM *); +void STDCALL Ke386IoSetAccessProcess(PEPROCESS, int); //entry point -NTSTATUS DriverEntry (IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegistryPath){ +STDCALL NTSTATUS DriverEntry (IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegistryPath){ UNICODE_STRING DeviceNameUnicodeString; UNICODE_STRING DeviceLinkUnicodeString; NTSTATUS ntStatus; @@ -106,7 +119,7 @@ NTSTATUS DriverEntry (IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING Registry // Process the IRPs sent to this device -static NTSTATUS dhahelperdispatch(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp){ +static STDCALL NTSTATUS dhahelperdispatch(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp){ PIO_STACK_LOCATION IrpStack; ULONG dwInputBufferLength; ULONG dwOutputBufferLength; @@ -207,7 +220,7 @@ static NTSTATUS dhahelperdispatch(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp){ // Delete the associated device and return -static void dhahelperunload(IN PDRIVER_OBJECT DriverObject){ +static STDCALL void dhahelperunload(IN PDRIVER_OBJECT DriverObject){ UNICODE_STRING DeviceLinkUnicodeString; NTSTATUS ntStatus=STATUS_SUCCESS; OutputDebugString ("dhahelper: entering dhahelperunload"); @@ -240,7 +253,7 @@ static void dhahelperunload(IN PDRIVER_OBJECT DriverObject){ //I'm not sure what the limitations of ZwMapViewOfSection are but mapping 128MB videoram (that is probably already mapped by the gfxcard driver) //won't work so it is generally a good idea to map only the memory you really need -static NTSTATUS MapPhysicalMemoryToLinearSpace(PVOID pPhysAddress,ULONG PhysMemSizeInBytes,PVOID *PhysMemLin){ +static STDCALL NTSTATUS MapPhysicalMemoryToLinearSpace(PVOID pPhysAddress,ULONG PhysMemSizeInBytes,PVOID *PhysMemLin){ alloc_priv* alloclisttmp; PMDL Mdl=NULL; PVOID SystemVirtualAddress=NULL; @@ -248,8 +261,14 @@ static NTSTATUS MapPhysicalMemoryToLinearSpace(PVOID pPhysAddress,ULONG PhysMemS PHYSICAL_ADDRESS pStartPhysAddress; OutputDebugString ("dhahelper: entering MapPhysicalMemoryToLinearSpace"); +#ifdef _WIN64 pStartPhysAddress.QuadPart = (ULONGLONG)pPhysAddress; +#else + pStartPhysAddress.QuadPart = (ULONGLONG)(ULONG)pPhysAddress; +#endif +#ifndef NO_SEH __try { +#endif SystemVirtualAddress=MmMapIoSpace(pStartPhysAddress,PhysMemSizeInBytes, /*MmWriteCombined*/MmNonCached); if(!SystemVirtualAddress){ OutputDebugString("dhahelper: MmMapIoSpace failed"); @@ -263,18 +282,24 @@ static NTSTATUS MapPhysicalMemoryToLinearSpace(PVOID pPhysAddress,ULONG PhysMemS } OutputDebugString("dhahelper: Mdl 0x%x",Mdl); MmBuildMdlForNonPagedPool(Mdl); +#ifdef _WIN64 + UserVirtualAddress = (PVOID)(((ULONGLONG)PAGE_ALIGN(MmMapLockedPages(Mdl,UserMode))) + MmGetMdlByteOffset(Mdl)); +#else UserVirtualAddress = (PVOID)(((ULONG)PAGE_ALIGN(MmMapLockedPages(Mdl,UserMode))) + MmGetMdlByteOffset(Mdl)); +#endif if(!UserVirtualAddress){ OutputDebugString("dhahelper: MmMapLockedPages failed"); return STATUS_INSUFFICIENT_RESOURCES; } OutputDebugString("dhahelper: UserVirtualAddress 0x%x",UserVirtualAddress); +#ifndef NO_SEH }__except(EXCEPTION_EXECUTE_HANDLER){ NTSTATUS ntStatus; ntStatus = GetExceptionCode(); OutputDebugString("dhahelper: MapPhysicalMemoryToLinearSpace failed due to exception 0x%0x\n", ntStatus); return ntStatus; } +#endif OutputDebugString("dhahelper: adding data to internal allocation list"); @@ -304,7 +329,7 @@ static NTSTATUS MapPhysicalMemoryToLinearSpace(PVOID pPhysAddress,ULONG PhysMemS return STATUS_SUCCESS; } -static NTSTATUS UnmapPhysicalMemory(PVOID UserVirtualAddress){ +static STDCALL NTSTATUS UnmapPhysicalMemory(PVOID UserVirtualAddress){ unsigned int i; unsigned int x=0; unsigned int alloccounttmp=alloccount; @@ -327,16 +352,20 @@ static NTSTATUS UnmapPhysicalMemory(PVOID UserVirtualAddress){ } else if(alloclist[i].UserVirtualAddress==UserVirtualAddress){ if(x==i){ +#ifndef NO_SEH __try { +#endif MmUnmapLockedPages(alloclist[x].UserVirtualAddress, alloclist[x].Mdl); IoFreeMdl(alloclist[x].Mdl); MmUnmapIoSpace(alloclist[x].SystemVirtualAddress,alloclist[x].PhysMemSizeInBytes); +#ifndef NO_SEH }__except(EXCEPTION_EXECUTE_HANDLER){ NTSTATUS ntStatus; ntStatus = GetExceptionCode(); OutputDebugString("dhahelper: UnmapPhysicalMemory failed due to exception 0x%0x (Mdl 0x%x)\n", ntStatus,alloclist[x].Mdl); return ntStatus; } +#endif } alloccounttmp--; } diff --git a/vidix/dhahelperwin/dhahelper.rc b/vidix/dhahelperwin/dhahelper.rc new file mode 100644 index 0000000000..3f878a5fd9 --- /dev/null +++ b/vidix/dhahelperwin/dhahelper.rc @@ -0,0 +1,17 @@ +#include + +#include + +#undef VER_COMPANYNAME_STR +#undef VER_PRODUCTNAME_STR + +#define VER_FILETYPE VFT_DRV +#define VER_FILESUBTYPE VFT2_DRV_SYSTEM +#define VER_FILEDESCRIPTION_STR "DhaHelper - Direct HardWare Access Driver" +#define VER_INTERNALNAME_STR "DhaHelper.sys" +#define VER_ORIGINALFILENAME_STR "DhaHelper.sys" +#define VER_LEGALCOPYRIGHT_STR "Sascha Sommer" +#define VER_COMPANYNAME_STR "MPlayer " +#define VER_PRODUCTNAME_STR "DhaHelper Driver V1.0" + +#include "common.ver" diff --git a/vidix/dhahelperwin/ntverp.h b/vidix/dhahelperwin/ntverp.h new file mode 100644 index 0000000000..bfcc43240d --- /dev/null +++ b/vidix/dhahelperwin/ntverp.h @@ -0,0 +1,151 @@ +/* + * PROJECT: ReactOS + * LICENSE: GPL - See COPYING in the top level directory + * FILE: include/psdk/ntverp.h + * PURPOSE: Master Version File. + * This file should be modified only by the official builder + * to update VERSION, VER_PRODUCTVERSION, VER_PRODUCTVERSION_ + * STR and VER_PRODUCTBETA_STR values. + * The VER_PRODUCTBUILD lines must contain the product + * comments and end with the build#. + * The VER_PRODUCTBETA_STR lines must contain the product + * comments and end with "somestring"