Message buffer and printf reentrancy patch
Erik Trulsson
ertr1013 at student.uu.se
Sun Jun 15 12:02:16 PDT 2003
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 at student.uu.se
More information about the freebsd-arch
mailing list