aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Uriev <eugeneuriev@gmail.com>2024-03-31 23:03:22 +0300
committerTom Rini <trini@konsulko.com>2024-04-12 16:23:06 -0600
commit151493a875071448e2582489f6fa84d1630b3368 (patch)
tree4f05ba844d78b4a57faecf45ffe91260fc1f1653
parent7dafc5c9255c5436d7f8adc1078b7c01c36e7f07 (diff)
downloadu-boot-151493a875071448e2582489f6fa84d1630b3368.zip
u-boot-151493a875071448e2582489f6fa84d1630b3368.tar.gz
u-boot-151493a875071448e2582489f6fa84d1630b3368.tar.bz2
mcheck: integrate mcheck into dlmalloc.c
This changes are probable worth to be generalized in a separate .h-file so, making it able to cover libc-mallocs and others, without too much copy-paste. But the malloc<=>mALLOc substitutions interfere with an elegant way to do this. Signed-off-by: Eugene Uriev <eugeneuriev@gmail.com>
-rw-r--r--common/dlmalloc.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/common/dlmalloc.c b/common/dlmalloc.c
index 0813e7e..8de15d7 100644
--- a/common/dlmalloc.c
+++ b/common/dlmalloc.c
@@ -2225,6 +2225,73 @@ void cfree(mem) Void_t *mem;
#endif
+#ifdef MCHECK_HEAP_PROTECTION
+ #include "mcheck_core.inc.h"
+ #if !__STD_C
+ #error "must have __STD_C"
+ #endif
+
+Void_t *mALLOc(size_t bytes)
+{
+ size_t fullsz = mcheck_alloc_prehook(bytes);
+ void *p = mALLOc_impl(fullsz);
+
+ if (!p)
+ return p;
+ return mcheck_alloc_posthook(p, bytes);
+}
+
+void fREe(Void_t *mem) { fREe_impl(mcheck_free_prehook(mem)); }
+
+Void_t *rEALLOc(Void_t *oldmem, size_t bytes)
+{
+ if (bytes == 0) {
+ if (oldmem)
+ fREe(oldmem);
+ return NULL;
+ }
+
+ if (oldmem == NULL)
+ return mALLOc(bytes);
+
+ void *p = mcheck_reallocfree_prehook(oldmem);
+ size_t newsz = mcheck_alloc_prehook(bytes);
+
+ p = rEALLOc_impl(p, newsz);
+ if (!p)
+ return p;
+ return mcheck_alloc_noclean_posthook(p, bytes);
+}
+
+Void_t *mEMALIGn(size_t alignment, size_t bytes)
+{
+ return NULL;
+}
+
+// pvALLOc, vALLOc - redirect to mEMALIGn, defined here, so they need no wrapping.
+
+Void_t *cALLOc(size_t n, size_t elem_size)
+{
+ // NB: here is no overflow check.
+ size_t fullsz = mcheck_alloc_prehook(n * elem_size);
+ void *p = cALLOc_impl(1, fullsz);
+
+ if (!p)
+ return p;
+ return mcheck_alloc_noclean_posthook(p, n * elem_size);
+}
+
+// mcheck API {
+int mcheck(mcheck_abortfunc_t f)
+{
+ mcheck_initialize(f, 0);
+ return 0;
+}
+
+enum mcheck_status mprobe(void *__ptr) { return mcheck_mprobe(__ptr); }
+// mcheck API }
+#endif
+
/*