unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Siddhesh Poyarekar via Libc-alpha <libc-alpha@sourceware.org>
To: libc-alpha@sourceware.org
Cc: fweimer@redhat.com
Subject: [PATCH v3 10/10] Remove __morecore and __default_morecore
Date: Fri,  2 Jul 2021 08:05:46 +0530	[thread overview]
Message-ID: <20210702023546.3081774-11-siddhesh@sourceware.org> (raw)
In-Reply-To: <20210702023546.3081774-1-siddhesh@sourceware.org>

Make the __morecore and __default_morecore symbols compat-only and
remove their declarations from the API.

Reviewed-by: DJ Delorie <dj@redhat.com>
---
 NEWS                     |  5 +++++
 include/stdlib.h         |  3 ---
 malloc/arena.c           | 12 ++----------
 malloc/hooks.c           |  3 +++
 malloc/malloc-internal.h |  5 +++++
 malloc/malloc.c          |  4 +---
 malloc/malloc.h          |  8 --------
 malloc/morecore.c        | 15 +++++++++++++--
 8 files changed, 29 insertions(+), 26 deletions(-)

diff --git a/NEWS b/NEWS
index cebe8384bf..2533919f75 100644
--- a/NEWS
+++ b/NEWS
@@ -106,6 +106,11 @@ Deprecated and removed features, and other changes affecting compatibility:
   legacy programs until they are updated to remove references to the memory
   allocation hooks.
 
+* The __morecore and __after_morecore_hook malloc hooks and the default
+  implementation __default_morecore have been removed from the API.  Existing
+  applications will continue to link against these symbols but the interfaces
+  no longer have any effect on malloc.
+
 Changes to build and runtime requirements:
 
 * On Linux, the shm_open, sem_open, and related functions now expect the
diff --git a/include/stdlib.h b/include/stdlib.h
index 1f6e1508e4..1c6f70b082 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -306,9 +306,6 @@ libc_hidden_proto (__qfcvt_r)
 #  define MB_CUR_MAX (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_MB_CUR_MAX))
 # endif
 
