Merge "libc: Make calls to new user-space logger (revisit)"
diff --git a/libc/bionic/mmap.cpp b/libc/bionic/mmap.cpp
index 28a47cc..8f25a89 100644
--- a/libc/bionic/mmap.cpp
+++ b/libc/bionic/mmap.cpp
@@ -37,16 +37,23 @@
 
 #define MMAP2_SHIFT 12 // 2**12 == 4096
 
+static bool kernel_has_MADV_MERGEABLE = true;
+
 void* mmap64(void* addr, size_t size, int prot, int flags, int fd, off64_t offset) {
   if (offset < 0 || (offset & ((1UL << MMAP2_SHIFT)-1)) != 0) {
     errno = EINVAL;
     return MAP_FAILED;
   }
 
+  bool is_private_anonymous = (flags & (MAP_PRIVATE | MAP_ANONYMOUS)) != 0;
   void* result = __mmap2(addr, size, prot, flags, fd, offset >> MMAP2_SHIFT);
-  if (result != MAP_FAILED && (flags & (MAP_PRIVATE | MAP_ANONYMOUS)) != 0) {
+
+  if (result != MAP_FAILED && kernel_has_MADV_MERGEABLE && is_private_anonymous) {
     ErrnoRestorer errno_restorer;
-    madvise(result, size, MADV_MERGEABLE);
+    int rc = madvise(result, size, MADV_MERGEABLE);
+    if (rc == -1 && errno == EINVAL) {
+      kernel_has_MADV_MERGEABLE = false;
+    }
   }
 
   return result;
diff --git a/libc/include/sys/klog.h b/libc/include/sys/klog.h
index 02851d2..acfaa20 100644
--- a/libc/include/sys/klog.h
+++ b/libc/include/sys/klog.h
@@ -25,6 +25,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #ifndef _SYS_KLOG_H_
 #define _SYS_KLOG_H_
 
@@ -45,13 +46,6 @@
 #define KLOG_SIZE_UNREAD   9
 #define KLOG_SIZE_BUFFER   10
 
-/* These are deprecated names that were used in earlier bionic releases. Do not use. */
-#define KLOG_DISABLE 6
-#define KLOG_ENABLE 7
-#define KLOG_SETLEVEL 8
-#define KLOG_UNREADSIZE 9
-#define KLOG_WRITE 10
-
 extern int klogctl(int, char *, int);
 
 __END_DECLS