]>
Commit | Line | Data |
---|---|---|
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 | 27 | malloc_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 | |
37 | The | |
38 | .BR malloc_get_state () | |
39 | function records the current state of all | |
40 | .BR malloc (3) | |
41 | internal bookkeeping variables | |
42 | (but not the actual contents of the heap | |
43 | or the state of | |
44 | .BR malloc_hook (3) | |
45 | functions pointers). | |
46 | The state is recorded in a system-dependent opaque data structure | |
47 | dynamically allocated via | |
48 | .BR malloc (3), | |
49 | and a pointer to that data structure is returned as the function result. | |
50 | (It is the caller's responsibility to | |
51 | .BR free (3) | |
52 | this memory.) | |
53 | ||
54 | The | |
55 | .BR malloc_set_state () | |
56 | function restores the state of all | |
57 | .BR malloc (3) | |
58 | internal bookkeeping variables to the values recorded in | |
59 | the opaque data structure pointed to by | |
60 | .IR state . | |
61 | .SH RETURN VALUE | |
62 | On success, | |
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 () | |
67 | returns NULL. | |
68 | ||
69 | On success, | |
70 | .BR malloc_set_state () | |
71 | returns 0. | |
72 | If the implementation detects that | |
73 | .I state | |
74 | does not point to a correctly formed data structure, | |
75 | .\" if(ms->magic != MALLOC_STATE_MAGIC) return -1; | |
76 | .BR malloc_set_state () | |
77 | returns \-1. | |
78 | If the implementation detects that | |
79 | the version of the data structure referred to by | |
80 | .I state | |
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 () | |
85 | returns \-2. | |
86 | .SH CONFORMING TO | |
87 | These functions are GNU extensions. | |
88 | .SH NOTES | |
89 | These functions are especially useful when using this | |
90 | .BR malloc (3) | |
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 the GNU Emacs to implement its "dumping" function. | |
94 | ||
95 | Hook function pointers are never saved or restored by these | |
96 | functions, with two exceptions: | |
97 | if malloc checking (see | |
98 | .BR mallopt (3)) | |
99 | was in use when | |
100 | .BR malloc_get_state () | |
101 | was called, then | |
102 | .BR malloc_set_state () | |
103 | resets malloc checking hooks | |
104 | .\" i.e., calls __malloc_check_init() | |
105 | if possible; | |
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. | |
111 | .SH SEE ALSO | |
112 | .BR malloc (3), | |
113 | .BR mallopt (3) |