/** invokes syscall() from linux libc library */ private static long linux_syscall(long number, Object... args) { return linux_libc.syscall(new NativeLong(number), args).longValue(); }
private Timestamp buildTimestamp(Pointer header) { Timestamp ts = new Timestamp(pcap_pkthdr.getTvSec(header).longValue() * 1000L); switch (timestampPrecision) { case MICRO: ts.setNanos(pcap_pkthdr.getTvUsec(header).intValue() * 1000); break; case NANO: ts.setNanos(pcap_pkthdr.getTvUsec(header).intValue()); break; default: throw new AssertionError("Never get here."); } return ts; }
static void trySetMaxSizeVirtualMemory() { if (Constants.LINUX || Constants.MAC_OS_X) { final JNACLibrary.Rlimit rlimit = new JNACLibrary.Rlimit(); if (JNACLibrary.getrlimit(JNACLibrary.RLIMIT_AS, rlimit) == 0) { MAX_SIZE_VIRTUAL_MEMORY = rlimit.rlim_cur.longValue(); } else { logger.warn("unable to retrieve max size virtual memory [" + JNACLibrary.strerror(Native.getLastError()) + "]"); } } }
static void trySetMaxFileSize() { if (Constants.LINUX || Constants.MAC_OS_X) { final JNACLibrary.Rlimit rlimit = new JNACLibrary.Rlimit(); if (JNACLibrary.getrlimit(JNACLibrary.RLIMIT_FSIZE, rlimit) == 0) { MAX_FILE_SIZE = rlimit.rlim_cur.longValue(); } else { logger.warn("unable to retrieve max file size [" + JNACLibrary.strerror(Native.getLastError()) + "]"); } } }
static void trySetMaxNumberOfThreads() { if (Constants.LINUX) { // this is only valid on Linux and the value *is* different on OS X // see /usr/include/sys/resource.h on OS X // on Linux the resource RLIMIT_NPROC means *the number of threads* // this is in opposition to BSD-derived OSes final int rlimit_nproc = 6; final JNACLibrary.Rlimit rlimit = new JNACLibrary.Rlimit(); if (JNACLibrary.getrlimit(rlimit_nproc, rlimit) == 0) { MAX_NUMBER_OF_THREADS = rlimit.rlim_cur.longValue(); } else { logger.warn("unable to retrieve max number of threads [" + JNACLibrary.strerror(Native.getLastError()) + "]"); } } }
/** * Set <code>value</code> at location being pointed to. This is equivalent * to the expression * <code>*((long *)((char *)Pointer + offset)) = value</code>. * * @param offset byte offset from pointer at which <code>value</code> * must be set * @param value <code>long</code> value to set */ public void setNativeLong(long offset, NativeLong value) { if (NativeLong.SIZE == 8) { setLong(offset, value.longValue()); } else { setInt(offset, value.intValue()); } }
/** * @return the file position for a "savefile". * @throws PcapNativeException if an error occurs in the pcap native library. * @throws NotOpenException if this PcapHandle is not open. */ public long ftell() throws PcapNativeException, NotOpenException { if (!open) { throw new NotOpenException(); } NativeLong nposition; if (!dumperLock.readLock().tryLock()) { throw new NotOpenException(); } try { if (!open) { throw new NotOpenException(); } nposition = NativeMappings.pcap_dump_ftell(dumper); } finally { dumperLock.readLock().unlock(); } long position = nposition.longValue(); if (position < 0) { throw new PcapNativeException("Failed to get the file position."); } return position; }
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()));
@Override final long f_frsize() { return f_frsize.longValue(); }
@Override final long f_bsize() { return f_bsize.longValue(); }
@Override final long f_bsize() { return f_bsize.longValue(); }
/** * Retrieves the current frequency from the given channel * * @return the current frequency */ public long getFrequency() { return GSTTUNER_API.gst_tuner_get_frequency(tuner, this).longValue(); }
@Override public BitSet getAffinity() { final LinuxHelper.cpu_set_t cpuset = LinuxHelper.sched_getaffinity(); BitSet ret = new BitSet(LinuxHelper.cpu_set_t.__CPU_SETSIZE); int i = 0; for (NativeLong nl : cpuset.__bits) { for (int j = 0; j < Long.SIZE; j++) ret.set(i++, ((nl.longValue() >>> j) & 1) != 0); } return ret; }
@Override public Object readFrom(Memory buffer, Class<?> type) { ID id = ID.fromLong(buffer.getNativeLong(0).longValue()); if (id.isNull()) return null; return id; } @Override public Memory bufferForResult(Object methodCallResult) {
public VisualID getVisualID() { if (getPointer() != null) return new VisualID(getPointer().getNativeLong(Native.POINTER_SIZE).longValue()); throw new IllegalStateException("Attempting to retrieve VisualID from a null Visual"); } @Override
@SuppressWarnings({"UnusedDeclaration"}) public static void __CPU_SET(int cpu, cpu_set_t cpuset) { cpuset.__bits[__CPUELT(cpu)].setValue( cpuset.__bits[__CPUELT(cpu)].longValue() | __CPUMASK(cpu)); }
@SuppressWarnings({"UnusedDeclaration"}) public static void __CPU_CLR(int cpu, cpu_set_t cpuset) { cpuset.__bits[__CPUELT(cpu)].setValue( cpuset.__bits[__CPUELT(cpu)].longValue() & ~__CPUMASK(cpu)); }