towards fixing intermingled dmesg
Andriy Gapon
avg at icyb.net.ua
Sat Apr 17 12:15:52 UTC 2010
Here is a simple extension of msgbuf_addchar that is supposed to allow to put N
characters consecutively into msgbuf.
The idea is very simple: atomically forward msg_wseq by N and then copy
characters into the reserved space.
Could you please check if this is implemented correctly and if it would actually
work the way I expect?
There is still a harder issue of actually plugging this routine into subr_prf.c :-)
--- a/sys/kern/subr_msgbuf.c
+++ b/sys/kern/subr_msgbuf.c
@@ -131,6 +131,26 @@ msgbuf_addchar(struct msgbuf *mbp, int c)
mbp->msg_ptr[pos] = c;
}
+void
+msgbuf_addchars(struct msgbuf *mbp, const char *s, const int n)
+{
+ u_int new_seq, pos, seq;
+ int c, i;
+
+ do {
+ seq = mbp->msg_wseq;
+ new_seq = MSGBUF_SEQNORM(mbp, seq + n);
+ } while (atomic_cmpset_rel_int(&mbp->msg_wseq, seq, new_seq) == 0);
+
+ for (i = 0; i < n; i++) {
+ pos = MSGBUF_SEQ_TO_POS(mbp, seq + i);
+ c = s[i];
+ atomic_add_int(&mbp->msg_cksum, (u_int)(u_char)c -
+ (u_int)(u_char)mbp->msg_ptr[pos]);
+ mbp->msg_ptr[pos] = c;
+ }
+}
+
/*
* Read and mark as read a character from a message buffer.
* Returns the character, or -1 if no characters are available.
--
Andriy Gapon
More information about the freebsd-hackers
mailing list