Remove some inappropriate uses of __attribute__((packed))
commit590cb6d21c857534d940c4c0a165a9997826a0b0
authorJiří Zárevúcky <zarevucky.jiri@gmail.com>
Sun, 22 Oct 2023 15:39:53 +0000 (22 17:39 +0200)
committerJiří Zárevúcky <zarevucky.jiri@gmail.com>
Sun, 22 Oct 2023 15:53:32 +0000 (22 17:53 +0200)
tree8f171556f1b017348dd7df803caffa30917ad9e9
parentf4a42661db08a6e215d28ae55d64213d298d7424
Remove some inappropriate uses of __attribute__((packed))

__attribute__((packed)) means "ignore all alignment requirements
on members of this structure". This is useful if one needs to
map onto a structure in memory that has misaligned fields on purpose,
but those cases are extremely rare.

The side effect of the attribute is that taking a pointer to any
field longer than a single byte, and dereferencing that pointer,
is unsound and may crash the program on architectures that care
about memory alignment when reading/writing multibyte values.

Newer GCC versions can detect some of those unsafe cases and
produce a warning for it. This commit only removes those cases.

However, most, if not all, uses of ((packed)) in HelenOS
are unnecessary and a product of misunderstanding what the
attribute actually does. A common misconception is that it is
needed to avoid compiler adding arbitrary padding into the
structure, but that is simply not true. There is exactly one
correct memory layout for any C structure, because there must
be one layout for binary interoperability to exist and the one
everyone uses (except perhaps some goblin who just wants to break
things for fun) is the trivial best layout possible with given
constraints.
uspace/drv/bus/usb/xhci/hw_struct/common.h
uspace/drv/bus/usb/xhci/hw_struct/context.h
uspace/lib/ext4/include/ext4/types.h