aboutsummaryrefslogtreecommitdiff
path: root/manual/memory.texi
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2016-06-10 10:46:05 +0200
committerFlorian Weimer <fweimer@redhat.com>2016-06-10 10:46:05 +0200
commit2ba3cfa1607c36613f3b30fb1ae4ec530245ce64 (patch)
tree4c215fe75ef1c016943e36821137257480097e01 /manual/memory.texi
parentf00faa4a43706d85ad8d4d2c970d3f52f0f63bfb (diff)
downloadglibc-2ba3cfa1607c36613f3b30fb1ae4ec530245ce64.zip
glibc-2ba3cfa1607c36613f3b30fb1ae4ec530245ce64.tar.gz
glibc-2ba3cfa1607c36613f3b30fb1ae4ec530245ce64.tar.bz2
malloc: Remove __malloc_initialize_hook from the API [BZ #19564]
__malloc_initialize_hook is interposed by application code, so the usual approach to define a compatibility symbol does not work. This commit adds a new mechanism based on #pragma GCC poison in <stdc-predef.h>.
Diffstat (limited to 'manual/memory.texi')
-rw-r--r--manual/memory.texi24
1 files changed, 2 insertions, 22 deletions
diff --git a/manual/memory.texi b/manual/memory.texi
index a3ecc0d..92f041a 100644
--- a/manual/memory.texi
+++ b/manual/memory.texi
@@ -1370,19 +1370,6 @@ should make sure to restore all the hooks to their previous value. When
coming back from the recursive call, all the hooks should be resaved
since a hook might modify itself.
-@comment malloc.h
-@comment GNU
-@defvar __malloc_initialize_hook
-The value of this variable is a pointer to a function that is called
-once when the malloc implementation is initialized. This is a weak
-variable, so it can be overridden in the application with a definition
-like the following:
-
-@smallexample
-void (*@var{__malloc_initialize_hook}) (void) = my_init_hook;
-@end smallexample
-@end defvar
-
An issue to look out for is the time at which the malloc hook functions
can be safely installed. If the hook functions call the malloc-related
functions recursively, it is necessary that malloc has already properly
@@ -1393,11 +1380,6 @@ are assigned to @emph{before} the very first @code{malloc} call has
completed, because otherwise a chunk obtained from the ordinary,
un-hooked malloc may later be handed to @code{__free_hook}, for example.
-In both cases, the problem can be solved by setting up the hooks from
-within a user-defined function pointed to by
-@code{__malloc_initialize_hook}---then the hooks will be set up safely
-at the right time.
-
Here is an example showing how to use @code{__malloc_hook} and
@code{__free_hook} properly. It installs a function that prints out
information every time @code{malloc} or @code{free} is called. We just
@@ -1413,11 +1395,8 @@ static void my_init_hook (void);
static void *my_malloc_hook (size_t, const void *);
static void my_free_hook (void*, const void *);
-/* Override initializing hook from the C library. */
-void (*__malloc_initialize_hook) (void) = my_init_hook;
-
static void
-my_init_hook (void)
+my_init (void)
@{
old_malloc_hook = __malloc_hook;
old_free_hook = __free_hook;
@@ -1465,6 +1444,7 @@ my_free_hook (void *ptr, const void *caller)
main ()
@{
+ my_init ();
@dots{}
@}
@end smallexample