Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 16 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 17 | #include "dex_file.h" |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 18 | |
| 19 | #include <fcntl.h> |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 20 | #include <limits.h> |
Brian Carlstrom | b0460ea | 2011-07-29 10:08:05 -0700 | [diff] [blame] | 21 | #include <stdio.h> |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 22 | #include <stdlib.h> |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 23 | #include <string.h> |
Brian Carlstrom | b0460ea | 2011-07-29 10:08:05 -0700 | [diff] [blame] | 24 | #include <sys/file.h> |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 25 | #include <sys/stat.h> |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 26 | |
Elliott Hughes | 07ed66b | 2012-12-12 18:34:25 -0800 | [diff] [blame] | 27 | #include "base/logging.h" |
Elliott Hughes | e222ee0 | 2012-12-13 14:41:43 -0800 | [diff] [blame] | 28 | #include "base/stringprintf.h" |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 29 | #include "class_linker.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 30 | #include "dex_file-inl.h" |
jeffhao | 10037c8 | 2012-01-23 15:06:23 -0800 | [diff] [blame] | 31 | #include "dex_file_verifier.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 32 | #include "globals.h" |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 33 | #include "leb128.h" |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 34 | #include "mirror/art_field-inl.h" |
| 35 | #include "mirror/art_method-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 36 | #include "mirror/string.h" |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 37 | #include "os.h" |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 38 | #include "safe_map.h" |
Vladimir Marko | fd99576 | 2013-11-06 16:36:36 +0000 | [diff] [blame] | 39 | #include "ScopedFd.h" |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 40 | #include "sirt_ref.h" |
Brian Carlstrom | b0460ea | 2011-07-29 10:08:05 -0700 | [diff] [blame] | 41 | #include "thread.h" |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 42 | #include "UniquePtr.h" |
Ian Rogers | a672490 | 2013-09-23 09:23:37 -0700 | [diff] [blame] | 43 | #include "utf-inl.h" |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 44 | #include "utils.h" |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 45 | #include "well_known_classes.h" |
Brian Carlstrom | b0460ea | 2011-07-29 10:08:05 -0700 | [diff] [blame] | 46 | #include "zip_archive.h" |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 47 | |
| 48 | namespace art { |
| 49 | |
Brian Carlstrom | f615a61 | 2011-07-23 12:50:34 -0700 | [diff] [blame] | 50 | const byte DexFile::kDexMagic[] = { 'd', 'e', 'x', '\n' }; |
| 51 | const byte DexFile::kDexMagicVersion[] = { '0', '3', '5', '\0' }; |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 52 | |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 53 | DexFile::ClassPathEntry DexFile::FindInClassPath(const char* descriptor, |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 54 | const ClassPath& class_path) { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 55 | for (size_t i = 0; i != class_path.size(); ++i) { |
| 56 | const DexFile* dex_file = class_path[i]; |
| 57 | const DexFile::ClassDef* dex_class_def = dex_file->FindClassDef(descriptor); |
| 58 | if (dex_class_def != NULL) { |
| 59 | return ClassPathEntry(dex_file, dex_class_def); |
| 60 | } |
| 61 | } |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 62 | // TODO: remove reinterpret_cast when issue with -std=gnu++0x host issue resolved |
Brian Carlstrom | 7e93b50 | 2011-08-04 14:16:22 -0700 | [diff] [blame] | 63 | return ClassPathEntry(reinterpret_cast<const DexFile*>(NULL), |
| 64 | reinterpret_cast<const DexFile::ClassDef*>(NULL)); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 67 | static int OpenAndReadMagic(const char* filename, uint32_t* magic, std::string* error_msg) { |
Brian Carlstrom | 7c3d13a | 2013-09-04 17:15:11 -0700 | [diff] [blame] | 68 | CHECK(magic != NULL); |
Vladimir Marko | fd99576 | 2013-11-06 16:36:36 +0000 | [diff] [blame] | 69 | ScopedFd fd(open(filename, O_RDONLY, 0)); |
| 70 | if (fd.get() == -1) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 71 | *error_msg = StringPrintf("Unable to open '%s' : %s", filename, strerror(errno)); |
Brian Carlstrom | 7c3d13a | 2013-09-04 17:15:11 -0700 | [diff] [blame] | 72 | return -1; |
| 73 | } |
Vladimir Marko | fd99576 | 2013-11-06 16:36:36 +0000 | [diff] [blame] | 74 | int n = TEMP_FAILURE_RETRY(read(fd.get(), magic, sizeof(*magic))); |
Brian Carlstrom | 7c3d13a | 2013-09-04 17:15:11 -0700 | [diff] [blame] | 75 | if (n != sizeof(*magic)) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 76 | *error_msg = StringPrintf("Failed to find magic in '%s'", filename); |
Brian Carlstrom | 7c3d13a | 2013-09-04 17:15:11 -0700 | [diff] [blame] | 77 | return -1; |
| 78 | } |
Vladimir Marko | fd99576 | 2013-11-06 16:36:36 +0000 | [diff] [blame] | 79 | if (lseek(fd.get(), 0, SEEK_SET) != 0) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 80 | *error_msg = StringPrintf("Failed to seek to beginning of file '%s' : %s", filename, |
| 81 | strerror(errno)); |
Brian Carlstrom | 7c3d13a | 2013-09-04 17:15:11 -0700 | [diff] [blame] | 82 | return -1; |
| 83 | } |
Vladimir Marko | fd99576 | 2013-11-06 16:36:36 +0000 | [diff] [blame] | 84 | return fd.release(); |
Brian Carlstrom | 7c3d13a | 2013-09-04 17:15:11 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 87 | bool DexFile::GetChecksum(const char* filename, uint32_t* checksum, std::string* error_msg) { |
Brian Carlstrom | 7c3d13a | 2013-09-04 17:15:11 -0700 | [diff] [blame] | 88 | CHECK(checksum != NULL); |
| 89 | uint32_t magic; |
Vladimir Marko | fd99576 | 2013-11-06 16:36:36 +0000 | [diff] [blame] | 90 | ScopedFd fd(OpenAndReadMagic(filename, &magic, error_msg)); |
| 91 | if (fd.get() == -1) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 92 | DCHECK(!error_msg->empty()); |
Brian Carlstrom | 7c3d13a | 2013-09-04 17:15:11 -0700 | [diff] [blame] | 93 | return false; |
| 94 | } |
| 95 | if (IsZipMagic(magic)) { |
Vladimir Marko | fd99576 | 2013-11-06 16:36:36 +0000 | [diff] [blame] | 96 | UniquePtr<ZipArchive> zip_archive(ZipArchive::OpenFromFd(fd.release(), filename, error_msg)); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 97 | if (zip_archive.get() == NULL) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 98 | *error_msg = StringPrintf("Failed to open zip archive '%s'", filename); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 99 | return false; |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 100 | } |
Narayan Kamath | 92572be | 2013-11-28 14:06:24 +0000 | [diff] [blame] | 101 | UniquePtr<ZipEntry> zip_entry(zip_archive->Find(kClassesDex, error_msg)); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 102 | if (zip_entry.get() == NULL) { |
Brian Carlstrom | 4fa0bcd | 2013-12-10 11:24:21 -0800 | [diff] [blame] | 103 | *error_msg = StringPrintf("Zip archive '%s' doesn't contain %s (error msg: %s)", filename, |
Narayan Kamath | 92572be | 2013-11-28 14:06:24 +0000 | [diff] [blame] | 104 | kClassesDex, error_msg->c_str()); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 105 | return false; |
| 106 | } |
Brian Carlstrom | 7c3d13a | 2013-09-04 17:15:11 -0700 | [diff] [blame] | 107 | *checksum = zip_entry->GetCrc32(); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 108 | return true; |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 109 | } |
Brian Carlstrom | 7c3d13a | 2013-09-04 17:15:11 -0700 | [diff] [blame] | 110 | if (IsDexMagic(magic)) { |
Vladimir Marko | fd99576 | 2013-11-06 16:36:36 +0000 | [diff] [blame] | 111 | UniquePtr<const DexFile> dex_file(DexFile::OpenFile(fd.release(), filename, false, error_msg)); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 112 | if (dex_file.get() == NULL) { |
| 113 | return false; |
| 114 | } |
Brian Carlstrom | 7c3d13a | 2013-09-04 17:15:11 -0700 | [diff] [blame] | 115 | *checksum = dex_file->GetHeader().checksum_; |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 116 | return true; |
| 117 | } |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 118 | *error_msg = StringPrintf("Expected valid zip or dex file: '%s'", filename); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 119 | return false; |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 122 | const DexFile* DexFile::Open(const char* filename, |
| 123 | const char* location, |
| 124 | std::string* error_msg) { |
Brian Carlstrom | 7c3d13a | 2013-09-04 17:15:11 -0700 | [diff] [blame] | 125 | uint32_t magic; |
Vladimir Marko | fd99576 | 2013-11-06 16:36:36 +0000 | [diff] [blame] | 126 | ScopedFd fd(OpenAndReadMagic(filename, &magic, error_msg)); |
| 127 | if (fd.get() == -1) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 128 | DCHECK(!error_msg->empty()); |
Brian Carlstrom | 7c3d13a | 2013-09-04 17:15:11 -0700 | [diff] [blame] | 129 | return NULL; |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 130 | } |
Brian Carlstrom | 7c3d13a | 2013-09-04 17:15:11 -0700 | [diff] [blame] | 131 | if (IsZipMagic(magic)) { |
Vladimir Marko | fd99576 | 2013-11-06 16:36:36 +0000 | [diff] [blame] | 132 | return DexFile::OpenZip(fd.release(), location, error_msg); |
Brian Carlstrom | 0dd7dda | 2011-10-25 15:47:53 -0700 | [diff] [blame] | 133 | } |
Brian Carlstrom | 7c3d13a | 2013-09-04 17:15:11 -0700 | [diff] [blame] | 134 | if (IsDexMagic(magic)) { |
Vladimir Marko | fd99576 | 2013-11-06 16:36:36 +0000 | [diff] [blame] | 135 | return DexFile::OpenFile(fd.release(), location, true, error_msg); |
Brian Carlstrom | 7c3d13a | 2013-09-04 17:15:11 -0700 | [diff] [blame] | 136 | } |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 137 | *error_msg = StringPrintf("Expected valid zip or dex file: '%s'", filename); |
| 138 | return nullptr; |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 141 | int DexFile::GetPermissions() const { |
| 142 | if (mem_map_.get() == NULL) { |
| 143 | return 0; |
| 144 | } else { |
| 145 | return mem_map_->GetProtect(); |
| 146 | } |
| 147 | } |
| 148 | |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 149 | bool DexFile::IsReadOnly() const { |
| 150 | return GetPermissions() == PROT_READ; |
| 151 | } |
| 152 | |
Brian Carlstrom | e0948e1 | 2013-08-29 09:36:15 -0700 | [diff] [blame] | 153 | bool DexFile::EnableWrite() const { |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 154 | CHECK(IsReadOnly()); |
| 155 | if (mem_map_.get() == NULL) { |
| 156 | return false; |
| 157 | } else { |
Brian Carlstrom | e0948e1 | 2013-08-29 09:36:15 -0700 | [diff] [blame] | 158 | return mem_map_->Protect(PROT_READ | PROT_WRITE); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | |
Brian Carlstrom | e0948e1 | 2013-08-29 09:36:15 -0700 | [diff] [blame] | 162 | bool DexFile::DisableWrite() const { |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 163 | CHECK(!IsReadOnly()); |
| 164 | if (mem_map_.get() == NULL) { |
| 165 | return false; |
| 166 | } else { |
Brian Carlstrom | e0948e1 | 2013-08-29 09:36:15 -0700 | [diff] [blame] | 167 | return mem_map_->Protect(PROT_READ); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 168 | } |
| 169 | } |
| 170 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 171 | const DexFile* DexFile::OpenFile(int fd, const char* location, bool verify, |
| 172 | std::string* error_msg) { |
| 173 | CHECK(location != nullptr); |
Vladimir Marko | fd99576 | 2013-11-06 16:36:36 +0000 | [diff] [blame] | 174 | UniquePtr<MemMap> map; |
| 175 | { |
| 176 | ScopedFd delayed_close(fd); |
| 177 | struct stat sbuf; |
| 178 | memset(&sbuf, 0, sizeof(sbuf)); |
| 179 | if (fstat(fd, &sbuf) == -1) { |
Brian Carlstrom | 4fa0bcd | 2013-12-10 11:24:21 -0800 | [diff] [blame] | 180 | *error_msg = StringPrintf("DexFile: fstat '%s' failed: %s", location, strerror(errno)); |
Vladimir Marko | fd99576 | 2013-11-06 16:36:36 +0000 | [diff] [blame] | 181 | return nullptr; |
| 182 | } |
| 183 | if (S_ISDIR(sbuf.st_mode)) { |
| 184 | *error_msg = StringPrintf("Attempt to mmap directory '%s'", location); |
| 185 | return nullptr; |
| 186 | } |
| 187 | size_t length = sbuf.st_size; |
| 188 | map.reset(MemMap::MapFile(length, PROT_READ, MAP_PRIVATE, fd, 0, location, error_msg)); |
| 189 | if (map.get() == nullptr) { |
| 190 | DCHECK(!error_msg->empty()); |
| 191 | return nullptr; |
| 192 | } |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 193 | } |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 194 | |
| 195 | if (map->Size() < sizeof(DexFile::Header)) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 196 | *error_msg = StringPrintf( |
Brian Carlstrom | 4fa0bcd | 2013-12-10 11:24:21 -0800 | [diff] [blame] | 197 | "DexFile: failed to open dex file '%s' that is too short to have a header", location); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 198 | return nullptr; |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | const Header* dex_header = reinterpret_cast<const Header*>(map->Begin()); |
| 202 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 203 | const DexFile* dex_file = OpenMemory(location, dex_header->checksum_, map.release(), error_msg); |
| 204 | if (dex_file == nullptr) { |
| 205 | *error_msg = StringPrintf("Failed to open dex file '%s' from memory: %s", location, |
| 206 | error_msg->c_str()); |
| 207 | return nullptr; |
jeffhao | f6174e8 | 2012-01-31 16:14:17 -0800 | [diff] [blame] | 208 | } |
jeffhao | 54c1ceb | 2012-02-01 11:45:32 -0800 | [diff] [blame] | 209 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 210 | if (verify && !DexFileVerifier::Verify(dex_file, dex_file->Begin(), dex_file->Size(), location, |
| 211 | error_msg)) { |
| 212 | return nullptr; |
jeffhao | 54c1ceb | 2012-02-01 11:45:32 -0800 | [diff] [blame] | 213 | } |
| 214 | |
jeffhao | f6174e8 | 2012-01-31 16:14:17 -0800 | [diff] [blame] | 215 | return dex_file; |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Brian Carlstrom | b7bbba4 | 2011-10-13 14:58:47 -0700 | [diff] [blame] | 218 | const char* DexFile::kClassesDex = "classes.dex"; |
Brian Carlstrom | b0460ea | 2011-07-29 10:08:05 -0700 | [diff] [blame] | 219 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 220 | const DexFile* DexFile::OpenZip(int fd, const std::string& location, std::string* error_msg) { |
| 221 | UniquePtr<ZipArchive> zip_archive(ZipArchive::OpenFromFd(fd, location.c_str(), error_msg)); |
| 222 | if (zip_archive.get() == nullptr) { |
| 223 | DCHECK(!error_msg->empty()); |
| 224 | return nullptr; |
Brian Carlstrom | b0460ea | 2011-07-29 10:08:05 -0700 | [diff] [blame] | 225 | } |
Vladimir Marko | fd99576 | 2013-11-06 16:36:36 +0000 | [diff] [blame] | 226 | return DexFile::Open(*zip_archive, location, error_msg); |
Brian Carlstrom | a6cc893 | 2012-01-04 14:44:07 -0800 | [diff] [blame] | 227 | } |
| 228 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 229 | const DexFile* DexFile::OpenMemory(const std::string& location, |
| 230 | uint32_t location_checksum, |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 231 | MemMap* mem_map, |
| 232 | std::string* error_msg) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 233 | return OpenMemory(mem_map->Begin(), |
| 234 | mem_map->Size(), |
| 235 | location, |
| 236 | location_checksum, |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 237 | mem_map, |
| 238 | error_msg); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 239 | } |
| 240 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 241 | const DexFile* DexFile::Open(const ZipArchive& zip_archive, const std::string& location, |
| 242 | std::string* error_msg) { |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 243 | CHECK(!location.empty()); |
Narayan Kamath | 92572be | 2013-11-28 14:06:24 +0000 | [diff] [blame] | 244 | UniquePtr<ZipEntry> zip_entry(zip_archive.Find(kClassesDex, error_msg)); |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 245 | if (zip_entry.get() == NULL) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 246 | return nullptr; |
Brian Carlstrom | b0460ea | 2011-07-29 10:08:05 -0700 | [diff] [blame] | 247 | } |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 248 | UniquePtr<MemMap> map(zip_entry->ExtractToMemMap(kClassesDex, error_msg)); |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 249 | if (map.get() == NULL) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 250 | *error_msg = StringPrintf("Failed to extract '%s' from '%s': %s", kClassesDex, location.c_str(), |
| 251 | error_msg->c_str()); |
| 252 | return nullptr; |
Brian Carlstrom | b0460ea | 2011-07-29 10:08:05 -0700 | [diff] [blame] | 253 | } |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 254 | UniquePtr<const DexFile> dex_file(OpenMemory(location, zip_entry->GetCrc32(), map.release(), |
| 255 | error_msg)); |
| 256 | if (dex_file.get() == nullptr) { |
| 257 | *error_msg = StringPrintf("Failed to open dex file '%s' from memory: %s", location.c_str(), |
| 258 | error_msg->c_str()); |
| 259 | return nullptr; |
jeffhao | f6174e8 | 2012-01-31 16:14:17 -0800 | [diff] [blame] | 260 | } |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 261 | if (!DexFileVerifier::Verify(dex_file.get(), dex_file->Begin(), dex_file->Size(), |
| 262 | location.c_str(), error_msg)) { |
| 263 | return nullptr; |
jeffhao | 54c1ceb | 2012-02-01 11:45:32 -0800 | [diff] [blame] | 264 | } |
Brian Carlstrom | e0948e1 | 2013-08-29 09:36:15 -0700 | [diff] [blame] | 265 | if (!dex_file->DisableWrite()) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 266 | *error_msg = StringPrintf("Failed to make dex file '%s' read only", location.c_str()); |
| 267 | return nullptr; |
Brian Carlstrom | e0948e1 | 2013-08-29 09:36:15 -0700 | [diff] [blame] | 268 | } |
| 269 | CHECK(dex_file->IsReadOnly()) << location; |
| 270 | return dex_file.release(); |
Brian Carlstrom | b0460ea | 2011-07-29 10:08:05 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 273 | const DexFile* DexFile::OpenMemory(const byte* base, |
jeffhao | f6174e8 | 2012-01-31 16:14:17 -0800 | [diff] [blame] | 274 | size_t size, |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 275 | const std::string& location, |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 276 | uint32_t location_checksum, |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 277 | MemMap* mem_map, std::string* error_msg) { |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 278 | CHECK_ALIGNED(base, 4); // various dex file structures must be word aligned |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 279 | UniquePtr<DexFile> dex_file(new DexFile(base, size, location, location_checksum, mem_map)); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 280 | if (!dex_file->Init(error_msg)) { |
| 281 | return nullptr; |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 282 | } else { |
Brian Carlstrom | f615a61 | 2011-07-23 12:50:34 -0700 | [diff] [blame] | 283 | return dex_file.release(); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 284 | } |
| 285 | } |
| 286 | |
Brian Carlstrom | 0d6adac | 2014-02-05 17:39:16 -0800 | [diff] [blame] | 287 | DexFile::DexFile(const byte* base, size_t size, |
| 288 | const std::string& location, |
| 289 | uint32_t location_checksum, |
| 290 | MemMap* mem_map) |
| 291 | : begin_(base), |
| 292 | size_(size), |
| 293 | location_(location), |
| 294 | location_checksum_(location_checksum), |
| 295 | mem_map_(mem_map), |
| 296 | modification_lock("DEX modification lock"), |
| 297 | header_(reinterpret_cast<const Header*>(base)), |
| 298 | string_ids_(reinterpret_cast<const StringId*>(base + header_->string_ids_off_)), |
| 299 | type_ids_(reinterpret_cast<const TypeId*>(base + header_->type_ids_off_)), |
| 300 | field_ids_(reinterpret_cast<const FieldId*>(base + header_->field_ids_off_)), |
| 301 | method_ids_(reinterpret_cast<const MethodId*>(base + header_->method_ids_off_)), |
| 302 | proto_ids_(reinterpret_cast<const ProtoId*>(base + header_->proto_ids_off_)), |
| 303 | class_defs_(reinterpret_cast<const ClassDef*>(base + header_->class_defs_off_)) { |
| 304 | CHECK(begin_ != NULL) << GetLocation(); |
| 305 | CHECK_GT(size_, 0U) << GetLocation(); |
| 306 | } |
| 307 | |
Jesse Wilson | 6bf1915 | 2011-09-29 13:12:33 -0400 | [diff] [blame] | 308 | DexFile::~DexFile() { |
Elliott Hughes | 8cef0b8 | 2011-10-11 19:24:00 -0700 | [diff] [blame] | 309 | // We don't call DeleteGlobalRef on dex_object_ because we're only called by DestroyJavaVM, and |
| 310 | // that's only called after DetachCurrentThread, which means there's no JNIEnv. We could |
| 311 | // re-attach, but cleaning up these global references is not obviously useful. It's not as if |
| 312 | // the global reference table is otherwise empty! |
Jesse Wilson | 6bf1915 | 2011-09-29 13:12:33 -0400 | [diff] [blame] | 313 | } |
| 314 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 315 | bool DexFile::Init(std::string* error_msg) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 316 | if (!CheckMagicAndVersion(error_msg)) { |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 317 | return false; |
| 318 | } |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 319 | return true; |
| 320 | } |
| 321 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 322 | bool DexFile::CheckMagicAndVersion(std::string* error_msg) const { |
Brian Carlstrom | 6e3b1d9 | 2012-01-11 01:36:32 -0800 | [diff] [blame] | 323 | CHECK(header_->magic_ != NULL) << GetLocation(); |
| 324 | if (!IsMagicValid(header_->magic_)) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 325 | std::ostringstream oss; |
| 326 | oss << "Unrecognized magic number in " << GetLocation() << ":" |
Brian Carlstrom | 6e3b1d9 | 2012-01-11 01:36:32 -0800 | [diff] [blame] | 327 | << " " << header_->magic_[0] |
| 328 | << " " << header_->magic_[1] |
| 329 | << " " << header_->magic_[2] |
| 330 | << " " << header_->magic_[3]; |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 331 | *error_msg = oss.str(); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 332 | return false; |
| 333 | } |
Brian Carlstrom | 6e3b1d9 | 2012-01-11 01:36:32 -0800 | [diff] [blame] | 334 | if (!IsVersionValid(header_->magic_)) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 335 | std::ostringstream oss; |
| 336 | oss << "Unrecognized version number in " << GetLocation() << ":" |
Brian Carlstrom | 6e3b1d9 | 2012-01-11 01:36:32 -0800 | [diff] [blame] | 337 | << " " << header_->magic_[4] |
| 338 | << " " << header_->magic_[5] |
| 339 | << " " << header_->magic_[6] |
| 340 | << " " << header_->magic_[7]; |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 341 | *error_msg = oss.str(); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 342 | return false; |
| 343 | } |
| 344 | return true; |
| 345 | } |
| 346 | |
Brian Carlstrom | 6e3b1d9 | 2012-01-11 01:36:32 -0800 | [diff] [blame] | 347 | bool DexFile::IsMagicValid(const byte* magic) { |
| 348 | return (memcmp(magic, kDexMagic, sizeof(kDexMagic)) == 0); |
| 349 | } |
| 350 | |
| 351 | bool DexFile::IsVersionValid(const byte* magic) { |
| 352 | const byte* version = &magic[sizeof(kDexMagic)]; |
| 353 | return (memcmp(version, kDexMagicVersion, sizeof(kDexMagicVersion)) == 0); |
| 354 | } |
| 355 | |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 356 | uint32_t DexFile::GetVersion() const { |
| 357 | const char* version = reinterpret_cast<const char*>(&GetHeader().magic_[sizeof(kDexMagic)]); |
| 358 | return atoi(version); |
| 359 | } |
| 360 | |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 361 | const DexFile::ClassDef* DexFile::FindClassDef(const char* descriptor) const { |
| 362 | size_t num_class_defs = NumClassDefs(); |
| 363 | if (num_class_defs == 0) { |
| 364 | return NULL; |
| 365 | } |
| 366 | const StringId* string_id = FindStringId(descriptor); |
| 367 | if (string_id == NULL) { |
| 368 | return NULL; |
| 369 | } |
| 370 | const TypeId* type_id = FindTypeId(GetIndexForStringId(*string_id)); |
| 371 | if (type_id == NULL) { |
| 372 | return NULL; |
| 373 | } |
| 374 | uint16_t type_idx = GetIndexForTypeId(*type_id); |
| 375 | for (size_t i = 0; i < num_class_defs; ++i) { |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 376 | const ClassDef& class_def = GetClassDef(i); |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 377 | if (class_def.class_idx_ == type_idx) { |
| 378 | return &class_def; |
| 379 | } |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 380 | } |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 381 | return NULL; |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 384 | const DexFile::ClassDef* DexFile::FindClassDef(uint16_t type_idx) const { |
| 385 | size_t num_class_defs = NumClassDefs(); |
| 386 | for (size_t i = 0; i < num_class_defs; ++i) { |
| 387 | const ClassDef& class_def = GetClassDef(i); |
| 388 | if (class_def.class_idx_ == type_idx) { |
| 389 | return &class_def; |
| 390 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 391 | } |
| 392 | return NULL; |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Ian Rogers | 9b1a4f4 | 2011-11-14 18:35:10 -0800 | [diff] [blame] | 395 | const DexFile::FieldId* DexFile::FindFieldId(const DexFile::TypeId& declaring_klass, |
| 396 | const DexFile::StringId& name, |
| 397 | const DexFile::TypeId& type) const { |
| 398 | // Binary search MethodIds knowing that they are sorted by class_idx, name_idx then proto_idx |
| 399 | const uint16_t class_idx = GetIndexForTypeId(declaring_klass); |
| 400 | const uint32_t name_idx = GetIndexForStringId(name); |
| 401 | const uint16_t type_idx = GetIndexForTypeId(type); |
Ian Rogers | f8582c3 | 2013-05-29 16:33:03 -0700 | [diff] [blame] | 402 | int32_t lo = 0; |
| 403 | int32_t hi = NumFieldIds() - 1; |
Ian Rogers | 9b1a4f4 | 2011-11-14 18:35:10 -0800 | [diff] [blame] | 404 | while (hi >= lo) { |
Ian Rogers | f8582c3 | 2013-05-29 16:33:03 -0700 | [diff] [blame] | 405 | int32_t mid = (hi + lo) / 2; |
Ian Rogers | 9b1a4f4 | 2011-11-14 18:35:10 -0800 | [diff] [blame] | 406 | const DexFile::FieldId& field = GetFieldId(mid); |
| 407 | if (class_idx > field.class_idx_) { |
| 408 | lo = mid + 1; |
| 409 | } else if (class_idx < field.class_idx_) { |
| 410 | hi = mid - 1; |
| 411 | } else { |
| 412 | if (name_idx > field.name_idx_) { |
| 413 | lo = mid + 1; |
| 414 | } else if (name_idx < field.name_idx_) { |
| 415 | hi = mid - 1; |
| 416 | } else { |
| 417 | if (type_idx > field.type_idx_) { |
| 418 | lo = mid + 1; |
| 419 | } else if (type_idx < field.type_idx_) { |
| 420 | hi = mid - 1; |
| 421 | } else { |
| 422 | return &field; |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | } |
| 427 | return NULL; |
| 428 | } |
| 429 | |
| 430 | const DexFile::MethodId* DexFile::FindMethodId(const DexFile::TypeId& declaring_klass, |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 431 | const DexFile::StringId& name, |
| 432 | const DexFile::ProtoId& signature) const { |
| 433 | // Binary search MethodIds knowing that they are sorted by class_idx, name_idx then proto_idx |
Ian Rogers | 9b1a4f4 | 2011-11-14 18:35:10 -0800 | [diff] [blame] | 434 | const uint16_t class_idx = GetIndexForTypeId(declaring_klass); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 435 | const uint32_t name_idx = GetIndexForStringId(name); |
| 436 | const uint16_t proto_idx = GetIndexForProtoId(signature); |
Ian Rogers | f8582c3 | 2013-05-29 16:33:03 -0700 | [diff] [blame] | 437 | int32_t lo = 0; |
| 438 | int32_t hi = NumMethodIds() - 1; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 439 | while (hi >= lo) { |
Ian Rogers | f8582c3 | 2013-05-29 16:33:03 -0700 | [diff] [blame] | 440 | int32_t mid = (hi + lo) / 2; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 441 | const DexFile::MethodId& method = GetMethodId(mid); |
| 442 | if (class_idx > method.class_idx_) { |
| 443 | lo = mid + 1; |
| 444 | } else if (class_idx < method.class_idx_) { |
| 445 | hi = mid - 1; |
| 446 | } else { |
| 447 | if (name_idx > method.name_idx_) { |
| 448 | lo = mid + 1; |
| 449 | } else if (name_idx < method.name_idx_) { |
| 450 | hi = mid - 1; |
| 451 | } else { |
| 452 | if (proto_idx > method.proto_idx_) { |
| 453 | lo = mid + 1; |
| 454 | } else if (proto_idx < method.proto_idx_) { |
| 455 | hi = mid - 1; |
| 456 | } else { |
| 457 | return &method; |
| 458 | } |
| 459 | } |
| 460 | } |
| 461 | } |
| 462 | return NULL; |
| 463 | } |
| 464 | |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 465 | const DexFile::StringId* DexFile::FindStringId(const char* string) const { |
Ian Rogers | f8582c3 | 2013-05-29 16:33:03 -0700 | [diff] [blame] | 466 | int32_t lo = 0; |
| 467 | int32_t hi = NumStringIds() - 1; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 468 | while (hi >= lo) { |
Ian Rogers | f8582c3 | 2013-05-29 16:33:03 -0700 | [diff] [blame] | 469 | int32_t mid = (hi + lo) / 2; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 470 | const DexFile::StringId& str_id = GetStringId(mid); |
Ian Rogers | cf5077a | 2013-10-31 12:37:54 -0700 | [diff] [blame] | 471 | const char* str = GetStringData(str_id); |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 472 | int compare = CompareModifiedUtf8ToModifiedUtf8AsUtf16CodePointValues(string, str); |
| 473 | if (compare > 0) { |
| 474 | lo = mid + 1; |
| 475 | } else if (compare < 0) { |
| 476 | hi = mid - 1; |
| 477 | } else { |
| 478 | return &str_id; |
| 479 | } |
| 480 | } |
| 481 | return NULL; |
| 482 | } |
| 483 | |
| 484 | const DexFile::StringId* DexFile::FindStringId(const uint16_t* string) const { |
| 485 | int32_t lo = 0; |
| 486 | int32_t hi = NumStringIds() - 1; |
| 487 | while (hi >= lo) { |
| 488 | int32_t mid = (hi + lo) / 2; |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 489 | const DexFile::StringId& str_id = GetStringId(mid); |
Ian Rogers | cf5077a | 2013-10-31 12:37:54 -0700 | [diff] [blame] | 490 | const char* str = GetStringData(str_id); |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 491 | int compare = CompareModifiedUtf8ToUtf16AsCodePointValues(str, string); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 492 | if (compare > 0) { |
| 493 | lo = mid + 1; |
| 494 | } else if (compare < 0) { |
| 495 | hi = mid - 1; |
| 496 | } else { |
| 497 | return &str_id; |
| 498 | } |
| 499 | } |
| 500 | return NULL; |
| 501 | } |
| 502 | |
| 503 | const DexFile::TypeId* DexFile::FindTypeId(uint32_t string_idx) const { |
Ian Rogers | f8582c3 | 2013-05-29 16:33:03 -0700 | [diff] [blame] | 504 | int32_t lo = 0; |
| 505 | int32_t hi = NumTypeIds() - 1; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 506 | while (hi >= lo) { |
Ian Rogers | f8582c3 | 2013-05-29 16:33:03 -0700 | [diff] [blame] | 507 | int32_t mid = (hi + lo) / 2; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 508 | const TypeId& type_id = GetTypeId(mid); |
| 509 | if (string_idx > type_id.descriptor_idx_) { |
| 510 | lo = mid + 1; |
| 511 | } else if (string_idx < type_id.descriptor_idx_) { |
| 512 | hi = mid - 1; |
| 513 | } else { |
| 514 | return &type_id; |
| 515 | } |
| 516 | } |
| 517 | return NULL; |
| 518 | } |
| 519 | |
| 520 | const DexFile::ProtoId* DexFile::FindProtoId(uint16_t return_type_idx, |
Vladimir Marko | 5c96e6b | 2013-11-14 15:34:17 +0000 | [diff] [blame] | 521 | const uint16_t* signature_type_idxs, |
| 522 | uint32_t signature_length) const { |
Ian Rogers | f8582c3 | 2013-05-29 16:33:03 -0700 | [diff] [blame] | 523 | int32_t lo = 0; |
| 524 | int32_t hi = NumProtoIds() - 1; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 525 | while (hi >= lo) { |
Ian Rogers | f8582c3 | 2013-05-29 16:33:03 -0700 | [diff] [blame] | 526 | int32_t mid = (hi + lo) / 2; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 527 | const DexFile::ProtoId& proto = GetProtoId(mid); |
| 528 | int compare = return_type_idx - proto.return_type_idx_; |
| 529 | if (compare == 0) { |
| 530 | DexFileParameterIterator it(*this, proto); |
| 531 | size_t i = 0; |
Vladimir Marko | 5c96e6b | 2013-11-14 15:34:17 +0000 | [diff] [blame] | 532 | while (it.HasNext() && i < signature_length && compare == 0) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 533 | compare = signature_type_idxs[i] - it.GetTypeIdx(); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 534 | it.Next(); |
| 535 | i++; |
| 536 | } |
| 537 | if (compare == 0) { |
| 538 | if (it.HasNext()) { |
| 539 | compare = -1; |
Vladimir Marko | 5c96e6b | 2013-11-14 15:34:17 +0000 | [diff] [blame] | 540 | } else if (i < signature_length) { |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 541 | compare = 1; |
| 542 | } |
| 543 | } |
| 544 | } |
| 545 | if (compare > 0) { |
| 546 | lo = mid + 1; |
| 547 | } else if (compare < 0) { |
| 548 | hi = mid - 1; |
| 549 | } else { |
| 550 | return &proto; |
| 551 | } |
| 552 | } |
| 553 | return NULL; |
| 554 | } |
| 555 | |
| 556 | // Given a signature place the type ids into the given vector |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 557 | bool DexFile::CreateTypeList(const StringPiece& signature, uint16_t* return_type_idx, |
| 558 | std::vector<uint16_t>* param_type_idxs) const { |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 559 | if (signature[0] != '(') { |
| 560 | return false; |
| 561 | } |
| 562 | size_t offset = 1; |
| 563 | size_t end = signature.size(); |
| 564 | bool process_return = false; |
| 565 | while (offset < end) { |
Vladimir Marko | e9c36b3 | 2013-11-21 15:49:16 +0000 | [diff] [blame] | 566 | size_t start_offset = offset; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 567 | char c = signature[offset]; |
| 568 | offset++; |
| 569 | if (c == ')') { |
| 570 | process_return = true; |
| 571 | continue; |
| 572 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 573 | while (c == '[') { // process array prefix |
| 574 | if (offset >= end) { // expect some descriptor following [ |
| 575 | return false; |
| 576 | } |
| 577 | c = signature[offset]; |
| 578 | offset++; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 579 | } |
| 580 | if (c == 'L') { // process type descriptors |
| 581 | do { |
| 582 | if (offset >= end) { // unexpected early termination of descriptor |
| 583 | return false; |
| 584 | } |
| 585 | c = signature[offset]; |
| 586 | offset++; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 587 | } while (c != ';'); |
| 588 | } |
Vladimir Marko | e9c36b3 | 2013-11-21 15:49:16 +0000 | [diff] [blame] | 589 | // TODO: avoid creating a std::string just to get a 0-terminated char array |
| 590 | std::string descriptor(signature.data() + start_offset, offset - start_offset); |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 591 | const DexFile::StringId* string_id = FindStringId(descriptor.c_str()); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 592 | if (string_id == NULL) { |
| 593 | return false; |
| 594 | } |
| 595 | const DexFile::TypeId* type_id = FindTypeId(GetIndexForStringId(*string_id)); |
| 596 | if (type_id == NULL) { |
| 597 | return false; |
| 598 | } |
| 599 | uint16_t type_idx = GetIndexForTypeId(*type_id); |
| 600 | if (!process_return) { |
| 601 | param_type_idxs->push_back(type_idx); |
| 602 | } else { |
| 603 | *return_type_idx = type_idx; |
| 604 | return offset == end; // return true if the signature had reached a sensible end |
| 605 | } |
| 606 | } |
| 607 | return false; // failed to correctly parse return type |
| 608 | } |
| 609 | |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 610 | const Signature DexFile::CreateSignature(const StringPiece& signature) const { |
| 611 | uint16_t return_type_idx; |
| 612 | std::vector<uint16_t> param_type_indices; |
| 613 | bool success = CreateTypeList(signature, &return_type_idx, ¶m_type_indices); |
| 614 | if (!success) { |
| 615 | return Signature::NoSignature(); |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 616 | } |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 617 | const ProtoId* proto_id = FindProtoId(return_type_idx, param_type_indices); |
| 618 | if (proto_id == NULL) { |
| 619 | return Signature::NoSignature(); |
Brian Carlstrom | 20cfffa | 2011-08-26 02:31:27 -0700 | [diff] [blame] | 620 | } |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 621 | return Signature(this, *proto_id); |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 622 | } |
| 623 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 624 | int32_t DexFile::GetLineNumFromPC(mirror::ArtMethod* method, uint32_t rel_pc) const { |
Shih-wei Liao | ff0f9be | 2011-08-29 15:43:53 -0700 | [diff] [blame] | 625 | // For native method, lineno should be -2 to indicate it is native. Note that |
| 626 | // "line number == -2" is how libcore tells from StackTraceElement. |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 627 | if (method->GetCodeItemOffset() == 0) { |
Shih-wei Liao | ff0f9be | 2011-08-29 15:43:53 -0700 | [diff] [blame] | 628 | return -2; |
| 629 | } |
| 630 | |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 631 | const CodeItem* code_item = GetCodeItem(method->GetCodeItemOffset()); |
Elliott Hughes | caf7654 | 2012-06-28 16:08:22 -0700 | [diff] [blame] | 632 | DCHECK(code_item != NULL) << PrettyMethod(method) << " " << GetLocation(); |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 633 | |
| 634 | // A method with no line number info should return -1 |
| 635 | LineNumFromPcContext context(rel_pc, -1); |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 636 | DecodeDebugInfo(code_item, method->IsStatic(), method->GetDexMethodIndex(), LineNumForPcCb, |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 637 | NULL, &context); |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 638 | return context.line_num_; |
| 639 | } |
| 640 | |
Ian Rogers | dbbc99d | 2013-04-18 16:51:54 -0700 | [diff] [blame] | 641 | int32_t DexFile::FindTryItem(const CodeItem &code_item, uint32_t address) { |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 642 | // Note: Signed type is important for max and min. |
| 643 | int32_t min = 0; |
Ian Rogers | dbbc99d | 2013-04-18 16:51:54 -0700 | [diff] [blame] | 644 | int32_t max = code_item.tries_size_ - 1; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 645 | |
Ian Rogers | dbbc99d | 2013-04-18 16:51:54 -0700 | [diff] [blame] | 646 | while (min <= max) { |
| 647 | int32_t mid = min + ((max - min) / 2); |
| 648 | |
| 649 | const art::DexFile::TryItem* ti = GetTryItems(code_item, mid); |
| 650 | uint32_t start = ti->start_addr_; |
| 651 | uint32_t end = start + ti->insn_count_; |
| 652 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 653 | if (address < start) { |
| 654 | max = mid - 1; |
Ian Rogers | dbbc99d | 2013-04-18 16:51:54 -0700 | [diff] [blame] | 655 | } else if (address >= end) { |
| 656 | min = mid + 1; |
| 657 | } else { // We have a winner! |
| 658 | return mid; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 659 | } |
| 660 | } |
| 661 | // No match. |
| 662 | return -1; |
| 663 | } |
| 664 | |
Ian Rogers | dbbc99d | 2013-04-18 16:51:54 -0700 | [diff] [blame] | 665 | int32_t DexFile::FindCatchHandlerOffset(const CodeItem &code_item, uint32_t address) { |
| 666 | int32_t try_item = FindTryItem(code_item, address); |
| 667 | if (try_item == -1) { |
| 668 | return -1; |
| 669 | } else { |
| 670 | return DexFile::GetTryItems(code_item, try_item)->handler_off_; |
| 671 | } |
| 672 | } |
| 673 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 674 | void DexFile::DecodeDebugInfo0(const CodeItem* code_item, bool is_static, uint32_t method_idx, |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 675 | DexDebugNewPositionCb position_cb, DexDebugNewLocalCb local_cb, |
| 676 | void* context, const byte* stream, LocalInfo* local_in_reg) const { |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 677 | uint32_t line = DecodeUnsignedLeb128(&stream); |
| 678 | uint32_t parameters_size = DecodeUnsignedLeb128(&stream); |
| 679 | uint16_t arg_reg = code_item->registers_size_ - code_item->ins_size_; |
| 680 | uint32_t address = 0; |
Elliott Hughes | 3064683 | 2011-10-13 16:59:46 -0700 | [diff] [blame] | 681 | bool need_locals = (local_cb != NULL); |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 682 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 683 | if (!is_static) { |
Elliott Hughes | 3064683 | 2011-10-13 16:59:46 -0700 | [diff] [blame] | 684 | if (need_locals) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 685 | const char* descriptor = GetMethodDeclaringClassDescriptor(GetMethodId(method_idx)); |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 686 | local_in_reg[arg_reg].name_ = "this"; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 687 | local_in_reg[arg_reg].descriptor_ = descriptor; |
Elliott Hughes | 392b124 | 2011-11-30 13:55:50 -0800 | [diff] [blame] | 688 | local_in_reg[arg_reg].signature_ = NULL; |
Elliott Hughes | 3064683 | 2011-10-13 16:59:46 -0700 | [diff] [blame] | 689 | local_in_reg[arg_reg].start_address_ = 0; |
| 690 | local_in_reg[arg_reg].is_live_ = true; |
| 691 | } |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 692 | arg_reg++; |
| 693 | } |
| 694 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 695 | DexFileParameterIterator it(*this, GetMethodPrototype(GetMethodId(method_idx))); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 696 | for (uint32_t i = 0; i < parameters_size && it.HasNext(); ++i, it.Next()) { |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 697 | if (arg_reg >= code_item->registers_size_) { |
jeffhao | f872887 | 2011-10-28 19:11:13 -0700 | [diff] [blame] | 698 | LOG(ERROR) << "invalid stream - arg reg >= reg size (" << arg_reg |
Brian Carlstrom | 2aab947 | 2011-12-12 15:21:43 -0800 | [diff] [blame] | 699 | << " >= " << code_item->registers_size_ << ") in " << GetLocation(); |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 700 | return; |
| 701 | } |
Elliott Hughes | 392b124 | 2011-11-30 13:55:50 -0800 | [diff] [blame] | 702 | uint32_t id = DecodeUnsignedLeb128P1(&stream); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 703 | const char* descriptor = it.GetDescriptor(); |
Elliott Hughes | 392b124 | 2011-11-30 13:55:50 -0800 | [diff] [blame] | 704 | if (need_locals && id != kDexNoIndex) { |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 705 | const char* name = StringDataByIdx(id); |
Elliott Hughes | 3064683 | 2011-10-13 16:59:46 -0700 | [diff] [blame] | 706 | local_in_reg[arg_reg].name_ = name; |
| 707 | local_in_reg[arg_reg].descriptor_ = descriptor; |
Elliott Hughes | 392b124 | 2011-11-30 13:55:50 -0800 | [diff] [blame] | 708 | local_in_reg[arg_reg].signature_ = NULL; |
Elliott Hughes | 3064683 | 2011-10-13 16:59:46 -0700 | [diff] [blame] | 709 | local_in_reg[arg_reg].start_address_ = address; |
| 710 | local_in_reg[arg_reg].is_live_ = true; |
| 711 | } |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 712 | switch (*descriptor) { |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 713 | case 'D': |
| 714 | case 'J': |
| 715 | arg_reg += 2; |
| 716 | break; |
| 717 | default: |
| 718 | arg_reg += 1; |
| 719 | break; |
| 720 | } |
| 721 | } |
| 722 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 723 | if (it.HasNext()) { |
Brian Carlstrom | f79fccb | 2014-02-20 08:55:10 -0800 | [diff] [blame^] | 724 | LOG(ERROR) << "invalid stream - problem with parameter iterator in " << GetLocation() |
| 725 | << " for method " << PrettyMethod(method_idx, *this); |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 726 | return; |
| 727 | } |
| 728 | |
| 729 | for (;;) { |
| 730 | uint8_t opcode = *stream++; |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 731 | uint16_t reg; |
Jeff Hao | b7cefc7 | 2013-11-14 14:51:09 -0800 | [diff] [blame] | 732 | uint32_t name_idx; |
| 733 | uint32_t descriptor_idx; |
| 734 | uint32_t signature_idx = 0; |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 735 | |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 736 | switch (opcode) { |
| 737 | case DBG_END_SEQUENCE: |
| 738 | return; |
| 739 | |
| 740 | case DBG_ADVANCE_PC: |
| 741 | address += DecodeUnsignedLeb128(&stream); |
| 742 | break; |
| 743 | |
| 744 | case DBG_ADVANCE_LINE: |
Shih-wei Liao | 8a05d27 | 2011-10-15 18:45:43 -0700 | [diff] [blame] | 745 | line += DecodeSignedLeb128(&stream); |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 746 | break; |
| 747 | |
| 748 | case DBG_START_LOCAL: |
| 749 | case DBG_START_LOCAL_EXTENDED: |
| 750 | reg = DecodeUnsignedLeb128(&stream); |
| 751 | if (reg > code_item->registers_size_) { |
jeffhao | f872887 | 2011-10-28 19:11:13 -0700 | [diff] [blame] | 752 | LOG(ERROR) << "invalid stream - reg > reg size (" << reg << " > " |
Brian Carlstrom | 2aab947 | 2011-12-12 15:21:43 -0800 | [diff] [blame] | 753 | << code_item->registers_size_ << ") in " << GetLocation(); |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 754 | return; |
| 755 | } |
| 756 | |
jeffhao | f872887 | 2011-10-28 19:11:13 -0700 | [diff] [blame] | 757 | name_idx = DecodeUnsignedLeb128P1(&stream); |
| 758 | descriptor_idx = DecodeUnsignedLeb128P1(&stream); |
| 759 | if (opcode == DBG_START_LOCAL_EXTENDED) { |
| 760 | signature_idx = DecodeUnsignedLeb128P1(&stream); |
| 761 | } |
| 762 | |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 763 | // Emit what was previously there, if anything |
Elliott Hughes | 3064683 | 2011-10-13 16:59:46 -0700 | [diff] [blame] | 764 | if (need_locals) { |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 765 | InvokeLocalCbIfLive(context, reg, address, local_in_reg, local_cb); |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 766 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 767 | local_in_reg[reg].name_ = StringDataByIdx(name_idx); |
| 768 | local_in_reg[reg].descriptor_ = StringByTypeIdx(descriptor_idx); |
Elliott Hughes | 3064683 | 2011-10-13 16:59:46 -0700 | [diff] [blame] | 769 | if (opcode == DBG_START_LOCAL_EXTENDED) { |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 770 | local_in_reg[reg].signature_ = StringDataByIdx(signature_idx); |
Elliott Hughes | 3064683 | 2011-10-13 16:59:46 -0700 | [diff] [blame] | 771 | } |
| 772 | local_in_reg[reg].start_address_ = address; |
| 773 | local_in_reg[reg].is_live_ = true; |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 774 | } |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 775 | break; |
| 776 | |
| 777 | case DBG_END_LOCAL: |
| 778 | reg = DecodeUnsignedLeb128(&stream); |
| 779 | if (reg > code_item->registers_size_) { |
jeffhao | f872887 | 2011-10-28 19:11:13 -0700 | [diff] [blame] | 780 | LOG(ERROR) << "invalid stream - reg > reg size (" << reg << " > " |
Brian Carlstrom | 2aab947 | 2011-12-12 15:21:43 -0800 | [diff] [blame] | 781 | << code_item->registers_size_ << ") in " << GetLocation(); |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 782 | return; |
| 783 | } |
| 784 | |
Elliott Hughes | 3064683 | 2011-10-13 16:59:46 -0700 | [diff] [blame] | 785 | if (need_locals) { |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 786 | InvokeLocalCbIfLive(context, reg, address, local_in_reg, local_cb); |
Elliott Hughes | 3064683 | 2011-10-13 16:59:46 -0700 | [diff] [blame] | 787 | local_in_reg[reg].is_live_ = false; |
| 788 | } |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 789 | break; |
| 790 | |
| 791 | case DBG_RESTART_LOCAL: |
| 792 | reg = DecodeUnsignedLeb128(&stream); |
| 793 | if (reg > code_item->registers_size_) { |
jeffhao | f872887 | 2011-10-28 19:11:13 -0700 | [diff] [blame] | 794 | LOG(ERROR) << "invalid stream - reg > reg size (" << reg << " > " |
Brian Carlstrom | 2aab947 | 2011-12-12 15:21:43 -0800 | [diff] [blame] | 795 | << code_item->registers_size_ << ") in " << GetLocation(); |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 796 | return; |
| 797 | } |
| 798 | |
Elliott Hughes | 3064683 | 2011-10-13 16:59:46 -0700 | [diff] [blame] | 799 | if (need_locals) { |
| 800 | if (local_in_reg[reg].name_ == NULL || local_in_reg[reg].descriptor_ == NULL) { |
Brian Carlstrom | 2aab947 | 2011-12-12 15:21:43 -0800 | [diff] [blame] | 801 | LOG(ERROR) << "invalid stream - no name or descriptor in " << GetLocation(); |
Elliott Hughes | 3064683 | 2011-10-13 16:59:46 -0700 | [diff] [blame] | 802 | return; |
| 803 | } |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 804 | |
Elliott Hughes | 3064683 | 2011-10-13 16:59:46 -0700 | [diff] [blame] | 805 | // If the register is live, the "restart" is superfluous, |
| 806 | // and we don't want to mess with the existing start address. |
| 807 | if (!local_in_reg[reg].is_live_) { |
| 808 | local_in_reg[reg].start_address_ = address; |
| 809 | local_in_reg[reg].is_live_ = true; |
| 810 | } |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 811 | } |
| 812 | break; |
| 813 | |
| 814 | case DBG_SET_PROLOGUE_END: |
| 815 | case DBG_SET_EPILOGUE_BEGIN: |
| 816 | case DBG_SET_FILE: |
| 817 | break; |
| 818 | |
Shih-wei Liao | 8e1b4ff | 2011-10-15 15:43:51 -0700 | [diff] [blame] | 819 | default: { |
| 820 | int adjopcode = opcode - DBG_FIRST_SPECIAL; |
| 821 | |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 822 | address += adjopcode / DBG_LINE_RANGE; |
| 823 | line += DBG_LINE_BASE + (adjopcode % DBG_LINE_RANGE); |
| 824 | |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 825 | if (position_cb != NULL) { |
| 826 | if (position_cb(context, address, line)) { |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 827 | // early exit |
| 828 | return; |
| 829 | } |
| 830 | } |
| 831 | break; |
Shih-wei Liao | 8e1b4ff | 2011-10-15 15:43:51 -0700 | [diff] [blame] | 832 | } |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 833 | } |
| 834 | } |
| 835 | } |
| 836 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 837 | void DexFile::DecodeDebugInfo(const CodeItem* code_item, bool is_static, uint32_t method_idx, |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 838 | DexDebugNewPositionCb position_cb, DexDebugNewLocalCb local_cb, |
| 839 | void* context) const { |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 840 | const byte* stream = GetDebugInfoStream(code_item); |
Brian Carlstrom | e0948e1 | 2013-08-29 09:36:15 -0700 | [diff] [blame] | 841 | UniquePtr<LocalInfo[]> local_in_reg(local_cb != NULL ? |
| 842 | new LocalInfo[code_item->registers_size_] : |
| 843 | NULL); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 844 | if (stream != NULL) { |
Elliott Hughes | ee0fa76 | 2012-03-26 17:12:41 -0700 | [diff] [blame] | 845 | DecodeDebugInfo0(code_item, is_static, method_idx, position_cb, local_cb, context, stream, &local_in_reg[0]); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 846 | } |
| 847 | for (int reg = 0; reg < code_item->registers_size_; reg++) { |
Elliott Hughes | ee0fa76 | 2012-03-26 17:12:41 -0700 | [diff] [blame] | 848 | InvokeLocalCbIfLive(context, reg, code_item->insns_size_in_code_units_, &local_in_reg[0], local_cb); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 849 | } |
| 850 | } |
| 851 | |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 852 | bool DexFile::LineNumForPcCb(void* raw_context, uint32_t address, uint32_t line_num) { |
| 853 | LineNumFromPcContext* context = reinterpret_cast<LineNumFromPcContext*>(raw_context); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 854 | |
| 855 | // We know that this callback will be called in |
| 856 | // ascending address order, so keep going until we find |
| 857 | // a match or we've just gone past it. |
| 858 | if (address > context->address_) { |
| 859 | // The line number from the previous positions callback |
| 860 | // wil be the final result. |
| 861 | return true; |
| 862 | } else { |
| 863 | context->line_num_ = line_num; |
| 864 | return address == context->address_; |
| 865 | } |
| 866 | } |
| 867 | |
Brian Carlstrom | 0d6adac | 2014-02-05 17:39:16 -0800 | [diff] [blame] | 868 | std::ostream& operator<<(std::ostream& os, const DexFile& dex_file) { |
| 869 | os << StringPrintf("[DexFile: %s dex-checksum=%08x location-checksum=%08x %p-%p]", |
| 870 | dex_file.GetLocation().c_str(), |
| 871 | dex_file.GetHeader().checksum_, dex_file.GetLocationChecksum(), |
| 872 | dex_file.Begin(), dex_file.Begin() + dex_file.Size()); |
| 873 | return os; |
| 874 | } |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 875 | std::string Signature::ToString() const { |
| 876 | if (dex_file_ == nullptr) { |
| 877 | CHECK(proto_id_ == nullptr); |
| 878 | return "<no signature>"; |
| 879 | } |
| 880 | const DexFile::TypeList* params = dex_file_->GetProtoParameters(*proto_id_); |
| 881 | std::string result; |
| 882 | if (params == nullptr) { |
| 883 | result += "()"; |
| 884 | } else { |
| 885 | result += "("; |
| 886 | for (uint32_t i = 0; i < params->Size(); ++i) { |
| 887 | result += dex_file_->StringByTypeIdx(params->GetTypeItem(i).type_idx_); |
| 888 | } |
| 889 | result += ")"; |
| 890 | } |
| 891 | result += dex_file_->StringByTypeIdx(proto_id_->return_type_idx_); |
| 892 | return result; |
| 893 | } |
| 894 | |
Vladimir Marko | d9cffea | 2013-11-25 15:08:02 +0000 | [diff] [blame] | 895 | bool Signature::operator==(const StringPiece& rhs) const { |
| 896 | if (dex_file_ == nullptr) { |
| 897 | return false; |
| 898 | } |
| 899 | StringPiece tail(rhs); |
| 900 | if (!tail.starts_with("(")) { |
| 901 | return false; // Invalid signature |
| 902 | } |
| 903 | tail.remove_prefix(1); // "("; |
| 904 | const DexFile::TypeList* params = dex_file_->GetProtoParameters(*proto_id_); |
| 905 | if (params != nullptr) { |
| 906 | for (uint32_t i = 0; i < params->Size(); ++i) { |
| 907 | StringPiece param(dex_file_->StringByTypeIdx(params->GetTypeItem(i).type_idx_)); |
| 908 | if (!tail.starts_with(param)) { |
| 909 | return false; |
| 910 | } |
| 911 | tail.remove_prefix(param.length()); |
| 912 | } |
| 913 | } |
| 914 | if (!tail.starts_with(")")) { |
| 915 | return false; |
| 916 | } |
| 917 | tail.remove_prefix(1); // ")"; |
| 918 | return tail == dex_file_->StringByTypeIdx(proto_id_->return_type_idx_); |
| 919 | } |
| 920 | |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 921 | std::ostream& operator<<(std::ostream& os, const Signature& sig) { |
| 922 | return os << sig.ToString(); |
| 923 | } |
| 924 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 925 | // Decodes the header section from the class data bytes. |
| 926 | void ClassDataItemIterator::ReadClassDataHeader() { |
| 927 | CHECK(ptr_pos_ != NULL); |
| 928 | header_.static_fields_size_ = DecodeUnsignedLeb128(&ptr_pos_); |
| 929 | header_.instance_fields_size_ = DecodeUnsignedLeb128(&ptr_pos_); |
| 930 | header_.direct_methods_size_ = DecodeUnsignedLeb128(&ptr_pos_); |
| 931 | header_.virtual_methods_size_ = DecodeUnsignedLeb128(&ptr_pos_); |
| 932 | } |
| 933 | |
| 934 | void ClassDataItemIterator::ReadClassDataField() { |
| 935 | field_.field_idx_delta_ = DecodeUnsignedLeb128(&ptr_pos_); |
| 936 | field_.access_flags_ = DecodeUnsignedLeb128(&ptr_pos_); |
Brian Carlstrom | 68adbe4 | 2012-05-11 17:18:08 -0700 | [diff] [blame] | 937 | if (last_idx_ != 0 && field_.field_idx_delta_ == 0) { |
Brian Carlstrom | 6f29d0e | 2012-05-11 15:50:29 -0700 | [diff] [blame] | 938 | LOG(WARNING) << "Duplicate field " << PrettyField(GetMemberIndex(), dex_file_) |
| 939 | << " in " << dex_file_.GetLocation(); |
| 940 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | void ClassDataItemIterator::ReadClassDataMethod() { |
| 944 | method_.method_idx_delta_ = DecodeUnsignedLeb128(&ptr_pos_); |
| 945 | method_.access_flags_ = DecodeUnsignedLeb128(&ptr_pos_); |
| 946 | method_.code_off_ = DecodeUnsignedLeb128(&ptr_pos_); |
Brian Carlstrom | 68adbe4 | 2012-05-11 17:18:08 -0700 | [diff] [blame] | 947 | if (last_idx_ != 0 && method_.method_idx_delta_ == 0) { |
Brian Carlstrom | 6f29d0e | 2012-05-11 15:50:29 -0700 | [diff] [blame] | 948 | LOG(WARNING) << "Duplicate method " << PrettyMethod(GetMemberIndex(), dex_file_) |
| 949 | << " in " << dex_file_.GetLocation(); |
| 950 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | // Read a signed integer. "zwidth" is the zero-based byte count. |
| 954 | static int32_t ReadSignedInt(const byte* ptr, int zwidth) { |
| 955 | int32_t val = 0; |
| 956 | for (int i = zwidth; i >= 0; --i) { |
| 957 | val = ((uint32_t)val >> 8) | (((int32_t)*ptr++) << 24); |
| 958 | } |
| 959 | val >>= (3 - zwidth) * 8; |
| 960 | return val; |
| 961 | } |
| 962 | |
| 963 | // Read an unsigned integer. "zwidth" is the zero-based byte count, |
| 964 | // "fill_on_right" indicates which side we want to zero-fill from. |
| 965 | static uint32_t ReadUnsignedInt(const byte* ptr, int zwidth, bool fill_on_right) { |
| 966 | uint32_t val = 0; |
| 967 | if (!fill_on_right) { |
| 968 | for (int i = zwidth; i >= 0; --i) { |
| 969 | val = (val >> 8) | (((uint32_t)*ptr++) << 24); |
| 970 | } |
| 971 | val >>= (3 - zwidth) * 8; |
| 972 | } else { |
| 973 | for (int i = zwidth; i >= 0; --i) { |
| 974 | val = (val >> 8) | (((uint32_t)*ptr++) << 24); |
| 975 | } |
| 976 | } |
| 977 | return val; |
| 978 | } |
| 979 | |
| 980 | // Read a signed long. "zwidth" is the zero-based byte count. |
| 981 | static int64_t ReadSignedLong(const byte* ptr, int zwidth) { |
| 982 | int64_t val = 0; |
| 983 | for (int i = zwidth; i >= 0; --i) { |
| 984 | val = ((uint64_t)val >> 8) | (((int64_t)*ptr++) << 56); |
| 985 | } |
| 986 | val >>= (7 - zwidth) * 8; |
| 987 | return val; |
| 988 | } |
| 989 | |
| 990 | // Read an unsigned long. "zwidth" is the zero-based byte count, |
| 991 | // "fill_on_right" indicates which side we want to zero-fill from. |
| 992 | static uint64_t ReadUnsignedLong(const byte* ptr, int zwidth, bool fill_on_right) { |
| 993 | uint64_t val = 0; |
| 994 | if (!fill_on_right) { |
| 995 | for (int i = zwidth; i >= 0; --i) { |
| 996 | val = (val >> 8) | (((uint64_t)*ptr++) << 56); |
| 997 | } |
| 998 | val >>= (7 - zwidth) * 8; |
| 999 | } else { |
| 1000 | for (int i = zwidth; i >= 0; --i) { |
| 1001 | val = (val >> 8) | (((uint64_t)*ptr++) << 56); |
| 1002 | } |
| 1003 | } |
| 1004 | return val; |
| 1005 | } |
| 1006 | |
| 1007 | EncodedStaticFieldValueIterator::EncodedStaticFieldValueIterator(const DexFile& dex_file, |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1008 | SirtRef<mirror::DexCache>* dex_cache, |
| 1009 | SirtRef<mirror::ClassLoader>* class_loader, |
Ian Rogers | ca19066 | 2012-06-26 15:45:57 -0700 | [diff] [blame] | 1010 | ClassLinker* linker, |
| 1011 | const DexFile::ClassDef& class_def) |
Brian Carlstrom | 88f3654 | 2012-10-16 23:24:21 -0700 | [diff] [blame] | 1012 | : dex_file_(dex_file), dex_cache_(dex_cache), class_loader_(class_loader), linker_(linker), |
| 1013 | array_size_(), pos_(-1), type_(kByte) { |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1014 | DCHECK(dex_cache != nullptr); |
| 1015 | DCHECK(class_loader != nullptr); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1016 | ptr_ = dex_file.GetEncodedStaticFieldValuesArray(class_def); |
| 1017 | if (ptr_ == NULL) { |
| 1018 | array_size_ = 0; |
| 1019 | } else { |
| 1020 | array_size_ = DecodeUnsignedLeb128(&ptr_); |
| 1021 | } |
| 1022 | if (array_size_ > 0) { |
| 1023 | Next(); |
| 1024 | } |
| 1025 | } |
| 1026 | |
| 1027 | void EncodedStaticFieldValueIterator::Next() { |
| 1028 | pos_++; |
| 1029 | if (pos_ >= array_size_) { |
| 1030 | return; |
| 1031 | } |
| 1032 | byte value_type = *ptr_++; |
| 1033 | byte value_arg = value_type >> kEncodedValueArgShift; |
| 1034 | size_t width = value_arg + 1; // assume and correct later |
Brian Carlstrom | 88f3654 | 2012-10-16 23:24:21 -0700 | [diff] [blame] | 1035 | type_ = static_cast<ValueType>(value_type & kEncodedValueTypeMask); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1036 | switch (type_) { |
| 1037 | case kBoolean: |
| 1038 | jval_.i = (value_arg != 0) ? 1 : 0; |
| 1039 | width = 0; |
| 1040 | break; |
| 1041 | case kByte: |
| 1042 | jval_.i = ReadSignedInt(ptr_, value_arg); |
| 1043 | CHECK(IsInt(8, jval_.i)); |
| 1044 | break; |
| 1045 | case kShort: |
| 1046 | jval_.i = ReadSignedInt(ptr_, value_arg); |
| 1047 | CHECK(IsInt(16, jval_.i)); |
| 1048 | break; |
| 1049 | case kChar: |
| 1050 | jval_.i = ReadUnsignedInt(ptr_, value_arg, false); |
| 1051 | CHECK(IsUint(16, jval_.i)); |
| 1052 | break; |
| 1053 | case kInt: |
| 1054 | jval_.i = ReadSignedInt(ptr_, value_arg); |
| 1055 | break; |
| 1056 | case kLong: |
| 1057 | jval_.j = ReadSignedLong(ptr_, value_arg); |
| 1058 | break; |
| 1059 | case kFloat: |
| 1060 | jval_.i = ReadUnsignedInt(ptr_, value_arg, true); |
| 1061 | break; |
| 1062 | case kDouble: |
| 1063 | jval_.j = ReadUnsignedLong(ptr_, value_arg, true); |
| 1064 | break; |
| 1065 | case kString: |
| 1066 | case kType: |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1067 | jval_.i = ReadUnsignedInt(ptr_, value_arg, false); |
| 1068 | break; |
| 1069 | case kField: |
Brian Carlstrom | 88f3654 | 2012-10-16 23:24:21 -0700 | [diff] [blame] | 1070 | case kMethod: |
| 1071 | case kEnum: |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1072 | case kArray: |
| 1073 | case kAnnotation: |
| 1074 | UNIMPLEMENTED(FATAL) << ": type " << type_; |
| 1075 | break; |
| 1076 | case kNull: |
| 1077 | jval_.l = NULL; |
| 1078 | width = 0; |
| 1079 | break; |
| 1080 | default: |
| 1081 | LOG(FATAL) << "Unreached"; |
| 1082 | } |
| 1083 | ptr_ += width; |
| 1084 | } |
| 1085 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1086 | template<bool kTransactionActive> |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 1087 | void EncodedStaticFieldValueIterator::ReadValueToField(mirror::ArtField* field) const { |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1088 | switch (type_) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1089 | case kBoolean: field->SetBoolean<kTransactionActive>(field->GetDeclaringClass(), jval_.z); break; |
| 1090 | case kByte: field->SetByte<kTransactionActive>(field->GetDeclaringClass(), jval_.b); break; |
| 1091 | case kShort: field->SetShort<kTransactionActive>(field->GetDeclaringClass(), jval_.s); break; |
| 1092 | case kChar: field->SetChar<kTransactionActive>(field->GetDeclaringClass(), jval_.c); break; |
| 1093 | case kInt: field->SetInt<kTransactionActive>(field->GetDeclaringClass(), jval_.i); break; |
| 1094 | case kLong: field->SetLong<kTransactionActive>(field->GetDeclaringClass(), jval_.j); break; |
| 1095 | case kFloat: field->SetFloat<kTransactionActive>(field->GetDeclaringClass(), jval_.f); break; |
| 1096 | case kDouble: field->SetDouble<kTransactionActive>(field->GetDeclaringClass(), jval_.d); break; |
| 1097 | case kNull: field->SetObject<kTransactionActive>(field->GetDeclaringClass(), NULL); break; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1098 | case kString: { |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1099 | CHECK(!kMovingFields); |
| 1100 | mirror::String* resolved = linker_->ResolveString(dex_file_, jval_.i, *dex_cache_); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1101 | field->SetObject<kTransactionActive>(field->GetDeclaringClass(), resolved); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1102 | break; |
| 1103 | } |
Brian Carlstrom | 88f3654 | 2012-10-16 23:24:21 -0700 | [diff] [blame] | 1104 | case kType: { |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1105 | CHECK(!kMovingFields); |
| 1106 | mirror::Class* resolved = linker_->ResolveType(dex_file_, jval_.i, *dex_cache_, |
| 1107 | *class_loader_); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1108 | field->SetObject<kTransactionActive>(field->GetDeclaringClass(), resolved); |
Brian Carlstrom | 88f3654 | 2012-10-16 23:24:21 -0700 | [diff] [blame] | 1109 | break; |
| 1110 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1111 | default: UNIMPLEMENTED(FATAL) << ": type " << type_; |
| 1112 | } |
| 1113 | } |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1114 | template void EncodedStaticFieldValueIterator::ReadValueToField<true>(mirror::ArtField* field) const; |
| 1115 | template void EncodedStaticFieldValueIterator::ReadValueToField<false>(mirror::ArtField* field) const; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1116 | |
| 1117 | CatchHandlerIterator::CatchHandlerIterator(const DexFile::CodeItem& code_item, uint32_t address) { |
| 1118 | handler_.address_ = -1; |
| 1119 | int32_t offset = -1; |
| 1120 | |
| 1121 | // Short-circuit the overwhelmingly common cases. |
| 1122 | switch (code_item.tries_size_) { |
| 1123 | case 0: |
| 1124 | break; |
| 1125 | case 1: { |
| 1126 | const DexFile::TryItem* tries = DexFile::GetTryItems(code_item, 0); |
| 1127 | uint32_t start = tries->start_addr_; |
| 1128 | if (address >= start) { |
| 1129 | uint32_t end = start + tries->insn_count_; |
| 1130 | if (address < end) { |
| 1131 | offset = tries->handler_off_; |
| 1132 | } |
| 1133 | } |
| 1134 | break; |
| 1135 | } |
| 1136 | default: |
Ian Rogers | dbbc99d | 2013-04-18 16:51:54 -0700 | [diff] [blame] | 1137 | offset = DexFile::FindCatchHandlerOffset(code_item, address); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1138 | } |
Logan Chien | 736df02 | 2012-04-27 16:25:57 +0800 | [diff] [blame] | 1139 | Init(code_item, offset); |
| 1140 | } |
| 1141 | |
| 1142 | CatchHandlerIterator::CatchHandlerIterator(const DexFile::CodeItem& code_item, |
| 1143 | const DexFile::TryItem& try_item) { |
| 1144 | handler_.address_ = -1; |
| 1145 | Init(code_item, try_item.handler_off_); |
| 1146 | } |
| 1147 | |
| 1148 | void CatchHandlerIterator::Init(const DexFile::CodeItem& code_item, |
| 1149 | int32_t offset) { |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1150 | if (offset >= 0) { |
Logan Chien | 736df02 | 2012-04-27 16:25:57 +0800 | [diff] [blame] | 1151 | Init(DexFile::GetCatchHandlerData(code_item, offset)); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1152 | } else { |
| 1153 | // Not found, initialize as empty |
| 1154 | current_data_ = NULL; |
| 1155 | remaining_count_ = -1; |
| 1156 | catch_all_ = false; |
| 1157 | DCHECK(!HasNext()); |
| 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | void CatchHandlerIterator::Init(const byte* handler_data) { |
| 1162 | current_data_ = handler_data; |
| 1163 | remaining_count_ = DecodeSignedLeb128(¤t_data_); |
| 1164 | |
| 1165 | // If remaining_count_ is non-positive, then it is the negative of |
| 1166 | // the number of catch types, and the catches are followed by a |
| 1167 | // catch-all handler. |
| 1168 | if (remaining_count_ <= 0) { |
| 1169 | catch_all_ = true; |
| 1170 | remaining_count_ = -remaining_count_; |
| 1171 | } else { |
| 1172 | catch_all_ = false; |
| 1173 | } |
| 1174 | Next(); |
| 1175 | } |
| 1176 | |
| 1177 | void CatchHandlerIterator::Next() { |
| 1178 | if (remaining_count_ > 0) { |
| 1179 | handler_.type_idx_ = DecodeUnsignedLeb128(¤t_data_); |
| 1180 | handler_.address_ = DecodeUnsignedLeb128(¤t_data_); |
| 1181 | remaining_count_--; |
| 1182 | return; |
| 1183 | } |
| 1184 | |
| 1185 | if (catch_all_) { |
| 1186 | handler_.type_idx_ = DexFile::kDexNoIndex16; |
| 1187 | handler_.address_ = DecodeUnsignedLeb128(¤t_data_); |
| 1188 | catch_all_ = false; |
| 1189 | return; |
| 1190 | } |
| 1191 | |
| 1192 | // no more handler |
| 1193 | remaining_count_ = -1; |
| 1194 | } |
| 1195 | |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1196 | } // namespace art |