Structure Flashcards

1
Q

Driver

A

Is as a container for a collection of subroutines that the operating system calls to perform various operations that relate to your hardware

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Routines present in every such container

A

DriverEntry and AddDevice routines, as well as dispatch functions for a few types of I/O Request Packet (IRP)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Drivers that need to queue requests

A

Might have a StartIo routine

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Drivers for devices that generate hardware interrupts

A

Have an interrupt service routine (ISR) and a deferred procedure call (DPC) routine

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Jobs as the author of a WDM driver

A

Select the functions that need to be included in your particular container

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

OS Scheduler

A

The operating system kernel contains a scheduler that gives short blocks of time, called time slices, to all the
threads that are currently eligible to run. An application begins life with a single thread and can create more if it wants. Each thread has a priority, given to it by the system and subject to adjustment up and down for various reasons. At each decision point, the scheduler picks the highest-priority eligible thread and gives it control by loading a set of saved register images,
including an instruction pointer, into the processor registers. A processor interrupt accompanies expiration of the thread’s time slice. As part of handling the interrupt, the system saves the current register images, which can be restored the next time the system decides to redispatch the same thread.

Instead of just waiting for its time slice to expire, a thread can block each time it initiates a time-consuming activity in another thread until the activity finishes. This is better than spinning in a polling loop waiting for completion because it allows other
threads to run sooner than they would if the system had to rely solely on expiration of a time slice to turn its attention to some other thread.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Application is

A

A selfish thread that grabs the CPU and tries to hold on until it exits and that the operating system scheduler acts like a playground monitor to make a bunch of selfish threads play well together

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

A a driver is also an executable file with extension

A

.SYS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Who charge the driver

A

A driver doesn’t contain a main program. Instead, it contains a collection of subroutines that the
system can call when the system thinks it’s time to. To be sure, these subroutines can use helper subroutines in the driver, in static libraries, and in the operating system, but the driver isn’t in charge of anything except its own hardware: the system is in charge of everything else, including the decisions about when to run your driver code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Thead context

A

Running in an arbitrary thread context. A driver subroutine executes in the context of whatever thread happens to be currently active at the time the system decides to call that subroutine. It’s not possible to predict which thread will be current at the time a hardware interrupt occurs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Arbitrary thread

A

All the eligible threads that happens to be executing at the time of hardware interrupt is likewise not predictable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

The system doesn’t always execute driver code in an arbitrary thread context

A

A driver can create its own system threads by
calling PsCreateSystemThread. A driver can also ask the system to call it back in the context of a system thread by scheduling a work item. In these situations, we consider the thread context to be nonarbitrary.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Thread block in an arbitrary thread

A

driver shouldn’t block

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

When a driver shouldn’t block

A
  • In an arbitrary thread

* When a driver creates an IRP to send to some other driver

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

IRP in an arbitrary thread

A

Asynchronous IRP. The I/O Manager doesn’t tie an asynchronous IRP to any particular thread

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

IRP in a nonarbitrary thread

A

Synchronous IRP. The I/O Manager ties the synchronous kind of IRP to the thread within which you
create the IRP. It will cancel the IRP automatically if that thread terminates.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Symmetric Multiprocessing

A

In this model, each CPU is treated exactly like every other CPU with respect to thread scheduling. Each CPU has its own current thread. It’s perfectly possible for the I/O Manager, executing in the context of the threads running on two or more CPUs, to call subroutines in your driver simultaneously.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Function driver

A

It understands all the details about how to make
the hardware work. It’s responsible for initiating I/O operations, for handling the interrupts that occur when those operations finish, and for providing a way for the end user to exercise any control over the device that might be appropriate.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Bus driver

A

It’s responsible for managing the connection between

the hardware and the computer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

PDO

A

physical device object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

FDO

A

function device object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

FiDO

A

filter device object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Plug and Play device

A

Is one that has an electronic signature that a bus driver can interrogate to learn the identity of a device.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Basic Data Structures

A

the driver object and the device object

25
Q

Driver object

A

represents the driver itself and contains pointers to all the driver subroutines that the system will ever call on its own motion.

26
Q

Device object

A

represents an instance of hardware and contains

data to help you manage that instance

27
Q

DeviceObject (PDEVICE_OBJECT)

A

anchors a list of device object data structures, one for each of the devices managed by the driver. The I/O Manager links the device objects together and maintains this field. The DriverUnload function of a non-WDM driver would use this field to traverse the list of device objects in order to delete them. A WDM driver probably doesn’t have any particular need to use this field.

28
Q

DeviceObject (PDEVICE_OBJECT)

A

anchors a list of device object data structures, one for each of the devices managed by the driver. The I/O Manager links the device objects together and maintains this field. The DriverUnload function of a non-WDM driver would use this field to traverse the list of device objects in order to delete them. A WDM driver probably doesn’t have any particular need to use this field.

29
Q

DriverExtension (PDRIVER_EXTENSION)

A

points to a small substructure within which only the AddDevice (PDRIVER_ADD_DEVICE) member is accessible to the likes of us. AddDevice is a pointer to a function within the driver that creates device objects

30
Q

HardwareDatabase (PUNICODE_STRING)

A

describes a string that names a hardware database registry key for the device. This
is a name like Registry\Machine\Hardware\Description\System and names the registry key within which resource allocation
information resides. WDM drivers have no need to access the information below this key because the PnP Manager performs resource allocation automatically. The name is stored in Unicode

31
Q

FastIoDispatch (PFAST_IO_DISPATCH)

A

points to a table of function pointers that file system and network drivers export.

32
Q

DriverStartIo (PDRIVER_STARTIO)

A

