Add PR_SET_VMA and PR_SET_VMA_ANON_NAME to <sys/prctl.h>.

We've copied & pasted these to too many places. And if we're going to
have another go at upstreaming these, that's probably yet another reason
to have the *values* in just one place. (Even if upstream wants different
names, we'll likely keep the legacy names around for a while for source
compatibility.)

Bug: http://b/111903542
Test: ran tests
Change-Id: I8ccc557453d69530e5b74f865cbe0b458c84e3ba
diff --git a/libc/bionic/pthread_create.cpp b/libc/bionic/pthread_create.cpp
index 98d1726..15366af 100644
--- a/libc/bionic/pthread_create.cpp
+++ b/libc/bionic/pthread_create.cpp
@@ -31,6 +31,7 @@
 #include <errno.h>
 #include <string.h>
 #include <sys/mman.h>
+#include <sys/prctl.h>
 #include <unistd.h>
 
 #include "pthread_internal.h"
@@ -39,7 +40,6 @@
 
 #include "private/bionic_defs.h"
 #include "private/bionic_macros.h"
-#include "private/bionic_prctl.h"
 #include "private/bionic_ssp.h"
 #include "private/bionic_tls.h"
 #include "private/ErrnoRestorer.h"
diff --git a/libc/include/sys/prctl.h b/libc/include/sys/prctl.h
index 64f5954..bd42411 100644
--- a/libc/include/sys/prctl.h
+++ b/libc/include/sys/prctl.h
@@ -26,17 +26,40 @@
  * SUCH DAMAGE.
  */
 
-#ifndef _SYS_PRCTL_H
-#define _SYS_PRCTL_H
+#pragma once
+
+/**
+ * @file sys/prctl.h
+ * @brief Process-specific operations.
+ */
 
 #include <sys/cdefs.h>
 
 #include <linux/prctl.h>
 
+/**
+ * Names a VMA (mmap'ed region). The second argument must be `PR_SET_VMA_ANON_NAME`,
+ * the third and fourth are a `void*` pointer to the VMA and its `size_t` length in
+ * bytes, and the final argument is a `const char*` pointer to the name.
+ *
+ * Note that the kernel keeps the pointer to the name rather than copying the name,
+ * so the lifetime of the string should be at least as long as that of the VMA.
+ */
+#define PR_SET_VMA 0x53564d41
+
+/**
+ * For use with `PR_SET_VMA`.
+ */
+#define PR_SET_VMA_ANON_NAME 0
+
 __BEGIN_DECLS
 
+/**
+ * [prctl(2)](http://man7.org/linux/man-pages/man2/prctl.2.html) performs a variety of
+ * operations based on the `PR_` constant passed as the first argument.
+ *
+ * Returns -1 and sets `errno` on failure; success values vary by option.
+ */
 int prctl(int __option, ...);
 
 __END_DECLS
-
-#endif
diff --git a/libc/private/WriteProtected.h b/libc/private/WriteProtected.h
index 20afdec..7a6b098 100644
--- a/libc/private/WriteProtected.h
+++ b/libc/private/WriteProtected.h
@@ -26,7 +26,6 @@
 #include <async_safe/log.h>
 
 #include "private/bionic_macros.h"
