libc: add poolisoverlap() and definitions for Pool *secrmem

This commit is contained in:
cinap_lenrek 2016-08-27 20:23:55 +02:00
parent a1e96ae4b5
commit 8a73650874
3 changed files with 26 additions and 1 deletions

View file

@ -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,

View file

@ -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 <u.h>
@ -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

View file

@ -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
*/