From ac4500e67de510a3724b98f248e5cb8f3cc1eb26 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Mon, 27 Jul 2020 14:03:56 -0700 Subject: Update language to comply with Android's inclusive language guidance See https://source.android.com/setup/contribute/respectful-code for reference Bug: http://b/161896447 Test: None Change-Id: I9e5a37a20012b2f7a8eac55701df03f7b7a9ab6c --- libcutils/ashmem-dev.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'libcutils/ashmem-dev.cpp') diff --git a/libcutils/ashmem-dev.cpp b/libcutils/ashmem-dev.cpp index 8c232f0cd..20cd6592d 100644 --- a/libcutils/ashmem-dev.cpp +++ b/libcutils/ashmem-dev.cpp @@ -122,7 +122,8 @@ static bool check_vendor_memfd_allowed() { return true; } - /* If its not a number, assume string, but check if its a sane string */ + // Non-numeric should be a single ASCII character. Characters after the + // first are ignored. if (tolower(vndk_version[0]) < 'a' || tolower(vndk_version[0]) > 'z') { ALOGE("memfd: ro.vndk.version not defined or invalid (%s), this is mandated since P.\n", vndk_version.c_str()); -- cgit v1.2.3 From 9a147033f8f250050635a4fce36b36dd28b1df14 Mon Sep 17 00:00:00 2001 From: Hridya Valsaraju Date: Fri, 7 Aug 2020 12:22:24 -0700 Subject: Add failure logs in __ashmem_open_locked() Bug: 160984921 Test: build, boot Change-Id: I754c961289828463af6de905d8b057b4350f5f07 --- libcutils/ashmem-dev.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'libcutils/ashmem-dev.cpp') diff --git a/libcutils/ashmem-dev.cpp b/libcutils/ashmem-dev.cpp index 20cd6592d..233d400e0 100644 --- a/libcutils/ashmem-dev.cpp +++ b/libcutils/ashmem-dev.cpp @@ -212,13 +212,16 @@ static int __ashmem_open_locked() // fallback for APEX w/ use_vendor on Q, which would have still used /dev/ashmem if (fd < 0) { + int saved_errno = errno; fd = TEMP_FAILURE_RETRY(open("/dev/ashmem", O_RDWR | O_CLOEXEC)); + if (fd < 0) { + /* Q launching devices and newer must not reach here since they should have been + * able to open ashmem_device_path */ + ALOGE("Unable to open ashmem device %s (error = %s) and /dev/ashmem(error = %s)", + ashmem_device_path.c_str(), strerror(saved_errno), strerror(errno)); + return fd; + } } - - if (fd < 0) { - return fd; - } - struct stat st; int ret = TEMP_FAILURE_RETRY(fstat(fd, &st)); if (ret < 0) { -- cgit v1.2.3 From 790ef0579311f5cbf0ab6258b2fb7f5e3747b1c9 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 3 Sep 2020 10:53:16 -0700 Subject: ashmem: ensure ashmem fds are CLOEXEC. Fix the memfd_create(2) path and add the missing unit test. Bug: https://issuetracker.google.com/165667331 Test: treehugger Change-Id: Ibb5c1d0f9d7caba1df04d1f03e82e55026d9f86a --- libcutils/ashmem-dev.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'libcutils/ashmem-dev.cpp') diff --git a/libcutils/ashmem-dev.cpp b/libcutils/ashmem-dev.cpp index 233d400e0..6a27f9a20 100644 --- a/libcutils/ashmem-dev.cpp +++ b/libcutils/ashmem-dev.cpp @@ -159,9 +159,11 @@ static bool __has_memfd_support() { return false; } - /* Check if kernel support exists, otherwise fall back to ashmem */ + // Check if kernel support exists, otherwise fall back to ashmem. + // This code needs to build on old API levels, so we can't use the libc + // wrapper. android::base::unique_fd fd( - syscall(__NR_memfd_create, "test_android_memfd", MFD_ALLOW_SEALING)); + syscall(__NR_memfd_create, "test_android_memfd", MFD_CLOEXEC | MFD_ALLOW_SEALING)); if (fd == -1) { ALOGE("memfd_create failed: %s, no memfd support.\n", strerror(errno)); return false; @@ -333,7 +335,9 @@ int ashmem_valid(int fd) } static int memfd_create_region(const char* name, size_t size) { - android::base::unique_fd fd(syscall(__NR_memfd_create, name, MFD_ALLOW_SEALING)); + // This code needs to build on old API levels, so we can't use the libc + // wrapper. + android::base::unique_fd fd(syscall(__NR_memfd_create, name, MFD_CLOEXEC | MFD_ALLOW_SEALING)); if (fd == -1) { ALOGE("memfd_create(%s, %zd) failed: %s\n", name, size, strerror(errno)); -- cgit v1.2.3