Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libast/disc/memfatal.c
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1985-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* David Korn <[email protected]> *
19
* Phong Vo <[email protected]> *
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
#ifdef VM_BADADDR
56
case VM_BADADDR:
57
error(ERROR_SYSTEM|3, "invalid pointer %p passed to free or realloc", obj);
58
return(-1);
59
#endif
60
case VM_NOMEM:
61
vmstat(region, &st);
62
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);
63
return(-1);
64
}
65
return(0);
66
}
67
68
/*
69
* initialize the malloc exception handler
70
*/
71
72
void
73
memfatal(void)
74
{
75
Vmdisc_t* disc;
76
77
malloc(0);
78
if (disc = vmdisc(Vmregion, NiL))
79
disc->exceptf = nomalloc;
80
}
81
82
#endif
83
84