public static int sched_getcpu() { final CLibrary lib = CLibrary.INSTANCE; try { final int ret = lib.sched_getcpu(); if (ret < 0) { throw new IllegalStateException("sched_getcpu() failed; errno=" + Native.getLastError()); } return ret; } catch (LastErrorException e) { throw new IllegalStateException("sched_getcpu() failed; errno=" + e.getErrorCode(), e); } catch (UnsatisfiedLinkError ule) { try { final IntByReference cpu = new IntByReference(); final IntByReference node = new IntByReference(); final int ret = lib.syscall(318, cpu, node, null); if (ret != 0) { throw new IllegalStateException("getcpu() failed; errno=" + Native.getLastError()); } return cpu.getValue(); } catch (LastErrorException lee) { if (lee.getErrorCode() == 38 && Platform.is64Bit()) { // unknown call final Pointer getcpuAddr = new Pointer((-10L << 20) + 1024L * 2L); final Function getcpu = Function.getFunction(getcpuAddr, Function.C_CONVENTION); final IntByReference cpu = new IntByReference(); if (getcpu.invokeInt(new Object[] {cpu, null, null}) < 0) { throw new IllegalStateException("getcpu() failed; errno=" + Native.getLastError()); } else { return cpu.getValue(); } } else { throw new IllegalStateException("getcpu() failed; errno=" + lee.getErrorCode(), lee); } } } }