diff options
author | 2024-10-01 21:13:32 +0000 | |
---|---|---|
committer | 2024-10-01 21:13:32 +0000 | |
commit | adc74e57c92f34a799eb2428b0af5fc0eceecc49 (patch) | |
tree | 32cbaea7ef9054573975e4cfb20447a5ce74e095 | |
parent | 14cf92a53435bb3e9d44a067f601c9b3bab4cd13 (diff) | |
parent | 8a56fce88807059d83af32ff87b9802a252cf52a (diff) |
Merge "Use MappedFile in android_database_SQLiteConnection" into main am: 8a56fce888
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/3002409
Change-Id: I045b9718d32bbd1bba33a39e706dc3ea28f0d8a6
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | core/jni/android_database_SQLiteConnection.cpp | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/core/jni/android_database_SQLiteConnection.cpp b/core/jni/android_database_SQLiteConnection.cpp index 8f7026859898..46590a947eda 100644 --- a/core/jni/android_database_SQLiteConnection.cpp +++ b/core/jni/android_database_SQLiteConnection.cpp @@ -16,27 +16,22 @@ #define LOG_TAG "SQLiteConnection" -#include <jni.h> -#include <nativehelper/JNIHelp.h> +#include <android-base/mapped_file.h> #include <android_runtime/AndroidRuntime.h> #include <android_runtime/Log.h> - -#include <utils/Log.h> -#include <utils/String8.h> -#include <utils/String16.h> -#include <cutils/ashmem.h> -#include <sys/mman.h> - -#include <string.h> -#include <unistd.h> - #include <androidfw/CursorWindow.h> - +#include <cutils/ashmem.h> +#include <jni.h> +#include <nativehelper/JNIHelp.h> #include <sqlite3.h> #include <sqlite3_android.h> +#include <string.h> +#include <unistd.h> +#include <utils/Log.h> +#include <utils/String16.h> +#include <utils/String8.h> #include "android_database_SQLiteCommon.h" - #include "core_jni_helpers.h" // Set to 1 to use UTF16 storage for localized indexes. @@ -649,13 +644,14 @@ static int createAshmemRegionWithData(JNIEnv* env, const void* data, size_t leng ALOGE("ashmem_create_region failed: %s", strerror(error)); } else { if (length > 0) { - void* ptr = mmap(NULL, length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (ptr == MAP_FAILED) { + std::unique_ptr<base::MappedFile> mappedFile = + base::MappedFile::FromFd(fd, 0, length, PROT_READ | PROT_WRITE); + if (mappedFile == nullptr) { error = errno; ALOGE("mmap failed: %s", strerror(error)); } else { - memcpy(ptr, data, length); - munmap(ptr, length); + memcpy(mappedFile->data(), data, length); + mappedFile.reset(); } } |