From 51a22a12ab370933a35463f5c81223132ec64dcb Mon Sep 17 00:00:00 2001 From: Dmitriy Ivanov Date: Fri, 8 Aug 2014 16:57:15 -0700 Subject: [PATCH] Label pages mapped by linker_allocator Change-Id: I7e0bf29bc1a480e9be0d1ae573ca1063d90d82ff --- libc/bionic/dlmalloc.c | 6 +----- libc/private/bionic_prctl.h | 26 ++++++++++++++++++++++++++ linker/linker_allocator.cpp | 5 +++++ 3 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 libc/private/bionic_prctl.h diff --git a/libc/bionic/dlmalloc.c b/libc/bionic/dlmalloc.c index d582071a7..e89c5d1ff 100644 --- a/libc/bionic/dlmalloc.c +++ b/libc/bionic/dlmalloc.c @@ -16,6 +16,7 @@ #include "dlmalloc.h" +#include "private/bionic_prctl.h" #include "private/libc_logging.h" // Send dlmalloc errors to the log. @@ -30,11 +31,6 @@ static void* named_anonymous_mmap(size_t length); #define MMAP(s) named_anonymous_mmap(s) #define DIRECT_MMAP(s) named_anonymous_mmap(s) -// Local definitions of custom prctl arguments to set a vma name in Android kernels. -#include -#define PR_SET_VMA 0x53564d41 -#define PR_SET_VMA_ANON_NAME 0 - // Ugly inclusion of C file so that bionic specific #defines configure dlmalloc. #include "../upstream-dlmalloc/malloc.c" diff --git a/libc/private/bionic_prctl.h b/libc/private/bionic_prctl.h new file mode 100644 index 000000000..103cccb65 --- /dev/null +++ b/libc/private/bionic_prctl.h @@ -0,0 +1,26 @@ +/* + * 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 + +// 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/linker/linker_allocator.cpp b/linker/linker_allocator.cpp index f5d3745b4..92220e8c4 100644 --- a/linker/linker_allocator.cpp +++ b/linker/linker_allocator.cpp @@ -18,6 +18,8 @@ #include #include +#include "private/bionic_prctl.h" + struct LinkerAllocatorPage { LinkerAllocatorPage* next; uint8_t bytes[PAGE_SIZE-sizeof(LinkerAllocatorPage*)]; @@ -96,6 +98,9 @@ void LinkerBlockAllocator::create_new_page() { if (page == MAP_FAILED) { abort(); // oom } + + prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, page, PAGE_SIZE, "linker_alloc"); + memset(page, 0, PAGE_SIZE); FreeBlockInfo* first_block = reinterpret_cast(page->bytes);