ref: 8a73650874a68575fb7b93a44f3bba352c50288a
parent: a1e96ae4b512307d69012f42a291253dee0f9303
author: cinap_lenrek <[email protected]>
date: Sat Aug 27 16:23:55 EDT 2016
libc: add poolisoverlap() and definitions for Pool *secrmem
--- a/sys/include/pool.h
+++ b/sys/include/pool.h
@@ -35,6 +35,7 @@
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 Pool* mainmem;
extern Pool* imagmem;
+extern Pool* secrmem;
enum { /* flags */
POOL_ANTAGONISM = 1<<0,
--- 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 @@
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
@@ -108,6 +111,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
--- a/sys/src/libc/port/pool.c
+++ b/sys/src/libc/port/pool.c
@@ -1332,6 +1332,19 @@
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
*/