diff options
-rw-r--r-- | libc/bionic/pthread_create.cpp | 2 | ||||
-rw-r--r-- | libc/include/sys/prctl.h | 31 | ||||
-rw-r--r-- | libc/private/WriteProtected.h | 1 | ||||
-rw-r--r-- | libc/private/bionic_prctl.h | 26 | ||||
-rw-r--r-- | libc/stdlib/atexit.c | 5 | ||||
-rw-r--r-- | libc/system_properties/contexts_serialized.cpp | 2 | ||||
-rw-r--r-- | libc/upstream-openbsd/android/include/arc4random.h | 3 | ||||
-rw-r--r-- | linker/linker_allocator.cpp | 3 | ||||
-rw-r--r-- | linker/linker_allocator.h | 3 | ||||
-rw-r--r-- | linker/linker_block_allocator.cpp | 3 | ||||
-rw-r--r-- | linker/linker_cfi.cpp | 2 | ||||
-rw-r--r-- | linker/linker_phdr.cpp | 2 | ||||
-rw-r--r-- | tests/sys_prctl_test.cpp | 3 |
13 files changed, 37 insertions, 49 deletions
diff --git a/libc/bionic/pthread_create.cpp b/libc/bionic/pthread_create.cpp index 98d172671..15366afe4 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 64f59540a..bd4241147 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 20afdecf6..7a6b09800 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 103cccb65..000000000 --- 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 a26bee4ff..bd6ac3db0 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 12e971563..6ccd46c99 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 afa8d1421..5f0b15e0f 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 a37e910b5..de3309bd5 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 82e4ef456..8c4198b65 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 abb1ebd08..dca944e9c 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 8910c3faf..782ebc663 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 54354a826..0a7ccd800 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 2123c944e..7afa626a6 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); |