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