summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Michael Hoisie <hoisie@google.com> 2024-10-01 20:46:03 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2024-10-01 20:46:03 +0000
commit8a56fce88807059d83af32ff87b9802a252cf52a (patch)
tree278f07b690976fbf1f44a4ed2c26811a2c241c99
parenta5e07fc5fd8172296381d7674e8e599abc71a4f7 (diff)
parentbe2d5ae0d34e4bd6f7796776546b3adbcaab0618 (diff)
Merge "Use MappedFile in android_database_SQLiteConnection" into main
-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 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();
}
}