I'm doing a kernel mode driver, and I've run into a bit of a bug when running the code on 64-bit.
The code runs fine on 32-bit, but when I build/run in amd64 I'm getting strange results. I read up a little on 64 bit pointers and addressing vs 32bit vs 16bit (in win32) and I'm sure I'm missing something regarding the fundamentals of pointers in the 64bit architecture.
Here is the C code that works just fine in 32-bit. ncImageLoadEventSettings.buff
is a char*
and ncILHead->count
is simply an int.
// Calculate offset
pnt = (void*)(ncImageLoadEventSettings.buff + sizeof(struct NC_IL_HEAD) + (ncILHead->count * sizeof(struct NC_IL_INFO)));
This code calculates the address at which to write a struct object onto a buffer (beginning at .buff
), which works perfectly fine in 32-bit mode.
It should be noted that the program reading this buffer is 32-bit. I think I read somewhere that structs in 64-bit mode are different sizes than those in 32-bit mode.
The 32-bit reader program reads some of the buffer's contents just fine, while the majority of the entries are garbage.
Is this the proper way to calculate addresses, or might there be an issue with the 64-bit vs 32-bit reader application that is reading that buffer?
See http://en.wikipedia.org/wiki/Data_structure_alignment#Typical_alignment_of_C_structs_on_x86
In general, pointers are larger (64bit), and most fields that are of 64bit size (including pointers) will be aligned (with added padding).
I'm doing a kernel mode driver, and I've run into a bit of a bug when running the code on 64-bit.
The code runs fine on 32-bit, but when I build/run in amd64 I'm getting strange results. I read up a little on 64 bit pointers and addressing vs 32bit vs 16bit (in win32) and I'm sure I'm missing something regarding the fundamentals of pointers in the 64bit architecture.
Here is the C code that works just fine in 32-bit. ncImageLoadEventSettings.buff
is a char*
and ncILHead->count
is simply an int.
// Calculate offset
pnt = (void*)(ncImageLoadEventSettings.buff + sizeof(struct NC_IL_HEAD) + (ncILHead->count * sizeof(struct NC_IL_INFO)));
This code calculates the address at which to write a struct object onto a buffer (beginning at .buff
), which works perfectly fine in 32-bit mode.
It should be noted that the program reading this buffer is 32-bit. I think I read somewhere that structs in 64-bit mode are different sizes than those in 32-bit mode.
The 32-bit reader program reads some of the buffer's contents just fine, while the majority of the entries are garbage.
Is this the proper way to calculate addresses, or might there be an issue with the 64-bit vs 32-bit reader application that is reading that buffer?
See http://en.wikipedia.org/wiki/Data_structure_alignment#Typical_alignment_of_C_structs_on_x86
In general, pointers are larger (64bit), and most fields that are of 64bit size (including pointers) will be aligned (with added padding).
0 commentaires:
Enregistrer un commentaire