From 15938f377f67cb87e223a970aef070d708b53ee4 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sat, 2 Sep 1995 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1995-09-02 --- port/qio.c | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/port/qio.c b/port/qio.c index e13ae6101485b6a727ecf518580ab42c76a57fcd..4a1239f60a6c18fb0609360a98969fdd3f93d810 100644 --- a/port/qio.c +++ b/port/qio.c @@ -138,16 +138,19 @@ ixsummary(void) } /* - * allocate queues and blocks (round data base address to 64 bit boundary) + * allocate blocks (round data base address to 64 bit boundary). + * if mallocz gives us more than we asked for, leave room at the front + * for header. */ Block* allocb(int size) { Block *b; ulong addr; + int n; - size = sizeof(Block) + size + (BY2V-1); - b = mallocz(size, 0); + n = sizeof(Block) + size + (BY2V-1); + b = mallocz(n, 0); if(b == 0) exhausted("Blocks"); memset(b, 0, sizeof(Block)); @@ -155,13 +158,40 @@ allocb(int size) addr = (ulong)b; addr = ROUND(addr + sizeof(Block), BY2V); b->base = (uchar*)addr; + b->lim = ((uchar*)b) + msize(b); b->rp = b->base; - b->wp = b->base; - b->lim = ((uchar*)b) + size; + n = b->lim - b->base - size; + b->rp += n & ~(BY2V-1); + b->wp = b->rp; return b; } +ulong bpadoverhead; + +/* + * pad a block to the front + */ +Block* +bpad(Block *bp, int size) +{ + int n; + Block *nbp; + + if(bp->rp - bp->base > size) + return bp; + + n = bp->wp - bp->rp; + bpadoverhead += n; + nbp = allocb(size+n); + nbp->rp += size; + nbp->wp = nbp->rp; + memmove(nbp->wp, bp->rp, n); + nbp->wp += n; + freeb(bp); + return nbp; +} + /* * Interrupt level copy out of a queue, return # bytes copied. */