From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LfJSQ-0002Jo-5t for qemu-devel@nongnu.org; Thu, 05 Mar 2009 14:42:14 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LfJSP-0002JC-6m for qemu-devel@nongnu.org; Thu, 05 Mar 2009 14:42:13 -0500 Received: from [199.232.76.173] (port=48537 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LfJSP-0002J6-0H for qemu-devel@nongnu.org; Thu, 05 Mar 2009 14:42:13 -0500 Received: from savannah.gnu.org ([199.232.41.3]:38605 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LfJSO-0003jF-Ed for qemu-devel@nongnu.org; Thu, 05 Mar 2009 14:42:12 -0500 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1LfJSK-0002U1-AO for qemu-devel@nongnu.org; Thu, 05 Mar 2009 19:42:08 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.69) (envelope-from ) id 1LfJSK-0002Tw-2L for qemu-devel@nongnu.org; Thu, 05 Mar 2009 19:42:08 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Thu, 05 Mar 2009 19:42:08 +0000 Subject: [Qemu-devel] [6693] char-mux: Use separate input buffers (Jan Kiszka) Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 6693 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6693 Author: aliguori Date: 2009-03-05 19:42:07 +0000 (Thu, 05 Mar 2009) Log Message: ----------- char-mux: Use separate input buffers (Jan Kiszka) Currently, the intermediate input buffer of mux'ed character devices records data across all sub-devices. This has the side effect that we easily leak data recorded over one sub-devices to another once we switch the focus. Avoid data loss and confusion by defining exclusive buffers. Note: In contrast to the original author's claim, the buffering concept still breaks down when the fifo of the currently active sub-device is full. As we cannot accept futher data from this point on without risking to loose it, we will also miss escape sequences, just like without all that buffering. In short: There is no reliable escape sequence handling without infinite buffers or the risk of loosing some data. Signed-off-by: Jan Kiszka Signed-off-by: Anthony Liguori Modified Paths: -------------- branches/stable_0_10_0/qemu-char.c Modified: branches/stable_0_10_0/qemu-char.c =================================================================== --- branches/stable_0_10_0/qemu-char.c 2009-03-05 19:42:04 UTC (rev 6692) +++ branches/stable_0_10_0/qemu-char.c 2009-03-05 19:42:07 UTC (rev 6693) @@ -225,12 +225,15 @@ IOEventHandler *chr_event[MAX_MUX]; void *ext_opaque[MAX_MUX]; CharDriverState *drv; - unsigned char buffer[MUX_BUFFER_SIZE]; - int prod; - int cons; int mux_cnt; int term_got_escape; int max_size; + /* Intermediate input buffer allows to catch escape sequences even if the + currently active device is not accepting any input - but only until it + is full as well. */ + unsigned char buffer[MAX_MUX][MUX_BUFFER_SIZE]; + int prod[MAX_MUX]; + int cons[MAX_MUX]; } MuxDriver; @@ -360,11 +363,11 @@ int m = chr->focus; MuxDriver *d = chr->opaque; - while (d->prod != d->cons && + while (d->prod[m] != d->cons[m] && d->chr_can_read[m] && d->chr_can_read[m](d->ext_opaque[m])) { d->chr_read[m](d->ext_opaque[m], - &d->buffer[d->cons++ & MUX_BUFFER_MASK], 1); + &d->buffer[m][d->cons[m]++ & MUX_BUFFER_MASK], 1); } } @@ -372,11 +375,12 @@ { CharDriverState *chr = opaque; MuxDriver *d = chr->opaque; + int m = chr->focus; - if ((d->prod - d->cons) < MUX_BUFFER_SIZE) + if ((d->prod[m] - d->cons[m]) < MUX_BUFFER_SIZE) return 1; - if (d->chr_can_read[chr->focus]) - return d->chr_can_read[chr->focus](d->ext_opaque[chr->focus]); + if (d->chr_can_read[m]) + return d->chr_can_read[m](d->ext_opaque[m]); return 0; } @@ -391,12 +395,12 @@ for(i = 0; i < size; i++) if (mux_proc_byte(chr, d, buf[i])) { - if (d->prod == d->cons && + if (d->prod[m] == d->cons[m] && d->chr_can_read[m] && d->chr_can_read[m](d->ext_opaque[m])) d->chr_read[m](d->ext_opaque[m], &buf[i], 1); else - d->buffer[d->prod++ & MUX_BUFFER_MASK] = buf[i]; + d->buffer[m][d->prod[m]++ & MUX_BUFFER_MASK] = buf[i]; } }