1 /*
2 Copyright (c) 1990 Regents of the University of California.
3 All rights reserved.
4  */
5 /* VxWorks provides its own version of malloc, and we can't use this
6    one because VxWorks does not provide sbrk.  So we have a hook to
7    not compile this code.  */
8 
9 #ifdef MALLOC_PROVIDED
10 
11 int _dummy_mstats = 1;
12 
13 #else
14 
15 /*
16 FUNCTION
17 <<mallinfo>>, <<malloc_stats>>, <<mallopt>>---malloc support
18 
19 INDEX
20 	mallinfo
21 INDEX
22 	malloc_stats
23 INDEX
24 	mallopt
25 INDEX
26 	_mallinfo_r
27 INDEX
28 	_malloc_stats_r
29 INDEX
30 	_mallopt_r
31 
32 SYNOPSIS
33 	#include <malloc.h>
34 	struct mallinfo mallinfo(void);
35 	void malloc_stats(void);
36 	int mallopt(int <[parameter]>, <[value]>);
37 
38 	struct mallinfo _mallinfo_r(void *<[reent]>);
39 	void _malloc_stats_r(void *<[reent]>);
40 	int _mallopt_r(void *<[reent]>, int <[parameter]>, <[value]>);
41 
42 DESCRIPTION
43 <<mallinfo>> returns a structure describing the current state of
44 memory allocation.  The structure is defined in malloc.h.  The
45 following fields are defined: <<arena>> is the total amount of space
46 in the heap; <<ordblks>> is the number of chunks which are not in use;
47 <<uordblks>> is the total amount of space allocated by <<malloc>>;
48 <<fordblks>> is the total amount of space not in use; <<keepcost>> is
49 the size of the top most memory block.
50 
51 <<malloc_stats>> print some statistics about memory allocation on
52 standard error.
53 
54 <<mallopt>> takes a parameter and a value.  The parameters are defined
55 in malloc.h, and may be one of the following: <<M_TRIM_THRESHOLD>>
56 sets the maximum amount of unused space in the top most block before
57 releasing it back to the system in <<free>> (the space is released by
58 calling <<_sbrk_r>> with a negative argument); <<M_TOP_PAD>> is the
59 amount of padding to allocate whenever <<_sbrk_r>> is called to
60 allocate more space.
61 
62 The alternate functions <<_mallinfo_r>>, <<_malloc_stats_r>>, and
63 <<_mallopt_r>> are reentrant versions.  The extra argument <[reent]>
64 is a pointer to a reentrancy structure.
65 
66 RETURNS
67 <<mallinfo>> returns a mallinfo structure.  The structure is defined
68 in malloc.h.
69 
70 <<malloc_stats>> does not return a result.
71 
72 <<mallopt>> returns zero if the parameter could not be set, or
73 non-zero if it could be set.
74 
75 PORTABILITY
76 <<mallinfo>> and <<mallopt>> are provided by SVR4, but <<mallopt>>
77 takes different parameters on different systems.  <<malloc_stats>> is
78 not portable.
79 
80 */
81 
82 #include <_ansi.h>
83 #include <stdlib.h>
84 #include <malloc.h>
85 #include <stdio.h>
86 
87 #if !defined (_ELIX_LEVEL) || _ELIX_LEVEL >= 2
88 
89 /* mstats is now compatibility code.  It used to be real, for a
90    previous version of the malloc routines.  It now just calls
91    malloc_stats.  */
92 
93 #ifndef _REENT_ONLY
94 
95 void
mstats(char * s)96 mstats (char *s)
97 {
98   fprintf (stderr, "Memory allocation statistics %s\n", s);
99   malloc_stats ();
100 }
101 
102 #endif
103 
104 #endif /* !_ELIX_LEVEL || _ELIX_LEVEL >= 2 */
105 
106 #endif /* ! defined (MALLOC_PROVIDED) */
107