* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* $Id$
*
*/
-#include <w32k.h>
+#include <win32k.h>
#define NDEBUG
#include <debug.h>
-typedef struct _DRIVERS
-{
- LIST_ENTRY ListEntry;
- HANDLE ImageHandle;
- UNICODE_STRING DriverName;
-}DRIVERS, *PDRIVERS;
-
extern LIST_ENTRY GlobalDriverListHead;
+
/*
* Blatantly stolen from ldr/utils.c in ntdll. I can't link ntdll from
* here, though.
return NULL;
}
RtlInitAnsiString(&ProcNameString, ProcName);
- Status = LdrGetProcedureAddress(Module,
+ Status = LdrGetProcedureAddress(((PDRIVERS)Module)->BaseAddress,
&ProcNameString,
0,
&Function);
APIENTRY
EngLoadImage (LPWSTR DriverName)
{
- HANDLE hImageHandle = NULL;
SYSTEM_GDI_DRIVER_INFORMATION GdiDriverInfo;
+ PDRIVERS DriverInfo = NULL;
NTSTATUS Status;
RtlInitUnicodeString(&GdiDriverInfo.DriverName, DriverName);
{
Current = CONTAINING_RECORD(CurrentEntry, DRIVERS, ListEntry);
if( Current && (0 == RtlCompareUnicodeString(&GdiDriverInfo.DriverName, &Current->DriverName, FALSE)) ) {
- hImageHandle = Current->ImageHandle;
+ DriverInfo = Current;
break;
}
CurrentEntry = CurrentEntry->Flink;
};
}
- if( !hImageHandle )
+ if( !DriverInfo )
{
/* the driver was not loaded before, so let's do that */
Status = ZwSetSystemInformation(SystemLoadGdiDriverInformation, &GdiDriverInfo, sizeof(SYSTEM_GDI_DRIVER_INFORMATION));
DPRINT1("ZwSetSystemInformation failed with Status 0x%lx\n", Status);
}
else {
- PDRIVERS DriverInfo;
- hImageHandle = (HANDLE)GdiDriverInfo.ImageAddress;
- DriverInfo = ExAllocatePool(PagedPool, sizeof(DRIVERS));
+ DriverInfo = ExAllocatePoolWithTag(PagedPool, sizeof(DRIVERS), TAG_DRIVER);
DriverInfo->DriverName.MaximumLength = GdiDriverInfo.DriverName.MaximumLength;
DriverInfo->DriverName.Length = GdiDriverInfo.DriverName.Length;
- DriverInfo->DriverName.Buffer = ExAllocatePool(PagedPool, GdiDriverInfo.DriverName.MaximumLength);
+ DriverInfo->DriverName.Buffer = ExAllocatePoolWithTag(PagedPool, GdiDriverInfo.DriverName.MaximumLength, TAG_DRIVER);
RtlCopyUnicodeString(&DriverInfo->DriverName, &GdiDriverInfo.DriverName);
- DriverInfo->ImageHandle = hImageHandle;
+ DriverInfo->SectionPointer = GdiDriverInfo.SectionPointer;
+ DriverInfo->BaseAddress = GdiDriverInfo.ImageAddress;
InsertHeadList(&GlobalDriverListHead, &DriverInfo->ListEntry);
}
}
- return hImageHandle;
-}
-
-
-/*
- * @unimplemented
- */
-HANDLE
-APIENTRY
-EngLoadModule(LPWSTR ModuleName)
-{
- SYSTEM_GDI_DRIVER_INFORMATION GdiDriverInfo;
- NTSTATUS Status;
-
- // FIXME: should load as readonly
-
- RtlInitUnicodeString (&GdiDriverInfo.DriverName, ModuleName);
- Status = ZwSetSystemInformation (SystemLoadGdiDriverInformation,
- &GdiDriverInfo, sizeof(SYSTEM_GDI_DRIVER_INFORMATION));
- if (!NT_SUCCESS(Status)) return NULL;
-
- return (HANDLE)GdiDriverInfo.ImageAddress;
+ return DriverInfo;
}
VOID
EngUnloadImage ( IN HANDLE hModule )
{
NTSTATUS Status;
+ PDRIVERS DriverInfo = (PDRIVERS)hModule;
DPRINT("hModule 0x%x\n", hModule);
Status = ZwSetSystemInformation(SystemUnloadGdiDriverInformation,
- &hModule, sizeof(HANDLE));
+ DriverInfo->SectionPointer, sizeof(PVOID));
if(!NT_SUCCESS(Status))
{
}
else
{
- /* remove from the list */
- if( !IsListEmpty(&GlobalDriverListHead) )
- {
- PLIST_ENTRY CurrentEntry = GlobalDriverListHead.Flink;
- PDRIVERS Current;
- /* probably the driver was already loaded, let's try to find it out */
- while( CurrentEntry != &GlobalDriverListHead )
- {
- Current = CONTAINING_RECORD(CurrentEntry, DRIVERS, ListEntry);
-
- if( Current ) {
- if(Current->ImageHandle == hModule) {
- ExFreePool(Current->DriverName.Buffer);
- RemoveEntryList(&Current->ListEntry);
- ExFreePool(Current);
- break;
- }
- }
- CurrentEntry = CurrentEntry->Flink;
- };
- }
+ ExFreePool(DriverInfo->DriverName.Buffer);
+ RemoveEntryList(&DriverInfo->ListEntry);
+ ExFreePool(DriverInfo);
}
}