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.