2 .\" Copyright (c) 2012 by Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .TH malloc_get_state 3 (date) "Linux man-pages (unreleased)"
8 malloc_get_state, malloc_set_state \-
9 record and restore state of malloc implementation
12 .RI ( libc ", " \-lc )
15 .B #include <malloc.h>
17 .B void *malloc_get_state(void);
18 .BI "int malloc_set_state(void *" state );
22 these function are removed in glibc 2.25.
25 .BR malloc_get_state ()
26 function records the current state of all
28 internal bookkeeping variables
29 (but not the actual contents of the heap
33 The state is recorded in a system-dependent opaque data structure
34 dynamically allocated via
36 and a pointer to that data structure is returned as the function result.
37 (It is the caller's responsibility to
42 .BR malloc_set_state ()
43 function restores the state of all
45 internal bookkeeping variables to the values recorded in
46 the opaque data structure pointed to by
50 .BR malloc_get_state ()
51 returns a pointer to a newly allocated opaque data structure.
52 On error (for example, memory could not be allocated for the data structure),
53 .BR malloc_get_state ()
57 .BR malloc_set_state ()
59 If the implementation detects that
61 does not point to a correctly formed data structure,
62 .\" if(ms->magic != MALLOC_STATE_MAGIC) return -1;
63 .BR malloc_set_state ()
65 If the implementation detects that
66 the version of the data structure referred to by
68 is a more recent version than this implementation knows about,
69 .\" /* Must fail if the major version is too high. */
70 .\" if((ms->version & ~0xffl) > (MALLOC_STATE_VERSION & ~0xffl)) return -2;
71 .BR malloc_set_state ()
74 For an explanation of the terms used in this section, see
82 Interface Attribute Value
84 .BR malloc_get_state (),
85 .BR malloc_set_state ()
86 T} Thread safety MT-Safe
94 These functions are useful when using this
96 implementation as part of a shared library,
97 and the heap contents are saved/restored via some other method.
98 This technique is used by GNU Emacs to implement its "dumping" function.
100 Hook function pointers are never saved or restored by these
101 functions, with two exceptions:
102 if malloc checking (see
105 .BR malloc_get_state ()
107 .BR malloc_set_state ()
108 resets malloc checking hooks
109 .\" i.e., calls __malloc_check_init()
111 .\" i.e., malloc checking is not already in use
112 .\" and the caller requested malloc checking
113 if malloc checking was not in use in the recorded state,
114 but the caller has requested malloc checking,
115 then the hooks are reset to 0.