Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 Jun 2003 21:02:09 +0200
From:      Erik Trulsson <ertr1013@student.uu.se>
To:        Don Lewis <truckman@FreeBSD.org>
Cc:        freebsd-arch@FreeBSD.org
Subject:   Re: Message buffer and printf reentrancy patch
Message-ID:  <20030615190209.GA75458@falcon.midgard.homeip.net>
In-Reply-To: <200306151826.h5FIPvM7046944@gw.catspoiler.org>
References:  <200306151406.aa36218@salmon.maths.tcd.ie> <200306151826.h5FIPvM7046944@gw.catspoiler.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Jun 15, 2003 at 11:25:57AM -0700, Don Lewis wrote:
> On 15 Jun, Ian Dowse wrote:
> > 
> > Below is a patch that makes the implementation of the kernel message
> > buffer mostly reentrant and more generic, and stops printf() ever
> > calling directly into the tty code. This should fix panics that can
> > occur via tputchar() when using xconsole, and generally make the
> > use of printf() in the kernel a bit safer. Many of the ideas here
> > were suggested by Bruce Evans.
> > 
> > A summary of the changes:
> >  - Use atomic operations to update the message buffer pointers.
> >  - Use a kind of sequence number for the pointers instead of just
> >    the offset into the buffer, as this avoids the need for the read
> >    code to touch the write pointer or the write code to touch the
> >    read pointer.
> 
> > +#define MSGBUF_SEQNORM(mbp, seq) ((seq) % (mbp)->msg_seqmod + ((seq) < 0 ? \
> > +    (mbp)->msg_seqmod : 0))
> > +#define MSGBUF_SEQ_TO_POS(mbp, seq) ((int)((u_int)(seq) % \
> > +    (u_int)(mbp)->msg_size))
> > +#define MSGBUF_SEQSUB(mbp, seq1, seq2) (MSGBUF_SEQNORM(mbp, (seq1) - (seq2)))
> > +
> 
> According to my copy of K&R, there is no guarantee that ((negative_int %
> postive_int) <= 0) on all platforms, though this is generally true.

With a C99 compiler it is always true.  In C89 it was implementation
defined if integer division rounded towards zero or towards
negative-infinity.  In C99 integer division always rounds towards zero.
This combined with the fact that (a/b)*b + a%b == a is always true (for
integer a,b and b!=0) means that (neg_int % pos_int <= 0 ) is always
true in C99, while it wasn't always true in C89.


-- 
<Insert your favourite quote here.>
Erik Trulsson
ertr1013@student.uu.se



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