Skip to content

Commit

Permalink
A handful of bugfixes and performance tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
grendello committed Oct 10, 2024
1 parent c854efa commit 40a46b6
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public class GeneratePackageManagerJava : AndroidTask
[Required]
public string AndroidBinUtilsDirectory { get; set; }

[Required]
public bool AssemblyStoreEmbeddedInRuntime { get; set; }

[Output]
public ITaskItem[] EmbeddedObjectFiles { get; set; }

Expand Down Expand Up @@ -366,6 +369,7 @@ void AddEnvironment ()
JniRemappingReplacementMethodIndexEntryCount = jniRemappingNativeCodeInfo == null ? 0 : jniRemappingNativeCodeInfo.ReplacementMethodIndexEntryCount,
MarshalMethodsEnabled = EnableMarshalMethods,
IgnoreSplitConfigs = ShouldIgnoreSplitConfigs (),
AssemblyStoreEmbeddedInRuntime = UseAssemblyStore && AssemblyStoreEmbeddedInRuntime,
};
LLVMIR.LlvmIrModule appConfigModule = appConfigAsmGen.Construct ();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ sealed class XamarinAndroidBundledAssembly
public List<ITaskItem> NativeLibraries { get; set; }
public bool MarshalMethodsEnabled { get; set; }
public bool IgnoreSplitConfigs { get; set; }
public bool AssemblyStoreEmbeddedInRuntime { get; set; }

public ApplicationConfigNativeAssemblyGenerator (IDictionary<string, string> environmentVariables, IDictionary<string, string> systemProperties, TaskLoggingHelper log)
: base (log)
Expand Down Expand Up @@ -294,6 +295,24 @@ protected override void Construct (LlvmIrModule module)
module.Add (bundled_assemblies);

AddAssemblyStores (module);

if (AssemblyStoreEmbeddedInRuntime) {
return;
}

// Need these to keep ABI compatibility with `libxamarin-app.so` used at the runtime's build time
var embedded_assembly_store_size = new LlvmIrGlobalVariable (
(ulong)0,
"embedded_assembly_store_size",
LlvmIrVariableOptions.GlobalConstant
);
module.Add (embedded_assembly_store_size);

var embedded_assembly_store = new LlvmIrGlobalVariable (typeof (byte[]), "embedded_assembly_store", LlvmIrVariableOptions.GlobalWritable) {
ZeroInitializeArray = true,
ArrayItemCount = 0,
};
module.Add (embedded_assembly_store);
}

void AddAssemblyStores (LlvmIrModule module)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
<_AndroidUseMarshalMethods Condition=" '$(AndroidIncludeDebugSymbols)' == 'True' ">False</_AndroidUseMarshalMethods>
<_AndroidUseMarshalMethods Condition=" '$(AndroidIncludeDebugSymbols)' != 'True' ">$(AndroidEnableMarshalMethods)</_AndroidUseMarshalMethods>
<_AndroidEmbedAssemblyStoreInRuntime Condition=" '$(AndroidUseAssemblyStore)' == 'True' And '$(_AndroidEmbedAssemblyStoreInRuntime)' == '' ">True</_AndroidEmbedAssemblyStoreInRuntime>
<_AndroidEmbedAssemblyStoreInRuntime Condition="'$(_AndroidEmbedAssemblyStoreInRuntime)' == '' ">False</_AndroidEmbedAssemblyStoreInRuntime>
</PropertyGroup>

