-
-
Notifications
You must be signed in to change notification settings - Fork 5
[WiP] Load versioned symbols from libfuse.so #117
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
Open
overheadhunter
wants to merge
15
commits into
develop
Choose a base branch
from
feature/linux-fuse-dlvsym
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
85b296c
Fixes for libfuse v3.12
SailReal cf0c1f8
Merge branch 'develop' into feature/linux-fuse-dlvsym
overheadhunter 93724ec
Merge branch 'develop' into feature/linux-fuse-dlvsym
overheadhunter 53b7bc6
avoid NPE if libraryPath is not set
overheadhunter 0b492a7
Merge branch 'develop' into feature/linux-fuse-dlvsym
overheadhunter ef28e02
try linking to `fuse_new@FUSE_3.0`
overheadhunter 5edb152
try to find error on aarch64
overheadhunter 5767b96
Revert "try to find error on aarch64"
overheadhunter a6a9286
use correct `fuse.lib.path`
overheadhunter 060e593
fix UnsatisfiedLinkError: forgot to dlopen lib
overheadhunter cdde9a7
cleanup
overheadhunter b3f1c85
try to remove `dlopen` already loaded lib
overheadhunter 5b82c40
fix workflow file
overheadhunter d1b5791
fix type
overheadhunter c6606cb
Revert "try to remove `dlopen` already loaded lib"
overheadhunter 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
95 changes: 95 additions & 0 deletions
95
jfuse-linux-aarch64/src/main/java/org/cryptomator/jfuse/linux/aarch64/FuseSymbolLookup.java
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,95 @@ | ||
| package org.cryptomator.jfuse.linux.aarch64; | ||
|
|
||
| import java.lang.foreign.Arena; | ||
| import java.lang.foreign.FunctionDescriptor; | ||
| import java.lang.foreign.Linker; | ||
| import java.lang.foreign.MemorySegment; | ||
| import java.lang.foreign.SymbolLookup; | ||
| import java.lang.invoke.MethodHandle; | ||
| import java.util.Optional; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
|
|
||
| import static java.lang.foreign.ValueLayout.ADDRESS; | ||
| import static java.lang.foreign.ValueLayout.JAVA_INT; | ||
|
|
||
| public class FuseSymbolLookup implements SymbolLookup { | ||
|
|
||
| private static final int RTLD_NOW = 0x02; | ||
|
|
||
| // https://man7.org/linux/man-pages/man3/dlopen.3.html | ||
| private static final FunctionDescriptor DLOPEN = FunctionDescriptor.of(ADDRESS, ADDRESS, JAVA_INT); | ||
| private static final FunctionDescriptor DLERROR = FunctionDescriptor.of(ADDRESS); | ||
|
|
||
| // https://man7.org/linux/man-pages/man3/dlvsym.3.html | ||
| private static final FunctionDescriptor DLVSYM = FunctionDescriptor.of(ADDRESS, ADDRESS, ADDRESS, ADDRESS); | ||
| private static final FunctionDescriptor DLSYM = FunctionDescriptor.of(ADDRESS, ADDRESS, ADDRESS); | ||
|
|
||
| private final MethodHandle dlopen; | ||
| private final MethodHandle dlerror; | ||
| private final MethodHandle dlvsym; | ||
| private final MethodHandle dlsym; | ||
| private final AtomicReference<MemorySegment> libHandle = new AtomicReference<>(); | ||
|
|
||
| private FuseSymbolLookup() { | ||
| var linker = Linker.nativeLinker(); | ||
| var defaultLookup = linker.defaultLookup(); | ||
| this.dlopen = linker.downcallHandle(defaultLookup.find("dlopen").orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol dlopen")), DLOPEN); | ||
| this.dlerror = linker.downcallHandle(defaultLookup.find("dlerror").orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol dlerror")), DLERROR); | ||
| this.dlvsym = linker.downcallHandle(defaultLookup.find("dlvsym").orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol dlvsym")), DLVSYM); | ||
| this.dlsym = linker.downcallHandle(defaultLookup.find("dlsym").orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol dlsym")), DLSYM); | ||
| } | ||
|
|
||
| public static FuseSymbolLookup getInstance() { | ||
| return Holder.INSTANCE; | ||
| } | ||
|
|
||
| private static class Holder { | ||
| private static final FuseSymbolLookup INSTANCE = new FuseSymbolLookup(); | ||
| } | ||
|
|
||
| public void open(String libPath) { | ||
| try (var session = Arena.ofConfined()) { | ||
| MemorySegment handle = (MemorySegment) dlopen.invokeExact(session.allocateFrom(libPath), RTLD_NOW); | ||
| libHandle.set(handle); | ||
| } catch (Throwable e) { | ||
| throw new AssertionError(e); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| * | ||
| * @param nameAndVersion the symbol name and version separated by '@'. | ||
| */ | ||
| @Override | ||
| public Optional<MemorySegment> find(String nameAndVersion) { | ||
| var handle = libHandle.get(); | ||
| if (handle == null) { | ||
| return Optional.empty(); | ||
| } | ||
| var sep = nameAndVersion.indexOf('@'); | ||
| try (var session = Arena.ofConfined()) { | ||
| MemorySegment addr = MemorySegment.NULL; | ||
| if (sep != -1) { | ||
| String name = nameAndVersion.substring(0, sep); | ||
| String version = nameAndVersion.substring(sep + 1); | ||
| addr = (MemorySegment) dlvsym.invokeExact(handle, session.allocateFrom(name), session.allocateFrom(version)); | ||
| } | ||
|
|
||
| if (MemorySegment.NULL.equals(addr)) { | ||
| addr = (MemorySegment) dlsym.invokeExact(handle, session.allocateFrom(nameAndVersion)); | ||
| } | ||
|
|
||
| if (MemorySegment.NULL.equals(addr)) { | ||
| var error = (MemorySegment) dlerror.invokeExact(); | ||
| System.err.println("dlvsym failed for symbol " + nameAndVersion + ": " + error.getString(0)); | ||
| return Optional.empty(); | ||
| } else { | ||
| return Optional.of(addr); | ||
| } | ||
| } catch (Throwable e) { | ||
| return Optional.empty(); | ||
| } | ||
| } | ||
|
|
||
| } | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider adding dlclose functionality or clarifying lifecycle.
Opening the library without closing may lead to resource leaks over long uptimes. If you expect to reload or unload the library at any point, implementing a matching dlclose call or clarifying that this process is intentionally omitted would be beneficial.