points to a function in your driver that processes I/O requests that the I/O Manager has serialized for you.

33
Q

DriverUnload (PDRIVER_UNLOAD)

A

points to a cleanup function in your driver.

34
Q

MajorFunction (array of PDRIVER_DISPATCH)

A

is a table of pointers to functions in your driver that handle each of the roughly two dozen types of I/O requests. This table is also something of a big deal, as you might guess, because it defines how I/O requests make it into your code.

35
Q

DriverObject (PDRIVER_OBJECT)

A

points to the object describing the driver associated with this device object, usually the one that called IoCreateDevice to create it.

36
Q

DriverObject (PDRIVER_OBJECT)

A

points to the object describing the driver associated with this device object, usually the one that called IoCreateDevice to create it.

37
Q

NextDevice (PDEVICE_OBJECT)

A

points to the next device object that belongs to the same driver as this one. This field is the
one that links device objects together starting from the driver object’s DeviceObject member. There’s probably no reason for a WDM driver to use this field. That’s just as well because proper use of this pointer requires synchronization using an internal
system lock that’s not exposed for access by device drivers.

38
Q

CurrentIrp (PIRP)

A

is used by the Microsoft IRP queuing routines StartPacket and StartNextPacket to record the IRP most
recently sent to your StartIo routine. WDM drivers should implement their own IRP queues (see Chapter 5) and may have no use for this field.

39
Q

Flags (ULONG)

A

contains a collection of flag bits

40
Q

Characteristics (ULONG)

A

is another collection of flag bits describing various optional characteristics of the device. The I/O Manager initializes these flags based on an argument to IoCreateDevice. Filter drivers propagate some of them upward in the device stack

41
Q

DeviceExtension (PVOID)

A

points to a data structure you define that will hold per-instance information about the device. The I/O Manager allocates space for the structure, but its name and contents are entirely up to you. A common convention is to declare a structure with the type name DEVICE_EXTENSION. To access it given a pointer (for example, fdo) to the device object, use a statement like this one:

42
Q

DeviceType (DEVICE_TYPE)

A

is an enumeration constant describing what type of device this is. The I/O Manager initializes
this member based on an argument to IoCreateDevice. Filter drivers might conceivably need to inspect it

43
Q

StackSize (CCHAR)

A

counts the number of device objects starting from this one and descending all the way to the PDO. The
purpose of this field is to inform interested parties regarding how many stack locations should be created for an IRP that will be sent first to this device’s driver. WDM drivers don’t normally need to modify this value, however, because the support routine they use for building the device stack (IoAttachDeviceToDeviceStack) does so automatically.

44
Q

AlignmentRequirement (ULONG)

A

specifies the required alignment for data buffers used in read or write requests to this device.

45
Q

DriverEntry Routine

A

Do the global initialization that the driver

needs to perform only once when it’s loaded for the first time

46
Q

NTSTATUS

A

Always return NTSTATUS

47
Q

DriverEntry Routine first argument

A

The first argument to DriverEntry is a pointer to a barely initialized driver object that represents your driver. A WDM driver’s DriverEntry function will finish initializing this object and return.

48
Q

DriverEntry Routine second argument

A

is the name of the service key in the registry. This string is not persistent—you must copy it if you plan to use it later. In a WDM driver, the only use I’ve ever made of this string is as part of WMI registration

49
Q

WDM job in DriverEntry

A

A WDM driver’s main job in DriverEntry is to fill in the various function pointers in the driver object. These pointers indicate to the operating system where to find the subroutines you’ve decided to place in your driver container

50
Q
  • DriverUnload
A

Set this to point to whatever cleanup routine you create. The I/O Manager will call this routine just prior to unloading the driver. If there’s nothing to clean up, you need to have a DriverUnload function for the system to be able to unload your driver dynamically.

51
Q
  • DriverExtension->AddDevice
A

Set this to point to your AddDevice function. The PnP Manager will call AddDevice once for each hardware instance you’re responsible for

52
Q
  • DriverStartIo
A

If your driver uses the standard method of queuing I/O requests, you’ll set this member of the driver object to point to your StartIo routine

53
Q
  • MajorFunction
A

The I/O Manager initializes this vector of function pointers to point to a dummy dispatch function that fails every request. You’re presumably going to be handling certain types of IRPs—otherwise, your driver is basically going to be deaf and inert—so you’ll set at least some of these pointers to your own dispatch functions.

54
Q

Handle IRPs

A

Every WDM driver must handle PNP, POWER, and SYSTEM_CONTROL I/O requests, and it should handle
SYSTEM_CONTROL I/O requests

55
Q

DriverUnload

A

The purpose of a WDM driver’s DriverUnload function is to clean up after any global initialization that DriverEntry might have done. If your DriverEntry routine returns a failure status, the system doesn’t call your DriverUnload routine. Therefore, if DriverEntry generates any side effects that need cleaning up prior to returning an error status, DriverEntry has to perform the cleanup.

56
Q

AddDevice Routine

A

a driver might be called upon to manage more than one actual device. In the WDM architecture, a driver has a special AddDevice function that the PnP Manager can call for each such device.
The basic responsibility of AddDevice in a function driver is to create a device object and link it into the stack rooted in this PDO. The steps involved are as follows:
1. Call IoCreateDevice to create a device object and an instance of your own device extension object.
2. Register one or more device interfaces so that applications know about the existence of your device. Alternatively, give the device object a name and then create a symbolic link.
3. Next initialize your device extension and the Flags member of the device object.
4. Call IoAttachDeviceToDeviceStack to put your new device object into the stack.

57
Q

ISR

A

interrupt service routine

58
Q

DPC

A

deferred procedure call