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 2014-06-13 "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 .BR malloc_get_state ()
39 function records the current state of all
41 internal bookkeeping variables
42 (but not the actual contents of the heap
46 The state is recorded in a system-dependent opaque data structure
47 dynamically allocated via
49 and a pointer to that data structure is returned as the function result.
50 (It is the caller's responsibility to
55 .BR malloc_set_state ()
56 function restores the state of all
58 internal bookkeeping variables to the values recorded in
59 the opaque data structure pointed to by
63 .BR malloc_get_state ()
64 returns a pointer to a newly allocated opaque data structure.
65 On error (for example, memory could not be allocated for the data structure),
66 .BR malloc_get_state ()
70 .BR malloc_set_state ()
72 If the implementation detects that
74 does not point to a correctly formed data structure,
75 .\" if(ms->magic != MALLOC_STATE_MAGIC) return -1;
76 .BR malloc_set_state ()
78 If the implementation detects that
79 the version of the data structure referred to by
81 is a more recent version than this implementation knows about,
82 .\" /* Must fail if the major version is too high. */
83 .\" if((ms->version & ~0xffl) > (MALLOC_STATE_VERSION & ~0xffl)) return -2;
84 .BR malloc_set_state ()
87 These functions are GNU extensions.
89 These functions are useful when using this
91 implementation as part of a shared library,
92 and the heap contents are saved/restored via some other method.
93 This technique is used by GNU Emacs to implement its "dumping" function.
95 Hook function pointers are never saved or restored by these
96 functions, with two exceptions:
97 if malloc checking (see
100 .BR malloc_get_state ()
102 .BR malloc_set_state ()
103 resets malloc checking hooks
104 .\" i.e., calls __malloc_check_init()
106 .\" i.e., malloc checking is not already in use
107 .\" and the caller requested malloc checking
108 if malloc checking was not in use in the recorded state,
109 but the caller has requested malloc checking,
110 then the hooks are reset to 0.
115 This page is part of release 3.79 of the Linux
118 A description of the project,
119 information about reporting bugs,
120 and the latest version of this page,
122 \%http://www.kernel.org/doc/man\-pages/.