Clean up kAccWritable in the verifier.
kAccVerifier was deprecated, instead memory permissions were used in its
stead.
Move dead code scanning in the verifier to be enabled when the results
will be logged.
Change-Id: Id20e62eefe958bd577b86bd7396a439d7a01c1b3
diff --git a/src/dex_file.h b/src/dex_file.h
index 993716c..f1f76a8 100644
--- a/src/dex_file.h
+++ b/src/dex_file.h
@@ -789,6 +789,14 @@
void ChangePermissions(int prot) const;
+ int GetPermissions() const {
+ if (mem_map_.get() == NULL) {
+ return 0;
+ } else {
+ return mem_map_->GetProtect();
+ }
+ }
+
private:
// Opens a .dex file
static const DexFile* OpenFile(const std::string& filename,
diff --git a/src/mem_map.cc b/src/mem_map.cc
index c9929cc..409e653 100644
--- a/src/mem_map.cc
+++ b/src/mem_map.cc
@@ -91,7 +91,7 @@
<< ", " << prot << ", " << flags << ", " << fd.get() << ", 0) failed for " << name;
return NULL;
}
- return new MemMap(actual, byte_count, actual, page_aligned_byte_count);
+ return new MemMap(actual, byte_count, actual, page_aligned_byte_count, prot);
}
MemMap* MemMap::MapFileAtAddress(byte* addr, size_t byte_count, int prot, int flags, int fd, off_t start) {
@@ -113,7 +113,7 @@
PLOG(ERROR) << "mmap failed";
return NULL;
}
- return new MemMap(actual + page_offset, byte_count, actual, page_aligned_byte_count);
+ return new MemMap(actual + page_offset, byte_count, actual, page_aligned_byte_count, prot);
}
MemMap::~MemMap() {
@@ -126,8 +126,8 @@
}
}
-MemMap::MemMap(byte* begin, size_t size, void* base_begin, size_t base_size)
- : begin_(begin), size_(size), base_begin_(base_begin), base_size_(base_size) {
+MemMap::MemMap(byte* begin, size_t size, void* base_begin, size_t base_size, int prot)
+ : begin_(begin), size_(size), base_begin_(base_begin), base_size_(base_size), prot_(prot) {
CHECK(begin_ != NULL);
CHECK_NE(size_, 0U);
CHECK(base_begin_ != NULL);
@@ -137,10 +137,12 @@
bool MemMap::Protect(int prot) {
if (base_begin_ == NULL && base_size_ == 0) {
+ prot_ = prot;
return true;
}
if (mprotect(base_begin_, base_size_, prot) == 0) {
+ prot_ = prot;
return true;
}
diff --git a/src/mem_map.h b/src/mem_map.h
index 3f39210..f442570 100644
--- a/src/mem_map.h
+++ b/src/mem_map.h
@@ -59,6 +59,10 @@
bool Protect(int prot);
+ int GetProtect() const {
+ return prot_;
+ }
+
byte* Begin() const {
return begin_;
}
@@ -72,13 +76,14 @@
}
private:
- MemMap(byte* begin, size_t size, void* base_begin, size_t base_size);
+ MemMap(byte* begin, size_t size, void* base_begin, size_t base_size, int prot);
- byte* const begin_; // start of data
- const size_t size_; // length of data
+ byte* const begin_; // Start of data.
+ const size_t size_; // Length of data.
- void* const base_begin_; // page-aligned base address
- const size_t base_size_; // length of mapping
+ void* const base_begin_; // Page-aligned base address.
+ const size_t base_size_; // Length of mapping.
+ int prot_; // Protection of the map.
};
} // namespace art
diff --git a/src/object.h b/src/object.h
index efdc3d7..0fc6acc 100644
--- a/src/object.h
+++ b/src/object.h
@@ -138,7 +138,6 @@
static const uint32_t kAccConstructor = 0x00010000; // method (dex only)
static const uint32_t kAccDeclaredSynchronized = 0x00020000; // method (dex only)
static const uint32_t kAccClassIsProxy = 0x00040000; // class (dex only)
-static const uint32_t kAccWritable = 0x80000000; // method (dex only)
// Special runtime-only flags.
// Note: if only kAccClassIsReference is set, we have a soft reference.
diff --git a/src/verifier/method_verifier.cc b/src/verifier/method_verifier.cc
index 9082172..0a487e3 100644
--- a/src/verifier/method_verifier.cc
+++ b/src/verifier/method_verifier.cc
@@ -1249,7 +1249,7 @@
insn_flags_[insn_idx].ClearChanged();
}
- if (DEAD_CODE_SCAN && ((method_access_flags_ & kAccWritable) == 0)) {
+ if (gDebugVerify) {
/*
* Scan for dead code. There's nothing "evil" about dead code
* (besides the wasted space), but it indicates a flaw somewhere
@@ -3073,6 +3073,9 @@
<< PrettyMethod(method_idx_, *dex_file_) << " " << failure_message->str();
return;
}
+
+ CHECK_EQ(dex_file_->GetPermissions() & PROT_WRITE, PROT_WRITE); // Dex file needs to be writable.
+
const Instruction* inst = Instruction::At(code_item_->insns_ + work_insn_idx_);
DCHECK(inst->IsThrow()) << "Expected instruction that will throw " << inst->Name();
VerifyErrorRefType ref_type;
diff --git a/src/verifier/method_verifier.h b/src/verifier/method_verifier.h
index 8eef71a..b2a88b7 100644
--- a/src/verifier/method_verifier.h
+++ b/src/verifier/method_verifier.h
@@ -58,13 +58,6 @@
class PcToReferenceMap;
/*
- * Set this to enable dead code scanning. This is not required, but it's very useful when testing
- * changes to the verifier (to make sure we're not skipping over stuff). The only reason not to do
- * it is that it slightly increases the time required to perform verification.
- */
-#define DEAD_CODE_SCAN kIsDebugBuild
-
-/*
* "Direct" and "virtual" methods are stored independently. The type of call used to invoke the
* method determines which list we search, and whether we travel up into superclasses.
*