xref: /onnv-gate/usr/src/lib/libast/common/disc/memfatal.c (revision 12068:08a39a083754)
14887Schin /***********************************************************************
24887Schin *                                                                      *
34887Schin *               This software is part of the ast package               *
4*12068SRoger.Faulkner@Oracle.COM *          Copyright (c) 1985-2010 AT&T Intellectual Property          *
54887Schin *                      and is licensed under the                       *
64887Schin *                  Common Public License, Version 1.0                  *
78462SApril.Chin@Sun.COM *                    by AT&T Intellectual Property                     *
84887Schin *                                                                      *
94887Schin *                A copy of the License is available at                 *
104887Schin *            http://www.opensource.org/licenses/cpl1.0.txt             *
114887Schin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
124887Schin *                                                                      *
134887Schin *              Information and Software Systems Research               *
144887Schin *                            AT&T Research                             *
154887Schin *                           Florham Park NJ                            *
164887Schin *                                                                      *
174887Schin *                 Glenn Fowler <gsf@research.att.com>                  *
184887Schin *                  David Korn <dgk@research.att.com>                   *
194887Schin *                   Phong Vo <kpv@research.att.com>                    *
204887Schin *                                                                      *
214887Schin ***********************************************************************/
224887Schin #pragma prototyped
234887Schin 
244887Schin /*
254887Schin  * install error message handler for fatal malloc exceptions
264887Schin  */
274887Schin 
284887Schin #include <ast.h>
294887Schin #include <error.h>
304887Schin #include <vmalloc.h>
314887Schin 
324887Schin #include "FEATURE/vmalloc"
334887Schin 
344887Schin #if _std_malloc
354887Schin 
364887Schin void
memfatal(void)374887Schin memfatal(void)
384887Schin {
394887Schin }
404887Schin 
414887Schin #else
424887Schin 
434887Schin /*
444887Schin  * print message and fail on VM_BADADDR,VM_NOMEM
454887Schin  */
464887Schin 
474887Schin static int
nomalloc(Vmalloc_t * region,int type,void * obj,Vmdisc_t * disc)484887Schin nomalloc(Vmalloc_t* region, int type, void* obj, Vmdisc_t* disc)
494887Schin {
504887Schin 	Vmstat_t	st;
514887Schin 
524887Schin 	NoP(disc);
534887Schin 	switch (type)
544887Schin 	{
554887Schin 	case VM_BADADDR:
564887Schin 		error(ERROR_SYSTEM|3, "invalid pointer %p passed to free or realloc", obj);
574887Schin 		return(-1);
584887Schin 	case VM_NOMEM:
594887Schin 		vmstat(region, &st);
604887Schin 		error(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);
614887Schin 		return(-1);
624887Schin 	}
634887Schin 	return(0);
644887Schin }
654887Schin 
664887Schin /*
674887Schin  * initialize the malloc exception handler
684887Schin  */
694887Schin 
704887Schin void
memfatal(void)714887Schin memfatal(void)
724887Schin {
734887Schin 	Vmdisc_t*	disc;
744887Schin 
7510898Sroland.mainz@nrubsig.org 	malloc(0);
7610898Sroland.mainz@nrubsig.org 	if (disc = vmdisc(Vmregion, NiL))
774887Schin 		disc->exceptf = nomalloc;
784887Schin }
794887Schin 
804887Schin #endif
81