|
|
1.1 root 1: /* freemem.c - freemem */
2:
3: #include <conf.h>
4: #include <kernel.h>
5: #include <mem.h>
6:
7: /*------------------------------------------------------------------------
8: * freemem -- free a memory block, returning it to memlist
9: *------------------------------------------------------------------------
10: */
11: SYSCALL freemem(block, size)
12: struct mblock *block;
13: unsigned size;
14: {
15: struct mblock *p, *q;
16: unsigned top;
17:
18: if (size==0 || (unsigned)block>(unsigned)maxaddr
1.1.1.2 ! root 19: || ((unsigned)block)<((unsigned)&end))
1.1 root 20: return(SYSERR);
21: size = (unsigned)roundew(size);
1.1.1.2 ! root 22: disable();
! 23: for( p=memlist.mnext,q= &memlist;
! 24: p != (struct mblock *) NULL && p < block ;
! 25: q=p,p=p->mnext )
1.1 root 26: ;
27: if ((top=q->mlen+(unsigned)q)>(unsigned)block && q!= &memlist ||
1.1.1.2 ! root 28: p!=NULL && (size+(unsigned)block) > (unsigned)p ) {
! 29: restore();
1.1 root 30: return(SYSERR);
31: }
32: if ( q!= &memlist && top == (unsigned)block )
1.1.1.2 ! root 33: q->mlen += size;
1.1 root 34: else {
35: block->mlen = size;
36: block->mnext = p;
37: q->mnext = block;
38: q = block;
39: }
40: if ( (unsigned)( q->mlen + (unsigned)q ) == (unsigned)p) {
41: q->mlen += p->mlen;
42: q->mnext = p->mnext;
43: }
1.1.1.2 ! root 44: restore();
1.1 root 45: return(OK);
46: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.