-
Notifications
You must be signed in to change notification settings - Fork 546
[CoreCLR] Support for fastdev assemblies #10113
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
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
4e32f8f
Changes from https://github.com/dotnet/android/pull/10065
grendello 39931bc
WIP
grendello 12e6277
Fix after rebase
grendello 8156edb
Use string blobs to decrease number of relocations
grendello 2510637
Optimize debug maps a bit
grendello ed0dbbc
Implement fallback matching when hash clashes are detected
grendello b9d04d1
java-to-managed map should be fully functional now
grendello 4fa897c
A handful of tweaks for the Debug build
grendello 57d0b80
Cleanup
grendello 2f74c7a
Add on-device test for string-based typemaps
grendello e943a4f
Fix after rebase
grendello 626796f
Fix nullable issues after rebase on `main`
grendello 6406817
This test requires more changes in the runtime, will be enabled in an…
grendello cf50b0d
Test the debug typemaps
grendello a99cb00
Implement support for fastdev assemblies
grendello b6cfb67
Update src/Xamarin.Android.Build.Tasks/Utilities/LlvmIrGenerator/Llvm…
grendello a728f2b
Be more generic (even though it looks fugly)
grendello bb7b04b
A handful of cosmetic changes
grendello 37ed99f
Use better looking code
grendello a8e6925
Drop the `typemap_` prefix
grendello c096b28
Fix after rebase
grendello aec4156
Cleanup
grendello e5a13a3
Cleanup
grendello 29bef2d
Fix after rebase
grendello File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#include <sys/types.h> | ||
#include <dirent.h> | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
|
||
#include <cerrno> | ||
#include <cstring> | ||
#include <limits> | ||
|
||
#include <constants.hh> | ||
#include <host/fastdev-assemblies.hh> | ||
#include <runtime-base/android-system.hh> | ||
#include <runtime-base/util.hh> | ||
|
||
using namespace xamarin::android; | ||
|
||
auto FastDevAssemblies::open_assembly (std::string_view const& name, int64_t &size) noexcept -> void* | ||
{ | ||
size = 0; | ||
|
||
std::string const& override_dir_path = AndroidSystem::get_primary_override_dir (); | ||
if (!Util::dir_exists (override_dir_path)) [[unlikely]] { | ||
log_debug (LOG_ASSEMBLY, "Override directory '{}' does not exist", override_dir_path); | ||
return nullptr; | ||
} | ||
|
||
// NOTE: override_dir will be kept open, we have no way of knowing when it will be no longer | ||
// needed | ||
if (override_dir_fd < 0) [[unlikely]] { | ||
std::lock_guard dir_lock { override_dir_lock }; | ||
if (override_dir_fd < 0) [[likely]] { | ||
override_dir = opendir (override_dir_path.c_str ()); | ||
if (override_dir == nullptr) [[unlikely]] { | ||
log_warn (LOG_ASSEMBLY, "Failed to open override dir '{}'. {}", override_dir_path, strerror (errno)); | ||
return nullptr; | ||
} | ||
override_dir_fd = dirfd (override_dir); | ||
} | ||
} | ||
|
||
log_debug ( | ||
LOG_ASSEMBLY, | ||
"Attempting to load FastDev assembly '{}' from override directory '{}'", | ||
name, | ||
override_dir_path | ||
); | ||
|
||
if (!Util::file_exists (override_dir_fd, name)) { | ||
log_warn (LOG_ASSEMBLY, "FastDev assembly '{}' not found.", name); | ||
return nullptr; | ||
} | ||
log_debug (LOG_ASSEMBLY, "Found FastDev assembly '{}'", name); | ||
|
||
auto file_size = Util::get_file_size_at (override_dir_fd, name); | ||
if (!file_size) [[unlikely]] { | ||
log_warn (LOG_ASSEMBLY, "Unable to determine FastDev assembly '{}' file size", name); | ||
return nullptr; | ||
} | ||
|
||
constexpr size_t MAX_SIZE = std::numeric_limits<std::remove_reference_t<decltype(size)>>::max (); | ||
if (file_size.value () > MAX_SIZE) [[unlikely]] { | ||
Helpers::abort_application ( | ||
LOG_ASSEMBLY, | ||
std::format ( | ||
"FastDev assembly '{}' size exceeds the maximum supported value of {}", | ||
name, | ||
MAX_SIZE | ||
) | ||
); | ||
} | ||
|
||
size = static_cast<int64_t>(file_size.value ()); | ||
int asm_fd = openat (override_dir_fd, name.data (), O_RDONLY); | ||
if (asm_fd < 0) { | ||
log_warn ( | ||
LOG_ASSEMBLY, | ||
"Failed to open FastDev assembly '{}' for reading. {}", | ||
name, | ||
strerror (errno) | ||
); | ||
|
||
size = 0; | ||
return nullptr; | ||
} | ||
|
||
// TODO: consider who owns the pointer - we allocate the data, but we have no way of knowing when | ||
// the allocated space is no longer (if ever) needed by CoreCLR. Probably would be best if | ||
// CoreCLR notified us when it wants to free the data, as that eliminates any races as well | ||
// as ambiguity. | ||
auto buffer = new uint8_t[file_size.value ()]; | ||
ssize_t nread = 0; | ||
do { | ||
nread = read (asm_fd, reinterpret_cast<void*>(buffer), file_size.value ()); | ||
} while (nread == -1 && errno == EINTR); | ||
close (asm_fd); | ||
|
||
if (nread != size) [[unlikely]] { | ||
delete[] buffer; | ||
|
||
log_warn ( | ||
LOG_ASSEMBLY, | ||
"Failed to read FastDev assembly '{}' data. {}", | ||
name, | ||
strerror (errno) | ||
); | ||
|
||
size = 0; | ||
return nullptr; | ||
} | ||
log_debug (LOG_ASSEMBLY, "Read {} bytes of FastDev assembly '{}'", nread, name); | ||
|
||
return reinterpret_cast<void*>(buffer); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include <dirent.h> | ||
|
||
#include <cstdint> | ||
#include <mutex> | ||
#include <string_view> | ||
|
||
namespace xamarin::android { | ||
class FastDevAssemblies | ||
{ | ||
public: | ||
#if defined(DEBUG) | ||
static auto open_assembly (std::string_view const& name, int64_t &size) noexcept -> void*; | ||
#else | ||
static auto open_assembly ([[maybe_unused]] std::string_view const& name, [[maybe_unused]] int64_t &size) noexcept -> void* | ||
{ | ||
return nullptr; | ||
} | ||
#endif | ||
|
||
private: | ||
#if defined(DEBUG) | ||
static inline DIR *override_dir = nullptr; | ||
static inline int override_dir_fd = -1; | ||
static inline std::mutex override_dir_lock {}; | ||
#endif | ||
}; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.