diff options
author | Justin DeMartino <jjdemartino@google.com> | 2020-10-14 19:39:53 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2020-10-14 19:39:53 +0000 |
commit | 0d11af03e43f110b0bb160f7e20436d0043e3038 (patch) | |
tree | 48f8bcca856276ec73a86dd3fb26143d3ca64578 /libcutils/ashmem-dev.cpp | |
parent | 075666ebd0dee8d0c4a2efa54f7c324a3f67ee2a (diff) | |
parent | a6c01e4e98d2b343dcecfc99611e2e6250c730db (diff) |
Merge changes from topic "SP1A.200921.001" into s-keystone-qcom-dev
* changes:
fs_mgr: adb-remount-test.sh: filter out more administrivia mounts.
Merge SP1A.200921.001 Change-Id: I90b97c4e9fb10b1f45e74def404823eed5b1aaa8
Diffstat (limited to 'libcutils/ashmem-dev.cpp')
-rw-r--r-- | libcutils/ashmem-dev.cpp | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/libcutils/ashmem-dev.cpp b/libcutils/ashmem-dev.cpp index 8c232f0cd..6a27f9a20 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()); @@ -158,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; @@ -211,13 +214,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) { @@ -329,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)); |