Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 16 Jun 2003 21:13:13 +1000 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        Don Lewis <truckman@FreeBSD.org>
Cc:        freebsd-arch@FreeBSD.org
Subject:   Re: Message buffer and printf reentrancy patch 
Message-ID:  <20030616205631.F28116@gamplex.bde.org>
In-Reply-To: <200306161048.h5GAmMM7048782@gw.catspoiler.org>
References:  <200306161048.h5GAmMM7048782@gw.catspoiler.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 16 Jun 2003, Don Lewis wrote:

> On 16 Jun, Bruce Evans wrote:
> > On Sun, 15 Jun 2003, Ian Dowse wrote:
> >> >> ...
> >> >> +#define MSGBUF_SEQSUB(mbp, seq1, seq2) (MSGBUF_SEQNORM(mbp, (seq1) - (seq2)
> > ...
> > This problem and many casts could be avoided by using unsigned types
> > for most of the msgbuf fields.  I forget the details of why we changed
> > them back to signed.  The log message for msgbuf.h 1.19 says that this
> > is because we perform signed arithmetic on them.  The details for this,
> > can probably be handled by the macros now.
>
> Using unsigned types was the first thing that I thought of.  I was
> wondering if the reason that this wasn't done was some sort of
> portability problem with the atomic operations.

MSG_SEQSUB() takes differences of sequence numbers now.  The differences
can be negative.  Though the macro could convert to a signed type, the
range of sequence numbers must be limited for their differences to fit
in a signed type, so the type for sequence numbers may as well be signed
too.

> It looks like MSGBUF_SEQNORM() could avoid the conditional code and any
> questions about signed remainders if it was defined like this:
>
> #define MSGBUF_SEQNORM(mbp, seq) (((seq) + (mbp)->msg_seqmod) % \
>     (mbp)->msg_seqmod)
>
> as long as msg_seqmod < INT_MAX/2.  MSGBUF_SEQNORM() could be simplified
> further if msg_seqmod was added by the caller (such as MSGBUF_SEQSUB())
> if the argument could be negative.

Yes.  The negative numbers of interest seem to be limited to at most
differences of sequence numbers (or maybe differeces of indexes, which
are smaller), so they are larger than -msg_seqmod.  MSGBUF_SEQSUB()
shouldn't add the bias, however,  since it is used in contexts where
we really want to see the negative values.

Bruce



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