Refine search
/** * Turn on the keyboard overlay. This is a keyboard that hovers in front of the user, that can be typed upon by * pointing the ray extending from the top of the controller at the key the user wants to press. * @param showingState - true or false * @return - true if successful. If this call fails, an error is logged. */ public static boolean setKeyboardOverlayShowing(boolean showingState) { int ret; if (showingState) { Pointer pointer = new Memory(3); pointer.setString(0, "mc"); Pointer empty = new Memory(1); empty.setString(0, ""); ret = vrOverlay.ShowKeyboard.apply(0, 0, pointer, 256, empty, (byte) 1, 0); keyboardShowing = 0 == ret; //0 = no error, > 0 see EVROverlayError if (ret != 0) { logger.error("VR Overlay Error: " + vrOverlay.GetOverlayErrorNameFromEnum.apply(ret).getString(0)); } } else { try { vrOverlay.HideKeyboard.apply(); } catch (Error e) { logger.error("Error bringing up keyboard overlay: " + e.toString()); } keyboardShowing = false; } return keyboardShowing; }
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)); } }
try { int suggestionsCount = 0; PointerByReference suggestions = new PointerByReference(); final byte[] wordAsBytes = stringToBytes(word); if (wordAsBytes.length == 0 && word.length() > 0) { Pointer[] pointerArray = suggestions.getValue(). getPointerArray(0, suggestionsCount); long len = pointerArray[i].indexOf(0, (byte)0); if (len != -1) { if (len > Integer.MAX_VALUE) { "String improperly terminated: " + len); byte[] data = pointerArray[i].getByteArray(0, (int)len);
/** * 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; }
/** * 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); }
private MacAddress getMacAddress(String nifName) { Pointer lpAdapter = NativePacketDllMappings.PacketOpenAdapter(nifName); long hFile = -1; if (lpAdapter != null) { if (Native.POINTER_SIZE == 4) { hFile = lpAdapter.getInt(0); } else { hFile = lpAdapter.getLong(0); } } if (hFile == -1L) { int err = Native.getLastError(); logger.error("Unable to open the NIF {}, Error Code: {}", nifName, err); return null; } Memory mem = new Memory(NativePacketDllMappings.PACKET_OID_DATA_SIZE); mem.clear(); PACKET_OID_DATA oidData = new PACKET_OID_DATA(mem); oidData.Length = new NativeLong(6L); oidData.Oid = new NativeLong(0x01010102L); int status = NativePacketDllMappings.PacketRequest(lpAdapter, 0, oidData); NativePacketDllMappings.PacketCloseAdapter(lpAdapter); if (status == 0) { logger.error("Failed to retrieve the link layer address of the NIF: {}", nifName); return null; } else { return MacAddress.getByAddress(oidData.Data); } }
Structure s = (Structure)currentValue; if (Structure.ByReference.class.isAssignableFrom(type)) { s = Structure.updateStructureByReference((Class<Structure>) type, s, getPointer(offset)); } else { s.useMemory(this, (int)offset, true); result = Function.valueOf(getInt(offset) != 0); } else if (type == byte.class || type == Byte.class) { result = Byte.valueOf(getByte(offset)); } else if (type == short.class || type == Short.class) { result = Short.valueOf(getShort(offset)); } else if (type == char.class || type == Character.class) { result = Character.valueOf(getChar(offset)); } else if (type == int.class || type == Integer.class) { result = Integer.valueOf(getInt(offset)); } else if (type == long.class || type == Long.class) { result = Long.valueOf(getLong(offset)); } else if (type == float.class || type == Float.class) { result = Float.valueOf(getFloat(offset)); } else if (type == double.class || type == Double.class) { result = Double.valueOf(getDouble(offset)); } else if (Pointer.class.isAssignableFrom(type)) { Pointer p = getPointer(offset); if (p != null) { Pointer oldp = currentValue instanceof Pointer Pointer p = getPointer(offset); result = p != null ? p.getString(0) : null; } else if (type == WString.class) {
PointerByReference errorRef = new PointerByReference(); int ret = libc_mac.sandbox_init(rules.toAbsolutePath().toString(), SANDBOX_NAMED, errorRef); Pointer errorBuf = errorRef.getValue(); RuntimeException e = new UnsupportedOperationException("sandbox_init(): " + errorBuf.getString(0)); libc_mac.sandbox_free_error(errorBuf); throw e;
@Override public HmdType getType() { if( vrsystemFunctions != null ) { Pointer str1 = new Memory(128); Pointer str2 = new Memory(128); String completeName = ""; vrsystemFunctions.GetStringTrackedDeviceProperty.apply(JOpenVRLibrary.k_unTrackedDeviceIndex_Hmd, JOpenVRLibrary.ETrackedDeviceProperty.ETrackedDeviceProperty_Prop_ManufacturerName_String, str1, 128, hmdErrorStore); if( hmdErrorStore.getValue() == 0 ) completeName += str1.getString(0); vrsystemFunctions.GetStringTrackedDeviceProperty.apply(JOpenVRLibrary.k_unTrackedDeviceIndex_Hmd, JOpenVRLibrary.ETrackedDeviceProperty.ETrackedDeviceProperty_Prop_ModelNumber_String, str2, 128, hmdErrorStore); if( hmdErrorStore.getValue() == 0 ) completeName += " " + str2.getString(0); if( completeName.length() > 0 ) { completeName = completeName.toLowerCase(Locale.ENGLISH).trim();
private static class MemberOrder { public int first; public int middle; public int last; }
if (eventHandle.getPointer().getInt(0) == WEvtApi.EvtSubscribeErrors.ERROR_EVT_QUERY_RESULT_STALE) { logger.error(MISSING_EVENT_MESSAGE); } else { logger.error(RECEIVED_THE_FOLLOWING_WIN32_ERROR + eventHandle.getPointer().getInt(0)); int newMaxSize = used.getInt(0); buffer = new Memory(size); wEvtApi.EvtRender(null, eventHandle, WEvtApi.EvtRenderFlags.EVENT_XML, size, buffer, used, propertyCount); int usedBytes = used.getInt(0); String string = StandardCharsets.UTF_16LE.decode(buffer.getByteBuffer(0, usedBytes)).toString(); if (string.endsWith("\u0000")) {
public HRESULT GetTypeComp( /* [out] */ITypeComp.ByReference pTComp) { Pointer vptr = this.getPointer().getPointer(0); Function func = Function.getFunction(vptr.getPointer(32)); PointerByReference ppTComp = new PointerByReference(); int hr = func.invokeInt(new Object[] { this.getPointer(), ppTComp }); pTComp.setPointer(ppTComp.getPointer()); return new HRESULT(hr); }
public HRESULT GetTypeInfo( /* [in] */UINT index, /* [out] */ITypeInfo.ByReference pTInfo) { Pointer vptr = this.getPointer().getPointer(0); Function func = Function.getFunction(vptr.getPointer(16)); PointerByReference ppTInfo = new PointerByReference(); int hr = func.invokeInt(new Object[] { this.getPointer(), index, ppTInfo }); pTInfo.setPointer(ppTInfo.getValue()); return new HRESULT(hr); }
PointerByReference headerPP = new PointerByReference(); PointerByReference dataPP = new PointerByReference(); int rc = NativeMappings.pcap_next_ex(handle, headerPP, dataPP); switch (rc) { throw new TimeoutException(); case 1: Pointer headerP = headerPP.getValue(); Pointer dataP = dataPP.getValue(); if (headerP == null || dataP == null) { return dataP.getByteArray(0, pcap_pkthdr.getCaplen(headerP)); case -1: throw new PcapNativeException("Error occurred in pcap_next_ex(): " + getError(), rc);
throw new UnsupportedOperationException("seccomp unavailable: seccomp(BOGUS_OPERATION) returned " + ret); } else { int errno = Native.getLastError(); switch (errno) { case ENOSYS: break; // ok throw new UnsupportedOperationException("seccomp unavailable: seccomp(SECCOMP_SET_MODE_FILTER, BOGUS_FLAG) returned " + ret); } else { int errno = Native.getLastError(); switch (errno) { case ENOSYS: break; // ok throw new UnsupportedOperationException("seccomp unavailable: prctl(BOGUS_OPTION) returned " + ret); } else { int errno = Native.getLastError(); switch (errno) { case ENOSYS: break; // ok long pointer = Pointer.nativeValue(prog.getPointer()); if (linux_syscall(arch.seccomp, SECCOMP_SET_MODE_FILTER, SECCOMP_FILTER_FLAG_TSYNC, new NativeLong(pointer)) != 0) { method = 0; int errno1 = Native.getLastError();
if (value instanceof Pointer) { if (dstType == String.class) { value = ((Pointer)value).getString(0, encoding); value = new WString(((Pointer)value).getWideString(0)); value = ((Pointer)value).getStringArray(0, encoding); value = ((Pointer)value).getWideStringArray(0); Structure s = Structure.newInstance((Class<? extends Structure>) dstType); byte[] buf = new byte[s.size()]; ((Pointer)value).read(0, buf, 0, buf.length); s.getPointer().write(0, buf, 0, buf.length); s.read(); value = s; value = Function.valueOf(((Number)value).intValue() != 0);
/** * Indirect the native pointer as a pointer to <code>long</code>. This is * equivalent to the expression * <code>*((long *)((char *)Pointer + offset))</code>. * * @param offset byte offset from pointer to perform the indirection * @return the <code>long</code> value being pointed to */ public NativeLong getNativeLong(long offset) { return new NativeLong(NativeLong.SIZE == 8 ? getLong(offset) : getInt(offset)); }
logger.warn("Unable to lock JVM memory. Failed to set working set size. Error code {}", Native.getLastError()); } else { JNAKernel32Library.MemoryBasicInformation memInfo = new JNAKernel32Library.MemoryBasicInformation(); long address = 0; while (kernel.VirtualQueryEx(process, new Pointer(address), memInfo, memInfo.size()) != 0) { boolean lockable = memInfo.State.longValue() == JNAKernel32Library.MEM_COMMIT && (memInfo.Protect.longValue() & JNAKernel32Library.PAGE_NOACCESS) != JNAKernel32Library.PAGE_NOACCESS && (memInfo.Protect.longValue() & JNAKernel32Library.PAGE_GUARD) != JNAKernel32Library.PAGE_GUARD; if (lockable) { kernel.VirtualLock(memInfo.BaseAddress, new SizeT(memInfo.RegionSize.longValue()));
private static boolean initOpenVROverlay() { vrOverlay = new VR_IVROverlay_FnTable(JOpenVRLibrary.VR_GetGenericInterface(JOpenVRLibrary.IVROverlay_Version, hmdErrorStore)); if (hmdErrorStore.get(0) == 0) { vrOverlay.setAutoSynch(false); vrOverlay.read(); logger.info("OpenVR Overlay initialized OK."); } else { String errorString = jopenvr.JOpenVRLibrary.VR_GetVRInitErrorAsEnglishDescription(hmdErrorStore.get(0)).getString(0); logger.info("vrOverlay initialization failed:" + errorString); return false; } return true; }