|
From: Henry N. <hen...@ar...> - 2011-01-10 22:41:21
|
Hello Vladislav,
On 10.01.2011 21:36, Vladislav Grishenko wrote:
> Dear Henry,
>
> My Windows 7 x86 installation goes into BSOD right on/after console attach.
> I've bisected it to recent r1560 changeset introduced co_offsetof macro.
>
>> size = (char*)(&message->putcs + 1) - (char*)message + bytes_per_line;
> Original construction means the struct length, excluding the member plus
> size of one member, not its offset actually.
>
>> #define co_offsetof(TYPE, MEMBER) ((int)&((TYPE *)0)->MEMBER)
>> size = co_offsetof(co_console_message_t, putcs) + 1 + bytes_per_line;
> New one means the struct length excluding the member + one byte, that's
> seems wrong.
>
> So, to keep co_offsetof macro and restore binary compability, I suggest
> following changes:
>> #define co_offsetof(TYPE, MEMBER) ((int) (&((TYPE *)0)->MEMBER))
>> size = co_offsetof(co_console_message_t, putcs + 1) + bytes_per_line;
many thanks for pointing to that bug!
You are right, that this should give the size for struct without the
data self.
The +1 was to point directly behind the element "putcs".
Your changes was not working on my test with gcc 4.4.1:
// Building:
// DIR=$HOME/colinux/build/devel-gcc412.svn
// gcc -m32 -I$DIR/linux-2.6.33.5-source/include
-I$DIR/linux-2.6.33.5-build/include
-I$DIR/linux-2.6.33.5-source/arch/x86/include foo.c
#include <stdio.h>
#include <linux/cooperative.h>
#define bytes_per_line 0
#define co_offsetof(TYPE, MEMBER) ((int) &((TYPE *)0)->MEMBER)
int main()
{
co_console_message_t*<->message;
int size1 = (char*)(&message->putcs + 1) - (char*)message +
bytes_per_line; // old
int size2 = co_offsetof(co_console_message_t, putcs) + 1 +
bytes_per_line; // Henry
int size3 = co_offsetof(co_console_message_t, putcs + 1) +
bytes_per_line; // Vladislav
int size4 = co_offsetof(co_console_message_t, putcs.data) +
bytes_per_line; // right
return printf("%d %d %d %d\n", size1, size2, size3, size4);
}
Result:
10 5 5 10
So, the right calculation would be:
- size = co_offsetof(co_console_message_t, putcs) + 1 +
bytes_per_line;
+ size = co_offsetof(co_console_message_t, putcs.data) +
bytes_per_line;
--
Henry N.
|