Chris Cant - Writing Windows WDM Device Drivers

Здесь есть возможность читать онлайн «Chris Cant - Writing Windows WDM Device Drivers» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Город: Lawrence, Kansas 66046, ISBN: , Издательство: R & D Books, Жанр: Программирование, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

Writing Windows WDM Device Drivers: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Writing Windows WDM Device Drivers»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

Writing Windows WDM Device Drivers — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Writing Windows WDM Device Drivers», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

The rest of the Wdm1Test main function performs each of these tests in turn.

1. Open the first Wdm1 device.

2. Read the first DWORD stored in the shared memory buffer. This will fail first time round, as there will be nothing in the buffer.

3. Write 0x12345678 to the start of the buffer. 0x78 is written at file pointer zero, 0x56 at one, 0x34 at two, and 0x12 at three.

4. Set the file pointer to position 3.

5. Read one byte from the file. This should be 0x12.

6. Write 0x12345678 to the buffer starting at file position 3.

7. Use an IOCTL to get the buffer size, which should be 7 (i.e., 3+4).

8. Use an IOCTL to get the entire buffer. The first word is printed and should be 0x78345678.

9. Check that issuing an IOCTL with an invalid parameter fails. The IOCTL asks for the entire buffer with a request size that is too big.

10. Use an IOCTL to zero all the bytes in the buffer. Get the entire buffer again. The first word is printed which should be 0x00000000.

11. Use an IOCTL to remove the buffer. Check that the buffer size is now zero.

12. Try to issue an invalid IOCTL code. Confirm that this fails.

13. Write 0xabcdef01 to the start of the buffer. When Wdm1Test is run next, Test 2 should find this value.

Listing 5.6 Wdm1Test output on W2000

Test 1

Symbolic link is \\?\root#unknown#0003#{c0cf0640-5f6e-11d2-b677-00c0dfe4c1f3}

Opened OK

Test 2

Read successfully read stored value of 0xABC0EF01

Test 3

Write 0x12345678 succeeded

Test 4

SetFilePointer worked

Test 5

Read successfully read stored value of 0x12

Test 6

Write at new file pointer succeeded

Test 7

Buffer size is 7 (4 bytes returned)

Test 8

First DWORD of buffer is 78345678 (7 bytes returned)

Test 9

Too big get buffer failed correctly 87

Test 10

Zero buffer succeeded

First DWORD of buffer is 00000000 (7 bytes returned)

Test 11

Remove buffer succeeded

Buffer size is 0 (4 bytes returned)

Test 12

Unrecognised IOCTL correctly failed 1

Test 13

SetFilePointer worked Write 0xabcdef01 succeeded

Test 14

CloseHandle worked

Press enter please

Wdm1Test exercises all the functions of the Wdm1 driver. It checks that things that should work do work, and things that should fail do fail.

Writing this test program showed that the Wdm1 device does behave differently in Windows 98 and Windows 2000. However, the problem does not lie in the driver itself, but is due to Windows 98 not supporting SetFilePointer for device files.

Conclusion

This chapter shows how to open a connection to a Wdm1 device using device interfaces. The Wdm1Test user mode program puts the Wdm1 driver through its paces.

Chapter 7 shows how Wdm1 implements the read, write, and IOCTL calls. However, before I continue looking at the driver, the next chapter describes how to test and debug drivers. It explains how this book uses the DebugPrint software to see what is going on in a driver.

Listing 5.7 Wdm1Test.cpp

///////////////////////////////////////////////////////////////////////

//Copyright © 1998 Chris Cant, PHD Computer Consultants Ltd

//WDM Book for R&D Books, Miller Freeman Inc

//

//Wdm1Test example

///////////////////////////////////////////////////////////////////////

//WdmlTest.cpp:Win32 console application to exercise Wdm1 devices

///////////////////////////////////////////////////////////////////////

//mainProgram main line

//GetDeviceVialnterfaceOpen a handle via a device interface

///////////////////////////////////////////////////////////////////////

//Version history

//27-Apr-991.0.0CCcreation

///////////////////////////////////////////////////////////////////////

#include "windows.h"

#include "C:\98ddk\inc\win98\setupapi.h"// VC++ 5 one is out of date

#include "stdio.h"

#include "initguid.h"

#include "..\sys\GUIDs.h"

#include "winioctl.h"

#include "..\sys\Ioctl.h"

HANDLE GetDeviceViaInterface(GUID* pGuid, DWORD instance);

int main(int argc, char* argv[]) {

int TestNo = 1;

//////////////////////////////////////////////////////////////////////

// Open device

printf("\nTest %d\n",TestNo++);

HANDLE hWdm1 = GetDeviceViaInterface((LPGUID)&WDM1_GUID,0);

if (hWdml==NULL) {

printf("XXX Could not find open Wdm1 device\n");

return 1;

}

printf(" Opened OK\n");

//////////////////////////////////////////////////////////////////////

// Read first ULONG that's left in buffer

printf("\nTest %d\n",TestNo++);

DWORD TxdBytes;

ULONG Rvalue =0;

if (!ReadFile(hWdm1, &Rvalue, 4, &TxdBytes, NULL)) printf("XXX Could not read value %d\n", GetLastError());

else if(TxdBytes==4) printf(" Read successfully read stored value of 0x%X\n",Rvalue);

else printf("XXX Wrong number of bytes read: %d\n",TxdBytes);

//////////////////////////////////////////////////////////////////////

// Write 0x12345678

printf("\nTest M\n" ,TestNo++);

ULONG Wvalue = 0x12345678;

if (!WriteFile(hWdm1, &Wvalue, 4, &TxdBytes, NULL)) printf("XXX Could not write %X\n",Wvalue);

else if (TxdBytes==4) printf(" Write 0x12345678 succeeded\n");

else printf("XXX Wrong number of bytes written: %d\n",TxdBytes);

//////////////////////////////////////////////////////////////////////

// Set file pointer

printf("\nTest %d\n",TestNo++);

DWORD dwNewPtr = SetFilePointer(hWdrn1, 3, NULL, FILE_BEGIN);

if (dwNewPtr==0xFFFFFFFF) printf("XXX SetFilePointer failed %d\n", GetLastError());

else printf(" SetFilePointer worked\n");

//////////////////////////////////////////////////////////////////////

// Read

printf("\nTest %d\n",TestNo++);

Rvalue = 0;

if (!ReadFile(hWdm1, &Rvalue, 1, &TxdBytes, NULL)) printf("XXX Could not read value\n");

else if( TxdBytes==1) printf(" Read successfully read stored value of 0x%X\n",Rvalue);

else printf("XXX Wrong number of bytes read: %d\n",TxdBytes);

//////////////////////////////////////////////////////////////////////

// Write

printf("\nTest %d\n",TestNo++);

if (!WriteFile(hWdm1, &Wvalue, 4, &TxdBytes, NULL)) printf("XXX Could not write %X\n" ,Wvalue);

else if (TxdBytes==4) printf(" Write at new file pointer succeeded\n");

else printf("XXX Wrong number of bytes written: %d\n",TxdBytes);

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «Writing Windows WDM Device Drivers»

Представляем Вашему вниманию похожие книги на «Writing Windows WDM Device Drivers» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «Writing Windows WDM Device Drivers»

Обсуждение, отзывы о книге «Writing Windows WDM Device Drivers» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x