<!-- Do not resolve from the GAC under any circumstances in Mobile -->
Expand Down Expand Up @@ -1749,6 +1750,7 @@ because xbuild doesn't support framework reference assemblies.
EnableMarshalMethods="$(_AndroidUseMarshalMethods)"
CustomBundleConfigFile="$(AndroidBundleConfigurationFile)"
AndroidBinUtilsDirectory="$(AndroidBinUtilsDirectory)"
AssemblyStoreEmbeddedInRuntime="$(_AndroidEmbedAssemblyStoreInRuntime)"
>
<Output TaskParameter="EmbeddedObjectFiles" ItemName="_NativeAssemblyTarget" />
</GeneratePackageManagerJava>
Expand Down
2 changes: 1 addition & 1 deletion src/native/monodroid/monodroid-glue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ MonodroidRuntime::set_profile_options ()
.append (OUTPUT_ARG)
.append (output_path.get (), output_path.length ());
}
if (Util::create_directory (AndroidSystem::override_dirs[0], 0) < 0) {
if (Util::create_directory (AndroidSystem::override_dirs[0], 0777, 000) < 0) {
log_warn (LOG_DEFAULT, "Failed to create directory '%s'. %s", AndroidSystem::override_dirs[0], std::strerror (errno));
}

Expand Down
18 changes: 3 additions & 15 deletions src/native/runtime-base/android-system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,26 +262,14 @@ AndroidSystem::monodroid_get_system_property_from_overrides ([[maybe_unused]] co
return 0;
}

// TODO: review this. Do we really have to create the dir in release?
void
AndroidSystem::create_update_dir (char *override_dir) noexcept
{
#if defined (RELEASE)
/*
* Don't create .__override__ on Release builds, because Google requires
* that pre-loaded apps not create world-writable directories.
*
* However, if any logging is enabled (which should _not_ happen with
* pre-loaded apps!), we need the .__override__ directory...
*/
if (log_categories == 0 && monodroid_get_system_property (SharedConstants::DEBUG_MONO_PROFILE_PROPERTY, nullptr) == 0) {
return;
}
#endif // def RELEASE

override_dirs [0] = override_dir;
#if defined(DEBUG)
log_debug (LOG_DEFAULT, "Creating public update directory: `%s`", override_dir);
Util::create_public_directory (override_dir);
log_warn (LOG_DEFAULT, "Creating public update directory: `%s`", override_dir);
#endif
}

bool
Expand Down
2 changes: 0 additions & 2 deletions src/native/runtime-base/timing-internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ FastTiming::really_initialize (bool log_immediately) noexcept
if (immediate_logging) {
return;
}

log_write (LOG_TIMING, LogLevel::Info, "[2/1] To get timing results, send the mono.android.app.DUMP_TIMING_DATA intent to the application");
}

void
Expand Down
10 changes: 4 additions & 6 deletions src/native/runtime-base/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,14 @@ Util::path_combine (const char *path1, const char *path2)
void
Util::create_public_directory (const char *dir)
{
mode_t m = umask (0);
int ret = mkdir (dir, 0777);
int ret = create_directory (dir, 0777, 0);
if (ret < 0) {
log_warn (LOG_DEFAULT, "Failed to create directory '%s'. %s", dir, std::strerror (errno));
log_warn (LOG_DEFAULT, "Failed to create public directory '%s'. %s", dir, std::strerror (errno));
}
umask (m);
}

int
Util::create_directory (const char *pathname, mode_t mode)
Util::create_directory (const char *pathname, mode_t mode, mode_t mask)
{
if (mode <= 0)
mode = DEFAULT_DIRECTORY_MODE;
Expand All @@ -156,7 +154,7 @@ Util::create_directory (const char *pathname, mode_t mode)
errno = EINVAL;
return -1;
}
mode_t oldumask = umask (022);
mode_t oldumask = umask (mask);
std::unique_ptr<char> path {strdup_new (pathname)};
int rv, ret = 0;
for (char *d = path.get (); d != nullptr && *d; ++d) {
Expand Down
2 changes: 1 addition & 1 deletion src/native/runtime-base/util.hh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace xamarin::android
static char *monodroid_strdup_vprintf (const char *format, va_list vargs);
static char* path_combine (const char *path1, const char *path2);
static void create_public_directory (const char *dir);
static int create_directory (const char *pathname, mode_t mode);
static int create_directory (const char *pathname, mode_t mode, mode_t mask = 022);
static void set_world_accessable (const char *path);
static void set_user_executable (const char *path);
static bool file_exists (const char *file);
Expand Down

0 comments on commit 40a46b6

Please sign in to comment.