public static void main(String[] args) throws Exception { String path = args[0]; File file = new File(path); FileInputStream in = new FileInputStream(file); int fd = voldemort.store.readonly.io.Native.getFd(in.getFD()); if(logger.isDebugEnabled()) logger.debug("File descriptor is: " + fd); // mmap a large file... Pointer addr = mmap(file.length(), PROT_READ, mman.MAP_SHARED, fd, 0L); if(logger.isDebugEnabled()) logger.debug("mmap address is: " + Pointer.nativeValue(addr)); // try to mlock it directly mlock(addr, file.length()); munlock(addr, file.length()); munmap(addr, file.length()); } }
/** * Map the given region of the given file descriptor into memory. * Returns a Pointer to the newly mapped memory throws an * IOException on error. */ public static Pointer mmap(long len, int prot, int flags, int fildes, long off) throws IOException { // we don't really have a need to change the recommended pointer. Pointer addr = new Pointer(0); Pointer result = Delegate.mmap(addr, new NativeLong(len), prot, flags, fildes, new NativeLong(off)); if(Pointer.nativeValue(result) == -1) { if(logger.isDebugEnabled()) logger.debug(errno.strerror()); throw new IOException("mmap failed: " + errno.strerror()); } return result; }
/** * @see NativeCalls#killProcess(int) */ @Override public boolean killProcess(final int processId) { try { final Pointer procHandle = Kernel32.OpenProcess(Kernel32.PROCESS_TERMINATE, false, processId); final long hval; if (procHandle == null || (hval = Pointer.nativeValue(procHandle)) == Kernel32.INVALID_HANDLE || hval == 0) { return false; } else { final boolean result = Kernel32.TerminateProcess(procHandle, -1); Kernel32.CloseHandle(procHandle); return result; } } catch (LastErrorException le) { // some problem in killing the process return false; } }
/** * @see NativeCalls#isProcessActive(int) */ @Override public boolean isProcessActive(final int processId) { try { final Pointer procHandle = Kernel32.OpenProcess(Kernel32.PROCESS_QUERY_INFORMATION, false, processId); final long hval; if (procHandle == null || (hval = Pointer.nativeValue(procHandle)) == Kernel32.INVALID_HANDLE || hval == 0) { return false; } else { final IntByReference status = new IntByReference(); final boolean result = Kernel32.GetExitCodeProcess(procHandle, status) && status.getValue() == Kernel32.STILL_ACTIVE; Kernel32.CloseHandle(procHandle); return result; } } catch (LastErrorException le) { // some problem in getting process status return false; } }
/** * Allocates align memory for use with O_DIRECT and returns native byte buffer. * @param fsBlockSize alignment, FS ans OS block size. * @param size capacity. * @return byte buffer, to be released by {@link #free(ByteBuffer)}. */ public static ByteBuffer allocate(int fsBlockSize, int size) { assert fsBlockSize > 0; assert size > 0; PointerByReference refToPtr = new PointerByReference(); int retVal = IgniteNativeIoLib.posix_memalign(refToPtr, new NativeLong(fsBlockSize), new NativeLong(size)); if (retVal != 0) throw new IgniteOutOfMemoryException("Failed to allocate memory: " + IgniteNativeIoLib.strerror(retVal)); return GridUnsafe.wrapPointer(Pointer.nativeValue(refToPtr.getValue()), size); }
/** * Constructs an mpz_t from a Pointer. * * @param from an block of native memory at least {@link #SIZE} bytes large */ public mpz_t(Pointer from) { this(Pointer.nativeValue(from)); } }
public NSMenu(Pointer p) { this(Pointer.nativeValue(p)); }
public NSAppleEventDescriptor(Pointer p) { this(Pointer.nativeValue(p)); }
public NSWindow(Pointer p) { this(Pointer.nativeValue(p)); }
long pointer = Pointer.nativeValue(prog.getPointer());
private static Pointer getStdInputHandle() throws IOException { Pointer handle = kernel32.GetStdHandle(Kernel32Defs.STD_INPUT_HANDLE); if (Pointer.nativeValue(handle) == 0 || Pointer.nativeValue(handle) == Kernel32Defs.INVALID_HANDLE_VALUE) { throw new IOException("GetStdHandle(STD_INPUT_HANDLE) failed."); } return handle; }
BufRef(ByteBuffer buffer) { mBuffer = buffer; mPointer = Pointer.nativeValue(Native.getDirectBufferPointer(buffer)); } }
public OSXSysTrayAction(JMenuItem mi) { super(Runtime.INSTANCE.class_createInstance(klass, 0)); map.put(Pointer.nativeValue(this), this); this.mi = mi; }
BufRef(ByteBuffer buffer) { mBuffer = buffer; mPointer = Pointer.nativeValue(Native.getDirectBufferPointer(buffer)); } }
BufRef(ByteBuffer buffer) { mBuffer = buffer; mPointer = Pointer.nativeValue(Native.getDirectBufferPointer(buffer)); } }
public void callback(Pointer self, Pointer selector) { if (selector.equals(registerActionSelector)) { OSXSysTrayAction a = map.get(Pointer.nativeValue(self)); a.mi.doClick(); } } };
/** * Returns allocated direct memory back to OS */ public void deallocate(OPointer pointer) { if (pointer == null) { throw new IllegalArgumentException("Null value is passed"); } final Pointer ptr = pointer.getNativePointer(); Native.free(Pointer.nativeValue(ptr)); memoryConsumption.add(-pointer.getSize()); untrack(pointer); }
public void close() { if (Pointer.nativeValue(getPointer()) != 0) { GDI32.INSTANCE.DeleteObject(this); setPointer(new Pointer(0)); } }
public void close() { if (Pointer.nativeValue(getPointer()) != 0) { GDI32.INSTANCE.DeleteObject(this); setPointer(new Pointer(0)); } } }
static String createPathForDevide(IOHIDDeviceRef dev) { short vid, pid; String transport = getStringProperty(dev, CFSTR(kIOHIDTransportKey)); if (transport == null) return null; vid = (short) getIntProperty(dev, CFSTR(kIOHIDVendorIDKey)); pid = (short) getIntProperty(dev, CFSTR(kIOHIDProductIDKey)); return String.format("%s_%04x_%04x_0x%08x", transport, vid, pid, Pointer.nativeValue(dev.getPointer())); }