Skip to content

Commit 955170e

Browse files
committed
A handful of bugfixes and performance tweaks
1 parent f8461e6 commit 955170e

File tree

7 files changed

+35
-22
lines changed

7 files changed

+35
-22
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public override bool RunTask ()
6565
[Required]
6666
public string AndroidBinUtilsDirectory { get; set; }
6767

68+
[Required]
69+
public bool AssemblyStoreEmbeddedInRuntime { get; set; }
70+
6871
[Output]
6972
public ITaskItem[] EmbeddedObjectFiles { get; set; }
7073

@@ -331,6 +334,7 @@ void AddEnvironment ()
331334
JniRemappingReplacementMethodIndexEntryCount = jniRemappingNativeCodeInfo == null ? 0 : jniRemappingNativeCodeInfo.ReplacementMethodIndexEntryCount,
332335
MarshalMethodsEnabled = EnableMarshalMethods,
333336
IgnoreSplitConfigs = ShouldIgnoreSplitConfigs (),
337+
AssemblyStoreEmbeddedInRuntime = UseAssemblyStore && AssemblyStoreEmbeddedInRuntime,
334338
};
335339
LLVMIR.LlvmIrModule appConfigModule = appConfigAsmGen.Construct ();
336340

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ sealed class XamarinAndroidBundledAssembly
197197
public bool MarshalMethodsEnabled { get; set; }
198198
public bool ManagedMarshalMethodsLookupEnabled { get; set; }
199199
public bool IgnoreSplitConfigs { get; set; }
200+
public bool AssemblyStoreEmbeddedInRuntime { get; set; }
200201

201202
public ApplicationConfigNativeAssemblyGenerator (IDictionary<string, string> environmentVariables, IDictionary<string, string> systemProperties, TaskLoggingHelper log)
202203
: base (log)
@@ -306,6 +307,24 @@ protected override void Construct (LlvmIrModule module)
306307
module.Add (bundled_assemblies);
307308

308309
AddAssemblyStores (module);
310+
311+
if (AssemblyStoreEmbeddedInRuntime) {
312+
return;
313+
}
314+
315+
// Need these to keep ABI compatibility with `libxamarin-app.so` used at the runtime's build time
316+
var embedded_assembly_store_size = new LlvmIrGlobalVariable (
317+
(ulong)0,
318+
"embedded_assembly_store_size",
319+
LlvmIrVariableOptions.GlobalConstant
320+
);
321+
module.Add (embedded_assembly_store_size);
322+
323+
var embedded_assembly_store = new LlvmIrGlobalVariable (typeof (byte[]), "embedded_assembly_store", LlvmIrVariableOptions.GlobalWritable) {
324+
ZeroInitializeArray = true,
325+
ArrayItemCount = 0,
326+
};
327+
module.Add (embedded_assembly_store);
309328
}
310329

311330
void AddAssemblyStores (LlvmIrModule module)

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
361361
<_AndroidUseMarshalMethods Condition=" '$(AndroidIncludeDebugSymbols)' == 'True' ">False</_AndroidUseMarshalMethods>
362362
<_AndroidUseMarshalMethods Condition=" '$(AndroidIncludeDebugSymbols)' != 'True' ">$(AndroidEnableMarshalMethods)</_AndroidUseMarshalMethods>
363363
<_AndroidEmbedAssemblyStoreInRuntime Condition=" '$(AndroidUseAssemblyStore)' == 'True' And '$(_AndroidEmbedAssemblyStoreInRuntime)' == '' ">True</_AndroidEmbedAssemblyStoreInRuntime>
364+
<_AndroidEmbedAssemblyStoreInRuntime Condition="'$(_AndroidEmbedAssemblyStoreInRuntime)' == '' ">False</_AndroidEmbedAssemblyStoreInRuntime>
364365
</PropertyGroup>
365366

366367
<!-- Do not resolve from the GAC under any circumstances in Mobile -->
@@ -1906,6 +1907,7 @@ because xbuild doesn't support framework reference assemblies.
19061907
EnableMarshalMethods="$(_AndroidUseMarshalMethods)"
19071908
CustomBundleConfigFile="$(AndroidBundleConfigurationFile)"
19081909
AndroidBinUtilsDirectory="$(AndroidBinUtilsDirectory)"
1910+
AssemblyStoreEmbeddedInRuntime="$(_AndroidEmbedAssemblyStoreInRuntime)"
19091911
>
19101912
<Output TaskParameter="EmbeddedObjectFiles" ItemName="_NativeAssemblyTarget" />
19111913
</GeneratePackageManagerJava>

