< prev index next >

src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/SystemLookup.java

Print this page
*** 23,12 ***
   * questions.
   */
  
  package jdk.internal.foreign;
  
- import jdk.incubator.foreign.MemoryAccess;
  import jdk.incubator.foreign.MemorySegment;
  import jdk.incubator.foreign.ResourceScope;
  import jdk.incubator.foreign.SymbolLookup;
  import jdk.incubator.foreign.MemoryAddress;
  import jdk.internal.loader.NativeLibraries;
  import jdk.internal.loader.NativeLibrary;
--- 23,12 ---
   * questions.
   */
  
  package jdk.internal.foreign;
  
  import jdk.incubator.foreign.MemorySegment;
+ import jdk.incubator.foreign.NativeSymbol;
  import jdk.incubator.foreign.ResourceScope;
  import jdk.incubator.foreign.SymbolLookup;
  import jdk.incubator.foreign.MemoryAddress;
  import jdk.internal.loader.NativeLibraries;
  import jdk.internal.loader.NativeLibrary;

*** 37,11 ***
  import java.nio.file.Path;
  import java.util.Objects;
  import java.util.Optional;
  import java.util.function.Function;
  
! import static jdk.incubator.foreign.CLinker.C_POINTER;
  
  public class SystemLookup implements SymbolLookup {
  
      private SystemLookup() { }
  
--- 37,11 ---
  import java.nio.file.Path;
  import java.util.Objects;
  import java.util.Optional;
  import java.util.function.Function;
  
! import static jdk.incubator.foreign.ValueLayout.ADDRESS;
  
  public class SystemLookup implements SymbolLookup {
  
      private SystemLookup() { }
  

*** 69,15 ***
              // use a fallback lookup to look up inline functions from fallback lib
  
              SymbolLookup fallbackLibLookup = libLookup(libs -> libs.loadLibrary("WinFallbackLookup"));
  
              int numSymbols = WindowsFallbackSymbols.values().length;
!             MemorySegment funcs = fallbackLibLookup.lookup("funcs").orElseThrow()
!                 .asSegment(C_POINTER.byteSize() * numSymbols, ResourceScope.newImplicitScope());
  
              SymbolLookup fallbackLookup = name -> Optional.ofNullable(WindowsFallbackSymbols.valueOfOrNull(name))
!                 .map(symbol -> MemoryAccess.getAddressAtIndex(funcs, symbol.ordinal()));
  
              final SymbolLookup finalLookup = lookup;
              lookup = name -> finalLookup.lookup(name).or(() -> fallbackLookup.lookup(name));
          }
  
--- 69,15 ---
              // use a fallback lookup to look up inline functions from fallback lib
  
              SymbolLookup fallbackLibLookup = libLookup(libs -> libs.loadLibrary("WinFallbackLookup"));
  
              int numSymbols = WindowsFallbackSymbols.values().length;
!             MemorySegment funcs = MemorySegment.ofAddressNative(fallbackLibLookup.lookup("funcs").orElseThrow().address(),
!                 ADDRESS.byteSize() * numSymbols, ResourceScope.globalScope());
  
              SymbolLookup fallbackLookup = name -> Optional.ofNullable(WindowsFallbackSymbols.valueOfOrNull(name))
!                 .map(symbol -> NativeSymbol.ofAddress(symbol.name(), funcs.getAtIndex(ADDRESS, symbol.ordinal()), ResourceScope.globalScope()));
  
              final SymbolLookup finalLookup = lookup;
              lookup = name -> finalLookup.lookup(name).or(() -> fallbackLookup.lookup(name));
          }
  

*** 89,19 ***
          return name -> {
              Objects.requireNonNull(name);
              try {
                  long addr = lib.lookup(name);
                  return addr == 0 ?
!                         Optional.empty() : Optional.of(MemoryAddress.ofLong(addr));
              } catch (NoSuchMethodException e) {
                  return Optional.empty();
              }
          };
      }
  
      @Override
!     public Optional<MemoryAddress> lookup(String name) {
          return syslookup.lookup(name);
      }
  
      public static SystemLookup getInstance() {
          return INSTANCE;
--- 89,20 ---
          return name -> {
              Objects.requireNonNull(name);
              try {
                  long addr = lib.lookup(name);
                  return addr == 0 ?
!                         Optional.empty() :
+                         Optional.of(NativeSymbol.ofAddress(name, MemoryAddress.ofLong(addr), ResourceScope.globalScope()));
              } catch (NoSuchMethodException e) {
                  return Optional.empty();
              }
          };
      }
  
      @Override
!     public Optional<NativeSymbol> lookup(String name) {
          return syslookup.lookup(name);
      }
  
      public static SystemLookup getInstance() {
          return INSTANCE;
< prev index next >