[PATCH] D68427: [scudo][standalone] Make malloc_info return a minimal XML

Kostya Kortchinsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 3 14:54:01 PDT 2019


cryptoad created this revision.
cryptoad added reviewers: cferris, morehouse, hctim, eugenis, vitalybuka.
Herald added subscribers: Sanitizers, delcypher.
Herald added projects: LLVM, Sanitizers.

Initially, our malloc_info was returning ENOTSUP, but Android would
rather have it return successfully and write a barebone XML to the
stream, so we will oblige.

Add an associated test.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D68427

Files:
  lib/scudo/standalone/tests/wrappers_c_test.cpp
  lib/scudo/standalone/wrappers_c.inc


Index: lib/scudo/standalone/wrappers_c.inc
===================================================================
--- lib/scudo/standalone/wrappers_c.inc
+++ lib/scudo/standalone/wrappers_c.inc
@@ -179,7 +179,8 @@
       SCUDO_ALLOCATOR.allocate(size, scudo::Chunk::Origin::Malloc, alignment));
 }
 
-INTERFACE WEAK int SCUDO_PREFIX(malloc_info)(int, FILE *) {
-  errno = ENOTSUP;
-  return -1;
+INTERFACE WEAK int SCUDO_PREFIX(malloc_info)(UNUSED int options, FILE *stream) {
+  fputs("<malloc version=\"1\">", stream);
+  fputs("</malloc>", stream);
+  return 0;
 }
Index: lib/scudo/standalone/tests/wrappers_c_test.cpp
===================================================================
--- lib/scudo/standalone/tests/wrappers_c_test.cpp
+++ lib/scudo/standalone/tests/wrappers_c_test.cpp
@@ -281,3 +281,15 @@
 
   free(P);
 }
+
+TEST(ScudoWrappersCTest, MallocInfo) {
+  char Buffer[64];
+  FILE *F = fmemopen(Buffer, sizeof(Buffer), "w+");
+  EXPECT_NE(F, nullptr);
+  errno = 0;
+  EXPECT_EQ(malloc_info(0, F), 0);
+  EXPECT_EQ(errno, 0);
+  fflush(F);
+  EXPECT_EQ(strncmp(Buffer, "<malloc", 7), 0);
+  fclose(F);
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68427.223104.patch
Type: text/x-patch
Size: 1121 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191003/a34f8676/attachment.bin>


More information about the llvm-commits mailing list