public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/nsz/mtag] malloc: Use mtag_enabled instead of USE_MTAG
@ 2021-03-11 17:41 Szabolcs Nagy
0 siblings, 0 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2021-03-11 17:41 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=258556dd57f7f7e91ed111dfb60be2c3c5923818
commit 258556dd57f7f7e91ed111dfb60be2c3c5923818
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date: Wed Feb 17 10:15:18 2021 +0000
malloc: Use mtag_enabled instead of USE_MTAG
Use the runtime check where possible: it should not cause slow down in
the !USE_MTAG case since then mtag_enabled is constant false, but it
allows compiling the tagging logic so it's less likely to break or
diverge when developers only test the !USE_MTAG case.
Reviewed-by: DJ Delorie <dj@redhat.com>
Diff:
---
malloc/hooks.c | 10 ++++------
malloc/malloc.c | 10 ++++------
2 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/malloc/hooks.c b/malloc/hooks.c
index d8e304c31c..9474e199c3 100644
--- a/malloc/hooks.c
+++ b/malloc/hooks.c
@@ -262,11 +262,10 @@ free_check (void *mem, const void *caller)
int err = errno;
-#ifdef USE_MTAG
/* Quickly check that the freed pointer matches the tag for the memory.
This gives a useful double-free detection. */
- *(volatile char *)mem;
-#endif
+ if (__glibc_unlikely (mtag_enabled))
+ *(volatile char *)mem;
__libc_lock_lock (main_arena.mutex);
p = mem2chunk_check (mem, NULL);
@@ -310,11 +309,10 @@ realloc_check (void *oldmem, size_t bytes, const void *caller)
return NULL;
}
-#ifdef USE_MTAG
/* Quickly check that the freed pointer matches the tag for the memory.
This gives a useful double-free detection. */
- *(volatile char *)oldmem;
-#endif
+ if (__glibc_unlikely (mtag_enabled))
+ *(volatile char *)oldmem;
__libc_lock_lock (main_arena.mutex);
const mchunkptr oldp = mem2chunk_check (oldmem, &magic_p);
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 849bd8e2c9..36583120ce 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -3286,11 +3286,10 @@ __libc_free (void *mem)
if (mem == 0) /* free(0) has no effect */
return;
-#ifdef USE_MTAG
/* Quickly check that the freed pointer matches the tag for the memory.
This gives a useful double-free detection. */
- *(volatile char *)mem;
-#endif
+ if (__glibc_unlikely (mtag_enabled))
+ *(volatile char *)mem;
int err = errno;
@@ -3352,11 +3351,10 @@ __libc_realloc (void *oldmem, size_t bytes)
if (oldmem == 0)
return __libc_malloc (bytes);
-#ifdef USE_MTAG
/* Perform a quick check to ensure that the pointer's tag matches the
memory's tag. */
- *(volatile char*) oldmem;
-#endif
+ if (__glibc_unlikely (mtag_enabled))
+ *(volatile char*) oldmem;
/* chunk corresponding to oldmem */
const mchunkptr oldp = mem2chunk (oldmem);
^ permalink raw reply [flat|nested] 4+ messages in thread
* [glibc/nsz/mtag] malloc: Use mtag_enabled instead of USE_MTAG
@ 2021-03-19 11:57 Szabolcs Nagy
0 siblings, 0 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2021-03-19 11:57 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=5ed1f23333ec62c179d597d8f0e925c5aaa929d3
commit 5ed1f23333ec62c179d597d8f0e925c5aaa929d3
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date: Wed Feb 17 10:15:18 2021 +0000
malloc: Use mtag_enabled instead of USE_MTAG
Use the runtime check where possible: it should not cause slow down in
the !USE_MTAG case since then mtag_enabled is constant false, but it
allows compiling the tagging logic so it's less likely to break or
diverge when developers only test the !USE_MTAG case.
Reviewed-by: DJ Delorie <dj@redhat.com>
Diff:
---
malloc/hooks.c | 10 ++++------
malloc/malloc.c | 10 ++++------
2 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/malloc/hooks.c b/malloc/hooks.c
index d8e304c31c..9474e199c3 100644
--- a/malloc/hooks.c
+++ b/malloc/hooks.c
@@ -262,11 +262,10 @@ free_check (void *mem, const void *caller)
int err = errno;
-#ifdef USE_MTAG
/* Quickly check that the freed pointer matches the tag for the memory.
This gives a useful double-free detection. */
- *(volatile char *)mem;
-#endif
+ if (__glibc_unlikely (mtag_enabled))
+ *(volatile char *)mem;
__libc_lock_lock (main_arena.mutex);
p = mem2chunk_check (mem, NULL);
@@ -310,11 +309,10 @@ realloc_check (void *oldmem, size_t bytes, const void *caller)
return NULL;
}
-#ifdef USE_MTAG
/* Quickly check that the freed pointer matches the tag for the memory.
This gives a useful double-free detection. */
- *(volatile char *)oldmem;
-#endif
+ if (__glibc_unlikely (mtag_enabled))
+ *(volatile char *)oldmem;
__libc_lock_lock (main_arena.mutex);
const mchunkptr oldp = mem2chunk_check (oldmem, &magic_p);
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 849bd8e2c9..36583120ce 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -3286,11 +3286,10 @@ __libc_free (void *mem)
if (mem == 0) /* free(0) has no effect */
return;
-#ifdef USE_MTAG
/* Quickly check that the freed pointer matches the tag for the memory.
This gives a useful double-free detection. */
- *(volatile char *)mem;
-#endif
+ if (__glibc_unlikely (mtag_enabled))
+ *(volatile char *)mem;
int err = errno;
@@ -3352,11 +3351,10 @@ __libc_realloc (void *oldmem, size_t bytes)
if (oldmem == 0)
return __libc_malloc (bytes);
-#ifdef USE_MTAG
/* Perform a quick check to ensure that the pointer's tag matches the
memory's tag. */
- *(volatile char*) oldmem;
-#endif
+ if (__glibc_unlikely (mtag_enabled))
+ *(volatile char*) oldmem;
/* chunk corresponding to oldmem */
const mchunkptr oldp = mem2chunk (oldmem);
^ permalink raw reply [flat|nested] 4+ messages in thread
* [glibc/nsz/mtag] malloc: Use mtag_enabled instead of USE_MTAG
@ 2021-03-11 17:39 Szabolcs Nagy
0 siblings, 0 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2021-03-11 17:39 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=258556dd57f7f7e91ed111dfb60be2c3c5923818
commit 258556dd57f7f7e91ed111dfb60be2c3c5923818
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date: Wed Feb 17 10:15:18 2021 +0000
malloc: Use mtag_enabled instead of USE_MTAG
Use the runtime check where possible: it should not cause slow down in
the !USE_MTAG case since then mtag_enabled is constant false, but it
allows compiling the tagging logic so it's less likely to break or
diverge when developers only test the !USE_MTAG case.
Reviewed-by: DJ Delorie <dj@redhat.com>
Diff:
---
malloc/hooks.c | 10 ++++------
malloc/malloc.c | 10 ++++------
2 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/malloc/hooks.c b/malloc/hooks.c
index d8e304c31c..9474e199c3 100644
--- a/malloc/hooks.c
+++ b/malloc/hooks.c
@@ -262,11 +262,10 @@ free_check (void *mem, const void *caller)
int err = errno;
-#ifdef USE_MTAG
/* Quickly check that the freed pointer matches the tag for the memory.
This gives a useful double-free detection. */
- *(volatile char *)mem;
-#endif
+ if (__glibc_unlikely (mtag_enabled))
+ *(volatile char *)mem;
__libc_lock_lock (main_arena.mutex);
p = mem2chunk_check (mem, NULL);
@@ -310,11 +309,10 @@ realloc_check (void *oldmem, size_t bytes, const void *caller)
return NULL;
}
-#ifdef USE_MTAG
/* Quickly check that the freed pointer matches the tag for the memory.
This gives a useful double-free detection. */
- *(volatile char *)oldmem;
-#endif
+ if (__glibc_unlikely (mtag_enabled))
+ *(volatile char *)oldmem;
__libc_lock_lock (main_arena.mutex);
const mchunkptr oldp = mem2chunk_check (oldmem, &magic_p);
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 849bd8e2c9..36583120ce 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -3286,11 +3286,10 @@ __libc_free (void *mem)
if (mem == 0) /* free(0) has no effect */
return;
-#ifdef USE_MTAG
/* Quickly check that the freed pointer matches the tag for the memory.
This gives a useful double-free detection. */
- *(volatile char *)mem;
-#endif
+ if (__glibc_unlikely (mtag_enabled))
+ *(volatile char *)mem;
int err = errno;
@@ -3352,11 +3351,10 @@ __libc_realloc (void *oldmem, size_t bytes)
if (oldmem == 0)
return __libc_malloc (bytes);
-#ifdef USE_MTAG
/* Perform a quick check to ensure that the pointer's tag matches the
memory's tag. */
- *(volatile char*) oldmem;
-#endif
+ if (__glibc_unlikely (mtag_enabled))
+ *(volatile char*) oldmem;
/* chunk corresponding to oldmem */
const mchunkptr oldp = mem2chunk (oldmem);
^ permalink raw reply [flat|nested] 4+ messages in thread
* [glibc/nsz/mtag] malloc: Use mtag_enabled instead of USE_MTAG
@ 2021-03-04 16:26 Szabolcs Nagy
0 siblings, 0 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2021-03-04 16:26 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=faf5b199ad51eb746a05d3eab6ae1e230fc4de0c
commit faf5b199ad51eb746a05d3eab6ae1e230fc4de0c
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date: Wed Feb 17 10:15:18 2021 +0000
malloc: Use mtag_enabled instead of USE_MTAG
Use the runtime check where possible: it should not cause slow down in
the !USE_MTAG case since then mtag_enabled is constant false, but it
allows compiling the tagging logic so it's less likely to break or
diverge when developers only test the !USE_MTAG case.
Diff:
---
malloc/hooks.c | 10 ++++------
malloc/malloc.c | 10 ++++------
2 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/malloc/hooks.c b/malloc/hooks.c
index d8e304c31c..9474e199c3 100644
--- a/malloc/hooks.c
+++ b/malloc/hooks.c
@@ -262,11 +262,10 @@ free_check (void *mem, const void *caller)
int err = errno;
-#ifdef USE_MTAG
/* Quickly check that the freed pointer matches the tag for the memory.
This gives a useful double-free detection. */
- *(volatile char *)mem;
-#endif
+ if (__glibc_unlikely (mtag_enabled))
+ *(volatile char *)mem;
__libc_lock_lock (main_arena.mutex);
p = mem2chunk_check (mem, NULL);
@@ -310,11 +309,10 @@ realloc_check (void *oldmem, size_t bytes, const void *caller)
return NULL;
}
-#ifdef USE_MTAG
/* Quickly check that the freed pointer matches the tag for the memory.
This gives a useful double-free detection. */
- *(volatile char *)oldmem;
-#endif
+ if (__glibc_unlikely (mtag_enabled))
+ *(volatile char *)oldmem;
__libc_lock_lock (main_arena.mutex);
const mchunkptr oldp = mem2chunk_check (oldmem, &magic_p);
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 8854afec88..2d96bb085c 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -3286,11 +3286,10 @@ __libc_free (void *mem)
if (mem == 0) /* free(0) has no effect */
return;
-#ifdef USE_MTAG
/* Quickly check that the freed pointer matches the tag for the memory.
This gives a useful double-free detection. */
- *(volatile char *)mem;
-#endif
+ if (__glibc_unlikely (mtag_enabled))
+ *(volatile char *)mem;
int err = errno;
@@ -3352,11 +3351,10 @@ __libc_realloc (void *oldmem, size_t bytes)
if (oldmem == 0)
return __libc_malloc (bytes);
-#ifdef USE_MTAG
/* Perform a quick check to ensure that the pointer's tag matches the
memory's tag. */
- *(volatile char*) oldmem;
-#endif
+ if (__glibc_unlikely (mtag_enabled))
+ *(volatile char*) oldmem;
/* chunk corresponding to oldmem */
const mchunkptr oldp = mem2chunk (oldmem);
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-03-19 11:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-11 17:41 [glibc/nsz/mtag] malloc: Use mtag_enabled instead of USE_MTAG Szabolcs Nagy
-- strict thread matches above, loose matches on Subject: below --
2021-03-19 11:57 Szabolcs Nagy
2021-03-11 17:39 Szabolcs Nagy
2021-03-04 16:26 Szabolcs Nagy
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).