From 90b87909659f5c683a385adeaeabe7c77b66f98b Mon Sep 17 00:00:00 2001 From: yokota Date: Mon, 3 Aug 1998 09:17:06 +0000 Subject: [PATCH] Fix the bug which always reallocated the cut buffer whenever the screen mode is changed even if another vty has larger size. Reallocate the buffer only when the new screen size is larger than the current cut buffer size. --- sys/dev/syscons/syscons.c | 25 ++++++++++++++++++------- sys/i386/isa/syscons.c | 25 ++++++++++++++++++------- sys/isa/syscons.c | 25 ++++++++++++++++++------- 3 files changed, 54 insertions(+), 21 deletions(-) diff --git a/sys/dev/syscons/syscons.c b/sys/dev/syscons/syscons.c index 000f9d733ee4..b996d39de587 100644 --- a/sys/dev/syscons/syscons.c +++ b/sys/dev/syscons/syscons.c @@ -25,7 +25,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: syscons.c,v 1.268 1998/08/03 09:09:34 yokota Exp $ + * $Id: syscons.c,v 1.269 1998/08/03 09:15:36 yokota Exp $ */ #include "sc.h" @@ -184,6 +184,7 @@ static char vgaregs[MODE_PARAM_SIZE]; static char vgaregs2[MODE_PARAM_SIZE]; static int rows_offset = 1; static char *cut_buffer; +static int cut_buffer_size; static int mouse_level = 0; /* sysmouse protocol level */ static mousestatus_t mouse_status = { 0, 0, 0, 0, 0, 0 }; static u_short mouse_and_mask[16] = { @@ -720,7 +721,10 @@ scattach(struct isa_device *dev) scp = console[0]; if (crtc_vga) { - cut_buffer = (char *)malloc(scp->xsize*scp->ysize, M_DEVBUF, M_NOWAIT); + cut_buffer_size = scp->xsize * scp->ysize + 1; + cut_buffer = (char *)malloc(cut_buffer_size, M_DEVBUF, M_NOWAIT); + if (cut_buffer != NULL) + cut_buffer[0] = '\0'; } scp->scr_buf = (u_short *)malloc(scp->xsize*scp->ysize*sizeof(u_short), @@ -1289,7 +1293,7 @@ scioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) else psignal(cur_console->mouse_proc, cur_console->mouse_signal); } - else if (mouse->operation == MOUSE_ACTION) { + else if (mouse->operation == MOUSE_ACTION && cut_buffer != NULL) { /* process button presses */ if ((cur_console->mouse_buttons ^ mouse->u.data.buttons) && !(cur_console->status & UNKNOWN_MODE)) { @@ -1356,7 +1360,7 @@ scioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) break; } - if (cur_console->status & UNKNOWN_MODE) + if ((cur_console->status & UNKNOWN_MODE) || (cut_buffer == NULL)) break; switch (mouse->u.event.id) { @@ -1641,9 +1645,16 @@ scioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) scp->mouse_pos = scp->mouse_oldpos = scp->scr_buf + (scp->mouse_ypos / scp->font_size) * scp->xsize + scp->mouse_xpos / 8; - free(cut_buffer, M_DEVBUF); - cut_buffer = (char *)malloc(scp->xsize*scp->ysize, M_DEVBUF, M_NOWAIT); - cut_buffer[0] = 0x00; + /* allocate a larger cut buffer if necessary */ + if ((cut_buffer == NULL) + || (cut_buffer_size < scp->xsize * scp->ysize + 1)) { + if (cut_buffer != NULL) + free(cut_buffer, M_DEVBUF); + cut_buffer_size = scp->xsize * scp->ysize + 1; + cut_buffer = (char *)malloc(cut_buffer_size, M_DEVBUF, M_NOWAIT); + if (cut_buffer != NULL) + cut_buffer[0] = '\0'; + } splx(s); usp = scp->history; diff --git a/sys/i386/isa/syscons.c b/sys/i386/isa/syscons.c index 000f9d733ee4..b996d39de587 100644 --- a/sys/i386/isa/syscons.c +++ b/sys/i386/isa/syscons.c @@ -25,7 +25,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: syscons.c,v 1.268 1998/08/03 09:09:34 yokota Exp $ + * $Id: syscons.c,v 1.269 1998/08/03 09:15:36 yokota Exp $ */ #include "sc.h" @@ -184,6 +184,7 @@ static char vgaregs[MODE_PARAM_SIZE]; static char vgaregs2[MODE_PARAM_SIZE]; static int rows_offset = 1; static char *cut_buffer; +static int cut_buffer_size; static int mouse_level = 0; /* sysmouse protocol level */ static mousestatus_t mouse_status = { 0, 0, 0, 0, 0, 0 }; static u_short mouse_and_mask[16] = { @@ -720,7 +721,10 @@ scattach(struct isa_device *dev) scp = console[0]; if (crtc_vga) { - cut_buffer = (char *)malloc(scp->xsize*scp->ysize, M_DEVBUF, M_NOWAIT); + cut_buffer_size = scp->xsize * scp->ysize + 1; + cut_buffer = (char *)malloc(cut_buffer_size, M_DEVBUF, M_NOWAIT); + if (cut_buffer != NULL) + cut_buffer[0] = '\0'; } scp->scr_buf = (u_short *)malloc(scp->xsize*scp->ysize*sizeof(u_short), @@ -1289,7 +1293,7 @@ scioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) else psignal(cur_console->mouse_proc, cur_console->mouse_signal); } - else if (mouse->operation == MOUSE_ACTION) { + else if (mouse->operation == MOUSE_ACTION && cut_buffer != NULL) { /* process button presses */ if ((cur_console->mouse_buttons ^ mouse->u.data.buttons) && !(cur_console->status & UNKNOWN_MODE)) { @@ -1356,7 +1360,7 @@ scioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) break; } - if (cur_console->status & UNKNOWN_MODE) + if ((cur_console->status & UNKNOWN_MODE) || (cut_buffer == NULL)) break; switch (mouse->u.event.id) { @@ -1641,9 +1645,16 @@ scioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) scp->mouse_pos = scp->mouse_oldpos = scp->scr_buf + (scp->mouse_ypos / scp->font_size) * scp->xsize + scp->mouse_xpos / 8; - free(cut_buffer, M_DEVBUF); - cut_buffer = (char *)malloc(scp->xsize*scp->ysize, M_DEVBUF, M_NOWAIT); - cut_buffer[0] = 0x00; + /* allocate a larger cut buffer if necessary */ + if ((cut_buffer == NULL) + || (cut_buffer_size < scp->xsize * scp->ysize + 1)) { + if (cut_buffer != NULL) + free(cut_buffer, M_DEVBUF); + cut_buffer_size = scp->xsize * scp->ysize + 1; + cut_buffer = (char *)malloc(cut_buffer_size, M_DEVBUF, M_NOWAIT); + if (cut_buffer != NULL) + cut_buffer[0] = '\0'; + } splx(s); usp = scp->history; diff --git a/sys/isa/syscons.c b/sys/isa/syscons.c index 000f9d733ee4..b996d39de587 100644 --- a/sys/isa/syscons.c +++ b/sys/isa/syscons.c @@ -25,7 +25,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: syscons.c,v 1.268 1998/08/03 09:09:34 yokota Exp $ + * $Id: syscons.c,v 1.269 1998/08/03 09:15:36 yokota Exp $ */ #include "sc.h" @@ -184,6 +184,7 @@ static char vgaregs[MODE_PARAM_SIZE]; static char vgaregs2[MODE_PARAM_SIZE]; static int rows_offset = 1; static char *cut_buffer; +static int cut_buffer_size; static int mouse_level = 0; /* sysmouse protocol level */ static mousestatus_t mouse_status = { 0, 0, 0, 0, 0, 0 }; static u_short mouse_and_mask[16] = { @@ -720,7 +721,10 @@ scattach(struct isa_device *dev) scp = console[0]; if (crtc_vga) { - cut_buffer = (char *)malloc(scp->xsize*scp->ysize, M_DEVBUF, M_NOWAIT); + cut_buffer_size = scp->xsize * scp->ysize + 1; + cut_buffer = (char *)malloc(cut_buffer_size, M_DEVBUF, M_NOWAIT); + if (cut_buffer != NULL) + cut_buffer[0] = '\0'; } scp->scr_buf = (u_short *)malloc(scp->xsize*scp->ysize*sizeof(u_short), @@ -1289,7 +1293,7 @@ scioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) else psignal(cur_console->mouse_proc, cur_console->mouse_signal); } - else if (mouse->operation == MOUSE_ACTION) { + else if (mouse->operation == MOUSE_ACTION && cut_buffer != NULL) { /* process button presses */ if ((cur_console->mouse_buttons ^ mouse->u.data.buttons) && !(cur_console->status & UNKNOWN_MODE)) { @@ -1356,7 +1360,7 @@ scioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) break; } - if (cur_console->status & UNKNOWN_MODE) + if ((cur_console->status & UNKNOWN_MODE) || (cut_buffer == NULL)) break; switch (mouse->u.event.id) { @@ -1641,9 +1645,16 @@ scioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) scp->mouse_pos = scp->mouse_oldpos = scp->scr_buf + (scp->mouse_ypos / scp->font_size) * scp->xsize + scp->mouse_xpos / 8; - free(cut_buffer, M_DEVBUF); - cut_buffer = (char *)malloc(scp->xsize*scp->ysize, M_DEVBUF, M_NOWAIT); - cut_buffer[0] = 0x00; + /* allocate a larger cut buffer if necessary */ + if ((cut_buffer == NULL) + || (cut_buffer_size < scp->xsize * scp->ysize + 1)) { + if (cut_buffer != NULL) + free(cut_buffer, M_DEVBUF); + cut_buffer_size = scp->xsize * scp->ysize + 1; + cut_buffer = (char *)malloc(cut_buffer_size, M_DEVBUF, M_NOWAIT); + if (cut_buffer != NULL) + cut_buffer[0] = '\0'; + } splx(s); usp = scp->history;