summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <treehugger-gerrit@google.com> 2016-07-16 04:46:46 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2016-07-16 04:46:46 +0000
commit173f435e56acfd0501fc460747572a4796dcffe0 (patch)
tree5e5716d1b07f229efb78783d26518511539ef5a3
parent161c866ca742049f5c916696e1503c697be30e87 (diff)
parent43e10b031e3bb42df54adf8f0525a29d2b308a4e (diff)
Merge "ART: Replace ScopedFd with FdFile"
-rw-r--r--compiler/oat_test.cc6
-rw-r--r--compiler/oat_writer.cc10
-rw-r--r--compiler/oat_writer.h3
-rw-r--r--dex2oat/dex2oat.cc3
-rw-r--r--runtime/base/file_magic.cc17
-rw-r--r--runtime/base/file_magic.h4
-rw-r--r--runtime/dex_file.cc30
-rw-r--r--runtime/mem_map.cc25
-rw-r--r--runtime/oat_file_assistant.cc1
9 files changed, 46 insertions, 53 deletions
diff --git a/compiler/oat_test.cc b/compiler/oat_test.cc
index 41b19601b9..18ebfeb7f4 100644
--- a/compiler/oat_test.cc
+++ b/compiler/oat_test.cc
@@ -158,7 +158,7 @@ class OatTest : public CommonCompilerTest {
}
bool WriteElf(File* file,
- ScopedFd&& zip_fd,
+ File&& zip_fd,
const char* location,
SafeMap<std::string, std::string>& key_value_store,
bool verify) {
@@ -708,8 +708,8 @@ void OatTest::TestZipFileInput(bool verify) {
{
// Test using the AddZipDexFileSource() interface with the zip file handle.
- ScopedFd zip_fd(dup(zip_file.GetFd()));
- ASSERT_NE(-1, zip_fd.get());
+ File zip_fd(dup(zip_file.GetFd()), /* check_usage */ false);
+ ASSERT_NE(-1, zip_fd.Fd());
ScratchFile oat_file;
success = WriteElf(oat_file.GetFile(),
diff --git a/compiler/oat_writer.cc b/compiler/oat_writer.cc
index cdc7df11b6..b32199f0a5 100644
--- a/compiler/oat_writer.cc
+++ b/compiler/oat_writer.cc
@@ -323,14 +323,14 @@ bool OatWriter::AddDexFileSource(const char* filename,
DCHECK(write_state_ == WriteState::kAddingDexFileSources);
uint32_t magic;
std::string error_msg;
- ScopedFd fd(OpenAndReadMagic(filename, &magic, &error_msg));
- if (fd.get() == -1) {
+ File fd = OpenAndReadMagic(filename, &magic, &error_msg);
+ if (fd.Fd() == -1) {
PLOG(ERROR) << "Failed to read magic number from dex file: '" << filename << "'";
return false;
} else if (IsDexMagic(magic)) {
// The file is open for reading, not writing, so it's OK to let the File destructor
// close it without checking for explicit Close(), so pass checkUsage = false.
- raw_dex_files_.emplace_back(new File(fd.release(), location, /* checkUsage */ false));
+ raw_dex_files_.emplace_back(new File(fd.Release(), location, /* checkUsage */ false));
oat_dex_files_.emplace_back(location,
DexFileSource(raw_dex_files_.back().get()),
create_type_lookup_table);
@@ -346,12 +346,12 @@ bool OatWriter::AddDexFileSource(const char* filename,
}
// Add dex file source(s) from a zip file specified by a file handle.
-bool OatWriter::AddZippedDexFilesSource(ScopedFd&& zip_fd,
+bool OatWriter::AddZippedDexFilesSource(File&& zip_fd,
const char* location,
CreateTypeLookupTable create_type_lookup_table) {
DCHECK(write_state_ == WriteState::kAddingDexFileSources);
std::string error_msg;
- zip_archives_.emplace_back(ZipArchive::OpenFromFd(zip_fd.release(), location, &error_msg));
+ zip_archives_.emplace_back(ZipArchive::OpenFromFd(zip_fd.Release(), location, &error_msg));
ZipArchive* zip_archive = zip_archives_.back().get();
if (zip_archive == nullptr) {
LOG(ERROR) << "Failed to open zip from file descriptor for '" << location << "': "
diff --git a/compiler/oat_writer.h b/compiler/oat_writer.h
index cc81f39f36..decb7dbc26 100644
--- a/compiler/oat_writer.h
+++ b/compiler/oat_writer.h
@@ -29,7 +29,6 @@
#include "oat.h"
#include "os.h"
#include "safe_map.h"
-#include "ScopedFd.h"
#include "utils/array_ref.h"
namespace art {
@@ -132,7 +131,7 @@ class OatWriter {
CreateTypeLookupTable create_type_lookup_table = CreateTypeLookupTable::kDefault);
// Add dex file source(s) from a zip file specified by a file handle.
bool AddZippedDexFilesSource(
- ScopedFd&& zip_fd,
+ File&& zip_fd,
const char* location,
CreateTypeLookupTable create_type_lookup_table = CreateTypeLookupTable::kDefault);
// Add dex file source from raw memory.
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index 8d20e5bfff..0d1d4d7673 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -2145,7 +2145,8 @@ class Dex2Oat FINAL {
TimingLogger::ScopedTiming t2("AddDexFileSources", timings_);
if (zip_fd_ != -1) {
DCHECK_EQ(oat_writers_.size(), 1u);
- if (!oat_writers_[0]->AddZippedDexFilesSource(ScopedFd(zip_fd_), zip_location_.c_str())) {
+ if (!oat_writers_[0]->AddZippedDexFilesSource(File(zip_fd_, /* check_usage */ false),
+ zip_location_.c_str())) {
return false;
}
} else if (oat_writers_.size() > 1u) {
diff --git a/runtime/base/file_magic.cc b/runtime/base/file_magic.cc
index 97563382a1..de6f4237ff 100644
--- a/runtime/base/file_magic.cc
+++ b/runtime/base/file_magic.cc
@@ -21,27 +21,28 @@
#include <sys/types.h>
#include "base/logging.h"
+#include "base/unix_file/fd_file.h"
#include "dex_file.h"
#include "stringprintf.h"
namespace art {
-ScopedFd OpenAndReadMagic(const char* filename, uint32_t* magic, std::string* error_msg) {
+File OpenAndReadMagic(const char* filename, uint32_t* magic, std::string* error_msg) {
CHECK(magic != nullptr);
- ScopedFd fd(open(filename, O_RDONLY, 0));
- if (fd.get() == -1) {
+ File fd(filename, O_RDONLY, /* check_usage */ false);
+ if (fd.Fd() == -1) {
*error_msg = StringPrintf("Unable to open '%s' : %s", filename, strerror(errno));
- return ScopedFd();
+ return File();
}
- int n = TEMP_FAILURE_RETRY(read(fd.get(), magic, sizeof(*magic)));
+ int n = TEMP_FAILURE_RETRY(read(fd.Fd(), magic, sizeof(*magic)));
if (n != sizeof(*magic)) {
*error_msg = StringPrintf("Failed to find magic in '%s'", filename);
- return ScopedFd();
+ return File();
}
- if (lseek(fd.get(), 0, SEEK_SET) != 0) {
+ if (lseek(fd.Fd(), 0, SEEK_SET) != 0) {
*error_msg = StringPrintf("Failed to seek to beginning of file '%s' : %s", filename,
strerror(errno));
- return ScopedFd();
+ return File();
}
return fd;
}
diff --git a/runtime/base/file_magic.h b/runtime/base/file_magic.h
index f7e4bad16d..4b5d2f5a48 100644
--- a/runtime/base/file_magic.h
+++ b/runtime/base/file_magic.h
@@ -20,12 +20,12 @@
#include <stdint.h>
#include <string>
-#include "ScopedFd.h"
+#include "os.h"
namespace art {
// Open file and read magic number
-ScopedFd OpenAndReadMagic(const char* filename, uint32_t* magic, std::string* error_msg);
+File OpenAndReadMagic(const char* filename, uint32_t* magic, std::string* error_msg);
// Check whether the given magic matches a known file type.
bool IsZipMagic(uint32_t magic);
diff --git a/runtime/dex_file.cc b/runtime/dex_file.cc
index 5a203afd1a..5d9ae14d1f 100644
--- a/runtime/dex_file.cc
+++ b/runtime/dex_file.cc
@@ -35,6 +35,7 @@
#include "base/stl_util.h"
#include "base/stringprintf.h"
#include "base/systrace.h"
+#include "base/unix_file/fd_file.h"
#include "class_linker-inl.h"
#include "dex_file-inl.h"
#include "dex_file_verifier.h"
@@ -54,11 +55,6 @@
#include "well_known_classes.h"
#include "zip_archive.h"
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wshadow"
-#include "ScopedFd.h"
-#pragma GCC diagnostic pop
-
namespace art {
const uint8_t DexFile::kDexMagic[] = { 'd', 'e', 'x', '\n' };
@@ -85,14 +81,14 @@ bool DexFile::GetChecksum(const char* filename, uint32_t* checksum, std::string*
DCHECK_EQ(zip_entry_name[-1], kMultiDexSeparator);
}
- ScopedFd fd(OpenAndReadMagic(file_part, &magic, error_msg));
- if (fd.get() == -1) {
+ File fd = OpenAndReadMagic(file_part, &magic, error_msg);
+ if (fd.Fd() == -1) {
DCHECK(!error_msg->empty());
return false;
}
if (IsZipMagic(magic)) {
std::unique_ptr<ZipArchive> zip_archive(
- ZipArchive::OpenFromFd(fd.release(), filename, error_msg));
+ ZipArchive::OpenFromFd(fd.Release(), filename, error_msg));
if (zip_archive.get() == nullptr) {
*error_msg = StringPrintf("Failed to open zip archive '%s' (error msg: %s)", file_part,
error_msg->c_str());
@@ -109,7 +105,7 @@ bool DexFile::GetChecksum(const char* filename, uint32_t* checksum, std::string*
}
if (IsDexMagic(magic)) {
std::unique_ptr<const DexFile> dex_file(
- DexFile::OpenFile(fd.release(), filename, false, false, error_msg));
+ DexFile::OpenFile(fd.Release(), filename, false, false, error_msg));
if (dex_file.get() == nullptr) {
return false;
}
@@ -128,16 +124,16 @@ bool DexFile::Open(const char* filename,
ScopedTrace trace(std::string("Open dex file ") + location);
DCHECK(dex_files != nullptr) << "DexFile::Open: out-param is nullptr";
uint32_t magic;
- ScopedFd fd(OpenAndReadMagic(filename, &magic, error_msg));
- if (fd.get() == -1) {
+ File fd = OpenAndReadMagic(filename, &magic, error_msg);
+ if (fd.Fd() == -1) {
DCHECK(!error_msg->empty());
return false;
}
if (IsZipMagic(magic)) {
- return DexFile::OpenZip(fd.release(), location, verify_checksum, error_msg, dex_files);
+ return DexFile::OpenZip(fd.Release(), location, verify_checksum, error_msg, dex_files);
}
if (IsDexMagic(magic)) {
- std::unique_ptr<const DexFile> dex_file(DexFile::OpenFile(fd.release(),
+ std::unique_ptr<const DexFile> dex_file(DexFile::OpenFile(fd.Release(),
location,
/* verify */ true,
verify_checksum,
@@ -166,12 +162,12 @@ static bool ContainsClassesDex(int fd, const char* filename) {
bool DexFile::MaybeDex(const char* filename) {
uint32_t magic;
std::string error_msg;
- ScopedFd fd(OpenAndReadMagic(filename, &magic, &error_msg));
- if (fd.get() == -1) {
+ File fd = OpenAndReadMagic(filename, &magic, &error_msg);
+ if (fd.Fd() == -1) {
return false;
}
if (IsZipMagic(magic)) {
- return ContainsClassesDex(fd.release(), filename);
+ return ContainsClassesDex(fd.Release(), filename);
} else if (IsDexMagic(magic)) {
return true;
}
@@ -244,7 +240,7 @@ std::unique_ptr<const DexFile> DexFile::OpenFile(int fd,
CHECK(location != nullptr);
std::unique_ptr<MemMap> map;
{
- ScopedFd delayed_close(fd);
+ File delayed_close(fd, /* check_usage */ false);
struct stat sbuf;
memset(&sbuf, 0, sizeof(sbuf));
if (fstat(fd, &sbuf) == -1) {
diff --git a/runtime/mem_map.cc b/runtime/mem_map.cc
index c047ba20f5..bb07fcbf37 100644
--- a/runtime/mem_map.cc
+++ b/runtime/mem_map.cc
@@ -25,12 +25,8 @@
#include <sstream>
#include "base/stringprintf.h"
-
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wshadow"
-#include "ScopedFd.h"
-#pragma GCC diagnostic pop
-
+#include "base/unix_file/fd_file.h"
+#include "os.h"
#include "thread-inl.h"
#include "utils.h"
@@ -301,7 +297,7 @@ MemMap* MemMap::MapAnonymous(const char* name,
flags |= MAP_FIXED;
}
- ScopedFd fd(-1);
+ File fd;
if (use_ashmem) {
if (!kIsTargetBuild) {
@@ -320,8 +316,9 @@ MemMap* MemMap::MapAnonymous(const char* name,
// prefixed "dalvik-".
std::string debug_friendly_name("dalvik-");
debug_friendly_name += name;
- fd.reset(ashmem_create_region(debug_friendly_name.c_str(), page_aligned_byte_count));
- if (fd.get() == -1) {
+ fd.Reset(ashmem_create_region(debug_friendly_name.c_str(), page_aligned_byte_count),
+ /* check_usage */ false);
+ if (fd.Fd() == -1) {
*error_msg = StringPrintf("ashmem_create_region failed for '%s': %s", name, strerror(errno));
return nullptr;
}
@@ -335,7 +332,7 @@ MemMap* MemMap::MapAnonymous(const char* name,
page_aligned_byte_count,
prot,
flags,
- fd.get(),
+ fd.Fd(),
0,
low_4gb);
saved_errno = errno;
@@ -352,7 +349,7 @@ MemMap* MemMap::MapAnonymous(const char* name,
page_aligned_byte_count,
prot,
flags,
- fd.get(),
+ fd.Fd(),
strerror(saved_errno));
}
return nullptr;
@@ -558,7 +555,7 @@ MemMap* MemMap::RemapAtEnd(uint8_t* new_end, const char* tail_name, int tail_pro
return nullptr;
}
}
- ScopedFd fd(int_fd);
+ File fd(int_fd, /* check_usage */ false);
MEMORY_TOOL_MAKE_UNDEFINED(tail_base_begin, tail_base_size);
// Unmap/map the tail region.
@@ -574,12 +571,12 @@ MemMap* MemMap::RemapAtEnd(uint8_t* new_end, const char* tail_name, int tail_pro
// region. Note this isn't perfect as there's no way to prevent
// other threads to try to take this memory region here.
uint8_t* actual = reinterpret_cast<uint8_t*>(mmap(tail_base_begin, tail_base_size, tail_prot,
- flags, fd.get(), 0));
+ flags, fd.Fd(), 0));
if (actual == MAP_FAILED) {
PrintFileToLog("/proc/self/maps", LogSeverity::WARNING);
*error_msg = StringPrintf("anonymous mmap(%p, %zd, 0x%x, 0x%x, %d, 0) failed. See process "
"maps in the log.", tail_base_begin, tail_base_size, tail_prot, flags,
- fd.get());
+ fd.Fd());
return nullptr;
}
return new MemMap(tail_name, actual, tail_size, actual, tail_base_size, tail_prot, false);
diff --git a/runtime/oat_file_assistant.cc b/runtime/oat_file_assistant.cc
index aae9d97aeb..67281231bf 100644
--- a/runtime/oat_file_assistant.cc
+++ b/runtime/oat_file_assistant.cc
@@ -39,7 +39,6 @@
#include "os.h"
#include "runtime.h"
#include "scoped_thread_state_change.h"
-#include "ScopedFd.h"
#include "utils.h"
namespace art {