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 v8 10/10] mcheck Fix malloc_usable_size [BZ #22057]
Date: Tue, 13 Jul 2021 13:08:45 +0530	[thread overview]
Message-ID: <20210713073845.504356-11-siddhesh@sourceware.org> (raw)
In-Reply-To: <20210713073845.504356-1-siddhesh@sourceware.org>

Interpose malloc_usable_size to return the correct mcheck value for
malloc_usable_size.
---
 malloc/Makefile       | 4 +---
 malloc/malloc-debug.c | 8 ++++++--
 malloc/mcheck-impl.c  | 6 ++++++
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/malloc/Makefile b/malloc/Makefile
index c9504d0916..04c6b09949 100644
--- a/malloc/Makefile
+++ b/malloc/Makefile
@@ -83,7 +83,7 @@ ifeq ($(have-GLIBC_2.24)$(build-shared),yesyes)
 # the tests expect specific internal behavior that is changed due to linking to
 # libmcheck.a.
 tests-exclude-mcheck = tst-mallocstate \
-	tst-safe-linking tst-malloc-usable \
+	tst-safe-linking \
 	tst-malloc-backtrace \
 	tst-malloc-fork-deadlock \
 	tst-malloc-stats-cancellation \
@@ -92,8 +92,6 @@ tests-exclude-mcheck = tst-mallocstate \
 	tst-malloc-thread-fail \
 	tst-malloc-usable-tunables \
 	tst-malloc_info \
-	tst-pvalloc-fortify \
-	tst-reallocarray \
 	tst-compathooks-off tst-compathooks-on
 
 tests-mcheck = $(filter-out $(tests-exclude-mcheck), $(tests))
diff --git a/malloc/malloc-debug.c b/malloc/malloc-debug.c
index ef44546a4e..7968787ad6 100644
--- a/malloc/malloc-debug.c
+++ b/malloc/malloc-debug.c
@@ -357,8 +357,12 @@ strong_alias (__debug_calloc, calloc)
 size_t
 malloc_usable_size (void *mem)
 {
-  return (__is_malloc_debug_enabled (MALLOC_CHECK_HOOK)
-	  ? malloc_check_get_size (mem) : musable (mem));
+  if (__is_malloc_debug_enabled (MALLOC_MCHECK_HOOK))
+    return mcheck_usable_size (mem);
+  if (__is_malloc_debug_enabled (MALLOC_CHECK_HOOK))
+    return malloc_check_get_size (mem);
+
+  return musable (mem);
 }
 
 #define LIBC_SYMBOL(sym) libc_ ## sym
diff --git a/malloc/mcheck-impl.c b/malloc/mcheck-impl.c
index 8857e6b179..6597a290a6 100644
--- a/malloc/mcheck-impl.c
+++ b/malloc/mcheck-impl.c
@@ -404,3 +404,9 @@ __mcheck_initialize (void (*func) (enum mcheck_status), bool in_pedantic)
   pedantic = in_pedantic;
   return 0;
 }
+
+static int
+mcheck_usable_size (struct hdr *h)
+{
+  return (h - 1)->size;
+}
-- 
2.31.1


  parent reply	other threads:[~2021-07-13  7:46 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-13  7:38 [PATCH v8 00/10] malloc hooks removal Siddhesh Poyarekar via Libc-alpha
2021-07-13  7:38 ` [PATCH v8 01/10] Make mcheck tests conditional on GLIBC_2.24 or earlier Siddhesh Poyarekar via Libc-alpha
2021-07-17 22:03   ` Carlos O'Donell via Libc-alpha
2021-07-13  7:38 ` [PATCH v8 02/10] Remove __after_morecore_hook Siddhesh Poyarekar via Libc-alpha
2021-07-17 22:03   ` Carlos O'Donell via Libc-alpha
2021-07-13  7:38 ` [PATCH v8 03/10] Remove __morecore and __default_morecore Siddhesh Poyarekar via Libc-alpha
2021-07-14  7:01   ` Siddhesh Poyarekar
2021-07-14 12:54     ` Guillaume Morin
2021-07-14 14:13       ` Siddhesh Poyarekar
2021-07-14 16:42         ` Guillaume Morin
2021-07-14 17:15           ` Carlos O'Donell via Libc-alpha
2021-07-14 17:42             ` Adhemerval Zanella via Libc-alpha
2021-07-14 18:37               ` Guillaume Morin
2021-07-14 18:48               ` Siddhesh Poyarekar
2021-07-14 18:31             ` Guillaume Morin
2021-07-14 17:32           ` Siddhesh Poyarekar
2021-07-14 18:25             ` Guillaume Morin
2021-07-14 18:43               ` Siddhesh Poyarekar
2021-07-14 18:51                 ` Guillaume Morin
2021-07-17 22:03   ` Carlos O'Donell via Libc-alpha
2021-07-13  7:38 ` [PATCH v8 04/10] Move malloc hooks into a compat DSO Siddhesh Poyarekar via Libc-alpha
2021-07-17 22:04   ` Carlos O'Donell via Libc-alpha
2021-07-13  7:38 ` [PATCH v8 05/10] mcheck: Wean away from malloc hooks Siddhesh Poyarekar via Libc-alpha
2021-07-13 15:47   ` H.J. Lu via Libc-alpha
2021-07-14  2:44     ` Siddhesh Poyarekar via Libc-alpha
2021-07-17 22:04   ` Carlos O'Donell via Libc-alpha
2021-07-13  7:38 ` [PATCH v8 06/10] Simplify __malloc_initialized Siddhesh Poyarekar via Libc-alpha
2021-07-17 22:04   ` Carlos O'Donell via Libc-alpha
2021-07-13  7:38 ` [PATCH v8 07/10] mtrace: Wean away from malloc hooks Siddhesh Poyarekar via Libc-alpha
2021-07-17 22:04   ` Carlos O'Donell via Libc-alpha
2021-07-13  7:38 ` [PATCH v8 08/10] glibc.malloc.check: " Siddhesh Poyarekar via Libc-alpha
2021-07-17 22:04   ` Carlos O'Donell via Libc-alpha
2021-07-13  7:38 ` [PATCH v8 09/10] Remove " Siddhesh Poyarekar via Libc-alpha
2021-07-17 22:04   ` Carlos O'Donell via Libc-alpha
2021-07-13  7:38 ` Siddhesh Poyarekar via Libc-alpha [this message]
2021-07-17 22:04   ` [PATCH v8 10/10] mcheck Fix malloc_usable_size [BZ #22057] Carlos O'Donell via Libc-alpha
2021-07-13 14:48 ` [PATCH v8 00/10] malloc hooks removal H.J. Lu via Libc-alpha
2021-07-13 15:41   ` Siddhesh Poyarekar via Libc-alpha
2021-07-17 22:03 ` Carlos O'Donell via Libc-alpha

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=20210713073845.504356-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).