diff --git a/DEPS b/DEPS index cfc308f9..95622b61 100644 --- a/DEPS +++ b/DEPS @@ -28,7 +28,7 @@ deps = { '5e2b3ddde7cda5eb6bc09a5546a76b00e49d888f', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - 'fa146c1264953b42baccfc261dc6aa59a1661d26', + '88e056258a01450b07414642fa5fb98493c1f6ce', 'crashpad/third_party/zlib/zlib': Var('chromium_git') + '/chromium/src/third_party/zlib@' + '13dc246a58e4b72104d35f9b1809af95221ebda7', diff --git a/build/gyp_crashpad_android.py b/build/gyp_crashpad_android.py index 4461425a..f78c05b9 100755 --- a/build/gyp_crashpad_android.py +++ b/build/gyp_crashpad_android.py @@ -69,26 +69,32 @@ def main(args): os.environ['CXX_target'] = os.path.join(ndk_bin_dir, '%s-g++' % arch_triplet) - # Unlike the Clang build, when using GCC with “unified headers,” - # __ANDROID_API__ isn’t set automatically and must be pushed in to the - # build. Fish the correct value out of the Clang wrapper script. If unified - # headers are not being used, the Clang wrapper won’t mention - # __ANDROID_API__, but the standalone toolchain’s will - # #define it for both Clang and GCC. - # - # Unified headers are the way of the future, according to - # https://android.googlesource.com/platform/ndk/+/ndk-r14/CHANGELOG.md and - # https://android.googlesource.com/platform/ndk/+/master/docs/UnifiedHeaders.md. - with open(clang_path, 'r') as file: - clang_script_contents = file.read() - matches = re.finditer(r'\s-D__ANDROID_API__=([\d]+)\s', - clang_script_contents) - match = next(matches, None) - if match: - android_api = int(match.group(1)) - extra_args.extend(['-D', 'android_api_level=%d' % android_api]) - if next(matches, None): - raise AssertionError('__ANDROID_API__ defined too many times') + # Unlike the Clang build, when using GCC with unified headers, __ANDROID_API__ + # isn’t set automatically and must be pushed in to the build. Fish the correct + # value out of the Clang wrapper script. If deprecated headers are in use, the + # Clang wrapper won’t mention __ANDROID_API__, but the standalone toolchain’s + # will #define it for both Clang and GCC. + # + # android_api_level is extracted in this manner even when compiling with Clang + # so that it’s available for use in GYP conditions that need to test the API + # level, but beware that it’ll only be available when unified headers are in + # use. + # + # Unified headers are the way of the future, according to + # https://android.googlesource.com/platform/ndk/+/ndk-r14/CHANGELOG.md and + # https://android.googlesource.com/platform/ndk/+/master/docs/UnifiedHeaders.md. + # Traditional (deprecated) headers have been removed entirely as of NDK r16. + # https://android.googlesource.com/platform/ndk/+/ndk-release-r16/CHANGELOG.md. + with open(clang_path, 'r') as file: + clang_script_contents = file.read() + matches = re.finditer(r'\s-D__ANDROID_API__=([\d]+)\s', + clang_script_contents) + match = next(matches, None) + if match: + android_api = int(match.group(1)) + extra_args.extend(['-D', 'android_api_level=%d' % android_api]) + if next(matches, None): + raise AssertionError('__ANDROID_API__ defined too many times') for tool in ('ar', 'nm', 'readelf'): os.environ['%s_target' % tool.upper()] = ( diff --git a/compat/android/sys/mman.cc b/compat/android/sys/mman.cc deleted file mode 100644 index f4d722c9..00000000 --- a/compat/android/sys/mman.cc +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright 2017 The Crashpad Authors. All rights reserved. -// -// 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. - -#include - -#include -#include -#include -#include - -#if defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 21 - -// Bionic has provided a wrapper for __mmap2() since the beginning of time. See -// bionic/libc/SYSCALLS.TXT in any Android version. -extern "C" void* __mmap2(void* addr, - size_t size, - int prot, - int flags, - int fd, - size_t pgoff); - -namespace { - -template -T Align(T value, uint8_t alignment) { - return (value + alignment - 1) & ~(alignment - 1); -} - -// Adapted from Android 8.0.0 bionic/libc/bionic/mmap.cpp. -void* LocalMmap64(void* addr, - size_t size, - int prot, - int flags, - int fd, - off64_t offset) { - constexpr int kMmap2Shift = 12; - - if (offset < 0 || (offset & ((1UL << kMmap2Shift) - 1)) != 0) { - errno = EINVAL; - return MAP_FAILED; - } - - const size_t rounded = Align(size, getpagesize()); - if (rounded < size || rounded > PTRDIFF_MAX) { - errno = ENOMEM; - return MAP_FAILED; - } - - const bool is_private_anonymous = - (flags & (MAP_PRIVATE | MAP_ANONYMOUS)) == (MAP_PRIVATE | MAP_ANONYMOUS); - const bool is_stack_or_grows_down = - (flags & (MAP_STACK | MAP_GROWSDOWN)) != 0; - - void* const result = - __mmap2(addr, size, prot, flags, fd, offset >> kMmap2Shift); - - static bool kernel_has_MADV_MERGEABLE = true; - if (result != MAP_FAILED && kernel_has_MADV_MERGEABLE && - is_private_anonymous && !is_stack_or_grows_down) { - const int saved_errno = errno; - const int rc = madvise(result, size, MADV_MERGEABLE); - if (rc == -1 && errno == EINVAL) { - kernel_has_MADV_MERGEABLE = false; - } - errno = saved_errno; - } - - return result; -} - -} // namespace - -extern "C" { - -void* mmap(void* addr, size_t size, int prot, int flags, int fd, off_t offset) { - // Use the system’s mmap64() wrapper if available. It will be available on - // Android 5.0 (“Lollipop”) and later. - using Mmap64Type = void* (*)(void*, size_t, int, int, int, off64_t); - static const Mmap64Type mmap64 = - reinterpret_cast(dlsym(RTLD_DEFAULT, "mmap64")); - if (mmap64) { - return mmap64(addr, size, prot, flags, fd, offset); - } - - // Otherwise, use the local implementation, which should amount to exactly the - // same thing. - return LocalMmap64(addr, size, prot, flags, fd, offset); -} - -} // extern "C" - -#endif // defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 21 diff --git a/compat/android/sys/mman.h b/compat/android/sys/mman.h deleted file mode 100644 index 5e7cd69f..00000000 --- a/compat/android/sys/mman.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2017 The Crashpad Authors. All rights reserved. -// -// 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 CRASHPAD_COMPAT_ANDROID_SYS_MMAN_H_ -#define CRASHPAD_COMPAT_ANDROID_SYS_MMAN_H_ - -#include_next - -#include -#include - -// There’s no mmap() wrapper compatible with a 64-bit off_t for 32-bit code -// until API 21 (Android 5.0/“Lollipop”). A custom mmap() wrapper is provided -// here. Note that this scenario is only possible with NDK unified headers. -// -// https://android.googlesource.com/platform/bionic/+/0bfcbaf4d069e005d6e959d97f8d11c77722b70d/docs/32-bit-abi.md#is-32_bit-1 - -#if defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 21 - -#ifdef __cplusplus -extern "C" { -#endif - -void* mmap(void* addr, size_t size, int prot, int flags, int fd, off_t offset); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 21 - -#endif // CRASHPAD_COMPAT_ANDROID_SYS_MMAN_H_ diff --git a/compat/compat.gyp b/compat/compat.gyp index b0aec0af..2e6eb038 100644 --- a/compat/compat.gyp +++ b/compat/compat.gyp @@ -26,8 +26,6 @@ 'android/linux/prctl.h', 'android/linux/ptrace.h', 'android/sched.h', - 'android/sys/mman.cc', - 'android/sys/mman.h', 'android/sys/syscall.h', 'android/sys/user.h', 'linux/signal.h', diff --git a/doc/developing.md b/doc/developing.md index 4dd74782..d034b4d4 100644 --- a/doc/developing.md +++ b/doc/developing.md @@ -119,7 +119,7 @@ Kit)](https://developer.android.com/ndk/) runs on. If it’s not already present on your system, [download the NDK package for your system](https://developer.android.com/ndk/downloads/) and expand it to a suitable location. These instructions assume that it’s been expanded to -`~/android-ndk-r15b`. +`~/android-ndk-r16`. To build Crashpad, portions of the NDK must be reassembled into a [standalone toolchain](https://developer.android.com/ndk/guides/standalone_toolchain.html). @@ -133,8 +133,8 @@ desired. To build a standalone toolchain targeting 64-bit ARM and API level 21 ``` $ cd ~ -$ python android-ndk-r15b/build/tools/make_standalone_toolchain.py \ - --arch=arm64 --api=21 --install-dir=android-ndk-r15b_arm64_api21 +$ python android-ndk-r16/build/tools/make_standalone_toolchain.py \ + --arch=arm64 --api=21 --install-dir=android-ndk-r16_arm64_api21 ``` Note that Chrome uses Android API level 21 for 64-bit platforms and 16 for @@ -152,7 +152,7 @@ operation. ``` $ cd ~/crashpad/crashpad $ python build/gyp_crashpad_android.py \ - --ndk ~/android-ndk-r15b_arm64_api21 \ + --ndk ~/android-ndk-r16_arm64_api21 \ --generator-output out/android_arm64_api21 ```