Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLR hosting #9572

Draft
wants to merge 57 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
4c6b83d
Enable static linking with libc++
grendello Nov 26, 2024
e2f89a4
Remove C++ ABI compatibility sources
grendello Nov 26, 2024
e2ad767
Update apkdesc files
grendello Nov 26, 2024
33500bb
Playing around with some ideas
grendello Oct 31, 2024
95ecd76
More consistent use of std::string_view + remove unused code
grendello Nov 4, 2024
539b080
Making EmbeddedAssemblies a static type
grendello Nov 7, 2024
2aa6e2b
More cleanup
grendello Nov 13, 2024
07246e5
More move to static, more cleanup
grendello Nov 13, 2024
6649f01
MonodroidRuntime is static now
grendello Nov 13, 2024
51e007a
Buglets fixed
grendello Nov 14, 2024
497e094
Trying to find out why AppContext.GetData doesn't appear to work
grendello Nov 21, 2024
00d300f
Cleanup
grendello Nov 21, 2024
69a35ad
Lengths and offsets...
grendello Nov 25, 2024
01c77c0
Cleanup
grendello Nov 26, 2024
e0b1e57
Start using std::format and std::string_view string literals
grendello Nov 26, 2024
15ace79
A bit less of reinterpret_cast<>
grendello Nov 26, 2024
28c6439
Conversion to std::format continues
grendello Nov 27, 2024
98a4054
More std::format
grendello Nov 27, 2024
ac5c3ed
Friendlier, no need to use `std::format` directly in log_* anymore
grendello Nov 28, 2024
886ef40
Cleanup
grendello Nov 29, 2024
15d864f
Cleanup
grendello Nov 29, 2024
00f55b5
Update apkdesc files
grendello Nov 29, 2024
d383a44
std::format doesn't like null pointers when printing strings
grendello Nov 29, 2024
5a4d188
Address feedback
grendello Dec 3, 2024
18fd987
Enable static linking with libc++
grendello Nov 26, 2024
3f2b078
Remove C++ ABI compatibility sources
grendello Nov 26, 2024
541c402
Update apkdesc files
grendello Nov 26, 2024
cadc2b5
Playing around with some ideas
grendello Oct 31, 2024
0d4b21b
More consistent use of std::string_view + remove unused code
grendello Nov 4, 2024
7db3b37
Making EmbeddedAssemblies a static type
grendello Nov 7, 2024
a449f89
More cleanup
grendello Nov 13, 2024
b95077d
More move to static, more cleanup
grendello Nov 13, 2024
1d45842
MonodroidRuntime is static now
grendello Nov 13, 2024
7fb04ad
Buglets fixed
grendello Nov 14, 2024
430aea3
Trying to find out why AppContext.GetData doesn't appear to work
grendello Nov 21, 2024
5c728e7
Cleanup
grendello Nov 21, 2024
6e3b5e3
Lengths and offsets...
grendello Nov 25, 2024
6d88346
Cleanup
grendello Nov 26, 2024
ad67d54
Start using std::format and std::string_view string literals
grendello Nov 26, 2024
3bc283a
A bit less of reinterpret_cast<>
grendello Nov 26, 2024
bbbbb79
Conversion to std::format continues
grendello Nov 27, 2024
4e3fa71
More std::format
grendello Nov 27, 2024
96679f0
Friendlier, no need to use `std::format` directly in log_* anymore
grendello Nov 28, 2024
df0e22a
Cleanup
grendello Nov 29, 2024
4cb2c57
Cleanup
grendello Nov 29, 2024
41a3acf
Update apkdesc files
grendello Nov 29, 2024
c57ba46
std::format doesn't like null pointers when printing strings
grendello Nov 29, 2024
36a5945
Beginnings of CLR hosting
grendello Dec 2, 2024
8d3c5ba
Address feedback
grendello Dec 3, 2024
20fc6e7
First packaging steps + Java startup code changes
grendello Dec 3, 2024
d0faeb8
Build deps + application config for CLR
grendello Dec 3, 2024
555cd9c
Moving on: logging + timing
grendello Dec 4, 2024
77aa40a
Beginnings of initialization code
grendello Dec 4, 2024
6a5ce4c
Merge branch 'main' into dev/grendel/use-libc++
grendello Dec 5, 2024
5d96662
More environment work
grendello Dec 5, 2024
d8abae9
Merge branch 'main' into dev/grendel/clr-host
grendello Dec 5, 2024
bc699a5
Merge branch 'dev/grendel/use-libc++' into dev/grendel/clr-host
grendello Dec 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Start using std::format and std::string_view string literals
grendello committed Dec 4, 2024
commit ad67d5497810ef04205f5c69961b93227c9b2d17
130 changes: 77 additions & 53 deletions src/native/monodroid/embedded-assemblies-zip.cc

