From: Florian Krohm Date: Sat, 11 Oct 2014 14:48:38 +0000 (+0000) Subject: Merge the memory allocation bits from libvex.h into main_util.c. X-Git-Tag: svn/VALGRIND_3_11_0^2~177 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=174a4951ae507632b48d97cff6bc5f86269ab00d;p=thirdparty%2Fvalgrind.git Merge the memory allocation bits from libvex.h into main_util.c. This is to avoid linkage problems due to unresolved symbols for some compilers. See also valgrind r14600 and BZ #339542. git-svn-id: svn://svn.valgrind.org/vex/trunk@2974 --- diff --git a/VEX/priv/main_util.c b/VEX/priv/main_util.c index 31652304f1..2031b8869e 100644 --- a/VEX/priv/main_util.c +++ b/VEX/priv/main_util.c @@ -67,6 +67,11 @@ static HChar* permanent_first = &permanent[0]; static HChar* permanent_curr = &permanent[0]; static HChar* permanent_last = &permanent[N_PERMANENT_BYTES-1]; +static HChar* private_LibVEX_alloc_first = &temporary[0]; +static HChar* private_LibVEX_alloc_curr = &temporary[0]; +static HChar* private_LibVEX_alloc_last = &temporary[N_TEMPORARY_BYTES-1]; + + static VexAllocMode mode = VexAllocModeTEMP; void vexAllocSanityCheck ( void ) @@ -149,14 +154,8 @@ VexAllocMode vexGetAllocMode ( void ) return mode; } -/* Visible to library client, unfortunately. */ - -HChar* private_LibVEX_alloc_first = &temporary[0]; -HChar* private_LibVEX_alloc_curr = &temporary[0]; -HChar* private_LibVEX_alloc_last = &temporary[N_TEMPORARY_BYTES-1]; - __attribute__((noreturn)) -void private_LibVEX_alloc_OOM(void) +static void private_LibVEX_alloc_OOM(void) { const HChar* pool = "???"; if (private_LibVEX_alloc_first == &temporary[0]) pool = "TEMP"; @@ -197,6 +196,51 @@ void vexSetAllocModeTEMP_and_clear ( void ) /* Exported to library client. */ +/* Allocate in Vex's temporary allocation area. Be careful with this. + You can only call it inside an instrumentation or optimisation + callback that you have previously specified in a call to + LibVEX_Translate. The storage allocated will only stay alive until + translation of the current basic block is complete. + */ + +void* LibVEX_Alloc ( Int nbytes ) +{ + struct align { + char c; + union { + char c; + short s; + int i; + long l; + long long ll; + float f; + double d; + /* long double is currently not used and would increase alignment + unnecessarily. */ + /* long double ld; */ + void *pto; + void (*ptf)(void); + } x; + }; + +#if 0 + /* Nasty debugging hack, do not use. */ + return malloc(nbytes); +#else + HChar* curr; + HChar* next; + Int ALIGN; + ALIGN = offsetof(struct align,x) - 1; + nbytes = (nbytes + ALIGN) & ~ALIGN; + curr = private_LibVEX_alloc_curr; + next = curr + nbytes; + if (next >= private_LibVEX_alloc_last) + private_LibVEX_alloc_OOM(); + private_LibVEX_alloc_curr = next; + return curr; +#endif +} + void LibVEX_ShowAllocStats ( void ) { vex_printf("vex storage: T total %lld bytes allocated\n", diff --git a/VEX/pub/libvex.h b/VEX/pub/libvex.h index 7ebe26fa0a..6da02daf23 100644 --- a/VEX/pub/libvex.h +++ b/VEX/pub/libvex.h @@ -452,50 +452,8 @@ void LibVEX_default_VexControl ( /*OUT*/ VexControl* vcon ); You can only call it inside an instrumentation or optimisation callback that you have previously specified in a call to LibVEX_Translate. The storage allocated will only stay alive until - translation of the current basic block is complete. - */ -extern HChar* private_LibVEX_alloc_first; -extern HChar* private_LibVEX_alloc_curr; -extern HChar* private_LibVEX_alloc_last; -extern void private_LibVEX_alloc_OOM(void) __attribute__((noreturn)); - -static inline void* LibVEX_Alloc ( Int nbytes ) -{ - struct align { - char c; - union { - char c; - short s; - int i; - long l; - long long ll; - float f; - double d; - /* long double is currently not used and would increase alignment - unnecessarily. */ - /* long double ld; */ - void *pto; - void (*ptf)(void); - } x; - }; - -#if 0 - /* Nasty debugging hack, do not use. */ - return malloc(nbytes); -#else - HChar* curr; - HChar* next; - Int ALIGN; - ALIGN = offsetof(struct align,x) - 1; - nbytes = (nbytes + ALIGN) & ~ALIGN; - curr = private_LibVEX_alloc_curr; - next = curr + nbytes; - if (next >= private_LibVEX_alloc_last) - private_LibVEX_alloc_OOM(); - private_LibVEX_alloc_curr = next; - return curr; -#endif -} + translation of the current basic block is complete. */ +extern void* LibVEX_Alloc ( Int nbytes ); /* Show Vex allocation statistics. */ extern void LibVEX_ShowAllocStats ( void );