|
| 1 | +package org.cryptomator.jfuse.linux.aarch64; |
| 2 | + |
| 3 | +import org.cryptomator.jfuse.linux.aarch64.extr.fuse3.fuse_h; |
| 4 | + |
| 5 | +import java.lang.foreign.FunctionDescriptor; |
| 6 | +import java.lang.foreign.Linker; |
| 7 | +import java.lang.foreign.MemorySegment; |
| 8 | +import java.lang.foreign.SymbolLookup; |
| 9 | +import java.lang.invoke.MethodHandle; |
| 10 | + |
| 11 | +/** |
| 12 | + * Class for not jextract'able symbols, e.g. fuse_new_31 |
| 13 | + */ |
| 14 | +public class FuseFFIHelper { |
| 15 | + |
| 16 | + |
| 17 | + static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.loaderLookup() |
| 18 | + .or(Linker.nativeLinker().defaultLookup()); |
| 19 | + |
| 20 | + static MemorySegment findOrThrow(String symbol) { |
| 21 | + return SYMBOL_LOOKUP.find(symbol) |
| 22 | + .orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol: " + symbol)); |
| 23 | + } |
| 24 | + |
| 25 | + private static class fuse_new_31 { |
| 26 | + public static final FunctionDescriptor DESC = FunctionDescriptor.of( |
| 27 | + fuse_h.C_POINTER, |
| 28 | + fuse_h.C_POINTER, |
| 29 | + fuse_h.C_POINTER, |
| 30 | + fuse_h.C_LONG, |
| 31 | + fuse_h.C_POINTER |
| 32 | + ); |
| 33 | + |
| 34 | + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( |
| 35 | + findOrThrow("fuse_new_31"), |
| 36 | + DESC); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * Function descriptor for: |
| 41 | + * {@snippet lang = c: |
| 42 | + * struct fuse *fuse_new(struct fuse_args *args, const struct fuse_operations *op, size_t op_size, void *private_data) |
| 43 | + *} |
| 44 | + */ |
| 45 | + public static FunctionDescriptor fuse_new_31$descriptor() { |
| 46 | + return fuse_new_31.DESC; |
| 47 | + } |
| 48 | + |
| 49 | + |
| 50 | + /** |
| 51 | + * Downcall method handle for: |
| 52 | + * {@snippet lang = c: |
| 53 | + * struct fuse *fuse_new(struct fuse_args *args, const struct fuse_operations *op, size_t op_size, void *private_data) |
| 54 | + *} |
| 55 | + */ |
| 56 | + public static MethodHandle fuse_new_31$handle() { |
| 57 | + return fuse_new_31.HANDLE; |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * {@snippet lang = c: |
| 62 | + * struct fuse *fuse_new(struct fuse_args *args, const struct fuse_operations *op, size_t op_size, void *private_data) |
| 63 | + *} |
| 64 | + */ |
| 65 | + public static MemorySegment fuse_new_31(MemorySegment args, MemorySegment op, long op_size, MemorySegment private_data) { |
| 66 | + var mh$ = fuse_new_31.HANDLE; |
| 67 | + try { |
| 68 | + return (MemorySegment) mh$.invokeExact(args, op, op_size, private_data); |
| 69 | + } catch (Throwable ex$) { |
| 70 | + throw new AssertionError("should not reach here", ex$); |
| 71 | + } |
| 72 | + } |
| 73 | +} |
0 commit comments