The following is a summary of guidelines
for memory allocation and usage in kernel-mode drivers.
·
Do not make assumptions about the
hardware platform, the pointer size, or the location or size of the virtual
address spaces. Make your driver platform-independent by using macros, types,
and system-defined constants, such as PHYSICAL_ADDRESS, PAGE_SIZE, and so
forth.
·
Lay out data structures
efficiently, considering natural and cache-line alignment and the processor
page size. When possible, reuse allocated data structures. For more information
about using memory efficiently, see “Six Tips for Efficient Memory Use,” which
is listed in the Resources section at the end of this paper.
·
Allocate only as much memory as
your device and driver require for normal operations.
·
Always check the translated
resources to determine whether your device registers are mapped into memory or
I/O space.
·
Do not allocate excessive
amounts of memory that your driver might never use. Your device must coexist with
other hardware and applications.
·
Use the system’s DMA routines.
Replacing them with your own routines is almost guaranteed to cause your driver
to fail on some hardware configurations.
·
Use lookaside lists when your
driver needs fixed-size, reusable buffers.
·
Test your driver with as many
different tools, and on as many different hardware configurations, as possible.
0 komentar:
Posting Komentar