Writing Device Drivers

How Structure Macros Work

In a 64-bit device driver, these macros do all that is necessary to use the same piece of kernel memory as a buffer for the contents of the native form of the data structure (that is, the LP64 form), and for the ILP32 form of the same structure. This usually means that each structure access is implemented by a conditional expression. When compiled as a 32-bit driver, since there is only one supported data model, there is only native form, so no conditional expression is used.

The 64-bit versions of the macros depend on the definition of a shadow version of the data structure which describes the 32-bit interface using fixed-width types. The name of the shadow data structure is formed by appending "32" to the name of the native data structure. It is convenient to place the definition of the shadow structure in the same file as the native structure to ease future maintenance costs.

The macros take arguments such as:


The structure name (as would appear after the struct keyword) of the native form of the data structure


A flag word containing the user data model, such as FILP32 or FLP64, extracted from the mode parameter of ioctl(9E)


The name used to refer to a particular instance of a structure which is manipulated by these macros


The name of the field within the structure