Introduction to Virtual Device Drivers


Guidelines for Designing and Writing a Driver



Download 274.5 Kb.
Page44/80
Date19.01.2022
Size274.5 Kb.
#58083
1   ...   40   41   42   43   44   45   46   47   ...   80
VXDS

Guidelines for Designing and Writing a Driver


When designing and writing your device driver, follow these guidelines:

Make every effort to make your device driver as small as possible; reserve system memory for applications.



  • Use multiple, discardable code segments to help reduce the amount of driver code needed in memory at any given time.

  • Use an automatic data segment only if necessary.

  • Make resources discardable, and lock them in memory only when needed.

  • Use the stack sparingly. Because device drivers use the stack of the application that initiated the call to the driver, there is no way for the driver to determine how much available space is on the stack.

  • Check for NULL pointers to avoid a general protection fault from using an invalid selector.

  • Check the segment limits when reading from or writing to allocated segments to avoid a general protection fault from attempting to access data beyond the end of a segment.

  • Use the __ahincr constant when creating selectors for huge memory (allocated memory greater than 64 kilobytes). Other methods of selector arithmetic can create invalid selectors and cause general protection faults.

  • Create code-segment aliases for any code to be executed from data segments. Attempting to call or jump to a data segment address generates a general protection fault.



Download 274.5 Kb.

Share with your friends:
1   ...   40   41   42   43   44   45   46   47   ...   80




The database is protected by copyright ©ininet.org 2024
send message

    Main page