Subject: Re: lib/1116: memory xdr streams do unaligned accesses
To: der Mouse <mouse@Collatz.McRCIM.McGill.EDU>
From: Keith Moore <moore@cs.utk.edu>
List: netbsd-bugs
Date: 06/05/1995 16:34:25
> >Description:
> 	An XDR stream created with xdrmem_create works only if the
> 	memory block handed to xdrmem_create() is 32bit-aligned,
> 	because xdrmem_getlong and xdrmem_putlong store through pointer
> 	casts.  If the block is unaligned, depending on the machine, it
> 	may (a) work fine, (b) work but with a performance penalty, (c)
> 	coredump, or (d) silently access memory one to three bytes
> 	earlier than it should.  (BTW, does NetBSD run on any machines
> 	that would do (d)?)

well, there's been talk of a port to the RT, some models of which (I
think) do (d).

> 
> >Fix:
> 	(a) Change the docs to note that the memory area must be
> 	    32bit-aligned,
> 	(b) Make xdrmem_getlong and xdrmem_putlong do four one-byte
> 	    loads/stores instead,
> 	(c) Duplicate enough internals so that there are two versions
> 	    of xdrmem_{ge,pu}tlong, one for aligned and one for
> 	    unaligned, and have xdrmem_create choose the correct ops
> 	    vector depending on the alignment of its argument.

There's also (a'): change xdrmem_create() so that it fails if given an
unaligned buffer.  (It could do so by storing NULL in the buffer
pointer in the XDR structure passed to xdrmem_create, so that the
program would core dump when it tried to use xdr_xxx to stuff anything
in that buffer.  Or xdrmem_create() could write a message to stderr
and call abort())

As far as I'm concerned, it's perfectly reasonable to require that
xdr's buffers be word-aligned.

Keith Moore