Reactos
at master 113 lines 3.1 kB view raw
1/* 2 * PROJECT: ReactOS VT100 emulator 3 * LICENSE: GPL - See COPYING in the top level directory 4 * FILE: drivers/base/green/green.c 5 * PURPOSE: Driver entry point 6 * PROGRAMMERS: Copyright 2005-2006 Herv� Poussineau (hpoussin@reactos.org) 7 */ 8 9#include "green.h" 10 11#define NDEBUG 12#include <debug.h> 13 14VOID NTAPI 15DriverUnload(IN PDRIVER_OBJECT DriverObject) 16{ 17 // nothing to do here yet 18} 19 20/* 21 * Standard DriverEntry method. 22 */ 23NTSTATUS NTAPI 24DriverEntry( 25 IN PDRIVER_OBJECT DriverObject, 26 IN PUNICODE_STRING RegistryPath) 27{ 28 PGREEN_DRIVER_EXTENSION DriverExtension; 29 ULONG i; 30 NTSTATUS Status; 31 32 Status = IoAllocateDriverObjectExtension( 33 DriverObject, 34 DriverObject, 35 sizeof(GREEN_DRIVER_EXTENSION), 36 (PVOID*)&DriverExtension); 37 if (!NT_SUCCESS(Status)) 38 { 39 DPRINT("IoAllocateDriverObjectExtension() failed with status 0x%08lx\n", Status); 40 return Status; 41 } 42 RtlZeroMemory(DriverExtension, sizeof(GREEN_DRIVER_EXTENSION)); 43 44 Status = GreenDuplicateUnicodeString( 45 0, 46 RegistryPath, 47 &DriverExtension->RegistryPath); 48 if (!NT_SUCCESS(Status)) 49 { 50 DPRINT("GreenDuplicateUnicodeString() failed with status 0x%08lx\n", Status); 51 return Status; 52 } 53 54 Status = ReadRegistryEntries(RegistryPath, DriverExtension); 55 if (!NT_SUCCESS(Status)) 56 { 57 DPRINT("ReadRegistryEntries() failed with status 0x%08lx\n", Status); 58 return Status; 59 } 60 61 DriverObject->DriverUnload = DriverUnload; 62 DriverObject->DriverExtension->AddDevice = GreenAddDevice; 63 64 for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++) 65 DriverObject->MajorFunction[i] = GreenDispatch; 66 67 return STATUS_SUCCESS; 68} 69 70NTSTATUS 71GreenDuplicateUnicodeString( 72 IN ULONG Flags, 73 IN PCUNICODE_STRING SourceString, 74 OUT PUNICODE_STRING DestinationString) 75{ 76 if (SourceString == NULL || DestinationString == NULL 77 || SourceString->Length > SourceString->MaximumLength 78 || (SourceString->Length == 0 && SourceString->MaximumLength > 0 && SourceString->Buffer == NULL) 79 || Flags == RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING || Flags >= 4) 80 { 81 return STATUS_INVALID_PARAMETER; 82 } 83 84 85 if ((SourceString->Length == 0) 86 && (Flags != (RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE | 87 RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING))) 88 { 89 DestinationString->Length = 0; 90 DestinationString->MaximumLength = 0; 91 DestinationString->Buffer = NULL; 92 } 93 else 94 { 95 USHORT DestMaxLength = SourceString->Length; 96 97 if (Flags & RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE) 98 DestMaxLength += sizeof(UNICODE_NULL); 99 100 DestinationString->Buffer = ExAllocatePool(PagedPool, DestMaxLength); 101 if (DestinationString->Buffer == NULL) 102 return STATUS_NO_MEMORY; 103 104 RtlCopyMemory(DestinationString->Buffer, SourceString->Buffer, SourceString->Length); 105 DestinationString->Length = SourceString->Length; 106 DestinationString->MaximumLength = DestMaxLength; 107 108 if (Flags & RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE) 109 DestinationString->Buffer[DestinationString->Length / sizeof(WCHAR)] = 0; 110 } 111 112 return STATUS_SUCCESS; 113}