void *(*resizef) (Vmalloc_t *, void *, size_t, int);
int (*freef) (Vmalloc_t *, void *);
long (*addrf) (Vmalloc_t *, void *);
- long (*sizef) (Vmalloc_t *, void *);
unsigned short meth;
};
extern int vmfree(Vmalloc_t *, void *);
extern long vmaddr(Vmalloc_t *, void *);
- extern long vmsize(Vmalloc_t *, void *);
extern Vmalloc_t *vmregion(void *);
extern int vmset(Vmalloc_t *, int, int);
#define vmfree(vm,d) (*(_VM_(vm)->meth.freef))((vm),(void*)(d))
#endif
#define vmaddr(vm,addr) (*(_VM_(vm)->meth.addrf))((vm),(void*)(addr))
-#define vmsize(vm,addr) (*(_VM_(vm)->meth.sizef))((vm),(void*)(addr))
#define vmoldof(v,p,t,n,x) (t*)vmresize((v), (p), sizeof(t)*(n)+(x), \
(VM_RSMOVE) )
#define vmnewof(v,p,t,n,x) (t*)vmresize((v), (p), sizeof(t)*(n)+(x), \
return data;
}
-/**
- * @param vm region allocating from
- * @param addr address to check
- */
-static long bestsize(Vmalloc_t * vm, void * addr)
-{
- reg Seg_t *seg;
- reg Block_t *b, *endb;
- reg long size;
- reg Vmdata_t *vd = vm->data;
-
- if (!(vd->mode & VM_TRUST)) {
- if (ISLOCK(vd, 0))
- return -1L;
- SETLOCK(vd, 0);
- }
-
- size = -1L;
- for (seg = vd->seg; seg; seg = seg->next) {
- b = SEGBLOCK(seg);
- endb = (Block_t *) (seg->baddr - sizeof(Head_t));
- if ((Vmuchar_t *) addr <= (Vmuchar_t *) b ||
- (Vmuchar_t *) addr >= (Vmuchar_t *) endb)
- continue;
- while (b < endb) {
- if (addr == DATA(b)) {
- if (!ISBUSY(SIZE(b)) || ISJUNK(SIZE(b)))
- size = -1L;
- else
- size = (long) SIZE(b) & ~BITS;
- goto done;
- } else if ((Vmuchar_t *) addr <= (Vmuchar_t *) b)
- break;
-
- b = (Block_t *) ((Vmuchar_t *) DATA(b) + (SIZE(b) & ~BITS));
- }
- }
-
- done:
- CLRLOCK(vd, 0);
- return size;
-}
-
/* A discipline to get memory using sbrk() or VirtualAlloc on win32 */
/**
* @param vm region doing allocation from
bestresize,
bestfree,
bestaddr,
- bestsize,
VM_MTBEST
};
bestresize,
bestfree,
bestaddr,
- bestsize,
VM_MTBEST},
NIL(char *), /* file */
0, /* line */