On Mon, Mar 9, 2015 at 7:14 AM, Denys Vlasenko <[email protected]> wrote:
> On Mon, Mar 9, 2015 at 2:43 PM, Andy Lutomirski <[email protected]> wrote:
>>>         /* Offset from the sysenter stack to tss.sp0 */
>>>         DEFINE(TSS_sysenter_sp0, offsetof(struct tss_struct, x86_tss.sp0) -
>>> -                sizeof(struct tss_struct));
>>> +               (offsetof(struct tss_struct, SYSENTER_stack_last_word) + 
>>> 4));
>>
>> Is there no way to do this using sizeof to avoid having a "last_word" member.
>
> sizeof of a structure member? IIRC in C sizeof can't be used for that.
> You need to concoct a fictitious object, dereference its member
> and take sizeof of _that_.
>
> It would look horrible. Something like:
>
> offsetof(struct tss_struct, SYSENTER_stack) +
>                 sizeof(((struct tss_struct*)NULL)->SYSENTER_stack)

vfio.h has:

/**
 * offsetofend(TYPE, MEMBER)
 *
 * @TYPE: The type of the structure
 * @MEMBER: The member within the structure to get the end offset of
 *
 * Simple helper macro for dealing with variable sized structures passed
 * from user space.  This allows us to easily determine if the provided
 * structure is sized to include various fields.
 */
#define offsetofend(TYPE, MEMBER) \
        (offsetof(TYPE, MEMBER) + sizeof(((TYPE *)0)->MEMBER))

we could stick that in stdef.h and use it.

--Andy
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to