From 2694e78a51876af674b11914967855656678dcd0 Mon Sep 17 00:00:00 2001 From: Bill Joy Date: Wed, 9 Apr 1980 23:03:27 -0800 Subject: [PATCH] date and time created 80/04/09 16:03:27 by bill SCCS-vsn: sys/kern/subr_rmap.c 3.1 SCCS-vsn: sys/kern/subr_rmap.c.sav 3.1 --- usr/src/sys/kern/subr_rmap.c | 100 +++++++++++++++++++++++++++++++ usr/src/sys/kern/subr_rmap.c.sav | 100 +++++++++++++++++++++++++++++++ 2 files changed, 200 insertions(+) create mode 100644 usr/src/sys/kern/subr_rmap.c create mode 100644 usr/src/sys/kern/subr_rmap.c.sav diff --git a/usr/src/sys/kern/subr_rmap.c b/usr/src/sys/kern/subr_rmap.c new file mode 100644 index 0000000000..cb52606a98 --- /dev/null +++ b/usr/src/sys/kern/subr_rmap.c @@ -0,0 +1,100 @@ +/* subr_rmap.c 3.1 %H% */ + +#include "../h/param.h" +#include "../h/systm.h" +#include "../h/map.h" +#include "../h/dir.h" +#include "../h/user.h" +#include "../h/proc.h" +#include "../h/mtpr.h" +#include "../h/text.h" + +/* + * Allocate 'size' units from the given + * map. Return the base of the allocated + * space. + * In a map, the addresses are increasing and the + * list is terminated by a 0 size. + * The swap map unit is 512 bytes. + * Algorithm is first-fit. + */ +malloc(mp, size) +struct map *mp; +{ + register int a; + register struct map *bp; + + if (size <= 0) + panic("malloc"); + for (bp=mp; bp->m_size; bp++) { + if (bp->m_size >= size) { + a = bp->m_addr; + bp->m_addr += size; + if ((bp->m_size -= size) == 0) { + do { + bp++; + (bp-1)->m_addr = bp->m_addr; + } while ((bp-1)->m_size = bp->m_size); + } + if (mp == swapmap && a % CLSIZE) + panic("malloc swapmap"); + return(a); + } + } + return(0); +} + +/* + * Free the previously allocated space aa + * of size units into the specified map. + * Sort aa into map and combine on + * one or both ends if possible. + */ +mfree(mp, size, a) +struct map *mp; +register int size, a; +{ + register struct map *bp; + register int t; + + if (a <= 0) + panic("mfree addr"); + if (size <= 0) + panic("mfree size"); + bp = mp; + for (; bp->m_addr<=a && bp->m_size!=0; bp++) + continue; + if (bp>mp && (bp-1)->m_addr+(bp-1)->m_size > a) + panic("mfree begov"); + if (a+size > bp->m_addr && bp->m_size) + panic("mfree endov"); + if (bp>mp && (bp-1)->m_addr+(bp-1)->m_size == a) { + (bp-1)->m_size += size; + if (a+size == bp->m_addr) { + (bp-1)->m_size += bp->m_size; + while (bp->m_size) { + bp++; + (bp-1)->m_addr = bp->m_addr; + (bp-1)->m_size = bp->m_size; + } + } + } else { + if (a+size == bp->m_addr && bp->m_size) { + bp->m_addr -= size; + bp->m_size += size; + } else if (size) { + do { + t = bp->m_addr; + bp->m_addr = a; + a = t; + t = bp->m_size; + bp->m_size = size; + bp++; + } while (size = t); + } + } + if ((mp == kernelmap) && kmapwnt) { + kmapwnt = 0; + wakeup((caddr_t)kernelmap); + } +} diff --git a/usr/src/sys/kern/subr_rmap.c.sav b/usr/src/sys/kern/subr_rmap.c.sav new file mode 100644 index 0000000000..ec2558bd82 --- /dev/null +++ b/usr/src/sys/kern/subr_rmap.c.sav @@ -0,0 +1,100 @@ +/* subr_rmap.c.sav 3.1 %H% */ + +#include "../h/param.h" +#include "../h/systm.h" +#include "../h/map.h" +#include "../h/dir.h" +#include "../h/user.h" +#include "../h/proc.h" +#include "../h/mtpr.h" +#include "../h/text.h" + +/* + * Allocate 'size' units from the given + * map. Return the base of the allocated + * space. + * In a map, the addresses are increasing and the + * list is terminated by a 0 size. + * The swap map unit is 512 bytes. + * Algorithm is first-fit. + */ +malloc(mp, size) +struct map *mp; +{ + register int a; + register struct map *bp; + + if (size <= 0) + panic("malloc"); + for (bp=mp; bp->m_size; bp++) { + if (bp->m_size >= size) { + a = bp->m_addr; + bp->m_addr += size; + if ((bp->m_size -= size) == 0) { + do { + bp++; + (bp-1)->m_addr = bp->m_addr; + } while ((bp-1)->m_size = bp->m_size); + } + if (mp == swapmap && a % CLSIZE) + panic("malloc swapmap"); + return(a); + } + } + return(0); +} + +/* + * Free the previously allocated space aa + * of size units into the specified map. + * Sort aa into map and combine on + * one or both ends if possible. + */ +mfree(mp, size, a) +struct map *mp; +register int size, a; +{ + register struct map *bp; + register int t; + + if (a <= 0) + panic("mfree addr"); + if (size <= 0) + panic("mfree size"); + bp = mp; + for (; bp->m_addr<=a && bp->m_size!=0; bp++) + continue; + if (bp>mp && (bp-1)->m_addr+(bp-1)->m_size > a) + panic("mfree begov"); + if (a+size > bp->m_addr && bp->m_size) + panic("mfree endov"); + if (bp>mp && (bp-1)->m_addr+(bp-1)->m_size == a) { + (bp-1)->m_size += size; + if (a+size == bp->m_addr) { + (bp-1)->m_size += bp->m_size; + while (bp->m_size) { + bp++; + (bp-1)->m_addr = bp->m_addr; + (bp-1)->m_size = bp->m_size; + } + } + } else { + if (a+size == bp->m_addr && bp->m_size) { + bp->m_addr -= size; + bp->m_size += size; + } else if (size) { + do { + t = bp->m_addr; + bp->m_addr = a; + a = t; + t = bp->m_size; + bp->m_size = size; + bp++; + } while (size = t); + } + } + if ((mp == kernelmap) && kmapwnt) { + kmapwnt = 0; + wakeup((caddr_t)kernelmap); + } +} -- 2.20.1