From bef248f012a4e52bac088724a070e3448b1c643c Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Wed, 7 Jun 2023 14:57:55 +0100 Subject: [PATCH] Generalising mps_addr_object, arenaaddrobject, pooladdrobject for pools that do not use segments. --- mps/code/addrobj.c | 4 +--- mps/code/arena.c | 12 +++++------- mps/code/mpm.h | 4 ++-- mps/code/mpmtypes.h | 2 +- mps/code/pool.c | 18 +++++++++++------- mps/code/poolabs.c | 6 +++--- mps/code/poolamc.c | 12 ++++++------ 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/mps/code/addrobj.c b/mps/code/addrobj.c index 1e4bcbff660..eda49fc1ffe 100644 --- a/mps/code/addrobj.c +++ b/mps/code/addrobj.c @@ -148,9 +148,7 @@ static void test_main(void) /* Do the test */ res = mps_addr_object(&out, arena, in); - /* We should insist MPS_RES_UNIMPL here but the Trivial Method for mps_addr_object is only reached for pools that contain objects in Segs. - Since mvff does not, and the input address is not inside a Seg, the call is rejected by the Arena with MPS_RES_FAIL */ - Insist(res == MPS_RES_FAIL); + Insist(res == MPS_RES_UNIMPL); /* Final clean up */ mps_free(mvff_pool, in, sizeof(mps_word_t)); diff --git a/mps/code/arena.c b/mps/code/arena.c index 9b5fc8f7a3e..7139ff4bc86 100644 --- a/mps/code/arena.c +++ b/mps/code/arena.c @@ -1367,19 +1367,17 @@ Bool ArenaHasAddr(Arena arena, Addr addr) /* ArenaAddrObject -- return base pointer of managed object */ Res ArenaAddrObject(Addr *pReturn, Arena arena, Addr addr) { - Seg seg; - Pool pool; + Tract tract; AVER(pReturn != NULL); AVERT(Arena, arena); - /* We currently assume that managed objects are inside Segments - and that pools where this feature is needed have Segments */ - if (!SegOfAddr(&seg, arena, addr)) + if (!TractOfAddr(&tract, arena, addr)) { + /* address does not belong to the arena */ return ResFAIL; + } - pool = SegPool(seg); - return PoolAddrObject(pReturn, pool, seg, addr); + return PoolAddrObject(pReturn, TractPool(tract), addr); } diff --git a/mps/code/mpm.h b/mps/code/mpm.h index d896fe369f8..e072a7a1ea7 100644 --- a/mps/code/mpm.h +++ b/mps/code/mpm.h @@ -236,7 +236,7 @@ extern Res PoolTraceBegin(Pool pool, Trace trace); extern void PoolFreeWalk(Pool pool, FreeBlockVisitor f, void *p); extern Size PoolTotalSize(Pool pool); extern Size PoolFreeSize(Pool pool); -extern Res PoolAddrObject(Addr *pReturn, Pool pool, Seg seg, Addr addr); +extern Res PoolAddrObject(Addr *pReturn, Pool pool, Addr addr); extern Res PoolAbsInit(Pool pool, Arena arena, PoolClass klass, ArgList arg); extern void PoolAbsFinish(Inst inst); @@ -268,7 +268,7 @@ extern void PoolTrivFreeWalk(Pool pool, FreeBlockVisitor f, void *p); extern PoolDebugMixin PoolNoDebugMixin(Pool pool); extern BufferClass PoolNoBufferClass(void); extern Size PoolNoSize(Pool pool); -extern Res PoolTrivAddr(Addr *pReturn, Pool pool, Seg seg, Addr addr); +extern Res PoolTrivAddrObject(Addr *pReturn, Pool pool, Addr addr); /* See .critical.macros. */ #define PoolFreeMacro(pool, old, size) Method(Pool, pool, free)(pool, old, size) diff --git a/mps/code/mpmtypes.h b/mps/code/mpmtypes.h index d68134a6574..c219e908e06 100644 --- a/mps/code/mpmtypes.h +++ b/mps/code/mpmtypes.h @@ -214,7 +214,7 @@ typedef Res (*PoolFramePushMethod)(AllocFrame *frameReturn, Pool pool, Buffer buf); typedef Res (*PoolFramePopMethod)(Pool pool, Buffer buf, AllocFrame frame); -typedef Res (*PoolAddrObjectMethod)(Addr *pReturn, Pool pool, Seg seg, Addr addr); +typedef Res (*PoolAddrObjectMethod)(Addr *pReturn, Pool pool, Addr addr); typedef void (*PoolFreeWalkMethod)(Pool pool, FreeBlockVisitor f, void *p); typedef BufferClass (*PoolBufferClassMethod)(void); typedef PoolDebugMixin (*PoolDebugMixinMethod)(Pool pool); diff --git a/mps/code/pool.c b/mps/code/pool.c index 0257359e36f..fc04563175b 100644 --- a/mps/code/pool.c +++ b/mps/code/pool.c @@ -303,16 +303,20 @@ Size PoolFreeSize(Pool pool) return Method(Pool, pool, freeSize)(pool); } -/* PoolAddrObject -- return base pointer from interior pointer */ -Res PoolAddrObject(Addr *pReturn, Pool pool, Seg seg, Addr addr) + +/* PoolAddrObject -- return base pointer from interior pointer + * + * Note: addr is not necessarily inside the pool, even though + * mps_addr_object dispatches via the tract table. This allows this + * function to be used more generally internally. The pool should + * check (it has to anyway). + */ + +Res PoolAddrObject(Addr *pReturn, Pool pool, Addr addr) { AVER(pReturn != NULL); AVERT(Pool, pool); - AVERT(Seg, seg); - AVER(pool == SegPool(seg)); - AVER(SegBase(seg) <= addr); - AVER(addr < SegLimit(seg)); - return Method(Pool, pool, addrObject)(pReturn, pool, seg, addr); + return Method(Pool, pool, addrObject)(pReturn, pool, addr); } /* PoolDescribe -- describe a pool */ diff --git a/mps/code/poolabs.c b/mps/code/poolabs.c index eb469e967de..d6eae2dd046 100644 --- a/mps/code/poolabs.c +++ b/mps/code/poolabs.c @@ -173,7 +173,7 @@ DEFINE_CLASS(Pool, AbstractPool, klass) klass->debugMixin = PoolNoDebugMixin; klass->totalSize = PoolNoSize; klass->freeSize = PoolNoSize; - klass->addrObject = PoolTrivAddr; + klass->addrObject = PoolTrivAddrObject; klass->sig = PoolClassSig; AVERT(PoolClass, klass); } @@ -476,10 +476,10 @@ Size PoolNoSize(Pool pool) return UNUSED_SIZE; } -Res PoolTrivAddr(Addr *pReturn, Pool pool, Seg seg, Addr addr) + +Res PoolTrivAddrObject(Addr *pReturn, Pool pool, Addr addr) { AVERT(Pool, pool); - AVERT(Seg, seg); AVER(pReturn != NULL); UNUSED(addr); diff --git a/mps/code/poolamc.c b/mps/code/poolamc.c index f62413b6401..4455bb9e859 100644 --- a/mps/code/poolamc.c +++ b/mps/code/poolamc.c @@ -1926,24 +1926,24 @@ static Res amcAddrObjectSearch(Addr *pReturn, Pool pool, Addr objBase, return ResFAIL; } + /* AMCAddrObject -- return base pointer from interior pointer */ -static Res AMCAddrObject(Addr *pReturn, Pool pool, Seg seg, Addr addr) +static Res AMCAddrObject(Addr *pReturn, Pool pool, Addr addr) { Res res; Arena arena; Addr base, limit; Buffer buffer; - + Seg seg; AVER(pReturn != NULL); AVERT(Pool, pool); - AVERT(Seg, seg); - AVER(SegPool(seg) == pool); - AVER(SegBase(seg) <= addr); - AVER(addr < SegLimit(seg)); arena = PoolArena(pool); + if (!SegOfAddr(&seg, arena, addr) || SegPool(seg) != pool) + return ResFAIL; + base = SegBase(seg); if (SegBuffer(&buffer, seg)) limit = BufferGetInit(buffer);