summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Elliott Hughes <enh@google.com> 2025-03-10 06:39:58 -0800
committer Elliott Hughes <enh@google.com> 2025-03-11 08:00:06 -0700
commitca2362c05e2fc05f9211e39ecb74857195b27780 (patch)
tree36152bc873f94721ceadb803a329cd64dfb41910
parent4370b86853f0fdf16f0e957365c6b600e5b32fe2 (diff)
Remove memfd_create_compat().
Multiple places were already unconditionally calling memfd_create(), and ART no longer runs tests on fugu (whose ancient kernel didn't have memfd_create()). Change-Id: I8ca96d75a9e6f4fe5395b210f60d9920808bb26c
-rw-r--r--compiler/common_compiler_test.cc2
-rw-r--r--libartbase/base/memfd.cc23
-rw-r--r--libartbase/base/memfd.h4
-rw-r--r--openjdkjvmti/ti_search.cc2
-rw-r--r--runtime/gc/space/image_space.cc6
5 files changed, 5 insertions, 32 deletions
diff --git a/compiler/common_compiler_test.cc b/compiler/common_compiler_test.cc
index e54c85f747..ef915e4152 100644
--- a/compiler/common_compiler_test.cc
+++ b/compiler/common_compiler_test.cc
@@ -63,7 +63,7 @@ class CommonCompilerTestImpl::CodeAndMetadata {
const uint32_t capacity = RoundUp(code_offset + code_size, page_size);
// Create a memfd handle with sufficient capacity.
- android::base::unique_fd mem_fd(art::memfd_create_compat("test code", /*flags=*/ 0));
+ android::base::unique_fd mem_fd(art::memfd_create("test code", /*flags=*/ 0));
CHECK_GE(mem_fd.get(), 0);
int err = ftruncate(mem_fd, capacity);
CHECK_EQ(err, 0);
diff --git a/libartbase/base/memfd.cc b/libartbase/base/memfd.cc
index 3b9872b295..4530f8199b 100644
--- a/libartbase/base/memfd.cc
+++ b/libartbase/base/memfd.cc
@@ -64,29 +64,6 @@ int memfd_create([[maybe_unused]] const char* name, [[maybe_unused]] unsigned in
#endif // __NR_memfd_create
-// This is a wrapper that will attempt to simulate memfd_create if normal running fails.
-int memfd_create_compat(const char* name, unsigned int flags) {
- int res = memfd_create(name, flags);
- if (res >= 0) {
- return res;
- }
-#if !defined(_WIN32)
- // Try to create an anonymous file with tmpfile that we can use instead.
- if (flags == 0) {
- FILE* file = tmpfile();
- if (file != nullptr) {
- // We want the normal 'dup' semantics since memfd_create without any flags isn't CLOEXEC.
- // Unfortunately on some android targets we will compiler error if we use dup directly and so
- // need to use fcntl.
- int nfd = fcntl(fileno(file), F_DUPFD, /*lowest allowed fd*/ 0);
- fclose(file);
- return nfd;
- }
- }
-#endif
- return res;
-}
-
#if defined(__BIONIC__)
static bool IsSealFutureWriteSupportedInternal() {
diff --git a/libartbase/base/memfd.h b/libartbase/base/memfd.h
index 3c27dcb9e3..b288f7bc37 100644
--- a/libartbase/base/memfd.h
+++ b/libartbase/base/memfd.h
@@ -69,10 +69,6 @@ namespace art {
// check for safety on older kernels (b/116769556)..
int memfd_create(const char* name, unsigned int flags);
-// Call memfd(2) if available on platform and return result. Try to give us an unlinked FD in some
-// other way if memfd fails or isn't supported.
-int memfd_create_compat(const char* name, unsigned int flags);
-
// Return whether the kernel supports sealing future writes of a memfd.
bool IsSealFutureWriteSupported();
diff --git a/openjdkjvmti/ti_search.cc b/openjdkjvmti/ti_search.cc
index 30a889aaa5..e441010939 100644
--- a/openjdkjvmti/ti_search.cc
+++ b/openjdkjvmti/ti_search.cc
@@ -278,7 +278,7 @@ jvmtiError SearchUtil::AddToDexClassLoaderInMemory(jvmtiEnv* jvmti_env,
// lot of code as well.
// Create a memfd
- art::File file(art::memfd_create_compat("JVMTI InMemory Added dex file", 0), /*check-usage*/true);
+ art::File file(art::memfd_create("JVMTI InMemory Added dex file", 0), /*check-usage*/true);
if (file.Fd() < 0) {
char* reason = strerror(errno);
JVMTI_LOG(ERROR, jvmti_env) << "Unable to create memfd due to " << reason;
diff --git a/runtime/gc/space/image_space.cc b/runtime/gc/space/image_space.cc
index 3d55c04828..97512bc79c 100644
--- a/runtime/gc/space/image_space.cc
+++ b/runtime/gc/space/image_space.cc
@@ -1967,9 +1967,9 @@ bool ImageSpace::BootImageLayout::CompileBootclasspathElements(
std::string art_filename = ExpandLocation(base_filename, bcp_index);
std::string vdex_filename = ImageHeader::GetVdexLocationFromImageLocation(art_filename);
std::string oat_filename = ImageHeader::GetOatLocationFromImageLocation(art_filename);
- android::base::unique_fd art_fd(memfd_create_compat(art_filename.c_str(), /*flags=*/ 0));
- android::base::unique_fd vdex_fd(memfd_create_compat(vdex_filename.c_str(), /*flags=*/ 0));
- android::base::unique_fd oat_fd(memfd_create_compat(oat_filename.c_str(), /*flags=*/ 0));
+ android::base::unique_fd art_fd(memfd_create(art_filename.c_str(), /*flags=*/ 0));
+ android::base::unique_fd vdex_fd(memfd_create(vdex_filename.c_str(), /*flags=*/ 0));
+ android::base::unique_fd oat_fd(memfd_create(oat_filename.c_str(), /*flags=*/ 0));
if (art_fd.get() == -1 || vdex_fd.get() == -1 || oat_fd.get() == -1) {
*error_msg = StringPrintf("Failed to create memfd handles for compiling bootclasspath for %s",
boot_class_path_locations_[bcp_index].c_str());