Large diffs are not rendered by default.

243 changes: 137 additions & 106 deletions src/native/monodroid/embedded-assemblies.cc

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions src/native/monodroid/embedded-assemblies.hh
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
#include <mono/metadata/mono-private-unstable.h>

#include "archive-dso-stub-config.hh"
#include "log_types.hh"
#include "strings.hh"
#include "xamarin-app.hh"
#include "cpp-util.hh"
@@ -309,7 +310,7 @@ namespace xamarin::android::internal {
elf_header->e_ident[EI_MAG1] != ELFMAG1 ||
elf_header->e_ident[EI_MAG2] != ELFMAG2 ||
elf_header->e_ident[EI_MAG3] != ELFMAG3) {
log_debug (LOG_ASSEMBLY, "Not an ELF image: %s", file_name);
log_debug (LOG_ASSEMBLY, std::format ("Not an ELF image: {}", file_name));
// Not an ELF image, just return what we mmapped before
return { map_info.area, map_info.size };
}
@@ -328,7 +329,7 @@ namespace xamarin::android::internal {
static void store_mapped_runtime_config_data (md_mmap_info const& map_info, const char *file_name) noexcept
{
auto [payload_start, payload_size] = get_wrapper_dso_payload_pointer_and_size (map_info, file_name);
log_debug (LOG_ASSEMBLY, "Runtime config: payload pointer %p ; size %zu", payload_start, payload_size);
log_debug (LOG_ASSEMBLY, std::format ("Runtime config: payload pointer {:p} ; size {}", payload_start, payload_size));
runtime_config_data = payload_start;
runtime_config_data_size = payload_size;
runtime_config_blob_found = true;
@@ -430,7 +431,7 @@ namespace xamarin::android::internal {
}
}
}
log_debug (LOG_ASSEMBLY, "Unmangled name to '%s'", name.get ());
log_debug (LOG_ASSEMBLY, std::format ("Unmangled name to '{}'", name.get ()));
};

private:
1 change: 0 additions & 1 deletion src/native/shared/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ set(LIB_ALIAS xa::shared)
set(XA_SHARED_SOURCES
helpers.cc
log_functions.cc
new_delete.cc
)
add_clang_check_sources("${XA_SHARED_SOURCES};")

25 changes: 25 additions & 0 deletions src/native/shared/helpers.hh
Original file line number Diff line number Diff line change
@@ -3,9 +3,14 @@

#include <cstdlib>
#include <source_location>
#include <string>
#include <string_view>

#include <java-interop-util.h>
#include "platform-compat.hh"
#include "log_types.hh"

using namespace std::string_view_literals;

namespace xamarin::android
{
@@ -46,10 +51,30 @@ namespace xamarin::android

[[noreturn]] static void abort_application (LogCategories category, const char *message, bool log_location = true, std::source_location sloc = std::source_location::current ()) noexcept;

[[noreturn]] static void abort_application (LogCategories category, std::string const& message, bool log_location = true, std::source_location sloc = std::source_location::current ()) noexcept
{
abort_application (category, message.c_str (), log_location, sloc);
}

[[noreturn]] static void abort_application (LogCategories category, std::string_view const& message, bool log_location = true, std::source_location sloc = std::source_location::current ()) noexcept
{
abort_application (category, message.data (), log_location, sloc);
}

[[noreturn]] static void abort_application (const char *message, bool log_location = true, std::source_location sloc = std::source_location::current ()) noexcept
{
abort_application (LOG_DEFAULT, message, log_location, sloc);
}

[[noreturn]] static void abort_application (std::string const& message, bool log_location = true, std::source_location sloc = std::source_location::current ()) noexcept
{
abort_application (LOG_DEFAULT, message.c_str (), log_location, sloc);
}

[[noreturn]] static void abort_application (std::string_view const& message, bool log_location = true, std::source_location sloc = std::source_location::current ()) noexcept
{
abort_application (LOG_DEFAULT, message.data (), log_location, sloc);
}
};
}
#endif // __HELPERS_HH
127 changes: 127 additions & 0 deletions src/native/shared/log_types.hh
Original file line number Diff line number Diff line change
@@ -2,10 +2,34 @@
#define LOG_LEVEL_HH

