John, OK, maybe you are right and the current status quo was just an accident. I am curious what do you and other people think about expressing expected structure size and padding more explicitly instead of trying to accommodate for sometimes intricate play between alignment and type size with something like char[N]? I.e. along the following lines:
#if __WORDSIZE < 64 #define MD_IOCTL_LEN 436 #else #define MD_IOCTL_LEN 448 #endif struct md_ioctl { union { struct _md_ioctl_payload { unsigned version; /* Structure layout version */ unsigned unit; /* unit number */ enum md_types type ; /* type of disk */ char *file; /* pathname of file to mount */ off_t mediasize; /* size of disk in bytes */ unsigned sectorsize; /* sectorsize */ unsigned options; /* options */ u_int64_t base; /* base address */ int fwheads; /* firmware heads */ int fwsectors; /* firmware sectors */ char *label; /* label of the device */ } md; char raw[MD_IOCTL_LEN]; /* payload + padding for future ideas */ }; }; CTASSERT(sizeof(struct md_ioctl) == MD_IOCTL_LEN); I've tested that it DTRT on i386 and amd64, need to validate on ARM and MIPS. The code impact should be minimal and easy to apply, i.e. ptr->md_ywz becomes ptr->md.xyz. On Tue, Aug 29, 2017 at 7:30 AM, John Baldwin <j...@freebsd.org> wrote: > On Monday, August 28, 2017 04:40:49 PM Maxim Sobolev wrote: > > John, well, this depends on how you look at it. The padding element size > is > > "int", which when you account for the alignment has the nice property on > > both 32 and 64-bit arches that no matter what kind of element you add > > (char, short, int or void *), you only need to bring down MDNPAD by 1 to > > keep the structure size the same. > > That's only true once. Add a second pointer and this trick won't work > again > on 64-bit platforms. It only worked this time by accident because there > was > unaccounted-for padding at the end of the structure, not on purpose. In > other places in the tree where ABI is more carefully maintained we use > explicit spare pointers or spare longs instead (e.g. padding in > kinfo_proc). > > -- > John Baldwin > > -- Maksym Sobolyev Sippy Software, Inc. Internet Telephony (VoIP) Experts Tel (Canada): +1-778-783-0474 Tel (Toll-Free): +1-855-747-7779 Fax: +1-866-857-6942 Web: http://www.sippysoft.com MSN: sa...@sippysoft.com Skype: SippySoft _______________________________________________ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"