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 2017-09-15 "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);"
34 .BI "int malloc_set_state(void *" state );
38 these function are removed in glibc version 2.25.
41 .BR malloc_get_state ()
42 function records the current state of all
44 internal bookkeeping variables
45 (but not the actual contents of the heap
49 The state is recorded in a system-dependent opaque data structure
50 dynamically allocated via
52 and a pointer to that data structure is returned as the function result.
53 (It is the caller's responsibility to
58 .BR malloc_set_state ()
59 function restores the state of all
61 internal bookkeeping variables to the values recorded in
62 the opaque data structure pointed to by
66 .BR malloc_get_state ()
67 returns a pointer to a newly allocated opaque data structure.
68 On error (for example, memory could not be allocated for the data structure),
69 .BR malloc_get_state ()
73 .BR malloc_set_state ()
75 If the implementation detects that
77 does not point to a correctly formed data structure,
78 .\" if(ms->magic != MALLOC_STATE_MAGIC) return -1;
79 .BR malloc_set_state ()
81 If the implementation detects that
82 the version of the data structure referred to by
84 is a more recent version than this implementation knows about,
85 .\" /* Must fail if the major version is too high. */
86 .\" if((ms->version & ~0xffl) > (MALLOC_STATE_VERSION & ~0xffl)) return -2;
87 .BR malloc_set_state ()
90 For an explanation of the terms used in this section, see
96 Interface Attribute Value
98 .BR malloc_get_state (),
99 .BR malloc_set_state ()
100 T} Thread safety MT-Safe
104 These functions are GNU extensions.
106 These functions are useful when using this
108 implementation as part of a shared library,
109 and the heap contents are saved/restored via some other method.
110 This technique is used by GNU Emacs to implement its "dumping" function.
112 Hook function pointers are never saved or restored by these
113 functions, with two exceptions:
114 if malloc checking (see
117 .BR malloc_get_state ()
119 .BR malloc_set_state ()
120 resets malloc checking hooks
121 .\" i.e., calls __malloc_check_init()
123 .\" i.e., malloc checking is not already in use
124 .\" and the caller requested malloc checking
125 if malloc checking was not in use in the recorded state,
126 but the caller has requested malloc checking,
127 then the hooks are reset to 0.