summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Michael Hoisie <hoisie@google.com> 2024-10-01 21:34:53 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2024-10-01 21:34:53 +0000
commit3c0c6fedef20d2253bd653167beeb13bdf82c26b (patch)
tree48abd7569480c8e301bb062d67f9b63bcfc56a3c
parenta71cb37c2a6d357bdeb2234bbaf20536d95935a5 (diff)
parentadc74e57c92f34a799eb2428b0af5fc0eceecc49 (diff)
Merge "Use MappedFile in android_database_SQLiteConnection" into main am: 8a56fce888 am: adc74e57c9
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/3002409 Change-Id: If011afd82b10b24c862fd3fdc2feae2b9c99bfbe Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--core/jni/android_database_SQLiteConnection.cpp32
1 files changed, 14 insertions, 18 deletions
diff --git a/core/jni/android_database_SQLiteConnection.cpp b/core/jni/android_database_SQLiteConnection.cpp
index 3370f386f4d2..ba7e70564143 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.
@@ -669,13 +664,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();
}
}