The kdump data stream is an unaligned data stream for stat and

sockaddr structures.  As such, we have top copy the data structure
into a local buffer before we can reference it, otherwise we have
unaligned references (these are fixed up automatically on some CPUs,
but not on others).  We do this unconditionally to make the code
easier to read and understand.

Submitted by:	Grzegorz Bernacki
This commit is contained in:
Warner Losh 2010-02-18 16:05:09 +00:00
parent c0f29c6e1d
commit 30c1278f14
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=204045

View File

@ -1328,6 +1328,8 @@ ktrstruct(char *buf, size_t buflen)
char *name, *data; char *name, *data;
size_t namelen, datalen; size_t namelen, datalen;
int i; int i;
struct stat sb;
struct sockaddr_storage ss;
for (name = buf, namelen = 0; for (name = buf, namelen = 0;
namelen < buflen && name[namelen] != '\0'; namelen < buflen && name[namelen] != '\0';
@ -1348,12 +1350,16 @@ ktrstruct(char *buf, size_t buflen)
if (strcmp(name, "stat") == 0) { if (strcmp(name, "stat") == 0) {
if (datalen != sizeof(struct stat)) if (datalen != sizeof(struct stat))
goto invalid; goto invalid;
ktrstat((struct stat *)data); memcpy(&sb, data, datalen);
ktrstat(&sb);
} else if (strcmp(name, "sockaddr") == 0) { } else if (strcmp(name, "sockaddr") == 0) {
if (datalen < sizeof(struct sockaddr) || if (datalen > sizeof(ss))
datalen != ((struct sockaddr *)(data))->sa_len)
goto invalid; goto invalid;
ktrsockaddr((struct sockaddr *)data); memcpy(&ss, data, datalen);
if (datalen < sizeof(struct sockaddr) ||
datalen != ss.ss_len)
goto invalid;
ktrsockaddr((struct sockaddr *)&ss);
} else { } else {
printf("unknown structure\n"); printf("unknown structure\n");
} }