]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/malloc_get_state.3
intro.1, _exit.2, access.2, alarm.2, alloc_hugepages.2, arch_prctl.2, bind.2, chdir...
[thirdparty/man-pages.git] / man3 / malloc_get_state.3
CommitLineData
0669cc5f
MK
1.\" Copyright (c) 2012 by Michael Kerrisk <mtk.manpages@gmail.com>
2.\"
93015253 3.\" %%%LICENSE_START(VERBATIM)
0669cc5f
MK
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.
4b72fb64 23.\" %%%LICENSE_END
0669cc5f 24.\"
092af13a 25.TH MALLOC_GET_STATE 3 2012-05-04 "GNU" "Linux Programmer's Manual"
0669cc5f 26.SH NAME
092af13a 27malloc_get_state, malloc_set_state \- record and restore state of malloc implementation
0669cc5f
MK
28.SH SYNOPSIS
29.nf
30.B #include <stdlib.h>
31.sp
32.BI "void* malloc_get_state(void);"
33
34.BI "int malloc_set_state(void *" state );
35.fi
36.SH DESCRIPTION
37The
38.BR malloc_get_state ()
39function records the current state of all
40.BR malloc (3)
41internal bookkeeping variables
42(but not the actual contents of the heap
43or the state of
44.BR malloc_hook (3)
45functions pointers).
46The state is recorded in a system-dependent opaque data structure
47dynamically allocated via
48.BR malloc (3),
49and a pointer to that data structure is returned as the function result.
50(It is the caller's responsibility to
51.BR free (3)
52this memory.)
53
54The
55.BR malloc_set_state ()
56function restores the state of all
57.BR malloc (3)
58internal bookkeeping variables to the values recorded in
59the opaque data structure pointed to by
60.IR state .
61.SH RETURN VALUE
62On success,
63.BR malloc_get_state ()
64returns a pointer to a newly allocated opaque data structure.
65On error (for example, memory could not be allocated for the data structure),
66.BR malloc_get_state ()
67returns NULL.
68
69On success,
70.BR malloc_set_state ()
71returns 0.
72If the implementation detects that
73.I state
74does not point to a correctly formed data structure,
75.\" if(ms->magic != MALLOC_STATE_MAGIC) return -1;
76.BR malloc_set_state ()
77returns \-1.
78If the implementation detects that
79the version of the data structure referred to by
80.I state
81is 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 ()
85returns \-2.
86.SH CONFORMING TO
87These functions are GNU extensions.
88.SH NOTES
89These functions are especially useful when using this
90.BR malloc (3)
91implementation as part of a shared library,
92and the heap contents are saved/restored via some other method.
93This technique is used by the GNU Emacs to implement its "dumping" function.
94
95Hook function pointers are never saved or restored by these
96functions, with two exceptions:
97if malloc checking (see
98.BR mallopt (3))
99was in use when
100.BR malloc_get_state ()
101was called, then
102.BR malloc_set_state ()
103resets malloc checking hooks
104.\" i.e., calls __malloc_check_init()
105if possible;
106.\" i.e., malloc checking is not already in use
107.\" and the caller requested malloc checking
108if malloc checking was not in use in the recorded state,
109but the caller has requested malloc checking,
110then the hooks are reset to 0.
111.SH SEE ALSO
112.BR malloc (3),
113.BR mallopt (3)