]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man/man3/malloc_get_state.3
man/, share/mk/: Move man*/ to man/
[thirdparty/man-pages.git] / man / man3 / malloc_get_state.3
CommitLineData
a1eaacb1 1'\" t
0669cc5f
MK
2.\" Copyright (c) 2012 by Michael Kerrisk <mtk.manpages@gmail.com>
3.\"
5fbde956 4.\" SPDX-License-Identifier: Linux-man-pages-copyleft
0669cc5f 5.\"
4c1c5274 6.TH malloc_get_state 3 (date) "Linux man-pages (unreleased)"
0669cc5f 7.SH NAME
15f0b7af
AC
8malloc_get_state, malloc_set_state \-
9record and restore state of malloc implementation
a00fca47
AC
10.SH LIBRARY
11Standard C library
8fc3b2cf 12.RI ( libc ", " \-lc )
0669cc5f
MK
13.SH SYNOPSIS
14.nf
ebae2ae3 15.B #include <malloc.h>
c6d039a3 16.P
1ae6b2c7 17.B void *malloc_get_state(void);
0669cc5f
MK
18.BI "int malloc_set_state(void *" state );
19.fi
20.SH DESCRIPTION
30ed4712 21.IR Note :
aa606765 22these functions are removed in glibc 2.25.
c6d039a3 23.P
0669cc5f
MK
24The
25.BR malloc_get_state ()
26function records the current state of all
27.BR malloc (3)
28internal bookkeeping variables
29(but not the actual contents of the heap
30or the state of
31.BR malloc_hook (3)
32functions pointers).
33The state is recorded in a system-dependent opaque data structure
34dynamically allocated via
35.BR malloc (3),
36and a pointer to that data structure is returned as the function result.
37(It is the caller's responsibility to
38.BR free (3)
39this memory.)
c6d039a3 40.P
0669cc5f
MK
41The
42.BR malloc_set_state ()
43function restores the state of all
44.BR malloc (3)
45internal bookkeeping variables to the values recorded in
46the opaque data structure pointed to by
47.IR state .
48.SH RETURN VALUE
49On success,
50.BR malloc_get_state ()
51returns a pointer to a newly allocated opaque data structure.
52On error (for example, memory could not be allocated for the data structure),
53.BR malloc_get_state ()
54returns NULL.
c6d039a3 55.P
0669cc5f
MK
56On success,
57.BR malloc_set_state ()
58returns 0.
59If the implementation detects that
60.I state
61does not point to a correctly formed data structure,
62.\" if(ms->magic != MALLOC_STATE_MAGIC) return -1;
63.BR malloc_set_state ()
64returns \-1.
65If the implementation detects that
66the version of the data structure referred to by
67.I state
68is 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 ()
72returns \-2.
99f8b666
ZL
73.SH ATTRIBUTES
74For an explanation of the terms used in this section, see
75.BR attributes (7).
76.TS
77allbox;
c466875e 78lbx lb lb
99f8b666
ZL
79l l l.
80Interface Attribute Value
81T{
9e54434e
BR
82.na
83.nh
99f8b666
ZL
84.BR malloc_get_state (),
85.BR malloc_set_state ()
86T} Thread safety MT-Safe
87.TE
3113c7f3 88.SH STANDARDS
4131356c 89GNU.
0669cc5f 90.SH NOTES
98a9b1ab 91These functions are useful when using this
0669cc5f
MK
92.BR malloc (3)
93implementation as part of a shared library,
94and the heap contents are saved/restored via some other method.
98a9b1ab 95This technique is used by GNU Emacs to implement its "dumping" function.
c6d039a3 96.P
0669cc5f
MK
97Hook function pointers are never saved or restored by these
98functions, with two exceptions:
99if malloc checking (see
100.BR mallopt (3))
101was in use when
102.BR malloc_get_state ()
103was called, then
104.BR malloc_set_state ()
105resets malloc checking hooks
106.\" i.e., calls __malloc_check_init()
107if possible;
108.\" i.e., malloc checking is not already in use
109.\" and the caller requested malloc checking
110if malloc checking was not in use in the recorded state,
111but the caller has requested malloc checking,
112then the hooks are reset to 0.
113.SH SEE ALSO
114.BR malloc (3),
115.BR mallopt (3)