Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[native] Better p/invoke handling when loading foreign libraries#10165

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@grendello
Copy link
Contributor

@grendellogrendello commentedJun 3, 2025
edited
Loading

Improve looking for "foreign" libraries when resolving a p/invoke symbol.

Foreign libraries are those which either aren't contained in the application APK
or which reside on the device in a system location. In such cases, we must attempt
to load the library using its name passed from the managed code (which uses the
DllImport attribute to name the library).

SinceDllImport doesn't usually use full name of the target library (e.g. instead
ofliblog.so it will use eitherliblog orlog), we must modify the library
name so that thedlopen(3) call can find it on the filesystem. We must make sure
that the library name follows thelibNAME.so convention before attempting to load
the library from filesystem..

This is an interim fix for us not finding e.g. theliblog.so library when the
[DllImport("liblog")] attribute is used in the managed code. The library resolution
and reloading system must be redesigned, which will happen in a separate PR as it is
currently not the highest priority task.

@grendellogrendello changed the titleDev/grendel/clr better pinvoke foreign libs[native] Better p/invoke handling when loading foreign librariesJun 3, 2025
@grendellogrendelloforce-pushed thedev/grendel/clr-better-pinvoke-foreign-libs branch fromd80648e to61b8ee2CompareJune 4, 2025 07:11
@grendellogrendelloforce-pushed thedev/grendel/clr-better-pinvoke-foreign-libs branch from61b8ee2 to2ef0038CompareJune 5, 2025 07:49
@grendellogrendello marked this pull request as ready for reviewJune 5, 2025 07:51
@grendellogrendello marked this pull request as draftJune 5, 2025 08:01
@grendellogrendello marked this pull request as ready for reviewJune 5, 2025 08:17
@grendellogrendello requested a review fromCopilotJune 5, 2025 09:32
Copy link

CopilotAI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Pull Request Overview

This PR improves the handling of foreign libraries loaded via p/invoke by ensuring that library names match the expected system naming conventions. Key changes include:

  • Adding an ends_with() utility function to check string suffixes in the runtime-base strings utilities.
  • Simplifying the library path resolution logic in AndroidSystem and updating DSO loading via a templated monodroid_dlopen.
  • Introducing a new constant DSO_PREFIX and a utility function to detect directory components in paths.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
FileDescription
src/native/common/include/runtime-base/strings.hhAdded an ends_with() helper for string suffix checking.
src/native/clr/runtime-base/android-system.ccRefactored library path resolution and suffix handling.
src/native/clr/include/runtime-base/util.hhAdded a utility to check for directory separators in paths.
src/native/clr/include/runtime-base/monodroid-dl.hhUpdated monodroid_dlopen to a templated version using a flag.
src/native/clr/include/host/pinvoke-override.hhAdjusted p/invoke override to use the new templated API.
src/native/clr/include/constants.hhIntroduced DSO_PREFIX for consistent library name handling.
Comments suppressed due to low confidence (1)

src/native/clr/include/runtime-base/monodroid-dl.hh:109

  • [nitpick] Consider adding a clarifying comment explaining the purpose and expected usage of the template parameter PREFER_AOT_CACHE to aid future maintainers in understanding this API change.
template<bool PREFER_AOT_CACHE> [[gnu::flatten]]

returnfalse;
}

returnmemcmp (buffer.get () + (length () - s.length ()), s.data (), s.length ()) ==0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Just for me to understand,length() is always inlined, so no problem with calling it multiple times in an expression?

[[gnu::always_inline]]
autolength ()constnoexcept -> size_t

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yeah, it's fully inlined each time it's called (which can also the be further optimized by common sub-expression elimination and other techniques, depending on context)

@grendellogrendello merged commit9f8e3d4 intomainJun 5, 2025
59 checks passed
@grendellogrendello deleted the dev/grendel/clr-better-pinvoke-foreign-libs branchJune 5, 2025 16:36
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsJul 6, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

Copilot code reviewCopilotCopilot left review comments

@jonathanpeppersjonathanpeppersjonathanpeppers approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@grendello@jonathanpeppers

[8]ページ先頭

©2009-2025 Movatter.jp