Add memory poisoning framework

While an area of memory is poisoned, reading or writing from it triggers a
sanitizer violation.

Implemented for ASan.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
diff --git a/tests/src/test_memory.c b/tests/src/test_memory.c
index cda91e5..6b1404b 100644
--- a/tests/src/test_memory.c
+++ b/tests/src/test_memory.c
@@ -13,3 +13,25 @@
 #include <test/macros.h>
 #include <test/memory.h>
 
+#if defined(MBEDTLS_TEST_HAVE_ASAN)
+#include <sanitizer/asan_interface.h>
+#include <stdint.h>
+#endif
+
+#if defined(MBEDTLS_TEST_HAVE_ASAN)
+void mbedtls_test_memory_poison(const unsigned char *ptr, size_t size)
+{
+    if (size == 0) {
+        return;
+    }
+    __asan_poison_memory_region(ptr, size);
+}
+
+void mbedtls_test_memory_unpoison(const unsigned char *ptr, size_t size)
+{
+    if (size == 0) {
+        return;
+    }
+    __asan_unpoison_memory_region(ptr, size);
+}
+#endif /* Asan */