mediaextractor: Skip setting  memory limits on ASan builds

ASan-ified libraries have a larger memory footprint which counts
towards a process's RLIMIT_AS. Detect ASan at runtime and skip
setting memory limits.

Test: Builds and boots. "MediaUtils: running with ASan, not setting
memory limits" appears in logcat, mediaextractor is no longer
crashing.

Bug: 31831213
Change-Id: I6705baa825cbfd45695def2cd80d8d2261b05339
diff --git a/media/libmedia/MediaUtils.cpp b/media/libmedia/MediaUtils.cpp
index a02ca65..dc2bc82 100644
--- a/media/libmedia/MediaUtils.cpp
+++ b/media/libmedia/MediaUtils.cpp
@@ -31,6 +31,11 @@
     size_t numberOfBytes,
     size_t percentageOfTotalMem) {
 
+    if (running_with_asan()) {
+        ALOGW("Running with ASan, skip enforcing memory limitations.");
+        return;
+    }
+
     long pageSize = sysconf(_SC_PAGESIZE);
     long numPages = sysconf(_SC_PHYS_PAGES);
     size_t maxMem = SIZE_MAX;
diff --git a/media/libmedia/MediaUtils.h b/media/libmedia/MediaUtils.h
index f80dd30..a678bcc 100644
--- a/media/libmedia/MediaUtils.h
+++ b/media/libmedia/MediaUtils.h
@@ -19,6 +19,12 @@
 
 namespace android {
 
+extern "C" void __asan_init(void) __attribute__((weak));
+
+static inline int running_with_asan() {
+    return &__asan_init != 0;
+}
+
 /**
    Limit the amount of memory a process can allocate using setrlimit(RLIMIT_AS).
    The value to use will be read from the specified system property, or if the