From owner-freebsd-alpha Sat Aug 12 1:33:20 2000 Delivered-To: freebsd-alpha@freebsd.org Received: from mailserv.waikato.ac.nz (mailserv.waikato.ac.nz [130.217.66.61]) by hub.freebsd.org (Postfix) with ESMTP id B4ED837BC4E for ; Sat, 12 Aug 2000 01:33:08 -0700 (PDT) (envelope-from mjl12@waikato.ac.nz) Received: from stu_ex3.waikato.ac.nz (stu-ex3.waikato.ac.nz [130.217.70.30]) by mailserv.waikato.ac.nz (8.9.3/8.9.0) with ESMTP id UAA82026 for ; Sat, 12 Aug 2000 20:37:13 +1200 Received: by stu-ex3.waikato.ac.nz with Internet Mail Service (5.5.2650.21) id ; Sat, 12 Aug 2000 20:33:05 +1200 Message-ID: <45E87454FFC2D211AD9800508B650094BA4E3E@stu-ex1.waikato.ac.nz> From: "MATTHEW JOHN,LUCKIE" To: "'freebsd-alpha@freebsd.org'" Subject: kernel modules/unaligned access fault Date: Sat, 12 Aug 2000 20:32:58 +1200 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: text/plain Sender: owner-freebsd-alpha@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org 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