From: Andy McFadden Date: Mon, 27 Jul 2009 21:44:22 +0000 (-0700) Subject: Added dvmLinearAllocContains(). X-Git-Tag: android-x86-2.2~796 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=7605a84a9a0a1764c1fb290d9c93e8114eaf620a;p=android-x86%2Fdalvik.git Added dvmLinearAllocContains(). --- diff --git a/vm/LinearAlloc.c b/vm/LinearAlloc.c index 84bb1035b..5863fb0d4 100644 --- a/vm/LinearAlloc.c +++ b/vm/LinearAlloc.c @@ -688,3 +688,21 @@ static void checkAllFree(Object* classLoader) dvmUnlockMutex(&pHdr->lock); } +/* + * Determine if [start, start+length) is contained in the in-use area of + * a single LinearAlloc. The full set of linear allocators is scanned. + * + * [ Since we currently only have one region, this is pretty simple. In + * the future we'll need to traverse a table of class loaders. ] + */ +bool dvmLinearAllocContains(void* start, size_t length) +{ + LinearAllocHdr* pHdr = getHeader(NULL); + + if (pHdr == NULL) + return false; + + return (char*) start >= pHdr->mapAddr && + ((char*)start + length) <= (pHdr->mapAddr + pHdr->curOffset); +} + diff --git a/vm/LinearAlloc.h b/vm/LinearAlloc.h index 9c1d0962e..c9a5c0899 100644 --- a/vm/LinearAlloc.h +++ b/vm/LinearAlloc.h @@ -112,4 +112,10 @@ char* dvmLinearStrdup(Object* classLoader, const char* str); */ void dvmLinearAllocDump(Object* classLoader); +/* + * Determine if [start, start+length) is contained in the in-use area of + * a single LinearAlloc. The full set of linear allocators is scanned. + */ +bool dvmLinearAllocContains(void* start, size_t length); + #endif /*_DALVIK_LINEARALLOC*/ diff --git a/vm/oo/Class.c b/vm/oo/Class.c index 330c3812e..23ffb0bc7 100644 --- a/vm/oo/Class.c +++ b/vm/oo/Class.c @@ -271,6 +271,12 @@ static void linearAllocTests() char* str = dvmLinearStrdup(NULL, "This is a test!"); LOGI("GOT: '%s'\n", str); + /* try to check the bounds; allocator may round allocation size up */ + fiddle = dvmLinearAlloc(NULL, 12); + LOGI("Should be 1: %d\n", dvmLinearAllocContains(fiddle, 12)); + LOGI("Should be 0: %d\n", dvmLinearAllocContains(fiddle, 13)); + LOGI("Should be 0: %d\n", dvmLinearAllocContains(fiddle - 128*1024, 1)); + dvmLinearAllocDump(NULL); dvmLinearFree(NULL, str); }