ref: e836796365fdcd389aaa0fd7deed34e4f21e7334
parent: c065eadb535347661079b93ef4b77739ec40a064
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Thu Feb 6 17:47:05 EST 2014
pool: use uintptr for pool size note, arenas and blocks still use ulong for sizes. so we have to check for overflow when attempting to merge arenas.
--- a/sys/include/pool.h
+++ b/sys/include/pool.h
@@ -1,11 +1,11 @@
typedef struct Pool Pool;
struct Pool {
char* name;
- ulong maxsize;
+ uintptr maxsize;
- ulong cursize;
- ulong curfree;
- ulong curalloc;
+ uintptr cursize;
+ uintptr curfree;
+ uintptr curalloc;
ulong minarena; /* smallest size of new arena */
ulong quantum; /* allocated blocks should be multiple of */
--- a/sys/src/libc/port/pool.c
+++ b/sys/src/libc/port/pool.c
@@ -555,8 +555,8 @@
LOG(p, "newarena %lud\n", asize);
if(p->cursize+asize > p->maxsize) {
if(poolcompactl(p) == 0){
- LOG(p, "pool too big: %lud+%lud > %lud\n",
- p->cursize, asize, p->maxsize);
+ LOG(p, "pool too big: %llud+%lud > %llud\n",
+ (uvlong)p->cursize, asize, (uvlong)p->maxsize);
werrstr("memory pool too large");
}
return;
@@ -637,12 +637,14 @@
{
Bhdr *bbot, *btop;
Btail *t;
+ ulong newsize;
blockcheck(p, bot);
blockcheck(p, top);
assert(bot->aup == top && top > bot);
- if(p->merge == nil || p->merge(bot, top) == 0)
+ newsize = top->asize + ((uchar*)top - (uchar*)bot);
+ if(newsize < top->asize || p->merge == nil || p->merge(bot, top) == 0)
return nil;
/* remove top from list */
@@ -659,7 +661,7 @@
blockcheck(p, btop);
/* grow bottom arena to encompass top */
- arenasetsize(bot, top->asize + ((uchar*)top - (uchar*)bot));
+ arenasetsize(bot, newsize);
/* grow bottom block to encompass space between arenas */
blockgrow(p, bbot, (uchar*)btop-(uchar*)bbot);