protected void tryLoad(String libFile) throws UnsupportedOperationException { hsl = (HunspellLibrary)Native.loadLibrary(libFile, HunspellLibrary.class); }
public EventSubscribeXmlRenderingCallback(ComponentLog logger, Consumer<String> consumer, int maxBufferSize, WEvtApi wEvtApi, Kernel32 kernel32, ErrorLookup errorLookup) { this.logger = logger; this.consumer = consumer; this.maxBufferSize = maxBufferSize; this.wEvtApi = wEvtApi; this.kernel32 = kernel32; this.size = Math.min(maxBufferSize, INITIAL_BUFFER_SIZE); this.errorLookup = errorLookup; this.buffer = new Memory(size); this.used = new Memory(4); this.propertyCount = new Memory(4); }
public void destroy() { for (ByteBuffer byteBuffer : availableBuffers) { final long address = ((DirectBuffer) byteBuffer).address(); Pointer pointer = new Pointer(address); LibC.INSTANCE.munlock(pointer, new NativeLong(fileSize)); } }
private String readLine(int fd, long addr, String prefix) throws IOException { if(LOGGER.isLoggable(FINEST)) LOGGER.finest("Reading "+prefix+" at "+addr); Memory m = new Memory(1); byte ch = 1; ByteArrayOutputStream buf = new ByteArrayOutputStream(); int i = 0; while(true) { if (i++ > LINE_LENGTH_LIMIT) { LOGGER.finest("could not find end of line, giving up"); throw new IOException("could not find end of line, giving up"); } long r = LIBC.pread(fd, m, new NativeLong(1), new NativeLong(addr)); ch = m.getByte(0); if (ch == 0) break; buf.write(ch); addr++; } String line = buf.toString(); if(LOGGER.isLoggable(FINEST)) LOGGER.finest(prefix+" was "+line); return line; } }
Memory m = new Memory(psize); int fd = LIBC.open(getFile("as").getAbsolutePath(), 0); LIBC.pread(fd, m, new NativeLong(psize), new NativeLong(pr_envp)); long envp = b64 ? m.getLong(0) : to64(m.getInt(0)); LIBC.pread(fd, m, new NativeLong(psize), new NativeLong(envp+(n*psize))); long addr = b64 ? m.getLong(0) : to64(m.getInt(0));
public void restart() throws Exception { // close all files upon exec, except stdin, stdout, and stderr int sz = LIBC.getdtablesize(); for (int i = 3; i < sz; i++) { int flags = LIBC.fcntl(i, F_GETFD); if (flags < 0) continue; LIBC.fcntl(i, F_SETFD, flags | FD_CLOEXEC); } // exec to self String exe = Daemon.getCurrentExecutable(); LIBC.execv(exe, new StringArray(args.toArray(new String[args.size()]))); throw new IOException("Failed to exec '" + exe + "' " + LIBC.strerror(Native.getLastError())); }
/** * Retrieve last error set by the OS as string. This corresponds to and <code>errno</code> on * *nix platforms. * @return displayable string with OS error info. */ private static String getLastError() { return IgniteNativeIoLib.strerror(Native.getLastError()); }
/** * Init the native binding to the underlying system library. * @return <code>true</code> if the link is effective and <code>false</code> otherwise. */ public static void init() throws UnsatisfiedLinkError { Native.unregister(JOpenVRLibrary.class); String path = System.getProperty(JNA_OPENVR_LIBRARY_PATH); if (path != null){ JNA_LIBRARY_NAME = path; logger.config("Using OpenVR implementation located at "+JNA_LIBRARY_NAME); JNA_NATIVE_LIB = NativeLibrary.getInstance(JOpenVRLibrary.JNA_LIBRARY_NAME); Native.register(JOpenVRLibrary.class, JOpenVRLibrary.JNA_NATIVE_LIB); } else { JNA_LIBRARY_NAME = "openvr_api"; logger.config("Using embedded OpenVR implementation "+JOpenVRLibrary.JNA_LIBRARY_NAME); JNA_NATIVE_LIB = NativeLibrary.getInstance(JOpenVRLibrary.JNA_LIBRARY_NAME); Native.register(JOpenVRLibrary.class, JOpenVRLibrary.JNA_NATIVE_LIB); } }
/** * Frees the memory space pointed to by {@code addr} - address of buffer, which must have been returned by a * previous call {@link #allocate(int, int)}. * * @param addr direct buffer address to free. */ public static void free(long addr) { IgniteNativeIoLib.free(new Pointer(addr)); } }
/** * @see NativeCalls#isProcessActive(int) */ @Override public boolean isProcessActive(final int processId) { try { return kill(processId, 0) == 0; } catch (LastErrorException le) { if (le.getErrorCode() == EPERM) { // Process exists; it probably belongs to another user (bug 27698). return true; } } return false; }
@Override protected void fallocateFD(int fd, long offset, long len) throws LastErrorException { int errno = posix_fallocate64(fd, offset, len); if (errno != 0) { throw new LastErrorException(errno); } } }
public void munlock() { final long beginTime = System.currentTimeMillis(); final long address = ((DirectBuffer) (this.mappedByteBuffer)).address(); Pointer pointer = new Pointer(address); int ret = LibC.INSTANCE.munlock(pointer, new NativeLong(this.fileSize)); log.info("munlock {} {} {} ret = {} time consuming = {}", address, this.fileName, this.fileSize, ret, System.currentTimeMillis() - beginTime); }
private String readLine(int fd, long addr, String prefix) throws IOException { if(LOGGER.isLoggable(FINEST)) LOGGER.finest("Reading "+prefix+" at "+addr); Memory m = new Memory(1); byte ch = 1; ByteArrayOutputStream buf = new ByteArrayOutputStream(); int i = 0; while(true) { if (i++ > LINE_LENGTH_LIMIT) { LOGGER.finest("could not find end of line, giving up"); throw new IOException("could not find end of line, giving up"); } LIBC.pread(fd, m, new NativeLong(1), new NativeLong(addr)); ch = m.getByte(0); if (ch == 0) break; buf.write(ch); addr++; } String line = buf.toString(); if(LOGGER.isLoggable(FINEST)) LOGGER.finest(prefix+" was "+line); return line; } }
@Override public void restart() throws IOException, InterruptedException { Jenkins jenkins = Jenkins.getInstanceOrNull(); // guard against repeated concurrent calls to restart try { if (jenkins != null) { jenkins.cleanUp(); } } catch (Exception e) { LOGGER.log(Level.SEVERE, "Failed to clean up. Restart will continue.", e); } // close all files upon exec, except stdin, stdout, and stderr int sz = LIBC.getdtablesize(); for(int i=3; i<sz; i++) { int flags = LIBC.fcntl(i, F_GETFD); if(flags<0) continue; LIBC.fcntl(i, F_SETFD,flags| FD_CLOEXEC); } // exec to self String exe = args.get(0); LIBC.execvp(exe, new StringArray(args.toArray(new String[args.size()]))); throw new IOException("Failed to exec '"+exe+"' "+LIBC.strerror(Native.getLastError())); }
/*package*/ static Kernel32 load() { try { return (Kernel32) Native.loadLibrary("kernel32", Kernel32.class); } catch (Throwable e) { LOGGER.log(Level.SEVERE, "Failed to load Kernel32", e); return InitializationErrorInvocationHandler.create(Kernel32.class,e); } }
public static void tryMunlockall() { try { if(isOperatingSystem("windows")) return; munlockall(); logger.info("munlockall() on JVM Heap successful"); } catch(Exception e) { if(!(e instanceof LastErrorException)) logger.error("Unexpected error during mlock of server heap", e); LastErrorException le = (LastErrorException) e; logger.warn("Error unlocking JVM heap " + le.getErrorCode()); } }
/** * It's a heavy init method. */ public void init() { for (int i = 0; i < poolSize; i++) { ByteBuffer byteBuffer = ByteBuffer.allocateDirect(fileSize); final long address = ((DirectBuffer) byteBuffer).address(); Pointer pointer = new Pointer(address); LibC.INSTANCE.mlock(pointer, new NativeLong(fileSize)); availableBuffers.offer(byteBuffer); } }
public void mlock() { final long beginTime = System.currentTimeMillis(); final long address = ((DirectBuffer) (this.mappedByteBuffer)).address(); Pointer pointer = new Pointer(address); { int ret = LibC.INSTANCE.mlock(pointer, new NativeLong(this.fileSize)); log.info("mlock {} {} {} ret = {} time consuming = {}", address, this.fileName, this.fileSize, ret, System.currentTimeMillis() - beginTime); } { int ret = LibC.INSTANCE.madvise(pointer, new NativeLong(this.fileSize), LibC.MADV_WILLNEED); log.info("madvise {} {} {} ret = {} time consuming = {}", address, this.fileName, this.fileSize, ret, System.currentTimeMillis() - beginTime); } }