[AP-UTILS] Bus Error on Linux/Sparc
Erik Rossen
ap-utils@kiev.iorta.com
Wed, 31 Jul 2002 14:36:37 +0200
--XSEVMyPRvc8xgDhM
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
On Wed, Jul 31, 2002 at 09:52:46AM +0200, Erik Rossen wrote:
> On Mon, Jul 29, 2002 at 08:28:34AM +0000, Eric Heydrick wrote:
> > With ap-utils 1.0.3 on Debian 3.0/Sparc, I'm getting a "Bus error" when=
I=20
> > select Info-> SysInfo in ap-atmel. When I try to get Ethernet or Wirele=
ss=20
> > info, it just sits there without displaying any info.
> > Seems this could be a Sparc related issue. Any clues?
>=20
> I have a Sunblade 100 running woody and I get a bus error too.
>=20
> If I use gdb:
> Program received signal SIGBUS, Bus error.
> 0x0001a240 in sysinfo () at sysinfo.c:87
> 87Statio sprintf(message, _("ProductType: %lu"),
> HardConf->ProductType);
> (gdb) print &HardConf->ProductType
> $1 =3D (long unsigned int *) 0x7b4ca
>=20
> Unfortunately, 0x7b4ca is not aligned on a 4-byte boundary, thus the
> bus error when trying to access HardConf->ProductType.
>=20
> Two things that I do not understand:
>=20
> 1. I thought that gcc automatically aligns elements of structs if the
> architecture of the machine requires it???
>=20
> 2. Why doesn't gdb give a Bus error if I go:
> (gdb) print HardConf->ProductType
> $2 =3D 0
> ???
Just continuing with my reply...
1. gcc *does* align the fields of a struct
2. still don't know
The problem seems to be coming from the fact that raw structs are being
used to unpack information coming from SNMP requests. One of the hard
lessons to learn in C is *never* use structs to unpack a data stream -
always parse it piece-by-piece, even if it is painfully unelegant. This
is also necessary for taking care of endianess conversion.
Although I am not following the above advice, here is a quick patch to
ap-utils-1.0.3/atmel/sysinfo.c to get the sysinfo working, just to
demonstrate that alignment was the problem. malloc()s are usually fully
aligned by default.
73c73,74
< HardConf =3D (struct HARD_CONFIGURATION_STUCT *) varbinds[1].value;
---
> HardConf =3D malloc(varbinds[1].len_val);
> memcpy(HardConf, varbinds[1].value, varbinds[1].len_val);
This software will probably never reliably work on any architecture
except i386 until it is re-written to not use structs for unpacking. I
feel sorry for the guy who posted an ITP on debian-devel: he has a lot
of work in front of him.
--=20
Erik Rossen ^ OpenPGP key: 2935D0B9
rossen@freesurf.ch /e\ "Use GnuPG, see the
http://people.linux-gull.ch/rossen --- black helicopters."
--XSEVMyPRvc8xgDhM
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE9R9nUY88aPik10LkRAtwCAKC6tEVW2c0z3xD0TJKkNvzKXksaHQCcC+lT
i/VttXb1rGrZCIweiD4tkuQ=
=/VmZ
-----END PGP SIGNATURE-----
--XSEVMyPRvc8xgDhM--