1 .\" Copyright (c) 2012 by Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .TH MALLOC_GET_STATE 3 2012-03-26 "GNU" "Linux Programmer's Manual"
25 get_malloc_state, set_malloc_state \- record and restore state of malloc implementation
28 .B #include <stdlib.h>
30 .BI "void* malloc_get_state(void);"
32 .BI "int malloc_set_state(void *" state );
36 .BR malloc_get_state ()
37 function records the current state of all
39 internal bookkeeping variables
40 (but not the actual contents of the heap
44 The state is recorded in a system-dependent opaque data structure
45 dynamically allocated via
47 and a pointer to that data structure is returned as the function result.
48 (It is the caller's responsibility to
53 .BR malloc_set_state ()
54 function restores the state of all
56 internal bookkeeping variables to the values recorded in
57 the opaque data structure pointed to by
61 .BR malloc_get_state ()
62 returns a pointer to a newly allocated opaque data structure.
63 On error (for example, memory could not be allocated for the data structure),
64 .BR malloc_get_state ()
68 .BR malloc_set_state ()
70 If the implementation detects that
72 does not point to a correctly formed data structure,
73 .\" if(ms->magic != MALLOC_STATE_MAGIC) return -1;
74 .BR malloc_set_state ()
76 If the implementation detects that
77 the version of the data structure referred to by
79 is a more recent version than this implementation knows about,
80 .\" /* Must fail if the major version is too high. */
81 .\" if((ms->version & ~0xffl) > (MALLOC_STATE_VERSION & ~0xffl)) return -2;
82 .BR malloc_set_state ()
85 These functions are GNU extensions.
87 These functions are especially useful when using this
89 implementation as part of a shared library,
90 and the heap contents are saved/restored via some other method.
91 This technique is used by the GNU Emacs to implement its "dumping" function.
93 Hook function pointers are never saved or restored by these
94 functions, with two exceptions:
95 if malloc checking (see
98 .BR malloc_get_state ()
100 .BR malloc_set_state ()
101 resets malloc checking hooks
102 .\" i.e., calls __malloc_check_init()
104 .\" i.e., malloc checking is not already in use
105 .\" and the caller requested malloc checking
106 if malloc checking was not in use in the recorded state,
107 but the caller has requested malloc checking,
108 then the hooks are reset to 0.