diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/libc-symbols.h | 73 | ||||
-rw-r--r-- | include/set-freeres.h | 142 |
2 files changed, 142 insertions, 73 deletions
diff --git a/include/libc-symbols.h b/include/libc-symbols.h index 404169ce78..155781d448 100644 --- a/include/libc-symbols.h +++ b/include/libc-symbols.h @@ -237,79 +237,6 @@ requires at runtime the shared libraries from the glibc version used \ for linking") #endif -/* Resource Freeing Hooks: - - Normally a process exits and the OS cleans up any allocated - memory. However, when tooling like mtrace or valgrind is monitoring - the process we need to free all resources that are part of the - process in order to provide the consistency required to track - memory leaks. - - A single public API exists and is __libc_freeres(), and this is used - by applications like valgrind to freee resouces. - - There are 3 cases: - - (a) __libc_freeres - - In this case all you need to do is define the freeing routine: - - foo.c: - libfoo_freeres_fn (foo_freeres) - { - complex_free (mem); - } - - This ensures the function is called at the right point to free - resources. - - (b) __libc_freeres_ptr - - The framework for (a) iterates over the list of pointers-to-free - in (b) and frees them. - - foo.c: - libc_freeres_ptr (static char *foo_buffer); - - Freeing these resources alaways happens last and is equivalent - to registering a function that does 'free (foo_buffer)'. - - (c) Explicit lists of free routines to call or objects to free. - - It is the intended goal to remove (a) and (b) which have some - non-determinism based on link order, and instead use explicit - lists of functions and frees to resolve cleanup ordering issues - and make it easy to debug and maintain. - - As of today the following subsystems use (c): - - Per-thread cleanup: - * malloc/thread-freeres.c - - libdl cleanup: - * dlfcn/dlfreeres.c - - libpthread cleanup: - * nptl/nptlfreeres.c - - So if you need any shutdown routines to run you should add them - directly to the appropriate subsystem's shutdown list. */ - -/* Resource pointers to free in libc.so. */ -#define libc_freeres_ptr(decl) \ - __make_section_unallocated ("__libc_freeres_ptrs, \"aw\", %nobits") \ - decl __attribute__ ((section ("__libc_freeres_ptrs" __sec_comment))) - -/* Resource freeing functions from libc.so go in this section. */ -#define __libc_freeres_fn_section \ - __attribute__ ((__used__, section ("__libc_freeres_fn"))) - -/* Resource freeing functions for libc.so. */ -#define libc_freeres_fn(name) \ - static void name (void) __attribute_used__ __libc_freeres_fn_section; \ - text_set_element (__libc_subfreeres, name); \ - static void name (void) - /* Declare SYMBOL to be TYPE (`function' or `object') of SIZE bytes alias to ORIGINAL, when the assembler supports such declarations (such as in ELF). diff --git a/include/set-freeres.h b/include/set-freeres.h new file mode 100644 index 0000000000..b7f66519a3 --- /dev/null +++ b/include/set-freeres.h @@ -0,0 +1,142 @@ +/* Macros for internal resource Freeing Hooks. + Copyright (C) 2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#ifndef _SET_FREERES_H +#define _SET_FREERES_H 1 + +#include <shlib-compat.h> +#include <printf.h> +#include <time.h> +#include <resolv/resolv-internal.h> + +/* Resource Freeing Hooks: + + Normally a process exits and the OS cleans up any allocated + memory. However, when tooling like mtrace or valgrind is monitoring + the process we need to free all resources that are part of the + process in order to provide the consistency required to track + memory leaks. + + A single public API exists and is __libc_freeres, and this is used + by applications like valgrind to freee resouces. + + Each free routines must be explicit listed below. */ + +/* From libc.so. */ +extern void __dl_libc_freemem (void) attribute_hidden; +extern void __hdestroy (void) attribute_hidden; +extern void __gconv_cache_freemem (void) attribute_hidden; +extern void __gconv_conf_freemem (void) attribute_hidden; +extern void __gconv_db_freemem (void) attribute_hidden; +extern void __gconv_dl_freemem (void) attribute_hidden; +extern void __intl_freemem (void) attribute_hidden; +extern void __libio_freemem (void) attribute_hidden; +extern void __libc_fstab_freemem (void) attribute_hidden; +extern void __nscd_gr_map_freemem (void) attribute_hidden; +extern void __nscd_hst_map_freemem (void) attribute_hidden; +extern void __nscd_pw_map_freemem (void) attribute_hidden; +extern void __nscd_serv_map_freemem (void) attribute_hidden; +extern void __nscd_group_map_freemem (void) attribute_hidden; +extern void __libc_regcomp_freemem (void) attribute_hidden; +extern void __libc_atfork_freemem (void) attribute_hidden; +extern void __libc_resolv_conf_freemem (void) attribute_hidden; +extern void __res_thread_freeres (void) attribute_hidden; +extern void __libc_printf_freemem (void) attribute_hidden; +extern void __libc_fmtmsg_freemem (void) attribute_hidden; +extern void __libc_setenv_freemem (void) attribute_hidden; +#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_31) +extern void __rpc_freemem (void) attribute_hidden; +extern void __rpc_thread_destroy (void) attribute_hidden; +#endif +extern void __libc_getaddrinfo_freemem (void) attribute_hidden; +extern void __libc_tzset_freemem (void) attribute_hidden; +extern void __libc_localealias_freemem (void) attribute_hidden; +extern void __libc_getutent_freemem (void) attribute_hidden; +extern void __libc_getutline_freemem (void) attribute_hidden; +/* From nss/nss_module.c */ +extern void __nss_module_freeres (void) attribute_hidden; +/* From nss/nss_action.c */ +extern void __nss_action_freeres (void) attribute_hidden; +/* From nss/nss_database.c */ +extern void __nss_database_freeres (void) attribute_hidden; +/* From libio/genops.c */ +extern int _IO_cleanup (void) attribute_hidden;; +/* From dlfcn/dlerror.c */ +extern void __libc_dlerror_result_free (void) attribute_hidden; + +/* From either libc.so or libpthread.so */ +extern void __libpthread_freeres (void) attribute_hidden; +/* From either libc.so or libanl.so */ +#if PTHREAD_IN_LIBC +extern void __gai_freemem (void) attribute_hidden; +/* From either libc.so or librt.so */ +extern void __aio_freemem (void) attribute_hidden; +#endif + +/* From libc.so */ +extern char * __libc_fgetgrent_freemem_ptr attribute_hidden; +extern char * __libc_fgetsgent_freeres_ptr attribute_hidden; +extern char * __libc_getnetgrent_freemem_ptr attribute_hidden; +extern char * __libc_rcmd_freemem_ptr attribute_hidden; +extern char * __libc_rexec_freemem_ptr attribute_hidden; +extern void * __libc_mntent_freemem_ptr attribute_hidden; +extern char * __libc_fgetpwent_freemem_ptr attribute_hidden; +extern struct netaddr * __libc_resolv_res_hconf_freemem_ptr attribute_hidden; +extern char * __libc_fgetspent_freemem_ptr attribute_hidden; +extern __time64_t * __libc_tzfile_freemem_ptr attribute_hidden; +extern char * __libc_getnameinfo_freemem_ptr attribute_hidden; +extern struct utmp * __libc_getutent_freemem_ptr attribute_hidden; +extern struct utmp * __libc_getutid_freemem_ptr attribute_hidden; +extern struct utmp * __libc_getutline_freemem_ptr attribute_hidden; +extern printf_arginfo_size_function ** __libc_reg_printf_freemem_ptr + attribute_hidden; +extern printf_va_arg_function ** __libc_reg_type_freemem_ptr + attribute_hidden; +/* From nss/getXXbyYY.c */ +extern char * __libc_getgrgid_freemem_ptr attribute_hidden; +extern char * __libc_getgrnam_freemem_ptr attribute_hidden; +extern char * __libc_getpwnam_freemem_ptr attribute_hidden; +extern char * __libc_getpwuid_freemem_ptr attribute_hidden; +extern char * __libc_getspnam_freemem_ptr attribute_hidden; +extern char * __libc_getaliasbyname_freemem_ptr attribute_hidden; +extern char * __libc_gethostbyaddr_freemem_ptr attribute_hidden; +extern char * __libc_gethostbyname_freemem_ptr attribute_hidden; +extern char * __libc_gethostbyname2_freemem_ptr attribute_hidden; +extern char * __libc_getnetbyaddr_freemem_ptr attribute_hidden; +extern char * __libc_getnetbyname_freemem_ptr attribute_hidden; +extern char * __libc_getprotobynumber_freemem_ptr attribute_hidden; +extern char * __libc_getprotobyname_freemem_ptr attribute_hidden; +extern char * __libc_getrpcbyname_freemem_ptr attribute_hidden; +extern char * __libc_getrpcbynumber_freemem_ptr attribute_hidden; +extern char * __libc_getservbyname_freemem_ptr attribute_hidden; +extern char * __libc_getservbyport_freemem_ptr attribute_hidden; +/* From nss/getXXent.c */ +extern char * __libc_getgrent_freemem_ptr attribute_hidden; +extern char * __libc_getpwent_freemem_ptr attribute_hidden; +extern char * __libc_getspent_freemem_ptr attribute_hidden; +extern char * __libc_getaliasent_freemem_ptr attribute_hidden; +extern char * __libc_gethostent_freemem_ptr attribute_hidden; +extern char * __libc_getnetent_freemem_ptr attribute_hidden; +extern char * __libc_getprotoent_freemem_ptr attribute_hidden; +extern char * __libc_getrpcent_freemem_ptr attribute_hidden; +extern char * __libc_getservent_freemem_ptr attribute_hidden; +/* From misc/efgcvt-template.c */ +extern char * __libc_efgcvt_freemem_ptr attribute_hidden; +extern char * __libc_qefgcvt_freemem_ptr attribute_hidden; + +#endif |