-#include "private/bionic_prctl.h"
 
 template <typename T>
 union WriteProtectedContents {
diff --git a/libc/private/bionic_prctl.h b/libc/private/bionic_prctl.h
deleted file mode 100644
index 103cccb..0000000
--- a/libc/private/bionic_prctl.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef BIONIC_PRCTL_H
-#define BIONIC_PRCTL_H
-
-#include <sys/prctl.h>
-
-// This is only supported by Android kernels, so it's not in the uapi headers.
-#define PR_SET_VMA   0x53564d41
-#define PR_SET_VMA_ANON_NAME    0
-
-#endif // BIONIC_PRCTL_H
diff --git a/libc/stdlib/atexit.c b/libc/stdlib/atexit.c
index a26bee4..bd6ac3d 100644
--- a/libc/stdlib/atexit.c
+++ b/libc/stdlib/atexit.c
@@ -36,12 +36,9 @@
 #include <string.h>
 #include <unistd.h>
 #include <sys/mman.h>
+#include <sys/prctl.h>
 #include <sys/types.h>
 
-/* BEGIN android-changed */
-#include "private/bionic_prctl.h"
-/* END android-changed */
-
 static pthread_mutex_t g_atexit_lock = PTHREAD_MUTEX_INITIALIZER;
 #define _ATEXIT_LOCK() pthread_mutex_lock(&g_atexit_lock)
 #define _ATEXIT_UNLOCK() pthread_mutex_unlock(&g_atexit_lock)
diff --git a/libc/system_properties/contexts_serialized.cpp b/libc/system_properties/contexts_serialized.cpp
index 12e9715..6ccd46c 100644
--- a/libc/system_properties/contexts_serialized.cpp
+++ b/libc/system_properties/contexts_serialized.cpp
@@ -31,6 +31,7 @@
 #include <fcntl.h>
 #include <limits.h>
 #include <sys/mman.h>
+#include <sys/prctl.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 
@@ -38,7 +39,6 @@
 
 #include <async_safe/log.h>
 
-#include "private/bionic_prctl.h"
 #include "system_properties/system_properties.h"
 
 bool ContextsSerialized::InitializeContextNodes() {
diff --git a/libc/upstream-openbsd/android/include/arc4random.h b/libc/upstream-openbsd/android/include/arc4random.h
index afa8d14..5f0b15e 100644
--- a/libc/upstream-openbsd/android/include/arc4random.h
+++ b/libc/upstream-openbsd/android/include/arc4random.h
@@ -26,11 +26,10 @@
 #include <pthread.h>
 #include <signal.h>
 #include <sys/mman.h>
+#include <sys/prctl.h>
 
 #include <async_safe/log.h>
 
-#include "private/bionic_prctl.h"
-
 // Android gets these from "thread_private.h".
 #include "thread_private.h"
 //static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
diff --git a/linker/linker_allocator.cpp b/linker/linker_allocator.cpp
index a37e910..de3309b 100644
--- a/linker/linker_allocator.cpp
+++ b/linker/linker_allocator.cpp
@@ -35,12 +35,11 @@
 
 #include <stdlib.h>
 #include <sys/mman.h>
+#include <sys/prctl.h>
 #include <unistd.h>
 
 #include <async_safe/log.h>
 
-#include "private/bionic_prctl.h"
-
 //
 // LinkerMemeoryAllocator is general purpose allocator
 // designed to provide the same functionality as the malloc/free/realloc
diff --git a/linker/linker_allocator.h b/linker/linker_allocator.h
index 82e4ef4..8c4198b 100644
--- a/linker/linker_allocator.h
+++ b/linker/linker_allocator.h
@@ -32,6 +32,7 @@
 #include <stdlib.h>
 #include <sys/cdefs.h>
 #include <sys/mman.h>
+#include <sys/prctl.h>
 #include <stddef.h>
 #include <unistd.h>
 
@@ -39,8 +40,6 @@
 
 #include <async_safe/log.h>
 
-#include "private/bionic_prctl.h"
-
 const uint32_t kSmallObjectMaxSizeLog2 = 10;
 const uint32_t kSmallObjectMinSizeLog2 = 4;
 const uint32_t kSmallObjectAllocatorsCount = kSmallObjectMaxSizeLog2 - kSmallObjectMinSizeLog2 + 1;
diff --git a/linker/linker_block_allocator.cpp b/linker/linker_block_allocator.cpp
index abb1ebd..dca944e 100644
--- a/linker/linker_block_allocator.cpp
+++ b/linker/linker_block_allocator.cpp
@@ -30,10 +30,9 @@
 #include <inttypes.h>
 #include <string.h>
 #include <sys/mman.h>
+#include <sys/prctl.h>
 #include <unistd.h>
 
-#include "private/bionic_prctl.h"
-
 // the multiplier should be power of 2
 static constexpr size_t round_up(size_t size, size_t multiplier) {
   return (size + (multiplier - 1)) & ~(multiplier-1);
diff --git a/linker/linker_cfi.cpp b/linker/linker_cfi.cpp
index 8910c3f..782ebc6 100644
--- a/linker/linker_cfi.cpp
+++ b/linker/linker_cfi.cpp
@@ -31,9 +31,9 @@
 #include "linker_debug.h"
 #include "linker_globals.h"
 #include "private/bionic_page.h"
-#include "private/bionic_prctl.h"
 
 #include <sys/mman.h>
+#include <sys/prctl.h>
 #include <sys/types.h>
 #include <cstdint>
 
diff --git a/linker/linker_phdr.cpp b/linker/linker_phdr.cpp
index 54354a8..0a7ccd8 100644
--- a/linker/linker_phdr.cpp
+++ b/linker/linker_phdr.cpp
@@ -31,6 +31,7 @@
 #include <errno.h>
 #include <string.h>
 #include <sys/mman.h>
+#include <sys/prctl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -41,7 +42,6 @@
 #include "linker_debug.h"
 #include "linker_utils.h"
 
-#include "private/bionic_prctl.h"
 #include "private/CFIShadow.h" // For kLibraryAlignment
 
 static int GetTargetElfMachine() {
diff --git a/tests/sys_prctl_test.cpp b/tests/sys_prctl_test.cpp
index 2123c94..7afa626 100644
--- a/tests/sys_prctl_test.cpp
+++ b/tests/sys_prctl_test.cpp
@@ -29,11 +29,10 @@
 
 #include "android-base/file.h"
 #include "android-base/strings.h"
-#include "private/bionic_prctl.h"
 
 // http://b/20017123.
 TEST(sys_prctl, bug_20017123) {
-#if defined(__ANDROID__) // PR_SET_VMA is only available in Android kernels.
+#if defined(PR_SET_VMA) // PR_SET_VMA is only available in Android kernels.
   size_t page_size = static_cast<size_t>(sysconf(_SC_PAGESIZE));
   void* p = mmap(NULL, page_size * 3, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
   ASSERT_NE(MAP_FAILED, p);