![]() ![]() ![]() This means that any code snippets such as ULONG ulSlotPhysAddr Whether the shorter type is extended by filling with the sign bit or with zeros is well defined for each Win64 function. If one type is shorter than the other, it must be extended when converting to the longer type. Inline Win64 functions such as PtrToUlong and UlongToPtr safely convert between pointer and integer types without relying on assumptions about the relative sizes of these types. Instead, you should access the QuadPart of this member, as shown in the following: PUSHORT pBase = (PUSHORT)FindTranslatedPort(0)->u. // correct The following code shows what not to do: PUSHORT pBase = (PUSHORT)FindTranslatedPort(0)->u. // wrongĪgain, this can truncate the pointer. Start member of this structure is a PHYSICAL_ADDRESS pointer to the base address. For example, the FindTranslatedPort macro returns a pointer to a CM_PARTIAL_RESOURCE_DESCRIPTOR structure that contains the base address of an I/O port. To avoid truncating a 64-bit address, you should access the structure's QuadPart member rather than its LowPart member when copying an address into the structure or reading an address from the structure. This preserves all 64 bits of the pointer value.Ī resource list stores the physical address of a resource in a structure of type PHYSICAL_ADDRESS (see IResourceList). Irp->IoStatus.Information = (ULONG_PTR)pDeviceRelations // correct The correct approach is to cast the pointer to ULONG_PTR, as shown in the following: PDEVICE_RELATIONS pDeviceRelations This code sample erroneously casts the pDeviceRelations pointer to type ULONG, which can truncate the pointer value if sizeof(pDeviceRelations) > sizeof(ULONG). Irp->IoStatus.Information = (ULONG)pDeviceRelations // wrong The following code shows what not to do when copying a 64-bit pointer value to this field: PDEVICE_RELATIONS pDeviceRelations An unsigned integer of type DWORD_PTR or ULONG_PTR is always large enough to store the entire pointer, regardless of whether the code is compiled for a 32- or 64-bit machine.įor example, the IRP pointer field IoStatus. A better approach is to cast the pointer to type DWORD_PTR or ULONG_PTR. Casting a pointer to type DWORD or ULONG can cause a 64-bit pointer to be truncated. For 64-bit code, this assumption is dangerous. ![]() Programmers with experience writing code for 32-bit machines might be used to assuming that a pointer value fits into a DWORD or ULONG. Some of the pitfalls that you might encounter in writing a 64-bit audio driver are described below.įirst and foremost, a potential problem to look for in existing 32-bit driver code is conversion between pointer types and integer types such as DWORD or ULONG. If you are writing a 64-bit driver or writing a driver that can be compiled to run on both 32- and 64-bit systems, follow the porting guidelines in Driver Programming Techniques. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |