summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2016-08-27 20:23:55 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2016-08-27 20:23:55 +0200
commit8a73650874a68575fb7b93a44f3bba352c50288a (patch)
tree349517065c63d8b28024951f9919f37d9047a19c
parenta1e96ae4b512307d69012f42a291253dee0f9303 (diff)
libc: add poolisoverlap() and definitions for Pool *secrmem
-rw-r--r--sys/include/pool.h2
-rw-r--r--sys/man/2/pool12
-rw-r--r--sys/src/libc/port/pool.c13
3 files changed, 26 insertions, 1 deletions
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 <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
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
*/