mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-18 10:35:55 +00:00
Fix unaligned memory accesses on Alpha and possible other platforms.
By using a pointer to struct dos_partition, we implicitly tell the compiler that the pointer is 4-bytes aligned, even though we know that's not the case. The fact that we only dereference the pointer to access a byte-wide field (field dp_ptyp) is not a guarantee that the compiler will in fact use a byte-wide load. On some platforms it's more efficient to use long word or quad word loads and use bit-shifting and bit-masking to get the intended byte. On those platforms an misaligned load will be the result. The fix is to use byte-wide pointer arithmetic based on sizeof() and offsetof() to avoid invalid casts which avoids that the compiler makes invalid assumptions. Backtrace provided by: wilko@ MFC after: 1 week
This commit is contained in:
parent
49ddabdfce
commit
ae04949bff
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=159238
@ -358,8 +358,8 @@ g_gpt_ctl_remove(struct gctl_req *req, const char *flags, struct g_geom *gp,
|
||||
static int
|
||||
g_gpt_has_pmbr(struct g_consumer *cp, int *error)
|
||||
{
|
||||
struct dos_partition *part;
|
||||
char *buf;
|
||||
uint8_t *typ;
|
||||
int i, pmbr;
|
||||
uint16_t magic;
|
||||
|
||||
@ -373,9 +373,10 @@ g_gpt_has_pmbr(struct g_consumer *cp, int *error)
|
||||
if (magic != DOSMAGIC)
|
||||
goto out;
|
||||
|
||||
part = (struct dos_partition *)(uintptr_t)(buf + DOSPARTOFF);
|
||||
for (i = 0; i < 4; i++) {
|
||||
if (part[i].dp_typ != 0 && part[i].dp_typ != DOSPTYP_PMBR)
|
||||
typ = buf + DOSPARTOFF + i * sizeof(struct dos_partition) +
|
||||
offsetof(struct dos_partition, dp_typ);
|
||||
if (*typ != 0 && *typ != DOSPTYP_PMBR)
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user