Deleted Added
full compact
tty_ttydisc.c (198185) tty_ttydisc.c (223575)
1/*-
2 * Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Portions of this software were developed under sponsorship from Snow
6 * B.V., the Netherlands.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 14 unchanged lines hidden (view full) ---

23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Portions of this software were developed under sponsorship from Snow
6 * B.V., the Netherlands.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 14 unchanged lines hidden (view full) ---

23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: head/sys/kern/tty_ttydisc.c 198185 2009-10-17 08:59:41Z ed $");
31__FBSDID("$FreeBSD: head/sys/kern/tty_ttydisc.c 223575 2011-06-26 18:26:20Z ed $");
32
33#include <sys/param.h>
34#include <sys/fcntl.h>
35#include <sys/filio.h>
36#include <sys/kernel.h>
37#include <sys/signal.h>
38#include <sys/sysctl.h>
39#include <sys/systm.h>

--- 225 unchanged lines hidden (view full) ---

265ttydisc_read_raw_interbyte_timer(struct tty *tp, struct uio *uio, int ioflag)
266{
267 size_t vmin = tp->t_termios.c_cc[VMIN];
268 int oresid = uio->uio_resid;
269 int error;
270
271 MPASS(tp->t_termios.c_cc[VMIN] != 0);
272 MPASS(tp->t_termios.c_cc[VTIME] != 0);
32
33#include <sys/param.h>
34#include <sys/fcntl.h>
35#include <sys/filio.h>
36#include <sys/kernel.h>
37#include <sys/signal.h>
38#include <sys/sysctl.h>
39#include <sys/systm.h>

--- 225 unchanged lines hidden (view full) ---

265ttydisc_read_raw_interbyte_timer(struct tty *tp, struct uio *uio, int ioflag)
266{
267 size_t vmin = tp->t_termios.c_cc[VMIN];
268 int oresid = uio->uio_resid;
269 int error;
270
271 MPASS(tp->t_termios.c_cc[VMIN] != 0);
272 MPASS(tp->t_termios.c_cc[VTIME] != 0);
273
273
274 /*
275 * When using the interbyte timer, the timer should be started
276 * after the first byte has been received. We just call into the
277 * generic read timer code after we've received the first byte.
278 */
274 /*
275 * When using the interbyte timer, the timer should be started
276 * after the first byte has been received. We just call into the
277 * generic read timer code after we've received the first byte.
278 */
279
279
280 for (;;) {
281 error = ttyinq_read_uio(&tp->t_inq, tp, uio,
282 uio->uio_resid, 0);
283 if (error)
284 return (error);
285 if (uio->uio_resid == 0 || (oresid - uio->uio_resid) >= vmin)
286 return (0);
287

--- 38 unchanged lines hidden (view full) ---

326 else
327 error = ttydisc_read_raw_interbyte_timer(tp, uio, ioflag);
328
329 if (ttyinq_bytesleft(&tp->t_inq) >= tp->t_inlow ||
330 ttyinq_bytescanonicalized(&tp->t_inq) == 0) {
331 /* Unset the input watermark when we've got enough space. */
332 tty_hiwat_in_unblock(tp);
333 }
280 for (;;) {
281 error = ttyinq_read_uio(&tp->t_inq, tp, uio,
282 uio->uio_resid, 0);
283 if (error)
284 return (error);
285 if (uio->uio_resid == 0 || (oresid - uio->uio_resid) >= vmin)
286 return (0);
287

--- 38 unchanged lines hidden (view full) ---

326 else
327 error = ttydisc_read_raw_interbyte_timer(tp, uio, ioflag);
328
329 if (ttyinq_bytesleft(&tp->t_inq) >= tp->t_inlow ||
330 ttyinq_bytescanonicalized(&tp->t_inq) == 0) {
331 /* Unset the input watermark when we've got enough space. */
332 tty_hiwat_in_unblock(tp);
333 }
334
334
335 return (error);
336}
337
338static __inline unsigned int
339ttydisc_findchar(const char *obstart, unsigned int oblen)
340{
341 const char *c = obstart;
342

--- 173 unchanged lines hidden (view full) ---

516
517 /* Watermark reached. Try to sleep. */
518 tp->t_flags |= TF_HIWAT_OUT;
519
520 if (ioflag & IO_NDELAY) {
521 error = EWOULDBLOCK;
522 goto done;
523 }
335 return (error);
336}
337
338static __inline unsigned int
339ttydisc_findchar(const char *obstart, unsigned int oblen)
340{
341 const char *c = obstart;
342

--- 173 unchanged lines hidden (view full) ---

516
517 /* Watermark reached. Try to sleep. */
518 tp->t_flags |= TF_HIWAT_OUT;
519
520 if (ioflag & IO_NDELAY) {
521 error = EWOULDBLOCK;
522 goto done;
523 }
524
524
525 /*
526 * The driver may write back the data
527 * synchronously. Be sure to check the high
528 * water mark before going to sleep.
529 */
530 ttydevsw_outwakeup(tp);
531 if ((tp->t_flags & TF_HIWAT_OUT) == 0)
532 continue;

--- 29 unchanged lines hidden (view full) ---

562
563 if (ttyhook_hashook(tp, rint_bypass)) {
564 tp->t_flags |= TF_BYPASS;
565 } else if (ttyhook_hashook(tp, rint)) {
566 tp->t_flags &= ~TF_BYPASS;
567 } else if (!CMP_FLAG(i, ICRNL|IGNCR|IMAXBEL|INLCR|ISTRIP|IXON) &&
568 (!CMP_FLAG(i, BRKINT) || CMP_FLAG(i, IGNBRK)) &&
569 (!CMP_FLAG(i, PARMRK) ||
525 /*
526 * The driver may write back the data
527 * synchronously. Be sure to check the high
528 * water mark before going to sleep.
529 */
530 ttydevsw_outwakeup(tp);
531 if ((tp->t_flags & TF_HIWAT_OUT) == 0)
532 continue;

--- 29 unchanged lines hidden (view full) ---

562
563 if (ttyhook_hashook(tp, rint_bypass)) {
564 tp->t_flags |= TF_BYPASS;
565 } else if (ttyhook_hashook(tp, rint)) {
566 tp->t_flags &= ~TF_BYPASS;
567 } else if (!CMP_FLAG(i, ICRNL|IGNCR|IMAXBEL|INLCR|ISTRIP|IXON) &&
568 (!CMP_FLAG(i, BRKINT) || CMP_FLAG(i, IGNBRK)) &&
569 (!CMP_FLAG(i, PARMRK) ||
570 CMP_FLAG(i, IGNPAR|IGNBRK) == (IGNPAR|IGNBRK)) &&
570 CMP_FLAG(i, IGNPAR|IGNBRK) == (IGNPAR|IGNBRK)) &&
571 !CMP_FLAG(l, ECHO|ICANON|IEXTEN|ISIG|PENDIN)) {
572 tp->t_flags |= TF_BYPASS;
573 } else {
574 tp->t_flags &= ~TF_BYPASS;
575 }
576}
577
578void
579ttydisc_modem(struct tty *tp, int open)
580{
581
582 tty_lock_assert(tp, MA_OWNED);
583
584 if (open)
585 cv_broadcast(&tp->t_dcdwait);
571 !CMP_FLAG(l, ECHO|ICANON|IEXTEN|ISIG|PENDIN)) {
572 tp->t_flags |= TF_BYPASS;
573 } else {
574 tp->t_flags &= ~TF_BYPASS;
575 }
576}
577
578void
579ttydisc_modem(struct tty *tp, int open)
580{
581
582 tty_lock_assert(tp, MA_OWNED);
583
584 if (open)
585 cv_broadcast(&tp->t_dcdwait);
586
586
587 /*
588 * Ignore modem status lines when CLOCAL is turned on, but don't
589 * enter the zombie state when the TTY isn't opened, because
590 * that would cause the TTY to be in zombie state after being
591 * opened.
592 */
593 if (!tty_opened(tp) || CMP_FLAG(c, CLOCAL))
594 return;

--- 234 unchanged lines hidden (view full) ---

829 size_t ol;
830
831 tty_lock_assert(tp, MA_OWNED);
832
833 atomic_add_long(&tty_nin, 1);
834
835 if (ttyhook_hashook(tp, rint))
836 return ttyhook_rint(tp, c, flags);
587 /*
588 * Ignore modem status lines when CLOCAL is turned on, but don't
589 * enter the zombie state when the TTY isn't opened, because
590 * that would cause the TTY to be in zombie state after being
591 * opened.
592 */
593 if (!tty_opened(tp) || CMP_FLAG(c, CLOCAL))
594 return;

--- 234 unchanged lines hidden (view full) ---

829 size_t ol;
830
831 tty_lock_assert(tp, MA_OWNED);
832
833 atomic_add_long(&tty_nin, 1);
834
835 if (ttyhook_hashook(tp, rint))
836 return ttyhook_rint(tp, c, flags);
837
837
838 if (tp->t_flags & TF_BYPASS)
839 goto processed;
840
841 if (flags) {
842 if (flags & TRE_BREAK) {
843 if (CMP_FLAG(i, IGNBRK)) {
844 /* Ignore break characters. */
845 return (0);

--- 221 unchanged lines hidden (view full) ---

1067}
1068
1069size_t
1070ttydisc_rint_bypass(struct tty *tp, const void *buf, size_t len)
1071{
1072 size_t ret;
1073
1074 tty_lock_assert(tp, MA_OWNED);
838 if (tp->t_flags & TF_BYPASS)
839 goto processed;
840
841 if (flags) {
842 if (flags & TRE_BREAK) {
843 if (CMP_FLAG(i, IGNBRK)) {
844 /* Ignore break characters. */
845 return (0);

--- 221 unchanged lines hidden (view full) ---

1067}
1068
1069size_t
1070ttydisc_rint_bypass(struct tty *tp, const void *buf, size_t len)
1071{
1072 size_t ret;
1073
1074 tty_lock_assert(tp, MA_OWNED);
1075
1075
1076 MPASS(tp->t_flags & TF_BYPASS);
1077
1078 atomic_add_long(&tty_nin, len);
1079
1080 if (ttyhook_hashook(tp, rint_bypass))
1081 return ttyhook_rint_bypass(tp, buf, len);
1082
1083 ret = ttyinq_write(&tp->t_inq, buf, len, 0);

--- 33 unchanged lines hidden (view full) ---

1117 * XXX: Still allow character input when there's no space in the
1118 * buffers, but we haven't entered the high watermark. This is
1119 * to allow backspace characters to be inserted when in
1120 * canonical mode.
1121 */
1122 l = ttyinq_bytesleft(&tp->t_inq);
1123 if (l == 0 && (tp->t_flags & TF_HIWAT_IN) == 0)
1124 return (1);
1076 MPASS(tp->t_flags & TF_BYPASS);
1077
1078 atomic_add_long(&tty_nin, len);
1079
1080 if (ttyhook_hashook(tp, rint_bypass))
1081 return ttyhook_rint_bypass(tp, buf, len);
1082
1083 ret = ttyinq_write(&tp->t_inq, buf, len, 0);

--- 33 unchanged lines hidden (view full) ---

1117 * XXX: Still allow character input when there's no space in the
1118 * buffers, but we haven't entered the high watermark. This is
1119 * to allow backspace characters to be inserted when in
1120 * canonical mode.
1121 */
1122 l = ttyinq_bytesleft(&tp->t_inq);
1123 if (l == 0 && (tp->t_flags & TF_HIWAT_IN) == 0)
1124 return (1);
1125
1125
1126 return (l);
1127}
1128
1129static void
1130ttydisc_wakeup_watermark(struct tty *tp)
1131{
1132 size_t c;
1133

--- 62 unchanged lines hidden (view full) ---

1196 MIN(uio->uio_resid, sizeof buf));
1197 if (len == 0)
1198 break;
1199
1200 /* Copy to userspace. */
1201 tty_unlock(tp);
1202 error = uiomove(buf, len, uio);
1203 tty_lock(tp);
1126 return (l);
1127}
1128
1129static void
1130ttydisc_wakeup_watermark(struct tty *tp)
1131{
1132 size_t c;
1133

--- 62 unchanged lines hidden (view full) ---

1196 MIN(uio->uio_resid, sizeof buf));
1197 if (len == 0)
1198 break;
1199
1200 /* Copy to userspace. */
1201 tty_unlock(tp);
1202 error = uiomove(buf, len, uio);
1203 tty_lock(tp);
1204
1204
1205 if (error != 0)
1206 break;
1207 }
1208 } else {
1209 error = ttyoutq_read_uio(&tp->t_outq, tp, uio);
1210
1211 ttydisc_wakeup_watermark(tp);
1212 atomic_add_long(&tty_nout, obytes - uio->uio_resid);

--- 41 unchanged lines hidden ---
1205 if (error != 0)
1206 break;
1207 }
1208 } else {
1209 error = ttyoutq_read_uio(&tp->t_outq, tp, uio);
1210
1211 ttydisc_wakeup_watermark(tp);
1212 atomic_add_long(&tty_nout, obytes - uio->uio_resid);

--- 41 unchanged lines hidden ---