Thank You,
I understand this is legacy and very old. For understanding the basic i started from here. Anyhow if you prefer any best option for understanding the basics of driver dev please advice me. Apart form mentor i personaly want to delve into Windows Device Driver Developement so please suggest me best to proceed further as i already started.
Coming to the query:
Just i want to create two devices i.e below code…
NTSTATUS DriverEntry(
PDRIVER_OBJECT pDriverObject,
PUNICODE_STRING RegPath)
{
NTSTATUS status;
ULONG Device_No;
Device_No = 0;
DbgPrint(“WdmDriver1: In Driver Entry…\n”);
pDriverObject->DriverUnload = Wdm_Unload;
status = CreateDevice(pDriverObject, Device_No);
Device_No++;
status = CreateDevice(pDriverObject, Device_No);
return status;
}
I understood calling CreateDevice function with Device_no = 0;
have to create device with name: \Device\System_WdmDriver0 addding “0” at end… again called with device_no 1, so there willbe two device created. inorder to do this i have to convert int to unicode string i did …i.e. below code…
#include<ntddk.h>
#define DISPLAY_NAME “\DosDevices\Display_WdmDriver”
#define SYSTEM_NAME L"\Device\System_WdmDriver"
typedef struct _DEVICE_EXTENSION
{
PDEVICE_OBJECT pDeviceObj;
ULONG DeviceNo;
PUNICODE_STRING NtDeviceName;
PUNICODE_STRING DisplyName;
} DEVICE_EXTENSION, PDEVICE_EXTENSION;
NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObject, PUNICODE_STRING RegPath);
NTSTATUS CreateDevice(PDRIVER_OBJECT pDriverObject, ULONG Device_No);
void Wdm_Unload(PDRIVER_OBJECT pDriverObject);
NTSTATUS DriverEntry(
PDRIVER_OBJECT pDriverObject,
PUNICODE_STRING RegPath)
{
NTSTATUS status;
ULONG Device_No;
Device_No = 0;
DbgPrint(“WdmDriver1: In Driver Entry…\n”);
pDriverObject->DriverUnload = Wdm_Unload;
status = CreateDevice(pDriverObject, Device_No);
Device_No++;
status = CreateDevice(pDriverObject, Device_No);
return status;
}
NTSTATUS CreateDevice(PDRIVER_OBJECT pDriverObject, ULONG Device_No)
{
NTSTATUS status;
PDEVICE_OBJECT pDevObj;
PDEVICE_EXTENSION pDevExtension;
UNICODE_STRING ntDevName, symDevName, DevNo;
WCHAR ntDevNameBuffer[256];
WCHAR symDevNameBuffer[256];
WCHAR DevNoBuffer[10];
DevNo.Buffer = DevNoBuffer;
DevNo.MaximumLength = 10;
DbgPrint(“WdmDriver1: In CreatDevice…\n”);
ntDevName.Buffer = ntDevNameBuffer;
ntDevName.MaximumLength = 256 * 2;
ntDevName.Length = 0;
DevNo.Length = 0;
RtlAppendUnicodeStringToString(&ntDevName, SYSTEM_NAME);
status = RtlIntegerToUnicodeString(Device_No, 10, &DevNo);
if (status == STATUS_SUCCESS){
DbgPrint(“WdmDriver1: RtlIntegerToUnicodeString Success…\n”);
}
else
{
DbgPrint(“WdmDriver1: RtlIntegerToUnicodeString Failed…\n”);
return status;
}
status = RtlAppendUnicodeStringToString(&ntDevName, &DevNo);
if (status == STATUS_SUCCESS){
DbgPrint(“WdmDriver1: RtlIntegerToUnicodeString Success…\n”);
}
else
{
DbgPrint(“WdmDriver1: RtlIntegerToUnicodeString Failed…\n”);
return status;
}
status = IoCreateDevice(pDriverObject,
sizeof(DEVICE_EXTENSION),
&ntDevName,
FILE_DEVICE_UNKNOWN,
0,
TRUE,
&pDevObj);
if (status == STATUS_SUCCESS){
DbgPrint(“WdmDriver1: IoCreateDevice Success…\n”);
}
else
{
DbgPrint(“WdmDriver1: IoCreateDvice Failed…\n”);
return status;
}
Above all i did my own, book was only guide to do. As it is having some special headder for managinf Unicode Strings and bit complicated to follow. So please tell me the solution i am adding debugger output below…
WdmDriver1: In Driver Entry…
WdmDriver1: In CreatDevice…
Fatal System Error: 0x0000007e
(0xC0000005,0x82856B13,0x807E157C,0x807E1160)
Break instruction exception - code 80000003 (first chance)
A fatal system error has occurred.
Debugger entered on first try; Bugcheck callbacks have not been invoked.
A fatal system error has occurred.
Connected to Windows 7 7600 x86 compatible target at (Tue May 12 11:19:06.308 2015 (UTC + 5:30)), ptr64 FALSE
Loading Kernel Symbols
…
…
…
Loading User Symbols
Loading unloaded module list
…
Bugcheck Analysis
Use !analyze -v to get detailed debugging information.
BugCheck 7E, {c0000005, 82856b13, 807e157c, 807e1160}
Probably caused by : wdmhello.sys ( wdmhello!CreateDevice+6a )
Followup: MachineOwner
---------
nt!RtlpBreakWithStatusInstruction:
82883394 cc int 3
kd> !analyze -v
**************************************************************************
Bugcheck Analysis
*
*******************************************************************************
SYSTEM_THREAD_EXCEPTION_NOT_HANDLED (7e)
This is a very common bugcheck. Usually the exception address pinpoints
the driver/function that caused the problem. Always note this address
as well as the link date of the driver/image that contains this address.
Arguments:
Arg1: c0000005, The exception code that was not handled
Arg2: 82856b13, The address that the exception occurred at
Arg3: 807e157c, Exception Record Address
Arg4: 807e1160, Context Record Address
Debugging Details:
------------------
EXCEPTION_CODE: (NTSTATUS) 0xc0000005 - The instruction at 0x%08lx referenced memory at 0x%08lx. The memory could not be %s.
FAULTING_IP:
nt!memmove+33
82856b13 f3a5 rep movs dword ptr es:[edi],dword ptr [esi]
EXCEPTION_RECORD: 807e157c – (.exr 0xffffffff807e157c)
ExceptionAddress: 82856b13 (nt!memmove+0x00000033)
ExceptionCode: c0000005 (Access violation)
ExceptionFlags: 00000000
NumberParameters: 2
Parameter[0]: 00000000
Parameter[1]: 00760065
Attempt to read from address 00760065
CONTEXT: 807e1160 – (.cxr 0xffffffff807e1160)
eax=007600c1 ebx=807e18a8 ecx=00000017 edx=00000000 esi=00760065 edi=807e18a8
eip=82856b13 esp=807e1644 ebp=807e164c iopl=0 nv up ei pl nz ac pe nc
cs=0008 ss=0010 ds=0023 es=0023 fs=0030 gs=0000 efl=00010216
nt!memmove+0x33:
82856b13 f3a5 rep movs dword ptr es:[edi],dword ptr [esi]
Resetting default scope
DEFAULT_BUCKET_ID: VISTA_DRIVER_FAULT
PROCESS_NAME: System
CURRENT_IRQL: 2
ERROR_CODE: (NTSTATUS) 0xc0000005 - The instruction at 0x%08lx referenced memory at 0x%08lx. The memory could not be %s.
EXCEPTION_PARAMETER1: 00000000
EXCEPTION_PARAMETER2: 00760065
READ_ADDRESS: 00760065
FOLLOWUP_IP:
wdmhello!CreateDevice+6a [d:\drivercoding\wdm_coding\wdmhello\wdmhello.c @ 60]
94b7d0da 8d8dbcfbffff lea ecx,[ebp-444h]
BUGCHECK_STR: 0x7E
EXCEPTION_DOESNOT_MATCH_CODE: This indicates a hardware error.
Instruction at 82856b13 does not read/write to 00760065
LAST_CONTROL_TRANSFER: from 828d279d to 82856b13
STACK_TEXT:
807e164c 828d279d 807e18a8 00760065 0000005c nt!memmove+0x33
807e166c 94b7d0da 807e1ab8 0000005c 000a0000 nt!RtlAppendUnicodeStringToString+0x43
807e1ac0 94b7d043 856976f0 00000000 00000000 wdmhello!CreateDevice+0x6a [d:\drivercoding\wdm_coding\wdmhello\wdmhello.c @ 60]
807e1ad8 829bb728 856976f0 85711000 00000000 wdmhello!DriverEntry+0x33 [d:\drivercoding\wdm_coding\wdmhello\wdmhello.c @ 28]
807e1cbc 829b9499 00000001 00000000 807e1ce4 nt!IopLoadDriver+0x7ed
807e1d00 82885f2b 9439dcd0 00000000 8500ed48 nt!IopLoadUnloadDriver+0x70
807e1d50 82a2666d 00000001 1c1b2e73 00000000 nt!ExpWorkerThread+0x10d
807e1d90 828d80d9 82885e1e 00000001 00000000 nt!PspSystemThreadStartup+0x9e
00000000 00000000 00000000 00000000 00000000 nt!KiThreadStartup+0x19
FAULTING_SOURCE_CODE:
56: DevNo.Length = 0;
57:
58: RtlAppendUnicodeStringToString(&ntDevName, SYSTEM_NAME);
59:
> 60: status = RtlIntegerToUnicodeString(Device_No, 10, &DevNo);
61: if (status == STATUS_SUCCESS){
62: DbgPrint(“WdmDriver1: RtlIntegerToUnicodeString Success…\n”);
63: }
64: else
65: {
SYMBOL_STACK_INDEX: 2
SYMBOL_NAME: wdmhello!CreateDevice+6a
FOLLOWUP_NAME: MachineOwner
MODULE_NAME: wdmhello
IMAGE_NAME: wdmhello.sys
DEBUG_FLR_IMAGE_TIMESTAMP: 555193d4
STACK_COMMAND: .cxr 0xffffffff807e1160 ; kb
FAILURE_BUCKET_ID: 0x7E_CODE_ADDRESS_MISMATCH_wdmhello!CreateDevice+6a
BUCKET_ID: 0x7E_CODE_ADDRESS_MISMATCH_wdmhello!CreateDevice+6a
Followup: MachineOwner</ntddk.h>