Skip to content

Commit c0111f3

Browse files
committed
Runtime config binary blob is now fully embedded
1 parent 08381cd commit c0111f3

File tree

5 files changed

+24
-15
lines changed

5 files changed

+24
-15
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ void ExecuteWithAbi (string [] supportedAbis, string apkInputPath, string apkOut
212212
apk.Flush ();
213213
}
214214

215-
AddRuntimeConfigBlob (apk);
215+
// AddRuntimeConfigBlob (apk);
216216
AddRuntimeLibraries (apk, supportedAbis);
217217
apk.Flush();
218218
AddNativeLibraries (files, supportedAbis);

src/Xamarin.Android.Build.Tasks/Utilities/ELFEmbeddingHelper.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,13 @@ static void DoEmbed (
144144
throw new NotSupportedException ($"Internal error: unsupported target arch '{arch}'");
145145
}
146146

147+
inputFile = Path.GetFullPath (inputFile);
148+
outputFile = Path.GetFullPath (outputFile);
149+
147150
var fi = new FileInfo (inputFile);
148151
long inputFileSize = fi.Length;
149152
string asmInputFile = Path.ChangeExtension (outputFile, ".s");
153+
string sanitizedInputFilePath = inputFile.Replace ("\\", "\\\\");
150154

151155
using var fs = File.Open (asmInputFile, FileMode.Create, FileAccess.Write, FileShare.Read);
152156
using var sw = new StreamWriter (fs, asmFileEncoding);
@@ -158,7 +162,7 @@ static void DoEmbed (
158162
sw.WriteLine ($".global {symbolName}");
159163
sw.WriteLine ($".type {symbolName},{cfg.AssemblerDirectivePrefix}object");
160164
sw.WriteLine ($"{symbolName}:");
161-
sw.WriteLine ($"\t.incbin \"{inputFile}\"");
165+
sw.WriteLine ($"\t.incbin \"{sanitizedInputFilePath}\"");
162166
sw.WriteLine ($"\t.size {symbolName}, {inputFileSize}");
163167
sw.WriteLine ();
164168

src/native/monodroid/embedded-assemblies-zip.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ EmbeddedAssemblies::zip_load_entry_common (size_t entry_index, std::vector<uint8
5151
}
5252
}
5353

54-
if (application_config.have_runtime_config_blob && !runtime_config_blob_found) {
55-
if (Util::ends_with (entry_name, SharedConstants::RUNTIME_CONFIG_BLOB_NAME)) {
56-
runtime_config_blob_mmap = md_mmap_apk_file (state.file_fd, state.data_offset, state.file_size, entry_name.get ());
57-
store_mapped_runtime_config_data (runtime_config_blob_mmap, entry_name.get ());
58-
return false;
59-
}
60-
}
54+
// if (application_config.have_runtime_config_blob && !runtime_config_blob_found) {
55+
// if (Util::ends_with (entry_name, SharedConstants::RUNTIME_CONFIG_BLOB_NAME)) {
56+
// runtime_config_blob_mmap = md_mmap_apk_file (state.file_fd, state.data_offset, state.file_size, entry_name.get ());
57+
// store_mapped_runtime_config_data (runtime_config_blob_mmap, entry_name.get ());
58+
// return false;
59+
// }
60+
// }
6161

6262
// assemblies must be 16-byte or 4-byte aligned, or Bad Things happen
6363
if (((state.data_offset & 0xf) != 0) || ((state.data_offset & 0x3) != 0)) {

src/native/monodroid/monodroid-glue.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -694,14 +694,17 @@ MonodroidRuntime::create_domain (JNIEnv *env, jstring_array_wrapper &runtimeApks
694694

695695
gather_bundled_assemblies (runtimeApks, &user_assemblies_count, have_split_apks);
696696

697-
if (embeddedAssemblies.have_runtime_config_blob ()) {
697+
// if (embeddedAssemblies.have_runtime_config_blob ()) {
698+
if (embedded_runtime_config_size > 0) {
698699
size_t blob_time_index;
699700
if (FastTiming::enabled ()) [[unlikely]] {
700701
blob_time_index = internal_timing->start_event (TimingEventKind::RuntimeConfigBlob);
701702
}
702703

703704
runtime_config_args.kind = 1;
704-
embeddedAssemblies.get_runtime_config_blob (runtime_config_args.runtimeconfig.data.data, runtime_config_args.runtimeconfig.data.data_len);
705+
// embeddedAssemblies.get_runtime_config_blob (runtime_config_args.runtimeconfig.data.data, runtime_config_args.runtimeconfig.data.data_len);
706+
runtime_config_args.runtimeconfig.data.data = reinterpret_cast<const char*>(embedded_runtime_config);
707+
runtime_config_args.runtimeconfig.data.data_len = static_cast<uint32_t>(embedded_runtime_config_size);
705708
monovm_runtimeconfig_initialize (&runtime_config_args, cleanup_runtime_config, nullptr);
706709

707710
if (FastTiming::enabled ()) [[unlikely]] {
@@ -1356,10 +1359,10 @@ MonodroidRuntime::Java_mono_android_Runtime_initInternal (JNIEnv *env, jclass kl
13561359

13571360
Logger::init_logging_categories (mono_log_mask_raw, mono_log_level_raw);
13581361

1359-
log_warn (LOG_DEFAULT, "Embedded runtime config size: %zu", embedded_runtime_config_size);
1360-
if (embedded_runtime_config_size > 0) {
1361-
log_warn (LOG_DEFAULT, "First byte of embedded runtime config: 0x%x", embedded_runtime_config[0]);
1362-
}
1362+
// log_warn (LOG_DEFAULT, "Embedded runtime config size: %zu", embedded_runtime_config_size);
1363+
// if (embedded_runtime_config_size > 0) {
1364+
// log_warn (LOG_DEFAULT, "First byte of embedded runtime config: 0x%x", embedded_runtime_config[0]);
1365+
// }
13631366

13641367
std::unique_ptr<char[]> mono_log_mask (mono_log_mask_raw);
13651368
std::unique_ptr<char[]> mono_log_level (mono_log_level_raw);

src/native/runtime-base/android-system.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,10 +741,12 @@ AndroidSystem::setup_apk_directories (unsigned short running_on_cpu, jstring_arr
741741

742742
if (have_split_apks) {
743743
if (Util::ends_with (apk, SharedConstants::split_config_abi_apk_name)) {
744+
log_warn (LOG_ASSEMBLY, "Here #1");
744745
add_apk_libdir (apk, number_of_added_directories, abi);
745746
break;
746747
}
747748
} else {
749+
log_warn (LOG_ASSEMBLY, "Here #2");
748750
add_apk_libdir (apk, number_of_added_directories, abi);
749751
}
750752
}

0 commit comments

Comments
 (0)