.\" -*- coding: UTF-8 -*- .\" Copyright 2002 Walter Harms (walter.harms@informatik.uni-oldenburg.de) .\" .\" SPDX-License-Identifier: GPL-1.0-or-later .\" .\" Heavily based on glibc documentation .\" Polished, added docs, removed glibc doc bug, 2002-07-20, aeb .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH __malloc_hook 3 "3 mai 2023" "Pages du manuel de Linux 6.05.01" .SH NOM __malloc_hook, __malloc_initialize_hook, __memalign_hook, __free_hook, __realloc_hook, __after_morecore_hook \- Variables de débogage de malloc (OBSOLÈTE) .SH BIBLIOTHÈQUE Bibliothèque C standard (\fIlibc\fP, \fI\-lc\fP) .SH SYNOPSIS .nf \fB#include \fP .PP \fBvoid *(*volatile __malloc_hook)(size_t \fP\fIsize\fP\fB, const void *\fP\fIcaller\fP\fB);\fP .PP \fBvoid *(*volatile __realloc_hook)(void *\fP\fIptr\fP\fB, size_t \fP\fIsize\fP\fB,\fP \fB const void *\fP\fIcaller\fP\fB);\fP .PP \fBvoid *(*volatile __memalign_hook)(size_t \fP\fIalignment\fP\fB, size_t \fP\fIsize\fP\fB,\fP \fB const void *\fP\fIcaller\fP\fB);\fP .PP \fBvoid (*volatile __free_hook)(void *\fP\fIptr\fP\fB, const void *\fP\fIcaller\fP\fB);\fP .PP \fBvoid (*__malloc_initialize_hook)(void);\fP .PP \fBvoid (*volatile __after_morecore_hook)(void);\fP .fi .SH DESCRIPTION La bibliothèque C GNU vous permet de modifier le comportement de \fBmalloc\fP(3), \fBrealloc\fP(3) et \fBfree\fP(3) en fixant les points d'entrée des routines. Vous pouvez utiliser ces points pour, par exemple, faciliter le débogage des programmes utilisant des allocations de mémoire dynamique. .PP La variable \fB__malloc_initialize_hook\fP pointe vers une fonction qui est appelée une seule fois à l'initialisation de \fBmalloc\fP(). C'est une variable libre qui peut être modifiée par l'application avec une déclaration comme celle\-ci\ : .PP .in +4n .EX void (*__malloc_initialize_hook)(void) = my_init_hook; .EE .in .PP À présent, la fonction \fImy_init_hook\fP() pourra faire toute l'initialisation des routines. .PP Les quatre fonctions pointées par \fB__malloc_hook\fP, \fB__realloc_hook\fP, \fB__memalign_hook\fP et \fB__free_hook\fP ont des prototypes semblables à ceux des fonctions \fBmalloc\fP(3), \fBrealloc\fP(3), \fBmemalign\fP(3) et \fBfree\fP(3), respectivement, avec un argument final supplémentaire \fIcaller\fP qui fournit l'adresse du code appelant \fBmalloc\fP(3),\ etc. .PP La variable \fB__after_morecore_hook\fP pointe sur une fonction qui est invoquée à chaque fois que \fBsbrk\fP(2) a été appelée pour augmenter la mémoire. .SH STANDARDS GNU. .SH NOTES .\" https://bugzilla.redhat.com/show_bug.cgi?id=450187 .\" http://sourceware.org/bugzilla/show_bug.cgi?id=9957 L'utilisation de ces fonctions de crochet n'est pas sûre dans des programmes multiprocessus, et elles sont dorénavant obsolètes. À compter de la glibc\ 2.24, la variable \fB__malloc_initialize_hook\fP a été supprimée de l'API et à partir de la glibc\ 2.34, toutes les variables de crochet ont été supprimées de l'API. Les programmeurs devraient à la place préempter les appels à ces fonctions en définissant et exportant \fBmalloc\fP(), \fBfree\fP(), \fBrealloc\fP() et \fBcalloc\fP(). .SH EXEMPLES Voici un court exemple d'utilisation de ces variables. .PP .EX #include #include \& /* Prototypes for our hooks */ static void my_init_hook(void); static void *my_malloc_hook(size_t, const void *); \& /* Variables to save original hooks */ static void *(*old_malloc_hook)(size_t, const void *); \& /* Override initializing hook from the C library */ void (*__malloc_initialize_hook)(void) = my_init_hook; \& static void my_init_hook(void) { old_malloc_hook = __malloc_hook; __malloc_hook = my_malloc_hook; } \& static void * my_malloc_hook(size_t size, const void *caller) { void *result; \& /* Restore all old hooks */ __malloc_hook = old_malloc_hook; \& /* Call recursively */ result = malloc(size); \& /* Save underlying hooks */ old_malloc_hook = __malloc_hook; \& /* printf() might call malloc(), so protect it too */ printf("malloc(%zu) called from %p returns %p\en", size, caller, result); \& /* Restore our own hooks */ __malloc_hook = my_malloc_hook; \& return result; } .EE .SH "VOIR AUSSI" \fBmallinfo\fP(3), \fBmalloc\fP(3), \fBmcheck\fP(3), \fBmtrace\fP(3) .PP .SH TRADUCTION La traduction française de cette page de manuel a été créée par Christophe Blaess , Stéphan Rafin , Thierry Vignaud , François Micaux, Alain Portal , Jean-Philippe Guérard , Jean-Luc Coulon (f5ibh) , Julien Cristau , Thomas Huriaux , Nicolas François , Florentin Duneau , Simon Paillard , Denis Barbier , David Prévot et Grégoire Scano . .PP Cette traduction est une documentation libre ; veuillez vous reporter à la .UR https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License version 3 .UE concernant les conditions de copie et de distribution. Il n'y a aucune RESPONSABILITÉ LÉGALE. .PP Si vous découvrez un bogue dans la traduction de cette page de manuel, veuillez envoyer un message à .MT debian-l10n-french@lists.debian.org .ME .