#include <cstdint>
#include <format>
#include <string>
#include <string_view>

#include "java-interop-logger.h"

// We redeclare macros as real functions here
#if defined(DO_LOG)
#undef DO_LOG
#endif

#if defined(log_debug)
#undef log_debug
#endif

#if defined(log_info)
#undef log_info
#endif

namespace xamarin::android {
namespace detail {
[[gnu::always_inline]]
static inline bool _category_is_enabled (LogCategories category) noexcept
{
return (log_categories & category) == category;
}
}

enum class LogTimingCategories : uint32_t
{
Default = 0,
@@ -30,6 +54,109 @@ namespace xamarin::android {
// A slightly faster alternative to other log functions as it doesn't parse the message
// for format placeholders nor it uses variable arguments
void log_write (LogCategories category, LogLevel level, const char *message) noexcept;

template<typename ...Args> [[gnu::always_inline]]
static inline constexpr void log_debug (LogCategories category, const char *format, Args&& ...args) noexcept
{
if (detail::_category_is_enabled (category)) {
::log_debug_nocheck (category, format, std::forward<Args>(args)...);
}
}

template<typename ...Args> [[gnu::always_inline]]
static inline constexpr void log_debug (LogCategories category, std::string_view const& format, Args&& ...args) noexcept
{
if (detail::_category_is_enabled (category)) {
::log_debug_nocheck (category, format.data (), std::forward<Args>(args)...);
}
}

static inline constexpr void log_debug (LogCategories category, std::string const& message) noexcept
{
if (detail::_category_is_enabled (category)) {
::log_debug_nocheck (category, message.c_str ());
}
}

//
// This will be enabled once all log_* calls are converted to std::format format
//
// template<typename ...Args> [[gnu::always_inline]]
// static inline constexpr void log_debug (LogCategories category, std::format_string<Args...> fmt, Args&& ...args)
// {
// if (detail::_category_is_enabled (category)) {

// log_debug_nocheck (category, std::format (fmt, std::forward<Args>(args)...).c_str ());
// }
// }

template<typename ...Args> [[gnu::always_inline]]
static inline constexpr void log_info (LogCategories category, const char *format, Args&& ...args) noexcept
{
if (detail::_category_is_enabled (category)) {
::log_info_nocheck (category, format, std::forward<Args>(args)...);
}
}

template<typename ...Args> [[gnu::always_inline]]
static inline constexpr void log_info (LogCategories category, std::string_view const& format, Args&& ...args) noexcept
{
if (detail::_category_is_enabled (category)) {
::log_info_nocheck (category, format.data (), std::forward<Args>(args)...);
}
}

[[gnu::always_inline]]
static inline constexpr void log_info (LogCategories category, std::string const& message) noexcept
{
if (detail::_category_is_enabled (category)) {
::log_info_nocheck (category, message.c_str ());
}
}

[[gnu::always_inline]]
static inline constexpr void log_info_nocheck (LogCategories category, std::string const& message) noexcept
{
if (detail::_category_is_enabled (category)) {
::log_info_nocheck (category, message.c_str ());
}
}

[[gnu::always_inline]]
static inline constexpr void log_warn (LogCategories category, std::string const& message) noexcept
{
::log_warn (category, message.c_str ());
}

[[gnu::always_inline]]
static inline constexpr void log_warn (LogCategories category, std::string_view const& message) noexcept
{
::log_warn (category, message.data ());
}

[[gnu::always_inline]]
static inline constexpr void log_error (LogCategories category, std::string const& message) noexcept
{
::log_error (category, message.c_str ());
}

[[gnu::always_inline]]
static inline constexpr void log_error (LogCategories category, std::string_view const& message) noexcept
{
::log_error (category, message.data ());
}

[[gnu::always_inline]]
static inline constexpr void log_fatal (LogCategories category, std::string const& message) noexcept
{
::log_fatal (category, message.c_str ());
}

[[gnu::always_inline]]
static inline constexpr void log_fatal (LogCategories category, std::string_view const& message) noexcept
{
::log_fatal (category, message.data ());
}
}
extern unsigned int log_categories;
#endif // ndef LOG_LEVEL_HH
87 changes: 0 additions & 87 deletions src/native/shared/new_delete.cc

This file was deleted.