< prev index next >

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

Print this page
@@ -23,12 +23,12 @@
   * questions.
   */
  
  package jdk.internal.foreign;
  
- import jdk.incubator.foreign.MemoryAccess;
  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 +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;
+ import static jdk.incubator.foreign.ValueLayout.ADDRESS;
  
  public class SystemLookup implements SymbolLookup {
  
      private SystemLookup() { }
  

@@ -69,15 +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());
+             MemorySegment funcs = MemorySegment.ofAddressNative(fallbackLibLookup.lookup("funcs").orElseThrow().address(),
+                 ADDRESS.byteSize() * numSymbols, ResourceScope.globalScope());
  
              SymbolLookup fallbackLookup = name -> Optional.ofNullable(WindowsFallbackSymbols.valueOfOrNull(name))
-                 .map(symbol -> MemoryAccess.getAddressAtIndex(funcs, symbol.ordinal()));
+                 .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 +89,20 @@
          return name -> {
              Objects.requireNonNull(name);
              try {
                  long addr = lib.lookup(name);
                  return addr == 0 ?
-                         Optional.empty() : Optional.of(MemoryAddress.ofLong(addr));
+                         Optional.empty() :
+                         Optional.of(NativeSymbol.ofAddress(name, MemoryAddress.ofLong(addr), ResourceScope.globalScope()));
              } catch (NoSuchMethodException e) {
                  return Optional.empty();
              }
          };
      }
  
      @Override
-     public Optional<MemoryAddress> lookup(String name) {
+     public Optional<NativeSymbol> lookup(String name) {
          return syslookup.lookup(name);
      }
  
      public static SystemLookup getInstance() {
          return INSTANCE;
< prev index next >