xref: /titanic_51/usr/src/lib/libast/common/disc/memfatal.c (revision f34a71784df3fbc5d1227a7b6201fd318ad1667e)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2008 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #pragma prototyped
23 
24 /*
25  * install error message handler for fatal malloc exceptions
26  */
27 
28 #include <ast.h>
29 #include <error.h>
30 #include <vmalloc.h>
31 
32 #include "FEATURE/vmalloc"
33 
34 #if _std_malloc
35 
36 void
37 memfatal(void)
38 {
39 }
40 
41 #else
42 
43 /*
44  * print message and fail on VM_BADADDR,VM_NOMEM
45  */
46 
47 static int
48 nomalloc(Vmalloc_t* region, int type, void* obj, Vmdisc_t* disc)
49 {
50 	Vmstat_t	st;
51 
52 	NoP(disc);
53 	switch (type)
54 	{
55 	case VM_BADADDR:
56 		error(ERROR_SYSTEM|3, "invalid pointer %p passed to free or realloc", obj);
57 		return(-1);
58 	case VM_NOMEM:
59 		vmstat(region, &st);
60 		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);
61 		return(-1);
62 	}
63 	return(0);
64 }
65 
66 /*
67  * initialize the malloc exception handler
68  */
69 
70 void
71 memfatal(void)
72 {
73 	Vmdisc_t*	disc;
74 
75 	if (disc = vmdisc(Vmheap, NiL))
76 		disc->exceptf = nomalloc;
77 }
78 
79 #endif
80