|
15 | 15 | using namespace xamarin::android::internal;
|
16 | 16 |
|
17 | 17 | force_inline bool
|
18 |
| -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 | +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 |
19 | 19 | {
|
20 | 20 | entry_name.clear ();
|
21 | 21 |
|
@@ -141,7 +141,7 @@ EmbeddedAssemblies::store_individual_assembly_data (dynamic_local_string<SENSIBL
|
141 | 141 | }
|
142 | 142 |
|
143 | 143 | force_inline void
|
144 |
| -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 |
| 144 | +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 |
145 | 145 | {
|
146 | 146 | // TODO: do away with all the string manipulation here. Replace it with generating xxhash for the entry name
|
147 | 147 | dynamic_local_string<SENSIBLE_PATH_MAX> entry_name;
|
@@ -255,7 +255,7 @@ EmbeddedAssemblies::map_assembly_store (dynamic_local_string<SENSIBLE_PATH_MAX>
|
255 | 255 | }
|
256 | 256 |
|
257 | 257 | force_inline void
|
258 |
| -EmbeddedAssemblies::zip_load_assembly_store_entries (std::vector<uint8_t> const& buf, uint32_t num_entries, ZipEntryLoadState &state) noexcept |
| 258 | +EmbeddedAssemblies::zip_load_assembly_store_entries (std::span<uint8_t> const& buf, uint32_t num_entries, ZipEntryLoadState &state) noexcept |
259 | 259 | {
|
260 | 260 | if (all_required_zip_entries_found ()) {
|
261 | 261 | return;
|
@@ -326,26 +326,28 @@ EmbeddedAssemblies::zip_load_entries (int fd, const char *apk_name, [[maybe_unus
|
326 | 326 | )
|
327 | 327 | );
|
328 | 328 | }
|
329 |
| -#ifdef DEBUG |
330 |
| - log_info (LOG_ASSEMBLY, "Central directory offset: %u", cd_offset); |
331 |
| - log_info (LOG_ASSEMBLY, "Central directory size: %u", cd_size); |
332 |
| - log_info (LOG_ASSEMBLY, "Central directory entries: %u", cd_entries); |
333 |
| -#endif |
334 |
| - off_t retval = ::lseek (fd, static_cast<off_t>(cd_offset), SEEK_SET); |
335 |
| - if (retval < 0) { |
336 |
| - Helpers::abort_application ( |
337 |
| - LOG_ASSEMBLY, |
338 |
| - Util::monodroid_strdup_printf ( |
339 |
| - "Failed to seek to central directory position in APK: %s. retval=%d errno=%d, File=%s", |
340 |
| - std::strerror (errno), |
341 |
| - retval, |
342 |
| - errno, |
343 |
| - apk_name |
344 |
| - ) |
345 |
| - ); |
346 |
| - } |
347 | 329 |
|
348 |
| - std::vector<uint8_t> buf (cd_size); |
| 330 | + md_mmap_info apk_map = md_mmap_apk_file (fd, cd_offset, cd_size, apk_name); |
| 331 | + |
| 332 | + log_debug (LOG_ASSEMBLY, "Central directory offset: %u", cd_offset); |
| 333 | + log_debug (LOG_ASSEMBLY, "Central directory size: %u", cd_size); |
| 334 | + log_debug (LOG_ASSEMBLY, "Central directory entries: %u", cd_entries); |
| 335 | + |
| 336 | + // off_t retval = ::lseek (fd, static_cast<off_t>(cd_offset), SEEK_SET); |
| 337 | + // if (retval < 0) { |
| 338 | + // Helpers::abort_application ( |
| 339 | + // LOG_ASSEMBLY, |
| 340 | + // Util::monodroid_strdup_printf ( |
| 341 | + // "Failed to seek to central directory position in APK: %s. retval=%d errno=%d, File=%s", |
| 342 | + // std::strerror (errno), |
| 343 | + // retval, |
| 344 | + // errno, |
| 345 | + // apk_name |
| 346 | + // ) |
| 347 | + // ); |
| 348 | + // } |
| 349 | + |
| 350 | + std::span<uint8_t> buf (reinterpret_cast<uint8_t*>(apk_map.area), apk_map.size); |
349 | 351 | const auto [prefix, prefix_len] = get_assemblies_prefix_and_length ();
|
350 | 352 | ZipEntryLoadState state {
|
351 | 353 | .file_fd = fd,
|
@@ -381,6 +383,8 @@ EmbeddedAssemblies::zip_load_entries (int fd, const char *apk_name, [[maybe_unus
|
381 | 383 | } else {
|
382 | 384 | zip_load_individual_assembly_entries (buf, cd_entries, should_register, state);
|
383 | 385 | }
|
| 386 | + |
| 387 | + // TODO: unmap here |
384 | 388 | }
|
385 | 389 |
|
386 | 390 | template<bool NeedsNameAlloc>
|
@@ -636,7 +640,7 @@ EmbeddedAssemblies::zip_read_field (T const& buf, size_t index, size_t count, dy
|
636 | 640 | }
|
637 | 641 |
|
638 | 642 | bool
|
639 |
| -EmbeddedAssemblies::zip_read_entry_info (std::vector<uint8_t> const& buf, dynamic_local_string<SENSIBLE_PATH_MAX>& file_name, ZipEntryLoadState &state) |
| 643 | +EmbeddedAssemblies::zip_read_entry_info (std::span<uint8_t> const& buf, dynamic_local_string<SENSIBLE_PATH_MAX>& file_name, ZipEntryLoadState &state) |
640 | 644 | {
|
641 | 645 | constexpr size_t CD_COMPRESSION_METHOD_OFFSET = 10uz;
|
642 | 646 | constexpr size_t CD_UNCOMPRESSED_SIZE_OFFSET = 24uz;
|
|
0 commit comments