From b99a099cad7066274b25de9d603e7ced37d20e19 Mon Sep 17 00:00:00 2001 From: Carl Shapiro Date: Sun, 14 Feb 2010 19:01:31 -0800 Subject: [PATCH] Add a new method to export the extent of the break, akin to return value of sbrk(0) in UNIX. In terms of dlmalloc and our proprietary contiguous mspace class, this is the highest address returned by its morecore method. --- include/cutils/mspace.h | 5 +++++ libcutils/mspace.c | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/cutils/mspace.h b/include/cutils/mspace.h index e6e404722..93fe48eed 100644 --- a/include/cutils/mspace.h +++ b/include/cutils/mspace.h @@ -87,6 +87,11 @@ mspace create_contiguous_mspace_with_base(size_t starting_capacity, size_t max_capacity, int locked, void *base); size_t destroy_contiguous_mspace(mspace msp); + +/* + Returns the position of the "break" within the given mspace. +*/ +void *contiguous_mspace_sbrk0(mspace msp); #endif /* diff --git a/libcutils/mspace.c b/libcutils/mspace.c index 63b199d5f..6d3b35c84 100644 --- a/libcutils/mspace.c +++ b/libcutils/mspace.c @@ -271,4 +271,16 @@ size_t destroy_contiguous_mspace(mspace msp) { } return 0; } + +void *contiguous_mspace_sbrk0(mspace msp) { + struct mspace_contig_state *cs; + mstate ms; + const unsigned int pagesize = PAGESIZE; + + ms = (mstate)msp; + cs = (struct mspace_contig_state *)((uintptr_t)ms & ~(pagesize-1)); + assert(cs->magic == CONTIG_STATE_MAGIC); + assert(cs->m == ms); + return cs->brk; +} #endif