]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/kern/tty_dev.c
xnu-7195.101.1.tar.gz
[apple/xnu.git] / bsd / kern / tty_dev.c
index ccfd752fb142254bb2df75c0dd272ed887dd8d09..28fa8508d404803cc009694b9e7438c3035aa846 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 1997-2013 Apple Inc. All rights reserved.
+ * Copyright (c) 1997-2020 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  *
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  *
@@ -82,6 +82,7 @@
 #include <sys/sysctl.h>
 #include <miscfs/devfs/devfs.h>
 #include <miscfs/devfs/devfsdefs.h>     /* DEVFS_LOCK()/DEVFS_UNLOCK() */
 #include <sys/sysctl.h>
 #include <miscfs/devfs/devfs.h>
 #include <miscfs/devfs/devfsdefs.h>     /* DEVFS_LOCK()/DEVFS_UNLOCK() */
+#include <dev/kmreg_com.h>
 
 #if CONFIG_MACF
 #include <security/mac_framework.h>
 
 #if CONFIG_MACF
 #include <security/mac_framework.h>
@@ -506,6 +507,16 @@ out:
        return;
 }
 
        return;
 }
 
+static void
+ptcwakeup_knote(struct selinfo *sip, long hint)
+{
+       if ((sip->si_flags & SI_KNPOSTING) == 0) {
+               sip->si_flags |= SI_KNPOSTING;
+               KNOTE(&sip->si_note, hint);
+               sip->si_flags &= ~SI_KNPOSTING;
+       }
+}
+
 /*
  * Locks:      Assumes tty_lock() is held over this call.
  */
 /*
  * Locks:      Assumes tty_lock() is held over this call.
  */
@@ -520,12 +531,12 @@ ptcwakeup(struct tty *tp, int flag)
        if (flag & FREAD) {
                selwakeup(&pti->pt_selr);
                wakeup(TSA_PTC_READ(tp));
        if (flag & FREAD) {
                selwakeup(&pti->pt_selr);
                wakeup(TSA_PTC_READ(tp));
-               KNOTE(&pti->pt_selr.si_note, 1);
+               ptcwakeup_knote(&pti->pt_selr, 1);
        }
        if (flag & FWRITE) {
                selwakeup(&pti->pt_selw);
                wakeup(TSA_PTC_WRITE(tp));
        }
        if (flag & FWRITE) {
                selwakeup(&pti->pt_selw);
                wakeup(TSA_PTC_WRITE(tp));
-               KNOTE(&pti->pt_selw.si_note, 1);
+               ptcwakeup_knote(&pti->pt_selw, 1);
        }
 }
 
        }
 }
 
@@ -661,10 +672,25 @@ ptcread(dev_t dev, struct uio *uio, int flag)
                                        goto out;
                                }
                                if (pti->pt_send & TIOCPKT_IOCTL) {
                                        goto out;
                                }
                                if (pti->pt_send & TIOCPKT_IOCTL) {
-                                       cc = MIN((int)uio_resid(uio),
-                                           (int)sizeof(tp->t_termios));
-                                       uiomove((caddr_t)&tp->t_termios, cc,
-                                           uio);
+#ifdef __LP64__
+                                       if (uio->uio_segflg == UIO_USERSPACE32) {
+                                               static struct termios32 tio32;
+                                               cc = MIN((int)uio_resid(uio), (int)sizeof(tio32));
+                                               termios64to32((struct user_termios *)&tp->t_termios,
+                                                   (struct termios32 *)&tio32);
+                                               uiomove((caddr_t)&tio32, cc, uio);
+#else
+                                       if (uio->uio_segflg == UIO_USERSPACE64) {
+                                               static struct user_termios tio64;
+                                               cc = MIN((int)uio_resid(uio), (int)sizeof(tio64));
+                                               termios32to64((struct termios32 *)&tp->t_termios,
+                                                   (struct user_termios *)&tio64);
+                                               uiomove((caddr_t)&tio64, cc, uio);
+#endif
+                                       } else {
+                                               cc = MIN((int)uio_resid(uio), (int)sizeof(tp->t_termios));
+                                               uiomove((caddr_t)&tp->t_termios, cc, uio);
+                                       }
                                }
                                pti->pt_send = 0;
                                goto out;
                                }
                                pti->pt_send = 0;
                                goto out;
@@ -831,7 +857,7 @@ ptcselect(dev_t dev, int rw, void *wql, proc_t p)
                        retval = (driver->fix_7828447) ? tp->t_outq.c_cc : 1;
                        break;
                }
                        retval = (driver->fix_7828447) ? tp->t_outq.c_cc : 1;
                        break;
                }
-       /* FALLTHROUGH */
+               OS_FALLTHROUGH;
 
        case 0: /* exceptional */
                if ((tp->t_state & TS_ISOPEN) &&
 
        case 0: /* exceptional */
                if ((tp->t_state & TS_ISOPEN) &&
@@ -1011,6 +1037,9 @@ block:
        goto again;
 }
 
        goto again;
 }
 
+/*
+ * ptyioctl: Assumes dev was opened and lock was initilized
+ */
 __private_extern__ int
 ptyioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
 {
 __private_extern__ int
 ptyioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
 {
@@ -1020,9 +1049,14 @@ ptyioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
        int stop, error = 0;
        int allow_ext_ioctl = 1;
 
        int stop, error = 0;
        int allow_ext_ioctl = 1;
 
-       if (pti == NULL) {
+       if (pti == NULL || pti->pt_tty == NULL) {
                return ENXIO;
        }
                return ENXIO;
        }
+
+       if (cmd == KMIOCDISABLCONS) {
+               return 0;
+       }
+
        tp = pti->pt_tty;
        tty_lock(tp);
 
        tp = pti->pt_tty;
        tty_lock(tp);
 
@@ -1244,6 +1278,7 @@ ptyioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
                case TIOCLSET:
                        pti->pt_send |= TIOCPKT_IOCTL;
                        ptcwakeup(tp, FREAD);
                case TIOCLSET:
                        pti->pt_send |= TIOCPKT_IOCTL;
                        ptcwakeup(tp, FREAD);
+                       break;
                default:
                        break;
                }
                default:
                        break;
                }