Class NativeLibrary

java.lang.Object
org.jetbrains.nativecerts.NativeLibrary

@Internal public final class NativeLibrary extends Object
A thin wrapper around SymbolLookup and Linker for a single native library.

Binding classes (SecurityFramework, CoreFoundationExt, Crypt32Ext, ...) create one MethodHandle per native function via downcall(String, FunctionDescriptor, Linker.Option...) and expose it as a typed static Java method named exactly like the native function, so that the code can be read side by side with Apple/Microsoft documentation.

  • Constructor Details

    • NativeLibrary

      public NativeLibrary(String path)
      Parameters:
      path - Absolute path of the library or framework binary. The library is loaded once and stays loaded for the lifetime of the JVM (Arena.global()).
  • Method Details

    • symbol

      public MemorySegment symbol(String name)
      Returns:
      Address of an exported symbol (a function or a global variable).
      Throws:
      UnsatisfiedLinkError - if the symbol is not exported by the library
    • pointerVariable

      public MemorySegment pointerVariable(String name)
      Reads the value of an exported pointer-sized global variable, e.g. kSecClass or kCFBooleanTrue. The symbol itself is the address of the variable; the variable holds the pointer we are interested in.
    • downcall

      public MethodHandle downcall(String name, FunctionDescriptor descriptor, Linker.Option... options)
      Creates a downcall handle for an exported function.
    • rethrow

      public static RuntimeException rethrow(String function, Throwable exception)
      Converts a Throwable thrown by MethodHandle.invokeExact(Object...) into an unchecked exception. Downcall handles do not throw checked exceptions in practice; this exists only to satisfy the compiler without hiding a real failure.