src/native/mono/monodroid/monodroid-glue.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,8 +1159,8 @@ MonodroidRuntime::set_profile_options () noexcept
11591159
.append (OUTPUT_ARG)
11601160
.append (output_path.get (), output_path.length ());
11611161
}
1162-
if (Util::create_directory (AndroidSystem::override_dirs[0], 0) < 0) {
1163-
log_warn (LOG_DEFAULT, "Failed to create directory '{}'. {}", optional_string (AndroidSystem::override_dirs[0]), std::strerror (errno));
1162+
if (Util::create_directory (AndroidSystem::override_dirs[0], 0777, 000) < 0) {
1163+
log_warn (LOG_DEFAULT, "Failed to create directory '%s'. %s", AndroidSystem::override_dirs[0], std::strerror (errno));
11641164
}
11651165

11661166
log_warn (LOG_DEFAULT, "Initializing profiler with options: {}", optional_string (value.get ()));

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -262,26 +262,14 @@ AndroidSystem::monodroid_get_system_property_from_overrides ([[maybe_unused]] co
262262
return 0;
263263
}
264264

265-
// TODO: review this. Do we really have to create the dir in release?
266265
void
267266
AndroidSystem::create_update_dir (char *override_dir) noexcept
268267
{
269-
#if defined (RELEASE)
270-
/*
271-
* Don't create .__override__ on Release builds, because Google requires
272-
* that pre-loaded apps not create world-writable directories.
273-
*
274-
* However, if any logging is enabled (which should _not_ happen with
275-
* pre-loaded apps!), we need the .__override__ directory...
276-
*/
277-
if (log_categories == 0 && monodroid_get_system_property (SharedConstants::DEBUG_MONO_PROFILE_PROPERTY, nullptr) == 0) {
278-
return;
279-
}
280-
#endif // def RELEASE
281-
282268
override_dirs [0] = override_dir;
269+
#if defined(DEBUG)
270+
log_debug (LOG_DEFAULT, "Creating public update directory: `%s`", override_dir);
283271
Util::create_public_directory (override_dir);
284-
log_warn (LOG_DEFAULT, "Creating public update directory: `{}`", override_dir);
272+
#endif
285273
}
286274

287275
bool

src/native/mono/runtime-base/util.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,14 @@ Util::path_combine (const char *path1, const char *path2)
147147
void
148148
Util::create_public_directory (const char *dir)
149149
{
150-
int ret = create_directory (dir, 0777);
150+
int ret = create_directory (dir, 0777, 0);
151151
if (ret < 0) {
152-
log_warn (LOG_DEFAULT, "Failed to create directory '{}'. {}", dir, std::strerror (errno));
152+
log_warn (LOG_DEFAULT, "Failed to create public directory '%s'. %s", dir, std::strerror (errno));
153153
}
154154
}
155155

156156
int
157-
Util::create_directory (const char *pathname, mode_t mode)
157+
Util::create_directory (const char *pathname, mode_t mode, mode_t mask)
158158
{
159159
if (mode <= 0)
160160
mode = DEFAULT_DIRECTORY_MODE;
@@ -163,7 +163,7 @@ Util::create_directory (const char *pathname, mode_t mode)
163163
errno = EINVAL;
164164
return -1;
165165
}
166-
mode_t oldumask = umask (022);
166+
mode_t oldumask = umask (mask);
167167
std::unique_ptr<char> path {strdup_new (pathname)};
168168
int rv, ret = 0;
169169
for (char *d = path.get (); d != nullptr && *d; ++d) {

src/native/mono/runtime-base/util.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ namespace xamarin::android
6969
static char *monodroid_strdup_vprintf (const char *format, va_list vargs);
7070
static char* path_combine (const char *path1, const char *path2);
7171
static void create_public_directory (const char *dir);
72-
static int create_directory (const char *pathname, mode_t mode);
72+
static int create_directory (const char *pathname, mode_t mode, mode_t mask = 022);
7373
static void set_world_accessable (const char *path);
7474
static auto set_world_accessible (int fd) noexcept -> bool;
7575
static void set_user_executable (const char *path);

0 commit comments

Comments
 (0)