OSDN Git Service

(split) LDP: Update original to LDP v3.38.
[linuxjm/LDP_man-pages.git] / original / man3 / malloc_get_state.3
1 .\" Copyright (c) 2012 by Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein.  The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .TH MALLOC_GET_STATE 3 2012-03-26 "GNU" "Linux Programmer's Manual"
24 .SH NAME
25 get_malloc_state, set_malloc_state \- record and restore state of malloc implementation
26 .SH SYNOPSIS
27 .nf
28 .B #include <stdlib.h>
29 .sp
30 .BI "void* malloc_get_state(void);"
31
32 .BI "int malloc_set_state(void *" state );
33 .fi
34 .SH DESCRIPTION
35 The
36 .BR malloc_get_state ()
37 function records the current state of all
38 .BR malloc (3)
39 internal bookkeeping variables
40 (but not the actual contents of the heap
41 or the state of
42 .BR malloc_hook (3)
43 functions pointers).
44 The state is recorded in a system-dependent opaque data structure
45 dynamically allocated via
46 .BR malloc (3),
47 and a pointer to that data structure is returned as the function result.
48 (It is the caller's responsibility to
49 .BR free (3)
50 this memory.)
51
52 The
53 .BR malloc_set_state ()
54 function restores the state of all
55 .BR malloc (3)
56 internal bookkeeping variables to the values recorded in
57 the opaque data structure pointed to by
58 .IR state .
59 .SH RETURN VALUE
60 On success,
61 .BR malloc_get_state ()
62 returns a pointer to a newly allocated opaque data structure.
63 On error (for example, memory could not be allocated for the data structure),
64 .BR malloc_get_state ()
65 returns NULL.
66
67 On success,
68 .BR malloc_set_state ()
69 returns 0.
70 If the implementation detects that
71 .I state
72 does not point to a correctly formed data structure,
73 .\" if(ms->magic != MALLOC_STATE_MAGIC) return -1;
74 .BR malloc_set_state ()
75 returns \-1.
76 If the implementation detects that
77 the version of the data structure referred to by
78 .I state
79 is a more recent version than this implementation knows about,
80 .\" /* Must fail if the major version is too high. */
81 .\" if((ms->version & ~0xffl) > (MALLOC_STATE_VERSION & ~0xffl)) return -2;
82 .BR malloc_set_state ()
83 returns \-2.
84 .SH CONFORMING TO
85 These functions are GNU extensions.
86 .SH NOTES
87 These functions are especially useful when using this
88 .BR malloc (3)
89 implementation as part of a shared library,
90 and the heap contents are saved/restored via some other method.
91 This technique is used by the GNU Emacs to implement its "dumping" function.
92
93 Hook function pointers are never saved or restored by these
94 functions, with two exceptions:
95 if malloc checking (see
96 .BR mallopt (3))
97 was in use when
98 .BR malloc_get_state ()
99 was called, then
100 .BR malloc_set_state ()
101 resets malloc checking hooks
102 .\" i.e., calls __malloc_check_init()
103 if possible;
104 .\" i.e., malloc checking is not already in use
105 .\" and the caller requested malloc checking
106 if malloc checking was not in use in the recorded state,
107 but the caller has requested malloc checking,
108 then the hooks are reset to 0.
109 .SH SEE ALSO
110 .BR malloc (3),
111 .BR mallopt (3)