|
|
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: PStype ps;
16: struct mblock *p, *q;
17: unsigned top;
18:
19: if (size==0 || (unsigned)block>(unsigned)maxaddr
20: || ((unsigned)block)<((unsigned)&end))
21: return(SYSERR);
22: size = (unsigned)roundew(size);
23: disable(ps);
24: for( p=memlist.mnext,q= &memlist ; (char *)p!=NULL && p<block ;
25: q=p,p=p->mnext )
26: ;
27: if ((top=q->mlen+(unsigned)q)>(unsigned)block && q!= &memlist ||
28: (char *)p!=NULL && (size+(unsigned)block) > (unsigned)p ) {
29: restore(ps);
30: return(SYSERR);
31: }
32: if ( q!= &memlist && top == (unsigned)block )
33: q->mlen += size;
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: }
44: restore(ps);
45: return(OK);
46: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.