static UDis86 loadUDis86() { DefaultTypeMapper typeMapper = new DefaultTypeMapper(); typeMapper.put(X86Disassembler.class, new X86DisassemblerConverter()); return LibraryLoader.create(UDis86.class) .library("udis86") .search("/usr/local/lib") .search("/opt/local/lib") .search("/usr/lib") .mapper(typeMapper) .load(); }
/** * Sets the calling convention of the library to the Windows stdcall calling convention * * @return This {@code LibraryLoader} instance. */ public final LibraryLoader<T> stdcall() { return convention(CallingConvention.STDCALL); }
/** * Loads a native library and links the methods defined in {@code interfaceClass} * to native methods in the library. * * @param libraryName The name or path of library to load. * @return an implementation of the interface provided to {@link #create(Class)} that will call the native methods. */ public T load(String libraryName) { return library(libraryName).load(); }
/** * Loads a native library and links the methods defined in {@code interfaceClass} * to native methods in the library. * * @deprecated see {@link LibraryLoader} for the preferred interface to loading libraries. * @param libraryNames the name of the library to load * @param interfaceClass the interface that describes the native library interface * @param libraryOptions options * @return an instance of {@code interfaceclass} that will call the native methods. */ public static <T> T loadLibrary(Class<T> interfaceClass, Map<LibraryOption, ?> libraryOptions, String... libraryNames) { LibraryLoader<T> loader = FFIProvider.getSystemProvider().createLibraryLoader(interfaceClass); for (String libraryName : libraryNames) { loader.library(libraryName); for (String path : getLibraryPath(libraryName)) { loader.search(path); } } for (Map.Entry<LibraryOption, ?> option : libraryOptions.entrySet()) { loader.option(option.getKey(), option.getValue()); } return loader.failImmediately().load(); }
public AbstractFuseFS() { LibraryLoader<LibFuse> loader = LibraryLoader.create(LibFuse.class).failImmediately(); jnr.ffi.Platform p = jnr.ffi.Platform.getNativePlatform(); LibFuse libFuse = null; switch (p.getOS()) { case LINUX: libFuse = loader.load("libfuse.so.2"); break; case DARWIN: try { libFuse = LibraryLoader.create(LibFuse.class).failImmediately().load(library); break; } catch (Throwable e) { libFuse = LibraryLoader.create(LibFuse.class).failImmediately().load("fuse"); libFuse = loader.load(winFspPath); break; default: libFuse = LibraryLoader.create(LibFuse.class).failImmediately().load("libfuse.so.2"); } catch (Throwable e) { libFuse = LibraryLoader.create(LibFuse.class).failImmediately().load("fuse");
return loadLibrary(interfaceClass, Collections.unmodifiableList(libraryNames), getSearchPaths(), Collections.unmodifiableMap(optionMap)); return createErrorProxy(error); if (failImmediately) throw re; return createErrorProxy(re);
/** * Sets an option when loading libraries. * * @see LibraryOption * * @param option The option to set. * @param value The value for the option. * @return The {@code LibraryLoader} instance. */ public LibraryLoader<T> option(LibraryOption option, Object value) { switch (option) { case TypeMapper: if (value instanceof SignatureTypeMapper) { mapper((SignatureTypeMapper) value); } else if (value instanceof TypeMapper) { mapper((TypeMapper) value); } else if (value != null) { throw new IllegalArgumentException("invalid TypeMapper: " + value.getClass()); } break; case FunctionMapper: mapper((FunctionMapper) value); break; default: optionMap.put(option, value); } return this; }
/** * Loads a native library and links the methods defined in {@code interfaceClass} * to native methods in the library. * * @deprecated see {@link LibraryLoader} for the preferred interface to loading libraries. * @param <T> the interface type. * @param libraryNames the name of the library to load * @param interfaceClass the interface that describes the native library interface * @param libraryOptions options * @return an instance of {@code interfaceclass} that will call the native methods. */ public static <T> T loadLibrary(Class<T> interfaceClass, Map<LibraryOption, ?> libraryOptions, String... libraryNames) { LibraryLoader<T> loader = FFIProvider.getSystemProvider().createLibraryLoader(interfaceClass); for (String libraryName : libraryNames) { loader.library(libraryName); for (String path : getLibraryPath(libraryName)) { loader.search(path); } } for (Map.Entry<LibraryOption, ?> option : libraryOptions.entrySet()) { loader.option(option.getKey(), option.getValue()); } return loader.failImmediately().load(); }
public AbstractFuseFS() { LibraryLoader<LibFuse> loader = LibraryLoader.create(LibFuse.class).failImmediately(); jnr.ffi.Platform p = jnr.ffi.Platform.getNativePlatform(); LibFuse libFuse = null; switch (p.getOS()) { case LINUX: libFuse = loader.load("libfuse.so.2"); break; case DARWIN: try { libFuse = LibraryLoader.create(LibFuse.class).failImmediately().load(library); break; } catch (Throwable e) { libFuse = LibraryLoader.create(LibFuse.class).failImmediately().load("fuse"); libFuse = loader.load(winFspPath); break; default: libFuse = LibraryLoader.create(LibFuse.class).failImmediately().load("libfuse.so.2"); } catch (Throwable e) { libFuse = LibraryLoader.create(LibFuse.class).failImmediately().load("fuse");
/** * Loads a native library and links the methods defined in {@code interfaceClass} * to native methods in the library. * * @param libraryName The name or path of library to load. * @return an implementation of the interface provided to {@link #create(Class)} that will call the native methods. */ public T load(String libraryName) { return library(libraryName).load(); }
/** * Loads a native library and links the methods defined in {@code interfaceClass} * to native methods in the library. * * @return an implementation of the interface provided to {@link #create(Class)} that will call the native methods. */ public T load() { if (libraryNames.isEmpty()) { throw new UnsatisfiedLinkError("no library names specified"); } typeMappers.add(0, new SignatureTypeMapperAdapter(typeMapperBuilder.build())); optionMap.put(LibraryOption.TypeMapper, typeMappers.size() > 1 ? new CompositeTypeMapper(typeMappers) : typeMappers.get(0)); functionMappers.add(0, functionMapperBuilder.build()); optionMap.put(LibraryOption.FunctionMapper, functionMappers.size() > 1 ? new CompositeFunctionMapper(functionMappers) : functionMappers.get(0)); try { return loadLibrary(interfaceClass, Collections.unmodifiableList(libraryNames), getSearchPaths(), Collections.unmodifiableMap(optionMap)); } catch (LinkageError error) { if (failImmediately) throw error; return createErrorProxy(error); } catch (Exception ex) { RuntimeException re = ex instanceof RuntimeException ? (RuntimeException) ex : new RuntimeException(ex); if (failImmediately) throw re; return createErrorProxy(re); } }
/** * Sets an option when loading libraries. * * @see LibraryOption * * @param option The option to set * @param value The value for the option. * @return The {@code LibraryLoader} instance. */ public LibraryLoader<T> option(LibraryOption option, Object value) { switch (option) { case TypeMapper: if (value instanceof SignatureTypeMapper) { mapper((SignatureTypeMapper) value); } else if (value instanceof TypeMapper) { mapper((TypeMapper) value); } else if (value != null) { throw new IllegalArgumentException("invalid TypeMapper: " + value.getClass()); } break; case FunctionMapper: mapper((FunctionMapper) value); break; default: optionMap.put(option, value); } return this; }
static UDis86 loadUDis86() { DefaultTypeMapper typeMapper = new DefaultTypeMapper(); typeMapper.put(X86Disassembler.class, new X86DisassemblerConverter()); return LibraryLoader.create(UDis86.class) .library("udis86") .search("/usr/local/lib") .search("/opt/local/lib") .search("/usr/lib") .mapper(typeMapper) .load(); }
/** * Loads a native library and links the methods defined in {@code interfaceClass} * to native methods in the library. * * @deprecated see {@link LibraryLoader} for the preferred interface to loading libraries. * @param <T> the interface type. * @param libraryNames the name of the library to load * @param interfaceClass the interface that describes the native library interface * @param libraryOptions options * @return an instance of {@code interfaceclass} that will call the native methods. */ public static <T> T loadLibrary(Class<T> interfaceClass, Map<LibraryOption, ?> libraryOptions, String... libraryNames) { LibraryLoader<T> loader = FFIProvider.getSystemProvider().createLibraryLoader(interfaceClass); for (String libraryName : libraryNames) { loader.library(libraryName); for (String path : getLibraryPath(libraryName)) { loader.search(path); } } for (Map.Entry<LibraryOption, ?> option : libraryOptions.entrySet()) { loader.option(option.getKey(), option.getValue()); } return loader.failImmediately().load(); }
@Override public void stopNow() throws IOException { Process p = process.getProcess(); int pid = ProcessUtils.getPid(p); localLogger.info(String.format("Killing Jenkins Process, pid: %s running at JENKINS_HOME: %s",pid, jenkinsHome)); LibraryLoader.create(GNUCLibrary.class).load("c").kill(pid,2); synchronized (p) { try { p.wait(3000); } catch (InterruptedException e) { throw (IOException)new InterruptedIOException().initCause(e); } } p.destroy(); // if it hasn't died after 3 sec, just kill it }