From 6cc15668296ec46a984aff9adfb05347c3797d2e Mon Sep 17 00:00:00 2001 From: Guido van Rooij Date: Wed, 2 Mar 1994 20:29:03 +0000 Subject: [PATCH] Ttys structures are now allocated dynamically via ttymalloc/ttyfree. This inetrface should be used from now on. pseudo device pty xx still keeps its meaning: a maximum of xx ptys is allowed. A ringbuffer is now 2040 bytes long, per Garrett Wollman's request. The changes are inspired by the way NetBSD did it (thanks for that!), though I made it slihghtly different, including the interface so at least 75% of the allocated space is deallocated when the tty is closed. Note further that it is easy to modify the ringbuffer length runtime. This will have to wait untill some later date... -Guido --- sys/i386/doc/Changes | 10 +- sys/i386/i386/conf.c | 10 +- sys/i386/isa/com.c | 49 +++++---- sys/i386/isa/pccons.c | 44 ++++---- sys/i386/isa/sio.c | 35 +++--- sys/i386/isa/syscons.c | 25 +++-- sys/kern/tty.c | 235 +++++++++++++++++++++++++---------------- sys/kern/tty_pty.c | 128 ++++++++++++---------- sys/net/if_ppp.c | 36 +++---- sys/net/if_sl.c | 28 ++--- sys/sys/conf.h | 4 +- sys/sys/malloc.h | 7 +- sys/sys/tty.h | 17 +-- 13 files changed, 369 insertions(+), 259 deletions(-) diff --git a/sys/i386/doc/Changes b/sys/i386/doc/Changes index 99adc789ef..0ae9f5b5da 100644 --- a/sys/i386/doc/Changes +++ b/sys/i386/doc/Changes @@ -1,12 +1,19 @@ Hello, Emacs, this is an -*- Indented-Text -*- file! -$Id: Changes,v 1.14 1994/02/11 12:08:14 nate Exp $ +$Id: Changes,v 1.15 1994/02/21 23:03:09 rgrimes Exp $ This file is intended to keep track of important kernel and user changes in FreeBSD between releases. Entries are in reverse chronological order; userids can be decoded with the chart at the end of this file. +<<<<<<< Changes +Since 1.0.2: +- Struct ttys are allocated dynamically. (guido) + +||||||| 1.15 +Since 1.0.2: +======= Since 1.1 BETA: Between 1.1 BETA and 1.0.2: @@ -14,6 +21,7 @@ Between 1.1 BETA and 1.0.2: an active job. Fixed up the probe routine so that it works on most if not all printers now. (csgr/rgrimes) +>>>>>>> /tmp/T4025574 - Substantial changes to system configuration; you MUST re-build `config' before attempting to build a 1.1 kernel. (nate/martin) diff --git a/sys/i386/i386/conf.c b/sys/i386/i386/conf.c index babd44b989..acc39665bd 100644 --- a/sys/i386/i386/conf.c +++ b/sys/i386/i386/conf.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)conf.c 5.8 (Berkeley) 5/12/91 - * $Id: conf.c,v 1.20 1994/01/04 20:08:56 nate Exp $ + * $Id: conf.c,v 1.21 1994/02/27 21:51:05 phk Exp $ */ #include "param.h" @@ -229,7 +229,7 @@ d_close_t pcclose; d_rdwr_t pcread, pcwrite; d_ioctl_t pcioctl; d_mmap_t pcmmap; -extern struct tty pccons; +extern struct tty *pccons; /* controlling TTY */ d_open_t cttyopen; @@ -255,7 +255,7 @@ d_close_t ptcclose; d_rdwr_t ptcread, ptcwrite; d_select_t ptcselect; d_ioctl_t ptyioctl; -extern struct tty pt_tty[]; +extern struct tty *pt_tty[]; #else #define ptsopen (d_open_t *)enxio #define ptsclose (d_close_t *)enxio @@ -280,7 +280,7 @@ d_rdwr_t comwrite; d_ioctl_t comioctl; d_select_t comselect; #define comreset (d_reset_t *)enxio -extern struct tty com_tty[]; +extern struct tty *com_tty[]; #else #define comopen (d_open_t *)enxio #define comclose (d_close_t *)enxio @@ -442,7 +442,7 @@ d_ioctl_t sioioctl; d_select_t sioselect; d_stop_t siostop; #define sioreset (d_reset_t *)enxio -extern struct tty sio_tty[]; +extern struct tty *sio_tty[]; #else #define sioopen (d_open_t *)enxio #define sioclose (d_close_t *)enxio diff --git a/sys/i386/isa/com.c b/sys/i386/isa/com.c index 408004e8e0..2771f91937 100644 --- a/sys/i386/isa/com.c +++ b/sys/i386/isa/com.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * from: @(#)com.c 7.5 (Berkeley) 5/16/91 - * $Id: com.c,v 1.6 1993/11/25 01:31:30 wollman Exp $ + * $Id: com.c,v 1.7 1993/12/19 00:50:32 wollman Exp $ */ #include "com.h" @@ -86,7 +86,7 @@ int comconsinit; int comdefaultrate = TTYDEF_SPEED; int commajor; short com_addr[NCOM]; -struct tty com_tty[NCOM]; +struct tty *com_tty[NCOM]; struct speedtab comspeedtab[] = { 0, 0, @@ -199,7 +199,7 @@ comopen(int /*dev_t*/ dev, int flag, int mode, struct proc *p) unit = UNIT(dev); if (unit >= NCOM || (com_active & (1 << unit)) == 0) return (ENXIO); - tp = &com_tty[unit]; + tp = com_tty[unit] = ttymalloc(com_tty[unit]); tp->t_oproc = comstart; tp->t_param = comparam; tp->t_dev = dev; @@ -224,7 +224,7 @@ comopen(int /*dev_t*/ dev, int flag, int mode, struct proc *p) while ((flag&O_NONBLOCK) == 0 && (tp->t_cflag&CLOCAL) == 0 && (tp->t_state & TS_CARR_ON) == 0) { tp->t_state |= TS_WOPEN; - if (error = ttysleep(tp, (caddr_t)&tp->t_raw, TTIPRI | PCATCH, + if (error = ttysleep(tp, (caddr_t)tp->t_raw, TTIPRI | PCATCH, ttopen, 0)) break; } @@ -247,7 +247,7 @@ comclose(dev, flag, mode, p) unit = UNIT(dev); com = com_addr[unit]; - tp = &com_tty[unit]; + tp = com_tty[unit]; (*linesw[tp->t_line].l_close)(tp, flag); outb(com+com_cfcr, inb(com+com_cfcr) & ~CFCR_SBREAK); #ifdef KGDB @@ -259,6 +259,13 @@ comclose(dev, flag, mode, p) (tp->t_state&TS_ISOPEN) == 0) (void) commctl(dev, 0, DMSET); ttyclose(tp); + ttyfree(tp); +#ifdef broken /* session holds a ref to the tty; can't deallocate */ + com_tty[unit] = (struct tty *)NULL; +#endif + return (0); + + return(0); } @@ -268,7 +275,7 @@ comread(dev, uio, flag) struct uio *uio; int flag; { - register struct tty *tp = &com_tty[UNIT(dev)]; + register struct tty *tp = com_tty[UNIT(dev)]; return ((*linesw[tp->t_line].l_read)(tp, uio, flag)); } @@ -280,7 +287,7 @@ comwrite(dev, uio, flag) int flag; { int unit = UNIT(dev); - register struct tty *tp = &com_tty[unit]; + register struct tty *tp = com_tty[unit]; /* * (XXX) We disallow virtual consoles if the physical console is @@ -309,7 +316,7 @@ comintr(unit) return; case IIR_RXTOUT: case IIR_RXRDY: - tp = &com_tty[unit]; + tp = com_tty[unit]; /* * Process received bytes. Inline for speed... */ @@ -340,7 +347,7 @@ comintr(unit) } break; case IIR_TXRDY: - tp = &com_tty[unit]; + tp = com_tty[unit]; tp->t_state &=~ (TS_BUSY|TS_FLUSH); if (tp->t_line) (*linesw[tp->t_line].l_start)(tp); @@ -371,7 +378,7 @@ comeint(unit, stat, com) register struct tty *tp; register int c; - tp = &com_tty[unit]; + tp = com_tty[unit]; c = inb(com+com_data); if ((tp->t_state & TS_ISOPEN) == 0) { #ifdef KGDB @@ -401,7 +408,7 @@ commint(unit, com) register struct tty *tp; register int stat; - tp = &com_tty[unit]; + tp = com_tty[unit]; stat = inb(com+com_msr); if ((stat & MSR_DDCD) && (comsoftCAR & (1 << unit)) == 0) { if (stat & MSR_DCD) @@ -432,7 +439,7 @@ comioctl(dev, cmd, data, flag) register com; register int error; - tp = &com_tty[unit]; + tp = com_tty[unit]; error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag); if (error >= 0) return (error); @@ -545,10 +552,10 @@ comstart(tp) s = spltty(); if (tp->t_state & (TS_TIMEOUT|TS_TTSTOP)) goto out; - if (RB_LEN(&tp->t_out) <= tp->t_lowat) { + if (RB_LEN(tp->t_out) <= tp->t_lowat) { if (tp->t_state&TS_ASLEEP) { tp->t_state &= ~TS_ASLEEP; - wakeup((caddr_t)&tp->t_out); + wakeup((caddr_t)tp->t_out); } if (tp->t_wsel) { selwakeup(tp->t_wsel, tp->t_state & TS_WCOLL); @@ -556,15 +563,15 @@ comstart(tp) tp->t_state &= ~TS_WCOLL; } } - if (RB_LEN(&tp->t_out) == 0) + if (RB_LEN(tp->t_out) == 0) goto out; if (inb(com+com_lsr) & LSR_TXRDY) { - c = getc(&tp->t_out); + c = getc(tp->t_out); tp->t_state |= TS_BUSY; outb(com+com_data, c); if (com_hasfifo & (1 << unit)) - for (c = 1; c < 16 && RB_LEN(&tp->t_out); ++c) - outb(com+com_data, getc(&tp->t_out)); + for (c = 1; c < 16 && RB_LEN(tp->t_out); ++c) + outb(com+com_data, getc(tp->t_out)); } out: splx(s); @@ -647,7 +654,7 @@ comcnprobe(cp) /* initialize required fields */ cp->cn_dev = makedev(commajor, unit); - cp->cn_tp = &com_tty[unit]; + cp->cn_tp = com_tty[unit]; #ifdef COMCONSOLE cp->cn_pri = CN_REMOTE; /* Force a serial port console */ #else @@ -754,7 +761,7 @@ comselect(dev, rw, p) int rw; struct proc *p; { - register struct tty *tp = &com_tty[UNIT(dev)]; + register struct tty *tp = com_tty[UNIT(dev)]; int nread; int s = spltty(); struct proc *selp; @@ -773,7 +780,7 @@ comselect(dev, rw, p) break; case FWRITE: - if (RB_LEN(&tp->t_out) <= tp->t_lowat) + if (RB_LEN(tp->t_out) <= tp->t_lowat) goto win; if (tp->t_wsel && (selp = pfind(tp->t_wsel)) && selp->p_wchan == (caddr_t)&selwait) tp->t_state |= TS_WCOLL; diff --git a/sys/i386/isa/pccons.c b/sys/i386/isa/pccons.c index 61eacc57af..ddfffd395d 100644 --- a/sys/i386/isa/pccons.c +++ b/sys/i386/isa/pccons.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)pccons.c 5.11 (Berkeley) 5/21/91 - * $Id: pccons.c,v 1.12 1994/01/03 07:55:45 davidg Exp $ + * $Id: pccons.c,v 1.13 1994/02/10 10:17:58 ache Exp $ */ /* @@ -63,7 +63,7 @@ int pc_xmode; #endif /* XSERVER */ -struct tty pccons; +struct tty *pccons; struct pcconsoftc { char cs_flags; @@ -289,7 +289,7 @@ pcopen(dev, flag, mode, p) if (minor(dev) != 0) return (ENXIO); - tp = &pccons; + tp = pccons = ttymalloc(pccons); tp->t_oproc = pcstart; tp->t_param = pcparam; tp->t_dev = dev; @@ -316,8 +316,12 @@ pcclose(dev, flag, mode, p) int flag, mode; struct proc *p; { - (*linesw[pccons.t_line].l_close)(&pccons, flag); - ttyclose(&pccons); + (*linesw[pccons->t_line].l_close)(pccons, flag); + ttyclose(pccons); + ttyfree(pccons); +#ifdef broken /* session holds a ref to the tty; can't deallocate */ + pccons = (struct tty *)NULL; +#endif return(0); } @@ -328,7 +332,7 @@ pcread(dev, uio, flag) struct uio *uio; int flag; { - return ((*linesw[pccons.t_line].l_read)(&pccons, uio, flag)); + return ((*linesw[pccons->t_line].l_read)(pccons, uio, flag)); } /*ARGSUSED*/ @@ -338,7 +342,7 @@ pcwrite(dev, uio, flag) struct uio *uio; int flag; { - return ((*linesw[pccons.t_line].l_write)(&pccons, uio, flag)); + return ((*linesw[pccons->t_line].l_write)(pccons, uio, flag)); } /* @@ -361,7 +365,7 @@ pcrint(dev, irq, cpl) if (pcconsoftc.cs_flags & CSF_POLLING) return; #ifdef KDB - if (kdbrintr(c, &pccons)) + if (kdbrintr(c, pccons)) return; #endif if (!openf) @@ -369,11 +373,11 @@ pcrint(dev, irq, cpl) #ifdef XSERVER /* 15 Aug 92*/ /* send at least one character, because cntl-space is a null */ - (*linesw[pccons.t_line].l_rint)(*cp++ & 0xff, &pccons); + (*linesw[pccons->t_line].l_rint)(*cp++ & 0xff, pccons); #endif /* XSERVER */ while (*cp) - (*linesw[pccons.t_line].l_rint)(*cp++ & 0xff, &pccons); + (*linesw[pccons->t_line].l_rint)(*cp++ & 0xff, pccons); } #ifdef XSERVER /* 15 Aug 92*/ @@ -389,7 +393,7 @@ pcioctl(dev, cmd, data, flag) caddr_t data; int flag; { - register struct tty *tp = &pccons; + register struct tty *tp = pccons; register error; #ifdef XSERVER /* 15 Aug 92*/ @@ -436,12 +440,12 @@ pcxint(dev) if (!pcconsintr) return; - pccons.t_state &= ~TS_BUSY; + pccons->t_state &= ~TS_BUSY; pcconsoftc.cs_timo = 0; - if (pccons.t_line) - (*linesw[pccons.t_line].l_start)(&pccons); + if (pccons->t_line) + (*linesw[pccons->t_line].l_start)(pccons); else - pcstart(&pccons); + pcstart(pccons); } void @@ -454,10 +458,10 @@ pcstart(tp) if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP)) goto out; do { - if (RB_LEN(&tp->t_out) <= tp->t_lowat) { + if (RB_LEN(tp->t_out) <= tp->t_lowat) { if (tp->t_state&TS_ASLEEP) { tp->t_state &= ~TS_ASLEEP; - wakeup((caddr_t)&tp->t_out); + wakeup((caddr_t)tp->t_out); } if (tp->t_wsel) { selwakeup(tp->t_wsel, tp->t_state & TS_WCOLL); @@ -465,9 +469,9 @@ pcstart(tp) tp->t_state &= ~TS_WCOLL; } } - if (RB_LEN(&tp->t_out) == 0) + if (RB_LEN(tp->t_out) == 0) goto out; - c = getc(&tp->t_out); + c = getc(tp->t_out); tp->t_state |= TS_BUSY; /* 21 Aug 92*/ splx(s); sput(c, 0); @@ -491,7 +495,7 @@ pccnprobe(cp) /* initialize required fields */ cp->cn_dev = makedev(maj, 0); - cp->cn_tp = &pccons; + cp->cn_tp = pccons; cp->cn_pri = CN_INTERNAL; } diff --git a/sys/i386/isa/sio.c b/sys/i386/isa/sio.c index f17f6ae131..cebc9dce97 100644 --- a/sys/i386/isa/sio.c +++ b/sys/i386/isa/sio.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * from: @(#)com.c 7.5 (Berkeley) 5/16/91 - * $Id: sio.c,v 1.29 1994/02/24 16:39:48 phk Exp $ + * $Id: sio.c,v 1.30 1994/02/26 00:04:03 phk Exp $ */ #include "sio.h" @@ -270,7 +270,7 @@ static bool_t comconsinit; static speed_t comdefaultrate = TTYDEF_SPEED; static u_int com_events; /* input chars + weighted output completions */ static int commajor; -struct tty sio_tty[NSIO]; +struct tty *sio_tty[NSIO]; extern struct tty *constty; extern u_int ipending; /* XXX */ extern int tk_nin; /* XXX */ @@ -437,7 +437,7 @@ sioattach(isdp) com->modem_ctl_port = iobase + com_mcr; com->line_status_port = iobase + com_lsr; com->modem_status_port = iobase + com_msr; - com->tp = &sio_tty[unit]; + com->tp = sio_tty[unit]; /* attempt to determine UART type */ printf("sio%d: type", unit); @@ -568,7 +568,9 @@ sioopen(dev, flag, mode, p) return (ENXIO); #endif /* COM_BIDIR */ - tp = com->tp; + + sio_tty[unit] = ttymalloc(sio_tty[unit]); + tp = com->tp = sio_tty[unit]; s = spltty(); #ifdef COM_BIDIR @@ -722,7 +724,7 @@ bidir_open_top: #endif /* COM_BIDIR */ && !(tp->t_state & TS_CARR_ON)) { tp->t_state |= TS_WOPEN; - error = ttysleep(tp, (caddr_t)&tp->t_raw, TTIPRI | PCATCH, + error = ttysleep(tp, (caddr_t)tp->t_raw, TTIPRI | PCATCH, ttopen, 0); if (error != 0) break; @@ -768,6 +770,11 @@ sioclose(dev, flag, mode, p) (*linesw[tp->t_line].l_close)(tp, flag); comhardclose(com); ttyclose(tp); + ttyfree(tp); +#ifdef broken /* session holds a ref to the tty; can't deallocate */ + sio_tty[UNIT(dev)] = (struct tty *)NULL; + com->tp = (struct tty *)NULL; +#endif return (0); } @@ -1184,7 +1191,7 @@ comflush(com) com_events -= LOTS_OF_EVENTS; com->state &= ~(CS_ODONE | CS_BUSY); enable_intr(); - rbp = &com->tp->t_out; + rbp = com->tp->t_out; rbp->rb_hd += com->ocount; rbp->rb_hd = RB_ROLLOVER(rbp, rbp->rb_hd); com->ocount = 0; @@ -1305,7 +1312,7 @@ repeat: if (incc <= 0 || !(tp->t_state & TS_ISOPEN)) continue; if (com->state & CS_RTS_IFLOW - && RB_LEN(&tp->t_raw) + incc >= RB_I_HIGH_WATER + && RB_LEN(tp->t_raw) + incc >= RB_I_HIGH_WATER && !(tp->t_state & TS_RTS_IFLOW) /* * XXX - need RTS flow control for all line disciplines. @@ -1332,7 +1339,7 @@ repeat: tk_rawcc += incc; tp->t_rawcc += incc; com->delta_error_counts[CE_TTY_BUF_OVERFLOW] - += incc - rb_write(&tp->t_raw, (char *) buf, + += incc - rb_write(tp->t_raw, (char *) buf, incc); ttwakeup(tp); if (tp->t_state & TS_TTSTOP @@ -1439,7 +1446,7 @@ retry: enable_intr(); while ((inb(com->line_status_port) & (LSR_TSRE | LSR_TXRDY)) != (LSR_TSRE | LSR_TXRDY)) { - error = ttysleep(tp, (caddr_t)&tp->t_raw, TTIPRI | PCATCH, + error = ttysleep(tp, (caddr_t)tp->t_raw, TTIPRI | PCATCH, "sioparam", 1); if (error != 0 && error != EAGAIN) { if (!(tp->t_state & TS_TTSTOP)) { @@ -1532,10 +1539,10 @@ comstart(tp) enable_intr(); if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) goto out; - if (RB_LEN(&tp->t_out) <= tp->t_lowat) { + if (RB_LEN(tp->t_out) <= tp->t_lowat) { if (tp->t_state & TS_ASLEEP) { tp->t_state &= ~TS_ASLEEP; - wakeup((caddr_t)&tp->t_out); + wakeup((caddr_t)tp->t_out); } if (tp->t_wsel) { selwakeup(tp->t_wsel, tp->t_state & TS_WCOLL); @@ -1547,11 +1554,11 @@ comstart(tp) disable_intr(); comintr1(com); enable_intr(); - } else if (RB_LEN(&tp->t_out) != 0) { + } else if (RB_LEN(tp->t_out) != 0) { tp->t_state |= TS_BUSY; - com->ocount = RB_CONTIGGET(&tp->t_out); + com->ocount = RB_CONTIGGET(tp->t_out); disable_intr(); - com->obufend = (com->optr = (u_char *) tp->t_out.rb_hd) + com->obufend = (com->optr = (u_char *) tp->t_out->rb_hd) + com->ocount; com->state |= CS_BUSY; comintr1(com); /* fake interrupt to start output */ diff --git a/sys/i386/isa/syscons.c b/sys/i386/isa/syscons.c index 5eb10afafc..4932d59855 100644 --- a/sys/i386/isa/syscons.c +++ b/sys/i386/isa/syscons.c @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * from:@(#)syscons.c 1.3 940129 - * $Id: syscons.c,v 1.34 1994/02/04 10:36:15 chmr Exp $ + * $Id: syscons.c,v 1.35 1994/02/07 02:14:27 davidg Exp $ * */ @@ -273,26 +273,29 @@ int ttrstrt(); #endif #if defined(__FreeBSD__) +#define VIRTUAL_TTY(x) (pccons[x] = ttymalloc(pccons[x])) +#define CONSOLE_TTY (pccons[NCONS] = ttymalloc(pccons[NCONS])) #define frametype struct trapframe #define eflags tf_eflags #define timeout_t timeout_func_t #define MONO_BUF (KERNBASE+0xB0000) #define CGA_BUF (KERNBASE+0xB8000) +struct tty *pccons[NCONS+1]; #endif #if defined(__386BSD__) && !defined(__FreeBSD__) +#define VIRTUAL_TTY(x) &pccons[x] +#define CONSOLE_TTY &pccons[NCONS] #define frametype struct syscframe #define eflags sf_eflags #define timeout_t caddr_t #define MONO_BUF (0xFE0B0000) #define CGA_BUF (0xFE0B8000) +struct tty pccons[NCONS+1]; #endif #if defined(__386BSD__) || defined(__FreeBSD__) -#define VIRTUAL_TTY(x) &pccons[x] -#define CONSOLE_TTY &pccons[NCONS] u_short *Crtat = (u_short *)MONO_BUF; -struct tty pccons[NCONS+1]; void consinit(void) {scinit();} #include "ddb.h" #if NDDB > 0 @@ -300,7 +303,6 @@ void consinit(void) {scinit();} #endif #endif - struct isa_driver scdriver = { pcprobe, pcattach, "sc", }; @@ -1060,10 +1062,10 @@ void pcstart(struct tty *tp) s = spltty(); if (!(tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP))) for (;;) { - if (RB_LEN(&tp->t_out) <= tp->t_lowat) { + if (RB_LEN(tp->t_out) <= tp->t_lowat) { if (tp->t_state & TS_ASLEEP) { tp->t_state &= ~TS_ASLEEP; - wakeup((caddr_t)&tp->t_out); + wakeup((caddr_t)tp->t_out); } if (tp->t_wsel) { selwakeup(tp->t_wsel, @@ -1072,11 +1074,11 @@ void pcstart(struct tty *tp) tp->t_state &= ~TS_WCOLL; } } - if (RB_LEN(&tp->t_out) == 0) + if (RB_LEN(tp->t_out) == 0) break; if (scp->status & SLKED) break; - c = getc(&tp->t_out); + c = getc(tp->t_out); tp->t_state |= TS_BUSY; splx(s); ansi_put(scp, c); @@ -1100,9 +1102,10 @@ void pccnprobe(struct consdev *cp) /* initialize required fields */ cp->cn_dev = makedev(maj, NCONS); cp->cn_pri = CN_INTERNAL; -#if defined(__FreeBSD__) || defined(__386BSD__) +#warning Crude hack, do it better +/*#if defined(__FreeBSD__) || defined(__386BSD__) cp->cn_tp = CONSOLE_TTY; -#endif +#endif*/ } diff --git a/sys/kern/tty.c b/sys/kern/tty.c index d173417afb..39925b6c83 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -32,7 +32,7 @@ * SUCH DAMAGE. * * from: @(#)tty.c 7.44 (Berkeley) 5/28/91 - * $Id: tty.c,v 1.19 1994/02/13 17:21:31 ache Exp $ + * $Id: tty.c,v 1.20 1994/02/24 16:13:09 phk Exp $ */ #include "param.h" @@ -47,6 +47,7 @@ #include "dkstat.h" #include "uio.h" #include "kernel.h" +#include "malloc.h" #include "vnode.h" #include "syslog.h" #include "signalvar.h" @@ -62,7 +63,7 @@ #define I_LOW_WATER ((TTYHOG - 2 * 256) * 7 / 8) /* XXX */ /* XXX RB_LEN() is too slow. */ -#define INPUT_LEN(tp) (RB_LEN(&(tp)->t_can) + RB_LEN(&(tp)->t_raw)) +#define INPUT_LEN(tp) (RB_LEN((tp)->t_can) + RB_LEN((tp)->t_raw)) #undef MAX_INPUT /* XXX wrong in */ #define MAX_INPUT TTYHOG @@ -200,7 +201,7 @@ ttywait(tp) { int error = 0, s = spltty(); - while ((RB_LEN(&tp->t_out) || tp->t_state&TS_BUSY) && + while ((RB_LEN(tp->t_out) || tp->t_state&TS_BUSY) && (tp->t_state&TS_CARR_ON || tp->t_cflag&CLOCAL) && tp->t_oproc) { /* @@ -219,10 +220,10 @@ ttywait(tp) tp->t_lowat = 0; (*tp->t_oproc)(tp); - if ((RB_LEN(&tp->t_out) || tp->t_state&TS_BUSY) && + if ((RB_LEN(tp->t_out) || tp->t_state&TS_BUSY) && (tp->t_state&TS_CARR_ON || tp->t_cflag&CLOCAL)) { tp->t_state |= TS_ASLEEP; - if (error = ttysleep(tp, (caddr_t)&tp->t_out, + if (error = ttysleep(tp, (caddr_t)tp->t_out, TTOPRI | PCATCH, "ttywai", 0)) break; } else @@ -255,16 +256,16 @@ ttyflush(tp, rw) tp->t_state &= ~TS_TTSTOP; (*cdevsw[major(tp->t_dev)].d_stop)(tp, rw); if (rw & FREAD) { - flushq(&tp->t_can); - flushq(&tp->t_raw); + flushq(tp->t_can); + flushq(tp->t_raw); tp->t_rocount = 0; tp->t_rocol = 0; tp->t_state &= ~TS_LOCAL; ttwakeup(tp); } if (rw & FWRITE) { - flushq(&tp->t_out); - wakeup((caddr_t)&tp->t_out); + flushq(tp->t_out); + wakeup((caddr_t)tp->t_out); if (tp->t_wsel) { selwakeup(tp->t_wsel, tp->t_state & TS_WCOLL); tp->t_wsel = 0; @@ -284,16 +285,16 @@ ttyflush(tp, rw) * is still tricky because we don't want to add a * new obstruction to draining the output queue. */ - out_cc = RB_LEN(&tp->t_out); + out_cc = RB_LEN(tp->t_out); t_state = tp->t_state; ttyunblock(tp); tp->t_state &= ~TS_TBLOCK; - if (t_state & TS_TBLOCK && RB_LEN(&tp->t_out) != 0) - ttysleep(tp, (caddr_t)&tp->t_out, TTIPRI, + if (t_state & TS_TBLOCK && RB_LEN(tp->t_out) != 0) + ttysleep(tp, (caddr_t)tp->t_out, TTIPRI, "ttyfls", hz / 10); - if (out_cc == 0 && RB_LEN(&tp->t_out) != 0) { + if (out_cc == 0 && RB_LEN(tp->t_out) != 0) { (*cdevsw[major(tp->t_dev)].d_stop)(tp, FWRITE); - flushq(&tp->t_out); + flushq(tp->t_out); } } } @@ -312,7 +313,7 @@ ttyblock(tp) if ((tp->t_state & TS_TBLOCK) == 0 && tp->t_cc[VSTOP] != _POSIX_VDISABLE - && putc(tp->t_cc[VSTOP], &tp->t_out) == 0) + && putc(tp->t_cc[VSTOP], tp->t_out) == 0) tp->t_state |= TS_TBLOCK; if (tp->t_cflag & CDTR_IFLOW) tp->t_state |= TS_DTR_IFLOW; @@ -332,7 +333,7 @@ ttyunblock(tp) if (tp->t_state & TS_TBLOCK && tp->t_cc[VSTART] != _POSIX_VDISABLE - && putc(tp->t_cc[VSTART], &tp->t_out) == 0) + && putc(tp->t_cc[VSTART], tp->t_out) == 0) tp->t_state &= ~TS_TBLOCK; tp->t_state &= ~TS_HW_IFLOW; ttstart(tp); @@ -492,7 +493,7 @@ ttioctl(tp, com, data, flag) break; case TIOCOUTQ: - *(int *)data = RB_LEN(&tp->t_out); + *(int *)data = RB_LEN(tp->t_out); break; case TIOCSTOP: @@ -590,8 +591,8 @@ ttioctl(tp, com, data, flag) ttwakeup(tp); } else { - catb(&tp->t_raw, &tp->t_can); - catb(&tp->t_can, &tp->t_raw); + catb(tp->t_raw, tp->t_can); + catb(tp->t_can, tp->t_raw); } } tp->t_iflag = t->c_iflag; @@ -705,9 +706,9 @@ ttnread(tp) /* XXX races. */ if (tp->t_lflag & PENDIN) ttypend(tp); - nread = RB_LEN(&tp->t_can); + nread = RB_LEN(tp->t_can); if ((tp->t_lflag & ICANON) == 0) { - nread += RB_LEN(&tp->t_raw); + nread += RB_LEN(tp->t_raw); if (nread < tp->t_cc[VMIN]) nread = 0; } @@ -720,7 +721,7 @@ ttselect(dev, rw, p) int rw; struct proc *p; { - register struct tty *tp = &cdevsw[major(dev)].d_ttys[minor(dev)]; + register struct tty *tp = cdevsw[major(dev)].d_ttys[minor(dev)]; int nread; int s = spltty(); struct proc *selp; @@ -739,7 +740,7 @@ ttselect(dev, rw, p) break; case FWRITE: - if (RB_LEN(&tp->t_out) <= tp->t_lowat) + if (RB_LEN(tp->t_out) <= tp->t_lowat) goto win; if (tp->t_wsel && (selp = pfind(tp->t_wsel)) && selp->p_wchan == (caddr_t)&selwait) tp->t_state |= TS_WCOLL; @@ -769,9 +770,9 @@ ttyopen(dev, tp, dummy) tp->t_state &= ~TS_WOPEN; if ((tp->t_state & TS_ISOPEN) == 0) { tp->t_state |= TS_ISOPEN; - initrb(&tp->t_raw); - initrb(&tp->t_can); - initrb(&tp->t_out); + initrb(tp->t_raw); + initrb(tp->t_can); + initrb(tp->t_out); bzero((caddr_t)&tp->t_winsize, sizeof(tp->t_winsize)); } return (0); @@ -889,12 +890,12 @@ ttypend(tp) tp->t_lflag &= ~PENDIN; tp->t_state |= TS_TYPEN; - hd = tp->t_raw.rb_hd; - tl = tp->t_raw.rb_tl; - flushq(&tp->t_raw); + hd = tp->t_raw->rb_hd; + tl = tp->t_raw->rb_tl; + flushq(tp->t_raw); while (hd != tl) { ttyinput(*hd, tp); - hd = RB_SUCC(&tp->t_raw, hd); + hd = RB_SUCC(tp->t_raw, hd); } tp->t_state &= ~TS_TYPEN; } @@ -937,7 +938,7 @@ ttyinput(c, tp) if ((iflag & IXOFF && (tp->t_state & TS_TBLOCK) == 0 || tp->t_cflag & TS_HW_IFLOW && (tp->t_state & TS_HW_IFLOW) == 0) && INPUT_LEN(tp) > I_HIGH_WATER - 3 - && ((lflag & ICANON) == 0 || RB_LEN(&tp->t_can) != 0)) + && ((lflag & ICANON) == 0 || RB_LEN(tp->t_can) != 0)) ttyblock(tp); /* * Handle exceptional conditions (break, parity, framing). @@ -959,9 +960,9 @@ ttyinput(c, tp) parmrk: if (INPUT_LEN(tp) > MAX_INPUT - 3) goto input_overflow; - putc(0377|TTY_QUOTE, &tp->t_raw); - putc(0|TTY_QUOTE, &tp->t_raw); - putc(c|TTY_QUOTE, &tp->t_raw); + putc(0377|TTY_QUOTE, tp->t_raw); + putc(0|TTY_QUOTE, tp->t_raw); + putc(c|TTY_QUOTE, tp->t_raw); goto endcase; } else c = 0; @@ -1074,23 +1075,23 @@ parmrk: * erase (^H / ^?) */ if (CCEQ(cc[VERASE], c)) { - if (RB_LEN(&tp->t_raw)) - ttyrub(unputc(&tp->t_raw), tp); + if (RB_LEN(tp->t_raw)) + ttyrub(unputc(tp->t_raw), tp); goto endcase; } /* * kill (^U) */ if (CCEQ(cc[VKILL], c)) { - if (lflag&ECHOKE && RB_LEN(&tp->t_raw) == tp->t_rocount && + if (lflag&ECHOKE && RB_LEN(tp->t_raw) == tp->t_rocount && (lflag&ECHOPRT) == 0) { - while (RB_LEN(&tp->t_raw)) - ttyrub(unputc(&tp->t_raw), tp); + while (RB_LEN(tp->t_raw)) + ttyrub(unputc(tp->t_raw), tp); } else { ttyecho(c, tp); if (lflag&ECHOK || lflag&ECHOKE) ttyecho('\n', tp); - while (getc(&tp->t_raw) > 0) + while (getc(tp->t_raw) > 0) ; tp->t_rocount = 0; } @@ -1106,7 +1107,7 @@ parmrk: /* * erase whitespace */ - while ((c = unputc(&tp->t_raw)) == ' ' || c == '\t') + while ((c = unputc(tp->t_raw)) == ' ' || c == '\t') ttyrub(c, tp); if (c == -1) goto endcase; @@ -1115,14 +1116,14 @@ parmrk: * next chars type (for ALTWERASE) */ ttyrub(c, tp); - c = unputc(&tp->t_raw); + c = unputc(tp->t_raw); if (c == -1) goto endcase; /* * Handle one-letter word cases. */ if (c == ' ' || c == '\t') { - putc(c, &tp->t_raw); + putc(c, tp->t_raw); goto endcase; } ctype = ISALPHA(c); @@ -1131,13 +1132,13 @@ parmrk: */ do { ttyrub(c, tp); - c = unputc(&tp->t_raw); + c = unputc(tp->t_raw); if (c == -1) goto endcase; } while (c != ' ' && c != '\t' && ((lflag & ALTWERASE) == 0 || ISALPHA(c) == ctype)); - (void) putc(c, &tp->t_raw); + (void) putc(c, tp->t_raw); goto endcase; } /* @@ -1163,7 +1164,7 @@ parmrk: if (INPUT_LEN(tp) >= MAX_INPUT) { input_overflow: if (iflag&IMAXBEL) { - if (RB_LEN(&tp->t_out) < tp->t_hiwat) + if (RB_LEN(tp->t_out) < tp->t_hiwat) (void) ttyoutput(CTRL('g'), tp); } else ttyflush(tp, FREAD); @@ -1173,7 +1174,7 @@ input_overflow: * Put data char in q for user and * wakeup on seeing a line delimiter. */ - if (putc(c, &tp->t_raw) >= 0) { + if (putc(c, tp->t_raw) >= 0) { if ((lflag&ICANON) == 0) { ttwakeup(tp); ttyecho(c, tp); @@ -1181,7 +1182,7 @@ input_overflow: } if (ttbreakc(c)) { tp->t_rocount = 0; - catb(&tp->t_raw, &tp->t_can); + catb(tp->t_raw, tp->t_can); ttwakeup(tp); } else if (tp->t_rocount++ == 0) tp->t_rocol = tp->t_col; @@ -1236,7 +1237,7 @@ ttyoutput(c, tp) if ((oflag&OPOST) == 0) { if (tp->t_lflag&FLUSHO) return (-1); - if (putc(c, &tp->t_out)) + if (putc(c, tp->t_out)) return (c); tk_nout++; tp->t_outcc++; @@ -1261,17 +1262,17 @@ ttyoutput(c, tp) #ifdef was c -= b_to_q(" ", c, &tp->t_outq); #else - i = imin(c, RB_CONTIGPUT(&tp->t_out)); - bcopy(" ", tp->t_out.rb_tl, i); - tp->t_out.rb_tl = - RB_ROLLOVER(&tp->t_out, tp->t_out.rb_tl+i); - i = imin(c - i, RB_CONTIGPUT(&tp->t_out)); + i = imin(c, RB_CONTIGPUT(tp->t_out)); + bcopy(" ", tp->t_out->rb_tl, i); + tp->t_out->rb_tl = + RB_ROLLOVER(tp->t_out, tp->t_out->rb_tl+i); + i = imin(c - i, RB_CONTIGPUT(tp->t_out)); /* off end and still have space? */ if (i) { - bcopy(" ", tp->t_out.rb_tl, i); - tp->t_out.rb_tl = - RB_ROLLOVER(&tp->t_out, tp->t_out.rb_tl+i); + bcopy(" ", tp->t_out->rb_tl, i); + tp->t_out->rb_tl = + RB_ROLLOVER(tp->t_out, tp->t_out->rb_tl+i); } #endif tk_nout += c; @@ -1291,7 +1292,7 @@ ttyoutput(c, tp) */ if (c == '\n' && (tp->t_oflag&ONLCR) && ttyoutput('\r', tp) >= 0) return (c); - if ((tp->t_lflag&FLUSHO) == 0 && putc(c, &tp->t_out)) + if ((tp->t_lflag&FLUSHO) == 0 && putc(c, tp->t_out)) return (c); col = tp->t_col; @@ -1373,7 +1374,7 @@ loop: * If canonical, use the canonical queue, * else use the raw queue. */ - qp = lflag&ICANON ? &tp->t_can : &tp->t_raw; + qp = lflag&ICANON ? tp->t_can : tp->t_raw; rblen = RB_LEN(qp); if ((lflag & ICANON) == 0) { @@ -1484,7 +1485,7 @@ sleep: */ timeout((timeout_func_t)wakeup, (caddr_t)qp, (int)slp); } - error = ttysleep(tp, (caddr_t)&tp->t_raw, TTIPRI | PCATCH, + error = ttysleep(tp, (caddr_t)tp->t_raw, TTIPRI | PCATCH, carrier ? ttyin : ttopen, 0); if (slp) { slp = 0; @@ -1612,17 +1613,17 @@ ttycheckoutq(tp, wait) oldsig = curproc->p_sig; else oldsig = 0; - if (RB_LEN(&tp->t_out) > hiwat + 200) - while (RB_LEN(&tp->t_out) > hiwat) { + if (RB_LEN(tp->t_out) > hiwat + 200) + while (RB_LEN(tp->t_out) > hiwat) { ttstart(tp); if (wait == 0 || (curproc && curproc->p_sig != oldsig)) { splx(s); return (0); } - timeout((timeout_func_t)wakeup, (caddr_t)&tp->t_out, + timeout((timeout_func_t)wakeup, (caddr_t)tp->t_out, hz); /* XXX */ tp->t_state |= TS_ASLEEP; - tsleep((caddr_t)&tp->t_out, PZERO - 1, "ttchout", 0); + tsleep((caddr_t)tp->t_out, PZERO - 1, "ttchout", 0); } splx(s); return (1); @@ -1660,7 +1661,7 @@ loop: /* * sleep awaiting carrier */ - error = ttysleep(tp, (caddr_t)&tp->t_raw, + error = ttysleep(tp, (caddr_t)tp->t_raw, TTIPRI | PCATCH,ttopen, 0); splx(s); if (error) @@ -1704,7 +1705,7 @@ loop: * to fix this is messy because of all the gotos. */ s = spltty(); - if (RB_LEN(&tp->t_out) > hiwat) { + if (RB_LEN(tp->t_out) > hiwat) { splx(s); goto ovhiwat; } @@ -1755,7 +1756,7 @@ loop: cp++, cc--; s = spltty(); if ((tp->t_lflag&FLUSHO) || - RB_LEN(&tp->t_out) > hiwat) { + RB_LEN(tp->t_out) > hiwat) { splx(s); goto ovhiwat; } @@ -1778,18 +1779,18 @@ loop: #else i = ce; s = spltty(); - ce = imin(ce, RB_CONTIGPUT(&tp->t_out)); - bcopy(cp, tp->t_out.rb_tl, ce); - tp->t_out.rb_tl = RB_ROLLOVER(&tp->t_out, - tp->t_out.rb_tl + ce); + ce = imin(ce, RB_CONTIGPUT(tp->t_out)); + bcopy(cp, tp->t_out->rb_tl, ce); + tp->t_out->rb_tl = RB_ROLLOVER(tp->t_out, + tp->t_out->rb_tl + ce); i -= ce; if (i > 0) { int ii; - ii = imin(i, RB_CONTIGPUT(&tp->t_out)); - bcopy(cp + ce, tp->t_out.rb_tl, ii); - tp->t_out.rb_tl = RB_ROLLOVER(&tp->t_out, - tp->t_out.rb_tl + ii); + ii = imin(i, RB_CONTIGPUT(tp->t_out)); + bcopy(cp + ce, tp->t_out->rb_tl, ii); + tp->t_out->rb_tl = RB_ROLLOVER(tp->t_out, + tp->t_out->rb_tl + ii); i -= ii; ce += ii; } @@ -1801,13 +1802,13 @@ loop: if (i > 0) { ttstart(tp); s = spltty(); - if (RB_CONTIGPUT(&tp->t_out) > 0) { + if (RB_CONTIGPUT(tp->t_out) > 0) { splx(s); goto loop; /* synchronous/fast */ } /* out of space, wait a bit */ tp->t_state |= TS_ASLEEP; - if (error = ttysleep(tp, (caddr_t)&tp->t_out, + if (error = ttysleep(tp, (caddr_t)tp->t_out, TTOPRI | PCATCH, ttybuf, 0)) { splx(s); break; @@ -1816,7 +1817,7 @@ loop: goto loop; } s = spltty(); - if (tp->t_lflag&FLUSHO || RB_LEN(&tp->t_out) > hiwat) { + if (tp->t_lflag&FLUSHO || RB_LEN(tp->t_out) > hiwat) { splx(s); break; } @@ -1841,7 +1842,7 @@ ovhiwat: * This can only occur if FLUSHO is set in t_lflag, * or if ttstart/oproc is synchronous (or very fast). */ - if (RB_LEN(&tp->t_out) <= hiwat) { + if (RB_LEN(tp->t_out) <= hiwat) { splx(s); goto loop; } @@ -1853,7 +1854,7 @@ ovhiwat: return (0); } tp->t_state |= TS_ASLEEP; - error = ttysleep(tp, (caddr_t)&tp->t_out, TTOPRI | PCATCH, ttyout, 0); + error = ttysleep(tp, (caddr_t)tp->t_out, TTOPRI | PCATCH, ttyout, 0); splx(s); if (error) goto out; @@ -1904,7 +1905,7 @@ ttyrub(c, tp) case TAB: { int c; - if (tp->t_rocount < RB_LEN(&tp->t_raw)) { + if (tp->t_rocount < RB_LEN(tp->t_raw)) { ttyretype(tp); return; } @@ -1913,9 +1914,9 @@ ttyrub(c, tp) tp->t_state |= TS_CNTTB; tp->t_lflag |= FLUSHO; tp->t_col = tp->t_rocol; - cp = tp->t_raw.rb_hd; - for (c = nextc(&cp, &tp->t_raw); c ; - c = nextc(&cp, &tp->t_raw)) + cp = tp->t_raw->rb_hd; + for (c = nextc(&cp, tp->t_raw); c ; + c = nextc(&cp, tp->t_raw)) ttyecho(c, tp); tp->t_lflag &= ~FLUSHO; tp->t_state &= ~TS_CNTTB; @@ -1979,16 +1980,16 @@ ttyretype(tp) (void) ttyoutput('\n', tp); s = spltty(); - cp = tp->t_can.rb_hd; - for (c = nextc(&cp, &tp->t_can); c ; c = nextc(&cp, &tp->t_can)) + cp = tp->t_can->rb_hd; + for (c = nextc(&cp, tp->t_can); c ; c = nextc(&cp, tp->t_can)) ttyecho(c, tp); - cp = tp->t_raw.rb_hd; - for (c = nextc(&cp, &tp->t_raw); c ; c = nextc(&cp, &tp->t_raw)) + cp = tp->t_raw->rb_hd; + for (c = nextc(&cp, tp->t_raw); c ; c = nextc(&cp, tp->t_raw)) ttyecho(c, tp); tp->t_state &= ~TS_ERASE; splx(s); - tp->t_rocount = RB_LEN(&tp->t_raw); + tp->t_rocount = RB_LEN(tp->t_raw); tp->t_rocol = 0; } @@ -2049,7 +2050,7 @@ ttwakeup(tp) } if (tp->t_state & TS_ASYNC) pgsignal(tp->t_pgrp, SIGIO, 1); - wakeup((caddr_t)&tp->t_raw); + wakeup((caddr_t)tp->t_raw); } /* @@ -2273,3 +2274,57 @@ ttysleep(tp, chan, pri, wmesg, timo) return (ERESTART); return (0); } + + +/* + * Allocate a tty structure and its associated buffers. + */ +struct tty * +ttymalloc(itp) + struct tty *itp; +{ + struct tty *tp; + +#ifndef broken + /* + * Note that the itp input is not necessary when we can dealloc + * the struct tty. + */ + if(itp == NULL) { + MALLOC(tp, struct tty *, sizeof(struct tty), M_TTYS, M_WAITOK); + bzero(tp, sizeof *tp); + } else { + tp = itp; + } +#endif + if(tp->t_raw == NULL) { + MALLOC(tp->t_raw, struct ringb *, sizeof(struct ringb), M_TTYS, M_WAITOK); + bzero(tp->t_raw, sizeof *tp->t_raw); + } + if(tp->t_can == NULL) { + MALLOC(tp->t_can, struct ringb *, sizeof(struct ringb), M_TTYS, M_WAITOK); + bzero(tp->t_can, sizeof *tp->t_can); + } + if(tp->t_out == NULL) { + MALLOC(tp->t_out, struct ringb *, sizeof(struct ringb), M_TTYS, M_WAITOK); + bzero(tp->t_out, sizeof *tp->t_out); + } + return(tp); +} + +/* + * Free a tty structure and its buffers. + */ +void +ttyfree(tp) +struct tty *tp; +{ + FREE(tp->t_raw, M_TTYS); + FREE(tp->t_can, M_TTYS); + FREE(tp->t_out, M_TTYS); + tp->t_raw = tp->t_can = tp->t_out = NULL; +#ifdef broken /* session holds a ref to the tty; can't deallocate */ + /* also set tp to NULL when this isn't broken anymore */ + FREE(tp, M_TTYS); +#endif +} diff --git a/sys/kern/tty_pty.c b/sys/kern/tty_pty.c index 0d2f132c66..419bcf4681 100644 --- a/sys/kern/tty_pty.c +++ b/sys/kern/tty_pty.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * from: @(#)tty_pty.c 7.21 (Berkeley) 5/30/91 - * $Id: tty_pty.c,v 1.8 1994/01/26 21:23:50 davidg Exp $ + * $Id: tty_pty.c,v 1.9 1994/01/29 04:04:26 davidg Exp $ */ /* @@ -66,7 +66,7 @@ static void ptcwakeup(struct tty *, int); * pts == /dev/tty[pqrs]? * ptc == /dev/pty[pqrs]? */ -struct tty pt_tty[NPTY]; +struct tty *pt_tty[NPTY]; struct pt_ioctl { int pt_flags; pid_t pt_selr, pt_selw; @@ -75,13 +75,15 @@ struct pt_ioctl { } pt_ioctl[NPTY]; int npty = NPTY; /* for pstat -t */ -#define PF_RCOLL 0x01 -#define PF_WCOLL 0x02 -#define PF_PKT 0x08 /* packet mode */ -#define PF_STOPPED 0x10 /* user told stopped */ -#define PF_REMOTE 0x20 /* remote and flow controlled input */ -#define PF_NOSTOP 0x40 -#define PF_UCNTL 0x80 /* user control mode */ +#define PF_RCOLL 0x0001 +#define PF_WCOLL 0x0002 +#define PF_PKT 0x0008 /* packet mode */ +#define PF_STOPPED 0x0010 /* user told stopped */ +#define PF_REMOTE 0x0020 /* remote and flow controlled input */ +#define PF_NOSTOP 0x0040 +#define PF_UCNTL 0x0080 /* user control mode */ +#define PF_COPEN 0x0100 /* master open */ +#define PF_SOPEN 0x0200 /* slave open */ /*ARGSUSED*/ int @@ -99,7 +101,7 @@ ptsopen(dev, flag, devtype, p) #endif if (minor(dev) >= NPTY) return (ENXIO); - tp = &pt_tty[minor(dev)]; + tp = pt_tty[minor(dev)] = ttymalloc(pt_tty[minor(dev)]); if ((tp->t_state & TS_ISOPEN) == 0) { tp->t_state |= TS_WOPEN; ttychars(tp); /* Set up default chars */ @@ -117,12 +119,13 @@ ptsopen(dev, flag, devtype, p) tp->t_state |= TS_WOPEN; if (flag&FNONBLOCK) break; - if (error = ttysleep(tp, (caddr_t)&tp->t_raw, TTIPRI | PCATCH, + if (error = ttysleep(tp, (caddr_t)tp->t_raw, TTIPRI | PCATCH, ttopen, 0)) return (error); } error = (*linesw[tp->t_line].l_open)(dev, tp, flag); ptcwakeup(tp, FREAD|FWRITE); + pt_ioctl[minor(dev)].pt_flags |= PF_SOPEN; return (error); } @@ -134,10 +137,17 @@ ptsclose(dev, flag, mode, p) { register struct tty *tp; - tp = &pt_tty[minor(dev)]; + tp = pt_tty[minor(dev)]; (*linesw[tp->t_line].l_close)(tp, flag); ttyclose(tp); ptcwakeup(tp, FREAD|FWRITE); + pt_ioctl[minor(dev)].pt_flags &= ~PF_SOPEN; + if ((pt_ioctl[minor(dev)].pt_flags & PF_COPEN) == 0) { + ttyfree(tp); +#ifdef broken /* session holds a ref to the tty; can't deallocate */ + pt_tty[minor(dev)] = (struct tty *)NULL; +#endif + } return(0); } @@ -148,7 +158,7 @@ ptsread(dev, uio, flag) int flag; { struct proc *p = curproc; - register struct tty *tp = &pt_tty[minor(dev)]; + register struct tty *tp = pt_tty[minor(dev)]; register struct pt_ioctl *pti = &pt_ioctl[minor(dev)]; int error = 0; @@ -165,22 +175,22 @@ again: TTIPRI | PCATCH, ttybg, 0)) return (error); } - if (RB_LEN(&tp->t_can) == 0) { + if (RB_LEN(tp->t_can) == 0) { if (flag & IO_NDELAY) return (EWOULDBLOCK); - if (error = ttysleep(tp, (caddr_t)&tp->t_can, + if (error = ttysleep(tp, (caddr_t)tp->t_can, TTIPRI | PCATCH, ttyin, 0)) return (error); goto again; } - while (RB_LEN(&tp->t_can) > 1 && uio->uio_resid > 0) - if (ureadc(getc(&tp->t_can), uio) < 0) { + while (RB_LEN(tp->t_can) > 1 && uio->uio_resid > 0) + if (ureadc(getc(tp->t_can), uio) < 0) { error = EFAULT; break; } - if (RB_LEN(&tp->t_can) == 1) - (void) getc(&tp->t_can); - if (RB_LEN(&tp->t_can)) + if (RB_LEN(tp->t_can) == 1) + (void) getc(tp->t_can); + if (RB_LEN(tp->t_can)) return (error); } else if (tp->t_oproc) @@ -202,7 +212,7 @@ ptswrite(dev, uio, flag) { register struct tty *tp; - tp = &pt_tty[minor(dev)]; + tp = pt_tty[minor(dev)]; if (tp->t_oproc == 0) return (EIO); return ((*linesw[tp->t_line].l_write)(tp, uio, flag)); @@ -240,7 +250,7 @@ ptcwakeup(tp, flag) pti->pt_selr = 0; pti->pt_flags &= ~PF_RCOLL; } - wakeup((caddr_t)&tp->t_out.rb_tl); + wakeup((caddr_t)&tp->t_out->rb_tl); } if (flag & FWRITE) { if (pti->pt_selw) { @@ -248,7 +258,7 @@ ptcwakeup(tp, flag) pti->pt_selw = 0; pti->pt_flags &= ~PF_WCOLL; } - wakeup((caddr_t)&tp->t_raw.rb_hd); + wakeup((caddr_t)&tp->t_raw->rb_hd); } } @@ -268,14 +278,15 @@ ptcopen(dev, flag, devtype, p) if (minor(dev) >= NPTY) return (ENXIO); - tp = &pt_tty[minor(dev)]; + tp = pt_tty[minor(dev)] = ttymalloc(pt_tty[minor(dev)]); if (tp->t_oproc) return (EIO); tp->t_oproc = ptsstart; (void)(*linesw[tp->t_line].l_modem)(tp, 1); tp->t_lflag &= ~EXTPROC; pti = &pt_ioctl[minor(dev)]; - pti->pt_flags = 0; + pti->pt_flags &= PF_SOPEN; + pti->pt_flags |= PF_COPEN; pti->pt_send = 0; pti->pt_ucntl = 0; return (0); @@ -289,7 +300,7 @@ ptcclose(dev) { register struct tty *tp; - tp = &pt_tty[minor(dev)]; + tp = pt_tty[minor(dev)]; (void)(*linesw[tp->t_line].l_modem)(tp, 0); tp->t_state &= ~TS_CARR_ON; tp->t_oproc = 0; /* mark closed */ @@ -298,6 +309,13 @@ ptcclose(dev) if (constty==tp) constty = 0; + pt_ioctl[minor(dev)].pt_flags &= ~PF_COPEN; + if ((pt_ioctl[minor(dev)].pt_flags & PF_SOPEN) == 0) { + ttyfree(tp); +#ifdef broken /* session holds a ref to the tty; can't deallocate */ + pt_tty[minor(dev)] = (struct tty *)NULL; +#endif + } return (0); } @@ -307,7 +325,7 @@ ptcread(dev, uio, flag) struct uio *uio; int flag; { - register struct tty *tp = &pt_tty[minor(dev)]; + register struct tty *tp = pt_tty[minor(dev)]; struct pt_ioctl *pti = &pt_ioctl[minor(dev)]; char buf[BUFSIZ]; int error = 0, cc; @@ -339,14 +357,14 @@ ptcread(dev, uio, flag) pti->pt_ucntl = 0; return (0); } - if (RB_LEN(&tp->t_out) && (tp->t_state&TS_TTSTOP) == 0) + if (RB_LEN(tp->t_out) && (tp->t_state&TS_TTSTOP) == 0) break; } if ((tp->t_state&TS_CARR_ON) == 0) return (0); /* EOF */ if (flag & IO_NDELAY) return (EWOULDBLOCK); - if (error = tsleep((caddr_t)&tp->t_out.rb_tl, TTIPRI | PCATCH, + if (error = tsleep((caddr_t)&tp->t_out->rb_tl, TTIPRI | PCATCH, ttyin, 0)) return (error); } @@ -356,21 +374,21 @@ ptcread(dev, uio, flag) #ifdef was cc = q_to_b(&tp->t_outq, buf, MIN(uio->uio_resid, BUFSIZ)); #else - cc = min(MIN(uio->uio_resid, BUFSIZ), RB_CONTIGGET(&tp->t_out)); + cc = min(MIN(uio->uio_resid, BUFSIZ), RB_CONTIGGET(tp->t_out)); if (cc) { - bcopy(tp->t_out.rb_hd, buf, cc); - tp->t_out.rb_hd = - RB_ROLLOVER(&tp->t_out, tp->t_out.rb_hd+cc); + bcopy(tp->t_out->rb_hd, buf, cc); + tp->t_out->rb_hd = + RB_ROLLOVER(tp->t_out, tp->t_out->rb_hd+cc); } #endif if (cc <= 0) break; error = uiomove(buf, cc, uio); } - if (RB_LEN(&tp->t_out) <= tp->t_lowat) { + if (RB_LEN(tp->t_out) <= tp->t_lowat) { if (tp->t_state&TS_ASLEEP) { tp->t_state &= ~TS_ASLEEP; - wakeup((caddr_t)&tp->t_out); + wakeup((caddr_t)tp->t_out); } if (tp->t_wsel) { selwakeup(tp->t_wsel, tp->t_state & TS_WCOLL); @@ -411,7 +429,7 @@ ptcselect(dev, rw, p) int rw; struct proc *p; { - register struct tty *tp = &pt_tty[minor(dev)]; + register struct tty *tp = pt_tty[minor(dev)]; struct pt_ioctl *pti = &pt_ioctl[minor(dev)]; struct proc *prev; int s; @@ -426,7 +444,7 @@ ptcselect(dev, rw, p) */ s = spltty(); if ((tp->t_state&TS_ISOPEN) && - RB_LEN(&tp->t_out) && (tp->t_state&TS_TTSTOP) == 0) { + RB_LEN(tp->t_out) && (tp->t_state&TS_TTSTOP) == 0) { splx(s); return (1); } @@ -448,12 +466,12 @@ ptcselect(dev, rw, p) case FWRITE: if (tp->t_state&TS_ISOPEN) { if (pti->pt_flags & PF_REMOTE) { - if (RB_LEN(&tp->t_can) == 0) + if (RB_LEN(tp->t_can) == 0) return (1); } else { - if (RB_LEN(&tp->t_raw) + RB_LEN(&tp->t_can) < TTYHOG-2) + if (RB_LEN(tp->t_raw) + RB_LEN(tp->t_can) < TTYHOG-2) return (1); - if (RB_LEN(&tp->t_can) == 0 && (tp->t_iflag&ICANON)) + if (RB_LEN(tp->t_can) == 0 && (tp->t_iflag&ICANON)) return (1); } } @@ -473,7 +491,7 @@ ptcwrite(dev, uio, flag) register struct uio *uio; int flag; { - register struct tty *tp = &pt_tty[minor(dev)]; + register struct tty *tp = pt_tty[minor(dev)]; register u_char *cp = 0; register int cc = 0; u_char locbuf[BUFSIZ]; @@ -485,12 +503,12 @@ again: if ((tp->t_state&TS_ISOPEN) == 0) goto block; if (pti->pt_flags & PF_REMOTE) { - if (RB_LEN(&tp->t_can)) + if (RB_LEN(tp->t_can)) goto block; - while (uio->uio_resid > 0 && RB_LEN(&tp->t_can) < TTYHOG - 1) { + while (uio->uio_resid > 0 && RB_LEN(tp->t_can) < TTYHOG - 1) { if (cc == 0) { cc = min(uio->uio_resid, BUFSIZ); - cc = min(cc, RB_CONTIGPUT(&tp->t_can)); + cc = min(cc, RB_CONTIGPUT(tp->t_can)); cp = locbuf; error = uiomove((caddr_t)cp, cc, uio); if (error) @@ -504,16 +522,16 @@ again: (void) b_to_q((char *)cp, cc, &tp->t_canq); #else if (cc) { - bcopy(cp, tp->t_can.rb_tl, cc); - tp->t_can.rb_tl = - RB_ROLLOVER(&tp->t_can, tp->t_can.rb_tl+cc); + bcopy(cp, tp->t_can->rb_tl, cc); + tp->t_can->rb_tl = + RB_ROLLOVER(tp->t_can, tp->t_can->rb_tl+cc); } #endif cc = 0; } - (void) putc(0, &tp->t_can); + (void) putc(0, tp->t_can); ttwakeup(tp); - wakeup((caddr_t)&tp->t_can); + wakeup((caddr_t)tp->t_can); return (0); } while (uio->uio_resid > 0) { @@ -528,9 +546,9 @@ again: return (EIO); } while (cc > 0) { - if ((RB_LEN(&tp->t_raw) + RB_LEN(&tp->t_can)) >= TTYHOG - 2 && - (RB_LEN(&tp->t_can) > 0 || !(tp->t_iflag&ICANON))) { - wakeup((caddr_t)&tp->t_raw); + if ((RB_LEN(tp->t_raw) + RB_LEN(tp->t_can)) >= TTYHOG - 2 && + (RB_LEN(tp->t_can) > 0 || !(tp->t_iflag&ICANON))) { + wakeup((caddr_t)tp->t_raw); goto block; } (*linesw[tp->t_line].l_rint)(*cp++, tp); @@ -554,7 +572,7 @@ block: return (EWOULDBLOCK); return (0); } - if (error = tsleep((caddr_t)&tp->t_raw.rb_hd, TTOPRI | PCATCH, + if (error = tsleep((caddr_t)&tp->t_raw->rb_hd, TTOPRI | PCATCH, ttyout, 0)) { /* adjust for data copied in but not written */ uio->uio_resid += cc; @@ -571,7 +589,7 @@ ptyioctl(dev, cmd, data, flag) dev_t dev; int flag; { - register struct tty *tp = &pt_tty[minor(dev)]; + register struct tty *tp = pt_tty[minor(dev)]; register struct pt_ioctl *pti = &pt_ioctl[minor(dev)]; register u_char *cc = tp->t_cc; int stop, error; @@ -648,7 +666,7 @@ ptyioctl(dev, cmd, data, flag) case TIOCSETA: case TIOCSETAW: case TIOCSETAF: - while (getc(&tp->t_out) >= 0) + while (getc(tp->t_out) >= 0) ; break; diff --git a/sys/net/if_ppp.c b/sys/net/if_ppp.c index 786a858c47..f198c4f9a1 100644 --- a/sys/net/if_ppp.c +++ b/sys/net/if_ppp.c @@ -70,7 +70,7 @@ */ /* - * $Id: if_ppp.c,v 1.6 1993/12/19 00:52:03 wollman Exp $ + * $Id: if_ppp.c,v 1.7 1993/12/20 19:31:30 wollman Exp $ * From: if_ppp.c,v 1.22 1993/08/31 23:20:40 paulus Exp * From: if_ppp.c,v 1.21 1993/08/29 11:22:37 paulus Exp * From: if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp @@ -355,7 +355,7 @@ pppread(tp, uio, flag) splx(s); return (EWOULDBLOCK); } - error = ttysleep(tp, (caddr_t)&tp->t_rawq, TTIPRI|PCATCH, ttyin, 0); + error = ttysleep(tp, (caddr_t)tp->t_rawq, TTIPRI|PCATCH, ttyin, 0); if (error) return error; } @@ -365,7 +365,7 @@ pppread(tp, uio, flag) } /* Pull place-holder byte out of canonical queue */ - getc(&tp->t_canq); + getc(tp->t_canq); /* Get the packet from the input queue */ IF_DEQUEUE(&sc->sc_inq, m0); @@ -715,9 +715,9 @@ pppstart(tp) * We are being called in lieu of ttstart and must do what * it would. */ - if (CCOUNT(&tp->t_outq) != 0 && tp->t_oproc != NULL) { + if (CCOUNT(tp->t_outq) != 0 && tp->t_oproc != NULL) { (*tp->t_oproc)(tp); - if (CCOUNT(&tp->t_outq) > PPP_HIWAT) + if (CCOUNT(tp->t_outq) > PPP_HIWAT) return; } /* @@ -809,9 +809,9 @@ pppstart(tp) * will flush any accumulated garbage. We do this whenever * the line may have been idle for some time. */ - if (CCOUNT(&tp->t_outq) == 0) { + if (CCOUNT(tp->t_outq) == 0) { ++sc->sc_bytessent; - (void) putc(PPP_FLAG, &tp->t_outq); + (void) putc(PPP_FLAG, tp->t_outq); } /* Calculate the FCS for the first mbuf's worth. */ @@ -834,7 +834,7 @@ pppstart(tp) if (n) { #ifndef RB_LEN /* NetBSD (0.9 or later), 4.3-Reno or similar. */ - ndone = n - b_to_q(start, n, &tp->t_outq); + ndone = n - b_to_q(start, n, tp->t_outq); #else #ifdef NetBSD /* NetBSD with 2-byte ring buffer entries */ @@ -843,12 +843,12 @@ pppstart(tp) /* 386BSD, FreeBSD */ int cc, nleft; for (nleft = n; nleft > 0; nleft -= cc) { - if ((cc = RB_CONTIGPUT(&tp->t_out)) == 0) + if ((cc = RB_CONTIGPUT(tp->t_out)) == 0) break; cc = min (cc, nleft); - bcopy((char *)start + n - nleft, tp->t_out.rb_tl, cc); - tp->t_out.rb_tl = RB_ROLLOVER(&tp->t_out, - tp->t_out.rb_tl + cc); + bcopy((char *)start + n - nleft, tp->t_out->rb_tl, cc); + tp->t_out->rb_tl = RB_ROLLOVER(tp->t_out, + tp->t_out->rb_tl + cc); } ndone = n - nleft; #endif /* NetBSD */ @@ -866,10 +866,10 @@ pppstart(tp) * Put it out in a different form. */ if (len) { - if (putc(PPP_ESCAPE, &tp->t_outq)) + if (putc(PPP_ESCAPE, tp->t_outq)) break; - if (putc(*start ^ PPP_TRANS, &tp->t_outq)) { - (void) unputc(&tp->t_outq); + if (putc(*start ^ PPP_TRANS, tp->t_outq)) { + (void) unputc(tp->t_outq); break; } sc->sc_bytessent += 2; @@ -912,10 +912,10 @@ pppstart(tp) * don't all fit, back out. */ for (q = endseq; q < p; ++q) - if (putc(*q, &tp->t_outq)) { + if (putc(*q, tp->t_outq)) { done = 0; for (; q > endseq; --q) - unputc(&tp->t_outq); + unputc(tp->t_outq); break; } } @@ -1213,7 +1213,7 @@ pppinput(c, tp) * Some other protocol - place on input queue for read(). * Put a placeholder byte in canq for ttselect()/ttnread(). */ - putc(0, &tp->t_canq); + putc(0, tp->t_canq); ttwakeup(tp); inq = &sc->sc_inq; break; diff --git a/sys/net/if_sl.c b/sys/net/if_sl.c index 358c2a0734..aca3b6721a 100644 --- a/sys/net/if_sl.c +++ b/sys/net/if_sl.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * from: @(#)if_sl.c 7.22 (Berkeley) 4/20/91 - * $Id: if_sl.c,v 1.6 1993/11/25 01:34:06 wollman Exp $ + * $Id: if_sl.c,v 1.7 1993/12/20 19:31:32 wollman Exp $ */ /* @@ -65,7 +65,7 @@ * interrupts and network activity; thus, splimp must be >= spltty. */ -/* $Id: if_sl.c,v 1.6 1993/11/25 01:34:06 wollman Exp $ */ +/* $Id: if_sl.c,v 1.7 1993/12/20 19:31:32 wollman Exp $ */ /* from if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp */ #include "sl.h" @@ -445,7 +445,7 @@ sloutput(ifp, m, dst, rt) } IF_ENQUEUE(ifq, m); sc->sc_if.if_lastchange = time; - if (RB_LEN(&sc->sc_ttyp->t_out) == 0) + if (RB_LEN(sc->sc_ttyp->t_out) == 0) slstart(sc->sc_ttyp); splx(s); return (0); @@ -478,7 +478,7 @@ slstart(tp) * it would. */ (*tp->t_oproc)(tp); - if (RB_LEN(&tp->t_out) > SLIP_HIWAT) + if (RB_LEN(tp->t_out) > SLIP_HIWAT) return; /* @@ -495,7 +495,7 @@ slstart(tp) * of RBSZ in tty.h also has to be upped to be at least * SLMTU*2. */ - if (min(RBSZ, 4 * SLMTU + 4) - RB_LEN(&tp->t_out) < 2 * SLMTU + 2) + if (min(RBSZ, 4 * SLMTU + 4) - RB_LEN(tp->t_out) < 2 * SLMTU + 2) return; /* @@ -558,9 +558,9 @@ slstart(tp) * will flush any accumulated garbage. We do this whenever * the line may have been idle for some time. */ - if (RB_LEN(&tp->t_out) == 0) { + if (RB_LEN(tp->t_out) == 0) { ++sc->sc_bytessent; - (void) putc(FRAME_END, &tp->t_out); + (void) putc(FRAME_END, tp->t_out); } while (m) { @@ -589,7 +589,7 @@ slstart(tp) * into the tty output queue. */ sc->sc_bytessent += rb_write( - &tp->t_out, + tp->t_out, (char *) bp, cp - bp); } @@ -599,12 +599,12 @@ slstart(tp) * Put it out in a different form. */ if (cp < ep) { - if (putc(FRAME_ESCAPE, &tp->t_out)) + if (putc(FRAME_ESCAPE, tp->t_out)) break; if (putc(*cp++ == FRAME_ESCAPE ? TRANS_FRAME_ESCAPE : TRANS_FRAME_END, - &tp->t_out)) { - (void) unputc(&tp->t_out); + tp->t_out)) { + (void) unputc(tp->t_out); break; } sc->sc_bytessent += 2; @@ -614,7 +614,7 @@ slstart(tp) m = m2; } - if (putc(FRAME_END, &tp->t_out)) { + if (putc(FRAME_END, tp->t_out)) { /* * Not enough room. Remove a char to make room * and end the packet normally. @@ -622,8 +622,8 @@ slstart(tp) * a day) you probably do not have enough clists * and you should increase "nclist" in param.c. */ - (void) unputc(&tp->t_out); - (void) putc(FRAME_END, &tp->t_out); + (void) unputc(tp->t_out); + (void) putc(FRAME_END, tp->t_out); sc->sc_if.if_collisions++; } else { ++sc->sc_bytessent; diff --git a/sys/sys/conf.h b/sys/sys/conf.h index d4afff5a20..c74da14fff 100644 --- a/sys/sys/conf.h +++ b/sys/sys/conf.h @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * from: @(#)conf.h 7.9 (Berkeley) 5/5/91 - * $Id: conf.h,v 1.3 1993/11/07 17:52:26 wollman Exp $ + * $Id: conf.h,v 1.4 1993/11/25 01:37:55 wollman Exp $ */ #ifndef _SYS_CONF_H_ @@ -81,7 +81,7 @@ struct cdevsw { d_ioctl_t *d_ioctl; d_stop_t *d_stop; d_reset_t *d_reset; - struct tty *d_ttys; + struct tty **d_ttys; d_select_t *d_select; d_mmap_t *d_mmap; d_strategy_t *d_strategy; diff --git a/sys/sys/malloc.h b/sys/sys/malloc.h index 92dc1989d4..70eba2b0d5 100644 --- a/sys/sys/malloc.h +++ b/sys/sys/malloc.h @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * from: @(#)malloc.h 7.25 (Berkeley) 5/15/91 - * $Id: malloc.h,v 1.3 1993/10/16 17:17:04 rgrimes Exp $ + * $Id: malloc.h,v 1.4 1993/11/07 17:52:43 wollman Exp $ */ #ifndef _MALLOC_H_ @@ -91,6 +91,7 @@ #define M_LOCKF 40 /* Byte-range locking structures */ #define M_PROC 41 /* Proc structures */ #define M_SUBPROC 42 /* Proc sub-structures */ +#define M_TTYS 45 /* allocated tty structures */ #define M_ISOFSMNT 48 /* isofs mount structures */ #define M_TEMP 49 /* misc temporary data buffers */ #define M_PCFSMNT 50 /* PCFS mount structure */ @@ -142,7 +143,9 @@ "lockf", /* 40 M_LOCKF */ \ "proc", /* 41 M_PROC */ \ "subproc", /* 42 M_PROC */ \ - 0, 0, 0, 0, 0, \ + 0, 0, \ + "ttys", /* 45 M_TTYS */ \ + 0, 0, \ "isofs mount", /* 48 M_ISOFSMNT */ \ "temp", /* 49 M_TEMP */ \ "PCFS mount", /* 50 M_PCFSMNT */ \ diff --git a/sys/sys/tty.h b/sys/sys/tty.h index f949ff8458..f580e6d0b8 100644 --- a/sys/sys/tty.h +++ b/sys/sys/tty.h @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * from: @(#)tty.h 7.10 (Berkeley) 6/26/91 - * $Id: tty.h,v 1.7 1993/12/19 00:55:28 wollman Exp $ + * $Id: tty.h,v 1.8 1994/01/28 23:15:17 ache Exp $ */ #ifndef _SYS_TTY_H_ @@ -42,8 +42,11 @@ /* * Ring buffers provide a contiguous, dense storage for * character data used by the tty driver. + * + * Make sizeof(struct ringb) be such that it fits exactly in + * a malloc bucket. */ -#define RBSZ 1024 +#define RBSZ 2040 struct ringb { char *rb_hd; /* head of buffer segment to be read */ @@ -117,9 +120,9 @@ struct tty { #if 0 int t_mask; /* interrupt mask */ #endif - struct ringb t_raw; /* ring buffers */ - struct ringb t_can; - struct ringb t_out; + struct ringb *t_raw; /* ring buffers */ + struct ringb *t_can; + struct ringb *t_out; }; #define TTIPRI 25 /* sleep priority for tty reads */ @@ -127,7 +130,7 @@ struct tty { #define TTMASK 15 #define OBUFSIZ 100 -#define TTYHOG 1024 +#define TTYHOG RBSZ #ifdef KERNEL #define TTMAXHIWAT (RBSZ/2) /* XXX */ @@ -237,6 +240,8 @@ extern void ttsetwater(struct tty *); extern void ttyinfo(struct tty *); extern int tputchar(int, struct tty *); extern int ttysleep(struct tty *, caddr_t, int, const char *, int); +extern struct tty *ttymalloc(struct tty *); +extern void ttyfree(struct tty *); /* From tty_ring.c: */ extern int putc(int, struct ringb *); -- 2.20.1