/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* David Korn <[email protected]> *18* Phong Vo <[email protected]> *19* *20***********************************************************************/21#pragma prototyped2223/*24* install error message handler for fatal malloc exceptions25*/2627#include <ast.h>28#include <error.h>29#include <vmalloc.h>3031#include "FEATURE/vmalloc"3233#if _std_malloc3435void36memfatal(void)37{38}3940#else4142/*43* print message and fail on VM_BADADDR,VM_NOMEM44*/4546static int47nomalloc(Vmalloc_t* region, int type, void* obj, Vmdisc_t* disc)48{49Vmstat_t st;5051NoP(disc);52switch (type)53{54#ifdef VM_BADADDR55case VM_BADADDR:56error(ERROR_SYSTEM|3, "invalid pointer %p passed to free or realloc", obj);57return(-1);58#endif59case VM_NOMEM:60vmstat(region, &st);61error(ERROR_SYSTEM|3, "storage allocator out of space on %lu byte request ( region %lu segments %lu busy %lu:%lu:%lu free %lu:%lu:%lu )", (size_t)obj, st.extent, st.n_seg, st.n_busy, st.s_busy, st.m_busy, st.n_free, st.s_free, st.m_free);62return(-1);63}64return(0);65}6667/*68* initialize the malloc exception handler69*/7071void72memfatal(void)73{74Vmdisc_t* disc;7576malloc(0);77if (disc = vmdisc(Vmregion, NiL))78disc->exceptf = nomalloc;79}8081#endif828384