Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 12 Aug 2000 20:32:58 +1200
From:      "MATTHEW JOHN,LUCKIE" <mjl12@waikato.ac.nz>
To:        "'freebsd-alpha@freebsd.org'" <freebsd-alpha@freebsd.org>
Subject:   kernel modules/unaligned access fault
Message-ID:  <45E87454FFC2D211AD9800508B650094BA4E3E@stu-ex1.waikato.ac.nz>

next in thread | raw e-mail | index | archive | help
Hi

I have created a specialised kernel module for an application i writing that
causes an ip packet to be created in kernel-land, timestamped, and then
sent.  I developed and tested this on a pentium machine, before trying it on
a spare alpha that i have turned into a freebsd 4.0-release box for mucking
around on.

this module is loaded via kldload and called via syscall

I am running into problems with the timestamping, whereby i am getting an
unaligned access fault panic.
I am making a call to getnanotime, with the results getting copied into a
bit of data in the mbuf that is offset 48 bytes in the packet

Here is the segment of code that is causing the problem:

struct pathrecord
{
  struct in_addr  ip; /* 4 bytes */
  struct timespec ts; /* 8 bytes */
};

in function code:

struct timespec   ts;
struct mbuf       *m;
struct pathrecord *pr;
u_int32_t         *ui;

m                = m_gethdr(M_DONTWAIT, MT_HEADER);
m->m_len         = 56;
m->m_pkthdr.len  = m->m_len;
m->m_pktdr.rcvif = NULL;

[... the ip packet and some other headers are now filled out ...]

/* if i take this 3 line block of code out, i dont get the faults */
m->m_data += 40;
ui = mtod(m, u_int32_t *);
*ui = 0;

m->m_data += 4; /* 44 bytes offset */
pr = mtod(m, struct pathrecord *pr);
pr->ip = 0;
getnanotime(&ts);
ts.ts_sec = htonl(ts.ts_sec);
ts.ts_nsec = htonl(ts.ts_nsec);
pr->ts = ts; /* crashes in this line, 44 bytes offset from m_data */

and here is the fault dumped from the operating system

fatal kernel trap:
trap entry = 0x4 (unaligned access fault)
a0         = 0xfffffe0000617e64
a1         = 0x2d
a2         = 0x1
pc         = 0xfffffe0000a5ad6c
ra         = 0xfffffe0000a5ad5c
curproc    = 0xfffffe0007bb50c0

pid = 197, comm = test
panic: trap

i know this is because i am not working with the alpha cpu how i should be,
but i dont really know what the story is with offsetting on non - 8bit
boundaries.  What should I do to correct my bug?

i also know this is not the most efficient use of coding - i should just be
working with data in the mbuf and not copying the timespec structure in, but
i was just wanting to narrow the bug right down.

Any suggestions will be welcome

Thanks

Matthew Luckie
mjl12@waikato.ac.nz


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-alpha" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?45E87454FFC2D211AD9800508B650094BA4E3E>