-extern void *__default_morecore (ptrdiff_t) __THROW;
-libc_hidden_proto (__default_morecore)
-
 struct abort_msg_s
 {
   unsigned int size;
diff --git a/malloc/arena.c b/malloc/arena.c
index 8591c8ea56..00e8b5a32f 100644
--- a/malloc/arena.c
+++ b/malloc/arena.c
@@ -272,14 +272,6 @@ next_env_entry (char ***position)
 #endif
 
 
-#if defined(SHARED) || defined(USE_MTAG)
-static void *
-__failing_morecore (ptrdiff_t d)
-{
-  return (void *) MORECORE_FAILURE;
-}
-#endif
-
 #ifdef SHARED
 extern struct dl_open_hook *_dl_open_hook;
 libc_hidden_proto (_dl_open_hook);
@@ -300,7 +292,7 @@ ptmalloc_init (void)
 	 and that morecore does not support tagged regions, then
 	 disable it.  */
       if (__MTAG_SBRK_UNTAGGED)
-	__morecore = __failing_morecore;
+	__always_fail_morecore = true;
 
       mtag_enabled = true;
       mtag_mmap_flags = __MTAG_MMAP_FLAGS;
@@ -313,7 +305,7 @@ ptmalloc_init (void)
      generic sbrk implementation also enforces this, but it is not
      used on Hurd.  */
   if (!__libc_initial)
-    __morecore = __failing_morecore;
+    __always_fail_morecore = true;
 #endif
 
   thread_arena = &main_arena;
diff --git a/malloc/hooks.c b/malloc/hooks.c
index 5e9355761a..b40696c8b7 100644
--- a/malloc/hooks.c
+++ b/malloc/hooks.c
@@ -81,6 +81,9 @@ compat_symbol (libc, __memalign_hook, __memalign_hook, GLIBC_2_0);
 void weak_variable (*__after_morecore_hook) (void) = NULL;
 compat_symbol (libc, __after_morecore_hook, __after_morecore_hook, GLIBC_2_0);
 
+void *(*__morecore)(ptrdiff_t);
+compat_symbol (libc, __morecore, __morecore, GLIBC_2_0);
+
 /* These hooks will get executed only through the interposed allocator
    functions in libmalloc_compathooks.  This means that the calls to malloc,
    realloc, etc. will lead back into the interposed functions, which is what we
diff --git a/malloc/malloc-internal.h b/malloc/malloc-internal.h
index ee0f5697af..b104f7cdbf 100644
--- a/malloc/malloc-internal.h
+++ b/malloc/malloc-internal.h
@@ -21,6 +21,7 @@
 
 #include <malloc-machine.h>
 #include <malloc-sysdep.h>
+#include <stdbool.h>
 
 /* INTERNAL_SIZE_T is the word-size used for internal bookkeeping of
    chunk sizes.
@@ -63,6 +64,8 @@
 
 #define top(ar_ptr) ((ar_ptr)->top)
 
+extern bool __always_fail_morecore attribute_hidden;
+
 /* Called in the parent process before a fork.  */
 void __malloc_fork_lock_parent (void) attribute_hidden;
 
@@ -78,4 +81,6 @@ void __malloc_arena_thread_freeres (void) attribute_hidden;
 /* Activate a standard set of debugging hooks. */
 void __malloc_check_init (void) attribute_hidden;
 
+extern void *__glibc_morecore (ptrdiff_t) attribute_hidden;
+
 #endif /* _MALLOC_INTERNAL_H */
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 296e4f9789..79855e93ab 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -382,10 +382,8 @@ __malloc_assert (const char *assertion, const char *file, unsigned int line,
 
 
 /* Definition for getting more memory from the OS.  */
-#define MORECORE         (*__morecore)
+#define MORECORE         (*__glibc_morecore)
 #define MORECORE_FAILURE 0
-void * __default_morecore (ptrdiff_t);
-void *(*__morecore)(ptrdiff_t) = __default_morecore;
 
 /* Memory tagging.  */
 
diff --git a/malloc/malloc.h b/malloc/malloc.h
index d066a05d82..2df0b38050 100644
--- a/malloc/malloc.h
+++ b/malloc/malloc.h
@@ -76,14 +76,6 @@ extern void *valloc (size_t __size) __THROW __attribute_malloc__
 extern void *pvalloc (size_t __size) __THROW __attribute_malloc__
   __wur __attr_dealloc_free;
 
-/* Underlying allocation function; successive calls should return
-   contiguous pieces of memory.  */
-extern void *(*__morecore) (ptrdiff_t __size) __MALLOC_DEPRECATED;
-
-/* Default value of `__morecore'.  */
-extern void *__default_morecore (ptrdiff_t __size)
-__THROW __attribute_malloc__  __MALLOC_DEPRECATED;
-
 /* SVID2/XPG mallinfo structure */
 
 struct mallinfo
diff --git a/malloc/morecore.c b/malloc/morecore.c
index 047228779b..c85a85c0eb 100644
--- a/malloc/morecore.c
+++ b/malloc/morecore.c
@@ -38,16 +38,27 @@ libc_hidden_proto (__sbrk)
 # define NULL 0
 #endif
 
+#if defined(SHARED) || defined(USE_MTAG)
+bool __always_fail_morecore = false;
+#endif
+
 /* Allocate INCREMENT more bytes of data space,
    and return the start of data space, or NULL on errors.
    If INCREMENT is negative, shrink data space.  */
 void *
-__default_morecore (ptrdiff_t increment)
+__glibc_morecore (ptrdiff_t increment)
 {
+#if defined(SHARED) || defined(USE_MTAG)
+  if (__always_fail_morecore)
+    return NULL;
+#endif
+
   void *result = (void *) __sbrk (increment);
   if (result == (void *) -1)
     return NULL;
 
   return result;
 }
-libc_hidden_def (__default_morecore)
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_34)
+compat_symbol (libc, __glibc_morecore, __default_morecore, GLIBC_2_0);
+#endif
-- 
2.31.1


      parent reply	other threads:[~2021-07-02  2:44 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-02  2:35 [PATCH v3 00/10] Remove malloc hooks Siddhesh Poyarekar via Libc-alpha
2021-07-02  2:35 ` [PATCH v3 01/10] mtrace: Deprecate mallwatch and tr_break Siddhesh Poyarekar via Libc-alpha
2021-07-02  2:35 ` [PATCH v3 02/10] Add mcheck tests to malloc Siddhesh Poyarekar via Libc-alpha
2021-07-06 14:50   ` Stefan Liebler via Libc-alpha
2021-07-06 15:54     ` Siddhesh Poyarekar
2021-07-08 23:37       ` H.J. Lu via Libc-alpha
2021-07-09  0:06         ` H.J. Lu via Libc-alpha
2021-07-09  1:46           ` Siddhesh Poyarekar
2021-07-09  3:53             ` [PATCH] Add a generic malloc test for MALLOC_ALIGNMENT H.J. Lu via Libc-alpha
2021-07-09  4:07               ` Siddhesh Poyarekar
2021-07-09 12:24                 ` [PATCH v2] " H.J. Lu via Libc-alpha
2021-07-09 13:00                   ` Siddhesh Poyarekar
2021-07-09 13:31                     ` [PATCH v3] " H.J. Lu via Libc-alpha
2021-07-09 13:34                       ` Siddhesh Poyarekar
2021-07-12 18:02             ` [PATCH v3 02/10] Add mcheck tests to malloc Matheus Castanho via Libc-alpha
2021-07-13  1:06               ` Siddhesh Poyarekar
2021-07-13 12:11                 ` Matheus Castanho via Libc-alpha
2021-07-02  2:35 ` [PATCH v3 03/10] Move glibc.malloc.check implementation into its own file Siddhesh Poyarekar via Libc-alpha
2021-07-02  9:05   ` Andreas Schwab
2021-07-02  9:29     ` Siddhesh Poyarekar via Libc-alpha
2021-07-02  9:59       ` Andreas Schwab
2021-07-02  2:35 ` [PATCH v3 04/10] malloc: Move malloc hook references to hooks.c Siddhesh Poyarekar via Libc-alpha
2021-07-02  2:35 ` [PATCH v3 05/10] glibc.malloc.check: Wean away from malloc hooks Siddhesh Poyarekar via Libc-alpha
2021-07-02  2:35 ` [PATCH v3 06/10] mcheck: " Siddhesh Poyarekar via Libc-alpha
2021-07-02  2:35 ` [PATCH v3 07/10] mtrace: " Siddhesh Poyarekar via Libc-alpha
2021-07-02  2:35 ` [PATCH v3 08/10] Remove " Siddhesh Poyarekar via Libc-alpha
2021-07-02  2:35 ` [PATCH v3 09/10] Remove __after_morecore_hook Siddhesh Poyarekar via Libc-alpha
2021-07-02  2:35 ` Siddhesh Poyarekar via Libc-alpha [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210702023546.3081774-11-siddhesh@sourceware.org \
    --to=libc-alpha@sourceware.org \
    --cc=fweimer@redhat.com \
    --cc=siddhesh@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).