mount_setattr.2: ffix
[man-pages.git] / man3 / malloc_get_state.3
blob72ffa07511945c26f56790803ea675f033874cdd
1 .\" Copyright (c) 2012 by Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
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.
7 .\"
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.
12 .\"
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
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .TH MALLOC_GET_STATE 3 2021-03-22 "GNU" "Linux Programmer's Manual"
26 .SH NAME
27 malloc_get_state, malloc_set_state \- record and restore state of malloc implementation
28 .SH SYNOPSIS
29 .nf
30 .B #include <malloc.h>
31 .PP
32 .BI "void *malloc_get_state(void);"
33 .BI "int malloc_set_state(void *" state );
34 .fi
35 .SH DESCRIPTION
36 .IR Note :
37 these function are removed in glibc version 2.25.
38 .PP
39 The
40 .BR malloc_get_state ()
41 function records the current state of all
42 .BR malloc (3)
43 internal bookkeeping variables
44 (but not the actual contents of the heap
45 or the state of
46 .BR malloc_hook (3)
47 functions pointers).
48 The state is recorded in a system-dependent opaque data structure
49 dynamically allocated via
50 .BR malloc (3),
51 and a pointer to that data structure is returned as the function result.
52 (It is the caller's responsibility to
53 .BR free (3)
54 this memory.)
55 .PP
56 The
57 .BR malloc_set_state ()
58 function restores the state of all
59 .BR malloc (3)
60 internal bookkeeping variables to the values recorded in
61 the opaque data structure pointed to by
62 .IR state .
63 .SH RETURN VALUE
64 On success,
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 ()
69 returns NULL.
70 .PP
71 On success,
72 .BR malloc_set_state ()
73 returns 0.
74 If the implementation detects that
75 .I state
76 does not point to a correctly formed data structure,
77 .\" if(ms->magic != MALLOC_STATE_MAGIC) return -1;
78 .BR malloc_set_state ()
79 returns \-1.
80 If the implementation detects that
81 the version of the data structure referred to by
82 .I state
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 ()
87 returns \-2.
88 .SH ATTRIBUTES
89 For an explanation of the terms used in this section, see
90 .BR attributes (7).
91 .ad l
92 .nh
93 .TS
94 allbox;
95 lbx lb lb
96 l l l.
97 Interface       Attribute       Value
99 .BR malloc_get_state (),
100 .BR malloc_set_state ()
101 T}      Thread safety   MT-Safe
105 .sp 1
106 .SH CONFORMING TO
107 These functions are GNU extensions.
108 .SH NOTES
109 These functions are useful when using this
110 .BR malloc (3)
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
118 .BR mallopt (3))
119 was in use when
120 .BR malloc_get_state ()
121 was called, then
122 .BR malloc_set_state ()
123 resets malloc checking hooks
124 .\" i.e., calls __malloc_check_init()
125 if possible;
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.
131 .SH SEE ALSO
132 .BR malloc (3),
133 .BR mallopt (3)