diff --git a/sys/include/pool.h b/sys/include/pool.h index 571373e9f..5f7fada45 100644 --- a/sys/include/pool.h +++ b/sys/include/pool.h @@ -35,6 +35,7 @@ extern void* poolalloc(Pool*, ulong); extern void* poolallocalign(Pool*, ulong, ulong, long, ulong); extern void poolfree(Pool*, void*); extern ulong poolmsize(Pool*, void*); +extern int poolisoverlap(Pool*, void*, ulong); extern void* poolrealloc(Pool*, void*, ulong); extern void poolcheck(Pool*); extern int poolcompact(Pool*); @@ -43,6 +44,7 @@ extern void pooldump(Pool*); extern Pool* mainmem; extern Pool* imagmem; +extern Pool* secrmem; enum { /* flags */ POOL_ANTAGONISM = 1<<0, diff --git a/sys/man/2/pool b/sys/man/2/pool index a44b57d4d..b637e3d7c 100644 --- a/sys/man/2/pool +++ b/sys/man/2/pool @@ -1,6 +1,6 @@ .TH POOL 2 .SH NAME -poolalloc, poolallocalign, poolfree, poolmsize, poolrealloc, poolcompact, poolcheck, poolblockcheck, +poolalloc, poolallocalign, poolfree, poolmsize, poolisoverlap, poolrealloc, poolcompact, poolcheck, poolblockcheck, pooldump \- general memory management routines .SH SYNOPSIS .B #include @@ -25,6 +25,9 @@ void poolfree(Pool* pool, void* ptr) ulong poolmsize(Pool* pool, void* ptr) .PP .B +int poolisoverlap(Pool* pool, void* ptr, ulong len) +.PP +.B void* poolrealloc(Pool* pool, void* ptr, ulong size) .PP .B @@ -109,6 +112,13 @@ that would usually go unused. .IR Poolmsize grows the block to encompass this extra space and returns the new size. .PP +.I Poolisoverlap +checks if the byte span +.BR [ptr , ptr + len) +overlaps the arenas of the specified +.BR pool , +returning non-zero when there is overlap or zero if none. +.PP The .I poolblockcheck and diff --git a/sys/src/libc/port/pool.c b/sys/src/libc/port/pool.c index 25ad52c57..546d5776a 100644 --- a/sys/src/libc/port/pool.c +++ b/sys/src/libc/port/pool.c @@ -1332,6 +1332,19 @@ poolmsize(Pool *p, void *v) return dsize; } +int +poolisoverlap(Pool *p, void *v, ulong n) +{ + Arena *a; + + p->lock(p); + for(a = p->arenalist; a != nil; a = a->down) + if((uchar*)v+n > (uchar*)a && (uchar*)v < (uchar*)a+a->asize) + break; + p->unlock(p); + return a != nil; +} + /* * Debugging */