1 .\" Copyright (c) 2012 by Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .TH MALLOC_GET_STATE 3 2021-03-22 "GNU" "Linux Programmer's Manual"
27 malloc_get_state, malloc_set_state \- record and restore state of malloc implementation
30 .B #include <malloc.h>
32 .BI "void *malloc_get_state(void);"
33 .BI "int malloc_set_state(void *" state );
37 these function are removed in glibc version 2.25.
40 .BR malloc_get_state ()
41 function records the current state of all
43 internal bookkeeping variables
44 (but not the actual contents of the heap
48 The state is recorded in a system-dependent opaque data structure
49 dynamically allocated via
51 and a pointer to that data structure is returned as the function result.
52 (It is the caller's responsibility to
57 .BR malloc_set_state ()
58 function restores the state of all
60 internal bookkeeping variables to the values recorded in
61 the opaque data structure pointed to by
65 .BR malloc_get_state ()
66 returns a pointer to a newly allocated opaque data structure.
67 On error (for example, memory could not be allocated for the data structure),
68 .BR malloc_get_state ()
72 .BR malloc_set_state ()
74 If the implementation detects that
76 does not point to a correctly formed data structure,
77 .\" if(ms->magic != MALLOC_STATE_MAGIC) return -1;
78 .BR malloc_set_state ()
80 If the implementation detects that
81 the version of the data structure referred to by
83 is a more recent version than this implementation knows about,
84 .\" /* Must fail if the major version is too high. */
85 .\" if((ms->version & ~0xffl) > (MALLOC_STATE_VERSION & ~0xffl)) return -2;
86 .BR malloc_set_state ()
89 For an explanation of the terms used in this section, see
97 Interface Attribute Value
99 .BR malloc_get_state (),
100 .BR malloc_set_state ()
101 T} Thread safety MT-Safe
107 These functions are GNU extensions.
109 These functions are useful when using this
111 implementation as part of a shared library,
112 and the heap contents are saved/restored via some other method.
113 This technique is used by GNU Emacs to implement its "dumping" function.
115 Hook function pointers are never saved or restored by these
116 functions, with two exceptions:
117 if malloc checking (see
120 .BR malloc_get_state ()
122 .BR malloc_set_state ()
123 resets malloc checking hooks
124 .\" i.e., calls __malloc_check_init()
126 .\" i.e., malloc checking is not already in use
127 .\" and the caller requested malloc checking
128 if malloc checking was not in use in the recorded state,
129 but the caller has requested malloc checking,
130 then the hooks are reset to 0.