|
15 | 15 |
|
16 | 16 | using namespace xamarin::android::internal;
|
17 | 17 |
|
18 |
| -[[gnu::always_inline]] bool |
19 |
| -EmbeddedAssemblies::zip_load_entry_common (size_t entry_index, std::vector<uint8_t> const& buf, dynamic_local_string<SENSIBLE_PATH_MAX> &entry_name, ZipEntryLoadState &state) noexcept |
| 18 | +force_inline bool |
| 19 | +EmbeddedAssemblies::zip_load_entry_common (size_t entry_index, std::span<uint8_t> const& buf, dynamic_local_string<SENSIBLE_PATH_MAX> &entry_name, ZipEntryLoadState &state) noexcept |
20 | 20 | {
|
21 | 21 | entry_name.clear ();
|
22 | 22 |
|
@@ -150,8 +150,8 @@ EmbeddedAssemblies::store_individual_assembly_data (dynamic_local_string<SENSIBL
|
150 | 150 | have_and_want_debug_symbols = register_debug_symbols && bundled_debug_data != nullptr;
|
151 | 151 | }
|
152 | 152 |
|
153 |
| -[[gnu::always_inline]] void |
154 |
| -EmbeddedAssemblies::zip_load_individual_assembly_entries (std::vector<uint8_t> const& buf, uint32_t num_entries, [[maybe_unused]] monodroid_should_register should_register, ZipEntryLoadState &state) noexcept |
| 153 | +force_inline void |
| 154 | +EmbeddedAssemblies::zip_load_individual_assembly_entries (std::span<uint8_t> const& buf, uint32_t num_entries, [[maybe_unused]] monodroid_should_register should_register, ZipEntryLoadState &state) noexcept |
155 | 155 | {
|
156 | 156 | // TODO: do away with all the string manipulation here. Replace it with generating xxhash for the entry name
|
157 | 157 | dynamic_local_string<SENSIBLE_PATH_MAX> entry_name;
|
@@ -264,8 +264,8 @@ EmbeddedAssemblies::map_assembly_store (dynamic_local_string<SENSIBLE_PATH_MAX>
|
264 | 264 | verify_assembly_store_and_set_info (payload_start, entry_name.get ());
|
265 | 265 | }
|
266 | 266 |
|
267 |
| -[[gnu::always_inline]] void |
268 |
| -EmbeddedAssemblies::zip_load_assembly_store_entries (std::vector<uint8_t> const& buf, uint32_t num_entries, ZipEntryLoadState &state) noexcept |
| 267 | +force_inline void |
| 268 | +EmbeddedAssemblies::zip_load_assembly_store_entries (std::span<uint8_t> const& buf, uint32_t num_entries, ZipEntryLoadState &state) noexcept |
269 | 269 | {
|
270 | 270 | if (all_required_zip_entries_found ()) {
|
271 | 271 | return;
|
@@ -344,26 +344,28 @@ EmbeddedAssemblies::zip_load_entries (int fd, const char *apk_name, [[maybe_unus
|
344 | 344 | )
|
345 | 345 | );
|
346 | 346 | }
|
347 |
| -#ifdef DEBUG |
348 |
| - log_info (LOG_ASSEMBLY, "Central directory offset: {}", cd_offset); |
349 |
| - log_info (LOG_ASSEMBLY, "Central directory size: {}", cd_size); |
350 |
| - log_info (LOG_ASSEMBLY, "Central directory entries: {}", cd_entries); |
351 |
| -#endif |
352 |
| - off_t retval = ::lseek (fd, static_cast<off_t>(cd_offset), SEEK_SET); |
353 |
| - if (retval < 0) { |
354 |
| - Helpers::abort_application ( |
355 |
| - LOG_ASSEMBLY, |
356 |
| - std::format ( |
357 |
| - "Failed to seek to central directory position in APK: {}. retval={} errno={}, File={}", |
358 |
| - std::strerror (errno), |
359 |
| - retval, |
360 |
| - errno, |
361 |
| - optional_string (apk_name) |
362 |
| - ) |
363 |
| - ); |
364 |
| - } |
365 | 347 |
|
366 |
| - std::vector<uint8_t> buf (cd_size); |
| 348 | + md_mmap_info apk_map = md_mmap_apk_file (fd, cd_offset, cd_size, apk_name); |
| 349 | + |
| 350 | + log_debug (LOG_ASSEMBLY, "Central directory offset: %u", cd_offset); |
| 351 | + log_debug (LOG_ASSEMBLY, "Central directory size: %u", cd_size); |
| 352 | + log_debug (LOG_ASSEMBLY, "Central directory entries: %u", cd_entries); |
| 353 | + |
| 354 | + // off_t retval = ::lseek (fd, static_cast<off_t>(cd_offset), SEEK_SET); |
| 355 | + // if (retval < 0) { |
| 356 | + // Helpers::abort_application ( |
| 357 | + // LOG_ASSEMBLY, |
| 358 | + // Util::monodroid_strdup_printf ( |
| 359 | + // "Failed to seek to central directory position in APK: %s. retval=%d errno=%d, File=%s", |
| 360 | + // std::strerror (errno), |
| 361 | + // retval, |
| 362 | + // errno, |
| 363 | + // apk_name |
| 364 | + // ) |
| 365 | + // ); |
| 366 | + // } |
| 367 | + |
| 368 | + std::span<uint8_t> buf (reinterpret_cast<uint8_t*>(apk_map.area), apk_map.size); |
367 | 369 | const auto [prefix, prefix_len] = get_assemblies_prefix_and_length ();
|
368 | 370 | ZipEntryLoadState state {
|
369 | 371 | .file_fd = fd,
|
@@ -399,6 +401,8 @@ EmbeddedAssemblies::zip_load_entries (int fd, const char *apk_name, [[maybe_unus
|
399 | 401 | } else {
|
400 | 402 | zip_load_individual_assembly_entries (buf, cd_entries, should_register, state);
|
401 | 403 | }
|
| 404 | + |
| 405 | + // TODO: unmap here |
402 | 406 | }
|
403 | 407 |
|
404 | 408 | template<bool NeedsNameAlloc>
|
@@ -660,7 +664,7 @@ EmbeddedAssemblies::zip_read_field (T const& buf, size_t index, size_t count, dy
|
660 | 664 | }
|
661 | 665 |
|
662 | 666 | bool
|
663 |
| -EmbeddedAssemblies::zip_read_entry_info (std::vector<uint8_t> const& buf, dynamic_local_string<SENSIBLE_PATH_MAX>& file_name, ZipEntryLoadState &state) noexcept |
| 667 | +EmbeddedAssemblies::zip_read_entry_info (std::span<uint8_t> const& buf, dynamic_local_string<SENSIBLE_PATH_MAX>& file_name, ZipEntryLoadState &state) |
664 | 668 | {
|
665 | 669 | constexpr size_t CD_COMPRESSION_METHOD_OFFSET = 10uz;
|
666 | 670 | constexpr size_t CD_UNCOMPRESSED_SIZE_OFFSET = 24uz;
|
|
0 commit comments