-#ifdef MAPMEM
-hilqmapin(mp, off)
- struct mapmem *mp;
-{
- struct hilloop *hilp = &hil0; /* XXX */
- register HILQ *hq = hilp->hl_queue[mp->mm_id].hq_eventqueue;
-
- if (hq == NULL || off >= sizeof(HILQ))
- return(-1);
- return(kvtop((u_int)hq + off) >> PGSHIFT);
-}
-
-/*
- * Fork hook.
- * Unmap queue from child's address space
- */
-hilqfork(mp, ischild)
- struct mapmem *mp;
-{
- struct proc *p = u.u_procp; /* XXX */
-#ifdef DEBUG
- if (hildebug & HDB_MMAP)
- printf("hilqfork(%d): %s qnum %d\n", p->p_pid,
- ischild ? "child" : "parent", mp->mm_id);
-#endif
- if (ischild) {
- mmmapout(p, mp);
- mmfree(p, mp);
- }
-}
-
-/*
- * Vfork hook.
- * Associate queue with child when VM resources are passed.
- */
-hilqvfork(mp, fup, tup)
- struct mapmem *mp;
- struct user *fup, *tup;
-{
- struct hilloop *hilp = &hil0; /* XXX */
- register struct hiliqueue *qp = &hilp->hl_queue[mp->mm_id];
-
-#ifdef DEBUG
- if (hildebug & HDB_MMAP)
- printf("hilqvfork(%d): from %x to %x qnum %d, qprocp %x\n",
- u.u_procp->p_pid, fup->u_procp, tup->u_procp,
- mp->mm_id, qp->hq_procp);
-#endif
- if (qp->hq_procp == fup->u_procp)
- qp->hq_procp = tup->u_procp;
-}
-
-/*
- * Exit hook.
- * Unmap all devices and free all queues.
- */
-hilqexit(mp)
- struct mapmem *mp;
-{
- struct proc *p = u.u_procp; /* XXX */
- register struct hilloop *hilp = &hil0; /* XXX */
- register int mask, i;
- int s;
-
-#ifdef DEBUG
- if (hildebug & HDB_MMAP)
- printf("hilqexit(%d): qnum %d\n", p->p_pid, mp->mm_id);
-#endif
- /*
- * Atomically take all devices off the queue
- */
- mask = ~hilqmask(mp->mm_id);
- s = splhil();
- for (i = 0; i < NHILD; i++)
- hilp->hl_device[i].hd_qmask &= mask;
- splx(s);
- /*
- * Now unmap from user address space and free queue
- */
- i = mp->mm_id;
- cifree((caddr_t)hilp->hl_queue[i].hq_eventqueue, sizeof(HILQ));
- hilp->hl_queue[i].hq_eventqueue = NULL;
- hilp->hl_queue[i].hq_procp = NULL;
- mmfree(p, mp);
-}
-#endif
-
-#include "clist.h"
-
-/*
- * This is just a copy of the virgin q_to_b routine with minor
- * optimizations for HIL use. It is used for two reasons:
- * 1. If we have PAGE mode defined, the normal q_to_b processes
- * chars one at a time and breaks on newlines.
- * 2. We don't have to raise the priority to spltty() for most
- * of the clist manipulations.
- */
-hilq_to_b(q, cp, cc)
- register struct clist *q;
- register char *cp;
-{
- register struct cblock *bp;
- register int nc;
- char *acp;
- int s;
- extern char cwaiting;
-
- if (cc <= 0)
- return (0);
- s = splhil();
- if (q->c_cc <= 0) {
- q->c_cc = 0;
- q->c_cf = q->c_cl = NULL;
- splx(s);
- return (0);
- }
- acp = cp;
-
- while (cc) {
- nc = sizeof (struct cblock) - ((int)q->c_cf & CROUND);
- nc = MIN(nc, cc);
- nc = MIN(nc, q->c_cc);
- (void) bcopy(q->c_cf, cp, (unsigned)nc);
- q->c_cf += nc;
- q->c_cc -= nc;
- cc -= nc;
- cp += nc;
- if (q->c_cc <= 0) {
- bp = (struct cblock *)(q->c_cf - 1);
- bp = (struct cblock *)((int)bp & ~CROUND);
- q->c_cf = q->c_cl = NULL;
- spltty();
- bp->c_next = cfreelist;
- cfreelist = bp;
- cfreecount += CBSIZE;
- if (cwaiting) {
- wakeup(&cwaiting);
- cwaiting = 0;
- }
- break;
- }
- if (((int)q->c_cf & CROUND) == 0) {
- bp = (struct cblock *)(q->c_cf);
- bp--;
- q->c_cf = bp->c_next->c_info;
- spltty();
- bp->c_next = cfreelist;
- cfreelist = bp;
- cfreecount += CBSIZE;
- if (cwaiting) {
- wakeup(&cwaiting);
- cwaiting = 0;
- }
- splhil();
- }
- }
- splx(s);
- return (cp-acp);
-}
-