From 8f9337f18a02172497117c520e93bc691610fedc Mon Sep 17 00:00:00 2001
From: Manuel Bleichenbacher
Date: Mon, 22 Aug 2022 19:54:18 +0200
Subject: [PATCH 001/433] jextract on macOS
---
java-does-usb/jextract/gen_macos.sh | 15 ++
.../usb/macos/gen/Constants$root.java | 23 ++
.../usb/macos/gen/RuntimeHelper.java | 233 ++++++++++++++++++
.../codecrete/usb/macos/gen/constants$0.java | 22 ++
.../net/codecrete/usb/macos/gen/mach_h.java | 34 +++
5 files changed, 327 insertions(+)
create mode 100755 java-does-usb/jextract/gen_macos.sh
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/macos/gen/Constants$root.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/macos/gen/RuntimeHelper.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/macos/gen/constants$0.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach_h.java
diff --git a/java-does-usb/jextract/gen_macos.sh b/java-does-usb/jextract/gen_macos.sh
new file mode 100755
index 00000000..1ed1f947
--- /dev/null
+++ b/java-does-usb/jextract/gen_macos.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+JEXTRACT=../../../jextract/build/jextract/bin/jextract
+
+# CoreFoundation
+#$JEXTRACT --source --target-package net.codecrete.usb.macos.gen --output ../src/main/java \
+# -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include \
+# --include-function CFUUIDCreateFromUUIDBytes \
+# /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Versions/A/Headers/CoreFoundation.h
+
+## mach_error
+$JEXTRACT --source --target-package net.codecrete.usb.macos.gen --output ../src/main/java \
+ -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include \
+ --include-function mach_error \
+ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/mach/mach.h
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/Constants$root.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/Constants$root.java
new file mode 100644
index 00000000..14626843
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/Constants$root.java
@@ -0,0 +1,23 @@
+// Generated by jextract
+
+package net.codecrete.usb.macos.gen;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.VarHandle;
+import java.nio.ByteOrder;
+import java.lang.foreign.*;
+import static java.lang.foreign.ValueLayout.*;
+public class Constants$root {
+
+ static final OfBoolean C_BOOL$LAYOUT = JAVA_BOOLEAN;
+ static final OfByte C_CHAR$LAYOUT = JAVA_BYTE;
+ static final OfShort C_SHORT$LAYOUT = JAVA_SHORT.withBitAlignment(16);
+ static final OfInt C_INT$LAYOUT = JAVA_INT.withBitAlignment(32);
+ static final OfLong C_LONG$LAYOUT = JAVA_LONG.withBitAlignment(64);
+ static final OfLong C_LONG_LONG$LAYOUT = JAVA_LONG.withBitAlignment(64);
+ static final OfFloat C_FLOAT$LAYOUT = JAVA_FLOAT.withBitAlignment(32);
+ static final OfDouble C_DOUBLE$LAYOUT = JAVA_DOUBLE.withBitAlignment(64);
+ static final OfAddress C_POINTER$LAYOUT = ADDRESS.withBitAlignment(64);
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/RuntimeHelper.java
new file mode 100644
index 00000000..01993f2e
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/RuntimeHelper.java
@@ -0,0 +1,233 @@
+package net.codecrete.usb.macos.gen;
+// Generated by jextract
+
+import java.lang.foreign.Addressable;
+import java.lang.foreign.Linker;
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.foreign.GroupLayout;
+import java.lang.foreign.SymbolLookup;
+import java.lang.foreign.MemoryAddress;
+import java.lang.foreign.MemoryLayout;
+import java.lang.foreign.MemorySegment;
+import java.lang.foreign.MemorySession;
+import java.lang.foreign.SegmentAllocator;
+import java.lang.foreign.ValueLayout;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.io.File;
+import java.nio.file.Path;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.Optional;
+import java.util.stream.Stream;
+
+import static java.lang.foreign.Linker.*;
+import static java.lang.foreign.ValueLayout.*;
+
+final class RuntimeHelper {
+
+ private RuntimeHelper() {}
+ private final static Linker LINKER = Linker.nativeLinker();
+ private final static ClassLoader LOADER = RuntimeHelper.class.getClassLoader();
+ private final static MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup();
+ private final static SymbolLookup SYMBOL_LOOKUP;
+
+ final static SegmentAllocator CONSTANT_ALLOCATOR =
+ (size, align) -> MemorySegment.allocateNative(size, align, MemorySession.openImplicit());
+
+ static {
+
+ SymbolLookup loaderLookup = SymbolLookup.loaderLookup();
+ SYMBOL_LOOKUP = name -> loaderLookup.lookup(name).or(() -> LINKER.defaultLookup().lookup(name));
+ }
+
+ static T requireNonNull(T obj, String symbolName) {
+ if (obj == null) {
+ throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName);
+ }
+ return obj;
+ }
+
+ private final static SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); };
+
+ static final MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) {
+ return SYMBOL_LOOKUP.lookup(name).map(symbol -> MemorySegment.ofAddress(symbol.address(), layout.byteSize(), MemorySession.openShared())).orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> LINKER.downcallHandle(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(FunctionDescriptor fdesc) {
+ return LINKER.downcallHandle(fdesc);
+ }
+
+ static final MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> VarargsInvoker.make(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MemorySegment upcallStub(Class fi, Z z, FunctionDescriptor fdesc, MemorySession session) {
+ try {
+ MethodHandle handle = MH_LOOKUP.findVirtual(fi, "apply", Linker.upcallType(fdesc));
+ handle = handle.bindTo(z);
+ return LINKER.upcallStub(handle, fdesc, session);
+ } catch (Throwable ex) {
+ throw new AssertionError(ex);
+ }
+ }
+
+ static MemorySegment asArray(MemoryAddress addr, MemoryLayout layout, int numElements, MemorySession session) {
+ return MemorySegment.ofAddress(addr, numElements * layout.byteSize(), session);
+ }
+
+ // Internals only below this point
+
+ private static class VarargsInvoker {
+ private static final MethodHandle INVOKE_MH;
+ private final MemorySegment symbol;
+ private final FunctionDescriptor function;
+
+ private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) {
+ this.symbol = symbol;
+ this.function = function;
+ }
+
+ static {
+ try {
+ INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class));
+ } catch (ReflectiveOperationException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) {
+ VarargsInvoker invoker = new VarargsInvoker(symbol, function);
+ MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1);
+ MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class);
+ for (MemoryLayout layout : function.argumentLayouts()) {
+ mtype = mtype.appendParameterTypes(carrier(layout, false));
+ }
+ mtype = mtype.appendParameterTypes(Object[].class);
+ if (mtype.returnType().equals(MemorySegment.class)) {
+ mtype = mtype.insertParameterTypes(0, SegmentAllocator.class);
+ } else {
+ handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR);
+ }
+ return handle.asType(mtype);
+ }
+
+ static Class> carrier(MemoryLayout layout, boolean ret) {
+ if (layout instanceof ValueLayout valueLayout) {
+ return (ret || valueLayout.carrier() != MemoryAddress.class) ?
+ valueLayout.carrier() : Addressable.class;
+ } else if (layout instanceof GroupLayout) {
+ return MemorySegment.class;
+ } else {
+ throw new AssertionError("Cannot get here!");
+ }
+ }
+
+ private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable {
+ // one trailing Object[]
+ int nNamedArgs = function.argumentLayouts().size();
+ assert(args.length == nNamedArgs + 1);
+ // The last argument is the array of vararg collector
+ Object[] unnamedArgs = (Object[]) args[args.length - 1];
+
+ int argsCount = nNamedArgs + unnamedArgs.length;
+ Class>[] argTypes = new Class>[argsCount];
+ MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length];
+
+ int pos = 0;
+ for (pos = 0; pos < nNamedArgs; pos++) {
+ argLayouts[pos] = function.argumentLayouts().get(pos);
+ }
+
+ assert pos == nNamedArgs;
+ for (Object o: unnamedArgs) {
+ argLayouts[pos] = variadicLayout(normalize(o.getClass()));
+ pos++;
+ }
+ assert pos == argsCount;
+
+ FunctionDescriptor f = (function.returnLayout().isEmpty()) ?
+ FunctionDescriptor.ofVoid(argLayouts) :
+ FunctionDescriptor.of(function.returnLayout().get(), argLayouts);
+ MethodHandle mh = LINKER.downcallHandle(symbol, f);
+ if (mh.type().returnType() == MemorySegment.class) {
+ mh = mh.bindTo(allocator);
+ }
+ // flatten argument list so that it can be passed to an asSpreader MH
+ Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length];
+ System.arraycopy(args, 0, allArgs, 0, nNamedArgs);
+ System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length);
+
+ return mh.asSpreader(Object[].class, argsCount).invoke(allArgs);
+ }
+
+ private static Class> unboxIfNeeded(Class> clazz) {
+ if (clazz == Boolean.class) {
+ return boolean.class;
+ } else if (clazz == Void.class) {
+ return void.class;
+ } else if (clazz == Byte.class) {
+ return byte.class;
+ } else if (clazz == Character.class) {
+ return char.class;
+ } else if (clazz == Short.class) {
+ return short.class;
+ } else if (clazz == Integer.class) {
+ return int.class;
+ } else if (clazz == Long.class) {
+ return long.class;
+ } else if (clazz == Float.class) {
+ return float.class;
+ } else if (clazz == Double.class) {
+ return double.class;
+ } else {
+ return clazz;
+ }
+ }
+
+ private Class> promote(Class> c) {
+ if (c == byte.class || c == char.class || c == short.class || c == int.class) {
+ return long.class;
+ } else if (c == float.class) {
+ return double.class;
+ } else {
+ return c;
+ }
+ }
+
+ private Class> normalize(Class> c) {
+ c = unboxIfNeeded(c);
+ if (c.isPrimitive()) {
+ return promote(c);
+ }
+ if (MemoryAddress.class.isAssignableFrom(c)) {
+ return MemoryAddress.class;
+ }
+ if (MemorySegment.class.isAssignableFrom(c)) {
+ return MemorySegment.class;
+ }
+ throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName());
+ }
+
+ private MemoryLayout variadicLayout(Class> c) {
+ if (c == long.class) {
+ return JAVA_LONG;
+ } else if (c == double.class) {
+ return JAVA_DOUBLE;
+ } else if (MemoryAddress.class.isAssignableFrom(c)) {
+ return ADDRESS;
+ } else {
+ throw new IllegalArgumentException("Unhandled variadic argument class: " + c);
+ }
+ }
+ }
+}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/constants$0.java
new file mode 100644
index 00000000..9ec2b3a5
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/constants$0.java
@@ -0,0 +1,22 @@
+// Generated by jextract
+
+package net.codecrete.usb.macos.gen;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.VarHandle;
+import java.nio.ByteOrder;
+import java.lang.foreign.*;
+import static java.lang.foreign.ValueLayout.*;
+class constants$0 {
+
+ static final FunctionDescriptor mach_error$FUNC = FunctionDescriptor.ofVoid(
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle mach_error$MH = RuntimeHelper.downcallHandle(
+ "mach_error",
+ constants$0.mach_error$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach_h.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach_h.java
new file mode 100644
index 00000000..c739f909
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach_h.java
@@ -0,0 +1,34 @@
+// Generated by jextract
+
+package net.codecrete.usb.macos.gen;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.VarHandle;
+import java.nio.ByteOrder;
+import java.lang.foreign.*;
+import static java.lang.foreign.ValueLayout.*;
+public class mach_h {
+
+ /* package-private */ mach_h() {}
+ public static OfByte C_CHAR = Constants$root.C_CHAR$LAYOUT;
+ public static OfShort C_SHORT = Constants$root.C_SHORT$LAYOUT;
+ public static OfInt C_INT = Constants$root.C_INT$LAYOUT;
+ public static OfLong C_LONG = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong C_LONG_LONG = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfFloat C_FLOAT = Constants$root.C_FLOAT$LAYOUT;
+ public static OfDouble C_DOUBLE = Constants$root.C_DOUBLE$LAYOUT;
+ public static OfAddress C_POINTER = Constants$root.C_POINTER$LAYOUT;
+ public static MethodHandle mach_error$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.mach_error$MH,"mach_error");
+ }
+ public static void mach_error ( Addressable str, int error_value) {
+ var mh$ = mach_error$MH();
+ try {
+ mh$.invokeExact(str, error_value);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+}
+
+
From bbf8f350dd6abc7d3cbd6edfd969d4c54db8618c Mon Sep 17 00:00:00 2001
From: Manuel Bl
Date: Mon, 22 Aug 2022 21:01:04 +0200
Subject: [PATCH 002/433] jextract on Linux
---
java-does-usb/jextract/gen_linux.sh | 41 +++++++++
.../main/java/net/codecrete/usb/linux/IO.java | 84 ++-----------------
.../codecrete/usb/linux/LinuxUSBDevice.java | 50 ++++++-----
.../net/codecrete/usb/linux/USBDevFS.java | 55 ------------
.../java/net/codecrete/usb/macos/Kernel.java | 7 +-
.../usb/macos/gen/Constants$root.java | 4 -
.../usb/macos/gen/RuntimeHelper.java | 21 +----
.../codecrete/usb/macos/gen/constants$0.java | 5 +-
.../net/codecrete/usb/macos/gen/mach_h.java | 5 +-
9 files changed, 86 insertions(+), 186 deletions(-)
create mode 100755 java-does-usb/jextract/gen_linux.sh
diff --git a/java-does-usb/jextract/gen_linux.sh b/java-does-usb/jextract/gen_linux.sh
new file mode 100755
index 00000000..6fc40342
--- /dev/null
+++ b/java-does-usb/jextract/gen_linux.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+JEXTRACT=../../../jextract/build/jextract/bin/jextract
+
+# sd-device.h (install libsystemd-dev if file is missing)
+# Error: /usr/include/inttypes.h:290:8: error: unknown type name 'intmax_t'
+#$JEXTRACT --source --output ../src/main/java \
+# --header-class-name sd_device \
+# --target-package net.codecrete.usb.linux.gen.sd-device
+# /usr/include/systemd/sd-device.h
+
+# errno.h
+$JEXTRACT --source --output ../src/main/java \
+ --header-class-name errno \
+ --target-package net.codecrete.usb.linux.gen.errno \
+ /usr/include/errno.h
+
+# ioctl.h
+$JEXTRACT --source --output ../src/main/java \
+ --header-class-name ioctl \
+ --target-package net.codecrete.usb.linux.gen.ioctl \
+ /usr/include/x86_64-linux-gnu/sys/ioctl.h
+
+# fcntl.h
+$JEXTRACT --source --output ../src/main/java \
+ --header-class-name fcntl \
+ --target-package net.codecrete.usb.linux.gen.fcntl \
+ /usr/include/fcntl.h
+
+# unistd.h
+$JEXTRACT --source --output ../src/main/java \
+ --header-class-name unistd \
+ --target-package net.codecrete.usb.linux.gen.unistd \
+ /usr/include/unistd.h
+
+# usbdevice_fs.h
+# Missing constants like USBDEVFS_CLAIMINTERFACE
+$JEXTRACT --source --output ../src/main/java \
+ --header-class-name usbdevice_fs \
+ --target-package net.codecrete.usb.linux.gen.usbdevice_fs \
+ /usr/include/linux/usbdevice_fs.h
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/IO.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/IO.java
index eda603be..68792634 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/IO.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/IO.java
@@ -7,89 +7,19 @@
package net.codecrete.usb.linux;
-import java.lang.foreign.*;
-import java.lang.invoke.MethodHandle;
+import net.codecrete.usb.linux.gen.errno.errno;
-import static java.lang.foreign.ValueLayout.*;
+import java.lang.foreign.MemoryAddress;
+import java.lang.foreign.MemorySegment;
+import java.lang.foreign.MemorySession;
-public class IO {
-
- public static final int O_RDONLY = 0;
- public static final int O_WRONLY = 1;
- public static final int O_RDWR = 2;
- public static final int O_CREAT = 64;
- public static final int O_EXCL = 128;
- public static final int O_TRUNC = 512;
- public static final int O_APPEND = 1024;
- public static final int O_NONBLOCK = 2048;
- public static final int O_CLOEXEC = 524288;
-
- private static final MethodHandle open$Func;
- private static final MethodHandle ioctl$Func;
- private static final MethodHandle close$Func;
- private static final MethodHandle errno_location$Func;
-
- static {
- Linker linker = Linker.nativeLinker();
- SymbolLookup lookup = linker.defaultLookup();
-
- // int open (const char *__path, int __oflag, ...)
- // (method handle without variadic arguments)
- open$Func = linker.downcallHandle(
- lookup.lookup("open").get(),
- FunctionDescriptor.of(JAVA_INT, ADDRESS, JAVA_INT)
- );
-
- // int ioctl (int __fd, unsigned long int __request, ...);
- ioctl$Func = linker.downcallHandle(
- lookup.lookup("ioctl").get(),
- FunctionDescriptor.of(JAVA_INT, JAVA_INT, JAVA_LONG, ADDRESS)
- );
-
- // int close(int fd);
- close$Func = linker.downcallHandle(
- lookup.lookup("close").get(),
- FunctionDescriptor.of(JAVA_INT, JAVA_INT)
- );
+import static java.lang.foreign.ValueLayout.JAVA_INT;
- // int *__errno_location (void)
- errno_location$Func = linker.downcallHandle(
- lookup.lookup("__errno_location").get(),
- FunctionDescriptor.of(ADDRESS)
- );
- }
-
- // int open (const char *__path, int __oflag, ...)
- public static int open(String path, int oflag) {
- try (var session = MemorySession.openConfined()) {
- var pathCStr = session.allocateUtf8String(path);
- return (int) open$Func.invokeExact((Addressable) pathCStr, oflag);
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- // int ioctl (int __fd, unsigned long int __request, ...);
- public static int ioctl(int fd, long request, Addressable val) {
- try {
- return (int) ioctl$Func.invokeExact(fd, request, val);
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- // int close(int fd);
- public static int close(int fd) {
- try {
- return (int) close$Func.invokeExact(fd);
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
+public class IO {
public static int getErrno() {
try (var session = MemorySession.openConfined()) {
- var location = (MemoryAddress) errno_location$Func.invokeExact();
+ var location = (MemoryAddress) errno.__errno_location();
var errnoSegment = MemorySegment.ofAddress(location, JAVA_INT.byteSize(), session);
return errnoSegment.get(JAVA_INT, 0);
} catch (Throwable e) {
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDevice.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDevice.java
index c6c71b6d..e1b7c622 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDevice.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDevice.java
@@ -12,6 +12,11 @@
import net.codecrete.usb.USBDirection;
import net.codecrete.usb.USBException;
import net.codecrete.usb.common.USBDeviceImpl;
+import net.codecrete.usb.linux.gen.fcntl.fcntl;
+import net.codecrete.usb.linux.gen.ioctl.ioctl;
+import net.codecrete.usb.linux.gen.unistd.unistd;
+import net.codecrete.usb.linux.gen.usbdevice_fs.usbdevfs_bulktransfer;
+import net.codecrete.usb.linux.gen.usbdevice_fs.usbdevfs_ctrltransfer;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.MemorySession;
@@ -26,15 +31,18 @@ public class LinuxUSBDevice extends USBDeviceImpl {
LinuxUSBDevice(String path, USBDeviceInfo info) {
super(path, info);
- fd = IO.open(path, IO.O_RDWR | IO.O_CLOEXEC);
- if (fd == -1)
- throw new USBException("Cannot open USB device", IO.getErrno());
+ try (var session = MemorySession.openConfined()) {
+ var pathUtf8 = session.allocateUtf8String(path);
+ fd = fcntl.open(pathUtf8, fcntl.O_RDWR() | fcntl.O_CLOEXEC());
+ if (fd == -1)
+ throw new USBException("Cannot open USB device", IO.getErrno());
+ }
}
public void claimInterface(int interfaceNumber) {
try (var session = MemorySession.openConfined()) {
var intfNumSegment = session.allocate(JAVA_INT, interfaceNumber);
- int ret = IO.ioctl(fd, USBDevFS.CLAIMINTERFACE, intfNumSegment);
+ int ret = ioctl.ioctl(fd, USBDevFS.CLAIMINTERFACE, intfNumSegment.address());
if (ret != 0)
throw new USBException("Cannot claim USB interface", IO.getErrno());
}
@@ -43,21 +51,21 @@ public void claimInterface(int interfaceNumber) {
public void releaseInterface(int interfaceNumber) {
try (var session = MemorySession.openConfined()) {
var intfNumSegment = session.allocate(JAVA_INT, interfaceNumber);
- int ret = IO.ioctl(fd, USBDevFS.RELEASEINTERFACE, intfNumSegment);
+ int ret = ioctl.ioctl(fd, USBDevFS.RELEASEINTERFACE, intfNumSegment.address());
if (ret != 0)
throw new USBException("Cannot release USB interface", IO.getErrno());
}
}
private MemorySegment createCtrlTransfer(MemorySession session, USBDirection direction, USBControlTransfer setup, MemorySegment data) {
- var ctrlTransfer = session.allocate(USBDevFS.ctrltransfer$Struct);
+ var ctrlTransfer = session.allocate(usbdevfs_ctrltransfer.$LAYOUT());
var bmRequest = (direction == USBDirection.IN ? 0x80 : 0) | (setup.requestType().ordinal() << 5) | setup.recipient().ordinal();
- USBDevFS.ctrltransfer_bRequestType.set(ctrlTransfer, (byte) bmRequest);
- USBDevFS.ctrltransfer_bRequest.set(ctrlTransfer, setup.request());
- USBDevFS.ctrltransfer_wValue.set(ctrlTransfer, setup.value());
- USBDevFS.ctrltransfer_wIndex.set(ctrlTransfer, setup.index());
- USBDevFS.ctrltransfer_wLength.set(ctrlTransfer, (short) data.byteSize());
- USBDevFS.ctrltransfer_data.set(ctrlTransfer, data.address());
+ usbdevfs_ctrltransfer.bRequestType$set(ctrlTransfer, (byte) bmRequest);
+ usbdevfs_ctrltransfer.bRequest$set(ctrlTransfer, setup.request());
+ usbdevfs_ctrltransfer.wValue$set(ctrlTransfer, setup.value());
+ usbdevfs_ctrltransfer.wIndex$set(ctrlTransfer, setup.index());
+ usbdevfs_ctrltransfer.wLength$set(ctrlTransfer, (short) data.byteSize());
+ usbdevfs_ctrltransfer.data$set(ctrlTransfer, data.address());
return ctrlTransfer;
}
@@ -67,7 +75,7 @@ public byte[] controlTransferIn(USBControlTransfer setup, int length) {
var data = session.allocate(length);
var ctrlTransfer = createCtrlTransfer(session, USBDirection.IN, setup, data);
- int res = IO.ioctl(fd, USBDevFS.CONTROL, ctrlTransfer);
+ int res = ioctl.ioctl(fd, USBDevFS.CONTROL, ctrlTransfer.address());
if (res < 0)
throw new USBException("Control IN transfer failed", res);
@@ -84,17 +92,17 @@ public void controlTransferOut(USBControlTransfer setup, byte[] data) {
buffer.copyFrom(MemorySegment.ofArray(data));
var ctrlTransfer = createCtrlTransfer(session, USBDirection.OUT, setup, buffer);
- int res = IO.ioctl(fd, USBDevFS.CONTROL, ctrlTransfer);
+ int res = ioctl.ioctl(fd, USBDevFS.CONTROL, ctrlTransfer.address());
if (res < 0)
throw new USBException("Control OUT transfer failed", res);
}
}
private MemorySegment createBulkTransfer(MemorySession session, int endpointAddress, MemorySegment data) {
- var transfer = session.allocate(USBDevFS.bulktransfer$Struct);
- USBDevFS.bulktransfer_ep.set(transfer, endpointAddress);
- USBDevFS.bulktransfer_len.set(transfer, (int) data.byteSize());
- USBDevFS.bulktransfer_data.set(transfer, data.address());
+ var transfer = session.allocate(usbdevfs_bulktransfer.$LAYOUT());
+ usbdevfs_bulktransfer.ep$set(transfer, endpointAddress);
+ usbdevfs_bulktransfer.len$set(transfer, (int) data.byteSize());
+ usbdevfs_bulktransfer.data$set(transfer, data.address());
return transfer;
}
@@ -105,7 +113,7 @@ public void transferOut(int endpointNumber, byte[] data) {
buffer.copyFrom(MemorySegment.ofArray(data));
var transfer = createBulkTransfer(session, endpointNumber, buffer);
- int res = IO.ioctl(fd, USBDevFS.BULK, transfer);
+ int res = ioctl.ioctl(fd, USBDevFS.BULK, transfer.address());
if (res < 0)
throw new USBException(String.format("USB OUT transfer on endpoint %d failed", endpointNumber), res);
}
@@ -118,7 +126,7 @@ public byte[] transferIn(int endpointNumber, int maxLength) {
var transfer = createBulkTransfer(session, 0x80 | endpointNumber, buffer);
- int res = IO.ioctl(fd, USBDevFS.BULK, transfer);
+ int res = ioctl.ioctl(fd, USBDevFS.BULK, transfer.address());
if (res < 0)
throw new USBException(String.format("USB IN transfer on endpoint %d failed", endpointNumber), res);
@@ -128,6 +136,6 @@ public byte[] transferIn(int endpointNumber, int maxLength) {
@Override
public void close() throws Exception {
- IO.close(fd);
+ unistd.close(fd);
}
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/USBDevFS.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/USBDevFS.java
index b7fc431d..96b6c011 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/USBDevFS.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/USBDevFS.java
@@ -7,14 +7,6 @@
package net.codecrete.usb.linux;
-import java.lang.foreign.GroupLayout;
-import java.lang.invoke.VarHandle;
-
-import static java.lang.foreign.MemoryLayout.PathElement.groupElement;
-import static java.lang.foreign.MemoryLayout.paddingLayout;
-import static java.lang.foreign.MemoryLayout.structLayout;
-import static java.lang.foreign.ValueLayout.*;
-
/**
* Data structures and constants related to the USB device file system.
*/
@@ -24,51 +16,4 @@ public class USBDevFS {
public static final long BULK = 0xc0185502;
public static final long CLAIMINTERFACE = 0x8004550F;
public static final long RELEASEINTERFACE = 0x80045510;
-
- // struct usbdevfs_ctrltransfer {
- // __u8 bRequestType;
- // __u8 bRequest;
- // __u16 wValue;
- // __u16 wIndex;
- // __u16 wLength;
- // __u32 timeout; /* in milliseconds */
- // void *data;
- //};
- public static final GroupLayout ctrltransfer$Struct = structLayout(
- JAVA_BYTE.withName("bRequestType"),
- JAVA_BYTE.withName("bRequest"),
- JAVA_SHORT.withName("wValue"),
- JAVA_SHORT.withName("wIndex"),
- JAVA_SHORT.withName("wLength"),
- JAVA_INT.withName("timeout"),
- paddingLayout(4 * 8),
- ADDRESS.withName("data")
- );
-
- public static final VarHandle ctrltransfer_bRequestType = ctrltransfer$Struct.varHandle(groupElement("bRequestType"));
- public static final VarHandle ctrltransfer_bRequest = ctrltransfer$Struct.varHandle(groupElement("bRequest"));
- public static final VarHandle ctrltransfer_wValue = ctrltransfer$Struct.varHandle(groupElement("wValue"));
- public static final VarHandle ctrltransfer_wIndex = ctrltransfer$Struct.varHandle(groupElement("wIndex"));
- public static final VarHandle ctrltransfer_wLength = ctrltransfer$Struct.varHandle(groupElement("wLength"));
- public static final VarHandle ctrltransfer_timeout = ctrltransfer$Struct.varHandle(groupElement("timeout"));
- public static final VarHandle ctrltransfer_data = ctrltransfer$Struct.varHandle(groupElement("data"));
-
- // struct usbdevfs_bulktransfer {
- // unsigned int ep;
- // unsigned int len;
- // unsigned int timeout; /* in milliseconds */
- // void *data;
- //};
- public static final GroupLayout bulktransfer$Struct = structLayout(
- JAVA_INT.withName("ep"),
- JAVA_INT.withName("len"),
- JAVA_INT.withName("timeout"),
- paddingLayout(4 * 8),
- ADDRESS.withName("data")
- );
-
- public static final VarHandle bulktransfer_ep = bulktransfer$Struct.varHandle(groupElement("ep"));
- public static final VarHandle bulktransfer_len = bulktransfer$Struct.varHandle(groupElement("len"));
- public static final VarHandle bulktransfer_timeout = bulktransfer$Struct.varHandle(groupElement("timeout"));
- public static final VarHandle bulktransfer_data = bulktransfer$Struct.varHandle(groupElement("data"));
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/Kernel.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/Kernel.java
index 326accf2..f7c8103d 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/Kernel.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/Kernel.java
@@ -7,11 +7,12 @@
package net.codecrete.usb.macos;
-import java.lang.foreign.*;
+import java.lang.foreign.Addressable;
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.foreign.Linker;
+import java.lang.foreign.MemorySession;
import java.lang.invoke.MethodHandle;
-import java.util.Optional;
-import static java.lang.foreign.MemoryAddress.NULL;
import static java.lang.foreign.ValueLayout.ADDRESS;
import static java.lang.foreign.ValueLayout.JAVA_INT;
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/Constants$root.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/Constants$root.java
index 14626843..7697ff6a 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/Constants$root.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/Constants$root.java
@@ -2,10 +2,6 @@
package net.codecrete.usb.macos.gen;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.VarHandle;
-import java.nio.ByteOrder;
-import java.lang.foreign.*;
import static java.lang.foreign.ValueLayout.*;
public class Constants$root {
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/RuntimeHelper.java
index 01993f2e..9cf8e4d1 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/RuntimeHelper.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/RuntimeHelper.java
@@ -1,28 +1,11 @@
package net.codecrete.usb.macos.gen;
// Generated by jextract
-import java.lang.foreign.Addressable;
-import java.lang.foreign.Linker;
-import java.lang.foreign.FunctionDescriptor;
-import java.lang.foreign.GroupLayout;
-import java.lang.foreign.SymbolLookup;
-import java.lang.foreign.MemoryAddress;
-import java.lang.foreign.MemoryLayout;
-import java.lang.foreign.MemorySegment;
-import java.lang.foreign.MemorySession;
-import java.lang.foreign.SegmentAllocator;
-import java.lang.foreign.ValueLayout;
+import java.lang.foreign.*;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
-import java.io.File;
-import java.nio.file.Path;
-import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-import java.util.Optional;
-import java.util.stream.Stream;
-
-import static java.lang.foreign.Linker.*;
+
import static java.lang.foreign.ValueLayout.*;
final class RuntimeHelper {
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/constants$0.java
index 9ec2b3a5..7e25031b 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/constants$0.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/constants$0.java
@@ -2,11 +2,8 @@
package net.codecrete.usb.macos.gen;
+import java.lang.foreign.FunctionDescriptor;
import java.lang.invoke.MethodHandle;
-import java.lang.invoke.VarHandle;
-import java.nio.ByteOrder;
-import java.lang.foreign.*;
-import static java.lang.foreign.ValueLayout.*;
class constants$0 {
static final FunctionDescriptor mach_error$FUNC = FunctionDescriptor.ofVoid(
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach_h.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach_h.java
index c739f909..24894eb4 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach_h.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach_h.java
@@ -2,10 +2,9 @@
package net.codecrete.usb.macos.gen;
+import java.lang.foreign.Addressable;
import java.lang.invoke.MethodHandle;
-import java.lang.invoke.VarHandle;
-import java.nio.ByteOrder;
-import java.lang.foreign.*;
+
import static java.lang.foreign.ValueLayout.*;
public class mach_h {
From 7be8874ba27045ea18dfea127dae5bbaf0d31461 Mon Sep 17 00:00:00 2001
From: Manuel Bl
Date: Mon, 22 Aug 2022 21:09:06 +0200
Subject: [PATCH 003/433] jextract on Linux (2)
---
.../usb/linux/gen/errno/Constants$root.java | 19 +
.../usb/linux/gen/errno/RuntimeHelper.java | 216 ++
.../usb/linux/gen/errno/constants$0.java | 16 +
.../codecrete/usb/linux/gen/errno/errno.java | 555 ++++
.../usb/linux/gen/fcntl/Constants$root.java | 19 +
.../usb/linux/gen/fcntl/RuntimeHelper.java | 216 ++
.../usb/linux/gen/fcntl/__fsid_t.java | 25 +
.../usb/linux/gen/fcntl/constants$0.java | 63 +
.../usb/linux/gen/fcntl/constants$1.java | 20 +
.../codecrete/usb/linux/gen/fcntl/fcntl.java | 686 +++++
.../codecrete/usb/linux/gen/fcntl/flock.java | 109 +
.../codecrete/usb/linux/gen/fcntl/stat.java | 234 ++
.../usb/linux/gen/fcntl/timespec.java | 56 +
.../usb/linux/gen/ioctl/Constants$root.java | 19 +
.../usb/linux/gen/ioctl/RuntimeHelper.java | 216 ++
.../usb/linux/gen/ioctl/constants$0.java | 19 +
.../codecrete/usb/linux/gen/ioctl/ioctl.java | 758 +++++
.../codecrete/usb/linux/gen/ioctl/termio.java | 112 +
.../usb/linux/gen/ioctl/winsize.java | 90 +
.../usb/linux/gen/unistd/Constants$root.java | 19 +
.../usb/linux/gen/unistd/RuntimeHelper.java | 216 ++
.../usb/linux/gen/unistd/__fsid_t.java | 25 +
.../usb/linux/gen/unistd/constants$0.java | 61 +
.../usb/linux/gen/unistd/constants$1.java | 61 +
.../usb/linux/gen/unistd/constants$10.java | 52 +
.../usb/linux/gen/unistd/constants$11.java | 65 +
.../usb/linux/gen/unistd/constants$12.java | 55 +
.../usb/linux/gen/unistd/constants$13.java | 44 +
.../usb/linux/gen/unistd/constants$14.java | 55 +
.../usb/linux/gen/unistd/constants$15.java | 50 +
.../usb/linux/gen/unistd/constants$16.java | 50 +
.../usb/linux/gen/unistd/constants$17.java | 51 +
.../usb/linux/gen/unistd/constants$18.java | 52 +
.../usb/linux/gen/unistd/constants$19.java | 17 +
.../usb/linux/gen/unistd/constants$2.java | 58 +
.../usb/linux/gen/unistd/constants$3.java | 58 +
.../usb/linux/gen/unistd/constants$4.java | 60 +
.../usb/linux/gen/unistd/constants$5.java | 57 +
.../usb/linux/gen/unistd/constants$6.java | 50 +
.../usb/linux/gen/unistd/constants$7.java | 50 +
.../usb/linux/gen/unistd/constants$8.java | 46 +
.../usb/linux/gen/unistd/constants$9.java | 53 +
.../usb/linux/gen/unistd/unistd.java | 2714 +++++++++++++++++
.../gen/usbdevice_fs/Constants$root.java | 19 +
.../linux/gen/usbdevice_fs/RuntimeHelper.java | 216 ++
.../gen/usbdevice_fs/__kernel_fd_set.java | 25 +
.../gen/usbdevice_fs/__kernel_fsid_t.java | 25 +
.../usbdevice_fs/__kernel_sighandler_t.java | 27 +
.../linux/gen/usbdevice_fs/constants$0.java | 21 +
.../usbdevice_fs/usbdevfs_bulktransfer.java | 91 +
.../usbdevice_fs/usbdevfs_connectinfo.java | 57 +
.../usbdevice_fs/usbdevfs_conninfo_ex.java | 111 +
.../usbdevice_fs/usbdevfs_ctrltransfer.java | 142 +
.../usbdevfs_disconnect_claim.java | 60 +
.../usbdevfs_disconnectsignal.java | 57 +
.../gen/usbdevice_fs/usbdevfs_getdriver.java | 43 +
.../usbdevice_fs/usbdevfs_hub_portinfo.java | 43 +
.../gen/usbdevice_fs/usbdevfs_ioctl.java | 73 +
.../usbdevfs_iso_packet_desc.java | 73 +
.../usbdevice_fs/usbdevfs_setinterface.java | 56 +
.../gen/usbdevice_fs/usbdevfs_streams.java | 57 +
.../linux/gen/usbdevice_fs/usbdevfs_urb.java | 252 ++
.../linux/gen/usbdevice_fs/usbdevice_fs.java | 366 +++
63 files changed, 9281 insertions(+)
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/Constants$root.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/RuntimeHelper.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/constants$0.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/errno.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/Constants$root.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/RuntimeHelper.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/__fsid_t.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/constants$0.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/constants$1.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/fcntl.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/flock.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/stat.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/timespec.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/Constants$root.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/RuntimeHelper.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/constants$0.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/ioctl.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/termio.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/winsize.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/Constants$root.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/RuntimeHelper.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/__fsid_t.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$0.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$1.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$10.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$11.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$12.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$13.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$14.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$15.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$16.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$17.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$18.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$19.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$2.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$3.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$4.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$5.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$6.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$7.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$8.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$9.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/unistd.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/Constants$root.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/RuntimeHelper.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/__kernel_fd_set.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/__kernel_fsid_t.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/__kernel_sighandler_t.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$0.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_bulktransfer.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_connectinfo.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_conninfo_ex.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_ctrltransfer.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_disconnect_claim.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_disconnectsignal.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_getdriver.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_hub_portinfo.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_ioctl.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_iso_packet_desc.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_setinterface.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_streams.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_urb.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevice_fs.java
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/Constants$root.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/Constants$root.java
new file mode 100644
index 00000000..73adc572
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/Constants$root.java
@@ -0,0 +1,19 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.errno;
+
+import static java.lang.foreign.ValueLayout.*;
+public class Constants$root {
+
+ static final OfBoolean C_BOOL$LAYOUT = JAVA_BOOLEAN;
+ static final OfByte C_CHAR$LAYOUT = JAVA_BYTE;
+ static final OfShort C_SHORT$LAYOUT = JAVA_SHORT.withBitAlignment(16);
+ static final OfInt C_INT$LAYOUT = JAVA_INT.withBitAlignment(32);
+ static final OfLong C_LONG$LAYOUT = JAVA_LONG.withBitAlignment(64);
+ static final OfLong C_LONG_LONG$LAYOUT = JAVA_LONG.withBitAlignment(64);
+ static final OfFloat C_FLOAT$LAYOUT = JAVA_FLOAT.withBitAlignment(32);
+ static final OfDouble C_DOUBLE$LAYOUT = JAVA_DOUBLE.withBitAlignment(64);
+ static final OfAddress C_POINTER$LAYOUT = ADDRESS.withBitAlignment(64);
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/RuntimeHelper.java
new file mode 100644
index 00000000..282b5dfb
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/RuntimeHelper.java
@@ -0,0 +1,216 @@
+package net.codecrete.usb.linux.gen.errno;
+// Generated by jextract
+
+import java.lang.foreign.*;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+
+import static java.lang.foreign.ValueLayout.*;
+
+final class RuntimeHelper {
+
+ private RuntimeHelper() {}
+ private final static Linker LINKER = Linker.nativeLinker();
+ private final static ClassLoader LOADER = RuntimeHelper.class.getClassLoader();
+ private final static MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup();
+ private final static SymbolLookup SYMBOL_LOOKUP;
+
+ final static SegmentAllocator CONSTANT_ALLOCATOR =
+ (size, align) -> MemorySegment.allocateNative(size, align, MemorySession.openImplicit());
+
+ static {
+
+ SymbolLookup loaderLookup = SymbolLookup.loaderLookup();
+ SYMBOL_LOOKUP = name -> loaderLookup.lookup(name).or(() -> LINKER.defaultLookup().lookup(name));
+ }
+
+ static T requireNonNull(T obj, String symbolName) {
+ if (obj == null) {
+ throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName);
+ }
+ return obj;
+ }
+
+ private final static SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); };
+
+ static final MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) {
+ return SYMBOL_LOOKUP.lookup(name).map(symbol -> MemorySegment.ofAddress(symbol.address(), layout.byteSize(), MemorySession.openShared())).orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> LINKER.downcallHandle(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(FunctionDescriptor fdesc) {
+ return LINKER.downcallHandle(fdesc);
+ }
+
+ static final MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> VarargsInvoker.make(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MemorySegment upcallStub(Class fi, Z z, FunctionDescriptor fdesc, MemorySession session) {
+ try {
+ MethodHandle handle = MH_LOOKUP.findVirtual(fi, "apply", Linker.upcallType(fdesc));
+ handle = handle.bindTo(z);
+ return LINKER.upcallStub(handle, fdesc, session);
+ } catch (Throwable ex) {
+ throw new AssertionError(ex);
+ }
+ }
+
+ static MemorySegment asArray(MemoryAddress addr, MemoryLayout layout, int numElements, MemorySession session) {
+ return MemorySegment.ofAddress(addr, numElements * layout.byteSize(), session);
+ }
+
+ // Internals only below this point
+
+ private static class VarargsInvoker {
+ private static final MethodHandle INVOKE_MH;
+ private final MemorySegment symbol;
+ private final FunctionDescriptor function;
+
+ private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) {
+ this.symbol = symbol;
+ this.function = function;
+ }
+
+ static {
+ try {
+ INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class));
+ } catch (ReflectiveOperationException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) {
+ VarargsInvoker invoker = new VarargsInvoker(symbol, function);
+ MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1);
+ MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class);
+ for (MemoryLayout layout : function.argumentLayouts()) {
+ mtype = mtype.appendParameterTypes(carrier(layout, false));
+ }
+ mtype = mtype.appendParameterTypes(Object[].class);
+ if (mtype.returnType().equals(MemorySegment.class)) {
+ mtype = mtype.insertParameterTypes(0, SegmentAllocator.class);
+ } else {
+ handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR);
+ }
+ return handle.asType(mtype);
+ }
+
+ static Class> carrier(MemoryLayout layout, boolean ret) {
+ if (layout instanceof ValueLayout valueLayout) {
+ return (ret || valueLayout.carrier() != MemoryAddress.class) ?
+ valueLayout.carrier() : Addressable.class;
+ } else if (layout instanceof GroupLayout) {
+ return MemorySegment.class;
+ } else {
+ throw new AssertionError("Cannot get here!");
+ }
+ }
+
+ private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable {
+ // one trailing Object[]
+ int nNamedArgs = function.argumentLayouts().size();
+ assert(args.length == nNamedArgs + 1);
+ // The last argument is the array of vararg collector
+ Object[] unnamedArgs = (Object[]) args[args.length - 1];
+
+ int argsCount = nNamedArgs + unnamedArgs.length;
+ Class>[] argTypes = new Class>[argsCount];
+ MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length];
+
+ int pos = 0;
+ for (pos = 0; pos < nNamedArgs; pos++) {
+ argLayouts[pos] = function.argumentLayouts().get(pos);
+ }
+
+ assert pos == nNamedArgs;
+ for (Object o: unnamedArgs) {
+ argLayouts[pos] = variadicLayout(normalize(o.getClass()));
+ pos++;
+ }
+ assert pos == argsCount;
+
+ FunctionDescriptor f = (function.returnLayout().isEmpty()) ?
+ FunctionDescriptor.ofVoid(argLayouts) :
+ FunctionDescriptor.of(function.returnLayout().get(), argLayouts);
+ MethodHandle mh = LINKER.downcallHandle(symbol, f);
+ if (mh.type().returnType() == MemorySegment.class) {
+ mh = mh.bindTo(allocator);
+ }
+ // flatten argument list so that it can be passed to an asSpreader MH
+ Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length];
+ System.arraycopy(args, 0, allArgs, 0, nNamedArgs);
+ System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length);
+
+ return mh.asSpreader(Object[].class, argsCount).invoke(allArgs);
+ }
+
+ private static Class> unboxIfNeeded(Class> clazz) {
+ if (clazz == Boolean.class) {
+ return boolean.class;
+ } else if (clazz == Void.class) {
+ return void.class;
+ } else if (clazz == Byte.class) {
+ return byte.class;
+ } else if (clazz == Character.class) {
+ return char.class;
+ } else if (clazz == Short.class) {
+ return short.class;
+ } else if (clazz == Integer.class) {
+ return int.class;
+ } else if (clazz == Long.class) {
+ return long.class;
+ } else if (clazz == Float.class) {
+ return float.class;
+ } else if (clazz == Double.class) {
+ return double.class;
+ } else {
+ return clazz;
+ }
+ }
+
+ private Class> promote(Class> c) {
+ if (c == byte.class || c == char.class || c == short.class || c == int.class) {
+ return long.class;
+ } else if (c == float.class) {
+ return double.class;
+ } else {
+ return c;
+ }
+ }
+
+ private Class> normalize(Class> c) {
+ c = unboxIfNeeded(c);
+ if (c.isPrimitive()) {
+ return promote(c);
+ }
+ if (MemoryAddress.class.isAssignableFrom(c)) {
+ return MemoryAddress.class;
+ }
+ if (MemorySegment.class.isAssignableFrom(c)) {
+ return MemorySegment.class;
+ }
+ throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName());
+ }
+
+ private MemoryLayout variadicLayout(Class> c) {
+ if (c == long.class) {
+ return JAVA_LONG;
+ } else if (c == double.class) {
+ return JAVA_DOUBLE;
+ } else if (MemoryAddress.class.isAssignableFrom(c)) {
+ return ADDRESS;
+ } else {
+ throw new IllegalArgumentException("Unhandled variadic argument class: " + c);
+ }
+ }
+ }
+}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/constants$0.java
new file mode 100644
index 00000000..cb3211ae
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/constants$0.java
@@ -0,0 +1,16 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.errno;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$0 {
+
+ static final FunctionDescriptor __errno_location$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT);
+ static final MethodHandle __errno_location$MH = RuntimeHelper.downcallHandle(
+ "__errno_location",
+ constants$0.__errno_location$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/errno.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/errno.java
new file mode 100644
index 00000000..2a42c554
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/errno.java
@@ -0,0 +1,555 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.errno;
+
+import java.lang.foreign.MemoryAddress;
+import java.lang.invoke.MethodHandle;
+
+import static java.lang.foreign.ValueLayout.*;
+public class errno {
+
+ /* package-private */ errno() {}
+ public static OfByte C_CHAR = Constants$root.C_CHAR$LAYOUT;
+ public static OfShort C_SHORT = Constants$root.C_SHORT$LAYOUT;
+ public static OfInt C_INT = Constants$root.C_INT$LAYOUT;
+ public static OfLong C_LONG = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong C_LONG_LONG = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfFloat C_FLOAT = Constants$root.C_FLOAT$LAYOUT;
+ public static OfDouble C_DOUBLE = Constants$root.C_DOUBLE$LAYOUT;
+ public static OfAddress C_POINTER = Constants$root.C_POINTER$LAYOUT;
+ public static int _ERRNO_H() {
+ return (int)1L;
+ }
+ public static int _FEATURES_H() {
+ return (int)1L;
+ }
+ public static int _DEFAULT_SOURCE() {
+ return (int)1L;
+ }
+ public static int __GLIBC_USE_ISOC2X() {
+ return (int)0L;
+ }
+ public static int __USE_ISOC11() {
+ return (int)1L;
+ }
+ public static int __USE_ISOC99() {
+ return (int)1L;
+ }
+ public static int __USE_ISOC95() {
+ return (int)1L;
+ }
+ public static int __USE_POSIX_IMPLICITLY() {
+ return (int)1L;
+ }
+ public static int _POSIX_SOURCE() {
+ return (int)1L;
+ }
+ public static int __USE_POSIX() {
+ return (int)1L;
+ }
+ public static int __USE_POSIX2() {
+ return (int)1L;
+ }
+ public static int __USE_POSIX199309() {
+ return (int)1L;
+ }
+ public static int __USE_POSIX199506() {
+ return (int)1L;
+ }
+ public static int __USE_XOPEN2K() {
+ return (int)1L;
+ }
+ public static int __USE_XOPEN2K8() {
+ return (int)1L;
+ }
+ public static int _ATFILE_SOURCE() {
+ return (int)1L;
+ }
+ public static int __WORDSIZE() {
+ return (int)64L;
+ }
+ public static int __WORDSIZE_TIME64_COMPAT32() {
+ return (int)1L;
+ }
+ public static int __SYSCALL_WORDSIZE() {
+ return (int)64L;
+ }
+ public static int __USE_MISC() {
+ return (int)1L;
+ }
+ public static int __USE_ATFILE() {
+ return (int)1L;
+ }
+ public static int __USE_FORTIFY_LEVEL() {
+ return (int)0L;
+ }
+ public static int __GLIBC_USE_DEPRECATED_GETS() {
+ return (int)0L;
+ }
+ public static int __GLIBC_USE_DEPRECATED_SCANF() {
+ return (int)0L;
+ }
+ public static int _STDC_PREDEF_H() {
+ return (int)1L;
+ }
+ public static int __STDC_IEC_559__() {
+ return (int)1L;
+ }
+ public static int __STDC_IEC_559_COMPLEX__() {
+ return (int)1L;
+ }
+ public static int __GNU_LIBRARY__() {
+ return (int)6L;
+ }
+ public static int __GLIBC__() {
+ return (int)2L;
+ }
+ public static int __GLIBC_MINOR__() {
+ return (int)35L;
+ }
+ public static int _SYS_CDEFS_H() {
+ return (int)1L;
+ }
+ public static int __glibc_c99_flexarr_available() {
+ return (int)1L;
+ }
+ public static int __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI() {
+ return (int)0L;
+ }
+ public static int __HAVE_GENERIC_SELECTION() {
+ return (int)1L;
+ }
+ public static int _BITS_ERRNO_H() {
+ return (int)1L;
+ }
+ public static int EPERM() {
+ return (int)1L;
+ }
+ public static int ENOENT() {
+ return (int)2L;
+ }
+ public static int ESRCH() {
+ return (int)3L;
+ }
+ public static int EINTR() {
+ return (int)4L;
+ }
+ public static int EIO() {
+ return (int)5L;
+ }
+ public static int ENXIO() {
+ return (int)6L;
+ }
+ public static int E2BIG() {
+ return (int)7L;
+ }
+ public static int ENOEXEC() {
+ return (int)8L;
+ }
+ public static int EBADF() {
+ return (int)9L;
+ }
+ public static int ECHILD() {
+ return (int)10L;
+ }
+ public static int EAGAIN() {
+ return (int)11L;
+ }
+ public static int ENOMEM() {
+ return (int)12L;
+ }
+ public static int EACCES() {
+ return (int)13L;
+ }
+ public static int EFAULT() {
+ return (int)14L;
+ }
+ public static int ENOTBLK() {
+ return (int)15L;
+ }
+ public static int EBUSY() {
+ return (int)16L;
+ }
+ public static int EEXIST() {
+ return (int)17L;
+ }
+ public static int EXDEV() {
+ return (int)18L;
+ }
+ public static int ENODEV() {
+ return (int)19L;
+ }
+ public static int ENOTDIR() {
+ return (int)20L;
+ }
+ public static int EISDIR() {
+ return (int)21L;
+ }
+ public static int EINVAL() {
+ return (int)22L;
+ }
+ public static int ENFILE() {
+ return (int)23L;
+ }
+ public static int EMFILE() {
+ return (int)24L;
+ }
+ public static int ENOTTY() {
+ return (int)25L;
+ }
+ public static int ETXTBSY() {
+ return (int)26L;
+ }
+ public static int EFBIG() {
+ return (int)27L;
+ }
+ public static int ENOSPC() {
+ return (int)28L;
+ }
+ public static int ESPIPE() {
+ return (int)29L;
+ }
+ public static int EROFS() {
+ return (int)30L;
+ }
+ public static int EMLINK() {
+ return (int)31L;
+ }
+ public static int EPIPE() {
+ return (int)32L;
+ }
+ public static int EDOM() {
+ return (int)33L;
+ }
+ public static int ERANGE() {
+ return (int)34L;
+ }
+ public static int EDEADLK() {
+ return (int)35L;
+ }
+ public static int ENAMETOOLONG() {
+ return (int)36L;
+ }
+ public static int ENOLCK() {
+ return (int)37L;
+ }
+ public static int ENOSYS() {
+ return (int)38L;
+ }
+ public static int ENOTEMPTY() {
+ return (int)39L;
+ }
+ public static int ELOOP() {
+ return (int)40L;
+ }
+ public static int ENOMSG() {
+ return (int)42L;
+ }
+ public static int EIDRM() {
+ return (int)43L;
+ }
+ public static int ECHRNG() {
+ return (int)44L;
+ }
+ public static int EL2NSYNC() {
+ return (int)45L;
+ }
+ public static int EL3HLT() {
+ return (int)46L;
+ }
+ public static int EL3RST() {
+ return (int)47L;
+ }
+ public static int ELNRNG() {
+ return (int)48L;
+ }
+ public static int EUNATCH() {
+ return (int)49L;
+ }
+ public static int ENOCSI() {
+ return (int)50L;
+ }
+ public static int EL2HLT() {
+ return (int)51L;
+ }
+ public static int EBADE() {
+ return (int)52L;
+ }
+ public static int EBADR() {
+ return (int)53L;
+ }
+ public static int EXFULL() {
+ return (int)54L;
+ }
+ public static int ENOANO() {
+ return (int)55L;
+ }
+ public static int EBADRQC() {
+ return (int)56L;
+ }
+ public static int EBADSLT() {
+ return (int)57L;
+ }
+ public static int EBFONT() {
+ return (int)59L;
+ }
+ public static int ENOSTR() {
+ return (int)60L;
+ }
+ public static int ENODATA() {
+ return (int)61L;
+ }
+ public static int ETIME() {
+ return (int)62L;
+ }
+ public static int ENOSR() {
+ return (int)63L;
+ }
+ public static int ENONET() {
+ return (int)64L;
+ }
+ public static int ENOPKG() {
+ return (int)65L;
+ }
+ public static int EREMOTE() {
+ return (int)66L;
+ }
+ public static int ENOLINK() {
+ return (int)67L;
+ }
+ public static int EADV() {
+ return (int)68L;
+ }
+ public static int ESRMNT() {
+ return (int)69L;
+ }
+ public static int ECOMM() {
+ return (int)70L;
+ }
+ public static int EPROTO() {
+ return (int)71L;
+ }
+ public static int EMULTIHOP() {
+ return (int)72L;
+ }
+ public static int EDOTDOT() {
+ return (int)73L;
+ }
+ public static int EBADMSG() {
+ return (int)74L;
+ }
+ public static int EOVERFLOW() {
+ return (int)75L;
+ }
+ public static int ENOTUNIQ() {
+ return (int)76L;
+ }
+ public static int EBADFD() {
+ return (int)77L;
+ }
+ public static int EREMCHG() {
+ return (int)78L;
+ }
+ public static int ELIBACC() {
+ return (int)79L;
+ }
+ public static int ELIBBAD() {
+ return (int)80L;
+ }
+ public static int ELIBSCN() {
+ return (int)81L;
+ }
+ public static int ELIBMAX() {
+ return (int)82L;
+ }
+ public static int ELIBEXEC() {
+ return (int)83L;
+ }
+ public static int EILSEQ() {
+ return (int)84L;
+ }
+ public static int ERESTART() {
+ return (int)85L;
+ }
+ public static int ESTRPIPE() {
+ return (int)86L;
+ }
+ public static int EUSERS() {
+ return (int)87L;
+ }
+ public static int ENOTSOCK() {
+ return (int)88L;
+ }
+ public static int EDESTADDRREQ() {
+ return (int)89L;
+ }
+ public static int EMSGSIZE() {
+ return (int)90L;
+ }
+ public static int EPROTOTYPE() {
+ return (int)91L;
+ }
+ public static int ENOPROTOOPT() {
+ return (int)92L;
+ }
+ public static int EPROTONOSUPPORT() {
+ return (int)93L;
+ }
+ public static int ESOCKTNOSUPPORT() {
+ return (int)94L;
+ }
+ public static int EOPNOTSUPP() {
+ return (int)95L;
+ }
+ public static int EPFNOSUPPORT() {
+ return (int)96L;
+ }
+ public static int EAFNOSUPPORT() {
+ return (int)97L;
+ }
+ public static int EADDRINUSE() {
+ return (int)98L;
+ }
+ public static int EADDRNOTAVAIL() {
+ return (int)99L;
+ }
+ public static int ENETDOWN() {
+ return (int)100L;
+ }
+ public static int ENETUNREACH() {
+ return (int)101L;
+ }
+ public static int ENETRESET() {
+ return (int)102L;
+ }
+ public static int ECONNABORTED() {
+ return (int)103L;
+ }
+ public static int ECONNRESET() {
+ return (int)104L;
+ }
+ public static int ENOBUFS() {
+ return (int)105L;
+ }
+ public static int EISCONN() {
+ return (int)106L;
+ }
+ public static int ENOTCONN() {
+ return (int)107L;
+ }
+ public static int ESHUTDOWN() {
+ return (int)108L;
+ }
+ public static int ETOOMANYREFS() {
+ return (int)109L;
+ }
+ public static int ETIMEDOUT() {
+ return (int)110L;
+ }
+ public static int ECONNREFUSED() {
+ return (int)111L;
+ }
+ public static int EHOSTDOWN() {
+ return (int)112L;
+ }
+ public static int EHOSTUNREACH() {
+ return (int)113L;
+ }
+ public static int EALREADY() {
+ return (int)114L;
+ }
+ public static int EINPROGRESS() {
+ return (int)115L;
+ }
+ public static int ESTALE() {
+ return (int)116L;
+ }
+ public static int EUCLEAN() {
+ return (int)117L;
+ }
+ public static int ENOTNAM() {
+ return (int)118L;
+ }
+ public static int ENAVAIL() {
+ return (int)119L;
+ }
+ public static int EISNAM() {
+ return (int)120L;
+ }
+ public static int EREMOTEIO() {
+ return (int)121L;
+ }
+ public static int EDQUOT() {
+ return (int)122L;
+ }
+ public static int ENOMEDIUM() {
+ return (int)123L;
+ }
+ public static int EMEDIUMTYPE() {
+ return (int)124L;
+ }
+ public static int ECANCELED() {
+ return (int)125L;
+ }
+ public static int ENOKEY() {
+ return (int)126L;
+ }
+ public static int EKEYEXPIRED() {
+ return (int)127L;
+ }
+ public static int EKEYREVOKED() {
+ return (int)128L;
+ }
+ public static int EKEYREJECTED() {
+ return (int)129L;
+ }
+ public static int EOWNERDEAD() {
+ return (int)130L;
+ }
+ public static int ENOTRECOVERABLE() {
+ return (int)131L;
+ }
+ public static int ERFKILL() {
+ return (int)132L;
+ }
+ public static int EHWPOISON() {
+ return (int)133L;
+ }
+ public static MethodHandle __errno_location$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.__errno_location$MH,"__errno_location");
+ }
+ public static MemoryAddress __errno_location () {
+ var mh$ = __errno_location$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact();
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static long _POSIX_C_SOURCE() {
+ return 200809L;
+ }
+ public static int __TIMESIZE() {
+ return (int)64L;
+ }
+ public static long __STDC_IEC_60559_BFP__() {
+ return 201404L;
+ }
+ public static long __STDC_IEC_60559_COMPLEX__() {
+ return 201404L;
+ }
+ public static long __STDC_ISO_10646__() {
+ return 201706L;
+ }
+ public static int EWOULDBLOCK() {
+ return (int)11L;
+ }
+ public static int EDEADLOCK() {
+ return (int)35L;
+ }
+ public static int ENOTSUP() {
+ return (int)95L;
+ }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/Constants$root.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/Constants$root.java
new file mode 100644
index 00000000..c938e854
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/Constants$root.java
@@ -0,0 +1,19 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.fcntl;
+
+import static java.lang.foreign.ValueLayout.*;
+public class Constants$root {
+
+ static final OfBoolean C_BOOL$LAYOUT = JAVA_BOOLEAN;
+ static final OfByte C_CHAR$LAYOUT = JAVA_BYTE;
+ static final OfShort C_SHORT$LAYOUT = JAVA_SHORT.withBitAlignment(16);
+ static final OfInt C_INT$LAYOUT = JAVA_INT.withBitAlignment(32);
+ static final OfLong C_LONG$LAYOUT = JAVA_LONG.withBitAlignment(64);
+ static final OfLong C_LONG_LONG$LAYOUT = JAVA_LONG.withBitAlignment(64);
+ static final OfFloat C_FLOAT$LAYOUT = JAVA_FLOAT.withBitAlignment(32);
+ static final OfDouble C_DOUBLE$LAYOUT = JAVA_DOUBLE.withBitAlignment(64);
+ static final OfAddress C_POINTER$LAYOUT = ADDRESS.withBitAlignment(64);
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/RuntimeHelper.java
new file mode 100644
index 00000000..48c09b33
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/RuntimeHelper.java
@@ -0,0 +1,216 @@
+package net.codecrete.usb.linux.gen.fcntl;
+// Generated by jextract
+
+import java.lang.foreign.*;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+
+import static java.lang.foreign.ValueLayout.*;
+
+final class RuntimeHelper {
+
+ private RuntimeHelper() {}
+ private final static Linker LINKER = Linker.nativeLinker();
+ private final static ClassLoader LOADER = RuntimeHelper.class.getClassLoader();
+ private final static MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup();
+ private final static SymbolLookup SYMBOL_LOOKUP;
+
+ final static SegmentAllocator CONSTANT_ALLOCATOR =
+ (size, align) -> MemorySegment.allocateNative(size, align, MemorySession.openImplicit());
+
+ static {
+
+ SymbolLookup loaderLookup = SymbolLookup.loaderLookup();
+ SYMBOL_LOOKUP = name -> loaderLookup.lookup(name).or(() -> LINKER.defaultLookup().lookup(name));
+ }
+
+ static T requireNonNull(T obj, String symbolName) {
+ if (obj == null) {
+ throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName);
+ }
+ return obj;
+ }
+
+ private final static SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); };
+
+ static final MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) {
+ return SYMBOL_LOOKUP.lookup(name).map(symbol -> MemorySegment.ofAddress(symbol.address(), layout.byteSize(), MemorySession.openShared())).orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> LINKER.downcallHandle(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(FunctionDescriptor fdesc) {
+ return LINKER.downcallHandle(fdesc);
+ }
+
+ static final MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> VarargsInvoker.make(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MemorySegment upcallStub(Class fi, Z z, FunctionDescriptor fdesc, MemorySession session) {
+ try {
+ MethodHandle handle = MH_LOOKUP.findVirtual(fi, "apply", Linker.upcallType(fdesc));
+ handle = handle.bindTo(z);
+ return LINKER.upcallStub(handle, fdesc, session);
+ } catch (Throwable ex) {
+ throw new AssertionError(ex);
+ }
+ }
+
+ static MemorySegment asArray(MemoryAddress addr, MemoryLayout layout, int numElements, MemorySession session) {
+ return MemorySegment.ofAddress(addr, numElements * layout.byteSize(), session);
+ }
+
+ // Internals only below this point
+
+ private static class VarargsInvoker {
+ private static final MethodHandle INVOKE_MH;
+ private final MemorySegment symbol;
+ private final FunctionDescriptor function;
+
+ private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) {
+ this.symbol = symbol;
+ this.function = function;
+ }
+
+ static {
+ try {
+ INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class));
+ } catch (ReflectiveOperationException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) {
+ VarargsInvoker invoker = new VarargsInvoker(symbol, function);
+ MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1);
+ MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class);
+ for (MemoryLayout layout : function.argumentLayouts()) {
+ mtype = mtype.appendParameterTypes(carrier(layout, false));
+ }
+ mtype = mtype.appendParameterTypes(Object[].class);
+ if (mtype.returnType().equals(MemorySegment.class)) {
+ mtype = mtype.insertParameterTypes(0, SegmentAllocator.class);
+ } else {
+ handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR);
+ }
+ return handle.asType(mtype);
+ }
+
+ static Class> carrier(MemoryLayout layout, boolean ret) {
+ if (layout instanceof ValueLayout valueLayout) {
+ return (ret || valueLayout.carrier() != MemoryAddress.class) ?
+ valueLayout.carrier() : Addressable.class;
+ } else if (layout instanceof GroupLayout) {
+ return MemorySegment.class;
+ } else {
+ throw new AssertionError("Cannot get here!");
+ }
+ }
+
+ private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable {
+ // one trailing Object[]
+ int nNamedArgs = function.argumentLayouts().size();
+ assert(args.length == nNamedArgs + 1);
+ // The last argument is the array of vararg collector
+ Object[] unnamedArgs = (Object[]) args[args.length - 1];
+
+ int argsCount = nNamedArgs + unnamedArgs.length;
+ Class>[] argTypes = new Class>[argsCount];
+ MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length];
+
+ int pos = 0;
+ for (pos = 0; pos < nNamedArgs; pos++) {
+ argLayouts[pos] = function.argumentLayouts().get(pos);
+ }
+
+ assert pos == nNamedArgs;
+ for (Object o: unnamedArgs) {
+ argLayouts[pos] = variadicLayout(normalize(o.getClass()));
+ pos++;
+ }
+ assert pos == argsCount;
+
+ FunctionDescriptor f = (function.returnLayout().isEmpty()) ?
+ FunctionDescriptor.ofVoid(argLayouts) :
+ FunctionDescriptor.of(function.returnLayout().get(), argLayouts);
+ MethodHandle mh = LINKER.downcallHandle(symbol, f);
+ if (mh.type().returnType() == MemorySegment.class) {
+ mh = mh.bindTo(allocator);
+ }
+ // flatten argument list so that it can be passed to an asSpreader MH
+ Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length];
+ System.arraycopy(args, 0, allArgs, 0, nNamedArgs);
+ System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length);
+
+ return mh.asSpreader(Object[].class, argsCount).invoke(allArgs);
+ }
+
+ private static Class> unboxIfNeeded(Class> clazz) {
+ if (clazz == Boolean.class) {
+ return boolean.class;
+ } else if (clazz == Void.class) {
+ return void.class;
+ } else if (clazz == Byte.class) {
+ return byte.class;
+ } else if (clazz == Character.class) {
+ return char.class;
+ } else if (clazz == Short.class) {
+ return short.class;
+ } else if (clazz == Integer.class) {
+ return int.class;
+ } else if (clazz == Long.class) {
+ return long.class;
+ } else if (clazz == Float.class) {
+ return float.class;
+ } else if (clazz == Double.class) {
+ return double.class;
+ } else {
+ return clazz;
+ }
+ }
+
+ private Class> promote(Class> c) {
+ if (c == byte.class || c == char.class || c == short.class || c == int.class) {
+ return long.class;
+ } else if (c == float.class) {
+ return double.class;
+ } else {
+ return c;
+ }
+ }
+
+ private Class> normalize(Class> c) {
+ c = unboxIfNeeded(c);
+ if (c.isPrimitive()) {
+ return promote(c);
+ }
+ if (MemoryAddress.class.isAssignableFrom(c)) {
+ return MemoryAddress.class;
+ }
+ if (MemorySegment.class.isAssignableFrom(c)) {
+ return MemorySegment.class;
+ }
+ throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName());
+ }
+
+ private MemoryLayout variadicLayout(Class> c) {
+ if (c == long.class) {
+ return JAVA_LONG;
+ } else if (c == double.class) {
+ return JAVA_DOUBLE;
+ } else if (MemoryAddress.class.isAssignableFrom(c)) {
+ return ADDRESS;
+ } else {
+ throw new IllegalArgumentException("Unhandled variadic argument class: " + c);
+ }
+ }
+ }
+}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/__fsid_t.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/__fsid_t.java
new file mode 100644
index 00000000..681bc974
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/__fsid_t.java
@@ -0,0 +1,25 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.fcntl;
+
+import java.lang.foreign.*;
+public class __fsid_t {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ MemoryLayout.sequenceLayout(2, Constants$root.C_INT$LAYOUT).withName("__val")
+ );
+ public static MemoryLayout $LAYOUT() {
+ return __fsid_t.$struct$LAYOUT;
+ }
+ public static MemorySegment __val$slice(MemorySegment seg) {
+ return seg.asSlice(0, 8);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/constants$0.java
new file mode 100644
index 00000000..5dadf164
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/constants$0.java
@@ -0,0 +1,63 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.fcntl;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$0 {
+
+ static final FunctionDescriptor fcntl$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle fcntl$MH = RuntimeHelper.downcallHandleVariadic(
+ "fcntl",
+ constants$0.fcntl$FUNC
+ );
+ static final FunctionDescriptor open$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle open$MH = RuntimeHelper.downcallHandleVariadic(
+ "open",
+ constants$0.open$FUNC
+ );
+ static final FunctionDescriptor openat$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle openat$MH = RuntimeHelper.downcallHandleVariadic(
+ "openat",
+ constants$0.openat$FUNC
+ );
+ static final FunctionDescriptor creat$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle creat$MH = RuntimeHelper.downcallHandle(
+ "creat",
+ constants$0.creat$FUNC
+ );
+ static final FunctionDescriptor lockf$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT
+ );
+ static final MethodHandle lockf$MH = RuntimeHelper.downcallHandle(
+ "lockf",
+ constants$0.lockf$FUNC
+ );
+ static final FunctionDescriptor posix_fadvise$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle posix_fadvise$MH = RuntimeHelper.downcallHandle(
+ "posix_fadvise",
+ constants$0.posix_fadvise$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/constants$1.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/constants$1.java
new file mode 100644
index 00000000..0c420af8
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/constants$1.java
@@ -0,0 +1,20 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.fcntl;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$1 {
+
+ static final FunctionDescriptor posix_fallocate$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT
+ );
+ static final MethodHandle posix_fallocate$MH = RuntimeHelper.downcallHandle(
+ "posix_fallocate",
+ constants$1.posix_fallocate$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/fcntl.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/fcntl.java
new file mode 100644
index 00000000..d2ce44d6
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/fcntl.java
@@ -0,0 +1,686 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.fcntl;
+
+import java.lang.foreign.Addressable;
+import java.lang.invoke.MethodHandle;
+
+import static java.lang.foreign.ValueLayout.*;
+public class fcntl {
+
+ /* package-private */ fcntl() {}
+ public static OfByte C_CHAR = Constants$root.C_CHAR$LAYOUT;
+ public static OfShort C_SHORT = Constants$root.C_SHORT$LAYOUT;
+ public static OfInt C_INT = Constants$root.C_INT$LAYOUT;
+ public static OfLong C_LONG = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong C_LONG_LONG = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfFloat C_FLOAT = Constants$root.C_FLOAT$LAYOUT;
+ public static OfDouble C_DOUBLE = Constants$root.C_DOUBLE$LAYOUT;
+ public static OfAddress C_POINTER = Constants$root.C_POINTER$LAYOUT;
+ public static int _FCNTL_H() {
+ return (int)1L;
+ }
+ public static int _FEATURES_H() {
+ return (int)1L;
+ }
+ public static int _DEFAULT_SOURCE() {
+ return (int)1L;
+ }
+ public static int __GLIBC_USE_ISOC2X() {
+ return (int)0L;
+ }
+ public static int __USE_ISOC11() {
+ return (int)1L;
+ }
+ public static int __USE_ISOC99() {
+ return (int)1L;
+ }
+ public static int __USE_ISOC95() {
+ return (int)1L;
+ }
+ public static int __USE_POSIX_IMPLICITLY() {
+ return (int)1L;
+ }
+ public static int _POSIX_SOURCE() {
+ return (int)1L;
+ }
+ public static int __USE_POSIX() {
+ return (int)1L;
+ }
+ public static int __USE_POSIX2() {
+ return (int)1L;
+ }
+ public static int __USE_POSIX199309() {
+ return (int)1L;
+ }
+ public static int __USE_POSIX199506() {
+ return (int)1L;
+ }
+ public static int __USE_XOPEN2K() {
+ return (int)1L;
+ }
+ public static int __USE_XOPEN2K8() {
+ return (int)1L;
+ }
+ public static int _ATFILE_SOURCE() {
+ return (int)1L;
+ }
+ public static int __WORDSIZE() {
+ return (int)64L;
+ }
+ public static int __WORDSIZE_TIME64_COMPAT32() {
+ return (int)1L;
+ }
+ public static int __SYSCALL_WORDSIZE() {
+ return (int)64L;
+ }
+ public static int __USE_MISC() {
+ return (int)1L;
+ }
+ public static int __USE_ATFILE() {
+ return (int)1L;
+ }
+ public static int __USE_FORTIFY_LEVEL() {
+ return (int)0L;
+ }
+ public static int __GLIBC_USE_DEPRECATED_GETS() {
+ return (int)0L;
+ }
+ public static int __GLIBC_USE_DEPRECATED_SCANF() {
+ return (int)0L;
+ }
+ public static int _STDC_PREDEF_H() {
+ return (int)1L;
+ }
+ public static int __STDC_IEC_559__() {
+ return (int)1L;
+ }
+ public static int __STDC_IEC_559_COMPLEX__() {
+ return (int)1L;
+ }
+ public static int __GNU_LIBRARY__() {
+ return (int)6L;
+ }
+ public static int __GLIBC__() {
+ return (int)2L;
+ }
+ public static int __GLIBC_MINOR__() {
+ return (int)35L;
+ }
+ public static int _SYS_CDEFS_H() {
+ return (int)1L;
+ }
+ public static int __glibc_c99_flexarr_available() {
+ return (int)1L;
+ }
+ public static int __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI() {
+ return (int)0L;
+ }
+ public static int __HAVE_GENERIC_SELECTION() {
+ return (int)1L;
+ }
+ public static int _BITS_TYPES_H() {
+ return (int)1L;
+ }
+ public static int _BITS_TYPESIZES_H() {
+ return (int)1L;
+ }
+ public static int __OFF_T_MATCHES_OFF64_T() {
+ return (int)1L;
+ }
+ public static int __INO_T_MATCHES_INO64_T() {
+ return (int)1L;
+ }
+ public static int __RLIM_T_MATCHES_RLIM64_T() {
+ return (int)1L;
+ }
+ public static int __STATFS_MATCHES_STATFS64() {
+ return (int)1L;
+ }
+ public static int __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64() {
+ return (int)1L;
+ }
+ public static int __FD_SETSIZE() {
+ return (int)1024L;
+ }
+ public static int _BITS_TIME64_H() {
+ return (int)1L;
+ }
+ public static int __O_LARGEFILE() {
+ return (int)0L;
+ }
+ public static int F_GETLK64() {
+ return (int)5L;
+ }
+ public static int F_SETLK64() {
+ return (int)6L;
+ }
+ public static int F_SETLKW64() {
+ return (int)7L;
+ }
+ public static int O_ACCMODE() {
+ return (int)3L;
+ }
+ public static int O_RDONLY() {
+ return (int)0L;
+ }
+ public static int O_WRONLY() {
+ return (int)1L;
+ }
+ public static int O_RDWR() {
+ return (int)2L;
+ }
+ public static int O_CREAT() {
+ return (int)64L;
+ }
+ public static int O_EXCL() {
+ return (int)128L;
+ }
+ public static int O_NOCTTY() {
+ return (int)256L;
+ }
+ public static int O_TRUNC() {
+ return (int)512L;
+ }
+ public static int O_APPEND() {
+ return (int)1024L;
+ }
+ public static int O_NONBLOCK() {
+ return (int)2048L;
+ }
+ public static int O_SYNC() {
+ return (int)1052672L;
+ }
+ public static int O_ASYNC() {
+ return (int)8192L;
+ }
+ public static int __O_DIRECTORY() {
+ return (int)65536L;
+ }
+ public static int __O_NOFOLLOW() {
+ return (int)131072L;
+ }
+ public static int __O_CLOEXEC() {
+ return (int)524288L;
+ }
+ public static int __O_DIRECT() {
+ return (int)16384L;
+ }
+ public static int __O_NOATIME() {
+ return (int)262144L;
+ }
+ public static int __O_PATH() {
+ return (int)2097152L;
+ }
+ public static int __O_DSYNC() {
+ return (int)4096L;
+ }
+ public static int F_GETLK() {
+ return (int)5L;
+ }
+ public static int F_SETLK() {
+ return (int)6L;
+ }
+ public static int F_SETLKW() {
+ return (int)7L;
+ }
+ public static int F_DUPFD() {
+ return (int)0L;
+ }
+ public static int F_GETFD() {
+ return (int)1L;
+ }
+ public static int F_SETFD() {
+ return (int)2L;
+ }
+ public static int F_GETFL() {
+ return (int)3L;
+ }
+ public static int F_SETFL() {
+ return (int)4L;
+ }
+ public static int __F_SETOWN() {
+ return (int)8L;
+ }
+ public static int __F_GETOWN() {
+ return (int)9L;
+ }
+ public static int __F_SETSIG() {
+ return (int)10L;
+ }
+ public static int __F_GETSIG() {
+ return (int)11L;
+ }
+ public static int __F_SETOWN_EX() {
+ return (int)15L;
+ }
+ public static int __F_GETOWN_EX() {
+ return (int)16L;
+ }
+ public static int F_DUPFD_CLOEXEC() {
+ return (int)1030L;
+ }
+ public static int FD_CLOEXEC() {
+ return (int)1L;
+ }
+ public static int F_RDLCK() {
+ return (int)0L;
+ }
+ public static int F_WRLCK() {
+ return (int)1L;
+ }
+ public static int F_UNLCK() {
+ return (int)2L;
+ }
+ public static int F_EXLCK() {
+ return (int)4L;
+ }
+ public static int F_SHLCK() {
+ return (int)8L;
+ }
+ public static int LOCK_SH() {
+ return (int)1L;
+ }
+ public static int LOCK_EX() {
+ return (int)2L;
+ }
+ public static int LOCK_NB() {
+ return (int)4L;
+ }
+ public static int LOCK_UN() {
+ return (int)8L;
+ }
+ public static int __POSIX_FADV_DONTNEED() {
+ return (int)4L;
+ }
+ public static int __POSIX_FADV_NOREUSE() {
+ return (int)5L;
+ }
+ public static int POSIX_FADV_NORMAL() {
+ return (int)0L;
+ }
+ public static int POSIX_FADV_RANDOM() {
+ return (int)1L;
+ }
+ public static int POSIX_FADV_SEQUENTIAL() {
+ return (int)2L;
+ }
+ public static int POSIX_FADV_WILLNEED() {
+ return (int)3L;
+ }
+ public static int AT_SYMLINK_NOFOLLOW() {
+ return (int)256L;
+ }
+ public static int AT_REMOVEDIR() {
+ return (int)512L;
+ }
+ public static int AT_SYMLINK_FOLLOW() {
+ return (int)1024L;
+ }
+ public static int AT_EACCESS() {
+ return (int)512L;
+ }
+ public static int _STRUCT_TIMESPEC() {
+ return (int)1L;
+ }
+ public static int _BITS_ENDIAN_H() {
+ return (int)1L;
+ }
+ public static int __LITTLE_ENDIAN() {
+ return (int)1234L;
+ }
+ public static int __BIG_ENDIAN() {
+ return (int)4321L;
+ }
+ public static int __PDP_ENDIAN() {
+ return (int)3412L;
+ }
+ public static int _BITS_ENDIANNESS_H() {
+ return (int)1L;
+ }
+ public static int __time_t_defined() {
+ return (int)1L;
+ }
+ public static int _BITS_STAT_H() {
+ return (int)1L;
+ }
+ public static int _BITS_STRUCT_STAT_H() {
+ return (int)1L;
+ }
+ public static int __S_IFMT() {
+ return (int)61440L;
+ }
+ public static int __S_IFDIR() {
+ return (int)16384L;
+ }
+ public static int __S_IFCHR() {
+ return (int)8192L;
+ }
+ public static int __S_IFBLK() {
+ return (int)24576L;
+ }
+ public static int __S_IFREG() {
+ return (int)32768L;
+ }
+ public static int __S_IFIFO() {
+ return (int)4096L;
+ }
+ public static int __S_IFLNK() {
+ return (int)40960L;
+ }
+ public static int __S_IFSOCK() {
+ return (int)49152L;
+ }
+ public static int __S_ISUID() {
+ return (int)2048L;
+ }
+ public static int __S_ISGID() {
+ return (int)1024L;
+ }
+ public static int __S_ISVTX() {
+ return (int)512L;
+ }
+ public static int __S_IREAD() {
+ return (int)256L;
+ }
+ public static int __S_IWRITE() {
+ return (int)128L;
+ }
+ public static int __S_IEXEC() {
+ return (int)64L;
+ }
+ public static int R_OK() {
+ return (int)4L;
+ }
+ public static int W_OK() {
+ return (int)2L;
+ }
+ public static int X_OK() {
+ return (int)1L;
+ }
+ public static int F_OK() {
+ return (int)0L;
+ }
+ public static int SEEK_SET() {
+ return (int)0L;
+ }
+ public static int SEEK_CUR() {
+ return (int)1L;
+ }
+ public static int SEEK_END() {
+ return (int)2L;
+ }
+ public static int F_ULOCK() {
+ return (int)0L;
+ }
+ public static int F_LOCK() {
+ return (int)1L;
+ }
+ public static int F_TLOCK() {
+ return (int)2L;
+ }
+ public static int F_TEST() {
+ return (int)3L;
+ }
+ public static OfShort __int16_t = Constants$root.C_SHORT$LAYOUT;
+ public static OfInt __int32_t = Constants$root.C_INT$LAYOUT;
+ public static OfLong __int64_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfShort __int_least16_t = Constants$root.C_SHORT$LAYOUT;
+ public static OfInt __int_least32_t = Constants$root.C_INT$LAYOUT;
+ public static OfLong __int_least64_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __quad_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __intmax_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __off_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __off64_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfInt __pid_t = Constants$root.C_INT$LAYOUT;
+ public static OfLong __clock_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __time_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __suseconds_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __suseconds64_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfInt __daddr_t = Constants$root.C_INT$LAYOUT;
+ public static OfInt __key_t = Constants$root.C_INT$LAYOUT;
+ public static OfInt __clockid_t = Constants$root.C_INT$LAYOUT;
+ public static OfAddress __timer_t = Constants$root.C_POINTER$LAYOUT;
+ public static OfLong __blksize_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __blkcnt_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __blkcnt64_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __fsword_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __ssize_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __syscall_slong_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __loff_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfAddress __caddr_t = Constants$root.C_POINTER$LAYOUT;
+ public static OfLong __intptr_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfInt __sig_atomic_t = Constants$root.C_INT$LAYOUT;
+ public static OfLong off_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfInt pid_t = Constants$root.C_INT$LAYOUT;
+ public static OfLong time_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static MethodHandle fcntl$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.fcntl$MH,"fcntl");
+ }
+ public static int fcntl ( int __fd, int __cmd, Object... x2) {
+ var mh$ = fcntl$MH();
+ try {
+ return (int)mh$.invokeExact(__fd, __cmd, x2);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle open$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.open$MH,"open");
+ }
+ public static int open ( Addressable __file, int __oflag, Object... x2) {
+ var mh$ = open$MH();
+ try {
+ return (int)mh$.invokeExact(__file, __oflag, x2);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle openat$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.openat$MH,"openat");
+ }
+ public static int openat ( int __fd, Addressable __file, int __oflag, Object... x3) {
+ var mh$ = openat$MH();
+ try {
+ return (int)mh$.invokeExact(__fd, __file, __oflag, x3);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle creat$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.creat$MH,"creat");
+ }
+ public static int creat ( Addressable __file, int __mode) {
+ var mh$ = creat$MH();
+ try {
+ return (int)mh$.invokeExact(__file, __mode);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle lockf$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.lockf$MH,"lockf");
+ }
+ public static int lockf ( int __fd, int __cmd, long __len) {
+ var mh$ = lockf$MH();
+ try {
+ return (int)mh$.invokeExact(__fd, __cmd, __len);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle posix_fadvise$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.posix_fadvise$MH,"posix_fadvise");
+ }
+ public static int posix_fadvise ( int __fd, long __offset, long __len, int __advise) {
+ var mh$ = posix_fadvise$MH();
+ try {
+ return (int)mh$.invokeExact(__fd, __offset, __len, __advise);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle posix_fallocate$MH() {
+ return RuntimeHelper.requireNonNull(constants$1.posix_fallocate$MH,"posix_fallocate");
+ }
+ public static int posix_fallocate ( int __fd, long __offset, long __len) {
+ var mh$ = posix_fallocate$MH();
+ try {
+ return (int)mh$.invokeExact(__fd, __offset, __len);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static long _POSIX_C_SOURCE() {
+ return 200809L;
+ }
+ public static int __TIMESIZE() {
+ return (int)64L;
+ }
+ public static long __STDC_IEC_60559_BFP__() {
+ return 201404L;
+ }
+ public static long __STDC_IEC_60559_COMPLEX__() {
+ return 201404L;
+ }
+ public static long __STDC_ISO_10646__() {
+ return 201706L;
+ }
+ public static int O_NDELAY() {
+ return (int)2048L;
+ }
+ public static int O_FSYNC() {
+ return (int)1052672L;
+ }
+ public static int __O_TMPFILE() {
+ return (int)4259840L;
+ }
+ public static int O_DIRECTORY() {
+ return (int)65536L;
+ }
+ public static int O_NOFOLLOW() {
+ return (int)131072L;
+ }
+ public static int O_CLOEXEC() {
+ return (int)524288L;
+ }
+ public static int O_DSYNC() {
+ return (int)4096L;
+ }
+ public static int O_RSYNC() {
+ return (int)1052672L;
+ }
+ public static int F_SETOWN() {
+ return (int)8L;
+ }
+ public static int F_GETOWN() {
+ return (int)9L;
+ }
+ public static int FAPPEND() {
+ return (int)1024L;
+ }
+ public static int FFSYNC() {
+ return (int)1052672L;
+ }
+ public static int FASYNC() {
+ return (int)8192L;
+ }
+ public static int FNONBLOCK() {
+ return (int)2048L;
+ }
+ public static int FNDELAY() {
+ return (int)2048L;
+ }
+ public static int POSIX_FADV_DONTNEED() {
+ return (int)4L;
+ }
+ public static int POSIX_FADV_NOREUSE() {
+ return (int)5L;
+ }
+ public static int AT_FDCWD() {
+ return (int)-100L;
+ }
+ public static int __BYTE_ORDER() {
+ return (int)1234L;
+ }
+ public static int __FLOAT_WORD_ORDER() {
+ return (int)1234L;
+ }
+ public static long UTIME_NOW() {
+ return 1073741823L;
+ }
+ public static long UTIME_OMIT() {
+ return 1073741822L;
+ }
+ public static int S_IFMT() {
+ return (int)61440L;
+ }
+ public static int S_IFDIR() {
+ return (int)16384L;
+ }
+ public static int S_IFCHR() {
+ return (int)8192L;
+ }
+ public static int S_IFBLK() {
+ return (int)24576L;
+ }
+ public static int S_IFREG() {
+ return (int)32768L;
+ }
+ public static int S_IFIFO() {
+ return (int)4096L;
+ }
+ public static int S_IFLNK() {
+ return (int)40960L;
+ }
+ public static int S_IFSOCK() {
+ return (int)49152L;
+ }
+ public static int S_ISUID() {
+ return (int)2048L;
+ }
+ public static int S_ISGID() {
+ return (int)1024L;
+ }
+ public static int S_ISVTX() {
+ return (int)512L;
+ }
+ public static int S_IRUSR() {
+ return (int)256L;
+ }
+ public static int S_IWUSR() {
+ return (int)128L;
+ }
+ public static int S_IXUSR() {
+ return (int)64L;
+ }
+ public static int S_IRWXU() {
+ return (int)448L;
+ }
+ public static int S_IRGRP() {
+ return (int)32L;
+ }
+ public static int S_IWGRP() {
+ return (int)16L;
+ }
+ public static int S_IXGRP() {
+ return (int)8L;
+ }
+ public static int S_IRWXG() {
+ return (int)56L;
+ }
+ public static int S_IROTH() {
+ return (int)4L;
+ }
+ public static int S_IWOTH() {
+ return (int)2L;
+ }
+ public static int S_IXOTH() {
+ return (int)1L;
+ }
+ public static int S_IRWXO() {
+ return (int)7L;
+ }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/flock.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/flock.java
new file mode 100644
index 00000000..e3192d4c
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/flock.java
@@ -0,0 +1,109 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.fcntl;
+
+import java.lang.foreign.*;
+import java.lang.invoke.VarHandle;
+public class flock {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ Constants$root.C_SHORT$LAYOUT.withName("l_type"),
+ Constants$root.C_SHORT$LAYOUT.withName("l_whence"),
+ MemoryLayout.paddingLayout(32),
+ Constants$root.C_LONG_LONG$LAYOUT.withName("l_start"),
+ Constants$root.C_LONG_LONG$LAYOUT.withName("l_len"),
+ Constants$root.C_INT$LAYOUT.withName("l_pid"),
+ MemoryLayout.paddingLayout(32)
+ ).withName("flock");
+ public static MemoryLayout $LAYOUT() {
+ return flock.$struct$LAYOUT;
+ }
+ static final VarHandle l_type$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("l_type"));
+ public static VarHandle l_type$VH() {
+ return flock.l_type$VH;
+ }
+ public static short l_type$get(MemorySegment seg) {
+ return (short)flock.l_type$VH.get(seg);
+ }
+ public static void l_type$set( MemorySegment seg, short x) {
+ flock.l_type$VH.set(seg, x);
+ }
+ public static short l_type$get(MemorySegment seg, long index) {
+ return (short)flock.l_type$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void l_type$set(MemorySegment seg, long index, short x) {
+ flock.l_type$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle l_whence$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("l_whence"));
+ public static VarHandle l_whence$VH() {
+ return flock.l_whence$VH;
+ }
+ public static short l_whence$get(MemorySegment seg) {
+ return (short)flock.l_whence$VH.get(seg);
+ }
+ public static void l_whence$set( MemorySegment seg, short x) {
+ flock.l_whence$VH.set(seg, x);
+ }
+ public static short l_whence$get(MemorySegment seg, long index) {
+ return (short)flock.l_whence$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void l_whence$set(MemorySegment seg, long index, short x) {
+ flock.l_whence$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle l_start$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("l_start"));
+ public static VarHandle l_start$VH() {
+ return flock.l_start$VH;
+ }
+ public static long l_start$get(MemorySegment seg) {
+ return (long)flock.l_start$VH.get(seg);
+ }
+ public static void l_start$set( MemorySegment seg, long x) {
+ flock.l_start$VH.set(seg, x);
+ }
+ public static long l_start$get(MemorySegment seg, long index) {
+ return (long)flock.l_start$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void l_start$set(MemorySegment seg, long index, long x) {
+ flock.l_start$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle l_len$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("l_len"));
+ public static VarHandle l_len$VH() {
+ return flock.l_len$VH;
+ }
+ public static long l_len$get(MemorySegment seg) {
+ return (long)flock.l_len$VH.get(seg);
+ }
+ public static void l_len$set( MemorySegment seg, long x) {
+ flock.l_len$VH.set(seg, x);
+ }
+ public static long l_len$get(MemorySegment seg, long index) {
+ return (long)flock.l_len$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void l_len$set(MemorySegment seg, long index, long x) {
+ flock.l_len$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle l_pid$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("l_pid"));
+ public static VarHandle l_pid$VH() {
+ return flock.l_pid$VH;
+ }
+ public static int l_pid$get(MemorySegment seg) {
+ return (int)flock.l_pid$VH.get(seg);
+ }
+ public static void l_pid$set( MemorySegment seg, int x) {
+ flock.l_pid$VH.set(seg, x);
+ }
+ public static int l_pid$get(MemorySegment seg, long index) {
+ return (int)flock.l_pid$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void l_pid$set(MemorySegment seg, long index, int x) {
+ flock.l_pid$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/stat.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/stat.java
new file mode 100644
index 00000000..c41afa20
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/stat.java
@@ -0,0 +1,234 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.fcntl;
+
+import java.lang.foreign.*;
+import java.lang.invoke.VarHandle;
+public class stat {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ Constants$root.C_LONG_LONG$LAYOUT.withName("st_dev"),
+ Constants$root.C_LONG_LONG$LAYOUT.withName("st_ino"),
+ Constants$root.C_LONG_LONG$LAYOUT.withName("st_nlink"),
+ Constants$root.C_INT$LAYOUT.withName("st_mode"),
+ Constants$root.C_INT$LAYOUT.withName("st_uid"),
+ Constants$root.C_INT$LAYOUT.withName("st_gid"),
+ Constants$root.C_INT$LAYOUT.withName("__pad0"),
+ Constants$root.C_LONG_LONG$LAYOUT.withName("st_rdev"),
+ Constants$root.C_LONG_LONG$LAYOUT.withName("st_size"),
+ Constants$root.C_LONG_LONG$LAYOUT.withName("st_blksize"),
+ Constants$root.C_LONG_LONG$LAYOUT.withName("st_blocks"),
+ MemoryLayout.structLayout(
+ Constants$root.C_LONG_LONG$LAYOUT.withName("tv_sec"),
+ Constants$root.C_LONG_LONG$LAYOUT.withName("tv_nsec")
+ ).withName("st_atim"),
+ MemoryLayout.structLayout(
+ Constants$root.C_LONG_LONG$LAYOUT.withName("tv_sec"),
+ Constants$root.C_LONG_LONG$LAYOUT.withName("tv_nsec")
+ ).withName("st_mtim"),
+ MemoryLayout.structLayout(
+ Constants$root.C_LONG_LONG$LAYOUT.withName("tv_sec"),
+ Constants$root.C_LONG_LONG$LAYOUT.withName("tv_nsec")
+ ).withName("st_ctim"),
+ MemoryLayout.sequenceLayout(3, Constants$root.C_LONG_LONG$LAYOUT).withName("__glibc_reserved")
+ ).withName("stat");
+ public static MemoryLayout $LAYOUT() {
+ return stat.$struct$LAYOUT;
+ }
+ static final VarHandle st_dev$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("st_dev"));
+ public static VarHandle st_dev$VH() {
+ return stat.st_dev$VH;
+ }
+ public static long st_dev$get(MemorySegment seg) {
+ return (long)stat.st_dev$VH.get(seg);
+ }
+ public static void st_dev$set( MemorySegment seg, long x) {
+ stat.st_dev$VH.set(seg, x);
+ }
+ public static long st_dev$get(MemorySegment seg, long index) {
+ return (long)stat.st_dev$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void st_dev$set(MemorySegment seg, long index, long x) {
+ stat.st_dev$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle st_ino$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("st_ino"));
+ public static VarHandle st_ino$VH() {
+ return stat.st_ino$VH;
+ }
+ public static long st_ino$get(MemorySegment seg) {
+ return (long)stat.st_ino$VH.get(seg);
+ }
+ public static void st_ino$set( MemorySegment seg, long x) {
+ stat.st_ino$VH.set(seg, x);
+ }
+ public static long st_ino$get(MemorySegment seg, long index) {
+ return (long)stat.st_ino$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void st_ino$set(MemorySegment seg, long index, long x) {
+ stat.st_ino$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle st_nlink$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("st_nlink"));
+ public static VarHandle st_nlink$VH() {
+ return stat.st_nlink$VH;
+ }
+ public static long st_nlink$get(MemorySegment seg) {
+ return (long)stat.st_nlink$VH.get(seg);
+ }
+ public static void st_nlink$set( MemorySegment seg, long x) {
+ stat.st_nlink$VH.set(seg, x);
+ }
+ public static long st_nlink$get(MemorySegment seg, long index) {
+ return (long)stat.st_nlink$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void st_nlink$set(MemorySegment seg, long index, long x) {
+ stat.st_nlink$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle st_mode$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("st_mode"));
+ public static VarHandle st_mode$VH() {
+ return stat.st_mode$VH;
+ }
+ public static int st_mode$get(MemorySegment seg) {
+ return (int)stat.st_mode$VH.get(seg);
+ }
+ public static void st_mode$set( MemorySegment seg, int x) {
+ stat.st_mode$VH.set(seg, x);
+ }
+ public static int st_mode$get(MemorySegment seg, long index) {
+ return (int)stat.st_mode$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void st_mode$set(MemorySegment seg, long index, int x) {
+ stat.st_mode$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle st_uid$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("st_uid"));
+ public static VarHandle st_uid$VH() {
+ return stat.st_uid$VH;
+ }
+ public static int st_uid$get(MemorySegment seg) {
+ return (int)stat.st_uid$VH.get(seg);
+ }
+ public static void st_uid$set( MemorySegment seg, int x) {
+ stat.st_uid$VH.set(seg, x);
+ }
+ public static int st_uid$get(MemorySegment seg, long index) {
+ return (int)stat.st_uid$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void st_uid$set(MemorySegment seg, long index, int x) {
+ stat.st_uid$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle st_gid$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("st_gid"));
+ public static VarHandle st_gid$VH() {
+ return stat.st_gid$VH;
+ }
+ public static int st_gid$get(MemorySegment seg) {
+ return (int)stat.st_gid$VH.get(seg);
+ }
+ public static void st_gid$set( MemorySegment seg, int x) {
+ stat.st_gid$VH.set(seg, x);
+ }
+ public static int st_gid$get(MemorySegment seg, long index) {
+ return (int)stat.st_gid$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void st_gid$set(MemorySegment seg, long index, int x) {
+ stat.st_gid$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle __pad0$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("__pad0"));
+ public static VarHandle __pad0$VH() {
+ return stat.__pad0$VH;
+ }
+ public static int __pad0$get(MemorySegment seg) {
+ return (int)stat.__pad0$VH.get(seg);
+ }
+ public static void __pad0$set( MemorySegment seg, int x) {
+ stat.__pad0$VH.set(seg, x);
+ }
+ public static int __pad0$get(MemorySegment seg, long index) {
+ return (int)stat.__pad0$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void __pad0$set(MemorySegment seg, long index, int x) {
+ stat.__pad0$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle st_rdev$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("st_rdev"));
+ public static VarHandle st_rdev$VH() {
+ return stat.st_rdev$VH;
+ }
+ public static long st_rdev$get(MemorySegment seg) {
+ return (long)stat.st_rdev$VH.get(seg);
+ }
+ public static void st_rdev$set( MemorySegment seg, long x) {
+ stat.st_rdev$VH.set(seg, x);
+ }
+ public static long st_rdev$get(MemorySegment seg, long index) {
+ return (long)stat.st_rdev$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void st_rdev$set(MemorySegment seg, long index, long x) {
+ stat.st_rdev$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle st_size$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("st_size"));
+ public static VarHandle st_size$VH() {
+ return stat.st_size$VH;
+ }
+ public static long st_size$get(MemorySegment seg) {
+ return (long)stat.st_size$VH.get(seg);
+ }
+ public static void st_size$set( MemorySegment seg, long x) {
+ stat.st_size$VH.set(seg, x);
+ }
+ public static long st_size$get(MemorySegment seg, long index) {
+ return (long)stat.st_size$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void st_size$set(MemorySegment seg, long index, long x) {
+ stat.st_size$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle st_blksize$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("st_blksize"));
+ public static VarHandle st_blksize$VH() {
+ return stat.st_blksize$VH;
+ }
+ public static long st_blksize$get(MemorySegment seg) {
+ return (long)stat.st_blksize$VH.get(seg);
+ }
+ public static void st_blksize$set( MemorySegment seg, long x) {
+ stat.st_blksize$VH.set(seg, x);
+ }
+ public static long st_blksize$get(MemorySegment seg, long index) {
+ return (long)stat.st_blksize$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void st_blksize$set(MemorySegment seg, long index, long x) {
+ stat.st_blksize$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle st_blocks$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("st_blocks"));
+ public static VarHandle st_blocks$VH() {
+ return stat.st_blocks$VH;
+ }
+ public static long st_blocks$get(MemorySegment seg) {
+ return (long)stat.st_blocks$VH.get(seg);
+ }
+ public static void st_blocks$set( MemorySegment seg, long x) {
+ stat.st_blocks$VH.set(seg, x);
+ }
+ public static long st_blocks$get(MemorySegment seg, long index) {
+ return (long)stat.st_blocks$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void st_blocks$set(MemorySegment seg, long index, long x) {
+ stat.st_blocks$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static MemorySegment st_atim$slice(MemorySegment seg) {
+ return seg.asSlice(72, 16);
+ }
+ public static MemorySegment st_mtim$slice(MemorySegment seg) {
+ return seg.asSlice(88, 16);
+ }
+ public static MemorySegment st_ctim$slice(MemorySegment seg) {
+ return seg.asSlice(104, 16);
+ }
+ public static MemorySegment __glibc_reserved$slice(MemorySegment seg) {
+ return seg.asSlice(120, 24);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/timespec.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/timespec.java
new file mode 100644
index 00000000..5dae8dc0
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/timespec.java
@@ -0,0 +1,56 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.fcntl;
+
+import java.lang.foreign.*;
+import java.lang.invoke.VarHandle;
+public class timespec {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ Constants$root.C_LONG_LONG$LAYOUT.withName("tv_sec"),
+ Constants$root.C_LONG_LONG$LAYOUT.withName("tv_nsec")
+ ).withName("timespec");
+ public static MemoryLayout $LAYOUT() {
+ return timespec.$struct$LAYOUT;
+ }
+ static final VarHandle tv_sec$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("tv_sec"));
+ public static VarHandle tv_sec$VH() {
+ return timespec.tv_sec$VH;
+ }
+ public static long tv_sec$get(MemorySegment seg) {
+ return (long)timespec.tv_sec$VH.get(seg);
+ }
+ public static void tv_sec$set( MemorySegment seg, long x) {
+ timespec.tv_sec$VH.set(seg, x);
+ }
+ public static long tv_sec$get(MemorySegment seg, long index) {
+ return (long)timespec.tv_sec$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void tv_sec$set(MemorySegment seg, long index, long x) {
+ timespec.tv_sec$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle tv_nsec$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("tv_nsec"));
+ public static VarHandle tv_nsec$VH() {
+ return timespec.tv_nsec$VH;
+ }
+ public static long tv_nsec$get(MemorySegment seg) {
+ return (long)timespec.tv_nsec$VH.get(seg);
+ }
+ public static void tv_nsec$set( MemorySegment seg, long x) {
+ timespec.tv_nsec$VH.set(seg, x);
+ }
+ public static long tv_nsec$get(MemorySegment seg, long index) {
+ return (long)timespec.tv_nsec$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void tv_nsec$set(MemorySegment seg, long index, long x) {
+ timespec.tv_nsec$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/Constants$root.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/Constants$root.java
new file mode 100644
index 00000000..c9e48345
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/Constants$root.java
@@ -0,0 +1,19 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.ioctl;
+
+import static java.lang.foreign.ValueLayout.*;
+public class Constants$root {
+
+ static final OfBoolean C_BOOL$LAYOUT = JAVA_BOOLEAN;
+ static final OfByte C_CHAR$LAYOUT = JAVA_BYTE;
+ static final OfShort C_SHORT$LAYOUT = JAVA_SHORT.withBitAlignment(16);
+ static final OfInt C_INT$LAYOUT = JAVA_INT.withBitAlignment(32);
+ static final OfLong C_LONG$LAYOUT = JAVA_LONG.withBitAlignment(64);
+ static final OfLong C_LONG_LONG$LAYOUT = JAVA_LONG.withBitAlignment(64);
+ static final OfFloat C_FLOAT$LAYOUT = JAVA_FLOAT.withBitAlignment(32);
+ static final OfDouble C_DOUBLE$LAYOUT = JAVA_DOUBLE.withBitAlignment(64);
+ static final OfAddress C_POINTER$LAYOUT = ADDRESS.withBitAlignment(64);
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/RuntimeHelper.java
new file mode 100644
index 00000000..e7740016
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/RuntimeHelper.java
@@ -0,0 +1,216 @@
+package net.codecrete.usb.linux.gen.ioctl;
+// Generated by jextract
+
+import java.lang.foreign.*;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+
+import static java.lang.foreign.ValueLayout.*;
+
+final class RuntimeHelper {
+
+ private RuntimeHelper() {}
+ private final static Linker LINKER = Linker.nativeLinker();
+ private final static ClassLoader LOADER = RuntimeHelper.class.getClassLoader();
+ private final static MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup();
+ private final static SymbolLookup SYMBOL_LOOKUP;
+
+ final static SegmentAllocator CONSTANT_ALLOCATOR =
+ (size, align) -> MemorySegment.allocateNative(size, align, MemorySession.openImplicit());
+
+ static {
+
+ SymbolLookup loaderLookup = SymbolLookup.loaderLookup();
+ SYMBOL_LOOKUP = name -> loaderLookup.lookup(name).or(() -> LINKER.defaultLookup().lookup(name));
+ }
+
+ static T requireNonNull(T obj, String symbolName) {
+ if (obj == null) {
+ throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName);
+ }
+ return obj;
+ }
+
+ private final static SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); };
+
+ static final MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) {
+ return SYMBOL_LOOKUP.lookup(name).map(symbol -> MemorySegment.ofAddress(symbol.address(), layout.byteSize(), MemorySession.openShared())).orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> LINKER.downcallHandle(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(FunctionDescriptor fdesc) {
+ return LINKER.downcallHandle(fdesc);
+ }
+
+ static final MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> VarargsInvoker.make(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MemorySegment upcallStub(Class fi, Z z, FunctionDescriptor fdesc, MemorySession session) {
+ try {
+ MethodHandle handle = MH_LOOKUP.findVirtual(fi, "apply", Linker.upcallType(fdesc));
+ handle = handle.bindTo(z);
+ return LINKER.upcallStub(handle, fdesc, session);
+ } catch (Throwable ex) {
+ throw new AssertionError(ex);
+ }
+ }
+
+ static MemorySegment asArray(MemoryAddress addr, MemoryLayout layout, int numElements, MemorySession session) {
+ return MemorySegment.ofAddress(addr, numElements * layout.byteSize(), session);
+ }
+
+ // Internals only below this point
+
+ private static class VarargsInvoker {
+ private static final MethodHandle INVOKE_MH;
+ private final MemorySegment symbol;
+ private final FunctionDescriptor function;
+
+ private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) {
+ this.symbol = symbol;
+ this.function = function;
+ }
+
+ static {
+ try {
+ INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class));
+ } catch (ReflectiveOperationException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) {
+ VarargsInvoker invoker = new VarargsInvoker(symbol, function);
+ MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1);
+ MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class);
+ for (MemoryLayout layout : function.argumentLayouts()) {
+ mtype = mtype.appendParameterTypes(carrier(layout, false));
+ }
+ mtype = mtype.appendParameterTypes(Object[].class);
+ if (mtype.returnType().equals(MemorySegment.class)) {
+ mtype = mtype.insertParameterTypes(0, SegmentAllocator.class);
+ } else {
+ handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR);
+ }
+ return handle.asType(mtype);
+ }
+
+ static Class> carrier(MemoryLayout layout, boolean ret) {
+ if (layout instanceof ValueLayout valueLayout) {
+ return (ret || valueLayout.carrier() != MemoryAddress.class) ?
+ valueLayout.carrier() : Addressable.class;
+ } else if (layout instanceof GroupLayout) {
+ return MemorySegment.class;
+ } else {
+ throw new AssertionError("Cannot get here!");
+ }
+ }
+
+ private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable {
+ // one trailing Object[]
+ int nNamedArgs = function.argumentLayouts().size();
+ assert(args.length == nNamedArgs + 1);
+ // The last argument is the array of vararg collector
+ Object[] unnamedArgs = (Object[]) args[args.length - 1];
+
+ int argsCount = nNamedArgs + unnamedArgs.length;
+ Class>[] argTypes = new Class>[argsCount];
+ MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length];
+
+ int pos = 0;
+ for (pos = 0; pos < nNamedArgs; pos++) {
+ argLayouts[pos] = function.argumentLayouts().get(pos);
+ }
+
+ assert pos == nNamedArgs;
+ for (Object o: unnamedArgs) {
+ argLayouts[pos] = variadicLayout(normalize(o.getClass()));
+ pos++;
+ }
+ assert pos == argsCount;
+
+ FunctionDescriptor f = (function.returnLayout().isEmpty()) ?
+ FunctionDescriptor.ofVoid(argLayouts) :
+ FunctionDescriptor.of(function.returnLayout().get(), argLayouts);
+ MethodHandle mh = LINKER.downcallHandle(symbol, f);
+ if (mh.type().returnType() == MemorySegment.class) {
+ mh = mh.bindTo(allocator);
+ }
+ // flatten argument list so that it can be passed to an asSpreader MH
+ Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length];
+ System.arraycopy(args, 0, allArgs, 0, nNamedArgs);
+ System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length);
+
+ return mh.asSpreader(Object[].class, argsCount).invoke(allArgs);
+ }
+
+ private static Class> unboxIfNeeded(Class> clazz) {
+ if (clazz == Boolean.class) {
+ return boolean.class;
+ } else if (clazz == Void.class) {
+ return void.class;
+ } else if (clazz == Byte.class) {
+ return byte.class;
+ } else if (clazz == Character.class) {
+ return char.class;
+ } else if (clazz == Short.class) {
+ return short.class;
+ } else if (clazz == Integer.class) {
+ return int.class;
+ } else if (clazz == Long.class) {
+ return long.class;
+ } else if (clazz == Float.class) {
+ return float.class;
+ } else if (clazz == Double.class) {
+ return double.class;
+ } else {
+ return clazz;
+ }
+ }
+
+ private Class> promote(Class> c) {
+ if (c == byte.class || c == char.class || c == short.class || c == int.class) {
+ return long.class;
+ } else if (c == float.class) {
+ return double.class;
+ } else {
+ return c;
+ }
+ }
+
+ private Class> normalize(Class> c) {
+ c = unboxIfNeeded(c);
+ if (c.isPrimitive()) {
+ return promote(c);
+ }
+ if (MemoryAddress.class.isAssignableFrom(c)) {
+ return MemoryAddress.class;
+ }
+ if (MemorySegment.class.isAssignableFrom(c)) {
+ return MemorySegment.class;
+ }
+ throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName());
+ }
+
+ private MemoryLayout variadicLayout(Class> c) {
+ if (c == long.class) {
+ return JAVA_LONG;
+ } else if (c == double.class) {
+ return JAVA_DOUBLE;
+ } else if (MemoryAddress.class.isAssignableFrom(c)) {
+ return ADDRESS;
+ } else {
+ throw new IllegalArgumentException("Unhandled variadic argument class: " + c);
+ }
+ }
+ }
+}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/constants$0.java
new file mode 100644
index 00000000..e68a7892
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/constants$0.java
@@ -0,0 +1,19 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.ioctl;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$0 {
+
+ static final FunctionDescriptor ioctl$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT
+ );
+ static final MethodHandle ioctl$MH = RuntimeHelper.downcallHandleVariadic(
+ "ioctl",
+ constants$0.ioctl$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/ioctl.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/ioctl.java
new file mode 100644
index 00000000..795090b8
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/ioctl.java
@@ -0,0 +1,758 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.ioctl;
+
+import java.lang.invoke.MethodHandle;
+
+import static java.lang.foreign.ValueLayout.*;
+public class ioctl {
+
+ /* package-private */ ioctl() {}
+ public static OfByte C_CHAR = Constants$root.C_CHAR$LAYOUT;
+ public static OfShort C_SHORT = Constants$root.C_SHORT$LAYOUT;
+ public static OfInt C_INT = Constants$root.C_INT$LAYOUT;
+ public static OfLong C_LONG = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong C_LONG_LONG = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfFloat C_FLOAT = Constants$root.C_FLOAT$LAYOUT;
+ public static OfDouble C_DOUBLE = Constants$root.C_DOUBLE$LAYOUT;
+ public static OfAddress C_POINTER = Constants$root.C_POINTER$LAYOUT;
+ public static int _SYS_IOCTL_H() {
+ return (int)1L;
+ }
+ public static int _FEATURES_H() {
+ return (int)1L;
+ }
+ public static int _DEFAULT_SOURCE() {
+ return (int)1L;
+ }
+ public static int __GLIBC_USE_ISOC2X() {
+ return (int)0L;
+ }
+ public static int __USE_ISOC11() {
+ return (int)1L;
+ }
+ public static int __USE_ISOC99() {
+ return (int)1L;
+ }
+ public static int __USE_ISOC95() {
+ return (int)1L;
+ }
+ public static int __USE_POSIX_IMPLICITLY() {
+ return (int)1L;
+ }
+ public static int _POSIX_SOURCE() {
+ return (int)1L;
+ }
+ public static int __USE_POSIX() {
+ return (int)1L;
+ }
+ public static int __USE_POSIX2() {
+ return (int)1L;
+ }
+ public static int __USE_POSIX199309() {
+ return (int)1L;
+ }
+ public static int __USE_POSIX199506() {
+ return (int)1L;
+ }
+ public static int __USE_XOPEN2K() {
+ return (int)1L;
+ }
+ public static int __USE_XOPEN2K8() {
+ return (int)1L;
+ }
+ public static int _ATFILE_SOURCE() {
+ return (int)1L;
+ }
+ public static int __WORDSIZE() {
+ return (int)64L;
+ }
+ public static int __WORDSIZE_TIME64_COMPAT32() {
+ return (int)1L;
+ }
+ public static int __SYSCALL_WORDSIZE() {
+ return (int)64L;
+ }
+ public static int __USE_MISC() {
+ return (int)1L;
+ }
+ public static int __USE_ATFILE() {
+ return (int)1L;
+ }
+ public static int __USE_FORTIFY_LEVEL() {
+ return (int)0L;
+ }
+ public static int __GLIBC_USE_DEPRECATED_GETS() {
+ return (int)0L;
+ }
+ public static int __GLIBC_USE_DEPRECATED_SCANF() {
+ return (int)0L;
+ }
+ public static int _STDC_PREDEF_H() {
+ return (int)1L;
+ }
+ public static int __STDC_IEC_559__() {
+ return (int)1L;
+ }
+ public static int __STDC_IEC_559_COMPLEX__() {
+ return (int)1L;
+ }
+ public static int __GNU_LIBRARY__() {
+ return (int)6L;
+ }
+ public static int __GLIBC__() {
+ return (int)2L;
+ }
+ public static int __GLIBC_MINOR__() {
+ return (int)35L;
+ }
+ public static int _SYS_CDEFS_H() {
+ return (int)1L;
+ }
+ public static int __glibc_c99_flexarr_available() {
+ return (int)1L;
+ }
+ public static int __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI() {
+ return (int)0L;
+ }
+ public static int __HAVE_GENERIC_SELECTION() {
+ return (int)1L;
+ }
+ public static int _IOC_NRBITS() {
+ return (int)8L;
+ }
+ public static int _IOC_TYPEBITS() {
+ return (int)8L;
+ }
+ public static int _IOC_SIZEBITS() {
+ return (int)14L;
+ }
+ public static int _IOC_DIRBITS() {
+ return (int)2L;
+ }
+ public static int _IOC_NRSHIFT() {
+ return (int)0L;
+ }
+ public static int TCGETS() {
+ return (int)21505L;
+ }
+ public static int TCSETS() {
+ return (int)21506L;
+ }
+ public static int TCSETSW() {
+ return (int)21507L;
+ }
+ public static int TCSETSF() {
+ return (int)21508L;
+ }
+ public static int TCGETA() {
+ return (int)21509L;
+ }
+ public static int TCSETA() {
+ return (int)21510L;
+ }
+ public static int TCSETAW() {
+ return (int)21511L;
+ }
+ public static int TCSETAF() {
+ return (int)21512L;
+ }
+ public static int TCSBRK() {
+ return (int)21513L;
+ }
+ public static int TCXONC() {
+ return (int)21514L;
+ }
+ public static int TCFLSH() {
+ return (int)21515L;
+ }
+ public static int TIOCEXCL() {
+ return (int)21516L;
+ }
+ public static int TIOCNXCL() {
+ return (int)21517L;
+ }
+ public static int TIOCSCTTY() {
+ return (int)21518L;
+ }
+ public static int TIOCGPGRP() {
+ return (int)21519L;
+ }
+ public static int TIOCSPGRP() {
+ return (int)21520L;
+ }
+ public static int TIOCOUTQ() {
+ return (int)21521L;
+ }
+ public static int TIOCSTI() {
+ return (int)21522L;
+ }
+ public static int TIOCGWINSZ() {
+ return (int)21523L;
+ }
+ public static int TIOCSWINSZ() {
+ return (int)21524L;
+ }
+ public static int TIOCMGET() {
+ return (int)21525L;
+ }
+ public static int TIOCMBIS() {
+ return (int)21526L;
+ }
+ public static int TIOCMBIC() {
+ return (int)21527L;
+ }
+ public static int TIOCMSET() {
+ return (int)21528L;
+ }
+ public static int TIOCGSOFTCAR() {
+ return (int)21529L;
+ }
+ public static int TIOCSSOFTCAR() {
+ return (int)21530L;
+ }
+ public static int FIONREAD() {
+ return (int)21531L;
+ }
+ public static int TIOCLINUX() {
+ return (int)21532L;
+ }
+ public static int TIOCCONS() {
+ return (int)21533L;
+ }
+ public static int TIOCGSERIAL() {
+ return (int)21534L;
+ }
+ public static int TIOCSSERIAL() {
+ return (int)21535L;
+ }
+ public static int TIOCPKT() {
+ return (int)21536L;
+ }
+ public static int FIONBIO() {
+ return (int)21537L;
+ }
+ public static int TIOCNOTTY() {
+ return (int)21538L;
+ }
+ public static int TIOCSETD() {
+ return (int)21539L;
+ }
+ public static int TIOCGETD() {
+ return (int)21540L;
+ }
+ public static int TCSBRKP() {
+ return (int)21541L;
+ }
+ public static int TIOCSBRK() {
+ return (int)21543L;
+ }
+ public static int TIOCCBRK() {
+ return (int)21544L;
+ }
+ public static int TIOCGSID() {
+ return (int)21545L;
+ }
+ public static int TIOCGRS485() {
+ return (int)21550L;
+ }
+ public static int TIOCSRS485() {
+ return (int)21551L;
+ }
+ public static int TCGETX() {
+ return (int)21554L;
+ }
+ public static int TCSETX() {
+ return (int)21555L;
+ }
+ public static int TCSETXF() {
+ return (int)21556L;
+ }
+ public static int TCSETXW() {
+ return (int)21557L;
+ }
+ public static int TIOCVHANGUP() {
+ return (int)21559L;
+ }
+ public static int FIONCLEX() {
+ return (int)21584L;
+ }
+ public static int FIOCLEX() {
+ return (int)21585L;
+ }
+ public static int FIOASYNC() {
+ return (int)21586L;
+ }
+ public static int TIOCSERCONFIG() {
+ return (int)21587L;
+ }
+ public static int TIOCSERGWILD() {
+ return (int)21588L;
+ }
+ public static int TIOCSERSWILD() {
+ return (int)21589L;
+ }
+ public static int TIOCGLCKTRMIOS() {
+ return (int)21590L;
+ }
+ public static int TIOCSLCKTRMIOS() {
+ return (int)21591L;
+ }
+ public static int TIOCSERGSTRUCT() {
+ return (int)21592L;
+ }
+ public static int TIOCSERGETLSR() {
+ return (int)21593L;
+ }
+ public static int TIOCSERGETMULTI() {
+ return (int)21594L;
+ }
+ public static int TIOCSERSETMULTI() {
+ return (int)21595L;
+ }
+ public static int TIOCMIWAIT() {
+ return (int)21596L;
+ }
+ public static int TIOCGICOUNT() {
+ return (int)21597L;
+ }
+ public static int FIOQSIZE() {
+ return (int)21600L;
+ }
+ public static int TIOCPKT_DATA() {
+ return (int)0L;
+ }
+ public static int TIOCPKT_FLUSHREAD() {
+ return (int)1L;
+ }
+ public static int TIOCPKT_FLUSHWRITE() {
+ return (int)2L;
+ }
+ public static int TIOCPKT_STOP() {
+ return (int)4L;
+ }
+ public static int TIOCPKT_START() {
+ return (int)8L;
+ }
+ public static int TIOCPKT_NOSTOP() {
+ return (int)16L;
+ }
+ public static int TIOCPKT_DOSTOP() {
+ return (int)32L;
+ }
+ public static int TIOCPKT_IOCTL() {
+ return (int)64L;
+ }
+ public static int TIOCSER_TEMT() {
+ return (int)1L;
+ }
+ public static int SIOCADDRT() {
+ return (int)35083L;
+ }
+ public static int SIOCDELRT() {
+ return (int)35084L;
+ }
+ public static int SIOCRTMSG() {
+ return (int)35085L;
+ }
+ public static int SIOCGIFNAME() {
+ return (int)35088L;
+ }
+ public static int SIOCSIFLINK() {
+ return (int)35089L;
+ }
+ public static int SIOCGIFCONF() {
+ return (int)35090L;
+ }
+ public static int SIOCGIFFLAGS() {
+ return (int)35091L;
+ }
+ public static int SIOCSIFFLAGS() {
+ return (int)35092L;
+ }
+ public static int SIOCGIFADDR() {
+ return (int)35093L;
+ }
+ public static int SIOCSIFADDR() {
+ return (int)35094L;
+ }
+ public static int SIOCGIFDSTADDR() {
+ return (int)35095L;
+ }
+ public static int SIOCSIFDSTADDR() {
+ return (int)35096L;
+ }
+ public static int SIOCGIFBRDADDR() {
+ return (int)35097L;
+ }
+ public static int SIOCSIFBRDADDR() {
+ return (int)35098L;
+ }
+ public static int SIOCGIFNETMASK() {
+ return (int)35099L;
+ }
+ public static int SIOCSIFNETMASK() {
+ return (int)35100L;
+ }
+ public static int SIOCGIFMETRIC() {
+ return (int)35101L;
+ }
+ public static int SIOCSIFMETRIC() {
+ return (int)35102L;
+ }
+ public static int SIOCGIFMEM() {
+ return (int)35103L;
+ }
+ public static int SIOCSIFMEM() {
+ return (int)35104L;
+ }
+ public static int SIOCGIFMTU() {
+ return (int)35105L;
+ }
+ public static int SIOCSIFMTU() {
+ return (int)35106L;
+ }
+ public static int SIOCSIFNAME() {
+ return (int)35107L;
+ }
+ public static int SIOCSIFHWADDR() {
+ return (int)35108L;
+ }
+ public static int SIOCGIFENCAP() {
+ return (int)35109L;
+ }
+ public static int SIOCSIFENCAP() {
+ return (int)35110L;
+ }
+ public static int SIOCGIFHWADDR() {
+ return (int)35111L;
+ }
+ public static int SIOCGIFSLAVE() {
+ return (int)35113L;
+ }
+ public static int SIOCSIFSLAVE() {
+ return (int)35120L;
+ }
+ public static int SIOCADDMULTI() {
+ return (int)35121L;
+ }
+ public static int SIOCDELMULTI() {
+ return (int)35122L;
+ }
+ public static int SIOCGIFINDEX() {
+ return (int)35123L;
+ }
+ public static int SIOCSIFPFLAGS() {
+ return (int)35124L;
+ }
+ public static int SIOCGIFPFLAGS() {
+ return (int)35125L;
+ }
+ public static int SIOCDIFADDR() {
+ return (int)35126L;
+ }
+ public static int SIOCSIFHWBROADCAST() {
+ return (int)35127L;
+ }
+ public static int SIOCGIFCOUNT() {
+ return (int)35128L;
+ }
+ public static int SIOCGIFBR() {
+ return (int)35136L;
+ }
+ public static int SIOCSIFBR() {
+ return (int)35137L;
+ }
+ public static int SIOCGIFTXQLEN() {
+ return (int)35138L;
+ }
+ public static int SIOCSIFTXQLEN() {
+ return (int)35139L;
+ }
+ public static int SIOCDARP() {
+ return (int)35155L;
+ }
+ public static int SIOCGARP() {
+ return (int)35156L;
+ }
+ public static int SIOCSARP() {
+ return (int)35157L;
+ }
+ public static int SIOCDRARP() {
+ return (int)35168L;
+ }
+ public static int SIOCGRARP() {
+ return (int)35169L;
+ }
+ public static int SIOCSRARP() {
+ return (int)35170L;
+ }
+ public static int SIOCGIFMAP() {
+ return (int)35184L;
+ }
+ public static int SIOCSIFMAP() {
+ return (int)35185L;
+ }
+ public static int SIOCADDDLCI() {
+ return (int)35200L;
+ }
+ public static int SIOCDELDLCI() {
+ return (int)35201L;
+ }
+ public static int SIOCDEVPRIVATE() {
+ return (int)35312L;
+ }
+ public static int SIOCPROTOPRIVATE() {
+ return (int)35296L;
+ }
+ public static int NCC() {
+ return (int)8L;
+ }
+ public static int TIOCM_LE() {
+ return (int)1L;
+ }
+ public static int TIOCM_DTR() {
+ return (int)2L;
+ }
+ public static int TIOCM_RTS() {
+ return (int)4L;
+ }
+ public static int TIOCM_ST() {
+ return (int)8L;
+ }
+ public static int TIOCM_SR() {
+ return (int)16L;
+ }
+ public static int TIOCM_CTS() {
+ return (int)32L;
+ }
+ public static int TIOCM_CAR() {
+ return (int)64L;
+ }
+ public static int TIOCM_RNG() {
+ return (int)128L;
+ }
+ public static int TIOCM_DSR() {
+ return (int)256L;
+ }
+ public static int N_TTY() {
+ return (int)0L;
+ }
+ public static int N_SLIP() {
+ return (int)1L;
+ }
+ public static int N_MOUSE() {
+ return (int)2L;
+ }
+ public static int N_PPP() {
+ return (int)3L;
+ }
+ public static int N_STRIP() {
+ return (int)4L;
+ }
+ public static int N_AX25() {
+ return (int)5L;
+ }
+ public static int N_X25() {
+ return (int)6L;
+ }
+ public static int N_6PACK() {
+ return (int)7L;
+ }
+ public static int N_MASC() {
+ return (int)8L;
+ }
+ public static int N_R3964() {
+ return (int)9L;
+ }
+ public static int N_PROFIBUS_FDL() {
+ return (int)10L;
+ }
+ public static int N_IRDA() {
+ return (int)11L;
+ }
+ public static int N_SMSBLOCK() {
+ return (int)12L;
+ }
+ public static int N_HDLC() {
+ return (int)13L;
+ }
+ public static int N_SYNC_PPP() {
+ return (int)14L;
+ }
+ public static int N_HCI() {
+ return (int)15L;
+ }
+ public static int CERASE() {
+ return (int)127L;
+ }
+ public static int CMIN() {
+ return (int)1L;
+ }
+ public static int CQUIT() {
+ return (int)28L;
+ }
+ public static int CTIME() {
+ return (int)0L;
+ }
+ public static MethodHandle ioctl$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.ioctl$MH,"ioctl");
+ }
+ public static int ioctl ( int __fd, long __request, Object... x2) {
+ var mh$ = ioctl$MH();
+ try {
+ return (int)mh$.invokeExact(__fd, __request, x2);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static long _POSIX_C_SOURCE() {
+ return 200809L;
+ }
+ public static int __TIMESIZE() {
+ return (int)64L;
+ }
+ public static long __STDC_IEC_60559_BFP__() {
+ return 201404L;
+ }
+ public static long __STDC_IEC_60559_COMPLEX__() {
+ return 201404L;
+ }
+ public static long __STDC_ISO_10646__() {
+ return 201706L;
+ }
+ public static int _IOC_NRMASK() {
+ return (int)255L;
+ }
+ public static int _IOC_TYPEMASK() {
+ return (int)255L;
+ }
+ public static int _IOC_SIZEMASK() {
+ return (int)16383L;
+ }
+ public static int _IOC_DIRMASK() {
+ return (int)3L;
+ }
+ public static int _IOC_TYPESHIFT() {
+ return (int)8L;
+ }
+ public static int _IOC_SIZESHIFT() {
+ return (int)16L;
+ }
+ public static int _IOC_DIRSHIFT() {
+ return (int)30L;
+ }
+ public static int _IOC_NONE() {
+ return (int)0L;
+ }
+ public static int _IOC_WRITE() {
+ return (int)1L;
+ }
+ public static int _IOC_READ() {
+ return (int)2L;
+ }
+ public static int IOC_IN() {
+ return (int)1073741824L;
+ }
+ public static int IOC_OUT() {
+ return (int)2147483648L;
+ }
+ public static int IOC_INOUT() {
+ return (int)3221225472L;
+ }
+ public static int IOCSIZE_MASK() {
+ return (int)1073676288L;
+ }
+ public static int IOCSIZE_SHIFT() {
+ return (int)16L;
+ }
+ public static int TIOCINQ() {
+ return (int)21531L;
+ }
+ public static long TIOCGPTN() {
+ return 2147767344L;
+ }
+ public static long TIOCSPTLCK() {
+ return 1074025521L;
+ }
+ public static long TIOCGDEV() {
+ return 2147767346L;
+ }
+ public static long TIOCSIG() {
+ return 1074025526L;
+ }
+ public static long TIOCGPKT() {
+ return 2147767352L;
+ }
+ public static long TIOCGPTLCK() {
+ return 2147767353L;
+ }
+ public static long TIOCGEXCL() {
+ return 2147767360L;
+ }
+ public static int TIOCGPTPEER() {
+ return (int)21569L;
+ }
+ public static int SIOGIFINDEX() {
+ return (int)35123L;
+ }
+ public static int TIOCM_CD() {
+ return (int)64L;
+ }
+ public static int TIOCM_RI() {
+ return (int)128L;
+ }
+ public static int CEOF() {
+ return (int)4L;
+ }
+ public static int CEOL() {
+ return (int)0L;
+ }
+ public static int CINTR() {
+ return (int)3L;
+ }
+ public static int CSTATUS() {
+ return (int)0L;
+ }
+ public static int CKILL() {
+ return (int)21L;
+ }
+ public static int CSUSP() {
+ return (int)26L;
+ }
+ public static int CDSUSP() {
+ return (int)25L;
+ }
+ public static int CSTART() {
+ return (int)17L;
+ }
+ public static int CSTOP() {
+ return (int)19L;
+ }
+ public static int CLNEXT() {
+ return (int)22L;
+ }
+ public static int CDISCARD() {
+ return (int)15L;
+ }
+ public static int CWERASE() {
+ return (int)23L;
+ }
+ public static int CREPRINT() {
+ return (int)18L;
+ }
+ public static int CEOT() {
+ return (int)4L;
+ }
+ public static int CBRK() {
+ return (int)0L;
+ }
+ public static int CRPRNT() {
+ return (int)18L;
+ }
+ public static int CFLUSH() {
+ return (int)15L;
+ }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/termio.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/termio.java
new file mode 100644
index 00000000..500ef096
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/termio.java
@@ -0,0 +1,112 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.ioctl;
+
+import java.lang.foreign.*;
+import java.lang.invoke.VarHandle;
+public class termio {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ Constants$root.C_SHORT$LAYOUT.withName("c_iflag"),
+ Constants$root.C_SHORT$LAYOUT.withName("c_oflag"),
+ Constants$root.C_SHORT$LAYOUT.withName("c_cflag"),
+ Constants$root.C_SHORT$LAYOUT.withName("c_lflag"),
+ Constants$root.C_CHAR$LAYOUT.withName("c_line"),
+ MemoryLayout.sequenceLayout(8, Constants$root.C_CHAR$LAYOUT).withName("c_cc"),
+ MemoryLayout.paddingLayout(8)
+ ).withName("termio");
+ public static MemoryLayout $LAYOUT() {
+ return termio.$struct$LAYOUT;
+ }
+ static final VarHandle c_iflag$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("c_iflag"));
+ public static VarHandle c_iflag$VH() {
+ return termio.c_iflag$VH;
+ }
+ public static short c_iflag$get(MemorySegment seg) {
+ return (short)termio.c_iflag$VH.get(seg);
+ }
+ public static void c_iflag$set( MemorySegment seg, short x) {
+ termio.c_iflag$VH.set(seg, x);
+ }
+ public static short c_iflag$get(MemorySegment seg, long index) {
+ return (short)termio.c_iflag$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void c_iflag$set(MemorySegment seg, long index, short x) {
+ termio.c_iflag$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle c_oflag$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("c_oflag"));
+ public static VarHandle c_oflag$VH() {
+ return termio.c_oflag$VH;
+ }
+ public static short c_oflag$get(MemorySegment seg) {
+ return (short)termio.c_oflag$VH.get(seg);
+ }
+ public static void c_oflag$set( MemorySegment seg, short x) {
+ termio.c_oflag$VH.set(seg, x);
+ }
+ public static short c_oflag$get(MemorySegment seg, long index) {
+ return (short)termio.c_oflag$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void c_oflag$set(MemorySegment seg, long index, short x) {
+ termio.c_oflag$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle c_cflag$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("c_cflag"));
+ public static VarHandle c_cflag$VH() {
+ return termio.c_cflag$VH;
+ }
+ public static short c_cflag$get(MemorySegment seg) {
+ return (short)termio.c_cflag$VH.get(seg);
+ }
+ public static void c_cflag$set( MemorySegment seg, short x) {
+ termio.c_cflag$VH.set(seg, x);
+ }
+ public static short c_cflag$get(MemorySegment seg, long index) {
+ return (short)termio.c_cflag$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void c_cflag$set(MemorySegment seg, long index, short x) {
+ termio.c_cflag$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle c_lflag$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("c_lflag"));
+ public static VarHandle c_lflag$VH() {
+ return termio.c_lflag$VH;
+ }
+ public static short c_lflag$get(MemorySegment seg) {
+ return (short)termio.c_lflag$VH.get(seg);
+ }
+ public static void c_lflag$set( MemorySegment seg, short x) {
+ termio.c_lflag$VH.set(seg, x);
+ }
+ public static short c_lflag$get(MemorySegment seg, long index) {
+ return (short)termio.c_lflag$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void c_lflag$set(MemorySegment seg, long index, short x) {
+ termio.c_lflag$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle c_line$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("c_line"));
+ public static VarHandle c_line$VH() {
+ return termio.c_line$VH;
+ }
+ public static byte c_line$get(MemorySegment seg) {
+ return (byte)termio.c_line$VH.get(seg);
+ }
+ public static void c_line$set( MemorySegment seg, byte x) {
+ termio.c_line$VH.set(seg, x);
+ }
+ public static byte c_line$get(MemorySegment seg, long index) {
+ return (byte)termio.c_line$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void c_line$set(MemorySegment seg, long index, byte x) {
+ termio.c_line$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static MemorySegment c_cc$slice(MemorySegment seg) {
+ return seg.asSlice(9, 8);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/winsize.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/winsize.java
new file mode 100644
index 00000000..d05924c2
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/winsize.java
@@ -0,0 +1,90 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.ioctl;
+
+import java.lang.foreign.*;
+import java.lang.invoke.VarHandle;
+public class winsize {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ Constants$root.C_SHORT$LAYOUT.withName("ws_row"),
+ Constants$root.C_SHORT$LAYOUT.withName("ws_col"),
+ Constants$root.C_SHORT$LAYOUT.withName("ws_xpixel"),
+ Constants$root.C_SHORT$LAYOUT.withName("ws_ypixel")
+ ).withName("winsize");
+ public static MemoryLayout $LAYOUT() {
+ return winsize.$struct$LAYOUT;
+ }
+ static final VarHandle ws_row$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("ws_row"));
+ public static VarHandle ws_row$VH() {
+ return winsize.ws_row$VH;
+ }
+ public static short ws_row$get(MemorySegment seg) {
+ return (short)winsize.ws_row$VH.get(seg);
+ }
+ public static void ws_row$set( MemorySegment seg, short x) {
+ winsize.ws_row$VH.set(seg, x);
+ }
+ public static short ws_row$get(MemorySegment seg, long index) {
+ return (short)winsize.ws_row$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void ws_row$set(MemorySegment seg, long index, short x) {
+ winsize.ws_row$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle ws_col$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("ws_col"));
+ public static VarHandle ws_col$VH() {
+ return winsize.ws_col$VH;
+ }
+ public static short ws_col$get(MemorySegment seg) {
+ return (short)winsize.ws_col$VH.get(seg);
+ }
+ public static void ws_col$set( MemorySegment seg, short x) {
+ winsize.ws_col$VH.set(seg, x);
+ }
+ public static short ws_col$get(MemorySegment seg, long index) {
+ return (short)winsize.ws_col$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void ws_col$set(MemorySegment seg, long index, short x) {
+ winsize.ws_col$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle ws_xpixel$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("ws_xpixel"));
+ public static VarHandle ws_xpixel$VH() {
+ return winsize.ws_xpixel$VH;
+ }
+ public static short ws_xpixel$get(MemorySegment seg) {
+ return (short)winsize.ws_xpixel$VH.get(seg);
+ }
+ public static void ws_xpixel$set( MemorySegment seg, short x) {
+ winsize.ws_xpixel$VH.set(seg, x);
+ }
+ public static short ws_xpixel$get(MemorySegment seg, long index) {
+ return (short)winsize.ws_xpixel$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void ws_xpixel$set(MemorySegment seg, long index, short x) {
+ winsize.ws_xpixel$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle ws_ypixel$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("ws_ypixel"));
+ public static VarHandle ws_ypixel$VH() {
+ return winsize.ws_ypixel$VH;
+ }
+ public static short ws_ypixel$get(MemorySegment seg) {
+ return (short)winsize.ws_ypixel$VH.get(seg);
+ }
+ public static void ws_ypixel$set( MemorySegment seg, short x) {
+ winsize.ws_ypixel$VH.set(seg, x);
+ }
+ public static short ws_ypixel$get(MemorySegment seg, long index) {
+ return (short)winsize.ws_ypixel$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void ws_ypixel$set(MemorySegment seg, long index, short x) {
+ winsize.ws_ypixel$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/Constants$root.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/Constants$root.java
new file mode 100644
index 00000000..1fe4e3c0
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/Constants$root.java
@@ -0,0 +1,19 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.unistd;
+
+import static java.lang.foreign.ValueLayout.*;
+public class Constants$root {
+
+ static final OfBoolean C_BOOL$LAYOUT = JAVA_BOOLEAN;
+ static final OfByte C_CHAR$LAYOUT = JAVA_BYTE;
+ static final OfShort C_SHORT$LAYOUT = JAVA_SHORT.withBitAlignment(16);
+ static final OfInt C_INT$LAYOUT = JAVA_INT.withBitAlignment(32);
+ static final OfLong C_LONG$LAYOUT = JAVA_LONG.withBitAlignment(64);
+ static final OfLong C_LONG_LONG$LAYOUT = JAVA_LONG.withBitAlignment(64);
+ static final OfFloat C_FLOAT$LAYOUT = JAVA_FLOAT.withBitAlignment(32);
+ static final OfDouble C_DOUBLE$LAYOUT = JAVA_DOUBLE.withBitAlignment(64);
+ static final OfAddress C_POINTER$LAYOUT = ADDRESS.withBitAlignment(64);
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/RuntimeHelper.java
new file mode 100644
index 00000000..b771271b
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/RuntimeHelper.java
@@ -0,0 +1,216 @@
+package net.codecrete.usb.linux.gen.unistd;
+// Generated by jextract
+
+import java.lang.foreign.*;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+
+import static java.lang.foreign.ValueLayout.*;
+
+final class RuntimeHelper {
+
+ private RuntimeHelper() {}
+ private final static Linker LINKER = Linker.nativeLinker();
+ private final static ClassLoader LOADER = RuntimeHelper.class.getClassLoader();
+ private final static MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup();
+ private final static SymbolLookup SYMBOL_LOOKUP;
+
+ final static SegmentAllocator CONSTANT_ALLOCATOR =
+ (size, align) -> MemorySegment.allocateNative(size, align, MemorySession.openImplicit());
+
+ static {
+
+ SymbolLookup loaderLookup = SymbolLookup.loaderLookup();
+ SYMBOL_LOOKUP = name -> loaderLookup.lookup(name).or(() -> LINKER.defaultLookup().lookup(name));
+ }
+
+ static T requireNonNull(T obj, String symbolName) {
+ if (obj == null) {
+ throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName);
+ }
+ return obj;
+ }
+
+ private final static SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); };
+
+ static final MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) {
+ return SYMBOL_LOOKUP.lookup(name).map(symbol -> MemorySegment.ofAddress(symbol.address(), layout.byteSize(), MemorySession.openShared())).orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> LINKER.downcallHandle(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(FunctionDescriptor fdesc) {
+ return LINKER.downcallHandle(fdesc);
+ }
+
+ static final MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> VarargsInvoker.make(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MemorySegment upcallStub(Class fi, Z z, FunctionDescriptor fdesc, MemorySession session) {
+ try {
+ MethodHandle handle = MH_LOOKUP.findVirtual(fi, "apply", Linker.upcallType(fdesc));
+ handle = handle.bindTo(z);
+ return LINKER.upcallStub(handle, fdesc, session);
+ } catch (Throwable ex) {
+ throw new AssertionError(ex);
+ }
+ }
+
+ static MemorySegment asArray(MemoryAddress addr, MemoryLayout layout, int numElements, MemorySession session) {
+ return MemorySegment.ofAddress(addr, numElements * layout.byteSize(), session);
+ }
+
+ // Internals only below this point
+
+ private static class VarargsInvoker {
+ private static final MethodHandle INVOKE_MH;
+ private final MemorySegment symbol;
+ private final FunctionDescriptor function;
+
+ private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) {
+ this.symbol = symbol;
+ this.function = function;
+ }
+
+ static {
+ try {
+ INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class));
+ } catch (ReflectiveOperationException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) {
+ VarargsInvoker invoker = new VarargsInvoker(symbol, function);
+ MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1);
+ MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class);
+ for (MemoryLayout layout : function.argumentLayouts()) {
+ mtype = mtype.appendParameterTypes(carrier(layout, false));
+ }
+ mtype = mtype.appendParameterTypes(Object[].class);
+ if (mtype.returnType().equals(MemorySegment.class)) {
+ mtype = mtype.insertParameterTypes(0, SegmentAllocator.class);
+ } else {
+ handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR);
+ }
+ return handle.asType(mtype);
+ }
+
+ static Class> carrier(MemoryLayout layout, boolean ret) {
+ if (layout instanceof ValueLayout valueLayout) {
+ return (ret || valueLayout.carrier() != MemoryAddress.class) ?
+ valueLayout.carrier() : Addressable.class;
+ } else if (layout instanceof GroupLayout) {
+ return MemorySegment.class;
+ } else {
+ throw new AssertionError("Cannot get here!");
+ }
+ }
+
+ private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable {
+ // one trailing Object[]
+ int nNamedArgs = function.argumentLayouts().size();
+ assert(args.length == nNamedArgs + 1);
+ // The last argument is the array of vararg collector
+ Object[] unnamedArgs = (Object[]) args[args.length - 1];
+
+ int argsCount = nNamedArgs + unnamedArgs.length;
+ Class>[] argTypes = new Class>[argsCount];
+ MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length];
+
+ int pos = 0;
+ for (pos = 0; pos < nNamedArgs; pos++) {
+ argLayouts[pos] = function.argumentLayouts().get(pos);
+ }
+
+ assert pos == nNamedArgs;
+ for (Object o: unnamedArgs) {
+ argLayouts[pos] = variadicLayout(normalize(o.getClass()));
+ pos++;
+ }
+ assert pos == argsCount;
+
+ FunctionDescriptor f = (function.returnLayout().isEmpty()) ?
+ FunctionDescriptor.ofVoid(argLayouts) :
+ FunctionDescriptor.of(function.returnLayout().get(), argLayouts);
+ MethodHandle mh = LINKER.downcallHandle(symbol, f);
+ if (mh.type().returnType() == MemorySegment.class) {
+ mh = mh.bindTo(allocator);
+ }
+ // flatten argument list so that it can be passed to an asSpreader MH
+ Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length];
+ System.arraycopy(args, 0, allArgs, 0, nNamedArgs);
+ System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length);
+
+ return mh.asSpreader(Object[].class, argsCount).invoke(allArgs);
+ }
+
+ private static Class> unboxIfNeeded(Class> clazz) {
+ if (clazz == Boolean.class) {
+ return boolean.class;
+ } else if (clazz == Void.class) {
+ return void.class;
+ } else if (clazz == Byte.class) {
+ return byte.class;
+ } else if (clazz == Character.class) {
+ return char.class;
+ } else if (clazz == Short.class) {
+ return short.class;
+ } else if (clazz == Integer.class) {
+ return int.class;
+ } else if (clazz == Long.class) {
+ return long.class;
+ } else if (clazz == Float.class) {
+ return float.class;
+ } else if (clazz == Double.class) {
+ return double.class;
+ } else {
+ return clazz;
+ }
+ }
+
+ private Class> promote(Class> c) {
+ if (c == byte.class || c == char.class || c == short.class || c == int.class) {
+ return long.class;
+ } else if (c == float.class) {
+ return double.class;
+ } else {
+ return c;
+ }
+ }
+
+ private Class> normalize(Class> c) {
+ c = unboxIfNeeded(c);
+ if (c.isPrimitive()) {
+ return promote(c);
+ }
+ if (MemoryAddress.class.isAssignableFrom(c)) {
+ return MemoryAddress.class;
+ }
+ if (MemorySegment.class.isAssignableFrom(c)) {
+ return MemorySegment.class;
+ }
+ throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName());
+ }
+
+ private MemoryLayout variadicLayout(Class> c) {
+ if (c == long.class) {
+ return JAVA_LONG;
+ } else if (c == double.class) {
+ return JAVA_DOUBLE;
+ } else if (MemoryAddress.class.isAssignableFrom(c)) {
+ return ADDRESS;
+ } else {
+ throw new IllegalArgumentException("Unhandled variadic argument class: " + c);
+ }
+ }
+ }
+}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/__fsid_t.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/__fsid_t.java
new file mode 100644
index 00000000..990f9f6b
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/__fsid_t.java
@@ -0,0 +1,25 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.unistd;
+
+import java.lang.foreign.*;
+public class __fsid_t {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ MemoryLayout.sequenceLayout(2, Constants$root.C_INT$LAYOUT).withName("__val")
+ );
+ public static MemoryLayout $LAYOUT() {
+ return __fsid_t.$struct$LAYOUT;
+ }
+ public static MemorySegment __val$slice(MemorySegment seg) {
+ return seg.asSlice(0, 8);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$0.java
new file mode 100644
index 00000000..4535a379
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$0.java
@@ -0,0 +1,61 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.unistd;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$0 {
+
+ static final FunctionDescriptor access$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle access$MH = RuntimeHelper.downcallHandle(
+ "access",
+ constants$0.access$FUNC
+ );
+ static final FunctionDescriptor faccessat$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle faccessat$MH = RuntimeHelper.downcallHandle(
+ "faccessat",
+ constants$0.faccessat$FUNC
+ );
+ static final FunctionDescriptor lseek$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle lseek$MH = RuntimeHelper.downcallHandle(
+ "lseek",
+ constants$0.lseek$FUNC
+ );
+ static final FunctionDescriptor close$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle close$MH = RuntimeHelper.downcallHandle(
+ "close",
+ constants$0.close$FUNC
+ );
+ static final FunctionDescriptor closefrom$FUNC = FunctionDescriptor.ofVoid(
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle closefrom$MH = RuntimeHelper.downcallHandle(
+ "closefrom",
+ constants$0.closefrom$FUNC
+ );
+ static final FunctionDescriptor read$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT
+ );
+ static final MethodHandle read$MH = RuntimeHelper.downcallHandle(
+ "read",
+ constants$0.read$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$1.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$1.java
new file mode 100644
index 00000000..0cc4fe56
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$1.java
@@ -0,0 +1,61 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.unistd;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$1 {
+
+ static final FunctionDescriptor write$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT
+ );
+ static final MethodHandle write$MH = RuntimeHelper.downcallHandle(
+ "write",
+ constants$1.write$FUNC
+ );
+ static final FunctionDescriptor pread$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT
+ );
+ static final MethodHandle pread$MH = RuntimeHelper.downcallHandle(
+ "pread",
+ constants$1.pread$FUNC
+ );
+ static final FunctionDescriptor pwrite$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT
+ );
+ static final MethodHandle pwrite$MH = RuntimeHelper.downcallHandle(
+ "pwrite",
+ constants$1.pwrite$FUNC
+ );
+ static final FunctionDescriptor pipe$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle pipe$MH = RuntimeHelper.downcallHandle(
+ "pipe",
+ constants$1.pipe$FUNC
+ );
+ static final FunctionDescriptor alarm$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle alarm$MH = RuntimeHelper.downcallHandle(
+ "alarm",
+ constants$1.alarm$FUNC
+ );
+ static final FunctionDescriptor sleep$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle sleep$MH = RuntimeHelper.downcallHandle(
+ "sleep",
+ constants$1.sleep$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$10.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$10.java
new file mode 100644
index 00000000..64c7caab
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$10.java
@@ -0,0 +1,52 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.unistd;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$10 {
+
+ static final FunctionDescriptor vfork$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
+ static final MethodHandle vfork$MH = RuntimeHelper.downcallHandle(
+ "vfork",
+ constants$10.vfork$FUNC
+ );
+ static final FunctionDescriptor ttyname$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle ttyname$MH = RuntimeHelper.downcallHandle(
+ "ttyname",
+ constants$10.ttyname$FUNC
+ );
+ static final FunctionDescriptor ttyname_r$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT
+ );
+ static final MethodHandle ttyname_r$MH = RuntimeHelper.downcallHandle(
+ "ttyname_r",
+ constants$10.ttyname_r$FUNC
+ );
+ static final FunctionDescriptor isatty$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle isatty$MH = RuntimeHelper.downcallHandle(
+ "isatty",
+ constants$10.isatty$FUNC
+ );
+ static final FunctionDescriptor ttyslot$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
+ static final MethodHandle ttyslot$MH = RuntimeHelper.downcallHandle(
+ "ttyslot",
+ constants$10.ttyslot$FUNC
+ );
+ static final FunctionDescriptor link$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle link$MH = RuntimeHelper.downcallHandle(
+ "link",
+ constants$10.link$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$11.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$11.java
new file mode 100644
index 00000000..4dc75380
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$11.java
@@ -0,0 +1,65 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.unistd;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$11 {
+
+ static final FunctionDescriptor linkat$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle linkat$MH = RuntimeHelper.downcallHandle(
+ "linkat",
+ constants$11.linkat$FUNC
+ );
+ static final FunctionDescriptor symlink$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle symlink$MH = RuntimeHelper.downcallHandle(
+ "symlink",
+ constants$11.symlink$FUNC
+ );
+ static final FunctionDescriptor readlink$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT
+ );
+ static final MethodHandle readlink$MH = RuntimeHelper.downcallHandle(
+ "readlink",
+ constants$11.readlink$FUNC
+ );
+ static final FunctionDescriptor symlinkat$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle symlinkat$MH = RuntimeHelper.downcallHandle(
+ "symlinkat",
+ constants$11.symlinkat$FUNC
+ );
+ static final FunctionDescriptor readlinkat$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT
+ );
+ static final MethodHandle readlinkat$MH = RuntimeHelper.downcallHandle(
+ "readlinkat",
+ constants$11.readlinkat$FUNC
+ );
+ static final FunctionDescriptor unlink$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle unlink$MH = RuntimeHelper.downcallHandle(
+ "unlink",
+ constants$11.unlink$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$12.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$12.java
new file mode 100644
index 00000000..b73d5e46
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$12.java
@@ -0,0 +1,55 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.unistd;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$12 {
+
+ static final FunctionDescriptor unlinkat$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle unlinkat$MH = RuntimeHelper.downcallHandle(
+ "unlinkat",
+ constants$12.unlinkat$FUNC
+ );
+ static final FunctionDescriptor rmdir$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle rmdir$MH = RuntimeHelper.downcallHandle(
+ "rmdir",
+ constants$12.rmdir$FUNC
+ );
+ static final FunctionDescriptor tcgetpgrp$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle tcgetpgrp$MH = RuntimeHelper.downcallHandle(
+ "tcgetpgrp",
+ constants$12.tcgetpgrp$FUNC
+ );
+ static final FunctionDescriptor tcsetpgrp$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle tcsetpgrp$MH = RuntimeHelper.downcallHandle(
+ "tcsetpgrp",
+ constants$12.tcsetpgrp$FUNC
+ );
+ static final FunctionDescriptor getlogin$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT);
+ static final MethodHandle getlogin$MH = RuntimeHelper.downcallHandle(
+ "getlogin",
+ constants$12.getlogin$FUNC
+ );
+ static final FunctionDescriptor getlogin_r$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT
+ );
+ static final MethodHandle getlogin_r$MH = RuntimeHelper.downcallHandle(
+ "getlogin_r",
+ constants$12.getlogin_r$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$13.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$13.java
new file mode 100644
index 00000000..bab872f5
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$13.java
@@ -0,0 +1,44 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.unistd;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.foreign.MemorySegment;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.VarHandle;
+
+import static java.lang.foreign.ValueLayout.OfAddress;
+import static java.lang.foreign.ValueLayout.OfInt;
+class constants$13 {
+
+ static final FunctionDescriptor setlogin$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle setlogin$MH = RuntimeHelper.downcallHandle(
+ "setlogin",
+ constants$13.setlogin$FUNC
+ );
+ static final OfAddress optarg$LAYOUT = Constants$root.C_POINTER$LAYOUT;
+ static final VarHandle optarg$VH = constants$13.optarg$LAYOUT.varHandle();
+ static final MemorySegment optarg$SEGMENT = RuntimeHelper.lookupGlobalVariable("optarg", constants$13.optarg$LAYOUT);
+ static final OfInt optind$LAYOUT = Constants$root.C_INT$LAYOUT;
+ static final VarHandle optind$VH = constants$13.optind$LAYOUT.varHandle();
+ static final MemorySegment optind$SEGMENT = RuntimeHelper.lookupGlobalVariable("optind", constants$13.optind$LAYOUT);
+ static final OfInt opterr$LAYOUT = Constants$root.C_INT$LAYOUT;
+ static final VarHandle opterr$VH = constants$13.opterr$LAYOUT.varHandle();
+ static final MemorySegment opterr$SEGMENT = RuntimeHelper.lookupGlobalVariable("opterr", constants$13.opterr$LAYOUT);
+ static final OfInt optopt$LAYOUT = Constants$root.C_INT$LAYOUT;
+ static final VarHandle optopt$VH = constants$13.optopt$LAYOUT.varHandle();
+ static final MemorySegment optopt$SEGMENT = RuntimeHelper.lookupGlobalVariable("optopt", constants$13.optopt$LAYOUT);
+ static final FunctionDescriptor getopt$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle getopt$MH = RuntimeHelper.downcallHandle(
+ "getopt",
+ constants$13.getopt$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$14.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$14.java
new file mode 100644
index 00000000..68193487
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$14.java
@@ -0,0 +1,55 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.unistd;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$14 {
+
+ static final FunctionDescriptor gethostname$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT
+ );
+ static final MethodHandle gethostname$MH = RuntimeHelper.downcallHandle(
+ "gethostname",
+ constants$14.gethostname$FUNC
+ );
+ static final FunctionDescriptor sethostname$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT
+ );
+ static final MethodHandle sethostname$MH = RuntimeHelper.downcallHandle(
+ "sethostname",
+ constants$14.sethostname$FUNC
+ );
+ static final FunctionDescriptor sethostid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT
+ );
+ static final MethodHandle sethostid$MH = RuntimeHelper.downcallHandle(
+ "sethostid",
+ constants$14.sethostid$FUNC
+ );
+ static final FunctionDescriptor getdomainname$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT
+ );
+ static final MethodHandle getdomainname$MH = RuntimeHelper.downcallHandle(
+ "getdomainname",
+ constants$14.getdomainname$FUNC
+ );
+ static final FunctionDescriptor setdomainname$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT
+ );
+ static final MethodHandle setdomainname$MH = RuntimeHelper.downcallHandle(
+ "setdomainname",
+ constants$14.setdomainname$FUNC
+ );
+ static final FunctionDescriptor vhangup$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
+ static final MethodHandle vhangup$MH = RuntimeHelper.downcallHandle(
+ "vhangup",
+ constants$14.vhangup$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$15.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$15.java
new file mode 100644
index 00000000..432d2995
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$15.java
@@ -0,0 +1,50 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.unistd;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$15 {
+
+ static final FunctionDescriptor revoke$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle revoke$MH = RuntimeHelper.downcallHandle(
+ "revoke",
+ constants$15.revoke$FUNC
+ );
+ static final FunctionDescriptor profil$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle profil$MH = RuntimeHelper.downcallHandle(
+ "profil",
+ constants$15.profil$FUNC
+ );
+ static final FunctionDescriptor acct$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle acct$MH = RuntimeHelper.downcallHandle(
+ "acct",
+ constants$15.acct$FUNC
+ );
+ static final FunctionDescriptor getusershell$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT);
+ static final MethodHandle getusershell$MH = RuntimeHelper.downcallHandle(
+ "getusershell",
+ constants$15.getusershell$FUNC
+ );
+ static final FunctionDescriptor endusershell$FUNC = FunctionDescriptor.ofVoid();
+ static final MethodHandle endusershell$MH = RuntimeHelper.downcallHandle(
+ "endusershell",
+ constants$15.endusershell$FUNC
+ );
+ static final FunctionDescriptor setusershell$FUNC = FunctionDescriptor.ofVoid();
+ static final MethodHandle setusershell$MH = RuntimeHelper.downcallHandle(
+ "setusershell",
+ constants$15.setusershell$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$16.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$16.java
new file mode 100644
index 00000000..2373648b
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$16.java
@@ -0,0 +1,50 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.unistd;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$16 {
+
+ static final FunctionDescriptor daemon$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle daemon$MH = RuntimeHelper.downcallHandle(
+ "daemon",
+ constants$16.daemon$FUNC
+ );
+ static final FunctionDescriptor chroot$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle chroot$MH = RuntimeHelper.downcallHandle(
+ "chroot",
+ constants$16.chroot$FUNC
+ );
+ static final FunctionDescriptor getpass$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle getpass$MH = RuntimeHelper.downcallHandle(
+ "getpass",
+ constants$16.getpass$FUNC
+ );
+ static final FunctionDescriptor fsync$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle fsync$MH = RuntimeHelper.downcallHandle(
+ "fsync",
+ constants$16.fsync$FUNC
+ );
+ static final FunctionDescriptor gethostid$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT);
+ static final MethodHandle gethostid$MH = RuntimeHelper.downcallHandle(
+ "gethostid",
+ constants$16.gethostid$FUNC
+ );
+ static final FunctionDescriptor sync$FUNC = FunctionDescriptor.ofVoid();
+ static final MethodHandle sync$MH = RuntimeHelper.downcallHandle(
+ "sync",
+ constants$16.sync$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$17.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$17.java
new file mode 100644
index 00000000..9e76f6e5
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$17.java
@@ -0,0 +1,51 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.unistd;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$17 {
+
+ static final FunctionDescriptor getpagesize$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
+ static final MethodHandle getpagesize$MH = RuntimeHelper.downcallHandle(
+ "getpagesize",
+ constants$17.getpagesize$FUNC
+ );
+ static final FunctionDescriptor getdtablesize$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
+ static final MethodHandle getdtablesize$MH = RuntimeHelper.downcallHandle(
+ "getdtablesize",
+ constants$17.getdtablesize$FUNC
+ );
+ static final FunctionDescriptor truncate$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT
+ );
+ static final MethodHandle truncate$MH = RuntimeHelper.downcallHandle(
+ "truncate",
+ constants$17.truncate$FUNC
+ );
+ static final FunctionDescriptor ftruncate$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT
+ );
+ static final MethodHandle ftruncate$MH = RuntimeHelper.downcallHandle(
+ "ftruncate",
+ constants$17.ftruncate$FUNC
+ );
+ static final FunctionDescriptor brk$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle brk$MH = RuntimeHelper.downcallHandle(
+ "brk",
+ constants$17.brk$FUNC
+ );
+ static final FunctionDescriptor sbrk$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT
+ );
+ static final MethodHandle sbrk$MH = RuntimeHelper.downcallHandle(
+ "sbrk",
+ constants$17.sbrk$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$18.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$18.java
new file mode 100644
index 00000000..794239b3
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$18.java
@@ -0,0 +1,52 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.unistd;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.foreign.MemorySegment;
+import java.lang.invoke.MethodHandle;
+class constants$18 {
+
+ static final FunctionDescriptor syscall$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT
+ );
+ static final MethodHandle syscall$MH = RuntimeHelper.downcallHandleVariadic(
+ "syscall",
+ constants$18.syscall$FUNC
+ );
+ static final FunctionDescriptor lockf$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT
+ );
+ static final MethodHandle lockf$MH = RuntimeHelper.downcallHandle(
+ "lockf",
+ constants$18.lockf$FUNC
+ );
+ static final FunctionDescriptor fdatasync$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle fdatasync$MH = RuntimeHelper.downcallHandle(
+ "fdatasync",
+ constants$18.fdatasync$FUNC
+ );
+ static final FunctionDescriptor crypt$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle crypt$MH = RuntimeHelper.downcallHandle(
+ "crypt",
+ constants$18.crypt$FUNC
+ );
+ static final FunctionDescriptor getentropy$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT
+ );
+ static final MethodHandle getentropy$MH = RuntimeHelper.downcallHandle(
+ "getentropy",
+ constants$18.getentropy$FUNC
+ );
+ static final MemorySegment __ILP32_OFF32_CFLAGS$SEGMENT = RuntimeHelper.CONSTANT_ALLOCATOR.allocateUtf8String("-m32");
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$19.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$19.java
new file mode 100644
index 00000000..a33d0a5c
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$19.java
@@ -0,0 +1,17 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.unistd;
+
+import java.lang.foreign.MemoryAddress;
+import java.lang.foreign.MemorySegment;
+class constants$19 {
+
+ static final MemorySegment __ILP32_OFF32_LDFLAGS$SEGMENT = RuntimeHelper.CONSTANT_ALLOCATOR.allocateUtf8String("-m32");
+ static final MemorySegment __ILP32_OFFBIG_CFLAGS$SEGMENT = RuntimeHelper.CONSTANT_ALLOCATOR.allocateUtf8String("-m32 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64");
+ static final MemorySegment __ILP32_OFFBIG_LDFLAGS$SEGMENT = RuntimeHelper.CONSTANT_ALLOCATOR.allocateUtf8String("-m32");
+ static final MemorySegment __LP64_OFF64_CFLAGS$SEGMENT = RuntimeHelper.CONSTANT_ALLOCATOR.allocateUtf8String("-m64");
+ static final MemorySegment __LP64_OFF64_LDFLAGS$SEGMENT = RuntimeHelper.CONSTANT_ALLOCATOR.allocateUtf8String("-m64");
+ static final MemoryAddress NULL$ADDR = MemoryAddress.ofLong(0L);
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$2.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$2.java
new file mode 100644
index 00000000..df7185a3
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$2.java
@@ -0,0 +1,58 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.unistd;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$2 {
+
+ static final FunctionDescriptor ualarm$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle ualarm$MH = RuntimeHelper.downcallHandle(
+ "ualarm",
+ constants$2.ualarm$FUNC
+ );
+ static final FunctionDescriptor usleep$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle usleep$MH = RuntimeHelper.downcallHandle(
+ "usleep",
+ constants$2.usleep$FUNC
+ );
+ static final FunctionDescriptor pause$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
+ static final MethodHandle pause$MH = RuntimeHelper.downcallHandle(
+ "pause",
+ constants$2.pause$FUNC
+ );
+ static final FunctionDescriptor chown$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle chown$MH = RuntimeHelper.downcallHandle(
+ "chown",
+ constants$2.chown$FUNC
+ );
+ static final FunctionDescriptor fchown$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle fchown$MH = RuntimeHelper.downcallHandle(
+ "fchown",
+ constants$2.fchown$FUNC
+ );
+ static final FunctionDescriptor lchown$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle lchown$MH = RuntimeHelper.downcallHandle(
+ "lchown",
+ constants$2.lchown$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$3.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$3.java
new file mode 100644
index 00000000..81b2b5d6
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$3.java
@@ -0,0 +1,58 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.unistd;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$3 {
+
+ static final FunctionDescriptor fchownat$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle fchownat$MH = RuntimeHelper.downcallHandle(
+ "fchownat",
+ constants$3.fchownat$FUNC
+ );
+ static final FunctionDescriptor chdir$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle chdir$MH = RuntimeHelper.downcallHandle(
+ "chdir",
+ constants$3.chdir$FUNC
+ );
+ static final FunctionDescriptor fchdir$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle fchdir$MH = RuntimeHelper.downcallHandle(
+ "fchdir",
+ constants$3.fchdir$FUNC
+ );
+ static final FunctionDescriptor getcwd$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT
+ );
+ static final MethodHandle getcwd$MH = RuntimeHelper.downcallHandle(
+ "getcwd",
+ constants$3.getcwd$FUNC
+ );
+ static final FunctionDescriptor getwd$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle getwd$MH = RuntimeHelper.downcallHandle(
+ "getwd",
+ constants$3.getwd$FUNC
+ );
+ static final FunctionDescriptor dup$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle dup$MH = RuntimeHelper.downcallHandle(
+ "dup",
+ constants$3.dup$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$4.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$4.java
new file mode 100644
index 00000000..ec8066b8
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$4.java
@@ -0,0 +1,60 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.unistd;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.foreign.MemorySegment;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.VarHandle;
+
+import static java.lang.foreign.ValueLayout.OfAddress;
+class constants$4 {
+
+ static final FunctionDescriptor dup2$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle dup2$MH = RuntimeHelper.downcallHandle(
+ "dup2",
+ constants$4.dup2$FUNC
+ );
+ static final OfAddress __environ$LAYOUT = Constants$root.C_POINTER$LAYOUT;
+ static final VarHandle __environ$VH = constants$4.__environ$LAYOUT.varHandle();
+ static final MemorySegment __environ$SEGMENT = RuntimeHelper.lookupGlobalVariable("__environ", constants$4.__environ$LAYOUT);
+ static final FunctionDescriptor execve$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle execve$MH = RuntimeHelper.downcallHandle(
+ "execve",
+ constants$4.execve$FUNC
+ );
+ static final FunctionDescriptor fexecve$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle fexecve$MH = RuntimeHelper.downcallHandle(
+ "fexecve",
+ constants$4.fexecve$FUNC
+ );
+ static final FunctionDescriptor execv$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle execv$MH = RuntimeHelper.downcallHandle(
+ "execv",
+ constants$4.execv$FUNC
+ );
+ static final FunctionDescriptor execle$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle execle$MH = RuntimeHelper.downcallHandleVariadic(
+ "execle",
+ constants$4.execle$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$5.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$5.java
new file mode 100644
index 00000000..973d637c
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$5.java
@@ -0,0 +1,57 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.unistd;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$5 {
+
+ static final FunctionDescriptor execl$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle execl$MH = RuntimeHelper.downcallHandleVariadic(
+ "execl",
+ constants$5.execl$FUNC
+ );
+ static final FunctionDescriptor execvp$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle execvp$MH = RuntimeHelper.downcallHandle(
+ "execvp",
+ constants$5.execvp$FUNC
+ );
+ static final FunctionDescriptor execlp$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle execlp$MH = RuntimeHelper.downcallHandleVariadic(
+ "execlp",
+ constants$5.execlp$FUNC
+ );
+ static final FunctionDescriptor nice$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle nice$MH = RuntimeHelper.downcallHandle(
+ "nice",
+ constants$5.nice$FUNC
+ );
+ static final FunctionDescriptor _exit$FUNC = FunctionDescriptor.ofVoid(
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle _exit$MH = RuntimeHelper.downcallHandle(
+ "_exit",
+ constants$5._exit$FUNC
+ );
+ static final FunctionDescriptor pathconf$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle pathconf$MH = RuntimeHelper.downcallHandle(
+ "pathconf",
+ constants$5.pathconf$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$6.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$6.java
new file mode 100644
index 00000000..da5a5a31
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$6.java
@@ -0,0 +1,50 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.unistd;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$6 {
+
+ static final FunctionDescriptor fpathconf$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle fpathconf$MH = RuntimeHelper.downcallHandle(
+ "fpathconf",
+ constants$6.fpathconf$FUNC
+ );
+ static final FunctionDescriptor sysconf$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle sysconf$MH = RuntimeHelper.downcallHandle(
+ "sysconf",
+ constants$6.sysconf$FUNC
+ );
+ static final FunctionDescriptor confstr$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT
+ );
+ static final MethodHandle confstr$MH = RuntimeHelper.downcallHandle(
+ "confstr",
+ constants$6.confstr$FUNC
+ );
+ static final FunctionDescriptor getpid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
+ static final MethodHandle getpid$MH = RuntimeHelper.downcallHandle(
+ "getpid",
+ constants$6.getpid$FUNC
+ );
+ static final FunctionDescriptor getppid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
+ static final MethodHandle getppid$MH = RuntimeHelper.downcallHandle(
+ "getppid",
+ constants$6.getppid$FUNC
+ );
+ static final FunctionDescriptor getpgrp$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
+ static final MethodHandle getpgrp$MH = RuntimeHelper.downcallHandle(
+ "getpgrp",
+ constants$6.getpgrp$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$7.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$7.java
new file mode 100644
index 00000000..d08b63a9
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$7.java
@@ -0,0 +1,50 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.unistd;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$7 {
+
+ static final FunctionDescriptor __getpgid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle __getpgid$MH = RuntimeHelper.downcallHandle(
+ "__getpgid",
+ constants$7.__getpgid$FUNC
+ );
+ static final FunctionDescriptor getpgid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle getpgid$MH = RuntimeHelper.downcallHandle(
+ "getpgid",
+ constants$7.getpgid$FUNC
+ );
+ static final FunctionDescriptor setpgid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle setpgid$MH = RuntimeHelper.downcallHandle(
+ "setpgid",
+ constants$7.setpgid$FUNC
+ );
+ static final FunctionDescriptor setpgrp$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
+ static final MethodHandle setpgrp$MH = RuntimeHelper.downcallHandle(
+ "setpgrp",
+ constants$7.setpgrp$FUNC
+ );
+ static final FunctionDescriptor setsid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
+ static final MethodHandle setsid$MH = RuntimeHelper.downcallHandle(
+ "setsid",
+ constants$7.setsid$FUNC
+ );
+ static final FunctionDescriptor getsid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle getsid$MH = RuntimeHelper.downcallHandle(
+ "getsid",
+ constants$7.getsid$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$8.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$8.java
new file mode 100644
index 00000000..a94fab3c
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$8.java
@@ -0,0 +1,46 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.unistd;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$8 {
+
+ static final FunctionDescriptor getuid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
+ static final MethodHandle getuid$MH = RuntimeHelper.downcallHandle(
+ "getuid",
+ constants$8.getuid$FUNC
+ );
+ static final FunctionDescriptor geteuid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
+ static final MethodHandle geteuid$MH = RuntimeHelper.downcallHandle(
+ "geteuid",
+ constants$8.geteuid$FUNC
+ );
+ static final FunctionDescriptor getgid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
+ static final MethodHandle getgid$MH = RuntimeHelper.downcallHandle(
+ "getgid",
+ constants$8.getgid$FUNC
+ );
+ static final FunctionDescriptor getegid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
+ static final MethodHandle getegid$MH = RuntimeHelper.downcallHandle(
+ "getegid",
+ constants$8.getegid$FUNC
+ );
+ static final FunctionDescriptor getgroups$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle getgroups$MH = RuntimeHelper.downcallHandle(
+ "getgroups",
+ constants$8.getgroups$FUNC
+ );
+ static final FunctionDescriptor setuid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle setuid$MH = RuntimeHelper.downcallHandle(
+ "setuid",
+ constants$8.setuid$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$9.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$9.java
new file mode 100644
index 00000000..e4e65a59
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$9.java
@@ -0,0 +1,53 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.unistd;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$9 {
+
+ static final FunctionDescriptor setreuid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle setreuid$MH = RuntimeHelper.downcallHandle(
+ "setreuid",
+ constants$9.setreuid$FUNC
+ );
+ static final FunctionDescriptor seteuid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle seteuid$MH = RuntimeHelper.downcallHandle(
+ "seteuid",
+ constants$9.seteuid$FUNC
+ );
+ static final FunctionDescriptor setgid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle setgid$MH = RuntimeHelper.downcallHandle(
+ "setgid",
+ constants$9.setgid$FUNC
+ );
+ static final FunctionDescriptor setregid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle setregid$MH = RuntimeHelper.downcallHandle(
+ "setregid",
+ constants$9.setregid$FUNC
+ );
+ static final FunctionDescriptor setegid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle setegid$MH = RuntimeHelper.downcallHandle(
+ "setegid",
+ constants$9.setegid$FUNC
+ );
+ static final FunctionDescriptor fork$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
+ static final MethodHandle fork$MH = RuntimeHelper.downcallHandle(
+ "fork",
+ constants$9.fork$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/unistd.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/unistd.java
new file mode 100644
index 00000000..cf6b6b76
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/unistd.java
@@ -0,0 +1,2714 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.unistd;
+
+import java.lang.foreign.Addressable;
+import java.lang.foreign.MemoryAddress;
+import java.lang.foreign.MemoryLayout;
+import java.lang.foreign.MemorySegment;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.VarHandle;
+
+import static java.lang.foreign.ValueLayout.*;
+public class unistd {
+
+ /* package-private */ unistd() {}
+ public static OfByte C_CHAR = Constants$root.C_CHAR$LAYOUT;
+ public static OfShort C_SHORT = Constants$root.C_SHORT$LAYOUT;
+ public static OfInt C_INT = Constants$root.C_INT$LAYOUT;
+ public static OfLong C_LONG = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong C_LONG_LONG = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfFloat C_FLOAT = Constants$root.C_FLOAT$LAYOUT;
+ public static OfDouble C_DOUBLE = Constants$root.C_DOUBLE$LAYOUT;
+ public static OfAddress C_POINTER = Constants$root.C_POINTER$LAYOUT;
+ public static int _UNISTD_H() {
+ return (int)1L;
+ }
+ public static int _FEATURES_H() {
+ return (int)1L;
+ }
+ public static int _DEFAULT_SOURCE() {
+ return (int)1L;
+ }
+ public static int __GLIBC_USE_ISOC2X() {
+ return (int)0L;
+ }
+ public static int __USE_ISOC11() {
+ return (int)1L;
+ }
+ public static int __USE_ISOC99() {
+ return (int)1L;
+ }
+ public static int __USE_ISOC95() {
+ return (int)1L;
+ }
+ public static int __USE_POSIX_IMPLICITLY() {
+ return (int)1L;
+ }
+ public static int _POSIX_SOURCE() {
+ return (int)1L;
+ }
+ public static int __USE_POSIX() {
+ return (int)1L;
+ }
+ public static int __USE_POSIX2() {
+ return (int)1L;
+ }
+ public static int __USE_POSIX199309() {
+ return (int)1L;
+ }
+ public static int __USE_POSIX199506() {
+ return (int)1L;
+ }
+ public static int __USE_XOPEN2K() {
+ return (int)1L;
+ }
+ public static int __USE_XOPEN2K8() {
+ return (int)1L;
+ }
+ public static int _ATFILE_SOURCE() {
+ return (int)1L;
+ }
+ public static int __WORDSIZE() {
+ return (int)64L;
+ }
+ public static int __WORDSIZE_TIME64_COMPAT32() {
+ return (int)1L;
+ }
+ public static int __SYSCALL_WORDSIZE() {
+ return (int)64L;
+ }
+ public static int __USE_MISC() {
+ return (int)1L;
+ }
+ public static int __USE_ATFILE() {
+ return (int)1L;
+ }
+ public static int __USE_FORTIFY_LEVEL() {
+ return (int)0L;
+ }
+ public static int __GLIBC_USE_DEPRECATED_GETS() {
+ return (int)0L;
+ }
+ public static int __GLIBC_USE_DEPRECATED_SCANF() {
+ return (int)0L;
+ }
+ public static int _STDC_PREDEF_H() {
+ return (int)1L;
+ }
+ public static int __STDC_IEC_559__() {
+ return (int)1L;
+ }
+ public static int __STDC_IEC_559_COMPLEX__() {
+ return (int)1L;
+ }
+ public static int __GNU_LIBRARY__() {
+ return (int)6L;
+ }
+ public static int __GLIBC__() {
+ return (int)2L;
+ }
+ public static int __GLIBC_MINOR__() {
+ return (int)35L;
+ }
+ public static int _SYS_CDEFS_H() {
+ return (int)1L;
+ }
+ public static int __glibc_c99_flexarr_available() {
+ return (int)1L;
+ }
+ public static int __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI() {
+ return (int)0L;
+ }
+ public static int __HAVE_GENERIC_SELECTION() {
+ return (int)1L;
+ }
+ public static int _XOPEN_VERSION() {
+ return (int)700L;
+ }
+ public static int _XOPEN_XCU_VERSION() {
+ return (int)4L;
+ }
+ public static int _XOPEN_XPG2() {
+ return (int)1L;
+ }
+ public static int _XOPEN_XPG3() {
+ return (int)1L;
+ }
+ public static int _XOPEN_XPG4() {
+ return (int)1L;
+ }
+ public static int _XOPEN_UNIX() {
+ return (int)1L;
+ }
+ public static int _XOPEN_ENH_I18N() {
+ return (int)1L;
+ }
+ public static int _XOPEN_LEGACY() {
+ return (int)1L;
+ }
+ public static int _BITS_POSIX_OPT_H() {
+ return (int)1L;
+ }
+ public static int _POSIX_JOB_CONTROL() {
+ return (int)1L;
+ }
+ public static int _POSIX_SAVED_IDS() {
+ return (int)1L;
+ }
+ public static int _POSIX_CHOWN_RESTRICTED() {
+ return (int)0L;
+ }
+ public static int _POSIX_NO_TRUNC() {
+ return (int)1L;
+ }
+ public static int _XOPEN_REALTIME() {
+ return (int)1L;
+ }
+ public static int _XOPEN_REALTIME_THREADS() {
+ return (int)1L;
+ }
+ public static int _XOPEN_SHM() {
+ return (int)1L;
+ }
+ public static int _POSIX_REENTRANT_FUNCTIONS() {
+ return (int)1L;
+ }
+ public static int _POSIX_ASYNC_IO() {
+ return (int)1L;
+ }
+ public static int _LFS_ASYNCHRONOUS_IO() {
+ return (int)1L;
+ }
+ public static int _LFS64_ASYNCHRONOUS_IO() {
+ return (int)1L;
+ }
+ public static int _LFS_LARGEFILE() {
+ return (int)1L;
+ }
+ public static int _LFS64_LARGEFILE() {
+ return (int)1L;
+ }
+ public static int _LFS64_STDIO() {
+ return (int)1L;
+ }
+ public static int _POSIX_CPUTIME() {
+ return (int)0L;
+ }
+ public static int _POSIX_THREAD_CPUTIME() {
+ return (int)0L;
+ }
+ public static int _POSIX_REGEXP() {
+ return (int)1L;
+ }
+ public static int _POSIX_SHELL() {
+ return (int)1L;
+ }
+ public static int _POSIX_MONOTONIC_CLOCK() {
+ return (int)0L;
+ }
+ public static int _POSIX_V7_LP64_OFF64() {
+ return (int)1L;
+ }
+ public static int _POSIX_V6_LP64_OFF64() {
+ return (int)1L;
+ }
+ public static int _XBS5_LP64_OFF64() {
+ return (int)1L;
+ }
+ public static int STDIN_FILENO() {
+ return (int)0L;
+ }
+ public static int STDOUT_FILENO() {
+ return (int)1L;
+ }
+ public static int STDERR_FILENO() {
+ return (int)2L;
+ }
+ public static int _BITS_TYPES_H() {
+ return (int)1L;
+ }
+ public static int _BITS_TYPESIZES_H() {
+ return (int)1L;
+ }
+ public static int __OFF_T_MATCHES_OFF64_T() {
+ return (int)1L;
+ }
+ public static int __INO_T_MATCHES_INO64_T() {
+ return (int)1L;
+ }
+ public static int __RLIM_T_MATCHES_RLIM64_T() {
+ return (int)1L;
+ }
+ public static int __STATFS_MATCHES_STATFS64() {
+ return (int)1L;
+ }
+ public static int __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64() {
+ return (int)1L;
+ }
+ public static int __FD_SETSIZE() {
+ return (int)1024L;
+ }
+ public static int _BITS_TIME64_H() {
+ return (int)1L;
+ }
+ public static int R_OK() {
+ return (int)4L;
+ }
+ public static int W_OK() {
+ return (int)2L;
+ }
+ public static int X_OK() {
+ return (int)1L;
+ }
+ public static int F_OK() {
+ return (int)0L;
+ }
+ public static int SEEK_SET() {
+ return (int)0L;
+ }
+ public static int SEEK_CUR() {
+ return (int)1L;
+ }
+ public static int SEEK_END() {
+ return (int)2L;
+ }
+ public static int _GETOPT_POSIX_H() {
+ return (int)1L;
+ }
+ public static int _GETOPT_CORE_H() {
+ return (int)1L;
+ }
+ public static int F_ULOCK() {
+ return (int)0L;
+ }
+ public static int F_LOCK() {
+ return (int)1L;
+ }
+ public static int F_TLOCK() {
+ return (int)2L;
+ }
+ public static int F_TEST() {
+ return (int)3L;
+ }
+ public static OfShort __int16_t = Constants$root.C_SHORT$LAYOUT;
+ public static OfInt __int32_t = Constants$root.C_INT$LAYOUT;
+ public static OfLong __int64_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfShort __int_least16_t = Constants$root.C_SHORT$LAYOUT;
+ public static OfInt __int_least32_t = Constants$root.C_INT$LAYOUT;
+ public static OfLong __int_least64_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __quad_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __intmax_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __off_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __off64_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfInt __pid_t = Constants$root.C_INT$LAYOUT;
+ public static OfLong __clock_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __time_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __suseconds_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __suseconds64_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfInt __daddr_t = Constants$root.C_INT$LAYOUT;
+ public static OfInt __key_t = Constants$root.C_INT$LAYOUT;
+ public static OfInt __clockid_t = Constants$root.C_INT$LAYOUT;
+ public static OfAddress __timer_t = Constants$root.C_POINTER$LAYOUT;
+ public static OfLong __blksize_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __blkcnt_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __blkcnt64_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __fsword_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __ssize_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __syscall_slong_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __loff_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfAddress __caddr_t = Constants$root.C_POINTER$LAYOUT;
+ public static OfLong __intptr_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfInt __sig_atomic_t = Constants$root.C_INT$LAYOUT;
+ public static OfLong ssize_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong off_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfInt pid_t = Constants$root.C_INT$LAYOUT;
+ public static OfLong intptr_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static MethodHandle access$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.access$MH,"access");
+ }
+ public static int access ( Addressable __name, int __type) {
+ var mh$ = access$MH();
+ try {
+ return (int)mh$.invokeExact(__name, __type);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle faccessat$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.faccessat$MH,"faccessat");
+ }
+ public static int faccessat ( int __fd, Addressable __file, int __type, int __flag) {
+ var mh$ = faccessat$MH();
+ try {
+ return (int)mh$.invokeExact(__fd, __file, __type, __flag);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle lseek$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.lseek$MH,"lseek");
+ }
+ public static long lseek ( int __fd, long __offset, int __whence) {
+ var mh$ = lseek$MH();
+ try {
+ return (long)mh$.invokeExact(__fd, __offset, __whence);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle close$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.close$MH,"close");
+ }
+ public static int close ( int __fd) {
+ var mh$ = close$MH();
+ try {
+ return (int)mh$.invokeExact(__fd);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle closefrom$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.closefrom$MH,"closefrom");
+ }
+ public static void closefrom ( int __lowfd) {
+ var mh$ = closefrom$MH();
+ try {
+ mh$.invokeExact(__lowfd);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle read$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.read$MH,"read");
+ }
+ public static long read ( int __fd, Addressable __buf, long __nbytes) {
+ var mh$ = read$MH();
+ try {
+ return (long)mh$.invokeExact(__fd, __buf, __nbytes);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle write$MH() {
+ return RuntimeHelper.requireNonNull(constants$1.write$MH,"write");
+ }
+ public static long write ( int __fd, Addressable __buf, long __n) {
+ var mh$ = write$MH();
+ try {
+ return (long)mh$.invokeExact(__fd, __buf, __n);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle pread$MH() {
+ return RuntimeHelper.requireNonNull(constants$1.pread$MH,"pread");
+ }
+ public static long pread ( int __fd, Addressable __buf, long __nbytes, long __offset) {
+ var mh$ = pread$MH();
+ try {
+ return (long)mh$.invokeExact(__fd, __buf, __nbytes, __offset);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle pwrite$MH() {
+ return RuntimeHelper.requireNonNull(constants$1.pwrite$MH,"pwrite");
+ }
+ public static long pwrite ( int __fd, Addressable __buf, long __n, long __offset) {
+ var mh$ = pwrite$MH();
+ try {
+ return (long)mh$.invokeExact(__fd, __buf, __n, __offset);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle pipe$MH() {
+ return RuntimeHelper.requireNonNull(constants$1.pipe$MH,"pipe");
+ }
+ public static int pipe ( Addressable __pipedes) {
+ var mh$ = pipe$MH();
+ try {
+ return (int)mh$.invokeExact(__pipedes);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle alarm$MH() {
+ return RuntimeHelper.requireNonNull(constants$1.alarm$MH,"alarm");
+ }
+ public static int alarm ( int __seconds) {
+ var mh$ = alarm$MH();
+ try {
+ return (int)mh$.invokeExact(__seconds);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle sleep$MH() {
+ return RuntimeHelper.requireNonNull(constants$1.sleep$MH,"sleep");
+ }
+ public static int sleep ( int __seconds) {
+ var mh$ = sleep$MH();
+ try {
+ return (int)mh$.invokeExact(__seconds);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle ualarm$MH() {
+ return RuntimeHelper.requireNonNull(constants$2.ualarm$MH,"ualarm");
+ }
+ public static int ualarm ( int __value, int __interval) {
+ var mh$ = ualarm$MH();
+ try {
+ return (int)mh$.invokeExact(__value, __interval);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle usleep$MH() {
+ return RuntimeHelper.requireNonNull(constants$2.usleep$MH,"usleep");
+ }
+ public static int usleep ( int __useconds) {
+ var mh$ = usleep$MH();
+ try {
+ return (int)mh$.invokeExact(__useconds);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle pause$MH() {
+ return RuntimeHelper.requireNonNull(constants$2.pause$MH,"pause");
+ }
+ public static int pause () {
+ var mh$ = pause$MH();
+ try {
+ return (int)mh$.invokeExact();
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle chown$MH() {
+ return RuntimeHelper.requireNonNull(constants$2.chown$MH,"chown");
+ }
+ public static int chown ( Addressable __file, int __owner, int __group) {
+ var mh$ = chown$MH();
+ try {
+ return (int)mh$.invokeExact(__file, __owner, __group);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle fchown$MH() {
+ return RuntimeHelper.requireNonNull(constants$2.fchown$MH,"fchown");
+ }
+ public static int fchown ( int __fd, int __owner, int __group) {
+ var mh$ = fchown$MH();
+ try {
+ return (int)mh$.invokeExact(__fd, __owner, __group);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle lchown$MH() {
+ return RuntimeHelper.requireNonNull(constants$2.lchown$MH,"lchown");
+ }
+ public static int lchown ( Addressable __file, int __owner, int __group) {
+ var mh$ = lchown$MH();
+ try {
+ return (int)mh$.invokeExact(__file, __owner, __group);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle fchownat$MH() {
+ return RuntimeHelper.requireNonNull(constants$3.fchownat$MH,"fchownat");
+ }
+ public static int fchownat ( int __fd, Addressable __file, int __owner, int __group, int __flag) {
+ var mh$ = fchownat$MH();
+ try {
+ return (int)mh$.invokeExact(__fd, __file, __owner, __group, __flag);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle chdir$MH() {
+ return RuntimeHelper.requireNonNull(constants$3.chdir$MH,"chdir");
+ }
+ public static int chdir ( Addressable __path) {
+ var mh$ = chdir$MH();
+ try {
+ return (int)mh$.invokeExact(__path);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle fchdir$MH() {
+ return RuntimeHelper.requireNonNull(constants$3.fchdir$MH,"fchdir");
+ }
+ public static int fchdir ( int __fd) {
+ var mh$ = fchdir$MH();
+ try {
+ return (int)mh$.invokeExact(__fd);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle getcwd$MH() {
+ return RuntimeHelper.requireNonNull(constants$3.getcwd$MH,"getcwd");
+ }
+ public static MemoryAddress getcwd ( Addressable __buf, long __size) {
+ var mh$ = getcwd$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact(__buf, __size);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle getwd$MH() {
+ return RuntimeHelper.requireNonNull(constants$3.getwd$MH,"getwd");
+ }
+ public static MemoryAddress getwd ( Addressable __buf) {
+ var mh$ = getwd$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact(__buf);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle dup$MH() {
+ return RuntimeHelper.requireNonNull(constants$3.dup$MH,"dup");
+ }
+ public static int dup ( int __fd) {
+ var mh$ = dup$MH();
+ try {
+ return (int)mh$.invokeExact(__fd);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle dup2$MH() {
+ return RuntimeHelper.requireNonNull(constants$4.dup2$MH,"dup2");
+ }
+ public static int dup2 ( int __fd, int __fd2) {
+ var mh$ = dup2$MH();
+ try {
+ return (int)mh$.invokeExact(__fd, __fd2);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MemoryLayout __environ$LAYOUT() {
+ return constants$4.__environ$LAYOUT;
+ }
+ public static VarHandle __environ$VH() {
+ return constants$4.__environ$VH;
+ }
+ public static MemorySegment __environ$SEGMENT() {
+ return RuntimeHelper.requireNonNull(constants$4.__environ$SEGMENT,"__environ");
+ }
+ public static MemoryAddress __environ$get() {
+ return (java.lang.foreign.MemoryAddress) constants$4.__environ$VH.get(RuntimeHelper.requireNonNull(constants$4.__environ$SEGMENT, "__environ"));
+ }
+ public static void __environ$set( MemoryAddress x) {
+ constants$4.__environ$VH.set(RuntimeHelper.requireNonNull(constants$4.__environ$SEGMENT, "__environ"), x);
+ }
+ public static MethodHandle execve$MH() {
+ return RuntimeHelper.requireNonNull(constants$4.execve$MH,"execve");
+ }
+ public static int execve ( Addressable __path, Addressable __argv, Addressable __envp) {
+ var mh$ = execve$MH();
+ try {
+ return (int)mh$.invokeExact(__path, __argv, __envp);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle fexecve$MH() {
+ return RuntimeHelper.requireNonNull(constants$4.fexecve$MH,"fexecve");
+ }
+ public static int fexecve ( int __fd, Addressable __argv, Addressable __envp) {
+ var mh$ = fexecve$MH();
+ try {
+ return (int)mh$.invokeExact(__fd, __argv, __envp);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle execv$MH() {
+ return RuntimeHelper.requireNonNull(constants$4.execv$MH,"execv");
+ }
+ public static int execv ( Addressable __path, Addressable __argv) {
+ var mh$ = execv$MH();
+ try {
+ return (int)mh$.invokeExact(__path, __argv);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle execle$MH() {
+ return RuntimeHelper.requireNonNull(constants$4.execle$MH,"execle");
+ }
+ public static int execle ( Addressable __path, Addressable __arg, Object... x2) {
+ var mh$ = execle$MH();
+ try {
+ return (int)mh$.invokeExact(__path, __arg, x2);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle execl$MH() {
+ return RuntimeHelper.requireNonNull(constants$5.execl$MH,"execl");
+ }
+ public static int execl ( Addressable __path, Addressable __arg, Object... x2) {
+ var mh$ = execl$MH();
+ try {
+ return (int)mh$.invokeExact(__path, __arg, x2);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle execvp$MH() {
+ return RuntimeHelper.requireNonNull(constants$5.execvp$MH,"execvp");
+ }
+ public static int execvp ( Addressable __file, Addressable __argv) {
+ var mh$ = execvp$MH();
+ try {
+ return (int)mh$.invokeExact(__file, __argv);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle execlp$MH() {
+ return RuntimeHelper.requireNonNull(constants$5.execlp$MH,"execlp");
+ }
+ public static int execlp ( Addressable __file, Addressable __arg, Object... x2) {
+ var mh$ = execlp$MH();
+ try {
+ return (int)mh$.invokeExact(__file, __arg, x2);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle nice$MH() {
+ return RuntimeHelper.requireNonNull(constants$5.nice$MH,"nice");
+ }
+ public static int nice ( int __inc) {
+ var mh$ = nice$MH();
+ try {
+ return (int)mh$.invokeExact(__inc);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle _exit$MH() {
+ return RuntimeHelper.requireNonNull(constants$5._exit$MH,"_exit");
+ }
+ public static void _exit ( int __status) {
+ var mh$ = _exit$MH();
+ try {
+ mh$.invokeExact(__status);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static int _PC_LINK_MAX() {
+ return (int)0L;
+ }
+ public static int _PC_MAX_CANON() {
+ return (int)1L;
+ }
+ public static int _PC_MAX_INPUT() {
+ return (int)2L;
+ }
+ public static int _PC_NAME_MAX() {
+ return (int)3L;
+ }
+ public static int _PC_PATH_MAX() {
+ return (int)4L;
+ }
+ public static int _PC_PIPE_BUF() {
+ return (int)5L;
+ }
+ public static int _PC_CHOWN_RESTRICTED() {
+ return (int)6L;
+ }
+ public static int _PC_NO_TRUNC() {
+ return (int)7L;
+ }
+ public static int _PC_VDISABLE() {
+ return (int)8L;
+ }
+ public static int _PC_SYNC_IO() {
+ return (int)9L;
+ }
+ public static int _PC_ASYNC_IO() {
+ return (int)10L;
+ }
+ public static int _PC_PRIO_IO() {
+ return (int)11L;
+ }
+ public static int _PC_SOCK_MAXBUF() {
+ return (int)12L;
+ }
+ public static int _PC_FILESIZEBITS() {
+ return (int)13L;
+ }
+ public static int _PC_REC_INCR_XFER_SIZE() {
+ return (int)14L;
+ }
+ public static int _PC_REC_MAX_XFER_SIZE() {
+ return (int)15L;
+ }
+ public static int _PC_REC_MIN_XFER_SIZE() {
+ return (int)16L;
+ }
+ public static int _PC_REC_XFER_ALIGN() {
+ return (int)17L;
+ }
+ public static int _PC_ALLOC_SIZE_MIN() {
+ return (int)18L;
+ }
+ public static int _PC_SYMLINK_MAX() {
+ return (int)19L;
+ }
+ public static int _PC_2_SYMLINKS() {
+ return (int)20L;
+ }
+ public static int _SC_ARG_MAX() {
+ return (int)0L;
+ }
+ public static int _SC_CHILD_MAX() {
+ return (int)1L;
+ }
+ public static int _SC_CLK_TCK() {
+ return (int)2L;
+ }
+ public static int _SC_NGROUPS_MAX() {
+ return (int)3L;
+ }
+ public static int _SC_OPEN_MAX() {
+ return (int)4L;
+ }
+ public static int _SC_STREAM_MAX() {
+ return (int)5L;
+ }
+ public static int _SC_TZNAME_MAX() {
+ return (int)6L;
+ }
+ public static int _SC_JOB_CONTROL() {
+ return (int)7L;
+ }
+ public static int _SC_SAVED_IDS() {
+ return (int)8L;
+ }
+ public static int _SC_REALTIME_SIGNALS() {
+ return (int)9L;
+ }
+ public static int _SC_PRIORITY_SCHEDULING() {
+ return (int)10L;
+ }
+ public static int _SC_TIMERS() {
+ return (int)11L;
+ }
+ public static int _SC_ASYNCHRONOUS_IO() {
+ return (int)12L;
+ }
+ public static int _SC_PRIORITIZED_IO() {
+ return (int)13L;
+ }
+ public static int _SC_SYNCHRONIZED_IO() {
+ return (int)14L;
+ }
+ public static int _SC_FSYNC() {
+ return (int)15L;
+ }
+ public static int _SC_MAPPED_FILES() {
+ return (int)16L;
+ }
+ public static int _SC_MEMLOCK() {
+ return (int)17L;
+ }
+ public static int _SC_MEMLOCK_RANGE() {
+ return (int)18L;
+ }
+ public static int _SC_MEMORY_PROTECTION() {
+ return (int)19L;
+ }
+ public static int _SC_MESSAGE_PASSING() {
+ return (int)20L;
+ }
+ public static int _SC_SEMAPHORES() {
+ return (int)21L;
+ }
+ public static int _SC_SHARED_MEMORY_OBJECTS() {
+ return (int)22L;
+ }
+ public static int _SC_AIO_LISTIO_MAX() {
+ return (int)23L;
+ }
+ public static int _SC_AIO_MAX() {
+ return (int)24L;
+ }
+ public static int _SC_AIO_PRIO_DELTA_MAX() {
+ return (int)25L;
+ }
+ public static int _SC_DELAYTIMER_MAX() {
+ return (int)26L;
+ }
+ public static int _SC_MQ_OPEN_MAX() {
+ return (int)27L;
+ }
+ public static int _SC_MQ_PRIO_MAX() {
+ return (int)28L;
+ }
+ public static int _SC_VERSION() {
+ return (int)29L;
+ }
+ public static int _SC_PAGESIZE() {
+ return (int)30L;
+ }
+ public static int _SC_RTSIG_MAX() {
+ return (int)31L;
+ }
+ public static int _SC_SEM_NSEMS_MAX() {
+ return (int)32L;
+ }
+ public static int _SC_SEM_VALUE_MAX() {
+ return (int)33L;
+ }
+ public static int _SC_SIGQUEUE_MAX() {
+ return (int)34L;
+ }
+ public static int _SC_TIMER_MAX() {
+ return (int)35L;
+ }
+ public static int _SC_BC_BASE_MAX() {
+ return (int)36L;
+ }
+ public static int _SC_BC_DIM_MAX() {
+ return (int)37L;
+ }
+ public static int _SC_BC_SCALE_MAX() {
+ return (int)38L;
+ }
+ public static int _SC_BC_STRING_MAX() {
+ return (int)39L;
+ }
+ public static int _SC_COLL_WEIGHTS_MAX() {
+ return (int)40L;
+ }
+ public static int _SC_EQUIV_CLASS_MAX() {
+ return (int)41L;
+ }
+ public static int _SC_EXPR_NEST_MAX() {
+ return (int)42L;
+ }
+ public static int _SC_LINE_MAX() {
+ return (int)43L;
+ }
+ public static int _SC_RE_DUP_MAX() {
+ return (int)44L;
+ }
+ public static int _SC_CHARCLASS_NAME_MAX() {
+ return (int)45L;
+ }
+ public static int _SC_2_VERSION() {
+ return (int)46L;
+ }
+ public static int _SC_2_C_BIND() {
+ return (int)47L;
+ }
+ public static int _SC_2_C_DEV() {
+ return (int)48L;
+ }
+ public static int _SC_2_FORT_DEV() {
+ return (int)49L;
+ }
+ public static int _SC_2_FORT_RUN() {
+ return (int)50L;
+ }
+ public static int _SC_2_SW_DEV() {
+ return (int)51L;
+ }
+ public static int _SC_2_LOCALEDEF() {
+ return (int)52L;
+ }
+ public static int _SC_PII() {
+ return (int)53L;
+ }
+ public static int _SC_PII_XTI() {
+ return (int)54L;
+ }
+ public static int _SC_PII_SOCKET() {
+ return (int)55L;
+ }
+ public static int _SC_PII_INTERNET() {
+ return (int)56L;
+ }
+ public static int _SC_PII_OSI() {
+ return (int)57L;
+ }
+ public static int _SC_POLL() {
+ return (int)58L;
+ }
+ public static int _SC_SELECT() {
+ return (int)59L;
+ }
+ public static int _SC_UIO_MAXIOV() {
+ return (int)60L;
+ }
+ public static int _SC_IOV_MAX() {
+ return (int)60L;
+ }
+ public static int _SC_PII_INTERNET_STREAM() {
+ return (int)61L;
+ }
+ public static int _SC_PII_INTERNET_DGRAM() {
+ return (int)62L;
+ }
+ public static int _SC_PII_OSI_COTS() {
+ return (int)63L;
+ }
+ public static int _SC_PII_OSI_CLTS() {
+ return (int)64L;
+ }
+ public static int _SC_PII_OSI_M() {
+ return (int)65L;
+ }
+ public static int _SC_T_IOV_MAX() {
+ return (int)66L;
+ }
+ public static int _SC_THREADS() {
+ return (int)67L;
+ }
+ public static int _SC_THREAD_SAFE_FUNCTIONS() {
+ return (int)68L;
+ }
+ public static int _SC_GETGR_R_SIZE_MAX() {
+ return (int)69L;
+ }
+ public static int _SC_GETPW_R_SIZE_MAX() {
+ return (int)70L;
+ }
+ public static int _SC_LOGIN_NAME_MAX() {
+ return (int)71L;
+ }
+ public static int _SC_TTY_NAME_MAX() {
+ return (int)72L;
+ }
+ public static int _SC_THREAD_DESTRUCTOR_ITERATIONS() {
+ return (int)73L;
+ }
+ public static int _SC_THREAD_KEYS_MAX() {
+ return (int)74L;
+ }
+ public static int _SC_THREAD_STACK_MIN() {
+ return (int)75L;
+ }
+ public static int _SC_THREAD_THREADS_MAX() {
+ return (int)76L;
+ }
+ public static int _SC_THREAD_ATTR_STACKADDR() {
+ return (int)77L;
+ }
+ public static int _SC_THREAD_ATTR_STACKSIZE() {
+ return (int)78L;
+ }
+ public static int _SC_THREAD_PRIORITY_SCHEDULING() {
+ return (int)79L;
+ }
+ public static int _SC_THREAD_PRIO_INHERIT() {
+ return (int)80L;
+ }
+ public static int _SC_THREAD_PRIO_PROTECT() {
+ return (int)81L;
+ }
+ public static int _SC_THREAD_PROCESS_SHARED() {
+ return (int)82L;
+ }
+ public static int _SC_NPROCESSORS_CONF() {
+ return (int)83L;
+ }
+ public static int _SC_NPROCESSORS_ONLN() {
+ return (int)84L;
+ }
+ public static int _SC_PHYS_PAGES() {
+ return (int)85L;
+ }
+ public static int _SC_AVPHYS_PAGES() {
+ return (int)86L;
+ }
+ public static int _SC_ATEXIT_MAX() {
+ return (int)87L;
+ }
+ public static int _SC_PASS_MAX() {
+ return (int)88L;
+ }
+ public static int _SC_XOPEN_VERSION() {
+ return (int)89L;
+ }
+ public static int _SC_XOPEN_XCU_VERSION() {
+ return (int)90L;
+ }
+ public static int _SC_XOPEN_UNIX() {
+ return (int)91L;
+ }
+ public static int _SC_XOPEN_CRYPT() {
+ return (int)92L;
+ }
+ public static int _SC_XOPEN_ENH_I18N() {
+ return (int)93L;
+ }
+ public static int _SC_XOPEN_SHM() {
+ return (int)94L;
+ }
+ public static int _SC_2_CHAR_TERM() {
+ return (int)95L;
+ }
+ public static int _SC_2_C_VERSION() {
+ return (int)96L;
+ }
+ public static int _SC_2_UPE() {
+ return (int)97L;
+ }
+ public static int _SC_XOPEN_XPG2() {
+ return (int)98L;
+ }
+ public static int _SC_XOPEN_XPG3() {
+ return (int)99L;
+ }
+ public static int _SC_XOPEN_XPG4() {
+ return (int)100L;
+ }
+ public static int _SC_CHAR_BIT() {
+ return (int)101L;
+ }
+ public static int _SC_CHAR_MAX() {
+ return (int)102L;
+ }
+ public static int _SC_CHAR_MIN() {
+ return (int)103L;
+ }
+ public static int _SC_INT_MAX() {
+ return (int)104L;
+ }
+ public static int _SC_INT_MIN() {
+ return (int)105L;
+ }
+ public static int _SC_LONG_BIT() {
+ return (int)106L;
+ }
+ public static int _SC_WORD_BIT() {
+ return (int)107L;
+ }
+ public static int _SC_MB_LEN_MAX() {
+ return (int)108L;
+ }
+ public static int _SC_NZERO() {
+ return (int)109L;
+ }
+ public static int _SC_SSIZE_MAX() {
+ return (int)110L;
+ }
+ public static int _SC_SCHAR_MAX() {
+ return (int)111L;
+ }
+ public static int _SC_SCHAR_MIN() {
+ return (int)112L;
+ }
+ public static int _SC_SHRT_MAX() {
+ return (int)113L;
+ }
+ public static int _SC_SHRT_MIN() {
+ return (int)114L;
+ }
+ public static int _SC_UCHAR_MAX() {
+ return (int)115L;
+ }
+ public static int _SC_UINT_MAX() {
+ return (int)116L;
+ }
+ public static int _SC_ULONG_MAX() {
+ return (int)117L;
+ }
+ public static int _SC_USHRT_MAX() {
+ return (int)118L;
+ }
+ public static int _SC_NL_ARGMAX() {
+ return (int)119L;
+ }
+ public static int _SC_NL_LANGMAX() {
+ return (int)120L;
+ }
+ public static int _SC_NL_MSGMAX() {
+ return (int)121L;
+ }
+ public static int _SC_NL_NMAX() {
+ return (int)122L;
+ }
+ public static int _SC_NL_SETMAX() {
+ return (int)123L;
+ }
+ public static int _SC_NL_TEXTMAX() {
+ return (int)124L;
+ }
+ public static int _SC_XBS5_ILP32_OFF32() {
+ return (int)125L;
+ }
+ public static int _SC_XBS5_ILP32_OFFBIG() {
+ return (int)126L;
+ }
+ public static int _SC_XBS5_LP64_OFF64() {
+ return (int)127L;
+ }
+ public static int _SC_XBS5_LPBIG_OFFBIG() {
+ return (int)128L;
+ }
+ public static int _SC_XOPEN_LEGACY() {
+ return (int)129L;
+ }
+ public static int _SC_XOPEN_REALTIME() {
+ return (int)130L;
+ }
+ public static int _SC_XOPEN_REALTIME_THREADS() {
+ return (int)131L;
+ }
+ public static int _SC_ADVISORY_INFO() {
+ return (int)132L;
+ }
+ public static int _SC_BARRIERS() {
+ return (int)133L;
+ }
+ public static int _SC_BASE() {
+ return (int)134L;
+ }
+ public static int _SC_C_LANG_SUPPORT() {
+ return (int)135L;
+ }
+ public static int _SC_C_LANG_SUPPORT_R() {
+ return (int)136L;
+ }
+ public static int _SC_CLOCK_SELECTION() {
+ return (int)137L;
+ }
+ public static int _SC_CPUTIME() {
+ return (int)138L;
+ }
+ public static int _SC_THREAD_CPUTIME() {
+ return (int)139L;
+ }
+ public static int _SC_DEVICE_IO() {
+ return (int)140L;
+ }
+ public static int _SC_DEVICE_SPECIFIC() {
+ return (int)141L;
+ }
+ public static int _SC_DEVICE_SPECIFIC_R() {
+ return (int)142L;
+ }
+ public static int _SC_FD_MGMT() {
+ return (int)143L;
+ }
+ public static int _SC_FIFO() {
+ return (int)144L;
+ }
+ public static int _SC_PIPE() {
+ return (int)145L;
+ }
+ public static int _SC_FILE_ATTRIBUTES() {
+ return (int)146L;
+ }
+ public static int _SC_FILE_LOCKING() {
+ return (int)147L;
+ }
+ public static int _SC_FILE_SYSTEM() {
+ return (int)148L;
+ }
+ public static int _SC_MONOTONIC_CLOCK() {
+ return (int)149L;
+ }
+ public static int _SC_MULTI_PROCESS() {
+ return (int)150L;
+ }
+ public static int _SC_SINGLE_PROCESS() {
+ return (int)151L;
+ }
+ public static int _SC_NETWORKING() {
+ return (int)152L;
+ }
+ public static int _SC_READER_WRITER_LOCKS() {
+ return (int)153L;
+ }
+ public static int _SC_SPIN_LOCKS() {
+ return (int)154L;
+ }
+ public static int _SC_REGEXP() {
+ return (int)155L;
+ }
+ public static int _SC_REGEX_VERSION() {
+ return (int)156L;
+ }
+ public static int _SC_SHELL() {
+ return (int)157L;
+ }
+ public static int _SC_SIGNALS() {
+ return (int)158L;
+ }
+ public static int _SC_SPAWN() {
+ return (int)159L;
+ }
+ public static int _SC_SPORADIC_SERVER() {
+ return (int)160L;
+ }
+ public static int _SC_THREAD_SPORADIC_SERVER() {
+ return (int)161L;
+ }
+ public static int _SC_SYSTEM_DATABASE() {
+ return (int)162L;
+ }
+ public static int _SC_SYSTEM_DATABASE_R() {
+ return (int)163L;
+ }
+ public static int _SC_TIMEOUTS() {
+ return (int)164L;
+ }
+ public static int _SC_TYPED_MEMORY_OBJECTS() {
+ return (int)165L;
+ }
+ public static int _SC_USER_GROUPS() {
+ return (int)166L;
+ }
+ public static int _SC_USER_GROUPS_R() {
+ return (int)167L;
+ }
+ public static int _SC_2_PBS() {
+ return (int)168L;
+ }
+ public static int _SC_2_PBS_ACCOUNTING() {
+ return (int)169L;
+ }
+ public static int _SC_2_PBS_LOCATE() {
+ return (int)170L;
+ }
+ public static int _SC_2_PBS_MESSAGE() {
+ return (int)171L;
+ }
+ public static int _SC_2_PBS_TRACK() {
+ return (int)172L;
+ }
+ public static int _SC_SYMLOOP_MAX() {
+ return (int)173L;
+ }
+ public static int _SC_STREAMS() {
+ return (int)174L;
+ }
+ public static int _SC_2_PBS_CHECKPOINT() {
+ return (int)175L;
+ }
+ public static int _SC_V6_ILP32_OFF32() {
+ return (int)176L;
+ }
+ public static int _SC_V6_ILP32_OFFBIG() {
+ return (int)177L;
+ }
+ public static int _SC_V6_LP64_OFF64() {
+ return (int)178L;
+ }
+ public static int _SC_V6_LPBIG_OFFBIG() {
+ return (int)179L;
+ }
+ public static int _SC_HOST_NAME_MAX() {
+ return (int)180L;
+ }
+ public static int _SC_TRACE() {
+ return (int)181L;
+ }
+ public static int _SC_TRACE_EVENT_FILTER() {
+ return (int)182L;
+ }
+ public static int _SC_TRACE_INHERIT() {
+ return (int)183L;
+ }
+ public static int _SC_TRACE_LOG() {
+ return (int)184L;
+ }
+ public static int _SC_LEVEL1_ICACHE_SIZE() {
+ return (int)185L;
+ }
+ public static int _SC_LEVEL1_ICACHE_ASSOC() {
+ return (int)186L;
+ }
+ public static int _SC_LEVEL1_ICACHE_LINESIZE() {
+ return (int)187L;
+ }
+ public static int _SC_LEVEL1_DCACHE_SIZE() {
+ return (int)188L;
+ }
+ public static int _SC_LEVEL1_DCACHE_ASSOC() {
+ return (int)189L;
+ }
+ public static int _SC_LEVEL1_DCACHE_LINESIZE() {
+ return (int)190L;
+ }
+ public static int _SC_LEVEL2_CACHE_SIZE() {
+ return (int)191L;
+ }
+ public static int _SC_LEVEL2_CACHE_ASSOC() {
+ return (int)192L;
+ }
+ public static int _SC_LEVEL2_CACHE_LINESIZE() {
+ return (int)193L;
+ }
+ public static int _SC_LEVEL3_CACHE_SIZE() {
+ return (int)194L;
+ }
+ public static int _SC_LEVEL3_CACHE_ASSOC() {
+ return (int)195L;
+ }
+ public static int _SC_LEVEL3_CACHE_LINESIZE() {
+ return (int)196L;
+ }
+ public static int _SC_LEVEL4_CACHE_SIZE() {
+ return (int)197L;
+ }
+ public static int _SC_LEVEL4_CACHE_ASSOC() {
+ return (int)198L;
+ }
+ public static int _SC_LEVEL4_CACHE_LINESIZE() {
+ return (int)199L;
+ }
+ public static int _SC_IPV6() {
+ return (int)235L;
+ }
+ public static int _SC_RAW_SOCKETS() {
+ return (int)236L;
+ }
+ public static int _SC_V7_ILP32_OFF32() {
+ return (int)237L;
+ }
+ public static int _SC_V7_ILP32_OFFBIG() {
+ return (int)238L;
+ }
+ public static int _SC_V7_LP64_OFF64() {
+ return (int)239L;
+ }
+ public static int _SC_V7_LPBIG_OFFBIG() {
+ return (int)240L;
+ }
+ public static int _SC_SS_REPL_MAX() {
+ return (int)241L;
+ }
+ public static int _SC_TRACE_EVENT_NAME_MAX() {
+ return (int)242L;
+ }
+ public static int _SC_TRACE_NAME_MAX() {
+ return (int)243L;
+ }
+ public static int _SC_TRACE_SYS_MAX() {
+ return (int)244L;
+ }
+ public static int _SC_TRACE_USER_EVENT_MAX() {
+ return (int)245L;
+ }
+ public static int _SC_XOPEN_STREAMS() {
+ return (int)246L;
+ }
+ public static int _SC_THREAD_ROBUST_PRIO_INHERIT() {
+ return (int)247L;
+ }
+ public static int _SC_THREAD_ROBUST_PRIO_PROTECT() {
+ return (int)248L;
+ }
+ public static int _SC_MINSIGSTKSZ() {
+ return (int)249L;
+ }
+ public static int _SC_SIGSTKSZ() {
+ return (int)250L;
+ }
+ public static int _CS_PATH() {
+ return (int)0L;
+ }
+ public static int _CS_V6_WIDTH_RESTRICTED_ENVS() {
+ return (int)1L;
+ }
+ public static int _CS_GNU_LIBC_VERSION() {
+ return (int)2L;
+ }
+ public static int _CS_GNU_LIBPTHREAD_VERSION() {
+ return (int)3L;
+ }
+ public static int _CS_V5_WIDTH_RESTRICTED_ENVS() {
+ return (int)4L;
+ }
+ public static int _CS_V7_WIDTH_RESTRICTED_ENVS() {
+ return (int)5L;
+ }
+ public static int _CS_LFS_CFLAGS() {
+ return (int)1000L;
+ }
+ public static int _CS_LFS_LDFLAGS() {
+ return (int)1001L;
+ }
+ public static int _CS_LFS_LIBS() {
+ return (int)1002L;
+ }
+ public static int _CS_LFS_LINTFLAGS() {
+ return (int)1003L;
+ }
+ public static int _CS_LFS64_CFLAGS() {
+ return (int)1004L;
+ }
+ public static int _CS_LFS64_LDFLAGS() {
+ return (int)1005L;
+ }
+ public static int _CS_LFS64_LIBS() {
+ return (int)1006L;
+ }
+ public static int _CS_LFS64_LINTFLAGS() {
+ return (int)1007L;
+ }
+ public static int _CS_XBS5_ILP32_OFF32_CFLAGS() {
+ return (int)1100L;
+ }
+ public static int _CS_XBS5_ILP32_OFF32_LDFLAGS() {
+ return (int)1101L;
+ }
+ public static int _CS_XBS5_ILP32_OFF32_LIBS() {
+ return (int)1102L;
+ }
+ public static int _CS_XBS5_ILP32_OFF32_LINTFLAGS() {
+ return (int)1103L;
+ }
+ public static int _CS_XBS5_ILP32_OFFBIG_CFLAGS() {
+ return (int)1104L;
+ }
+ public static int _CS_XBS5_ILP32_OFFBIG_LDFLAGS() {
+ return (int)1105L;
+ }
+ public static int _CS_XBS5_ILP32_OFFBIG_LIBS() {
+ return (int)1106L;
+ }
+ public static int _CS_XBS5_ILP32_OFFBIG_LINTFLAGS() {
+ return (int)1107L;
+ }
+ public static int _CS_XBS5_LP64_OFF64_CFLAGS() {
+ return (int)1108L;
+ }
+ public static int _CS_XBS5_LP64_OFF64_LDFLAGS() {
+ return (int)1109L;
+ }
+ public static int _CS_XBS5_LP64_OFF64_LIBS() {
+ return (int)1110L;
+ }
+ public static int _CS_XBS5_LP64_OFF64_LINTFLAGS() {
+ return (int)1111L;
+ }
+ public static int _CS_XBS5_LPBIG_OFFBIG_CFLAGS() {
+ return (int)1112L;
+ }
+ public static int _CS_XBS5_LPBIG_OFFBIG_LDFLAGS() {
+ return (int)1113L;
+ }
+ public static int _CS_XBS5_LPBIG_OFFBIG_LIBS() {
+ return (int)1114L;
+ }
+ public static int _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS() {
+ return (int)1115L;
+ }
+ public static int _CS_POSIX_V6_ILP32_OFF32_CFLAGS() {
+ return (int)1116L;
+ }
+ public static int _CS_POSIX_V6_ILP32_OFF32_LDFLAGS() {
+ return (int)1117L;
+ }
+ public static int _CS_POSIX_V6_ILP32_OFF32_LIBS() {
+ return (int)1118L;
+ }
+ public static int _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS() {
+ return (int)1119L;
+ }
+ public static int _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS() {
+ return (int)1120L;
+ }
+ public static int _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS() {
+ return (int)1121L;
+ }
+ public static int _CS_POSIX_V6_ILP32_OFFBIG_LIBS() {
+ return (int)1122L;
+ }
+ public static int _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS() {
+ return (int)1123L;
+ }
+ public static int _CS_POSIX_V6_LP64_OFF64_CFLAGS() {
+ return (int)1124L;
+ }
+ public static int _CS_POSIX_V6_LP64_OFF64_LDFLAGS() {
+ return (int)1125L;
+ }
+ public static int _CS_POSIX_V6_LP64_OFF64_LIBS() {
+ return (int)1126L;
+ }
+ public static int _CS_POSIX_V6_LP64_OFF64_LINTFLAGS() {
+ return (int)1127L;
+ }
+ public static int _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS() {
+ return (int)1128L;
+ }
+ public static int _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS() {
+ return (int)1129L;
+ }
+ public static int _CS_POSIX_V6_LPBIG_OFFBIG_LIBS() {
+ return (int)1130L;
+ }
+ public static int _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS() {
+ return (int)1131L;
+ }
+ public static int _CS_POSIX_V7_ILP32_OFF32_CFLAGS() {
+ return (int)1132L;
+ }
+ public static int _CS_POSIX_V7_ILP32_OFF32_LDFLAGS() {
+ return (int)1133L;
+ }
+ public static int _CS_POSIX_V7_ILP32_OFF32_LIBS() {
+ return (int)1134L;
+ }
+ public static int _CS_POSIX_V7_ILP32_OFF32_LINTFLAGS() {
+ return (int)1135L;
+ }
+ public static int _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS() {
+ return (int)1136L;
+ }
+ public static int _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS() {
+ return (int)1137L;
+ }
+ public static int _CS_POSIX_V7_ILP32_OFFBIG_LIBS() {
+ return (int)1138L;
+ }
+ public static int _CS_POSIX_V7_ILP32_OFFBIG_LINTFLAGS() {
+ return (int)1139L;
+ }
+ public static int _CS_POSIX_V7_LP64_OFF64_CFLAGS() {
+ return (int)1140L;
+ }
+ public static int _CS_POSIX_V7_LP64_OFF64_LDFLAGS() {
+ return (int)1141L;
+ }
+ public static int _CS_POSIX_V7_LP64_OFF64_LIBS() {
+ return (int)1142L;
+ }
+ public static int _CS_POSIX_V7_LP64_OFF64_LINTFLAGS() {
+ return (int)1143L;
+ }
+ public static int _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS() {
+ return (int)1144L;
+ }
+ public static int _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS() {
+ return (int)1145L;
+ }
+ public static int _CS_POSIX_V7_LPBIG_OFFBIG_LIBS() {
+ return (int)1146L;
+ }
+ public static int _CS_POSIX_V7_LPBIG_OFFBIG_LINTFLAGS() {
+ return (int)1147L;
+ }
+ public static int _CS_V6_ENV() {
+ return (int)1148L;
+ }
+ public static int _CS_V7_ENV() {
+ return (int)1149L;
+ }
+ public static MethodHandle pathconf$MH() {
+ return RuntimeHelper.requireNonNull(constants$5.pathconf$MH,"pathconf");
+ }
+ public static long pathconf ( Addressable __path, int __name) {
+ var mh$ = pathconf$MH();
+ try {
+ return (long)mh$.invokeExact(__path, __name);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle fpathconf$MH() {
+ return RuntimeHelper.requireNonNull(constants$6.fpathconf$MH,"fpathconf");
+ }
+ public static long fpathconf ( int __fd, int __name) {
+ var mh$ = fpathconf$MH();
+ try {
+ return (long)mh$.invokeExact(__fd, __name);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle sysconf$MH() {
+ return RuntimeHelper.requireNonNull(constants$6.sysconf$MH,"sysconf");
+ }
+ public static long sysconf ( int __name) {
+ var mh$ = sysconf$MH();
+ try {
+ return (long)mh$.invokeExact(__name);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle confstr$MH() {
+ return RuntimeHelper.requireNonNull(constants$6.confstr$MH,"confstr");
+ }
+ public static long confstr ( int __name, Addressable __buf, long __len) {
+ var mh$ = confstr$MH();
+ try {
+ return (long)mh$.invokeExact(__name, __buf, __len);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle getpid$MH() {
+ return RuntimeHelper.requireNonNull(constants$6.getpid$MH,"getpid");
+ }
+ public static int getpid () {
+ var mh$ = getpid$MH();
+ try {
+ return (int)mh$.invokeExact();
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle getppid$MH() {
+ return RuntimeHelper.requireNonNull(constants$6.getppid$MH,"getppid");
+ }
+ public static int getppid () {
+ var mh$ = getppid$MH();
+ try {
+ return (int)mh$.invokeExact();
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle getpgrp$MH() {
+ return RuntimeHelper.requireNonNull(constants$6.getpgrp$MH,"getpgrp");
+ }
+ public static int getpgrp () {
+ var mh$ = getpgrp$MH();
+ try {
+ return (int)mh$.invokeExact();
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle __getpgid$MH() {
+ return RuntimeHelper.requireNonNull(constants$7.__getpgid$MH,"__getpgid");
+ }
+ public static int __getpgid ( int __pid) {
+ var mh$ = __getpgid$MH();
+ try {
+ return (int)mh$.invokeExact(__pid);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle getpgid$MH() {
+ return RuntimeHelper.requireNonNull(constants$7.getpgid$MH,"getpgid");
+ }
+ public static int getpgid ( int __pid) {
+ var mh$ = getpgid$MH();
+ try {
+ return (int)mh$.invokeExact(__pid);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle setpgid$MH() {
+ return RuntimeHelper.requireNonNull(constants$7.setpgid$MH,"setpgid");
+ }
+ public static int setpgid ( int __pid, int __pgid) {
+ var mh$ = setpgid$MH();
+ try {
+ return (int)mh$.invokeExact(__pid, __pgid);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle setpgrp$MH() {
+ return RuntimeHelper.requireNonNull(constants$7.setpgrp$MH,"setpgrp");
+ }
+ public static int setpgrp () {
+ var mh$ = setpgrp$MH();
+ try {
+ return (int)mh$.invokeExact();
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle setsid$MH() {
+ return RuntimeHelper.requireNonNull(constants$7.setsid$MH,"setsid");
+ }
+ public static int setsid () {
+ var mh$ = setsid$MH();
+ try {
+ return (int)mh$.invokeExact();
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle getsid$MH() {
+ return RuntimeHelper.requireNonNull(constants$7.getsid$MH,"getsid");
+ }
+ public static int getsid ( int __pid) {
+ var mh$ = getsid$MH();
+ try {
+ return (int)mh$.invokeExact(__pid);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle getuid$MH() {
+ return RuntimeHelper.requireNonNull(constants$8.getuid$MH,"getuid");
+ }
+ public static int getuid () {
+ var mh$ = getuid$MH();
+ try {
+ return (int)mh$.invokeExact();
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle geteuid$MH() {
+ return RuntimeHelper.requireNonNull(constants$8.geteuid$MH,"geteuid");
+ }
+ public static int geteuid () {
+ var mh$ = geteuid$MH();
+ try {
+ return (int)mh$.invokeExact();
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle getgid$MH() {
+ return RuntimeHelper.requireNonNull(constants$8.getgid$MH,"getgid");
+ }
+ public static int getgid () {
+ var mh$ = getgid$MH();
+ try {
+ return (int)mh$.invokeExact();
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle getegid$MH() {
+ return RuntimeHelper.requireNonNull(constants$8.getegid$MH,"getegid");
+ }
+ public static int getegid () {
+ var mh$ = getegid$MH();
+ try {
+ return (int)mh$.invokeExact();
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle getgroups$MH() {
+ return RuntimeHelper.requireNonNull(constants$8.getgroups$MH,"getgroups");
+ }
+ public static int getgroups ( int __size, Addressable __list) {
+ var mh$ = getgroups$MH();
+ try {
+ return (int)mh$.invokeExact(__size, __list);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle setuid$MH() {
+ return RuntimeHelper.requireNonNull(constants$8.setuid$MH,"setuid");
+ }
+ public static int setuid ( int __uid) {
+ var mh$ = setuid$MH();
+ try {
+ return (int)mh$.invokeExact(__uid);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle setreuid$MH() {
+ return RuntimeHelper.requireNonNull(constants$9.setreuid$MH,"setreuid");
+ }
+ public static int setreuid ( int __ruid, int __euid) {
+ var mh$ = setreuid$MH();
+ try {
+ return (int)mh$.invokeExact(__ruid, __euid);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle seteuid$MH() {
+ return RuntimeHelper.requireNonNull(constants$9.seteuid$MH,"seteuid");
+ }
+ public static int seteuid ( int __uid) {
+ var mh$ = seteuid$MH();
+ try {
+ return (int)mh$.invokeExact(__uid);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle setgid$MH() {
+ return RuntimeHelper.requireNonNull(constants$9.setgid$MH,"setgid");
+ }
+ public static int setgid ( int __gid) {
+ var mh$ = setgid$MH();
+ try {
+ return (int)mh$.invokeExact(__gid);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle setregid$MH() {
+ return RuntimeHelper.requireNonNull(constants$9.setregid$MH,"setregid");
+ }
+ public static int setregid ( int __rgid, int __egid) {
+ var mh$ = setregid$MH();
+ try {
+ return (int)mh$.invokeExact(__rgid, __egid);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle setegid$MH() {
+ return RuntimeHelper.requireNonNull(constants$9.setegid$MH,"setegid");
+ }
+ public static int setegid ( int __gid) {
+ var mh$ = setegid$MH();
+ try {
+ return (int)mh$.invokeExact(__gid);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle fork$MH() {
+ return RuntimeHelper.requireNonNull(constants$9.fork$MH,"fork");
+ }
+ public static int fork () {
+ var mh$ = fork$MH();
+ try {
+ return (int)mh$.invokeExact();
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle vfork$MH() {
+ return RuntimeHelper.requireNonNull(constants$10.vfork$MH,"vfork");
+ }
+ public static int vfork () {
+ var mh$ = vfork$MH();
+ try {
+ return (int)mh$.invokeExact();
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle ttyname$MH() {
+ return RuntimeHelper.requireNonNull(constants$10.ttyname$MH,"ttyname");
+ }
+ public static MemoryAddress ttyname ( int __fd) {
+ var mh$ = ttyname$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact(__fd);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle ttyname_r$MH() {
+ return RuntimeHelper.requireNonNull(constants$10.ttyname_r$MH,"ttyname_r");
+ }
+ public static int ttyname_r ( int __fd, Addressable __buf, long __buflen) {
+ var mh$ = ttyname_r$MH();
+ try {
+ return (int)mh$.invokeExact(__fd, __buf, __buflen);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle isatty$MH() {
+ return RuntimeHelper.requireNonNull(constants$10.isatty$MH,"isatty");
+ }
+ public static int isatty ( int __fd) {
+ var mh$ = isatty$MH();
+ try {
+ return (int)mh$.invokeExact(__fd);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle ttyslot$MH() {
+ return RuntimeHelper.requireNonNull(constants$10.ttyslot$MH,"ttyslot");
+ }
+ public static int ttyslot () {
+ var mh$ = ttyslot$MH();
+ try {
+ return (int)mh$.invokeExact();
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle link$MH() {
+ return RuntimeHelper.requireNonNull(constants$10.link$MH,"link");
+ }
+ public static int link ( Addressable __from, Addressable __to) {
+ var mh$ = link$MH();
+ try {
+ return (int)mh$.invokeExact(__from, __to);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle linkat$MH() {
+ return RuntimeHelper.requireNonNull(constants$11.linkat$MH,"linkat");
+ }
+ public static int linkat ( int __fromfd, Addressable __from, int __tofd, Addressable __to, int __flags) {
+ var mh$ = linkat$MH();
+ try {
+ return (int)mh$.invokeExact(__fromfd, __from, __tofd, __to, __flags);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle symlink$MH() {
+ return RuntimeHelper.requireNonNull(constants$11.symlink$MH,"symlink");
+ }
+ public static int symlink ( Addressable __from, Addressable __to) {
+ var mh$ = symlink$MH();
+ try {
+ return (int)mh$.invokeExact(__from, __to);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle readlink$MH() {
+ return RuntimeHelper.requireNonNull(constants$11.readlink$MH,"readlink");
+ }
+ public static long readlink ( Addressable __path, Addressable __buf, long __len) {
+ var mh$ = readlink$MH();
+ try {
+ return (long)mh$.invokeExact(__path, __buf, __len);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle symlinkat$MH() {
+ return RuntimeHelper.requireNonNull(constants$11.symlinkat$MH,"symlinkat");
+ }
+ public static int symlinkat ( Addressable __from, int __tofd, Addressable __to) {
+ var mh$ = symlinkat$MH();
+ try {
+ return (int)mh$.invokeExact(__from, __tofd, __to);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle readlinkat$MH() {
+ return RuntimeHelper.requireNonNull(constants$11.readlinkat$MH,"readlinkat");
+ }
+ public static long readlinkat ( int __fd, Addressable __path, Addressable __buf, long __len) {
+ var mh$ = readlinkat$MH();
+ try {
+ return (long)mh$.invokeExact(__fd, __path, __buf, __len);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle unlink$MH() {
+ return RuntimeHelper.requireNonNull(constants$11.unlink$MH,"unlink");
+ }
+ public static int unlink ( Addressable __name) {
+ var mh$ = unlink$MH();
+ try {
+ return (int)mh$.invokeExact(__name);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle unlinkat$MH() {
+ return RuntimeHelper.requireNonNull(constants$12.unlinkat$MH,"unlinkat");
+ }
+ public static int unlinkat ( int __fd, Addressable __name, int __flag) {
+ var mh$ = unlinkat$MH();
+ try {
+ return (int)mh$.invokeExact(__fd, __name, __flag);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle rmdir$MH() {
+ return RuntimeHelper.requireNonNull(constants$12.rmdir$MH,"rmdir");
+ }
+ public static int rmdir ( Addressable __path) {
+ var mh$ = rmdir$MH();
+ try {
+ return (int)mh$.invokeExact(__path);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle tcgetpgrp$MH() {
+ return RuntimeHelper.requireNonNull(constants$12.tcgetpgrp$MH,"tcgetpgrp");
+ }
+ public static int tcgetpgrp ( int __fd) {
+ var mh$ = tcgetpgrp$MH();
+ try {
+ return (int)mh$.invokeExact(__fd);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle tcsetpgrp$MH() {
+ return RuntimeHelper.requireNonNull(constants$12.tcsetpgrp$MH,"tcsetpgrp");
+ }
+ public static int tcsetpgrp ( int __fd, int __pgrp_id) {
+ var mh$ = tcsetpgrp$MH();
+ try {
+ return (int)mh$.invokeExact(__fd, __pgrp_id);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle getlogin$MH() {
+ return RuntimeHelper.requireNonNull(constants$12.getlogin$MH,"getlogin");
+ }
+ public static MemoryAddress getlogin () {
+ var mh$ = getlogin$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact();
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle getlogin_r$MH() {
+ return RuntimeHelper.requireNonNull(constants$12.getlogin_r$MH,"getlogin_r");
+ }
+ public static int getlogin_r ( Addressable __name, long __name_len) {
+ var mh$ = getlogin_r$MH();
+ try {
+ return (int)mh$.invokeExact(__name, __name_len);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle setlogin$MH() {
+ return RuntimeHelper.requireNonNull(constants$13.setlogin$MH,"setlogin");
+ }
+ public static int setlogin ( Addressable __name) {
+ var mh$ = setlogin$MH();
+ try {
+ return (int)mh$.invokeExact(__name);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MemoryLayout optarg$LAYOUT() {
+ return constants$13.optarg$LAYOUT;
+ }
+ public static VarHandle optarg$VH() {
+ return constants$13.optarg$VH;
+ }
+ public static MemorySegment optarg$SEGMENT() {
+ return RuntimeHelper.requireNonNull(constants$13.optarg$SEGMENT,"optarg");
+ }
+ public static MemoryAddress optarg$get() {
+ return (java.lang.foreign.MemoryAddress) constants$13.optarg$VH.get(RuntimeHelper.requireNonNull(constants$13.optarg$SEGMENT, "optarg"));
+ }
+ public static void optarg$set( MemoryAddress x) {
+ constants$13.optarg$VH.set(RuntimeHelper.requireNonNull(constants$13.optarg$SEGMENT, "optarg"), x);
+ }
+ public static MemoryLayout optind$LAYOUT() {
+ return constants$13.optind$LAYOUT;
+ }
+ public static VarHandle optind$VH() {
+ return constants$13.optind$VH;
+ }
+ public static MemorySegment optind$SEGMENT() {
+ return RuntimeHelper.requireNonNull(constants$13.optind$SEGMENT,"optind");
+ }
+ public static int optind$get() {
+ return (int) constants$13.optind$VH.get(RuntimeHelper.requireNonNull(constants$13.optind$SEGMENT, "optind"));
+ }
+ public static void optind$set( int x) {
+ constants$13.optind$VH.set(RuntimeHelper.requireNonNull(constants$13.optind$SEGMENT, "optind"), x);
+ }
+ public static MemoryLayout opterr$LAYOUT() {
+ return constants$13.opterr$LAYOUT;
+ }
+ public static VarHandle opterr$VH() {
+ return constants$13.opterr$VH;
+ }
+ public static MemorySegment opterr$SEGMENT() {
+ return RuntimeHelper.requireNonNull(constants$13.opterr$SEGMENT,"opterr");
+ }
+ public static int opterr$get() {
+ return (int) constants$13.opterr$VH.get(RuntimeHelper.requireNonNull(constants$13.opterr$SEGMENT, "opterr"));
+ }
+ public static void opterr$set( int x) {
+ constants$13.opterr$VH.set(RuntimeHelper.requireNonNull(constants$13.opterr$SEGMENT, "opterr"), x);
+ }
+ public static MemoryLayout optopt$LAYOUT() {
+ return constants$13.optopt$LAYOUT;
+ }
+ public static VarHandle optopt$VH() {
+ return constants$13.optopt$VH;
+ }
+ public static MemorySegment optopt$SEGMENT() {
+ return RuntimeHelper.requireNonNull(constants$13.optopt$SEGMENT,"optopt");
+ }
+ public static int optopt$get() {
+ return (int) constants$13.optopt$VH.get(RuntimeHelper.requireNonNull(constants$13.optopt$SEGMENT, "optopt"));
+ }
+ public static void optopt$set( int x) {
+ constants$13.optopt$VH.set(RuntimeHelper.requireNonNull(constants$13.optopt$SEGMENT, "optopt"), x);
+ }
+ public static MethodHandle getopt$MH() {
+ return RuntimeHelper.requireNonNull(constants$13.getopt$MH,"getopt");
+ }
+ public static int getopt ( int ___argc, Addressable ___argv, Addressable __shortopts) {
+ var mh$ = getopt$MH();
+ try {
+ return (int)mh$.invokeExact(___argc, ___argv, __shortopts);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle gethostname$MH() {
+ return RuntimeHelper.requireNonNull(constants$14.gethostname$MH,"gethostname");
+ }
+ public static int gethostname ( Addressable __name, long __len) {
+ var mh$ = gethostname$MH();
+ try {
+ return (int)mh$.invokeExact(__name, __len);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle sethostname$MH() {
+ return RuntimeHelper.requireNonNull(constants$14.sethostname$MH,"sethostname");
+ }
+ public static int sethostname ( Addressable __name, long __len) {
+ var mh$ = sethostname$MH();
+ try {
+ return (int)mh$.invokeExact(__name, __len);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle sethostid$MH() {
+ return RuntimeHelper.requireNonNull(constants$14.sethostid$MH,"sethostid");
+ }
+ public static int sethostid ( long __id) {
+ var mh$ = sethostid$MH();
+ try {
+ return (int)mh$.invokeExact(__id);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle getdomainname$MH() {
+ return RuntimeHelper.requireNonNull(constants$14.getdomainname$MH,"getdomainname");
+ }
+ public static int getdomainname ( Addressable __name, long __len) {
+ var mh$ = getdomainname$MH();
+ try {
+ return (int)mh$.invokeExact(__name, __len);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle setdomainname$MH() {
+ return RuntimeHelper.requireNonNull(constants$14.setdomainname$MH,"setdomainname");
+ }
+ public static int setdomainname ( Addressable __name, long __len) {
+ var mh$ = setdomainname$MH();
+ try {
+ return (int)mh$.invokeExact(__name, __len);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle vhangup$MH() {
+ return RuntimeHelper.requireNonNull(constants$14.vhangup$MH,"vhangup");
+ }
+ public static int vhangup () {
+ var mh$ = vhangup$MH();
+ try {
+ return (int)mh$.invokeExact();
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle revoke$MH() {
+ return RuntimeHelper.requireNonNull(constants$15.revoke$MH,"revoke");
+ }
+ public static int revoke ( Addressable __file) {
+ var mh$ = revoke$MH();
+ try {
+ return (int)mh$.invokeExact(__file);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle profil$MH() {
+ return RuntimeHelper.requireNonNull(constants$15.profil$MH,"profil");
+ }
+ public static int profil ( Addressable __sample_buffer, long __size, long __offset, int __scale) {
+ var mh$ = profil$MH();
+ try {
+ return (int)mh$.invokeExact(__sample_buffer, __size, __offset, __scale);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle acct$MH() {
+ return RuntimeHelper.requireNonNull(constants$15.acct$MH,"acct");
+ }
+ public static int acct ( Addressable __name) {
+ var mh$ = acct$MH();
+ try {
+ return (int)mh$.invokeExact(__name);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle getusershell$MH() {
+ return RuntimeHelper.requireNonNull(constants$15.getusershell$MH,"getusershell");
+ }
+ public static MemoryAddress getusershell () {
+ var mh$ = getusershell$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact();
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle endusershell$MH() {
+ return RuntimeHelper.requireNonNull(constants$15.endusershell$MH,"endusershell");
+ }
+ public static void endusershell () {
+ var mh$ = endusershell$MH();
+ try {
+ mh$.invokeExact();
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle setusershell$MH() {
+ return RuntimeHelper.requireNonNull(constants$15.setusershell$MH,"setusershell");
+ }
+ public static void setusershell () {
+ var mh$ = setusershell$MH();
+ try {
+ mh$.invokeExact();
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle daemon$MH() {
+ return RuntimeHelper.requireNonNull(constants$16.daemon$MH,"daemon");
+ }
+ public static int daemon ( int __nochdir, int __noclose) {
+ var mh$ = daemon$MH();
+ try {
+ return (int)mh$.invokeExact(__nochdir, __noclose);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle chroot$MH() {
+ return RuntimeHelper.requireNonNull(constants$16.chroot$MH,"chroot");
+ }
+ public static int chroot ( Addressable __path) {
+ var mh$ = chroot$MH();
+ try {
+ return (int)mh$.invokeExact(__path);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle getpass$MH() {
+ return RuntimeHelper.requireNonNull(constants$16.getpass$MH,"getpass");
+ }
+ public static MemoryAddress getpass ( Addressable __prompt) {
+ var mh$ = getpass$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact(__prompt);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle fsync$MH() {
+ return RuntimeHelper.requireNonNull(constants$16.fsync$MH,"fsync");
+ }
+ public static int fsync ( int __fd) {
+ var mh$ = fsync$MH();
+ try {
+ return (int)mh$.invokeExact(__fd);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle gethostid$MH() {
+ return RuntimeHelper.requireNonNull(constants$16.gethostid$MH,"gethostid");
+ }
+ public static long gethostid () {
+ var mh$ = gethostid$MH();
+ try {
+ return (long)mh$.invokeExact();
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle sync$MH() {
+ return RuntimeHelper.requireNonNull(constants$16.sync$MH,"sync");
+ }
+ public static void sync () {
+ var mh$ = sync$MH();
+ try {
+ mh$.invokeExact();
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle getpagesize$MH() {
+ return RuntimeHelper.requireNonNull(constants$17.getpagesize$MH,"getpagesize");
+ }
+ public static int getpagesize () {
+ var mh$ = getpagesize$MH();
+ try {
+ return (int)mh$.invokeExact();
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle getdtablesize$MH() {
+ return RuntimeHelper.requireNonNull(constants$17.getdtablesize$MH,"getdtablesize");
+ }
+ public static int getdtablesize () {
+ var mh$ = getdtablesize$MH();
+ try {
+ return (int)mh$.invokeExact();
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle truncate$MH() {
+ return RuntimeHelper.requireNonNull(constants$17.truncate$MH,"truncate");
+ }
+ public static int truncate ( Addressable __file, long __length) {
+ var mh$ = truncate$MH();
+ try {
+ return (int)mh$.invokeExact(__file, __length);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle ftruncate$MH() {
+ return RuntimeHelper.requireNonNull(constants$17.ftruncate$MH,"ftruncate");
+ }
+ public static int ftruncate ( int __fd, long __length) {
+ var mh$ = ftruncate$MH();
+ try {
+ return (int)mh$.invokeExact(__fd, __length);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle brk$MH() {
+ return RuntimeHelper.requireNonNull(constants$17.brk$MH,"brk");
+ }
+ public static int brk ( Addressable __addr) {
+ var mh$ = brk$MH();
+ try {
+ return (int)mh$.invokeExact(__addr);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle sbrk$MH() {
+ return RuntimeHelper.requireNonNull(constants$17.sbrk$MH,"sbrk");
+ }
+ public static MemoryAddress sbrk ( long __delta) {
+ var mh$ = sbrk$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact(__delta);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle syscall$MH() {
+ return RuntimeHelper.requireNonNull(constants$18.syscall$MH,"syscall");
+ }
+ public static long syscall ( long __sysno, Object... x1) {
+ var mh$ = syscall$MH();
+ try {
+ return (long)mh$.invokeExact(__sysno, x1);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle lockf$MH() {
+ return RuntimeHelper.requireNonNull(constants$18.lockf$MH,"lockf");
+ }
+ public static int lockf ( int __fd, int __cmd, long __len) {
+ var mh$ = lockf$MH();
+ try {
+ return (int)mh$.invokeExact(__fd, __cmd, __len);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle fdatasync$MH() {
+ return RuntimeHelper.requireNonNull(constants$18.fdatasync$MH,"fdatasync");
+ }
+ public static int fdatasync ( int __fildes) {
+ var mh$ = fdatasync$MH();
+ try {
+ return (int)mh$.invokeExact(__fildes);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle crypt$MH() {
+ return RuntimeHelper.requireNonNull(constants$18.crypt$MH,"crypt");
+ }
+ public static MemoryAddress crypt ( Addressable __key, Addressable __salt) {
+ var mh$ = crypt$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact(__key, __salt);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle getentropy$MH() {
+ return RuntimeHelper.requireNonNull(constants$18.getentropy$MH,"getentropy");
+ }
+ public static int getentropy ( Addressable __buffer, long __length) {
+ var mh$ = getentropy$MH();
+ try {
+ return (int)mh$.invokeExact(__buffer, __length);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static long _POSIX_C_SOURCE() {
+ return 200809L;
+ }
+ public static int __TIMESIZE() {
+ return (int)64L;
+ }
+ public static long __STDC_IEC_60559_BFP__() {
+ return 201404L;
+ }
+ public static long __STDC_IEC_60559_COMPLEX__() {
+ return 201404L;
+ }
+ public static long __STDC_ISO_10646__() {
+ return 201706L;
+ }
+ public static long _POSIX_VERSION() {
+ return 200809L;
+ }
+ public static long __POSIX2_THIS_VERSION() {
+ return 200809L;
+ }
+ public static long _POSIX2_VERSION() {
+ return 200809L;
+ }
+ public static long _POSIX2_C_VERSION() {
+ return 200809L;
+ }
+ public static long _POSIX2_C_BIND() {
+ return 200809L;
+ }
+ public static long _POSIX2_C_DEV() {
+ return 200809L;
+ }
+ public static long _POSIX2_SW_DEV() {
+ return 200809L;
+ }
+ public static long _POSIX2_LOCALEDEF() {
+ return 200809L;
+ }
+ public static long _POSIX_PRIORITY_SCHEDULING() {
+ return 200809L;
+ }
+ public static long _POSIX_SYNCHRONIZED_IO() {
+ return 200809L;
+ }
+ public static long _POSIX_FSYNC() {
+ return 200809L;
+ }
+ public static long _POSIX_MAPPED_FILES() {
+ return 200809L;
+ }
+ public static long _POSIX_MEMLOCK() {
+ return 200809L;
+ }
+ public static long _POSIX_MEMLOCK_RANGE() {
+ return 200809L;
+ }
+ public static long _POSIX_MEMORY_PROTECTION() {
+ return 200809L;
+ }
+ public static int _POSIX_VDISABLE() {
+ return (int)0L;
+ }
+ public static long _POSIX_THREADS() {
+ return 200809L;
+ }
+ public static long _POSIX_THREAD_SAFE_FUNCTIONS() {
+ return 200809L;
+ }
+ public static long _POSIX_THREAD_PRIORITY_SCHEDULING() {
+ return 200809L;
+ }
+ public static long _POSIX_THREAD_ATTR_STACKSIZE() {
+ return 200809L;
+ }
+ public static long _POSIX_THREAD_ATTR_STACKADDR() {
+ return 200809L;
+ }
+ public static long _POSIX_THREAD_PRIO_INHERIT() {
+ return 200809L;
+ }
+ public static long _POSIX_THREAD_PRIO_PROTECT() {
+ return 200809L;
+ }
+ public static long _POSIX_THREAD_ROBUST_PRIO_INHERIT() {
+ return 200809L;
+ }
+ public static int _POSIX_THREAD_ROBUST_PRIO_PROTECT() {
+ return (int)-1L;
+ }
+ public static long _POSIX_SEMAPHORES() {
+ return 200809L;
+ }
+ public static long _POSIX_REALTIME_SIGNALS() {
+ return 200809L;
+ }
+ public static long _POSIX_ASYNCHRONOUS_IO() {
+ return 200809L;
+ }
+ public static long _POSIX_PRIORITIZED_IO() {
+ return 200809L;
+ }
+ public static long _POSIX_SHARED_MEMORY_OBJECTS() {
+ return 200809L;
+ }
+ public static long _POSIX_READER_WRITER_LOCKS() {
+ return 200809L;
+ }
+ public static long _POSIX_TIMEOUTS() {
+ return 200809L;
+ }
+ public static long _POSIX_SPIN_LOCKS() {
+ return 200809L;
+ }
+ public static long _POSIX_SPAWN() {
+ return 200809L;
+ }
+ public static long _POSIX_TIMERS() {
+ return 200809L;
+ }
+ public static long _POSIX_BARRIERS() {
+ return 200809L;
+ }
+ public static long _POSIX_MESSAGE_PASSING() {
+ return 200809L;
+ }
+ public static long _POSIX_THREAD_PROCESS_SHARED() {
+ return 200809L;
+ }
+ public static long _POSIX_CLOCK_SELECTION() {
+ return 200809L;
+ }
+ public static long _POSIX_ADVISORY_INFO() {
+ return 200809L;
+ }
+ public static long _POSIX_IPV6() {
+ return 200809L;
+ }
+ public static long _POSIX_RAW_SOCKETS() {
+ return 200809L;
+ }
+ public static long _POSIX2_CHAR_TERM() {
+ return 200809L;
+ }
+ public static int _POSIX_SPORADIC_SERVER() {
+ return (int)-1L;
+ }
+ public static int _POSIX_THREAD_SPORADIC_SERVER() {
+ return (int)-1L;
+ }
+ public static int _POSIX_TRACE() {
+ return (int)-1L;
+ }
+ public static int _POSIX_TRACE_EVENT_FILTER() {
+ return (int)-1L;
+ }
+ public static int _POSIX_TRACE_INHERIT() {
+ return (int)-1L;
+ }
+ public static int _POSIX_TRACE_LOG() {
+ return (int)-1L;
+ }
+ public static int _POSIX_TYPED_MEMORY_OBJECTS() {
+ return (int)-1L;
+ }
+ public static int _POSIX_V7_LPBIG_OFFBIG() {
+ return (int)-1L;
+ }
+ public static int _POSIX_V6_LPBIG_OFFBIG() {
+ return (int)-1L;
+ }
+ public static int _XBS5_LPBIG_OFFBIG() {
+ return (int)-1L;
+ }
+ public static MemorySegment __ILP32_OFF32_CFLAGS() {
+ return constants$18.__ILP32_OFF32_CFLAGS$SEGMENT;
+ }
+ public static MemorySegment __ILP32_OFF32_LDFLAGS() {
+ return constants$19.__ILP32_OFF32_LDFLAGS$SEGMENT;
+ }
+ public static MemorySegment __ILP32_OFFBIG_CFLAGS() {
+ return constants$19.__ILP32_OFFBIG_CFLAGS$SEGMENT;
+ }
+ public static MemorySegment __ILP32_OFFBIG_LDFLAGS() {
+ return constants$19.__ILP32_OFFBIG_LDFLAGS$SEGMENT;
+ }
+ public static MemorySegment __LP64_OFF64_CFLAGS() {
+ return constants$19.__LP64_OFF64_CFLAGS$SEGMENT;
+ }
+ public static MemorySegment __LP64_OFF64_LDFLAGS() {
+ return constants$19.__LP64_OFF64_LDFLAGS$SEGMENT;
+ }
+ public static MemoryAddress NULL() {
+ return constants$19.NULL$ADDR;
+ }
+ public static int L_SET() {
+ return (int)0L;
+ }
+ public static int L_INCR() {
+ return (int)1L;
+ }
+ public static int L_XTND() {
+ return (int)2L;
+ }
+ public static int _SC_PAGE_SIZE() {
+ return (int)30L;
+ }
+ public static int _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS() {
+ return (int)1L;
+ }
+ public static int _CS_POSIX_V5_WIDTH_RESTRICTED_ENVS() {
+ return (int)4L;
+ }
+ public static int _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS() {
+ return (int)5L;
+ }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/Constants$root.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/Constants$root.java
new file mode 100644
index 00000000..e013f088
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/Constants$root.java
@@ -0,0 +1,19 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.usbdevice_fs;
+
+import static java.lang.foreign.ValueLayout.*;
+public class Constants$root {
+
+ static final OfBoolean C_BOOL$LAYOUT = JAVA_BOOLEAN;
+ static final OfByte C_CHAR$LAYOUT = JAVA_BYTE;
+ static final OfShort C_SHORT$LAYOUT = JAVA_SHORT.withBitAlignment(16);
+ static final OfInt C_INT$LAYOUT = JAVA_INT.withBitAlignment(32);
+ static final OfLong C_LONG$LAYOUT = JAVA_LONG.withBitAlignment(64);
+ static final OfLong C_LONG_LONG$LAYOUT = JAVA_LONG.withBitAlignment(64);
+ static final OfFloat C_FLOAT$LAYOUT = JAVA_FLOAT.withBitAlignment(32);
+ static final OfDouble C_DOUBLE$LAYOUT = JAVA_DOUBLE.withBitAlignment(64);
+ static final OfAddress C_POINTER$LAYOUT = ADDRESS.withBitAlignment(64);
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/RuntimeHelper.java
new file mode 100644
index 00000000..8d30b2af
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/RuntimeHelper.java
@@ -0,0 +1,216 @@
+package net.codecrete.usb.linux.gen.usbdevice_fs;
+// Generated by jextract
+
+import java.lang.foreign.*;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+
+import static java.lang.foreign.ValueLayout.*;
+
+final class RuntimeHelper {
+
+ private RuntimeHelper() {}
+ private final static Linker LINKER = Linker.nativeLinker();
+ private final static ClassLoader LOADER = RuntimeHelper.class.getClassLoader();
+ private final static MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup();
+ private final static SymbolLookup SYMBOL_LOOKUP;
+
+ final static SegmentAllocator CONSTANT_ALLOCATOR =
+ (size, align) -> MemorySegment.allocateNative(size, align, MemorySession.openImplicit());
+
+ static {
+
+ SymbolLookup loaderLookup = SymbolLookup.loaderLookup();
+ SYMBOL_LOOKUP = name -> loaderLookup.lookup(name).or(() -> LINKER.defaultLookup().lookup(name));
+ }
+
+ static T requireNonNull(T obj, String symbolName) {
+ if (obj == null) {
+ throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName);
+ }
+ return obj;
+ }
+
+ private final static SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); };
+
+ static final MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) {
+ return SYMBOL_LOOKUP.lookup(name).map(symbol -> MemorySegment.ofAddress(symbol.address(), layout.byteSize(), MemorySession.openShared())).orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> LINKER.downcallHandle(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(FunctionDescriptor fdesc) {
+ return LINKER.downcallHandle(fdesc);
+ }
+
+ static final MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> VarargsInvoker.make(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MemorySegment upcallStub(Class fi, Z z, FunctionDescriptor fdesc, MemorySession session) {
+ try {
+ MethodHandle handle = MH_LOOKUP.findVirtual(fi, "apply", Linker.upcallType(fdesc));
+ handle = handle.bindTo(z);
+ return LINKER.upcallStub(handle, fdesc, session);
+ } catch (Throwable ex) {
+ throw new AssertionError(ex);
+ }
+ }
+
+ static MemorySegment asArray(MemoryAddress addr, MemoryLayout layout, int numElements, MemorySession session) {
+ return MemorySegment.ofAddress(addr, numElements * layout.byteSize(), session);
+ }
+
+ // Internals only below this point
+
+ private static class VarargsInvoker {
+ private static final MethodHandle INVOKE_MH;
+ private final MemorySegment symbol;
+ private final FunctionDescriptor function;
+
+ private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) {
+ this.symbol = symbol;
+ this.function = function;
+ }
+
+ static {
+ try {
+ INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class));
+ } catch (ReflectiveOperationException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) {
+ VarargsInvoker invoker = new VarargsInvoker(symbol, function);
+ MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1);
+ MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class);
+ for (MemoryLayout layout : function.argumentLayouts()) {
+ mtype = mtype.appendParameterTypes(carrier(layout, false));
+ }
+ mtype = mtype.appendParameterTypes(Object[].class);
+ if (mtype.returnType().equals(MemorySegment.class)) {
+ mtype = mtype.insertParameterTypes(0, SegmentAllocator.class);
+ } else {
+ handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR);
+ }
+ return handle.asType(mtype);
+ }
+
+ static Class> carrier(MemoryLayout layout, boolean ret) {
+ if (layout instanceof ValueLayout valueLayout) {
+ return (ret || valueLayout.carrier() != MemoryAddress.class) ?
+ valueLayout.carrier() : Addressable.class;
+ } else if (layout instanceof GroupLayout) {
+ return MemorySegment.class;
+ } else {
+ throw new AssertionError("Cannot get here!");
+ }
+ }
+
+ private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable {
+ // one trailing Object[]
+ int nNamedArgs = function.argumentLayouts().size();
+ assert(args.length == nNamedArgs + 1);
+ // The last argument is the array of vararg collector
+ Object[] unnamedArgs = (Object[]) args[args.length - 1];
+
+ int argsCount = nNamedArgs + unnamedArgs.length;
+ Class>[] argTypes = new Class>[argsCount];
+ MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length];
+
+ int pos = 0;
+ for (pos = 0; pos < nNamedArgs; pos++) {
+ argLayouts[pos] = function.argumentLayouts().get(pos);
+ }
+
+ assert pos == nNamedArgs;
+ for (Object o: unnamedArgs) {
+ argLayouts[pos] = variadicLayout(normalize(o.getClass()));
+ pos++;
+ }
+ assert pos == argsCount;
+
+ FunctionDescriptor f = (function.returnLayout().isEmpty()) ?
+ FunctionDescriptor.ofVoid(argLayouts) :
+ FunctionDescriptor.of(function.returnLayout().get(), argLayouts);
+ MethodHandle mh = LINKER.downcallHandle(symbol, f);
+ if (mh.type().returnType() == MemorySegment.class) {
+ mh = mh.bindTo(allocator);
+ }
+ // flatten argument list so that it can be passed to an asSpreader MH
+ Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length];
+ System.arraycopy(args, 0, allArgs, 0, nNamedArgs);
+ System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length);
+
+ return mh.asSpreader(Object[].class, argsCount).invoke(allArgs);
+ }
+
+ private static Class> unboxIfNeeded(Class> clazz) {
+ if (clazz == Boolean.class) {
+ return boolean.class;
+ } else if (clazz == Void.class) {
+ return void.class;
+ } else if (clazz == Byte.class) {
+ return byte.class;
+ } else if (clazz == Character.class) {
+ return char.class;
+ } else if (clazz == Short.class) {
+ return short.class;
+ } else if (clazz == Integer.class) {
+ return int.class;
+ } else if (clazz == Long.class) {
+ return long.class;
+ } else if (clazz == Float.class) {
+ return float.class;
+ } else if (clazz == Double.class) {
+ return double.class;
+ } else {
+ return clazz;
+ }
+ }
+
+ private Class> promote(Class> c) {
+ if (c == byte.class || c == char.class || c == short.class || c == int.class) {
+ return long.class;
+ } else if (c == float.class) {
+ return double.class;
+ } else {
+ return c;
+ }
+ }
+
+ private Class> normalize(Class> c) {
+ c = unboxIfNeeded(c);
+ if (c.isPrimitive()) {
+ return promote(c);
+ }
+ if (MemoryAddress.class.isAssignableFrom(c)) {
+ return MemoryAddress.class;
+ }
+ if (MemorySegment.class.isAssignableFrom(c)) {
+ return MemorySegment.class;
+ }
+ throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName());
+ }
+
+ private MemoryLayout variadicLayout(Class> c) {
+ if (c == long.class) {
+ return JAVA_LONG;
+ } else if (c == double.class) {
+ return JAVA_DOUBLE;
+ } else if (MemoryAddress.class.isAssignableFrom(c)) {
+ return ADDRESS;
+ } else {
+ throw new IllegalArgumentException("Unhandled variadic argument class: " + c);
+ }
+ }
+ }
+}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/__kernel_fd_set.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/__kernel_fd_set.java
new file mode 100644
index 00000000..3d447c24
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/__kernel_fd_set.java
@@ -0,0 +1,25 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.usbdevice_fs;
+
+import java.lang.foreign.*;
+public class __kernel_fd_set {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ MemoryLayout.sequenceLayout(16, Constants$root.C_LONG_LONG$LAYOUT).withName("fds_bits")
+ );
+ public static MemoryLayout $LAYOUT() {
+ return __kernel_fd_set.$struct$LAYOUT;
+ }
+ public static MemorySegment fds_bits$slice(MemorySegment seg) {
+ return seg.asSlice(0, 128);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/__kernel_fsid_t.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/__kernel_fsid_t.java
new file mode 100644
index 00000000..1122a232
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/__kernel_fsid_t.java
@@ -0,0 +1,25 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.usbdevice_fs;
+
+import java.lang.foreign.*;
+public class __kernel_fsid_t {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ MemoryLayout.sequenceLayout(2, Constants$root.C_INT$LAYOUT).withName("val")
+ );
+ public static MemoryLayout $LAYOUT() {
+ return __kernel_fsid_t.$struct$LAYOUT;
+ }
+ public static MemorySegment val$slice(MemorySegment seg) {
+ return seg.asSlice(0, 8);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/__kernel_sighandler_t.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/__kernel_sighandler_t.java
new file mode 100644
index 00000000..43fc2525
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/__kernel_sighandler_t.java
@@ -0,0 +1,27 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.usbdevice_fs;
+
+import java.lang.foreign.Addressable;
+import java.lang.foreign.MemoryAddress;
+import java.lang.foreign.MemorySegment;
+import java.lang.foreign.MemorySession;
+public interface __kernel_sighandler_t {
+
+ void apply(int _x0);
+ static MemorySegment allocate(__kernel_sighandler_t fi, MemorySession session) {
+ return RuntimeHelper.upcallStub(__kernel_sighandler_t.class, fi, constants$0.__kernel_sighandler_t$FUNC, session);
+ }
+ static __kernel_sighandler_t ofAddress(MemoryAddress addr, MemorySession session) {
+ MemorySegment symbol = MemorySegment.ofAddress(addr, 0, session);
+ return (int __x0) -> {
+ try {
+ constants$0.__kernel_sighandler_t$MH.invokeExact((Addressable)symbol, __x0);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ };
+ }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$0.java
new file mode 100644
index 00000000..d455d82c
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$0.java
@@ -0,0 +1,21 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.usbdevice_fs;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.foreign.MemorySegment;
+import java.lang.invoke.MethodHandle;
+class constants$0 {
+
+ static final FunctionDescriptor __kernel_sighandler_t$FUNC = FunctionDescriptor.ofVoid(
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle __kernel_sighandler_t$MH = RuntimeHelper.downcallHandle(
+ constants$0.__kernel_sighandler_t$FUNC
+ );
+ static final MemorySegment REISERFS_SUPER_MAGIC_STRING$SEGMENT = RuntimeHelper.CONSTANT_ALLOCATOR.allocateUtf8String("ReIsErFs");
+ static final MemorySegment REISER2FS_SUPER_MAGIC_STRING$SEGMENT = RuntimeHelper.CONSTANT_ALLOCATOR.allocateUtf8String("ReIsEr2Fs");
+ static final MemorySegment REISER2FS_JR_SUPER_MAGIC_STRING$SEGMENT = RuntimeHelper.CONSTANT_ALLOCATOR.allocateUtf8String("ReIsEr3Fs");
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_bulktransfer.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_bulktransfer.java
new file mode 100644
index 00000000..670dc414
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_bulktransfer.java
@@ -0,0 +1,91 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.usbdevice_fs;
+
+import java.lang.foreign.*;
+import java.lang.invoke.VarHandle;
+public class usbdevfs_bulktransfer {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ Constants$root.C_INT$LAYOUT.withName("ep"),
+ Constants$root.C_INT$LAYOUT.withName("len"),
+ Constants$root.C_INT$LAYOUT.withName("timeout"),
+ MemoryLayout.paddingLayout(32),
+ Constants$root.C_POINTER$LAYOUT.withName("data")
+ ).withName("usbdevfs_bulktransfer");
+ public static MemoryLayout $LAYOUT() {
+ return usbdevfs_bulktransfer.$struct$LAYOUT;
+ }
+ static final VarHandle ep$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("ep"));
+ public static VarHandle ep$VH() {
+ return usbdevfs_bulktransfer.ep$VH;
+ }
+ public static int ep$get(MemorySegment seg) {
+ return (int)usbdevfs_bulktransfer.ep$VH.get(seg);
+ }
+ public static void ep$set( MemorySegment seg, int x) {
+ usbdevfs_bulktransfer.ep$VH.set(seg, x);
+ }
+ public static int ep$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_bulktransfer.ep$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void ep$set(MemorySegment seg, long index, int x) {
+ usbdevfs_bulktransfer.ep$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle len$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("len"));
+ public static VarHandle len$VH() {
+ return usbdevfs_bulktransfer.len$VH;
+ }
+ public static int len$get(MemorySegment seg) {
+ return (int)usbdevfs_bulktransfer.len$VH.get(seg);
+ }
+ public static void len$set( MemorySegment seg, int x) {
+ usbdevfs_bulktransfer.len$VH.set(seg, x);
+ }
+ public static int len$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_bulktransfer.len$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void len$set(MemorySegment seg, long index, int x) {
+ usbdevfs_bulktransfer.len$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle timeout$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("timeout"));
+ public static VarHandle timeout$VH() {
+ return usbdevfs_bulktransfer.timeout$VH;
+ }
+ public static int timeout$get(MemorySegment seg) {
+ return (int)usbdevfs_bulktransfer.timeout$VH.get(seg);
+ }
+ public static void timeout$set( MemorySegment seg, int x) {
+ usbdevfs_bulktransfer.timeout$VH.set(seg, x);
+ }
+ public static int timeout$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_bulktransfer.timeout$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void timeout$set(MemorySegment seg, long index, int x) {
+ usbdevfs_bulktransfer.timeout$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle data$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("data"));
+ public static VarHandle data$VH() {
+ return usbdevfs_bulktransfer.data$VH;
+ }
+ public static MemoryAddress data$get(MemorySegment seg) {
+ return (java.lang.foreign.MemoryAddress)usbdevfs_bulktransfer.data$VH.get(seg);
+ }
+ public static void data$set( MemorySegment seg, MemoryAddress x) {
+ usbdevfs_bulktransfer.data$VH.set(seg, x);
+ }
+ public static MemoryAddress data$get(MemorySegment seg, long index) {
+ return (java.lang.foreign.MemoryAddress)usbdevfs_bulktransfer.data$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void data$set(MemorySegment seg, long index, MemoryAddress x) {
+ usbdevfs_bulktransfer.data$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_connectinfo.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_connectinfo.java
new file mode 100644
index 00000000..0ad90f26
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_connectinfo.java
@@ -0,0 +1,57 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.usbdevice_fs;
+
+import java.lang.foreign.*;
+import java.lang.invoke.VarHandle;
+public class usbdevfs_connectinfo {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ Constants$root.C_INT$LAYOUT.withName("devnum"),
+ Constants$root.C_CHAR$LAYOUT.withName("slow"),
+ MemoryLayout.paddingLayout(24)
+ ).withName("usbdevfs_connectinfo");
+ public static MemoryLayout $LAYOUT() {
+ return usbdevfs_connectinfo.$struct$LAYOUT;
+ }
+ static final VarHandle devnum$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("devnum"));
+ public static VarHandle devnum$VH() {
+ return usbdevfs_connectinfo.devnum$VH;
+ }
+ public static int devnum$get(MemorySegment seg) {
+ return (int)usbdevfs_connectinfo.devnum$VH.get(seg);
+ }
+ public static void devnum$set( MemorySegment seg, int x) {
+ usbdevfs_connectinfo.devnum$VH.set(seg, x);
+ }
+ public static int devnum$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_connectinfo.devnum$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void devnum$set(MemorySegment seg, long index, int x) {
+ usbdevfs_connectinfo.devnum$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle slow$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("slow"));
+ public static VarHandle slow$VH() {
+ return usbdevfs_connectinfo.slow$VH;
+ }
+ public static byte slow$get(MemorySegment seg) {
+ return (byte)usbdevfs_connectinfo.slow$VH.get(seg);
+ }
+ public static void slow$set( MemorySegment seg, byte x) {
+ usbdevfs_connectinfo.slow$VH.set(seg, x);
+ }
+ public static byte slow$get(MemorySegment seg, long index) {
+ return (byte)usbdevfs_connectinfo.slow$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void slow$set(MemorySegment seg, long index, byte x) {
+ usbdevfs_connectinfo.slow$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_conninfo_ex.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_conninfo_ex.java
new file mode 100644
index 00000000..3279b19a
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_conninfo_ex.java
@@ -0,0 +1,111 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.usbdevice_fs;
+
+import java.lang.foreign.*;
+import java.lang.invoke.VarHandle;
+public class usbdevfs_conninfo_ex {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ Constants$root.C_INT$LAYOUT.withName("size"),
+ Constants$root.C_INT$LAYOUT.withName("busnum"),
+ Constants$root.C_INT$LAYOUT.withName("devnum"),
+ Constants$root.C_INT$LAYOUT.withName("speed"),
+ Constants$root.C_CHAR$LAYOUT.withName("num_ports"),
+ MemoryLayout.sequenceLayout(7, Constants$root.C_CHAR$LAYOUT).withName("ports")
+ ).withName("usbdevfs_conninfo_ex");
+ public static MemoryLayout $LAYOUT() {
+ return usbdevfs_conninfo_ex.$struct$LAYOUT;
+ }
+ static final VarHandle size$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("size"));
+ public static VarHandle size$VH() {
+ return usbdevfs_conninfo_ex.size$VH;
+ }
+ public static int size$get(MemorySegment seg) {
+ return (int)usbdevfs_conninfo_ex.size$VH.get(seg);
+ }
+ public static void size$set( MemorySegment seg, int x) {
+ usbdevfs_conninfo_ex.size$VH.set(seg, x);
+ }
+ public static int size$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_conninfo_ex.size$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void size$set(MemorySegment seg, long index, int x) {
+ usbdevfs_conninfo_ex.size$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle busnum$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("busnum"));
+ public static VarHandle busnum$VH() {
+ return usbdevfs_conninfo_ex.busnum$VH;
+ }
+ public static int busnum$get(MemorySegment seg) {
+ return (int)usbdevfs_conninfo_ex.busnum$VH.get(seg);
+ }
+ public static void busnum$set( MemorySegment seg, int x) {
+ usbdevfs_conninfo_ex.busnum$VH.set(seg, x);
+ }
+ public static int busnum$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_conninfo_ex.busnum$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void busnum$set(MemorySegment seg, long index, int x) {
+ usbdevfs_conninfo_ex.busnum$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle devnum$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("devnum"));
+ public static VarHandle devnum$VH() {
+ return usbdevfs_conninfo_ex.devnum$VH;
+ }
+ public static int devnum$get(MemorySegment seg) {
+ return (int)usbdevfs_conninfo_ex.devnum$VH.get(seg);
+ }
+ public static void devnum$set( MemorySegment seg, int x) {
+ usbdevfs_conninfo_ex.devnum$VH.set(seg, x);
+ }
+ public static int devnum$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_conninfo_ex.devnum$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void devnum$set(MemorySegment seg, long index, int x) {
+ usbdevfs_conninfo_ex.devnum$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle speed$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("speed"));
+ public static VarHandle speed$VH() {
+ return usbdevfs_conninfo_ex.speed$VH;
+ }
+ public static int speed$get(MemorySegment seg) {
+ return (int)usbdevfs_conninfo_ex.speed$VH.get(seg);
+ }
+ public static void speed$set( MemorySegment seg, int x) {
+ usbdevfs_conninfo_ex.speed$VH.set(seg, x);
+ }
+ public static int speed$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_conninfo_ex.speed$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void speed$set(MemorySegment seg, long index, int x) {
+ usbdevfs_conninfo_ex.speed$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle num_ports$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("num_ports"));
+ public static VarHandle num_ports$VH() {
+ return usbdevfs_conninfo_ex.num_ports$VH;
+ }
+ public static byte num_ports$get(MemorySegment seg) {
+ return (byte)usbdevfs_conninfo_ex.num_ports$VH.get(seg);
+ }
+ public static void num_ports$set( MemorySegment seg, byte x) {
+ usbdevfs_conninfo_ex.num_ports$VH.set(seg, x);
+ }
+ public static byte num_ports$get(MemorySegment seg, long index) {
+ return (byte)usbdevfs_conninfo_ex.num_ports$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void num_ports$set(MemorySegment seg, long index, byte x) {
+ usbdevfs_conninfo_ex.num_ports$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static MemorySegment ports$slice(MemorySegment seg) {
+ return seg.asSlice(17, 7);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_ctrltransfer.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_ctrltransfer.java
new file mode 100644
index 00000000..2dd9c901
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_ctrltransfer.java
@@ -0,0 +1,142 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.usbdevice_fs;
+
+import java.lang.foreign.*;
+import java.lang.invoke.VarHandle;
+public class usbdevfs_ctrltransfer {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ Constants$root.C_CHAR$LAYOUT.withName("bRequestType"),
+ Constants$root.C_CHAR$LAYOUT.withName("bRequest"),
+ Constants$root.C_SHORT$LAYOUT.withName("wValue"),
+ Constants$root.C_SHORT$LAYOUT.withName("wIndex"),
+ Constants$root.C_SHORT$LAYOUT.withName("wLength"),
+ Constants$root.C_INT$LAYOUT.withName("timeout"),
+ MemoryLayout.paddingLayout(32),
+ Constants$root.C_POINTER$LAYOUT.withName("data")
+ ).withName("usbdevfs_ctrltransfer");
+ public static MemoryLayout $LAYOUT() {
+ return usbdevfs_ctrltransfer.$struct$LAYOUT;
+ }
+ static final VarHandle bRequestType$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("bRequestType"));
+ public static VarHandle bRequestType$VH() {
+ return usbdevfs_ctrltransfer.bRequestType$VH;
+ }
+ public static byte bRequestType$get(MemorySegment seg) {
+ return (byte)usbdevfs_ctrltransfer.bRequestType$VH.get(seg);
+ }
+ public static void bRequestType$set( MemorySegment seg, byte x) {
+ usbdevfs_ctrltransfer.bRequestType$VH.set(seg, x);
+ }
+ public static byte bRequestType$get(MemorySegment seg, long index) {
+ return (byte)usbdevfs_ctrltransfer.bRequestType$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void bRequestType$set(MemorySegment seg, long index, byte x) {
+ usbdevfs_ctrltransfer.bRequestType$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle bRequest$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("bRequest"));
+ public static VarHandle bRequest$VH() {
+ return usbdevfs_ctrltransfer.bRequest$VH;
+ }
+ public static byte bRequest$get(MemorySegment seg) {
+ return (byte)usbdevfs_ctrltransfer.bRequest$VH.get(seg);
+ }
+ public static void bRequest$set( MemorySegment seg, byte x) {
+ usbdevfs_ctrltransfer.bRequest$VH.set(seg, x);
+ }
+ public static byte bRequest$get(MemorySegment seg, long index) {
+ return (byte)usbdevfs_ctrltransfer.bRequest$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void bRequest$set(MemorySegment seg, long index, byte x) {
+ usbdevfs_ctrltransfer.bRequest$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle wValue$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("wValue"));
+ public static VarHandle wValue$VH() {
+ return usbdevfs_ctrltransfer.wValue$VH;
+ }
+ public static short wValue$get(MemorySegment seg) {
+ return (short)usbdevfs_ctrltransfer.wValue$VH.get(seg);
+ }
+ public static void wValue$set( MemorySegment seg, short x) {
+ usbdevfs_ctrltransfer.wValue$VH.set(seg, x);
+ }
+ public static short wValue$get(MemorySegment seg, long index) {
+ return (short)usbdevfs_ctrltransfer.wValue$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void wValue$set(MemorySegment seg, long index, short x) {
+ usbdevfs_ctrltransfer.wValue$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle wIndex$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("wIndex"));
+ public static VarHandle wIndex$VH() {
+ return usbdevfs_ctrltransfer.wIndex$VH;
+ }
+ public static short wIndex$get(MemorySegment seg) {
+ return (short)usbdevfs_ctrltransfer.wIndex$VH.get(seg);
+ }
+ public static void wIndex$set( MemorySegment seg, short x) {
+ usbdevfs_ctrltransfer.wIndex$VH.set(seg, x);
+ }
+ public static short wIndex$get(MemorySegment seg, long index) {
+ return (short)usbdevfs_ctrltransfer.wIndex$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void wIndex$set(MemorySegment seg, long index, short x) {
+ usbdevfs_ctrltransfer.wIndex$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle wLength$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("wLength"));
+ public static VarHandle wLength$VH() {
+ return usbdevfs_ctrltransfer.wLength$VH;
+ }
+ public static short wLength$get(MemorySegment seg) {
+ return (short)usbdevfs_ctrltransfer.wLength$VH.get(seg);
+ }
+ public static void wLength$set( MemorySegment seg, short x) {
+ usbdevfs_ctrltransfer.wLength$VH.set(seg, x);
+ }
+ public static short wLength$get(MemorySegment seg, long index) {
+ return (short)usbdevfs_ctrltransfer.wLength$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void wLength$set(MemorySegment seg, long index, short x) {
+ usbdevfs_ctrltransfer.wLength$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle timeout$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("timeout"));
+ public static VarHandle timeout$VH() {
+ return usbdevfs_ctrltransfer.timeout$VH;
+ }
+ public static int timeout$get(MemorySegment seg) {
+ return (int)usbdevfs_ctrltransfer.timeout$VH.get(seg);
+ }
+ public static void timeout$set( MemorySegment seg, int x) {
+ usbdevfs_ctrltransfer.timeout$VH.set(seg, x);
+ }
+ public static int timeout$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_ctrltransfer.timeout$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void timeout$set(MemorySegment seg, long index, int x) {
+ usbdevfs_ctrltransfer.timeout$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle data$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("data"));
+ public static VarHandle data$VH() {
+ return usbdevfs_ctrltransfer.data$VH;
+ }
+ public static MemoryAddress data$get(MemorySegment seg) {
+ return (java.lang.foreign.MemoryAddress)usbdevfs_ctrltransfer.data$VH.get(seg);
+ }
+ public static void data$set( MemorySegment seg, MemoryAddress x) {
+ usbdevfs_ctrltransfer.data$VH.set(seg, x);
+ }
+ public static MemoryAddress data$get(MemorySegment seg, long index) {
+ return (java.lang.foreign.MemoryAddress)usbdevfs_ctrltransfer.data$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void data$set(MemorySegment seg, long index, MemoryAddress x) {
+ usbdevfs_ctrltransfer.data$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_disconnect_claim.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_disconnect_claim.java
new file mode 100644
index 00000000..023757d7
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_disconnect_claim.java
@@ -0,0 +1,60 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.usbdevice_fs;
+
+import java.lang.foreign.*;
+import java.lang.invoke.VarHandle;
+public class usbdevfs_disconnect_claim {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ Constants$root.C_INT$LAYOUT.withName("interface"),
+ Constants$root.C_INT$LAYOUT.withName("flags"),
+ MemoryLayout.sequenceLayout(256, Constants$root.C_CHAR$LAYOUT).withName("driver")
+ ).withName("usbdevfs_disconnect_claim");
+ public static MemoryLayout $LAYOUT() {
+ return usbdevfs_disconnect_claim.$struct$LAYOUT;
+ }
+ static final VarHandle interface_$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("interface"));
+ public static VarHandle interface_$VH() {
+ return usbdevfs_disconnect_claim.interface_$VH;
+ }
+ public static int interface_$get(MemorySegment seg) {
+ return (int)usbdevfs_disconnect_claim.interface_$VH.get(seg);
+ }
+ public static void interface_$set( MemorySegment seg, int x) {
+ usbdevfs_disconnect_claim.interface_$VH.set(seg, x);
+ }
+ public static int interface_$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_disconnect_claim.interface_$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void interface_$set(MemorySegment seg, long index, int x) {
+ usbdevfs_disconnect_claim.interface_$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle flags$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("flags"));
+ public static VarHandle flags$VH() {
+ return usbdevfs_disconnect_claim.flags$VH;
+ }
+ public static int flags$get(MemorySegment seg) {
+ return (int)usbdevfs_disconnect_claim.flags$VH.get(seg);
+ }
+ public static void flags$set( MemorySegment seg, int x) {
+ usbdevfs_disconnect_claim.flags$VH.set(seg, x);
+ }
+ public static int flags$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_disconnect_claim.flags$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void flags$set(MemorySegment seg, long index, int x) {
+ usbdevfs_disconnect_claim.flags$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static MemorySegment driver$slice(MemorySegment seg) {
+ return seg.asSlice(8, 256);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_disconnectsignal.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_disconnectsignal.java
new file mode 100644
index 00000000..97bf5c5e
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_disconnectsignal.java
@@ -0,0 +1,57 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.usbdevice_fs;
+
+import java.lang.foreign.*;
+import java.lang.invoke.VarHandle;
+public class usbdevfs_disconnectsignal {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ Constants$root.C_INT$LAYOUT.withName("signr"),
+ MemoryLayout.paddingLayout(32),
+ Constants$root.C_POINTER$LAYOUT.withName("context")
+ ).withName("usbdevfs_disconnectsignal");
+ public static MemoryLayout $LAYOUT() {
+ return usbdevfs_disconnectsignal.$struct$LAYOUT;
+ }
+ static final VarHandle signr$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("signr"));
+ public static VarHandle signr$VH() {
+ return usbdevfs_disconnectsignal.signr$VH;
+ }
+ public static int signr$get(MemorySegment seg) {
+ return (int)usbdevfs_disconnectsignal.signr$VH.get(seg);
+ }
+ public static void signr$set( MemorySegment seg, int x) {
+ usbdevfs_disconnectsignal.signr$VH.set(seg, x);
+ }
+ public static int signr$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_disconnectsignal.signr$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void signr$set(MemorySegment seg, long index, int x) {
+ usbdevfs_disconnectsignal.signr$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle context$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("context"));
+ public static VarHandle context$VH() {
+ return usbdevfs_disconnectsignal.context$VH;
+ }
+ public static MemoryAddress context$get(MemorySegment seg) {
+ return (java.lang.foreign.MemoryAddress)usbdevfs_disconnectsignal.context$VH.get(seg);
+ }
+ public static void context$set( MemorySegment seg, MemoryAddress x) {
+ usbdevfs_disconnectsignal.context$VH.set(seg, x);
+ }
+ public static MemoryAddress context$get(MemorySegment seg, long index) {
+ return (java.lang.foreign.MemoryAddress)usbdevfs_disconnectsignal.context$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void context$set(MemorySegment seg, long index, MemoryAddress x) {
+ usbdevfs_disconnectsignal.context$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_getdriver.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_getdriver.java
new file mode 100644
index 00000000..50208d87
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_getdriver.java
@@ -0,0 +1,43 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.usbdevice_fs;
+
+import java.lang.foreign.*;
+import java.lang.invoke.VarHandle;
+public class usbdevfs_getdriver {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ Constants$root.C_INT$LAYOUT.withName("interface"),
+ MemoryLayout.sequenceLayout(256, Constants$root.C_CHAR$LAYOUT).withName("driver")
+ ).withName("usbdevfs_getdriver");
+ public static MemoryLayout $LAYOUT() {
+ return usbdevfs_getdriver.$struct$LAYOUT;
+ }
+ static final VarHandle interface_$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("interface"));
+ public static VarHandle interface_$VH() {
+ return usbdevfs_getdriver.interface_$VH;
+ }
+ public static int interface_$get(MemorySegment seg) {
+ return (int)usbdevfs_getdriver.interface_$VH.get(seg);
+ }
+ public static void interface_$set( MemorySegment seg, int x) {
+ usbdevfs_getdriver.interface_$VH.set(seg, x);
+ }
+ public static int interface_$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_getdriver.interface_$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void interface_$set(MemorySegment seg, long index, int x) {
+ usbdevfs_getdriver.interface_$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static MemorySegment driver$slice(MemorySegment seg) {
+ return seg.asSlice(4, 256);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_hub_portinfo.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_hub_portinfo.java
new file mode 100644
index 00000000..e7c195cd
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_hub_portinfo.java
@@ -0,0 +1,43 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.usbdevice_fs;
+
+import java.lang.foreign.*;
+import java.lang.invoke.VarHandle;
+public class usbdevfs_hub_portinfo {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ Constants$root.C_CHAR$LAYOUT.withName("nports"),
+ MemoryLayout.sequenceLayout(127, Constants$root.C_CHAR$LAYOUT).withName("port")
+ ).withName("usbdevfs_hub_portinfo");
+ public static MemoryLayout $LAYOUT() {
+ return usbdevfs_hub_portinfo.$struct$LAYOUT;
+ }
+ static final VarHandle nports$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("nports"));
+ public static VarHandle nports$VH() {
+ return usbdevfs_hub_portinfo.nports$VH;
+ }
+ public static byte nports$get(MemorySegment seg) {
+ return (byte)usbdevfs_hub_portinfo.nports$VH.get(seg);
+ }
+ public static void nports$set( MemorySegment seg, byte x) {
+ usbdevfs_hub_portinfo.nports$VH.set(seg, x);
+ }
+ public static byte nports$get(MemorySegment seg, long index) {
+ return (byte)usbdevfs_hub_portinfo.nports$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void nports$set(MemorySegment seg, long index, byte x) {
+ usbdevfs_hub_portinfo.nports$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static MemorySegment port$slice(MemorySegment seg) {
+ return seg.asSlice(1, 127);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_ioctl.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_ioctl.java
new file mode 100644
index 00000000..35caf795
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_ioctl.java
@@ -0,0 +1,73 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.usbdevice_fs;
+
+import java.lang.foreign.*;
+import java.lang.invoke.VarHandle;
+public class usbdevfs_ioctl {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ Constants$root.C_INT$LAYOUT.withName("ifno"),
+ Constants$root.C_INT$LAYOUT.withName("ioctl_code"),
+ Constants$root.C_POINTER$LAYOUT.withName("data")
+ ).withName("usbdevfs_ioctl");
+ public static MemoryLayout $LAYOUT() {
+ return usbdevfs_ioctl.$struct$LAYOUT;
+ }
+ static final VarHandle ifno$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("ifno"));
+ public static VarHandle ifno$VH() {
+ return usbdevfs_ioctl.ifno$VH;
+ }
+ public static int ifno$get(MemorySegment seg) {
+ return (int)usbdevfs_ioctl.ifno$VH.get(seg);
+ }
+ public static void ifno$set( MemorySegment seg, int x) {
+ usbdevfs_ioctl.ifno$VH.set(seg, x);
+ }
+ public static int ifno$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_ioctl.ifno$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void ifno$set(MemorySegment seg, long index, int x) {
+ usbdevfs_ioctl.ifno$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle ioctl_code$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("ioctl_code"));
+ public static VarHandle ioctl_code$VH() {
+ return usbdevfs_ioctl.ioctl_code$VH;
+ }
+ public static int ioctl_code$get(MemorySegment seg) {
+ return (int)usbdevfs_ioctl.ioctl_code$VH.get(seg);
+ }
+ public static void ioctl_code$set( MemorySegment seg, int x) {
+ usbdevfs_ioctl.ioctl_code$VH.set(seg, x);
+ }
+ public static int ioctl_code$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_ioctl.ioctl_code$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void ioctl_code$set(MemorySegment seg, long index, int x) {
+ usbdevfs_ioctl.ioctl_code$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle data$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("data"));
+ public static VarHandle data$VH() {
+ return usbdevfs_ioctl.data$VH;
+ }
+ public static MemoryAddress data$get(MemorySegment seg) {
+ return (java.lang.foreign.MemoryAddress)usbdevfs_ioctl.data$VH.get(seg);
+ }
+ public static void data$set( MemorySegment seg, MemoryAddress x) {
+ usbdevfs_ioctl.data$VH.set(seg, x);
+ }
+ public static MemoryAddress data$get(MemorySegment seg, long index) {
+ return (java.lang.foreign.MemoryAddress)usbdevfs_ioctl.data$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void data$set(MemorySegment seg, long index, MemoryAddress x) {
+ usbdevfs_ioctl.data$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_iso_packet_desc.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_iso_packet_desc.java
new file mode 100644
index 00000000..dcbb988b
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_iso_packet_desc.java
@@ -0,0 +1,73 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.usbdevice_fs;
+
+import java.lang.foreign.*;
+import java.lang.invoke.VarHandle;
+public class usbdevfs_iso_packet_desc {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ Constants$root.C_INT$LAYOUT.withName("length"),
+ Constants$root.C_INT$LAYOUT.withName("actual_length"),
+ Constants$root.C_INT$LAYOUT.withName("status")
+ ).withName("usbdevfs_iso_packet_desc");
+ public static MemoryLayout $LAYOUT() {
+ return usbdevfs_iso_packet_desc.$struct$LAYOUT;
+ }
+ static final VarHandle length$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("length"));
+ public static VarHandle length$VH() {
+ return usbdevfs_iso_packet_desc.length$VH;
+ }
+ public static int length$get(MemorySegment seg) {
+ return (int)usbdevfs_iso_packet_desc.length$VH.get(seg);
+ }
+ public static void length$set( MemorySegment seg, int x) {
+ usbdevfs_iso_packet_desc.length$VH.set(seg, x);
+ }
+ public static int length$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_iso_packet_desc.length$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void length$set(MemorySegment seg, long index, int x) {
+ usbdevfs_iso_packet_desc.length$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle actual_length$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("actual_length"));
+ public static VarHandle actual_length$VH() {
+ return usbdevfs_iso_packet_desc.actual_length$VH;
+ }
+ public static int actual_length$get(MemorySegment seg) {
+ return (int)usbdevfs_iso_packet_desc.actual_length$VH.get(seg);
+ }
+ public static void actual_length$set( MemorySegment seg, int x) {
+ usbdevfs_iso_packet_desc.actual_length$VH.set(seg, x);
+ }
+ public static int actual_length$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_iso_packet_desc.actual_length$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void actual_length$set(MemorySegment seg, long index, int x) {
+ usbdevfs_iso_packet_desc.actual_length$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle status$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("status"));
+ public static VarHandle status$VH() {
+ return usbdevfs_iso_packet_desc.status$VH;
+ }
+ public static int status$get(MemorySegment seg) {
+ return (int)usbdevfs_iso_packet_desc.status$VH.get(seg);
+ }
+ public static void status$set( MemorySegment seg, int x) {
+ usbdevfs_iso_packet_desc.status$VH.set(seg, x);
+ }
+ public static int status$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_iso_packet_desc.status$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void status$set(MemorySegment seg, long index, int x) {
+ usbdevfs_iso_packet_desc.status$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_setinterface.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_setinterface.java
new file mode 100644
index 00000000..0aec7f05
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_setinterface.java
@@ -0,0 +1,56 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.usbdevice_fs;
+
+import java.lang.foreign.*;
+import java.lang.invoke.VarHandle;
+public class usbdevfs_setinterface {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ Constants$root.C_INT$LAYOUT.withName("interface"),
+ Constants$root.C_INT$LAYOUT.withName("altsetting")
+ ).withName("usbdevfs_setinterface");
+ public static MemoryLayout $LAYOUT() {
+ return usbdevfs_setinterface.$struct$LAYOUT;
+ }
+ static final VarHandle interface_$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("interface"));
+ public static VarHandle interface_$VH() {
+ return usbdevfs_setinterface.interface_$VH;
+ }
+ public static int interface_$get(MemorySegment seg) {
+ return (int)usbdevfs_setinterface.interface_$VH.get(seg);
+ }
+ public static void interface_$set( MemorySegment seg, int x) {
+ usbdevfs_setinterface.interface_$VH.set(seg, x);
+ }
+ public static int interface_$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_setinterface.interface_$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void interface_$set(MemorySegment seg, long index, int x) {
+ usbdevfs_setinterface.interface_$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle altsetting$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("altsetting"));
+ public static VarHandle altsetting$VH() {
+ return usbdevfs_setinterface.altsetting$VH;
+ }
+ public static int altsetting$get(MemorySegment seg) {
+ return (int)usbdevfs_setinterface.altsetting$VH.get(seg);
+ }
+ public static void altsetting$set( MemorySegment seg, int x) {
+ usbdevfs_setinterface.altsetting$VH.set(seg, x);
+ }
+ public static int altsetting$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_setinterface.altsetting$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void altsetting$set(MemorySegment seg, long index, int x) {
+ usbdevfs_setinterface.altsetting$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_streams.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_streams.java
new file mode 100644
index 00000000..463692b3
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_streams.java
@@ -0,0 +1,57 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.usbdevice_fs;
+
+import java.lang.foreign.*;
+import java.lang.invoke.VarHandle;
+public class usbdevfs_streams {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ Constants$root.C_INT$LAYOUT.withName("num_streams"),
+ Constants$root.C_INT$LAYOUT.withName("num_eps"),
+ MemoryLayout.sequenceLayout(0, Constants$root.C_CHAR$LAYOUT).withName("eps")
+ ).withName("usbdevfs_streams");
+ public static MemoryLayout $LAYOUT() {
+ return usbdevfs_streams.$struct$LAYOUT;
+ }
+ static final VarHandle num_streams$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("num_streams"));
+ public static VarHandle num_streams$VH() {
+ return usbdevfs_streams.num_streams$VH;
+ }
+ public static int num_streams$get(MemorySegment seg) {
+ return (int)usbdevfs_streams.num_streams$VH.get(seg);
+ }
+ public static void num_streams$set( MemorySegment seg, int x) {
+ usbdevfs_streams.num_streams$VH.set(seg, x);
+ }
+ public static int num_streams$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_streams.num_streams$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void num_streams$set(MemorySegment seg, long index, int x) {
+ usbdevfs_streams.num_streams$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle num_eps$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("num_eps"));
+ public static VarHandle num_eps$VH() {
+ return usbdevfs_streams.num_eps$VH;
+ }
+ public static int num_eps$get(MemorySegment seg) {
+ return (int)usbdevfs_streams.num_eps$VH.get(seg);
+ }
+ public static void num_eps$set( MemorySegment seg, int x) {
+ usbdevfs_streams.num_eps$VH.set(seg, x);
+ }
+ public static int num_eps$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_streams.num_eps$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void num_eps$set(MemorySegment seg, long index, int x) {
+ usbdevfs_streams.num_eps$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_urb.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_urb.java
new file mode 100644
index 00000000..5ffb8ae3
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_urb.java
@@ -0,0 +1,252 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.usbdevice_fs;
+
+import java.lang.foreign.*;
+import java.lang.invoke.VarHandle;
+public class usbdevfs_urb {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ Constants$root.C_CHAR$LAYOUT.withName("type"),
+ Constants$root.C_CHAR$LAYOUT.withName("endpoint"),
+ MemoryLayout.paddingLayout(16),
+ Constants$root.C_INT$LAYOUT.withName("status"),
+ Constants$root.C_INT$LAYOUT.withName("flags"),
+ MemoryLayout.paddingLayout(32),
+ Constants$root.C_POINTER$LAYOUT.withName("buffer"),
+ Constants$root.C_INT$LAYOUT.withName("buffer_length"),
+ Constants$root.C_INT$LAYOUT.withName("actual_length"),
+ Constants$root.C_INT$LAYOUT.withName("start_frame"),
+ MemoryLayout.unionLayout(
+ Constants$root.C_INT$LAYOUT.withName("number_of_packets"),
+ Constants$root.C_INT$LAYOUT.withName("stream_id")
+ ).withName("$anon$0"),
+ Constants$root.C_INT$LAYOUT.withName("error_count"),
+ Constants$root.C_INT$LAYOUT.withName("signr"),
+ Constants$root.C_POINTER$LAYOUT.withName("usercontext"),
+ MemoryLayout.sequenceLayout(0, MemoryLayout.structLayout(
+ Constants$root.C_INT$LAYOUT.withName("length"),
+ Constants$root.C_INT$LAYOUT.withName("actual_length"),
+ Constants$root.C_INT$LAYOUT.withName("status")
+ ).withName("usbdevfs_iso_packet_desc")).withName("iso_frame_desc")
+ ).withName("usbdevfs_urb");
+ public static MemoryLayout $LAYOUT() {
+ return usbdevfs_urb.$struct$LAYOUT;
+ }
+ static final VarHandle type$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("type"));
+ public static VarHandle type$VH() {
+ return usbdevfs_urb.type$VH;
+ }
+ public static byte type$get(MemorySegment seg) {
+ return (byte)usbdevfs_urb.type$VH.get(seg);
+ }
+ public static void type$set( MemorySegment seg, byte x) {
+ usbdevfs_urb.type$VH.set(seg, x);
+ }
+ public static byte type$get(MemorySegment seg, long index) {
+ return (byte)usbdevfs_urb.type$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void type$set(MemorySegment seg, long index, byte x) {
+ usbdevfs_urb.type$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle endpoint$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("endpoint"));
+ public static VarHandle endpoint$VH() {
+ return usbdevfs_urb.endpoint$VH;
+ }
+ public static byte endpoint$get(MemorySegment seg) {
+ return (byte)usbdevfs_urb.endpoint$VH.get(seg);
+ }
+ public static void endpoint$set( MemorySegment seg, byte x) {
+ usbdevfs_urb.endpoint$VH.set(seg, x);
+ }
+ public static byte endpoint$get(MemorySegment seg, long index) {
+ return (byte)usbdevfs_urb.endpoint$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void endpoint$set(MemorySegment seg, long index, byte x) {
+ usbdevfs_urb.endpoint$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle status$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("status"));
+ public static VarHandle status$VH() {
+ return usbdevfs_urb.status$VH;
+ }
+ public static int status$get(MemorySegment seg) {
+ return (int)usbdevfs_urb.status$VH.get(seg);
+ }
+ public static void status$set( MemorySegment seg, int x) {
+ usbdevfs_urb.status$VH.set(seg, x);
+ }
+ public static int status$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_urb.status$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void status$set(MemorySegment seg, long index, int x) {
+ usbdevfs_urb.status$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle flags$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("flags"));
+ public static VarHandle flags$VH() {
+ return usbdevfs_urb.flags$VH;
+ }
+ public static int flags$get(MemorySegment seg) {
+ return (int)usbdevfs_urb.flags$VH.get(seg);
+ }
+ public static void flags$set( MemorySegment seg, int x) {
+ usbdevfs_urb.flags$VH.set(seg, x);
+ }
+ public static int flags$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_urb.flags$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void flags$set(MemorySegment seg, long index, int x) {
+ usbdevfs_urb.flags$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle buffer$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("buffer"));
+ public static VarHandle buffer$VH() {
+ return usbdevfs_urb.buffer$VH;
+ }
+ public static MemoryAddress buffer$get(MemorySegment seg) {
+ return (java.lang.foreign.MemoryAddress)usbdevfs_urb.buffer$VH.get(seg);
+ }
+ public static void buffer$set( MemorySegment seg, MemoryAddress x) {
+ usbdevfs_urb.buffer$VH.set(seg, x);
+ }
+ public static MemoryAddress buffer$get(MemorySegment seg, long index) {
+ return (java.lang.foreign.MemoryAddress)usbdevfs_urb.buffer$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void buffer$set(MemorySegment seg, long index, MemoryAddress x) {
+ usbdevfs_urb.buffer$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle buffer_length$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("buffer_length"));
+ public static VarHandle buffer_length$VH() {
+ return usbdevfs_urb.buffer_length$VH;
+ }
+ public static int buffer_length$get(MemorySegment seg) {
+ return (int)usbdevfs_urb.buffer_length$VH.get(seg);
+ }
+ public static void buffer_length$set( MemorySegment seg, int x) {
+ usbdevfs_urb.buffer_length$VH.set(seg, x);
+ }
+ public static int buffer_length$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_urb.buffer_length$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void buffer_length$set(MemorySegment seg, long index, int x) {
+ usbdevfs_urb.buffer_length$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle actual_length$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("actual_length"));
+ public static VarHandle actual_length$VH() {
+ return usbdevfs_urb.actual_length$VH;
+ }
+ public static int actual_length$get(MemorySegment seg) {
+ return (int)usbdevfs_urb.actual_length$VH.get(seg);
+ }
+ public static void actual_length$set( MemorySegment seg, int x) {
+ usbdevfs_urb.actual_length$VH.set(seg, x);
+ }
+ public static int actual_length$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_urb.actual_length$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void actual_length$set(MemorySegment seg, long index, int x) {
+ usbdevfs_urb.actual_length$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle start_frame$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("start_frame"));
+ public static VarHandle start_frame$VH() {
+ return usbdevfs_urb.start_frame$VH;
+ }
+ public static int start_frame$get(MemorySegment seg) {
+ return (int)usbdevfs_urb.start_frame$VH.get(seg);
+ }
+ public static void start_frame$set( MemorySegment seg, int x) {
+ usbdevfs_urb.start_frame$VH.set(seg, x);
+ }
+ public static int start_frame$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_urb.start_frame$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void start_frame$set(MemorySegment seg, long index, int x) {
+ usbdevfs_urb.start_frame$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle number_of_packets$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("$anon$0"), MemoryLayout.PathElement.groupElement("number_of_packets"));
+ public static VarHandle number_of_packets$VH() {
+ return usbdevfs_urb.number_of_packets$VH;
+ }
+ public static int number_of_packets$get(MemorySegment seg) {
+ return (int)usbdevfs_urb.number_of_packets$VH.get(seg);
+ }
+ public static void number_of_packets$set( MemorySegment seg, int x) {
+ usbdevfs_urb.number_of_packets$VH.set(seg, x);
+ }
+ public static int number_of_packets$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_urb.number_of_packets$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void number_of_packets$set(MemorySegment seg, long index, int x) {
+ usbdevfs_urb.number_of_packets$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle stream_id$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("$anon$0"), MemoryLayout.PathElement.groupElement("stream_id"));
+ public static VarHandle stream_id$VH() {
+ return usbdevfs_urb.stream_id$VH;
+ }
+ public static int stream_id$get(MemorySegment seg) {
+ return (int)usbdevfs_urb.stream_id$VH.get(seg);
+ }
+ public static void stream_id$set( MemorySegment seg, int x) {
+ usbdevfs_urb.stream_id$VH.set(seg, x);
+ }
+ public static int stream_id$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_urb.stream_id$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void stream_id$set(MemorySegment seg, long index, int x) {
+ usbdevfs_urb.stream_id$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle error_count$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("error_count"));
+ public static VarHandle error_count$VH() {
+ return usbdevfs_urb.error_count$VH;
+ }
+ public static int error_count$get(MemorySegment seg) {
+ return (int)usbdevfs_urb.error_count$VH.get(seg);
+ }
+ public static void error_count$set( MemorySegment seg, int x) {
+ usbdevfs_urb.error_count$VH.set(seg, x);
+ }
+ public static int error_count$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_urb.error_count$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void error_count$set(MemorySegment seg, long index, int x) {
+ usbdevfs_urb.error_count$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle signr$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("signr"));
+ public static VarHandle signr$VH() {
+ return usbdevfs_urb.signr$VH;
+ }
+ public static int signr$get(MemorySegment seg) {
+ return (int)usbdevfs_urb.signr$VH.get(seg);
+ }
+ public static void signr$set( MemorySegment seg, int x) {
+ usbdevfs_urb.signr$VH.set(seg, x);
+ }
+ public static int signr$get(MemorySegment seg, long index) {
+ return (int)usbdevfs_urb.signr$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void signr$set(MemorySegment seg, long index, int x) {
+ usbdevfs_urb.signr$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle usercontext$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("usercontext"));
+ public static VarHandle usercontext$VH() {
+ return usbdevfs_urb.usercontext$VH;
+ }
+ public static MemoryAddress usercontext$get(MemorySegment seg) {
+ return (java.lang.foreign.MemoryAddress)usbdevfs_urb.usercontext$VH.get(seg);
+ }
+ public static void usercontext$set( MemorySegment seg, MemoryAddress x) {
+ usbdevfs_urb.usercontext$VH.set(seg, x);
+ }
+ public static MemoryAddress usercontext$get(MemorySegment seg, long index) {
+ return (java.lang.foreign.MemoryAddress)usbdevfs_urb.usercontext$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void usercontext$set(MemorySegment seg, long index, MemoryAddress x) {
+ usbdevfs_urb.usercontext$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevice_fs.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevice_fs.java
new file mode 100644
index 00000000..034c4d1b
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevice_fs.java
@@ -0,0 +1,366 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.usbdevice_fs;
+
+import java.lang.foreign.MemorySegment;
+
+import static java.lang.foreign.ValueLayout.*;
+public class usbdevice_fs {
+
+ /* package-private */ usbdevice_fs() {}
+ public static OfByte C_CHAR = Constants$root.C_CHAR$LAYOUT;
+ public static OfShort C_SHORT = Constants$root.C_SHORT$LAYOUT;
+ public static OfInt C_INT = Constants$root.C_INT$LAYOUT;
+ public static OfLong C_LONG = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong C_LONG_LONG = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfFloat C_FLOAT = Constants$root.C_FLOAT$LAYOUT;
+ public static OfDouble C_DOUBLE = Constants$root.C_DOUBLE$LAYOUT;
+ public static OfAddress C_POINTER = Constants$root.C_POINTER$LAYOUT;
+ public static int __BITS_PER_LONG() {
+ return (int)64L;
+ }
+ public static int __FD_SETSIZE() {
+ return (int)1024L;
+ }
+ public static int ADFS_SUPER_MAGIC() {
+ return (int)44533L;
+ }
+ public static int AFFS_SUPER_MAGIC() {
+ return (int)44543L;
+ }
+ public static int AFS_SUPER_MAGIC() {
+ return (int)1397113167L;
+ }
+ public static int AUTOFS_SUPER_MAGIC() {
+ return (int)391L;
+ }
+ public static int CODA_SUPER_MAGIC() {
+ return (int)1937076805L;
+ }
+ public static int CRAMFS_MAGIC() {
+ return (int)684539205L;
+ }
+ public static int CRAMFS_MAGIC_WEND() {
+ return (int)1161678120L;
+ }
+ public static int DEBUGFS_MAGIC() {
+ return (int)1684170528L;
+ }
+ public static int SECURITYFS_MAGIC() {
+ return (int)1935894131L;
+ }
+ public static int SMACK_MAGIC() {
+ return (int)1128357203L;
+ }
+ public static int TMPFS_MAGIC() {
+ return (int)16914836L;
+ }
+ public static int SQUASHFS_MAGIC() {
+ return (int)1936814952L;
+ }
+ public static int ECRYPTFS_SUPER_MAGIC() {
+ return (int)61791L;
+ }
+ public static int EFS_SUPER_MAGIC() {
+ return (int)4278867L;
+ }
+ public static int EXT2_SUPER_MAGIC() {
+ return (int)61267L;
+ }
+ public static int EXT3_SUPER_MAGIC() {
+ return (int)61267L;
+ }
+ public static int EXT4_SUPER_MAGIC() {
+ return (int)61267L;
+ }
+ public static int NILFS_SUPER_MAGIC() {
+ return (int)13364L;
+ }
+ public static int ISOFS_SUPER_MAGIC() {
+ return (int)38496L;
+ }
+ public static int JFFS2_SUPER_MAGIC() {
+ return (int)29366L;
+ }
+ public static int XFS_SUPER_MAGIC() {
+ return (int)1481003842L;
+ }
+ public static int PSTOREFS_MAGIC() {
+ return (int)1634035564L;
+ }
+ public static int HOSTFS_SUPER_MAGIC() {
+ return (int)12648430L;
+ }
+ public static int OVERLAYFS_SUPER_MAGIC() {
+ return (int)2035054128L;
+ }
+ public static int MINIX_SUPER_MAGIC() {
+ return (int)4991L;
+ }
+ public static int MINIX_SUPER_MAGIC2() {
+ return (int)5007L;
+ }
+ public static int MINIX2_SUPER_MAGIC() {
+ return (int)9320L;
+ }
+ public static int MINIX2_SUPER_MAGIC2() {
+ return (int)9336L;
+ }
+ public static int MINIX3_SUPER_MAGIC() {
+ return (int)19802L;
+ }
+ public static int MSDOS_SUPER_MAGIC() {
+ return (int)19780L;
+ }
+ public static int NCP_SUPER_MAGIC() {
+ return (int)22092L;
+ }
+ public static int NFS_SUPER_MAGIC() {
+ return (int)26985L;
+ }
+ public static int OCFS2_SUPER_MAGIC() {
+ return (int)1952539503L;
+ }
+ public static int OPENPROM_SUPER_MAGIC() {
+ return (int)40865L;
+ }
+ public static int QNX4_SUPER_MAGIC() {
+ return (int)47L;
+ }
+ public static int QNX6_SUPER_MAGIC() {
+ return (int)1746473250L;
+ }
+ public static int AFS_FS_MAGIC() {
+ return (int)1799439955L;
+ }
+ public static int REISERFS_SUPER_MAGIC() {
+ return (int)1382369651L;
+ }
+ public static int SMB_SUPER_MAGIC() {
+ return (int)20859L;
+ }
+ public static int CGROUP_SUPER_MAGIC() {
+ return (int)2613483L;
+ }
+ public static int CGROUP2_SUPER_MAGIC() {
+ return (int)1667723888L;
+ }
+ public static int RDTGROUP_SUPER_MAGIC() {
+ return (int)124082209L;
+ }
+ public static int STACK_END_MAGIC() {
+ return (int)1470918301L;
+ }
+ public static int TRACEFS_MAGIC() {
+ return (int)1953653091L;
+ }
+ public static int V9FS_MAGIC() {
+ return (int)16914839L;
+ }
+ public static int BDEVFS_MAGIC() {
+ return (int)1650746742L;
+ }
+ public static int DAXFS_MAGIC() {
+ return (int)1684300152L;
+ }
+ public static int BINFMTFS_MAGIC() {
+ return (int)1112100429L;
+ }
+ public static int DEVPTS_SUPER_MAGIC() {
+ return (int)7377L;
+ }
+ public static int BINDERFS_SUPER_MAGIC() {
+ return (int)1819242352L;
+ }
+ public static int FUTEXFS_SUPER_MAGIC() {
+ return (int)195894762L;
+ }
+ public static int PIPEFS_MAGIC() {
+ return (int)1346981957L;
+ }
+ public static int PROC_SUPER_MAGIC() {
+ return (int)40864L;
+ }
+ public static int SOCKFS_MAGIC() {
+ return (int)1397703499L;
+ }
+ public static int SYSFS_MAGIC() {
+ return (int)1650812274L;
+ }
+ public static int USBDEVICE_SUPER_MAGIC() {
+ return (int)40866L;
+ }
+ public static int MTD_INODE_FS_MAGIC() {
+ return (int)288389204L;
+ }
+ public static int ANON_INODE_FS_MAGIC() {
+ return (int)151263540L;
+ }
+ public static int BTRFS_TEST_MAGIC() {
+ return (int)1936880249L;
+ }
+ public static int NSFS_MAGIC() {
+ return (int)1853056627L;
+ }
+ public static int AAFS_MAGIC() {
+ return (int)1513908720L;
+ }
+ public static int ZONEFS_MAGIC() {
+ return (int)1515144787L;
+ }
+ public static int UDF_SUPER_MAGIC() {
+ return (int)352400198L;
+ }
+ public static int BALLOON_KVM_MAGIC() {
+ return (int)325456742L;
+ }
+ public static int ZSMALLOC_MAGIC() {
+ return (int)1479104553L;
+ }
+ public static int DMA_BUF_MAGIC() {
+ return (int)1145913666L;
+ }
+ public static int DEVMEM_MAGIC() {
+ return (int)1162691661L;
+ }
+ public static int Z3FOLD_MAGIC() {
+ return (int)51L;
+ }
+ public static int SECRETMEM_MAGIC() {
+ return (int)1397048141L;
+ }
+ public static int SHIFTFS_MAGIC() {
+ return (int)1785031266L;
+ }
+ public static int USBDEVFS_MAXDRIVERNAME() {
+ return (int)255L;
+ }
+ public static int USBDEVFS_URB_SHORT_NOT_OK() {
+ return (int)1L;
+ }
+ public static int USBDEVFS_URB_ISO_ASAP() {
+ return (int)2L;
+ }
+ public static int USBDEVFS_URB_BULK_CONTINUATION() {
+ return (int)4L;
+ }
+ public static int USBDEVFS_URB_NO_FSBR() {
+ return (int)32L;
+ }
+ public static int USBDEVFS_URB_ZERO_PACKET() {
+ return (int)64L;
+ }
+ public static int USBDEVFS_URB_NO_INTERRUPT() {
+ return (int)128L;
+ }
+ public static int USBDEVFS_URB_TYPE_ISO() {
+ return (int)0L;
+ }
+ public static int USBDEVFS_URB_TYPE_INTERRUPT() {
+ return (int)1L;
+ }
+ public static int USBDEVFS_URB_TYPE_CONTROL() {
+ return (int)2L;
+ }
+ public static int USBDEVFS_URB_TYPE_BULK() {
+ return (int)3L;
+ }
+ public static int USBDEVFS_CAP_ZERO_PACKET() {
+ return (int)1L;
+ }
+ public static int USBDEVFS_CAP_BULK_CONTINUATION() {
+ return (int)2L;
+ }
+ public static int USBDEVFS_CAP_NO_PACKET_SIZE_LIM() {
+ return (int)4L;
+ }
+ public static int USBDEVFS_CAP_BULK_SCATTER_GATHER() {
+ return (int)8L;
+ }
+ public static int USBDEVFS_CAP_REAP_AFTER_DISCONNECT() {
+ return (int)16L;
+ }
+ public static int USBDEVFS_CAP_MMAP() {
+ return (int)32L;
+ }
+ public static int USBDEVFS_CAP_DROP_PRIVILEGES() {
+ return (int)64L;
+ }
+ public static int USBDEVFS_CAP_CONNINFO_EX() {
+ return (int)128L;
+ }
+ public static int USBDEVFS_CAP_SUSPEND() {
+ return (int)256L;
+ }
+ public static int USBDEVFS_DISCONNECT_CLAIM_IF_DRIVER() {
+ return (int)1L;
+ }
+ public static int USBDEVFS_DISCONNECT_CLAIM_EXCEPT_DRIVER() {
+ return (int)2L;
+ }
+ public static OfShort __s16 = Constants$root.C_SHORT$LAYOUT;
+ public static OfInt __s32 = Constants$root.C_INT$LAYOUT;
+ public static OfLong __s64 = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfInt __kernel_key_t = Constants$root.C_INT$LAYOUT;
+ public static OfInt __kernel_mqd_t = Constants$root.C_INT$LAYOUT;
+ public static OfLong __kernel_long_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfInt __kernel_pid_t = Constants$root.C_INT$LAYOUT;
+ public static OfInt __kernel_ipc_pid_t = Constants$root.C_INT$LAYOUT;
+ public static OfLong __kernel_suseconds_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfInt __kernel_daddr_t = Constants$root.C_INT$LAYOUT;
+ public static OfLong __kernel_ssize_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __kernel_ptrdiff_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __kernel_off_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __kernel_loff_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __kernel_old_time_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __kernel_time_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __kernel_time64_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong __kernel_clock_t = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfInt __kernel_timer_t = Constants$root.C_INT$LAYOUT;
+ public static OfInt __kernel_clockid_t = Constants$root.C_INT$LAYOUT;
+ public static OfAddress __kernel_caddr_t = Constants$root.C_POINTER$LAYOUT;
+ public static int SELINUX_MAGIC() {
+ return (int)4185718668L;
+ }
+ public static int RAMFS_MAGIC() {
+ return (int)2240043254L;
+ }
+ public static int HUGETLBFS_MAGIC() {
+ return (int)2508478710L;
+ }
+ public static int EROFS_SUPER_MAGIC_V1() {
+ return (int)3774210530L;
+ }
+ public static int XENFS_SUPER_MAGIC() {
+ return (int)2881100148L;
+ }
+ public static int BTRFS_SUPER_MAGIC() {
+ return (int)2435016766L;
+ }
+ public static int F2FS_SUPER_MAGIC() {
+ return (int)4076150800L;
+ }
+ public static int HPFS_SUPER_MAGIC() {
+ return (int)4187351113L;
+ }
+ public static int EFIVARFS_MAGIC() {
+ return (int)3730735588L;
+ }
+ public static MemorySegment REISERFS_SUPER_MAGIC_STRING() {
+ return constants$0.REISERFS_SUPER_MAGIC_STRING$SEGMENT;
+ }
+ public static MemorySegment REISER2FS_SUPER_MAGIC_STRING() {
+ return constants$0.REISER2FS_SUPER_MAGIC_STRING$SEGMENT;
+ }
+ public static MemorySegment REISER2FS_JR_SUPER_MAGIC_STRING() {
+ return constants$0.REISER2FS_JR_SUPER_MAGIC_STRING$SEGMENT;
+ }
+ public static int BPF_FS_MAGIC() {
+ return (int)3405662737L;
+ }
+ public static int PPC_CMM_MAGIC() {
+ return (int)3344373136L;
+ }
+}
+
+
From 03dda1f01db5a867b83efdaa468bccd7dfbcac77 Mon Sep 17 00:00:00 2001
From: Manuel Bl
Date: Mon, 22 Aug 2022 20:11:10 +0200
Subject: [PATCH 004/433] jextract tests on Windows
---
java-does-usb/jextract/gen_windows.cmd | 67 ++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
create mode 100644 java-does-usb/jextract/gen_windows.cmd
diff --git a/java-does-usb/jextract/gen_windows.cmd b/java-does-usb/jextract/gen_windows.cmd
new file mode 100644
index 00000000..399b9408
--- /dev/null
+++ b/java-does-usb/jextract/gen_windows.cmd
@@ -0,0 +1,67 @@
+#!/bin/sh
+
+set JEXTRACT=..\..\..\jextract\build\jextract\bin\jextract
+
+:: handleapi.h
+:: Generates more than 1000 files
+:: Functions like CloseHandle() are generated multiple times but none of them in a public class
+::%JEXTRACT% --source --output ../src/main/java ^
+:: -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
+:: --header-class-name handleapi ^
+:: --target-package net.codecrete.usb.windows.gen.handleapi ^
+:: "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\handleapi.h"
+
+:: Generates code that produces run-time error:
+:: java.lang.UnsatisfiedLinkError: unresolved symbol: CloseHandle
+::%JEXTRACT% --source --output ../src/main/java ^
+:: -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
+:: --header-class-name handleapi ^
+:: --target-package net.codecrete.usb.windows.gen.handleapi ^
+:: --include-function CloseHandle ^
+:: "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\handleapi.h"
+
+:: Generates code that produces run-time error:
+:: java.lang.UnsatisfiedLinkError: unresolved symbol: CloseHandle
+::%JEXTRACT% --source --output ../src/main/java ^
+:: -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
+:: --header-class-name handleapi ^
+:: --target-package net.codecrete.usb.windows.gen.handleapi ^
+:: --include-function CloseHandle ^
+:: "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\Windows.h"
+
+:: winusb.h
+:: Fails with error:
+:: C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\shared\usb.h:32:9: error: unknown type name 'LARGE_INTEGER'
+:: winusb.h requires that certain other header files (like Windows.h) are processed first
+::%JEXTRACT% --source --output ../src/main/java ^
+:: -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
+:: --header-class-name WinUSB ^
+:: --target-package net.codecrete.usb.windows.gen.winusb ^
+:: "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\winusb.h"
+
+:: cfgmgr32.h
+:: Fails with error:
+:: C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\shared\devpropdef.h:33:9: error: unknown type name 'ULONG'
+::%JEXTRACT% --source --output ../src/main/java ^
+:: -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
+:: --header-class-name CfgMgr32 ^
+:: --target-package net.codecrete.usb.windows.gen.cfgmgr32 ^
+:: "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\cfgmgr32.h"
+
+:: setupapi.h
+:: Fails with error:
+:: C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\setupapi.h:65:9: error: unknown type name 'GUID'
+::%JEXTRACT% --source --output ../src/main/java ^
+:: -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
+:: --header-class-name SetupApi ^
+:: --target-package net.codecrete.usb.windows.gen.setupapi ^
+:: "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\setupapi.h"
+
+:: usbioctl.h
+:: Fails with error:
+:: C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\setupapi.h:65:9: error: unknown type name 'GUID'
+::%JEXTRACT% --source --output ../src/main/java ^
+:: -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
+:: --header-class-name USBIOCtl ^
+:: --target-package net.codecrete.usb.windows.gen.usbioctl ^
+:: "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\shared\usbioctl.h"
From e434b587ac9d86f057bf891cde141a8529b18454 Mon Sep 17 00:00:00 2001
From: Manuel Bleichenbacher
Date: Mon, 22 Aug 2022 22:15:41 +0200
Subject: [PATCH 005/433] macOS: nicer class name
---
java-does-usb/jextract/gen_macos.sh | 1 +
.../net/codecrete/usb/macos/gen/{mach_h.java => mach.java} | 4 ++--
2 files changed, 3 insertions(+), 2 deletions(-)
rename java-does-usb/src/main/java/net/codecrete/usb/macos/gen/{mach_h.java => mach.java} (95%)
diff --git a/java-does-usb/jextract/gen_macos.sh b/java-does-usb/jextract/gen_macos.sh
index 1ed1f947..2aabdfc6 100755
--- a/java-does-usb/jextract/gen_macos.sh
+++ b/java-does-usb/jextract/gen_macos.sh
@@ -11,5 +11,6 @@ JEXTRACT=../../../jextract/build/jextract/bin/jextract
## mach_error
$JEXTRACT --source --target-package net.codecrete.usb.macos.gen --output ../src/main/java \
-I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include \
+ --header-class-name mach \
--include-function mach_error \
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/mach/mach.h
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach_h.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach.java
similarity index 95%
rename from java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach_h.java
rename to java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach.java
index 24894eb4..c9d09ce1 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach_h.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach.java
@@ -6,9 +6,9 @@
import java.lang.invoke.MethodHandle;
import static java.lang.foreign.ValueLayout.*;
-public class mach_h {
+public class mach {
- /* package-private */ mach_h() {}
+ /* package-private */ mach() {}
public static OfByte C_CHAR = Constants$root.C_CHAR$LAYOUT;
public static OfShort C_SHORT = Constants$root.C_SHORT$LAYOUT;
public static OfInt C_INT = Constants$root.C_INT$LAYOUT;
From 2c8764bb0755142745696f5699e83aec1e62a366 Mon Sep 17 00:00:00 2001
From: Manuel Bl
Date: Tue, 23 Aug 2022 19:59:12 +0200
Subject: [PATCH 006/433] Linux: reduce jextract gen to needed
functions/structs
---
java-does-usb/jextract/gen_linux.sh | 12 +
.../codecrete/usb/linux/gen/errno/errno.java | 522 ----
.../usb/linux/gen/fcntl/__fsid_t.java | 25 -
.../usb/linux/gen/fcntl/constants$0.java | 44 -
.../usb/linux/gen/fcntl/constants$1.java | 20 -
.../codecrete/usb/linux/gen/fcntl/fcntl.java | 647 ----
.../codecrete/usb/linux/gen/fcntl/flock.java | 109 -
.../codecrete/usb/linux/gen/fcntl/stat.java | 234 --
.../usb/linux/gen/fcntl/timespec.java | 56 -
.../codecrete/usb/linux/gen/ioctl/ioctl.java | 726 -----
.../codecrete/usb/linux/gen/ioctl/termio.java | 112 -
.../usb/linux/gen/ioctl/winsize.java | 90 -
.../usb/linux/gen/unistd/__fsid_t.java | 25 -
.../usb/linux/gen/unistd/constants$0.java | 43 -
.../usb/linux/gen/unistd/constants$1.java | 61 -
.../usb/linux/gen/unistd/constants$10.java | 52 -
.../usb/linux/gen/unistd/constants$11.java | 65 -
.../usb/linux/gen/unistd/constants$12.java | 55 -
.../usb/linux/gen/unistd/constants$13.java | 44 -
.../usb/linux/gen/unistd/constants$14.java | 55 -
.../usb/linux/gen/unistd/constants$15.java | 50 -
.../usb/linux/gen/unistd/constants$16.java | 50 -
.../usb/linux/gen/unistd/constants$17.java | 51 -
.../usb/linux/gen/unistd/constants$18.java | 52 -
.../usb/linux/gen/unistd/constants$19.java | 17 -
.../usb/linux/gen/unistd/constants$2.java | 58 -
.../usb/linux/gen/unistd/constants$3.java | 58 -
.../usb/linux/gen/unistd/constants$4.java | 60 -
.../usb/linux/gen/unistd/constants$5.java | 57 -
.../usb/linux/gen/unistd/constants$6.java | 50 -
.../usb/linux/gen/unistd/constants$7.java | 50 -
.../usb/linux/gen/unistd/constants$8.java | 46 -
.../usb/linux/gen/unistd/constants$9.java | 53 -
.../usb/linux/gen/unistd/unistd.java | 2682 -----------------
.../gen/usbdevice_fs/__kernel_fd_set.java | 25 -
.../gen/usbdevice_fs/__kernel_fsid_t.java | 25 -
.../usbdevice_fs/__kernel_sighandler_t.java | 27 -
.../linux/gen/usbdevice_fs/constants$0.java | 21 -
.../usbdevice_fs/usbdevfs_connectinfo.java | 57 -
.../usbdevice_fs/usbdevfs_conninfo_ex.java | 111 -
.../usbdevfs_disconnect_claim.java | 60 -
.../usbdevfs_disconnectsignal.java | 57 -
.../gen/usbdevice_fs/usbdevfs_getdriver.java | 43 -
.../usbdevice_fs/usbdevfs_hub_portinfo.java | 43 -
.../gen/usbdevice_fs/usbdevfs_ioctl.java | 73 -
.../usbdevfs_iso_packet_desc.java | 73 -
.../usbdevice_fs/usbdevfs_setinterface.java | 56 -
.../gen/usbdevice_fs/usbdevfs_streams.java | 57 -
.../linux/gen/usbdevice_fs/usbdevfs_urb.java | 252 --
.../linux/gen/usbdevice_fs/usbdevice_fs.java | 347 ---
50 files changed, 12 insertions(+), 7646 deletions(-)
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/__fsid_t.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/constants$1.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/flock.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/stat.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/timespec.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/termio.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/winsize.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/__fsid_t.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$1.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$10.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$11.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$12.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$13.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$14.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$15.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$16.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$17.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$18.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$19.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$2.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$3.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$4.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$5.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$6.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$7.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$8.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$9.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/__kernel_fd_set.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/__kernel_fsid_t.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/__kernel_sighandler_t.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$0.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_connectinfo.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_conninfo_ex.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_disconnect_claim.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_disconnectsignal.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_getdriver.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_hub_portinfo.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_ioctl.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_iso_packet_desc.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_setinterface.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_streams.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_urb.java
diff --git a/java-does-usb/jextract/gen_linux.sh b/java-does-usb/jextract/gen_linux.sh
index 6fc40342..cfd9db19 100755
--- a/java-does-usb/jextract/gen_linux.sh
+++ b/java-does-usb/jextract/gen_linux.sh
@@ -13,24 +13,30 @@ JEXTRACT=../../../jextract/build/jextract/bin/jextract
$JEXTRACT --source --output ../src/main/java \
--header-class-name errno \
--target-package net.codecrete.usb.linux.gen.errno \
+ --include-function __errno_location \
/usr/include/errno.h
# ioctl.h
$JEXTRACT --source --output ../src/main/java \
--header-class-name ioctl \
--target-package net.codecrete.usb.linux.gen.ioctl \
+ --include-function ioctl \
/usr/include/x86_64-linux-gnu/sys/ioctl.h
# fcntl.h
$JEXTRACT --source --output ../src/main/java \
--header-class-name fcntl \
--target-package net.codecrete.usb.linux.gen.fcntl \
+ --include-function open \
+ --include-macro O_CLOEXEC \
+ --include-macro O_RDWR \
/usr/include/fcntl.h
# unistd.h
$JEXTRACT --source --output ../src/main/java \
--header-class-name unistd \
--target-package net.codecrete.usb.linux.gen.unistd \
+ --include-function close \
/usr/include/unistd.h
# usbdevice_fs.h
@@ -38,4 +44,10 @@ $JEXTRACT --source --output ../src/main/java \
$JEXTRACT --source --output ../src/main/java \
--header-class-name usbdevice_fs \
--target-package net.codecrete.usb.linux.gen.usbdevice_fs \
+ --include-struct usbdevfs_bulktransfer \
+ --include-struct usbdevfs_ctrltransfer \
+ --include-macro USBDEVFS_CONTROL \
+ --include-macro USBDEVFS_BULK \
+ --include-macro USBDEVFS_CLAIMINTERFACE \
+ --include-macro USBDEVFS_RELEASEINTERFACE \
/usr/include/linux/usbdevice_fs.h
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/errno.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/errno.java
index 2a42c554..ddc5d6e8 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/errno.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/errno/errno.java
@@ -17,504 +17,6 @@ public class errno {
public static OfFloat C_FLOAT = Constants$root.C_FLOAT$LAYOUT;
public static OfDouble C_DOUBLE = Constants$root.C_DOUBLE$LAYOUT;
public static OfAddress C_POINTER = Constants$root.C_POINTER$LAYOUT;
- public static int _ERRNO_H() {
- return (int)1L;
- }
- public static int _FEATURES_H() {
- return (int)1L;
- }
- public static int _DEFAULT_SOURCE() {
- return (int)1L;
- }
- public static int __GLIBC_USE_ISOC2X() {
- return (int)0L;
- }
- public static int __USE_ISOC11() {
- return (int)1L;
- }
- public static int __USE_ISOC99() {
- return (int)1L;
- }
- public static int __USE_ISOC95() {
- return (int)1L;
- }
- public static int __USE_POSIX_IMPLICITLY() {
- return (int)1L;
- }
- public static int _POSIX_SOURCE() {
- return (int)1L;
- }
- public static int __USE_POSIX() {
- return (int)1L;
- }
- public static int __USE_POSIX2() {
- return (int)1L;
- }
- public static int __USE_POSIX199309() {
- return (int)1L;
- }
- public static int __USE_POSIX199506() {
- return (int)1L;
- }
- public static int __USE_XOPEN2K() {
- return (int)1L;
- }
- public static int __USE_XOPEN2K8() {
- return (int)1L;
- }
- public static int _ATFILE_SOURCE() {
- return (int)1L;
- }
- public static int __WORDSIZE() {
- return (int)64L;
- }
- public static int __WORDSIZE_TIME64_COMPAT32() {
- return (int)1L;
- }
- public static int __SYSCALL_WORDSIZE() {
- return (int)64L;
- }
- public static int __USE_MISC() {
- return (int)1L;
- }
- public static int __USE_ATFILE() {
- return (int)1L;
- }
- public static int __USE_FORTIFY_LEVEL() {
- return (int)0L;
- }
- public static int __GLIBC_USE_DEPRECATED_GETS() {
- return (int)0L;
- }
- public static int __GLIBC_USE_DEPRECATED_SCANF() {
- return (int)0L;
- }
- public static int _STDC_PREDEF_H() {
- return (int)1L;
- }
- public static int __STDC_IEC_559__() {
- return (int)1L;
- }
- public static int __STDC_IEC_559_COMPLEX__() {
- return (int)1L;
- }
- public static int __GNU_LIBRARY__() {
- return (int)6L;
- }
- public static int __GLIBC__() {
- return (int)2L;
- }
- public static int __GLIBC_MINOR__() {
- return (int)35L;
- }
- public static int _SYS_CDEFS_H() {
- return (int)1L;
- }
- public static int __glibc_c99_flexarr_available() {
- return (int)1L;
- }
- public static int __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI() {
- return (int)0L;
- }
- public static int __HAVE_GENERIC_SELECTION() {
- return (int)1L;
- }
- public static int _BITS_ERRNO_H() {
- return (int)1L;
- }
- public static int EPERM() {
- return (int)1L;
- }
- public static int ENOENT() {
- return (int)2L;
- }
- public static int ESRCH() {
- return (int)3L;
- }
- public static int EINTR() {
- return (int)4L;
- }
- public static int EIO() {
- return (int)5L;
- }
- public static int ENXIO() {
- return (int)6L;
- }
- public static int E2BIG() {
- return (int)7L;
- }
- public static int ENOEXEC() {
- return (int)8L;
- }
- public static int EBADF() {
- return (int)9L;
- }
- public static int ECHILD() {
- return (int)10L;
- }
- public static int EAGAIN() {
- return (int)11L;
- }
- public static int ENOMEM() {
- return (int)12L;
- }
- public static int EACCES() {
- return (int)13L;
- }
- public static int EFAULT() {
- return (int)14L;
- }
- public static int ENOTBLK() {
- return (int)15L;
- }
- public static int EBUSY() {
- return (int)16L;
- }
- public static int EEXIST() {
- return (int)17L;
- }
- public static int EXDEV() {
- return (int)18L;
- }
- public static int ENODEV() {
- return (int)19L;
- }
- public static int ENOTDIR() {
- return (int)20L;
- }
- public static int EISDIR() {
- return (int)21L;
- }
- public static int EINVAL() {
- return (int)22L;
- }
- public static int ENFILE() {
- return (int)23L;
- }
- public static int EMFILE() {
- return (int)24L;
- }
- public static int ENOTTY() {
- return (int)25L;
- }
- public static int ETXTBSY() {
- return (int)26L;
- }
- public static int EFBIG() {
- return (int)27L;
- }
- public static int ENOSPC() {
- return (int)28L;
- }
- public static int ESPIPE() {
- return (int)29L;
- }
- public static int EROFS() {
- return (int)30L;
- }
- public static int EMLINK() {
- return (int)31L;
- }
- public static int EPIPE() {
- return (int)32L;
- }
- public static int EDOM() {
- return (int)33L;
- }
- public static int ERANGE() {
- return (int)34L;
- }
- public static int EDEADLK() {
- return (int)35L;
- }
- public static int ENAMETOOLONG() {
- return (int)36L;
- }
- public static int ENOLCK() {
- return (int)37L;
- }
- public static int ENOSYS() {
- return (int)38L;
- }
- public static int ENOTEMPTY() {
- return (int)39L;
- }
- public static int ELOOP() {
- return (int)40L;
- }
- public static int ENOMSG() {
- return (int)42L;
- }
- public static int EIDRM() {
- return (int)43L;
- }
- public static int ECHRNG() {
- return (int)44L;
- }
- public static int EL2NSYNC() {
- return (int)45L;
- }
- public static int EL3HLT() {
- return (int)46L;
- }
- public static int EL3RST() {
- return (int)47L;
- }
- public static int ELNRNG() {
- return (int)48L;
- }
- public static int EUNATCH() {
- return (int)49L;
- }
- public static int ENOCSI() {
- return (int)50L;
- }
- public static int EL2HLT() {
- return (int)51L;
- }
- public static int EBADE() {
- return (int)52L;
- }
- public static int EBADR() {
- return (int)53L;
- }
- public static int EXFULL() {
- return (int)54L;
- }
- public static int ENOANO() {
- return (int)55L;
- }
- public static int EBADRQC() {
- return (int)56L;
- }
- public static int EBADSLT() {
- return (int)57L;
- }
- public static int EBFONT() {
- return (int)59L;
- }
- public static int ENOSTR() {
- return (int)60L;
- }
- public static int ENODATA() {
- return (int)61L;
- }
- public static int ETIME() {
- return (int)62L;
- }
- public static int ENOSR() {
- return (int)63L;
- }
- public static int ENONET() {
- return (int)64L;
- }
- public static int ENOPKG() {
- return (int)65L;
- }
- public static int EREMOTE() {
- return (int)66L;
- }
- public static int ENOLINK() {
- return (int)67L;
- }
- public static int EADV() {
- return (int)68L;
- }
- public static int ESRMNT() {
- return (int)69L;
- }
- public static int ECOMM() {
- return (int)70L;
- }
- public static int EPROTO() {
- return (int)71L;
- }
- public static int EMULTIHOP() {
- return (int)72L;
- }
- public static int EDOTDOT() {
- return (int)73L;
- }
- public static int EBADMSG() {
- return (int)74L;
- }
- public static int EOVERFLOW() {
- return (int)75L;
- }
- public static int ENOTUNIQ() {
- return (int)76L;
- }
- public static int EBADFD() {
- return (int)77L;
- }
- public static int EREMCHG() {
- return (int)78L;
- }
- public static int ELIBACC() {
- return (int)79L;
- }
- public static int ELIBBAD() {
- return (int)80L;
- }
- public static int ELIBSCN() {
- return (int)81L;
- }
- public static int ELIBMAX() {
- return (int)82L;
- }
- public static int ELIBEXEC() {
- return (int)83L;
- }
- public static int EILSEQ() {
- return (int)84L;
- }
- public static int ERESTART() {
- return (int)85L;
- }
- public static int ESTRPIPE() {
- return (int)86L;
- }
- public static int EUSERS() {
- return (int)87L;
- }
- public static int ENOTSOCK() {
- return (int)88L;
- }
- public static int EDESTADDRREQ() {
- return (int)89L;
- }
- public static int EMSGSIZE() {
- return (int)90L;
- }
- public static int EPROTOTYPE() {
- return (int)91L;
- }
- public static int ENOPROTOOPT() {
- return (int)92L;
- }
- public static int EPROTONOSUPPORT() {
- return (int)93L;
- }
- public static int ESOCKTNOSUPPORT() {
- return (int)94L;
- }
- public static int EOPNOTSUPP() {
- return (int)95L;
- }
- public static int EPFNOSUPPORT() {
- return (int)96L;
- }
- public static int EAFNOSUPPORT() {
- return (int)97L;
- }
- public static int EADDRINUSE() {
- return (int)98L;
- }
- public static int EADDRNOTAVAIL() {
- return (int)99L;
- }
- public static int ENETDOWN() {
- return (int)100L;
- }
- public static int ENETUNREACH() {
- return (int)101L;
- }
- public static int ENETRESET() {
- return (int)102L;
- }
- public static int ECONNABORTED() {
- return (int)103L;
- }
- public static int ECONNRESET() {
- return (int)104L;
- }
- public static int ENOBUFS() {
- return (int)105L;
- }
- public static int EISCONN() {
- return (int)106L;
- }
- public static int ENOTCONN() {
- return (int)107L;
- }
- public static int ESHUTDOWN() {
- return (int)108L;
- }
- public static int ETOOMANYREFS() {
- return (int)109L;
- }
- public static int ETIMEDOUT() {
- return (int)110L;
- }
- public static int ECONNREFUSED() {
- return (int)111L;
- }
- public static int EHOSTDOWN() {
- return (int)112L;
- }
- public static int EHOSTUNREACH() {
- return (int)113L;
- }
- public static int EALREADY() {
- return (int)114L;
- }
- public static int EINPROGRESS() {
- return (int)115L;
- }
- public static int ESTALE() {
- return (int)116L;
- }
- public static int EUCLEAN() {
- return (int)117L;
- }
- public static int ENOTNAM() {
- return (int)118L;
- }
- public static int ENAVAIL() {
- return (int)119L;
- }
- public static int EISNAM() {
- return (int)120L;
- }
- public static int EREMOTEIO() {
- return (int)121L;
- }
- public static int EDQUOT() {
- return (int)122L;
- }
- public static int ENOMEDIUM() {
- return (int)123L;
- }
- public static int EMEDIUMTYPE() {
- return (int)124L;
- }
- public static int ECANCELED() {
- return (int)125L;
- }
- public static int ENOKEY() {
- return (int)126L;
- }
- public static int EKEYEXPIRED() {
- return (int)127L;
- }
- public static int EKEYREVOKED() {
- return (int)128L;
- }
- public static int EKEYREJECTED() {
- return (int)129L;
- }
- public static int EOWNERDEAD() {
- return (int)130L;
- }
- public static int ENOTRECOVERABLE() {
- return (int)131L;
- }
- public static int ERFKILL() {
- return (int)132L;
- }
- public static int EHWPOISON() {
- return (int)133L;
- }
public static MethodHandle __errno_location$MH() {
return RuntimeHelper.requireNonNull(constants$0.__errno_location$MH,"__errno_location");
}
@@ -526,30 +28,6 @@ public static MemoryAddress __errno_location () {
throw new AssertionError("should not reach here", ex$);
}
}
- public static long _POSIX_C_SOURCE() {
- return 200809L;
- }
- public static int __TIMESIZE() {
- return (int)64L;
- }
- public static long __STDC_IEC_60559_BFP__() {
- return 201404L;
- }
- public static long __STDC_IEC_60559_COMPLEX__() {
- return 201404L;
- }
- public static long __STDC_ISO_10646__() {
- return 201706L;
- }
- public static int EWOULDBLOCK() {
- return (int)11L;
- }
- public static int EDEADLOCK() {
- return (int)35L;
- }
- public static int ENOTSUP() {
- return (int)95L;
- }
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/__fsid_t.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/__fsid_t.java
deleted file mode 100644
index 681bc974..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/__fsid_t.java
+++ /dev/null
@@ -1,25 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.fcntl;
-
-import java.lang.foreign.*;
-public class __fsid_t {
-
- static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
- MemoryLayout.sequenceLayout(2, Constants$root.C_INT$LAYOUT).withName("__val")
- );
- public static MemoryLayout $LAYOUT() {
- return __fsid_t.$struct$LAYOUT;
- }
- public static MemorySegment __val$slice(MemorySegment seg) {
- return seg.asSlice(0, 8);
- }
- public static long sizeof() { return $LAYOUT().byteSize(); }
- public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
- public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
- return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
- }
- public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/constants$0.java
index 5dadf164..517dcb8f 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/constants$0.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/constants$0.java
@@ -6,14 +6,6 @@
import java.lang.invoke.MethodHandle;
class constants$0 {
- static final FunctionDescriptor fcntl$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle fcntl$MH = RuntimeHelper.downcallHandleVariadic(
- "fcntl",
- constants$0.fcntl$FUNC
- );
static final FunctionDescriptor open$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
Constants$root.C_POINTER$LAYOUT,
Constants$root.C_INT$LAYOUT
@@ -22,42 +14,6 @@ class constants$0 {
"open",
constants$0.open$FUNC
);
- static final FunctionDescriptor openat$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle openat$MH = RuntimeHelper.downcallHandleVariadic(
- "openat",
- constants$0.openat$FUNC
- );
- static final FunctionDescriptor creat$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle creat$MH = RuntimeHelper.downcallHandle(
- "creat",
- constants$0.creat$FUNC
- );
- static final FunctionDescriptor lockf$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT
- );
- static final MethodHandle lockf$MH = RuntimeHelper.downcallHandle(
- "lockf",
- constants$0.lockf$FUNC
- );
- static final FunctionDescriptor posix_fadvise$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle posix_fadvise$MH = RuntimeHelper.downcallHandle(
- "posix_fadvise",
- constants$0.posix_fadvise$FUNC
- );
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/constants$1.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/constants$1.java
deleted file mode 100644
index 0c420af8..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/constants$1.java
+++ /dev/null
@@ -1,20 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.fcntl;
-
-import java.lang.foreign.FunctionDescriptor;
-import java.lang.invoke.MethodHandle;
-class constants$1 {
-
- static final FunctionDescriptor posix_fallocate$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT
- );
- static final MethodHandle posix_fallocate$MH = RuntimeHelper.downcallHandle(
- "posix_fallocate",
- constants$1.posix_fallocate$FUNC
- );
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/fcntl.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/fcntl.java
index d2ce44d6..41eb1e0c 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/fcntl.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/fcntl.java
@@ -17,454 +17,9 @@ public class fcntl {
public static OfFloat C_FLOAT = Constants$root.C_FLOAT$LAYOUT;
public static OfDouble C_DOUBLE = Constants$root.C_DOUBLE$LAYOUT;
public static OfAddress C_POINTER = Constants$root.C_POINTER$LAYOUT;
- public static int _FCNTL_H() {
- return (int)1L;
- }
- public static int _FEATURES_H() {
- return (int)1L;
- }
- public static int _DEFAULT_SOURCE() {
- return (int)1L;
- }
- public static int __GLIBC_USE_ISOC2X() {
- return (int)0L;
- }
- public static int __USE_ISOC11() {
- return (int)1L;
- }
- public static int __USE_ISOC99() {
- return (int)1L;
- }
- public static int __USE_ISOC95() {
- return (int)1L;
- }
- public static int __USE_POSIX_IMPLICITLY() {
- return (int)1L;
- }
- public static int _POSIX_SOURCE() {
- return (int)1L;
- }
- public static int __USE_POSIX() {
- return (int)1L;
- }
- public static int __USE_POSIX2() {
- return (int)1L;
- }
- public static int __USE_POSIX199309() {
- return (int)1L;
- }
- public static int __USE_POSIX199506() {
- return (int)1L;
- }
- public static int __USE_XOPEN2K() {
- return (int)1L;
- }
- public static int __USE_XOPEN2K8() {
- return (int)1L;
- }
- public static int _ATFILE_SOURCE() {
- return (int)1L;
- }
- public static int __WORDSIZE() {
- return (int)64L;
- }
- public static int __WORDSIZE_TIME64_COMPAT32() {
- return (int)1L;
- }
- public static int __SYSCALL_WORDSIZE() {
- return (int)64L;
- }
- public static int __USE_MISC() {
- return (int)1L;
- }
- public static int __USE_ATFILE() {
- return (int)1L;
- }
- public static int __USE_FORTIFY_LEVEL() {
- return (int)0L;
- }
- public static int __GLIBC_USE_DEPRECATED_GETS() {
- return (int)0L;
- }
- public static int __GLIBC_USE_DEPRECATED_SCANF() {
- return (int)0L;
- }
- public static int _STDC_PREDEF_H() {
- return (int)1L;
- }
- public static int __STDC_IEC_559__() {
- return (int)1L;
- }
- public static int __STDC_IEC_559_COMPLEX__() {
- return (int)1L;
- }
- public static int __GNU_LIBRARY__() {
- return (int)6L;
- }
- public static int __GLIBC__() {
- return (int)2L;
- }
- public static int __GLIBC_MINOR__() {
- return (int)35L;
- }
- public static int _SYS_CDEFS_H() {
- return (int)1L;
- }
- public static int __glibc_c99_flexarr_available() {
- return (int)1L;
- }
- public static int __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI() {
- return (int)0L;
- }
- public static int __HAVE_GENERIC_SELECTION() {
- return (int)1L;
- }
- public static int _BITS_TYPES_H() {
- return (int)1L;
- }
- public static int _BITS_TYPESIZES_H() {
- return (int)1L;
- }
- public static int __OFF_T_MATCHES_OFF64_T() {
- return (int)1L;
- }
- public static int __INO_T_MATCHES_INO64_T() {
- return (int)1L;
- }
- public static int __RLIM_T_MATCHES_RLIM64_T() {
- return (int)1L;
- }
- public static int __STATFS_MATCHES_STATFS64() {
- return (int)1L;
- }
- public static int __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64() {
- return (int)1L;
- }
- public static int __FD_SETSIZE() {
- return (int)1024L;
- }
- public static int _BITS_TIME64_H() {
- return (int)1L;
- }
- public static int __O_LARGEFILE() {
- return (int)0L;
- }
- public static int F_GETLK64() {
- return (int)5L;
- }
- public static int F_SETLK64() {
- return (int)6L;
- }
- public static int F_SETLKW64() {
- return (int)7L;
- }
- public static int O_ACCMODE() {
- return (int)3L;
- }
- public static int O_RDONLY() {
- return (int)0L;
- }
- public static int O_WRONLY() {
- return (int)1L;
- }
public static int O_RDWR() {
return (int)2L;
}
- public static int O_CREAT() {
- return (int)64L;
- }
- public static int O_EXCL() {
- return (int)128L;
- }
- public static int O_NOCTTY() {
- return (int)256L;
- }
- public static int O_TRUNC() {
- return (int)512L;
- }
- public static int O_APPEND() {
- return (int)1024L;
- }
- public static int O_NONBLOCK() {
- return (int)2048L;
- }
- public static int O_SYNC() {
- return (int)1052672L;
- }
- public static int O_ASYNC() {
- return (int)8192L;
- }
- public static int __O_DIRECTORY() {
- return (int)65536L;
- }
- public static int __O_NOFOLLOW() {
- return (int)131072L;
- }
- public static int __O_CLOEXEC() {
- return (int)524288L;
- }
- public static int __O_DIRECT() {
- return (int)16384L;
- }
- public static int __O_NOATIME() {
- return (int)262144L;
- }
- public static int __O_PATH() {
- return (int)2097152L;
- }
- public static int __O_DSYNC() {
- return (int)4096L;
- }
- public static int F_GETLK() {
- return (int)5L;
- }
- public static int F_SETLK() {
- return (int)6L;
- }
- public static int F_SETLKW() {
- return (int)7L;
- }
- public static int F_DUPFD() {
- return (int)0L;
- }
- public static int F_GETFD() {
- return (int)1L;
- }
- public static int F_SETFD() {
- return (int)2L;
- }
- public static int F_GETFL() {
- return (int)3L;
- }
- public static int F_SETFL() {
- return (int)4L;
- }
- public static int __F_SETOWN() {
- return (int)8L;
- }
- public static int __F_GETOWN() {
- return (int)9L;
- }
- public static int __F_SETSIG() {
- return (int)10L;
- }
- public static int __F_GETSIG() {
- return (int)11L;
- }
- public static int __F_SETOWN_EX() {
- return (int)15L;
- }
- public static int __F_GETOWN_EX() {
- return (int)16L;
- }
- public static int F_DUPFD_CLOEXEC() {
- return (int)1030L;
- }
- public static int FD_CLOEXEC() {
- return (int)1L;
- }
- public static int F_RDLCK() {
- return (int)0L;
- }
- public static int F_WRLCK() {
- return (int)1L;
- }
- public static int F_UNLCK() {
- return (int)2L;
- }
- public static int F_EXLCK() {
- return (int)4L;
- }
- public static int F_SHLCK() {
- return (int)8L;
- }
- public static int LOCK_SH() {
- return (int)1L;
- }
- public static int LOCK_EX() {
- return (int)2L;
- }
- public static int LOCK_NB() {
- return (int)4L;
- }
- public static int LOCK_UN() {
- return (int)8L;
- }
- public static int __POSIX_FADV_DONTNEED() {
- return (int)4L;
- }
- public static int __POSIX_FADV_NOREUSE() {
- return (int)5L;
- }
- public static int POSIX_FADV_NORMAL() {
- return (int)0L;
- }
- public static int POSIX_FADV_RANDOM() {
- return (int)1L;
- }
- public static int POSIX_FADV_SEQUENTIAL() {
- return (int)2L;
- }
- public static int POSIX_FADV_WILLNEED() {
- return (int)3L;
- }
- public static int AT_SYMLINK_NOFOLLOW() {
- return (int)256L;
- }
- public static int AT_REMOVEDIR() {
- return (int)512L;
- }
- public static int AT_SYMLINK_FOLLOW() {
- return (int)1024L;
- }
- public static int AT_EACCESS() {
- return (int)512L;
- }
- public static int _STRUCT_TIMESPEC() {
- return (int)1L;
- }
- public static int _BITS_ENDIAN_H() {
- return (int)1L;
- }
- public static int __LITTLE_ENDIAN() {
- return (int)1234L;
- }
- public static int __BIG_ENDIAN() {
- return (int)4321L;
- }
- public static int __PDP_ENDIAN() {
- return (int)3412L;
- }
- public static int _BITS_ENDIANNESS_H() {
- return (int)1L;
- }
- public static int __time_t_defined() {
- return (int)1L;
- }
- public static int _BITS_STAT_H() {
- return (int)1L;
- }
- public static int _BITS_STRUCT_STAT_H() {
- return (int)1L;
- }
- public static int __S_IFMT() {
- return (int)61440L;
- }
- public static int __S_IFDIR() {
- return (int)16384L;
- }
- public static int __S_IFCHR() {
- return (int)8192L;
- }
- public static int __S_IFBLK() {
- return (int)24576L;
- }
- public static int __S_IFREG() {
- return (int)32768L;
- }
- public static int __S_IFIFO() {
- return (int)4096L;
- }
- public static int __S_IFLNK() {
- return (int)40960L;
- }
- public static int __S_IFSOCK() {
- return (int)49152L;
- }
- public static int __S_ISUID() {
- return (int)2048L;
- }
- public static int __S_ISGID() {
- return (int)1024L;
- }
- public static int __S_ISVTX() {
- return (int)512L;
- }
- public static int __S_IREAD() {
- return (int)256L;
- }
- public static int __S_IWRITE() {
- return (int)128L;
- }
- public static int __S_IEXEC() {
- return (int)64L;
- }
- public static int R_OK() {
- return (int)4L;
- }
- public static int W_OK() {
- return (int)2L;
- }
- public static int X_OK() {
- return (int)1L;
- }
- public static int F_OK() {
- return (int)0L;
- }
- public static int SEEK_SET() {
- return (int)0L;
- }
- public static int SEEK_CUR() {
- return (int)1L;
- }
- public static int SEEK_END() {
- return (int)2L;
- }
- public static int F_ULOCK() {
- return (int)0L;
- }
- public static int F_LOCK() {
- return (int)1L;
- }
- public static int F_TLOCK() {
- return (int)2L;
- }
- public static int F_TEST() {
- return (int)3L;
- }
- public static OfShort __int16_t = Constants$root.C_SHORT$LAYOUT;
- public static OfInt __int32_t = Constants$root.C_INT$LAYOUT;
- public static OfLong __int64_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfShort __int_least16_t = Constants$root.C_SHORT$LAYOUT;
- public static OfInt __int_least32_t = Constants$root.C_INT$LAYOUT;
- public static OfLong __int_least64_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __quad_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __intmax_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __off_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __off64_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfInt __pid_t = Constants$root.C_INT$LAYOUT;
- public static OfLong __clock_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __time_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __suseconds_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __suseconds64_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfInt __daddr_t = Constants$root.C_INT$LAYOUT;
- public static OfInt __key_t = Constants$root.C_INT$LAYOUT;
- public static OfInt __clockid_t = Constants$root.C_INT$LAYOUT;
- public static OfAddress __timer_t = Constants$root.C_POINTER$LAYOUT;
- public static OfLong __blksize_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __blkcnt_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __blkcnt64_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __fsword_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __ssize_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __syscall_slong_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __loff_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfAddress __caddr_t = Constants$root.C_POINTER$LAYOUT;
- public static OfLong __intptr_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfInt __sig_atomic_t = Constants$root.C_INT$LAYOUT;
- public static OfLong off_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfInt pid_t = Constants$root.C_INT$LAYOUT;
- public static OfLong time_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static MethodHandle fcntl$MH() {
- return RuntimeHelper.requireNonNull(constants$0.fcntl$MH,"fcntl");
- }
- public static int fcntl ( int __fd, int __cmd, Object... x2) {
- var mh$ = fcntl$MH();
- try {
- return (int)mh$.invokeExact(__fd, __cmd, x2);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
public static MethodHandle open$MH() {
return RuntimeHelper.requireNonNull(constants$0.open$MH,"open");
}
@@ -476,211 +31,9 @@ public static int open ( Addressable __file, int __oflag, Object... x2) {
throw new AssertionError("should not reach here", ex$);
}
}
- public static MethodHandle openat$MH() {
- return RuntimeHelper.requireNonNull(constants$0.openat$MH,"openat");
- }
- public static int openat ( int __fd, Addressable __file, int __oflag, Object... x3) {
- var mh$ = openat$MH();
- try {
- return (int)mh$.invokeExact(__fd, __file, __oflag, x3);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle creat$MH() {
- return RuntimeHelper.requireNonNull(constants$0.creat$MH,"creat");
- }
- public static int creat ( Addressable __file, int __mode) {
- var mh$ = creat$MH();
- try {
- return (int)mh$.invokeExact(__file, __mode);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle lockf$MH() {
- return RuntimeHelper.requireNonNull(constants$0.lockf$MH,"lockf");
- }
- public static int lockf ( int __fd, int __cmd, long __len) {
- var mh$ = lockf$MH();
- try {
- return (int)mh$.invokeExact(__fd, __cmd, __len);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle posix_fadvise$MH() {
- return RuntimeHelper.requireNonNull(constants$0.posix_fadvise$MH,"posix_fadvise");
- }
- public static int posix_fadvise ( int __fd, long __offset, long __len, int __advise) {
- var mh$ = posix_fadvise$MH();
- try {
- return (int)mh$.invokeExact(__fd, __offset, __len, __advise);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle posix_fallocate$MH() {
- return RuntimeHelper.requireNonNull(constants$1.posix_fallocate$MH,"posix_fallocate");
- }
- public static int posix_fallocate ( int __fd, long __offset, long __len) {
- var mh$ = posix_fallocate$MH();
- try {
- return (int)mh$.invokeExact(__fd, __offset, __len);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static long _POSIX_C_SOURCE() {
- return 200809L;
- }
- public static int __TIMESIZE() {
- return (int)64L;
- }
- public static long __STDC_IEC_60559_BFP__() {
- return 201404L;
- }
- public static long __STDC_IEC_60559_COMPLEX__() {
- return 201404L;
- }
- public static long __STDC_ISO_10646__() {
- return 201706L;
- }
- public static int O_NDELAY() {
- return (int)2048L;
- }
- public static int O_FSYNC() {
- return (int)1052672L;
- }
- public static int __O_TMPFILE() {
- return (int)4259840L;
- }
- public static int O_DIRECTORY() {
- return (int)65536L;
- }
- public static int O_NOFOLLOW() {
- return (int)131072L;
- }
public static int O_CLOEXEC() {
return (int)524288L;
}
- public static int O_DSYNC() {
- return (int)4096L;
- }
- public static int O_RSYNC() {
- return (int)1052672L;
- }
- public static int F_SETOWN() {
- return (int)8L;
- }
- public static int F_GETOWN() {
- return (int)9L;
- }
- public static int FAPPEND() {
- return (int)1024L;
- }
- public static int FFSYNC() {
- return (int)1052672L;
- }
- public static int FASYNC() {
- return (int)8192L;
- }
- public static int FNONBLOCK() {
- return (int)2048L;
- }
- public static int FNDELAY() {
- return (int)2048L;
- }
- public static int POSIX_FADV_DONTNEED() {
- return (int)4L;
- }
- public static int POSIX_FADV_NOREUSE() {
- return (int)5L;
- }
- public static int AT_FDCWD() {
- return (int)-100L;
- }
- public static int __BYTE_ORDER() {
- return (int)1234L;
- }
- public static int __FLOAT_WORD_ORDER() {
- return (int)1234L;
- }
- public static long UTIME_NOW() {
- return 1073741823L;
- }
- public static long UTIME_OMIT() {
- return 1073741822L;
- }
- public static int S_IFMT() {
- return (int)61440L;
- }
- public static int S_IFDIR() {
- return (int)16384L;
- }
- public static int S_IFCHR() {
- return (int)8192L;
- }
- public static int S_IFBLK() {
- return (int)24576L;
- }
- public static int S_IFREG() {
- return (int)32768L;
- }
- public static int S_IFIFO() {
- return (int)4096L;
- }
- public static int S_IFLNK() {
- return (int)40960L;
- }
- public static int S_IFSOCK() {
- return (int)49152L;
- }
- public static int S_ISUID() {
- return (int)2048L;
- }
- public static int S_ISGID() {
- return (int)1024L;
- }
- public static int S_ISVTX() {
- return (int)512L;
- }
- public static int S_IRUSR() {
- return (int)256L;
- }
- public static int S_IWUSR() {
- return (int)128L;
- }
- public static int S_IXUSR() {
- return (int)64L;
- }
- public static int S_IRWXU() {
- return (int)448L;
- }
- public static int S_IRGRP() {
- return (int)32L;
- }
- public static int S_IWGRP() {
- return (int)16L;
- }
- public static int S_IXGRP() {
- return (int)8L;
- }
- public static int S_IRWXG() {
- return (int)56L;
- }
- public static int S_IROTH() {
- return (int)4L;
- }
- public static int S_IWOTH() {
- return (int)2L;
- }
- public static int S_IXOTH() {
- return (int)1L;
- }
- public static int S_IRWXO() {
- return (int)7L;
- }
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/flock.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/flock.java
deleted file mode 100644
index e3192d4c..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/flock.java
+++ /dev/null
@@ -1,109 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.fcntl;
-
-import java.lang.foreign.*;
-import java.lang.invoke.VarHandle;
-public class flock {
-
- static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
- Constants$root.C_SHORT$LAYOUT.withName("l_type"),
- Constants$root.C_SHORT$LAYOUT.withName("l_whence"),
- MemoryLayout.paddingLayout(32),
- Constants$root.C_LONG_LONG$LAYOUT.withName("l_start"),
- Constants$root.C_LONG_LONG$LAYOUT.withName("l_len"),
- Constants$root.C_INT$LAYOUT.withName("l_pid"),
- MemoryLayout.paddingLayout(32)
- ).withName("flock");
- public static MemoryLayout $LAYOUT() {
- return flock.$struct$LAYOUT;
- }
- static final VarHandle l_type$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("l_type"));
- public static VarHandle l_type$VH() {
- return flock.l_type$VH;
- }
- public static short l_type$get(MemorySegment seg) {
- return (short)flock.l_type$VH.get(seg);
- }
- public static void l_type$set( MemorySegment seg, short x) {
- flock.l_type$VH.set(seg, x);
- }
- public static short l_type$get(MemorySegment seg, long index) {
- return (short)flock.l_type$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void l_type$set(MemorySegment seg, long index, short x) {
- flock.l_type$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle l_whence$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("l_whence"));
- public static VarHandle l_whence$VH() {
- return flock.l_whence$VH;
- }
- public static short l_whence$get(MemorySegment seg) {
- return (short)flock.l_whence$VH.get(seg);
- }
- public static void l_whence$set( MemorySegment seg, short x) {
- flock.l_whence$VH.set(seg, x);
- }
- public static short l_whence$get(MemorySegment seg, long index) {
- return (short)flock.l_whence$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void l_whence$set(MemorySegment seg, long index, short x) {
- flock.l_whence$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle l_start$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("l_start"));
- public static VarHandle l_start$VH() {
- return flock.l_start$VH;
- }
- public static long l_start$get(MemorySegment seg) {
- return (long)flock.l_start$VH.get(seg);
- }
- public static void l_start$set( MemorySegment seg, long x) {
- flock.l_start$VH.set(seg, x);
- }
- public static long l_start$get(MemorySegment seg, long index) {
- return (long)flock.l_start$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void l_start$set(MemorySegment seg, long index, long x) {
- flock.l_start$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle l_len$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("l_len"));
- public static VarHandle l_len$VH() {
- return flock.l_len$VH;
- }
- public static long l_len$get(MemorySegment seg) {
- return (long)flock.l_len$VH.get(seg);
- }
- public static void l_len$set( MemorySegment seg, long x) {
- flock.l_len$VH.set(seg, x);
- }
- public static long l_len$get(MemorySegment seg, long index) {
- return (long)flock.l_len$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void l_len$set(MemorySegment seg, long index, long x) {
- flock.l_len$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle l_pid$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("l_pid"));
- public static VarHandle l_pid$VH() {
- return flock.l_pid$VH;
- }
- public static int l_pid$get(MemorySegment seg) {
- return (int)flock.l_pid$VH.get(seg);
- }
- public static void l_pid$set( MemorySegment seg, int x) {
- flock.l_pid$VH.set(seg, x);
- }
- public static int l_pid$get(MemorySegment seg, long index) {
- return (int)flock.l_pid$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void l_pid$set(MemorySegment seg, long index, int x) {
- flock.l_pid$VH.set(seg.asSlice(index*sizeof()), x);
- }
- public static long sizeof() { return $LAYOUT().byteSize(); }
- public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
- public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
- return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
- }
- public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/stat.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/stat.java
deleted file mode 100644
index c41afa20..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/stat.java
+++ /dev/null
@@ -1,234 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.fcntl;
-
-import java.lang.foreign.*;
-import java.lang.invoke.VarHandle;
-public class stat {
-
- static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
- Constants$root.C_LONG_LONG$LAYOUT.withName("st_dev"),
- Constants$root.C_LONG_LONG$LAYOUT.withName("st_ino"),
- Constants$root.C_LONG_LONG$LAYOUT.withName("st_nlink"),
- Constants$root.C_INT$LAYOUT.withName("st_mode"),
- Constants$root.C_INT$LAYOUT.withName("st_uid"),
- Constants$root.C_INT$LAYOUT.withName("st_gid"),
- Constants$root.C_INT$LAYOUT.withName("__pad0"),
- Constants$root.C_LONG_LONG$LAYOUT.withName("st_rdev"),
- Constants$root.C_LONG_LONG$LAYOUT.withName("st_size"),
- Constants$root.C_LONG_LONG$LAYOUT.withName("st_blksize"),
- Constants$root.C_LONG_LONG$LAYOUT.withName("st_blocks"),
- MemoryLayout.structLayout(
- Constants$root.C_LONG_LONG$LAYOUT.withName("tv_sec"),
- Constants$root.C_LONG_LONG$LAYOUT.withName("tv_nsec")
- ).withName("st_atim"),
- MemoryLayout.structLayout(
- Constants$root.C_LONG_LONG$LAYOUT.withName("tv_sec"),
- Constants$root.C_LONG_LONG$LAYOUT.withName("tv_nsec")
- ).withName("st_mtim"),
- MemoryLayout.structLayout(
- Constants$root.C_LONG_LONG$LAYOUT.withName("tv_sec"),
- Constants$root.C_LONG_LONG$LAYOUT.withName("tv_nsec")
- ).withName("st_ctim"),
- MemoryLayout.sequenceLayout(3, Constants$root.C_LONG_LONG$LAYOUT).withName("__glibc_reserved")
- ).withName("stat");
- public static MemoryLayout $LAYOUT() {
- return stat.$struct$LAYOUT;
- }
- static final VarHandle st_dev$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("st_dev"));
- public static VarHandle st_dev$VH() {
- return stat.st_dev$VH;
- }
- public static long st_dev$get(MemorySegment seg) {
- return (long)stat.st_dev$VH.get(seg);
- }
- public static void st_dev$set( MemorySegment seg, long x) {
- stat.st_dev$VH.set(seg, x);
- }
- public static long st_dev$get(MemorySegment seg, long index) {
- return (long)stat.st_dev$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void st_dev$set(MemorySegment seg, long index, long x) {
- stat.st_dev$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle st_ino$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("st_ino"));
- public static VarHandle st_ino$VH() {
- return stat.st_ino$VH;
- }
- public static long st_ino$get(MemorySegment seg) {
- return (long)stat.st_ino$VH.get(seg);
- }
- public static void st_ino$set( MemorySegment seg, long x) {
- stat.st_ino$VH.set(seg, x);
- }
- public static long st_ino$get(MemorySegment seg, long index) {
- return (long)stat.st_ino$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void st_ino$set(MemorySegment seg, long index, long x) {
- stat.st_ino$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle st_nlink$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("st_nlink"));
- public static VarHandle st_nlink$VH() {
- return stat.st_nlink$VH;
- }
- public static long st_nlink$get(MemorySegment seg) {
- return (long)stat.st_nlink$VH.get(seg);
- }
- public static void st_nlink$set( MemorySegment seg, long x) {
- stat.st_nlink$VH.set(seg, x);
- }
- public static long st_nlink$get(MemorySegment seg, long index) {
- return (long)stat.st_nlink$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void st_nlink$set(MemorySegment seg, long index, long x) {
- stat.st_nlink$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle st_mode$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("st_mode"));
- public static VarHandle st_mode$VH() {
- return stat.st_mode$VH;
- }
- public static int st_mode$get(MemorySegment seg) {
- return (int)stat.st_mode$VH.get(seg);
- }
- public static void st_mode$set( MemorySegment seg, int x) {
- stat.st_mode$VH.set(seg, x);
- }
- public static int st_mode$get(MemorySegment seg, long index) {
- return (int)stat.st_mode$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void st_mode$set(MemorySegment seg, long index, int x) {
- stat.st_mode$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle st_uid$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("st_uid"));
- public static VarHandle st_uid$VH() {
- return stat.st_uid$VH;
- }
- public static int st_uid$get(MemorySegment seg) {
- return (int)stat.st_uid$VH.get(seg);
- }
- public static void st_uid$set( MemorySegment seg, int x) {
- stat.st_uid$VH.set(seg, x);
- }
- public static int st_uid$get(MemorySegment seg, long index) {
- return (int)stat.st_uid$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void st_uid$set(MemorySegment seg, long index, int x) {
- stat.st_uid$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle st_gid$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("st_gid"));
- public static VarHandle st_gid$VH() {
- return stat.st_gid$VH;
- }
- public static int st_gid$get(MemorySegment seg) {
- return (int)stat.st_gid$VH.get(seg);
- }
- public static void st_gid$set( MemorySegment seg, int x) {
- stat.st_gid$VH.set(seg, x);
- }
- public static int st_gid$get(MemorySegment seg, long index) {
- return (int)stat.st_gid$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void st_gid$set(MemorySegment seg, long index, int x) {
- stat.st_gid$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle __pad0$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("__pad0"));
- public static VarHandle __pad0$VH() {
- return stat.__pad0$VH;
- }
- public static int __pad0$get(MemorySegment seg) {
- return (int)stat.__pad0$VH.get(seg);
- }
- public static void __pad0$set( MemorySegment seg, int x) {
- stat.__pad0$VH.set(seg, x);
- }
- public static int __pad0$get(MemorySegment seg, long index) {
- return (int)stat.__pad0$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void __pad0$set(MemorySegment seg, long index, int x) {
- stat.__pad0$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle st_rdev$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("st_rdev"));
- public static VarHandle st_rdev$VH() {
- return stat.st_rdev$VH;
- }
- public static long st_rdev$get(MemorySegment seg) {
- return (long)stat.st_rdev$VH.get(seg);
- }
- public static void st_rdev$set( MemorySegment seg, long x) {
- stat.st_rdev$VH.set(seg, x);
- }
- public static long st_rdev$get(MemorySegment seg, long index) {
- return (long)stat.st_rdev$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void st_rdev$set(MemorySegment seg, long index, long x) {
- stat.st_rdev$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle st_size$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("st_size"));
- public static VarHandle st_size$VH() {
- return stat.st_size$VH;
- }
- public static long st_size$get(MemorySegment seg) {
- return (long)stat.st_size$VH.get(seg);
- }
- public static void st_size$set( MemorySegment seg, long x) {
- stat.st_size$VH.set(seg, x);
- }
- public static long st_size$get(MemorySegment seg, long index) {
- return (long)stat.st_size$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void st_size$set(MemorySegment seg, long index, long x) {
- stat.st_size$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle st_blksize$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("st_blksize"));
- public static VarHandle st_blksize$VH() {
- return stat.st_blksize$VH;
- }
- public static long st_blksize$get(MemorySegment seg) {
- return (long)stat.st_blksize$VH.get(seg);
- }
- public static void st_blksize$set( MemorySegment seg, long x) {
- stat.st_blksize$VH.set(seg, x);
- }
- public static long st_blksize$get(MemorySegment seg, long index) {
- return (long)stat.st_blksize$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void st_blksize$set(MemorySegment seg, long index, long x) {
- stat.st_blksize$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle st_blocks$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("st_blocks"));
- public static VarHandle st_blocks$VH() {
- return stat.st_blocks$VH;
- }
- public static long st_blocks$get(MemorySegment seg) {
- return (long)stat.st_blocks$VH.get(seg);
- }
- public static void st_blocks$set( MemorySegment seg, long x) {
- stat.st_blocks$VH.set(seg, x);
- }
- public static long st_blocks$get(MemorySegment seg, long index) {
- return (long)stat.st_blocks$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void st_blocks$set(MemorySegment seg, long index, long x) {
- stat.st_blocks$VH.set(seg.asSlice(index*sizeof()), x);
- }
- public static MemorySegment st_atim$slice(MemorySegment seg) {
- return seg.asSlice(72, 16);
- }
- public static MemorySegment st_mtim$slice(MemorySegment seg) {
- return seg.asSlice(88, 16);
- }
- public static MemorySegment st_ctim$slice(MemorySegment seg) {
- return seg.asSlice(104, 16);
- }
- public static MemorySegment __glibc_reserved$slice(MemorySegment seg) {
- return seg.asSlice(120, 24);
- }
- public static long sizeof() { return $LAYOUT().byteSize(); }
- public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
- public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
- return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
- }
- public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/timespec.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/timespec.java
deleted file mode 100644
index 5dae8dc0..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/fcntl/timespec.java
+++ /dev/null
@@ -1,56 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.fcntl;
-
-import java.lang.foreign.*;
-import java.lang.invoke.VarHandle;
-public class timespec {
-
- static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
- Constants$root.C_LONG_LONG$LAYOUT.withName("tv_sec"),
- Constants$root.C_LONG_LONG$LAYOUT.withName("tv_nsec")
- ).withName("timespec");
- public static MemoryLayout $LAYOUT() {
- return timespec.$struct$LAYOUT;
- }
- static final VarHandle tv_sec$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("tv_sec"));
- public static VarHandle tv_sec$VH() {
- return timespec.tv_sec$VH;
- }
- public static long tv_sec$get(MemorySegment seg) {
- return (long)timespec.tv_sec$VH.get(seg);
- }
- public static void tv_sec$set( MemorySegment seg, long x) {
- timespec.tv_sec$VH.set(seg, x);
- }
- public static long tv_sec$get(MemorySegment seg, long index) {
- return (long)timespec.tv_sec$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void tv_sec$set(MemorySegment seg, long index, long x) {
- timespec.tv_sec$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle tv_nsec$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("tv_nsec"));
- public static VarHandle tv_nsec$VH() {
- return timespec.tv_nsec$VH;
- }
- public static long tv_nsec$get(MemorySegment seg) {
- return (long)timespec.tv_nsec$VH.get(seg);
- }
- public static void tv_nsec$set( MemorySegment seg, long x) {
- timespec.tv_nsec$VH.set(seg, x);
- }
- public static long tv_nsec$get(MemorySegment seg, long index) {
- return (long)timespec.tv_nsec$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void tv_nsec$set(MemorySegment seg, long index, long x) {
- timespec.tv_nsec$VH.set(seg.asSlice(index*sizeof()), x);
- }
- public static long sizeof() { return $LAYOUT().byteSize(); }
- public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
- public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
- return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
- }
- public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/ioctl.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/ioctl.java
index 795090b8..cbe51a0b 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/ioctl.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/ioctl.java
@@ -16,585 +16,6 @@ public class ioctl {
public static OfFloat C_FLOAT = Constants$root.C_FLOAT$LAYOUT;
public static OfDouble C_DOUBLE = Constants$root.C_DOUBLE$LAYOUT;
public static OfAddress C_POINTER = Constants$root.C_POINTER$LAYOUT;
- public static int _SYS_IOCTL_H() {
- return (int)1L;
- }
- public static int _FEATURES_H() {
- return (int)1L;
- }
- public static int _DEFAULT_SOURCE() {
- return (int)1L;
- }
- public static int __GLIBC_USE_ISOC2X() {
- return (int)0L;
- }
- public static int __USE_ISOC11() {
- return (int)1L;
- }
- public static int __USE_ISOC99() {
- return (int)1L;
- }
- public static int __USE_ISOC95() {
- return (int)1L;
- }
- public static int __USE_POSIX_IMPLICITLY() {
- return (int)1L;
- }
- public static int _POSIX_SOURCE() {
- return (int)1L;
- }
- public static int __USE_POSIX() {
- return (int)1L;
- }
- public static int __USE_POSIX2() {
- return (int)1L;
- }
- public static int __USE_POSIX199309() {
- return (int)1L;
- }
- public static int __USE_POSIX199506() {
- return (int)1L;
- }
- public static int __USE_XOPEN2K() {
- return (int)1L;
- }
- public static int __USE_XOPEN2K8() {
- return (int)1L;
- }
- public static int _ATFILE_SOURCE() {
- return (int)1L;
- }
- public static int __WORDSIZE() {
- return (int)64L;
- }
- public static int __WORDSIZE_TIME64_COMPAT32() {
- return (int)1L;
- }
- public static int __SYSCALL_WORDSIZE() {
- return (int)64L;
- }
- public static int __USE_MISC() {
- return (int)1L;
- }
- public static int __USE_ATFILE() {
- return (int)1L;
- }
- public static int __USE_FORTIFY_LEVEL() {
- return (int)0L;
- }
- public static int __GLIBC_USE_DEPRECATED_GETS() {
- return (int)0L;
- }
- public static int __GLIBC_USE_DEPRECATED_SCANF() {
- return (int)0L;
- }
- public static int _STDC_PREDEF_H() {
- return (int)1L;
- }
- public static int __STDC_IEC_559__() {
- return (int)1L;
- }
- public static int __STDC_IEC_559_COMPLEX__() {
- return (int)1L;
- }
- public static int __GNU_LIBRARY__() {
- return (int)6L;
- }
- public static int __GLIBC__() {
- return (int)2L;
- }
- public static int __GLIBC_MINOR__() {
- return (int)35L;
- }
- public static int _SYS_CDEFS_H() {
- return (int)1L;
- }
- public static int __glibc_c99_flexarr_available() {
- return (int)1L;
- }
- public static int __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI() {
- return (int)0L;
- }
- public static int __HAVE_GENERIC_SELECTION() {
- return (int)1L;
- }
- public static int _IOC_NRBITS() {
- return (int)8L;
- }
- public static int _IOC_TYPEBITS() {
- return (int)8L;
- }
- public static int _IOC_SIZEBITS() {
- return (int)14L;
- }
- public static int _IOC_DIRBITS() {
- return (int)2L;
- }
- public static int _IOC_NRSHIFT() {
- return (int)0L;
- }
- public static int TCGETS() {
- return (int)21505L;
- }
- public static int TCSETS() {
- return (int)21506L;
- }
- public static int TCSETSW() {
- return (int)21507L;
- }
- public static int TCSETSF() {
- return (int)21508L;
- }
- public static int TCGETA() {
- return (int)21509L;
- }
- public static int TCSETA() {
- return (int)21510L;
- }
- public static int TCSETAW() {
- return (int)21511L;
- }
- public static int TCSETAF() {
- return (int)21512L;
- }
- public static int TCSBRK() {
- return (int)21513L;
- }
- public static int TCXONC() {
- return (int)21514L;
- }
- public static int TCFLSH() {
- return (int)21515L;
- }
- public static int TIOCEXCL() {
- return (int)21516L;
- }
- public static int TIOCNXCL() {
- return (int)21517L;
- }
- public static int TIOCSCTTY() {
- return (int)21518L;
- }
- public static int TIOCGPGRP() {
- return (int)21519L;
- }
- public static int TIOCSPGRP() {
- return (int)21520L;
- }
- public static int TIOCOUTQ() {
- return (int)21521L;
- }
- public static int TIOCSTI() {
- return (int)21522L;
- }
- public static int TIOCGWINSZ() {
- return (int)21523L;
- }
- public static int TIOCSWINSZ() {
- return (int)21524L;
- }
- public static int TIOCMGET() {
- return (int)21525L;
- }
- public static int TIOCMBIS() {
- return (int)21526L;
- }
- public static int TIOCMBIC() {
- return (int)21527L;
- }
- public static int TIOCMSET() {
- return (int)21528L;
- }
- public static int TIOCGSOFTCAR() {
- return (int)21529L;
- }
- public static int TIOCSSOFTCAR() {
- return (int)21530L;
- }
- public static int FIONREAD() {
- return (int)21531L;
- }
- public static int TIOCLINUX() {
- return (int)21532L;
- }
- public static int TIOCCONS() {
- return (int)21533L;
- }
- public static int TIOCGSERIAL() {
- return (int)21534L;
- }
- public static int TIOCSSERIAL() {
- return (int)21535L;
- }
- public static int TIOCPKT() {
- return (int)21536L;
- }
- public static int FIONBIO() {
- return (int)21537L;
- }
- public static int TIOCNOTTY() {
- return (int)21538L;
- }
- public static int TIOCSETD() {
- return (int)21539L;
- }
- public static int TIOCGETD() {
- return (int)21540L;
- }
- public static int TCSBRKP() {
- return (int)21541L;
- }
- public static int TIOCSBRK() {
- return (int)21543L;
- }
- public static int TIOCCBRK() {
- return (int)21544L;
- }
- public static int TIOCGSID() {
- return (int)21545L;
- }
- public static int TIOCGRS485() {
- return (int)21550L;
- }
- public static int TIOCSRS485() {
- return (int)21551L;
- }
- public static int TCGETX() {
- return (int)21554L;
- }
- public static int TCSETX() {
- return (int)21555L;
- }
- public static int TCSETXF() {
- return (int)21556L;
- }
- public static int TCSETXW() {
- return (int)21557L;
- }
- public static int TIOCVHANGUP() {
- return (int)21559L;
- }
- public static int FIONCLEX() {
- return (int)21584L;
- }
- public static int FIOCLEX() {
- return (int)21585L;
- }
- public static int FIOASYNC() {
- return (int)21586L;
- }
- public static int TIOCSERCONFIG() {
- return (int)21587L;
- }
- public static int TIOCSERGWILD() {
- return (int)21588L;
- }
- public static int TIOCSERSWILD() {
- return (int)21589L;
- }
- public static int TIOCGLCKTRMIOS() {
- return (int)21590L;
- }
- public static int TIOCSLCKTRMIOS() {
- return (int)21591L;
- }
- public static int TIOCSERGSTRUCT() {
- return (int)21592L;
- }
- public static int TIOCSERGETLSR() {
- return (int)21593L;
- }
- public static int TIOCSERGETMULTI() {
- return (int)21594L;
- }
- public static int TIOCSERSETMULTI() {
- return (int)21595L;
- }
- public static int TIOCMIWAIT() {
- return (int)21596L;
- }
- public static int TIOCGICOUNT() {
- return (int)21597L;
- }
- public static int FIOQSIZE() {
- return (int)21600L;
- }
- public static int TIOCPKT_DATA() {
- return (int)0L;
- }
- public static int TIOCPKT_FLUSHREAD() {
- return (int)1L;
- }
- public static int TIOCPKT_FLUSHWRITE() {
- return (int)2L;
- }
- public static int TIOCPKT_STOP() {
- return (int)4L;
- }
- public static int TIOCPKT_START() {
- return (int)8L;
- }
- public static int TIOCPKT_NOSTOP() {
- return (int)16L;
- }
- public static int TIOCPKT_DOSTOP() {
- return (int)32L;
- }
- public static int TIOCPKT_IOCTL() {
- return (int)64L;
- }
- public static int TIOCSER_TEMT() {
- return (int)1L;
- }
- public static int SIOCADDRT() {
- return (int)35083L;
- }
- public static int SIOCDELRT() {
- return (int)35084L;
- }
- public static int SIOCRTMSG() {
- return (int)35085L;
- }
- public static int SIOCGIFNAME() {
- return (int)35088L;
- }
- public static int SIOCSIFLINK() {
- return (int)35089L;
- }
- public static int SIOCGIFCONF() {
- return (int)35090L;
- }
- public static int SIOCGIFFLAGS() {
- return (int)35091L;
- }
- public static int SIOCSIFFLAGS() {
- return (int)35092L;
- }
- public static int SIOCGIFADDR() {
- return (int)35093L;
- }
- public static int SIOCSIFADDR() {
- return (int)35094L;
- }
- public static int SIOCGIFDSTADDR() {
- return (int)35095L;
- }
- public static int SIOCSIFDSTADDR() {
- return (int)35096L;
- }
- public static int SIOCGIFBRDADDR() {
- return (int)35097L;
- }
- public static int SIOCSIFBRDADDR() {
- return (int)35098L;
- }
- public static int SIOCGIFNETMASK() {
- return (int)35099L;
- }
- public static int SIOCSIFNETMASK() {
- return (int)35100L;
- }
- public static int SIOCGIFMETRIC() {
- return (int)35101L;
- }
- public static int SIOCSIFMETRIC() {
- return (int)35102L;
- }
- public static int SIOCGIFMEM() {
- return (int)35103L;
- }
- public static int SIOCSIFMEM() {
- return (int)35104L;
- }
- public static int SIOCGIFMTU() {
- return (int)35105L;
- }
- public static int SIOCSIFMTU() {
- return (int)35106L;
- }
- public static int SIOCSIFNAME() {
- return (int)35107L;
- }
- public static int SIOCSIFHWADDR() {
- return (int)35108L;
- }
- public static int SIOCGIFENCAP() {
- return (int)35109L;
- }
- public static int SIOCSIFENCAP() {
- return (int)35110L;
- }
- public static int SIOCGIFHWADDR() {
- return (int)35111L;
- }
- public static int SIOCGIFSLAVE() {
- return (int)35113L;
- }
- public static int SIOCSIFSLAVE() {
- return (int)35120L;
- }
- public static int SIOCADDMULTI() {
- return (int)35121L;
- }
- public static int SIOCDELMULTI() {
- return (int)35122L;
- }
- public static int SIOCGIFINDEX() {
- return (int)35123L;
- }
- public static int SIOCSIFPFLAGS() {
- return (int)35124L;
- }
- public static int SIOCGIFPFLAGS() {
- return (int)35125L;
- }
- public static int SIOCDIFADDR() {
- return (int)35126L;
- }
- public static int SIOCSIFHWBROADCAST() {
- return (int)35127L;
- }
- public static int SIOCGIFCOUNT() {
- return (int)35128L;
- }
- public static int SIOCGIFBR() {
- return (int)35136L;
- }
- public static int SIOCSIFBR() {
- return (int)35137L;
- }
- public static int SIOCGIFTXQLEN() {
- return (int)35138L;
- }
- public static int SIOCSIFTXQLEN() {
- return (int)35139L;
- }
- public static int SIOCDARP() {
- return (int)35155L;
- }
- public static int SIOCGARP() {
- return (int)35156L;
- }
- public static int SIOCSARP() {
- return (int)35157L;
- }
- public static int SIOCDRARP() {
- return (int)35168L;
- }
- public static int SIOCGRARP() {
- return (int)35169L;
- }
- public static int SIOCSRARP() {
- return (int)35170L;
- }
- public static int SIOCGIFMAP() {
- return (int)35184L;
- }
- public static int SIOCSIFMAP() {
- return (int)35185L;
- }
- public static int SIOCADDDLCI() {
- return (int)35200L;
- }
- public static int SIOCDELDLCI() {
- return (int)35201L;
- }
- public static int SIOCDEVPRIVATE() {
- return (int)35312L;
- }
- public static int SIOCPROTOPRIVATE() {
- return (int)35296L;
- }
- public static int NCC() {
- return (int)8L;
- }
- public static int TIOCM_LE() {
- return (int)1L;
- }
- public static int TIOCM_DTR() {
- return (int)2L;
- }
- public static int TIOCM_RTS() {
- return (int)4L;
- }
- public static int TIOCM_ST() {
- return (int)8L;
- }
- public static int TIOCM_SR() {
- return (int)16L;
- }
- public static int TIOCM_CTS() {
- return (int)32L;
- }
- public static int TIOCM_CAR() {
- return (int)64L;
- }
- public static int TIOCM_RNG() {
- return (int)128L;
- }
- public static int TIOCM_DSR() {
- return (int)256L;
- }
- public static int N_TTY() {
- return (int)0L;
- }
- public static int N_SLIP() {
- return (int)1L;
- }
- public static int N_MOUSE() {
- return (int)2L;
- }
- public static int N_PPP() {
- return (int)3L;
- }
- public static int N_STRIP() {
- return (int)4L;
- }
- public static int N_AX25() {
- return (int)5L;
- }
- public static int N_X25() {
- return (int)6L;
- }
- public static int N_6PACK() {
- return (int)7L;
- }
- public static int N_MASC() {
- return (int)8L;
- }
- public static int N_R3964() {
- return (int)9L;
- }
- public static int N_PROFIBUS_FDL() {
- return (int)10L;
- }
- public static int N_IRDA() {
- return (int)11L;
- }
- public static int N_SMSBLOCK() {
- return (int)12L;
- }
- public static int N_HDLC() {
- return (int)13L;
- }
- public static int N_SYNC_PPP() {
- return (int)14L;
- }
- public static int N_HCI() {
- return (int)15L;
- }
- public static int CERASE() {
- return (int)127L;
- }
- public static int CMIN() {
- return (int)1L;
- }
- public static int CQUIT() {
- return (int)28L;
- }
- public static int CTIME() {
- return (int)0L;
- }
public static MethodHandle ioctl$MH() {
return RuntimeHelper.requireNonNull(constants$0.ioctl$MH,"ioctl");
}
@@ -606,153 +27,6 @@ public static int ioctl ( int __fd, long __request, Object... x2) {
throw new AssertionError("should not reach here", ex$);
}
}
- public static long _POSIX_C_SOURCE() {
- return 200809L;
- }
- public static int __TIMESIZE() {
- return (int)64L;
- }
- public static long __STDC_IEC_60559_BFP__() {
- return 201404L;
- }
- public static long __STDC_IEC_60559_COMPLEX__() {
- return 201404L;
- }
- public static long __STDC_ISO_10646__() {
- return 201706L;
- }
- public static int _IOC_NRMASK() {
- return (int)255L;
- }
- public static int _IOC_TYPEMASK() {
- return (int)255L;
- }
- public static int _IOC_SIZEMASK() {
- return (int)16383L;
- }
- public static int _IOC_DIRMASK() {
- return (int)3L;
- }
- public static int _IOC_TYPESHIFT() {
- return (int)8L;
- }
- public static int _IOC_SIZESHIFT() {
- return (int)16L;
- }
- public static int _IOC_DIRSHIFT() {
- return (int)30L;
- }
- public static int _IOC_NONE() {
- return (int)0L;
- }
- public static int _IOC_WRITE() {
- return (int)1L;
- }
- public static int _IOC_READ() {
- return (int)2L;
- }
- public static int IOC_IN() {
- return (int)1073741824L;
- }
- public static int IOC_OUT() {
- return (int)2147483648L;
- }
- public static int IOC_INOUT() {
- return (int)3221225472L;
- }
- public static int IOCSIZE_MASK() {
- return (int)1073676288L;
- }
- public static int IOCSIZE_SHIFT() {
- return (int)16L;
- }
- public static int TIOCINQ() {
- return (int)21531L;
- }
- public static long TIOCGPTN() {
- return 2147767344L;
- }
- public static long TIOCSPTLCK() {
- return 1074025521L;
- }
- public static long TIOCGDEV() {
- return 2147767346L;
- }
- public static long TIOCSIG() {
- return 1074025526L;
- }
- public static long TIOCGPKT() {
- return 2147767352L;
- }
- public static long TIOCGPTLCK() {
- return 2147767353L;
- }
- public static long TIOCGEXCL() {
- return 2147767360L;
- }
- public static int TIOCGPTPEER() {
- return (int)21569L;
- }
- public static int SIOGIFINDEX() {
- return (int)35123L;
- }
- public static int TIOCM_CD() {
- return (int)64L;
- }
- public static int TIOCM_RI() {
- return (int)128L;
- }
- public static int CEOF() {
- return (int)4L;
- }
- public static int CEOL() {
- return (int)0L;
- }
- public static int CINTR() {
- return (int)3L;
- }
- public static int CSTATUS() {
- return (int)0L;
- }
- public static int CKILL() {
- return (int)21L;
- }
- public static int CSUSP() {
- return (int)26L;
- }
- public static int CDSUSP() {
- return (int)25L;
- }
- public static int CSTART() {
- return (int)17L;
- }
- public static int CSTOP() {
- return (int)19L;
- }
- public static int CLNEXT() {
- return (int)22L;
- }
- public static int CDISCARD() {
- return (int)15L;
- }
- public static int CWERASE() {
- return (int)23L;
- }
- public static int CREPRINT() {
- return (int)18L;
- }
- public static int CEOT() {
- return (int)4L;
- }
- public static int CBRK() {
- return (int)0L;
- }
- public static int CRPRNT() {
- return (int)18L;
- }
- public static int CFLUSH() {
- return (int)15L;
- }
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/termio.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/termio.java
deleted file mode 100644
index 500ef096..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/termio.java
+++ /dev/null
@@ -1,112 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.ioctl;
-
-import java.lang.foreign.*;
-import java.lang.invoke.VarHandle;
-public class termio {
-
- static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
- Constants$root.C_SHORT$LAYOUT.withName("c_iflag"),
- Constants$root.C_SHORT$LAYOUT.withName("c_oflag"),
- Constants$root.C_SHORT$LAYOUT.withName("c_cflag"),
- Constants$root.C_SHORT$LAYOUT.withName("c_lflag"),
- Constants$root.C_CHAR$LAYOUT.withName("c_line"),
- MemoryLayout.sequenceLayout(8, Constants$root.C_CHAR$LAYOUT).withName("c_cc"),
- MemoryLayout.paddingLayout(8)
- ).withName("termio");
- public static MemoryLayout $LAYOUT() {
- return termio.$struct$LAYOUT;
- }
- static final VarHandle c_iflag$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("c_iflag"));
- public static VarHandle c_iflag$VH() {
- return termio.c_iflag$VH;
- }
- public static short c_iflag$get(MemorySegment seg) {
- return (short)termio.c_iflag$VH.get(seg);
- }
- public static void c_iflag$set( MemorySegment seg, short x) {
- termio.c_iflag$VH.set(seg, x);
- }
- public static short c_iflag$get(MemorySegment seg, long index) {
- return (short)termio.c_iflag$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void c_iflag$set(MemorySegment seg, long index, short x) {
- termio.c_iflag$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle c_oflag$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("c_oflag"));
- public static VarHandle c_oflag$VH() {
- return termio.c_oflag$VH;
- }
- public static short c_oflag$get(MemorySegment seg) {
- return (short)termio.c_oflag$VH.get(seg);
- }
- public static void c_oflag$set( MemorySegment seg, short x) {
- termio.c_oflag$VH.set(seg, x);
- }
- public static short c_oflag$get(MemorySegment seg, long index) {
- return (short)termio.c_oflag$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void c_oflag$set(MemorySegment seg, long index, short x) {
- termio.c_oflag$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle c_cflag$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("c_cflag"));
- public static VarHandle c_cflag$VH() {
- return termio.c_cflag$VH;
- }
- public static short c_cflag$get(MemorySegment seg) {
- return (short)termio.c_cflag$VH.get(seg);
- }
- public static void c_cflag$set( MemorySegment seg, short x) {
- termio.c_cflag$VH.set(seg, x);
- }
- public static short c_cflag$get(MemorySegment seg, long index) {
- return (short)termio.c_cflag$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void c_cflag$set(MemorySegment seg, long index, short x) {
- termio.c_cflag$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle c_lflag$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("c_lflag"));
- public static VarHandle c_lflag$VH() {
- return termio.c_lflag$VH;
- }
- public static short c_lflag$get(MemorySegment seg) {
- return (short)termio.c_lflag$VH.get(seg);
- }
- public static void c_lflag$set( MemorySegment seg, short x) {
- termio.c_lflag$VH.set(seg, x);
- }
- public static short c_lflag$get(MemorySegment seg, long index) {
- return (short)termio.c_lflag$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void c_lflag$set(MemorySegment seg, long index, short x) {
- termio.c_lflag$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle c_line$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("c_line"));
- public static VarHandle c_line$VH() {
- return termio.c_line$VH;
- }
- public static byte c_line$get(MemorySegment seg) {
- return (byte)termio.c_line$VH.get(seg);
- }
- public static void c_line$set( MemorySegment seg, byte x) {
- termio.c_line$VH.set(seg, x);
- }
- public static byte c_line$get(MemorySegment seg, long index) {
- return (byte)termio.c_line$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void c_line$set(MemorySegment seg, long index, byte x) {
- termio.c_line$VH.set(seg.asSlice(index*sizeof()), x);
- }
- public static MemorySegment c_cc$slice(MemorySegment seg) {
- return seg.asSlice(9, 8);
- }
- public static long sizeof() { return $LAYOUT().byteSize(); }
- public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
- public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
- return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
- }
- public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/winsize.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/winsize.java
deleted file mode 100644
index d05924c2..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/ioctl/winsize.java
+++ /dev/null
@@ -1,90 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.ioctl;
-
-import java.lang.foreign.*;
-import java.lang.invoke.VarHandle;
-public class winsize {
-
- static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
- Constants$root.C_SHORT$LAYOUT.withName("ws_row"),
- Constants$root.C_SHORT$LAYOUT.withName("ws_col"),
- Constants$root.C_SHORT$LAYOUT.withName("ws_xpixel"),
- Constants$root.C_SHORT$LAYOUT.withName("ws_ypixel")
- ).withName("winsize");
- public static MemoryLayout $LAYOUT() {
- return winsize.$struct$LAYOUT;
- }
- static final VarHandle ws_row$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("ws_row"));
- public static VarHandle ws_row$VH() {
- return winsize.ws_row$VH;
- }
- public static short ws_row$get(MemorySegment seg) {
- return (short)winsize.ws_row$VH.get(seg);
- }
- public static void ws_row$set( MemorySegment seg, short x) {
- winsize.ws_row$VH.set(seg, x);
- }
- public static short ws_row$get(MemorySegment seg, long index) {
- return (short)winsize.ws_row$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void ws_row$set(MemorySegment seg, long index, short x) {
- winsize.ws_row$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle ws_col$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("ws_col"));
- public static VarHandle ws_col$VH() {
- return winsize.ws_col$VH;
- }
- public static short ws_col$get(MemorySegment seg) {
- return (short)winsize.ws_col$VH.get(seg);
- }
- public static void ws_col$set( MemorySegment seg, short x) {
- winsize.ws_col$VH.set(seg, x);
- }
- public static short ws_col$get(MemorySegment seg, long index) {
- return (short)winsize.ws_col$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void ws_col$set(MemorySegment seg, long index, short x) {
- winsize.ws_col$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle ws_xpixel$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("ws_xpixel"));
- public static VarHandle ws_xpixel$VH() {
- return winsize.ws_xpixel$VH;
- }
- public static short ws_xpixel$get(MemorySegment seg) {
- return (short)winsize.ws_xpixel$VH.get(seg);
- }
- public static void ws_xpixel$set( MemorySegment seg, short x) {
- winsize.ws_xpixel$VH.set(seg, x);
- }
- public static short ws_xpixel$get(MemorySegment seg, long index) {
- return (short)winsize.ws_xpixel$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void ws_xpixel$set(MemorySegment seg, long index, short x) {
- winsize.ws_xpixel$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle ws_ypixel$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("ws_ypixel"));
- public static VarHandle ws_ypixel$VH() {
- return winsize.ws_ypixel$VH;
- }
- public static short ws_ypixel$get(MemorySegment seg) {
- return (short)winsize.ws_ypixel$VH.get(seg);
- }
- public static void ws_ypixel$set( MemorySegment seg, short x) {
- winsize.ws_ypixel$VH.set(seg, x);
- }
- public static short ws_ypixel$get(MemorySegment seg, long index) {
- return (short)winsize.ws_ypixel$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void ws_ypixel$set(MemorySegment seg, long index, short x) {
- winsize.ws_ypixel$VH.set(seg.asSlice(index*sizeof()), x);
- }
- public static long sizeof() { return $LAYOUT().byteSize(); }
- public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
- public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
- return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
- }
- public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/__fsid_t.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/__fsid_t.java
deleted file mode 100644
index 990f9f6b..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/__fsid_t.java
+++ /dev/null
@@ -1,25 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.unistd;
-
-import java.lang.foreign.*;
-public class __fsid_t {
-
- static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
- MemoryLayout.sequenceLayout(2, Constants$root.C_INT$LAYOUT).withName("__val")
- );
- public static MemoryLayout $LAYOUT() {
- return __fsid_t.$struct$LAYOUT;
- }
- public static MemorySegment __val$slice(MemorySegment seg) {
- return seg.asSlice(0, 8);
- }
- public static long sizeof() { return $LAYOUT().byteSize(); }
- public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
- public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
- return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
- }
- public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$0.java
index 4535a379..26995ca4 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$0.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$0.java
@@ -6,33 +6,6 @@
import java.lang.invoke.MethodHandle;
class constants$0 {
- static final FunctionDescriptor access$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle access$MH = RuntimeHelper.downcallHandle(
- "access",
- constants$0.access$FUNC
- );
- static final FunctionDescriptor faccessat$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle faccessat$MH = RuntimeHelper.downcallHandle(
- "faccessat",
- constants$0.faccessat$FUNC
- );
- static final FunctionDescriptor lseek$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle lseek$MH = RuntimeHelper.downcallHandle(
- "lseek",
- constants$0.lseek$FUNC
- );
static final FunctionDescriptor close$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
Constants$root.C_INT$LAYOUT
);
@@ -40,22 +13,6 @@ class constants$0 {
"close",
constants$0.close$FUNC
);
- static final FunctionDescriptor closefrom$FUNC = FunctionDescriptor.ofVoid(
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle closefrom$MH = RuntimeHelper.downcallHandle(
- "closefrom",
- constants$0.closefrom$FUNC
- );
- static final FunctionDescriptor read$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT
- );
- static final MethodHandle read$MH = RuntimeHelper.downcallHandle(
- "read",
- constants$0.read$FUNC
- );
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$1.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$1.java
deleted file mode 100644
index 0cc4fe56..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$1.java
+++ /dev/null
@@ -1,61 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.unistd;
-
-import java.lang.foreign.FunctionDescriptor;
-import java.lang.invoke.MethodHandle;
-class constants$1 {
-
- static final FunctionDescriptor write$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT
- );
- static final MethodHandle write$MH = RuntimeHelper.downcallHandle(
- "write",
- constants$1.write$FUNC
- );
- static final FunctionDescriptor pread$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT
- );
- static final MethodHandle pread$MH = RuntimeHelper.downcallHandle(
- "pread",
- constants$1.pread$FUNC
- );
- static final FunctionDescriptor pwrite$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT
- );
- static final MethodHandle pwrite$MH = RuntimeHelper.downcallHandle(
- "pwrite",
- constants$1.pwrite$FUNC
- );
- static final FunctionDescriptor pipe$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT
- );
- static final MethodHandle pipe$MH = RuntimeHelper.downcallHandle(
- "pipe",
- constants$1.pipe$FUNC
- );
- static final FunctionDescriptor alarm$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle alarm$MH = RuntimeHelper.downcallHandle(
- "alarm",
- constants$1.alarm$FUNC
- );
- static final FunctionDescriptor sleep$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle sleep$MH = RuntimeHelper.downcallHandle(
- "sleep",
- constants$1.sleep$FUNC
- );
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$10.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$10.java
deleted file mode 100644
index 64c7caab..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$10.java
+++ /dev/null
@@ -1,52 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.unistd;
-
-import java.lang.foreign.FunctionDescriptor;
-import java.lang.invoke.MethodHandle;
-class constants$10 {
-
- static final FunctionDescriptor vfork$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
- static final MethodHandle vfork$MH = RuntimeHelper.downcallHandle(
- "vfork",
- constants$10.vfork$FUNC
- );
- static final FunctionDescriptor ttyname$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle ttyname$MH = RuntimeHelper.downcallHandle(
- "ttyname",
- constants$10.ttyname$FUNC
- );
- static final FunctionDescriptor ttyname_r$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT
- );
- static final MethodHandle ttyname_r$MH = RuntimeHelper.downcallHandle(
- "ttyname_r",
- constants$10.ttyname_r$FUNC
- );
- static final FunctionDescriptor isatty$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle isatty$MH = RuntimeHelper.downcallHandle(
- "isatty",
- constants$10.isatty$FUNC
- );
- static final FunctionDescriptor ttyslot$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
- static final MethodHandle ttyslot$MH = RuntimeHelper.downcallHandle(
- "ttyslot",
- constants$10.ttyslot$FUNC
- );
- static final FunctionDescriptor link$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_POINTER$LAYOUT
- );
- static final MethodHandle link$MH = RuntimeHelper.downcallHandle(
- "link",
- constants$10.link$FUNC
- );
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$11.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$11.java
deleted file mode 100644
index 4dc75380..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$11.java
+++ /dev/null
@@ -1,65 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.unistd;
-
-import java.lang.foreign.FunctionDescriptor;
-import java.lang.invoke.MethodHandle;
-class constants$11 {
-
- static final FunctionDescriptor linkat$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle linkat$MH = RuntimeHelper.downcallHandle(
- "linkat",
- constants$11.linkat$FUNC
- );
- static final FunctionDescriptor symlink$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_POINTER$LAYOUT
- );
- static final MethodHandle symlink$MH = RuntimeHelper.downcallHandle(
- "symlink",
- constants$11.symlink$FUNC
- );
- static final FunctionDescriptor readlink$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT
- );
- static final MethodHandle readlink$MH = RuntimeHelper.downcallHandle(
- "readlink",
- constants$11.readlink$FUNC
- );
- static final FunctionDescriptor symlinkat$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT
- );
- static final MethodHandle symlinkat$MH = RuntimeHelper.downcallHandle(
- "symlinkat",
- constants$11.symlinkat$FUNC
- );
- static final FunctionDescriptor readlinkat$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT
- );
- static final MethodHandle readlinkat$MH = RuntimeHelper.downcallHandle(
- "readlinkat",
- constants$11.readlinkat$FUNC
- );
- static final FunctionDescriptor unlink$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT
- );
- static final MethodHandle unlink$MH = RuntimeHelper.downcallHandle(
- "unlink",
- constants$11.unlink$FUNC
- );
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$12.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$12.java
deleted file mode 100644
index b73d5e46..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$12.java
+++ /dev/null
@@ -1,55 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.unistd;
-
-import java.lang.foreign.FunctionDescriptor;
-import java.lang.invoke.MethodHandle;
-class constants$12 {
-
- static final FunctionDescriptor unlinkat$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle unlinkat$MH = RuntimeHelper.downcallHandle(
- "unlinkat",
- constants$12.unlinkat$FUNC
- );
- static final FunctionDescriptor rmdir$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT
- );
- static final MethodHandle rmdir$MH = RuntimeHelper.downcallHandle(
- "rmdir",
- constants$12.rmdir$FUNC
- );
- static final FunctionDescriptor tcgetpgrp$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle tcgetpgrp$MH = RuntimeHelper.downcallHandle(
- "tcgetpgrp",
- constants$12.tcgetpgrp$FUNC
- );
- static final FunctionDescriptor tcsetpgrp$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle tcsetpgrp$MH = RuntimeHelper.downcallHandle(
- "tcsetpgrp",
- constants$12.tcsetpgrp$FUNC
- );
- static final FunctionDescriptor getlogin$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT);
- static final MethodHandle getlogin$MH = RuntimeHelper.downcallHandle(
- "getlogin",
- constants$12.getlogin$FUNC
- );
- static final FunctionDescriptor getlogin_r$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT
- );
- static final MethodHandle getlogin_r$MH = RuntimeHelper.downcallHandle(
- "getlogin_r",
- constants$12.getlogin_r$FUNC
- );
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$13.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$13.java
deleted file mode 100644
index bab872f5..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$13.java
+++ /dev/null
@@ -1,44 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.unistd;
-
-import java.lang.foreign.FunctionDescriptor;
-import java.lang.foreign.MemorySegment;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.VarHandle;
-
-import static java.lang.foreign.ValueLayout.OfAddress;
-import static java.lang.foreign.ValueLayout.OfInt;
-class constants$13 {
-
- static final FunctionDescriptor setlogin$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT
- );
- static final MethodHandle setlogin$MH = RuntimeHelper.downcallHandle(
- "setlogin",
- constants$13.setlogin$FUNC
- );
- static final OfAddress optarg$LAYOUT = Constants$root.C_POINTER$LAYOUT;
- static final VarHandle optarg$VH = constants$13.optarg$LAYOUT.varHandle();
- static final MemorySegment optarg$SEGMENT = RuntimeHelper.lookupGlobalVariable("optarg", constants$13.optarg$LAYOUT);
- static final OfInt optind$LAYOUT = Constants$root.C_INT$LAYOUT;
- static final VarHandle optind$VH = constants$13.optind$LAYOUT.varHandle();
- static final MemorySegment optind$SEGMENT = RuntimeHelper.lookupGlobalVariable("optind", constants$13.optind$LAYOUT);
- static final OfInt opterr$LAYOUT = Constants$root.C_INT$LAYOUT;
- static final VarHandle opterr$VH = constants$13.opterr$LAYOUT.varHandle();
- static final MemorySegment opterr$SEGMENT = RuntimeHelper.lookupGlobalVariable("opterr", constants$13.opterr$LAYOUT);
- static final OfInt optopt$LAYOUT = Constants$root.C_INT$LAYOUT;
- static final VarHandle optopt$VH = constants$13.optopt$LAYOUT.varHandle();
- static final MemorySegment optopt$SEGMENT = RuntimeHelper.lookupGlobalVariable("optopt", constants$13.optopt$LAYOUT);
- static final FunctionDescriptor getopt$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_POINTER$LAYOUT
- );
- static final MethodHandle getopt$MH = RuntimeHelper.downcallHandle(
- "getopt",
- constants$13.getopt$FUNC
- );
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$14.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$14.java
deleted file mode 100644
index 68193487..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$14.java
+++ /dev/null
@@ -1,55 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.unistd;
-
-import java.lang.foreign.FunctionDescriptor;
-import java.lang.invoke.MethodHandle;
-class constants$14 {
-
- static final FunctionDescriptor gethostname$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT
- );
- static final MethodHandle gethostname$MH = RuntimeHelper.downcallHandle(
- "gethostname",
- constants$14.gethostname$FUNC
- );
- static final FunctionDescriptor sethostname$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT
- );
- static final MethodHandle sethostname$MH = RuntimeHelper.downcallHandle(
- "sethostname",
- constants$14.sethostname$FUNC
- );
- static final FunctionDescriptor sethostid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT
- );
- static final MethodHandle sethostid$MH = RuntimeHelper.downcallHandle(
- "sethostid",
- constants$14.sethostid$FUNC
- );
- static final FunctionDescriptor getdomainname$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT
- );
- static final MethodHandle getdomainname$MH = RuntimeHelper.downcallHandle(
- "getdomainname",
- constants$14.getdomainname$FUNC
- );
- static final FunctionDescriptor setdomainname$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT
- );
- static final MethodHandle setdomainname$MH = RuntimeHelper.downcallHandle(
- "setdomainname",
- constants$14.setdomainname$FUNC
- );
- static final FunctionDescriptor vhangup$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
- static final MethodHandle vhangup$MH = RuntimeHelper.downcallHandle(
- "vhangup",
- constants$14.vhangup$FUNC
- );
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$15.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$15.java
deleted file mode 100644
index 432d2995..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$15.java
+++ /dev/null
@@ -1,50 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.unistd;
-
-import java.lang.foreign.FunctionDescriptor;
-import java.lang.invoke.MethodHandle;
-class constants$15 {
-
- static final FunctionDescriptor revoke$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT
- );
- static final MethodHandle revoke$MH = RuntimeHelper.downcallHandle(
- "revoke",
- constants$15.revoke$FUNC
- );
- static final FunctionDescriptor profil$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle profil$MH = RuntimeHelper.downcallHandle(
- "profil",
- constants$15.profil$FUNC
- );
- static final FunctionDescriptor acct$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT
- );
- static final MethodHandle acct$MH = RuntimeHelper.downcallHandle(
- "acct",
- constants$15.acct$FUNC
- );
- static final FunctionDescriptor getusershell$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT);
- static final MethodHandle getusershell$MH = RuntimeHelper.downcallHandle(
- "getusershell",
- constants$15.getusershell$FUNC
- );
- static final FunctionDescriptor endusershell$FUNC = FunctionDescriptor.ofVoid();
- static final MethodHandle endusershell$MH = RuntimeHelper.downcallHandle(
- "endusershell",
- constants$15.endusershell$FUNC
- );
- static final FunctionDescriptor setusershell$FUNC = FunctionDescriptor.ofVoid();
- static final MethodHandle setusershell$MH = RuntimeHelper.downcallHandle(
- "setusershell",
- constants$15.setusershell$FUNC
- );
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$16.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$16.java
deleted file mode 100644
index 2373648b..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$16.java
+++ /dev/null
@@ -1,50 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.unistd;
-
-import java.lang.foreign.FunctionDescriptor;
-import java.lang.invoke.MethodHandle;
-class constants$16 {
-
- static final FunctionDescriptor daemon$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle daemon$MH = RuntimeHelper.downcallHandle(
- "daemon",
- constants$16.daemon$FUNC
- );
- static final FunctionDescriptor chroot$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT
- );
- static final MethodHandle chroot$MH = RuntimeHelper.downcallHandle(
- "chroot",
- constants$16.chroot$FUNC
- );
- static final FunctionDescriptor getpass$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_POINTER$LAYOUT
- );
- static final MethodHandle getpass$MH = RuntimeHelper.downcallHandle(
- "getpass",
- constants$16.getpass$FUNC
- );
- static final FunctionDescriptor fsync$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle fsync$MH = RuntimeHelper.downcallHandle(
- "fsync",
- constants$16.fsync$FUNC
- );
- static final FunctionDescriptor gethostid$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT);
- static final MethodHandle gethostid$MH = RuntimeHelper.downcallHandle(
- "gethostid",
- constants$16.gethostid$FUNC
- );
- static final FunctionDescriptor sync$FUNC = FunctionDescriptor.ofVoid();
- static final MethodHandle sync$MH = RuntimeHelper.downcallHandle(
- "sync",
- constants$16.sync$FUNC
- );
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$17.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$17.java
deleted file mode 100644
index 9e76f6e5..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$17.java
+++ /dev/null
@@ -1,51 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.unistd;
-
-import java.lang.foreign.FunctionDescriptor;
-import java.lang.invoke.MethodHandle;
-class constants$17 {
-
- static final FunctionDescriptor getpagesize$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
- static final MethodHandle getpagesize$MH = RuntimeHelper.downcallHandle(
- "getpagesize",
- constants$17.getpagesize$FUNC
- );
- static final FunctionDescriptor getdtablesize$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
- static final MethodHandle getdtablesize$MH = RuntimeHelper.downcallHandle(
- "getdtablesize",
- constants$17.getdtablesize$FUNC
- );
- static final FunctionDescriptor truncate$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT
- );
- static final MethodHandle truncate$MH = RuntimeHelper.downcallHandle(
- "truncate",
- constants$17.truncate$FUNC
- );
- static final FunctionDescriptor ftruncate$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT
- );
- static final MethodHandle ftruncate$MH = RuntimeHelper.downcallHandle(
- "ftruncate",
- constants$17.ftruncate$FUNC
- );
- static final FunctionDescriptor brk$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT
- );
- static final MethodHandle brk$MH = RuntimeHelper.downcallHandle(
- "brk",
- constants$17.brk$FUNC
- );
- static final FunctionDescriptor sbrk$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT
- );
- static final MethodHandle sbrk$MH = RuntimeHelper.downcallHandle(
- "sbrk",
- constants$17.sbrk$FUNC
- );
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$18.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$18.java
deleted file mode 100644
index 794239b3..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$18.java
+++ /dev/null
@@ -1,52 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.unistd;
-
-import java.lang.foreign.FunctionDescriptor;
-import java.lang.foreign.MemorySegment;
-import java.lang.invoke.MethodHandle;
-class constants$18 {
-
- static final FunctionDescriptor syscall$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT
- );
- static final MethodHandle syscall$MH = RuntimeHelper.downcallHandleVariadic(
- "syscall",
- constants$18.syscall$FUNC
- );
- static final FunctionDescriptor lockf$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT
- );
- static final MethodHandle lockf$MH = RuntimeHelper.downcallHandle(
- "lockf",
- constants$18.lockf$FUNC
- );
- static final FunctionDescriptor fdatasync$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle fdatasync$MH = RuntimeHelper.downcallHandle(
- "fdatasync",
- constants$18.fdatasync$FUNC
- );
- static final FunctionDescriptor crypt$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_POINTER$LAYOUT
- );
- static final MethodHandle crypt$MH = RuntimeHelper.downcallHandle(
- "crypt",
- constants$18.crypt$FUNC
- );
- static final FunctionDescriptor getentropy$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT
- );
- static final MethodHandle getentropy$MH = RuntimeHelper.downcallHandle(
- "getentropy",
- constants$18.getentropy$FUNC
- );
- static final MemorySegment __ILP32_OFF32_CFLAGS$SEGMENT = RuntimeHelper.CONSTANT_ALLOCATOR.allocateUtf8String("-m32");
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$19.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$19.java
deleted file mode 100644
index a33d0a5c..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$19.java
+++ /dev/null
@@ -1,17 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.unistd;
-
-import java.lang.foreign.MemoryAddress;
-import java.lang.foreign.MemorySegment;
-class constants$19 {
-
- static final MemorySegment __ILP32_OFF32_LDFLAGS$SEGMENT = RuntimeHelper.CONSTANT_ALLOCATOR.allocateUtf8String("-m32");
- static final MemorySegment __ILP32_OFFBIG_CFLAGS$SEGMENT = RuntimeHelper.CONSTANT_ALLOCATOR.allocateUtf8String("-m32 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64");
- static final MemorySegment __ILP32_OFFBIG_LDFLAGS$SEGMENT = RuntimeHelper.CONSTANT_ALLOCATOR.allocateUtf8String("-m32");
- static final MemorySegment __LP64_OFF64_CFLAGS$SEGMENT = RuntimeHelper.CONSTANT_ALLOCATOR.allocateUtf8String("-m64");
- static final MemorySegment __LP64_OFF64_LDFLAGS$SEGMENT = RuntimeHelper.CONSTANT_ALLOCATOR.allocateUtf8String("-m64");
- static final MemoryAddress NULL$ADDR = MemoryAddress.ofLong(0L);
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$2.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$2.java
deleted file mode 100644
index df7185a3..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$2.java
+++ /dev/null
@@ -1,58 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.unistd;
-
-import java.lang.foreign.FunctionDescriptor;
-import java.lang.invoke.MethodHandle;
-class constants$2 {
-
- static final FunctionDescriptor ualarm$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle ualarm$MH = RuntimeHelper.downcallHandle(
- "ualarm",
- constants$2.ualarm$FUNC
- );
- static final FunctionDescriptor usleep$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle usleep$MH = RuntimeHelper.downcallHandle(
- "usleep",
- constants$2.usleep$FUNC
- );
- static final FunctionDescriptor pause$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
- static final MethodHandle pause$MH = RuntimeHelper.downcallHandle(
- "pause",
- constants$2.pause$FUNC
- );
- static final FunctionDescriptor chown$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle chown$MH = RuntimeHelper.downcallHandle(
- "chown",
- constants$2.chown$FUNC
- );
- static final FunctionDescriptor fchown$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle fchown$MH = RuntimeHelper.downcallHandle(
- "fchown",
- constants$2.fchown$FUNC
- );
- static final FunctionDescriptor lchown$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle lchown$MH = RuntimeHelper.downcallHandle(
- "lchown",
- constants$2.lchown$FUNC
- );
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$3.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$3.java
deleted file mode 100644
index 81b2b5d6..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$3.java
+++ /dev/null
@@ -1,58 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.unistd;
-
-import java.lang.foreign.FunctionDescriptor;
-import java.lang.invoke.MethodHandle;
-class constants$3 {
-
- static final FunctionDescriptor fchownat$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle fchownat$MH = RuntimeHelper.downcallHandle(
- "fchownat",
- constants$3.fchownat$FUNC
- );
- static final FunctionDescriptor chdir$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT
- );
- static final MethodHandle chdir$MH = RuntimeHelper.downcallHandle(
- "chdir",
- constants$3.chdir$FUNC
- );
- static final FunctionDescriptor fchdir$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle fchdir$MH = RuntimeHelper.downcallHandle(
- "fchdir",
- constants$3.fchdir$FUNC
- );
- static final FunctionDescriptor getcwd$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT
- );
- static final MethodHandle getcwd$MH = RuntimeHelper.downcallHandle(
- "getcwd",
- constants$3.getcwd$FUNC
- );
- static final FunctionDescriptor getwd$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_POINTER$LAYOUT
- );
- static final MethodHandle getwd$MH = RuntimeHelper.downcallHandle(
- "getwd",
- constants$3.getwd$FUNC
- );
- static final FunctionDescriptor dup$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle dup$MH = RuntimeHelper.downcallHandle(
- "dup",
- constants$3.dup$FUNC
- );
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$4.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$4.java
deleted file mode 100644
index ec8066b8..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$4.java
+++ /dev/null
@@ -1,60 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.unistd;
-
-import java.lang.foreign.FunctionDescriptor;
-import java.lang.foreign.MemorySegment;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.VarHandle;
-
-import static java.lang.foreign.ValueLayout.OfAddress;
-class constants$4 {
-
- static final FunctionDescriptor dup2$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle dup2$MH = RuntimeHelper.downcallHandle(
- "dup2",
- constants$4.dup2$FUNC
- );
- static final OfAddress __environ$LAYOUT = Constants$root.C_POINTER$LAYOUT;
- static final VarHandle __environ$VH = constants$4.__environ$LAYOUT.varHandle();
- static final MemorySegment __environ$SEGMENT = RuntimeHelper.lookupGlobalVariable("__environ", constants$4.__environ$LAYOUT);
- static final FunctionDescriptor execve$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_POINTER$LAYOUT
- );
- static final MethodHandle execve$MH = RuntimeHelper.downcallHandle(
- "execve",
- constants$4.execve$FUNC
- );
- static final FunctionDescriptor fexecve$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_POINTER$LAYOUT
- );
- static final MethodHandle fexecve$MH = RuntimeHelper.downcallHandle(
- "fexecve",
- constants$4.fexecve$FUNC
- );
- static final FunctionDescriptor execv$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_POINTER$LAYOUT
- );
- static final MethodHandle execv$MH = RuntimeHelper.downcallHandle(
- "execv",
- constants$4.execv$FUNC
- );
- static final FunctionDescriptor execle$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_POINTER$LAYOUT
- );
- static final MethodHandle execle$MH = RuntimeHelper.downcallHandleVariadic(
- "execle",
- constants$4.execle$FUNC
- );
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$5.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$5.java
deleted file mode 100644
index 973d637c..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$5.java
+++ /dev/null
@@ -1,57 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.unistd;
-
-import java.lang.foreign.FunctionDescriptor;
-import java.lang.invoke.MethodHandle;
-class constants$5 {
-
- static final FunctionDescriptor execl$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_POINTER$LAYOUT
- );
- static final MethodHandle execl$MH = RuntimeHelper.downcallHandleVariadic(
- "execl",
- constants$5.execl$FUNC
- );
- static final FunctionDescriptor execvp$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_POINTER$LAYOUT
- );
- static final MethodHandle execvp$MH = RuntimeHelper.downcallHandle(
- "execvp",
- constants$5.execvp$FUNC
- );
- static final FunctionDescriptor execlp$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_POINTER$LAYOUT
- );
- static final MethodHandle execlp$MH = RuntimeHelper.downcallHandleVariadic(
- "execlp",
- constants$5.execlp$FUNC
- );
- static final FunctionDescriptor nice$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle nice$MH = RuntimeHelper.downcallHandle(
- "nice",
- constants$5.nice$FUNC
- );
- static final FunctionDescriptor _exit$FUNC = FunctionDescriptor.ofVoid(
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle _exit$MH = RuntimeHelper.downcallHandle(
- "_exit",
- constants$5._exit$FUNC
- );
- static final FunctionDescriptor pathconf$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle pathconf$MH = RuntimeHelper.downcallHandle(
- "pathconf",
- constants$5.pathconf$FUNC
- );
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$6.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$6.java
deleted file mode 100644
index da5a5a31..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$6.java
+++ /dev/null
@@ -1,50 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.unistd;
-
-import java.lang.foreign.FunctionDescriptor;
-import java.lang.invoke.MethodHandle;
-class constants$6 {
-
- static final FunctionDescriptor fpathconf$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle fpathconf$MH = RuntimeHelper.downcallHandle(
- "fpathconf",
- constants$6.fpathconf$FUNC
- );
- static final FunctionDescriptor sysconf$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle sysconf$MH = RuntimeHelper.downcallHandle(
- "sysconf",
- constants$6.sysconf$FUNC
- );
- static final FunctionDescriptor confstr$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_LONG_LONG$LAYOUT
- );
- static final MethodHandle confstr$MH = RuntimeHelper.downcallHandle(
- "confstr",
- constants$6.confstr$FUNC
- );
- static final FunctionDescriptor getpid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
- static final MethodHandle getpid$MH = RuntimeHelper.downcallHandle(
- "getpid",
- constants$6.getpid$FUNC
- );
- static final FunctionDescriptor getppid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
- static final MethodHandle getppid$MH = RuntimeHelper.downcallHandle(
- "getppid",
- constants$6.getppid$FUNC
- );
- static final FunctionDescriptor getpgrp$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
- static final MethodHandle getpgrp$MH = RuntimeHelper.downcallHandle(
- "getpgrp",
- constants$6.getpgrp$FUNC
- );
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$7.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$7.java
deleted file mode 100644
index d08b63a9..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$7.java
+++ /dev/null
@@ -1,50 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.unistd;
-
-import java.lang.foreign.FunctionDescriptor;
-import java.lang.invoke.MethodHandle;
-class constants$7 {
-
- static final FunctionDescriptor __getpgid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle __getpgid$MH = RuntimeHelper.downcallHandle(
- "__getpgid",
- constants$7.__getpgid$FUNC
- );
- static final FunctionDescriptor getpgid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle getpgid$MH = RuntimeHelper.downcallHandle(
- "getpgid",
- constants$7.getpgid$FUNC
- );
- static final FunctionDescriptor setpgid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle setpgid$MH = RuntimeHelper.downcallHandle(
- "setpgid",
- constants$7.setpgid$FUNC
- );
- static final FunctionDescriptor setpgrp$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
- static final MethodHandle setpgrp$MH = RuntimeHelper.downcallHandle(
- "setpgrp",
- constants$7.setpgrp$FUNC
- );
- static final FunctionDescriptor setsid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
- static final MethodHandle setsid$MH = RuntimeHelper.downcallHandle(
- "setsid",
- constants$7.setsid$FUNC
- );
- static final FunctionDescriptor getsid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle getsid$MH = RuntimeHelper.downcallHandle(
- "getsid",
- constants$7.getsid$FUNC
- );
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$8.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$8.java
deleted file mode 100644
index a94fab3c..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$8.java
+++ /dev/null
@@ -1,46 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.unistd;
-
-import java.lang.foreign.FunctionDescriptor;
-import java.lang.invoke.MethodHandle;
-class constants$8 {
-
- static final FunctionDescriptor getuid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
- static final MethodHandle getuid$MH = RuntimeHelper.downcallHandle(
- "getuid",
- constants$8.getuid$FUNC
- );
- static final FunctionDescriptor geteuid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
- static final MethodHandle geteuid$MH = RuntimeHelper.downcallHandle(
- "geteuid",
- constants$8.geteuid$FUNC
- );
- static final FunctionDescriptor getgid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
- static final MethodHandle getgid$MH = RuntimeHelper.downcallHandle(
- "getgid",
- constants$8.getgid$FUNC
- );
- static final FunctionDescriptor getegid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
- static final MethodHandle getegid$MH = RuntimeHelper.downcallHandle(
- "getegid",
- constants$8.getegid$FUNC
- );
- static final FunctionDescriptor getgroups$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_POINTER$LAYOUT
- );
- static final MethodHandle getgroups$MH = RuntimeHelper.downcallHandle(
- "getgroups",
- constants$8.getgroups$FUNC
- );
- static final FunctionDescriptor setuid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle setuid$MH = RuntimeHelper.downcallHandle(
- "setuid",
- constants$8.setuid$FUNC
- );
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$9.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$9.java
deleted file mode 100644
index e4e65a59..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/constants$9.java
+++ /dev/null
@@ -1,53 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.unistd;
-
-import java.lang.foreign.FunctionDescriptor;
-import java.lang.invoke.MethodHandle;
-class constants$9 {
-
- static final FunctionDescriptor setreuid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle setreuid$MH = RuntimeHelper.downcallHandle(
- "setreuid",
- constants$9.setreuid$FUNC
- );
- static final FunctionDescriptor seteuid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle seteuid$MH = RuntimeHelper.downcallHandle(
- "seteuid",
- constants$9.seteuid$FUNC
- );
- static final FunctionDescriptor setgid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle setgid$MH = RuntimeHelper.downcallHandle(
- "setgid",
- constants$9.setgid$FUNC
- );
- static final FunctionDescriptor setregid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle setregid$MH = RuntimeHelper.downcallHandle(
- "setregid",
- constants$9.setregid$FUNC
- );
- static final FunctionDescriptor setegid$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle setegid$MH = RuntimeHelper.downcallHandle(
- "setegid",
- constants$9.setegid$FUNC
- );
- static final FunctionDescriptor fork$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT);
- static final MethodHandle fork$MH = RuntimeHelper.downcallHandle(
- "fork",
- constants$9.fork$FUNC
- );
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/unistd.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/unistd.java
index cf6b6b76..74045e41 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/unistd.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/unistd/unistd.java
@@ -2,12 +2,7 @@
package net.codecrete.usb.linux.gen.unistd;
-import java.lang.foreign.Addressable;
-import java.lang.foreign.MemoryAddress;
-import java.lang.foreign.MemoryLayout;
-import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
-import java.lang.invoke.VarHandle;
import static java.lang.foreign.ValueLayout.*;
public class unistd {
@@ -21,342 +16,6 @@ public class unistd {
public static OfFloat C_FLOAT = Constants$root.C_FLOAT$LAYOUT;
public static OfDouble C_DOUBLE = Constants$root.C_DOUBLE$LAYOUT;
public static OfAddress C_POINTER = Constants$root.C_POINTER$LAYOUT;
- public static int _UNISTD_H() {
- return (int)1L;
- }
- public static int _FEATURES_H() {
- return (int)1L;
- }
- public static int _DEFAULT_SOURCE() {
- return (int)1L;
- }
- public static int __GLIBC_USE_ISOC2X() {
- return (int)0L;
- }
- public static int __USE_ISOC11() {
- return (int)1L;
- }
- public static int __USE_ISOC99() {
- return (int)1L;
- }
- public static int __USE_ISOC95() {
- return (int)1L;
- }
- public static int __USE_POSIX_IMPLICITLY() {
- return (int)1L;
- }
- public static int _POSIX_SOURCE() {
- return (int)1L;
- }
- public static int __USE_POSIX() {
- return (int)1L;
- }
- public static int __USE_POSIX2() {
- return (int)1L;
- }
- public static int __USE_POSIX199309() {
- return (int)1L;
- }
- public static int __USE_POSIX199506() {
- return (int)1L;
- }
- public static int __USE_XOPEN2K() {
- return (int)1L;
- }
- public static int __USE_XOPEN2K8() {
- return (int)1L;
- }
- public static int _ATFILE_SOURCE() {
- return (int)1L;
- }
- public static int __WORDSIZE() {
- return (int)64L;
- }
- public static int __WORDSIZE_TIME64_COMPAT32() {
- return (int)1L;
- }
- public static int __SYSCALL_WORDSIZE() {
- return (int)64L;
- }
- public static int __USE_MISC() {
- return (int)1L;
- }
- public static int __USE_ATFILE() {
- return (int)1L;
- }
- public static int __USE_FORTIFY_LEVEL() {
- return (int)0L;
- }
- public static int __GLIBC_USE_DEPRECATED_GETS() {
- return (int)0L;
- }
- public static int __GLIBC_USE_DEPRECATED_SCANF() {
- return (int)0L;
- }
- public static int _STDC_PREDEF_H() {
- return (int)1L;
- }
- public static int __STDC_IEC_559__() {
- return (int)1L;
- }
- public static int __STDC_IEC_559_COMPLEX__() {
- return (int)1L;
- }
- public static int __GNU_LIBRARY__() {
- return (int)6L;
- }
- public static int __GLIBC__() {
- return (int)2L;
- }
- public static int __GLIBC_MINOR__() {
- return (int)35L;
- }
- public static int _SYS_CDEFS_H() {
- return (int)1L;
- }
- public static int __glibc_c99_flexarr_available() {
- return (int)1L;
- }
- public static int __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI() {
- return (int)0L;
- }
- public static int __HAVE_GENERIC_SELECTION() {
- return (int)1L;
- }
- public static int _XOPEN_VERSION() {
- return (int)700L;
- }
- public static int _XOPEN_XCU_VERSION() {
- return (int)4L;
- }
- public static int _XOPEN_XPG2() {
- return (int)1L;
- }
- public static int _XOPEN_XPG3() {
- return (int)1L;
- }
- public static int _XOPEN_XPG4() {
- return (int)1L;
- }
- public static int _XOPEN_UNIX() {
- return (int)1L;
- }
- public static int _XOPEN_ENH_I18N() {
- return (int)1L;
- }
- public static int _XOPEN_LEGACY() {
- return (int)1L;
- }
- public static int _BITS_POSIX_OPT_H() {
- return (int)1L;
- }
- public static int _POSIX_JOB_CONTROL() {
- return (int)1L;
- }
- public static int _POSIX_SAVED_IDS() {
- return (int)1L;
- }
- public static int _POSIX_CHOWN_RESTRICTED() {
- return (int)0L;
- }
- public static int _POSIX_NO_TRUNC() {
- return (int)1L;
- }
- public static int _XOPEN_REALTIME() {
- return (int)1L;
- }
- public static int _XOPEN_REALTIME_THREADS() {
- return (int)1L;
- }
- public static int _XOPEN_SHM() {
- return (int)1L;
- }
- public static int _POSIX_REENTRANT_FUNCTIONS() {
- return (int)1L;
- }
- public static int _POSIX_ASYNC_IO() {
- return (int)1L;
- }
- public static int _LFS_ASYNCHRONOUS_IO() {
- return (int)1L;
- }
- public static int _LFS64_ASYNCHRONOUS_IO() {
- return (int)1L;
- }
- public static int _LFS_LARGEFILE() {
- return (int)1L;
- }
- public static int _LFS64_LARGEFILE() {
- return (int)1L;
- }
- public static int _LFS64_STDIO() {
- return (int)1L;
- }
- public static int _POSIX_CPUTIME() {
- return (int)0L;
- }
- public static int _POSIX_THREAD_CPUTIME() {
- return (int)0L;
- }
- public static int _POSIX_REGEXP() {
- return (int)1L;
- }
- public static int _POSIX_SHELL() {
- return (int)1L;
- }
- public static int _POSIX_MONOTONIC_CLOCK() {
- return (int)0L;
- }
- public static int _POSIX_V7_LP64_OFF64() {
- return (int)1L;
- }
- public static int _POSIX_V6_LP64_OFF64() {
- return (int)1L;
- }
- public static int _XBS5_LP64_OFF64() {
- return (int)1L;
- }
- public static int STDIN_FILENO() {
- return (int)0L;
- }
- public static int STDOUT_FILENO() {
- return (int)1L;
- }
- public static int STDERR_FILENO() {
- return (int)2L;
- }
- public static int _BITS_TYPES_H() {
- return (int)1L;
- }
- public static int _BITS_TYPESIZES_H() {
- return (int)1L;
- }
- public static int __OFF_T_MATCHES_OFF64_T() {
- return (int)1L;
- }
- public static int __INO_T_MATCHES_INO64_T() {
- return (int)1L;
- }
- public static int __RLIM_T_MATCHES_RLIM64_T() {
- return (int)1L;
- }
- public static int __STATFS_MATCHES_STATFS64() {
- return (int)1L;
- }
- public static int __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64() {
- return (int)1L;
- }
- public static int __FD_SETSIZE() {
- return (int)1024L;
- }
- public static int _BITS_TIME64_H() {
- return (int)1L;
- }
- public static int R_OK() {
- return (int)4L;
- }
- public static int W_OK() {
- return (int)2L;
- }
- public static int X_OK() {
- return (int)1L;
- }
- public static int F_OK() {
- return (int)0L;
- }
- public static int SEEK_SET() {
- return (int)0L;
- }
- public static int SEEK_CUR() {
- return (int)1L;
- }
- public static int SEEK_END() {
- return (int)2L;
- }
- public static int _GETOPT_POSIX_H() {
- return (int)1L;
- }
- public static int _GETOPT_CORE_H() {
- return (int)1L;
- }
- public static int F_ULOCK() {
- return (int)0L;
- }
- public static int F_LOCK() {
- return (int)1L;
- }
- public static int F_TLOCK() {
- return (int)2L;
- }
- public static int F_TEST() {
- return (int)3L;
- }
- public static OfShort __int16_t = Constants$root.C_SHORT$LAYOUT;
- public static OfInt __int32_t = Constants$root.C_INT$LAYOUT;
- public static OfLong __int64_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfShort __int_least16_t = Constants$root.C_SHORT$LAYOUT;
- public static OfInt __int_least32_t = Constants$root.C_INT$LAYOUT;
- public static OfLong __int_least64_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __quad_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __intmax_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __off_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __off64_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfInt __pid_t = Constants$root.C_INT$LAYOUT;
- public static OfLong __clock_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __time_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __suseconds_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __suseconds64_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfInt __daddr_t = Constants$root.C_INT$LAYOUT;
- public static OfInt __key_t = Constants$root.C_INT$LAYOUT;
- public static OfInt __clockid_t = Constants$root.C_INT$LAYOUT;
- public static OfAddress __timer_t = Constants$root.C_POINTER$LAYOUT;
- public static OfLong __blksize_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __blkcnt_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __blkcnt64_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __fsword_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __ssize_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __syscall_slong_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __loff_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfAddress __caddr_t = Constants$root.C_POINTER$LAYOUT;
- public static OfLong __intptr_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfInt __sig_atomic_t = Constants$root.C_INT$LAYOUT;
- public static OfLong ssize_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong off_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfInt pid_t = Constants$root.C_INT$LAYOUT;
- public static OfLong intptr_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static MethodHandle access$MH() {
- return RuntimeHelper.requireNonNull(constants$0.access$MH,"access");
- }
- public static int access ( Addressable __name, int __type) {
- var mh$ = access$MH();
- try {
- return (int)mh$.invokeExact(__name, __type);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle faccessat$MH() {
- return RuntimeHelper.requireNonNull(constants$0.faccessat$MH,"faccessat");
- }
- public static int faccessat ( int __fd, Addressable __file, int __type, int __flag) {
- var mh$ = faccessat$MH();
- try {
- return (int)mh$.invokeExact(__fd, __file, __type, __flag);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle lseek$MH() {
- return RuntimeHelper.requireNonNull(constants$0.lseek$MH,"lseek");
- }
- public static long lseek ( int __fd, long __offset, int __whence) {
- var mh$ = lseek$MH();
- try {
- return (long)mh$.invokeExact(__fd, __offset, __whence);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
public static MethodHandle close$MH() {
return RuntimeHelper.requireNonNull(constants$0.close$MH,"close");
}
@@ -368,2347 +27,6 @@ public static int close ( int __fd) {
throw new AssertionError("should not reach here", ex$);
}
}
- public static MethodHandle closefrom$MH() {
- return RuntimeHelper.requireNonNull(constants$0.closefrom$MH,"closefrom");
- }
- public static void closefrom ( int __lowfd) {
- var mh$ = closefrom$MH();
- try {
- mh$.invokeExact(__lowfd);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle read$MH() {
- return RuntimeHelper.requireNonNull(constants$0.read$MH,"read");
- }
- public static long read ( int __fd, Addressable __buf, long __nbytes) {
- var mh$ = read$MH();
- try {
- return (long)mh$.invokeExact(__fd, __buf, __nbytes);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle write$MH() {
- return RuntimeHelper.requireNonNull(constants$1.write$MH,"write");
- }
- public static long write ( int __fd, Addressable __buf, long __n) {
- var mh$ = write$MH();
- try {
- return (long)mh$.invokeExact(__fd, __buf, __n);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle pread$MH() {
- return RuntimeHelper.requireNonNull(constants$1.pread$MH,"pread");
- }
- public static long pread ( int __fd, Addressable __buf, long __nbytes, long __offset) {
- var mh$ = pread$MH();
- try {
- return (long)mh$.invokeExact(__fd, __buf, __nbytes, __offset);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle pwrite$MH() {
- return RuntimeHelper.requireNonNull(constants$1.pwrite$MH,"pwrite");
- }
- public static long pwrite ( int __fd, Addressable __buf, long __n, long __offset) {
- var mh$ = pwrite$MH();
- try {
- return (long)mh$.invokeExact(__fd, __buf, __n, __offset);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle pipe$MH() {
- return RuntimeHelper.requireNonNull(constants$1.pipe$MH,"pipe");
- }
- public static int pipe ( Addressable __pipedes) {
- var mh$ = pipe$MH();
- try {
- return (int)mh$.invokeExact(__pipedes);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle alarm$MH() {
- return RuntimeHelper.requireNonNull(constants$1.alarm$MH,"alarm");
- }
- public static int alarm ( int __seconds) {
- var mh$ = alarm$MH();
- try {
- return (int)mh$.invokeExact(__seconds);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle sleep$MH() {
- return RuntimeHelper.requireNonNull(constants$1.sleep$MH,"sleep");
- }
- public static int sleep ( int __seconds) {
- var mh$ = sleep$MH();
- try {
- return (int)mh$.invokeExact(__seconds);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle ualarm$MH() {
- return RuntimeHelper.requireNonNull(constants$2.ualarm$MH,"ualarm");
- }
- public static int ualarm ( int __value, int __interval) {
- var mh$ = ualarm$MH();
- try {
- return (int)mh$.invokeExact(__value, __interval);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle usleep$MH() {
- return RuntimeHelper.requireNonNull(constants$2.usleep$MH,"usleep");
- }
- public static int usleep ( int __useconds) {
- var mh$ = usleep$MH();
- try {
- return (int)mh$.invokeExact(__useconds);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle pause$MH() {
- return RuntimeHelper.requireNonNull(constants$2.pause$MH,"pause");
- }
- public static int pause () {
- var mh$ = pause$MH();
- try {
- return (int)mh$.invokeExact();
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle chown$MH() {
- return RuntimeHelper.requireNonNull(constants$2.chown$MH,"chown");
- }
- public static int chown ( Addressable __file, int __owner, int __group) {
- var mh$ = chown$MH();
- try {
- return (int)mh$.invokeExact(__file, __owner, __group);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle fchown$MH() {
- return RuntimeHelper.requireNonNull(constants$2.fchown$MH,"fchown");
- }
- public static int fchown ( int __fd, int __owner, int __group) {
- var mh$ = fchown$MH();
- try {
- return (int)mh$.invokeExact(__fd, __owner, __group);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle lchown$MH() {
- return RuntimeHelper.requireNonNull(constants$2.lchown$MH,"lchown");
- }
- public static int lchown ( Addressable __file, int __owner, int __group) {
- var mh$ = lchown$MH();
- try {
- return (int)mh$.invokeExact(__file, __owner, __group);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle fchownat$MH() {
- return RuntimeHelper.requireNonNull(constants$3.fchownat$MH,"fchownat");
- }
- public static int fchownat ( int __fd, Addressable __file, int __owner, int __group, int __flag) {
- var mh$ = fchownat$MH();
- try {
- return (int)mh$.invokeExact(__fd, __file, __owner, __group, __flag);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle chdir$MH() {
- return RuntimeHelper.requireNonNull(constants$3.chdir$MH,"chdir");
- }
- public static int chdir ( Addressable __path) {
- var mh$ = chdir$MH();
- try {
- return (int)mh$.invokeExact(__path);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle fchdir$MH() {
- return RuntimeHelper.requireNonNull(constants$3.fchdir$MH,"fchdir");
- }
- public static int fchdir ( int __fd) {
- var mh$ = fchdir$MH();
- try {
- return (int)mh$.invokeExact(__fd);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle getcwd$MH() {
- return RuntimeHelper.requireNonNull(constants$3.getcwd$MH,"getcwd");
- }
- public static MemoryAddress getcwd ( Addressable __buf, long __size) {
- var mh$ = getcwd$MH();
- try {
- return (java.lang.foreign.MemoryAddress)mh$.invokeExact(__buf, __size);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle getwd$MH() {
- return RuntimeHelper.requireNonNull(constants$3.getwd$MH,"getwd");
- }
- public static MemoryAddress getwd ( Addressable __buf) {
- var mh$ = getwd$MH();
- try {
- return (java.lang.foreign.MemoryAddress)mh$.invokeExact(__buf);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle dup$MH() {
- return RuntimeHelper.requireNonNull(constants$3.dup$MH,"dup");
- }
- public static int dup ( int __fd) {
- var mh$ = dup$MH();
- try {
- return (int)mh$.invokeExact(__fd);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle dup2$MH() {
- return RuntimeHelper.requireNonNull(constants$4.dup2$MH,"dup2");
- }
- public static int dup2 ( int __fd, int __fd2) {
- var mh$ = dup2$MH();
- try {
- return (int)mh$.invokeExact(__fd, __fd2);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MemoryLayout __environ$LAYOUT() {
- return constants$4.__environ$LAYOUT;
- }
- public static VarHandle __environ$VH() {
- return constants$4.__environ$VH;
- }
- public static MemorySegment __environ$SEGMENT() {
- return RuntimeHelper.requireNonNull(constants$4.__environ$SEGMENT,"__environ");
- }
- public static MemoryAddress __environ$get() {
- return (java.lang.foreign.MemoryAddress) constants$4.__environ$VH.get(RuntimeHelper.requireNonNull(constants$4.__environ$SEGMENT, "__environ"));
- }
- public static void __environ$set( MemoryAddress x) {
- constants$4.__environ$VH.set(RuntimeHelper.requireNonNull(constants$4.__environ$SEGMENT, "__environ"), x);
- }
- public static MethodHandle execve$MH() {
- return RuntimeHelper.requireNonNull(constants$4.execve$MH,"execve");
- }
- public static int execve ( Addressable __path, Addressable __argv, Addressable __envp) {
- var mh$ = execve$MH();
- try {
- return (int)mh$.invokeExact(__path, __argv, __envp);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle fexecve$MH() {
- return RuntimeHelper.requireNonNull(constants$4.fexecve$MH,"fexecve");
- }
- public static int fexecve ( int __fd, Addressable __argv, Addressable __envp) {
- var mh$ = fexecve$MH();
- try {
- return (int)mh$.invokeExact(__fd, __argv, __envp);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle execv$MH() {
- return RuntimeHelper.requireNonNull(constants$4.execv$MH,"execv");
- }
- public static int execv ( Addressable __path, Addressable __argv) {
- var mh$ = execv$MH();
- try {
- return (int)mh$.invokeExact(__path, __argv);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle execle$MH() {
- return RuntimeHelper.requireNonNull(constants$4.execle$MH,"execle");
- }
- public static int execle ( Addressable __path, Addressable __arg, Object... x2) {
- var mh$ = execle$MH();
- try {
- return (int)mh$.invokeExact(__path, __arg, x2);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle execl$MH() {
- return RuntimeHelper.requireNonNull(constants$5.execl$MH,"execl");
- }
- public static int execl ( Addressable __path, Addressable __arg, Object... x2) {
- var mh$ = execl$MH();
- try {
- return (int)mh$.invokeExact(__path, __arg, x2);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle execvp$MH() {
- return RuntimeHelper.requireNonNull(constants$5.execvp$MH,"execvp");
- }
- public static int execvp ( Addressable __file, Addressable __argv) {
- var mh$ = execvp$MH();
- try {
- return (int)mh$.invokeExact(__file, __argv);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle execlp$MH() {
- return RuntimeHelper.requireNonNull(constants$5.execlp$MH,"execlp");
- }
- public static int execlp ( Addressable __file, Addressable __arg, Object... x2) {
- var mh$ = execlp$MH();
- try {
- return (int)mh$.invokeExact(__file, __arg, x2);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle nice$MH() {
- return RuntimeHelper.requireNonNull(constants$5.nice$MH,"nice");
- }
- public static int nice ( int __inc) {
- var mh$ = nice$MH();
- try {
- return (int)mh$.invokeExact(__inc);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle _exit$MH() {
- return RuntimeHelper.requireNonNull(constants$5._exit$MH,"_exit");
- }
- public static void _exit ( int __status) {
- var mh$ = _exit$MH();
- try {
- mh$.invokeExact(__status);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static int _PC_LINK_MAX() {
- return (int)0L;
- }
- public static int _PC_MAX_CANON() {
- return (int)1L;
- }
- public static int _PC_MAX_INPUT() {
- return (int)2L;
- }
- public static int _PC_NAME_MAX() {
- return (int)3L;
- }
- public static int _PC_PATH_MAX() {
- return (int)4L;
- }
- public static int _PC_PIPE_BUF() {
- return (int)5L;
- }
- public static int _PC_CHOWN_RESTRICTED() {
- return (int)6L;
- }
- public static int _PC_NO_TRUNC() {
- return (int)7L;
- }
- public static int _PC_VDISABLE() {
- return (int)8L;
- }
- public static int _PC_SYNC_IO() {
- return (int)9L;
- }
- public static int _PC_ASYNC_IO() {
- return (int)10L;
- }
- public static int _PC_PRIO_IO() {
- return (int)11L;
- }
- public static int _PC_SOCK_MAXBUF() {
- return (int)12L;
- }
- public static int _PC_FILESIZEBITS() {
- return (int)13L;
- }
- public static int _PC_REC_INCR_XFER_SIZE() {
- return (int)14L;
- }
- public static int _PC_REC_MAX_XFER_SIZE() {
- return (int)15L;
- }
- public static int _PC_REC_MIN_XFER_SIZE() {
- return (int)16L;
- }
- public static int _PC_REC_XFER_ALIGN() {
- return (int)17L;
- }
- public static int _PC_ALLOC_SIZE_MIN() {
- return (int)18L;
- }
- public static int _PC_SYMLINK_MAX() {
- return (int)19L;
- }
- public static int _PC_2_SYMLINKS() {
- return (int)20L;
- }
- public static int _SC_ARG_MAX() {
- return (int)0L;
- }
- public static int _SC_CHILD_MAX() {
- return (int)1L;
- }
- public static int _SC_CLK_TCK() {
- return (int)2L;
- }
- public static int _SC_NGROUPS_MAX() {
- return (int)3L;
- }
- public static int _SC_OPEN_MAX() {
- return (int)4L;
- }
- public static int _SC_STREAM_MAX() {
- return (int)5L;
- }
- public static int _SC_TZNAME_MAX() {
- return (int)6L;
- }
- public static int _SC_JOB_CONTROL() {
- return (int)7L;
- }
- public static int _SC_SAVED_IDS() {
- return (int)8L;
- }
- public static int _SC_REALTIME_SIGNALS() {
- return (int)9L;
- }
- public static int _SC_PRIORITY_SCHEDULING() {
- return (int)10L;
- }
- public static int _SC_TIMERS() {
- return (int)11L;
- }
- public static int _SC_ASYNCHRONOUS_IO() {
- return (int)12L;
- }
- public static int _SC_PRIORITIZED_IO() {
- return (int)13L;
- }
- public static int _SC_SYNCHRONIZED_IO() {
- return (int)14L;
- }
- public static int _SC_FSYNC() {
- return (int)15L;
- }
- public static int _SC_MAPPED_FILES() {
- return (int)16L;
- }
- public static int _SC_MEMLOCK() {
- return (int)17L;
- }
- public static int _SC_MEMLOCK_RANGE() {
- return (int)18L;
- }
- public static int _SC_MEMORY_PROTECTION() {
- return (int)19L;
- }
- public static int _SC_MESSAGE_PASSING() {
- return (int)20L;
- }
- public static int _SC_SEMAPHORES() {
- return (int)21L;
- }
- public static int _SC_SHARED_MEMORY_OBJECTS() {
- return (int)22L;
- }
- public static int _SC_AIO_LISTIO_MAX() {
- return (int)23L;
- }
- public static int _SC_AIO_MAX() {
- return (int)24L;
- }
- public static int _SC_AIO_PRIO_DELTA_MAX() {
- return (int)25L;
- }
- public static int _SC_DELAYTIMER_MAX() {
- return (int)26L;
- }
- public static int _SC_MQ_OPEN_MAX() {
- return (int)27L;
- }
- public static int _SC_MQ_PRIO_MAX() {
- return (int)28L;
- }
- public static int _SC_VERSION() {
- return (int)29L;
- }
- public static int _SC_PAGESIZE() {
- return (int)30L;
- }
- public static int _SC_RTSIG_MAX() {
- return (int)31L;
- }
- public static int _SC_SEM_NSEMS_MAX() {
- return (int)32L;
- }
- public static int _SC_SEM_VALUE_MAX() {
- return (int)33L;
- }
- public static int _SC_SIGQUEUE_MAX() {
- return (int)34L;
- }
- public static int _SC_TIMER_MAX() {
- return (int)35L;
- }
- public static int _SC_BC_BASE_MAX() {
- return (int)36L;
- }
- public static int _SC_BC_DIM_MAX() {
- return (int)37L;
- }
- public static int _SC_BC_SCALE_MAX() {
- return (int)38L;
- }
- public static int _SC_BC_STRING_MAX() {
- return (int)39L;
- }
- public static int _SC_COLL_WEIGHTS_MAX() {
- return (int)40L;
- }
- public static int _SC_EQUIV_CLASS_MAX() {
- return (int)41L;
- }
- public static int _SC_EXPR_NEST_MAX() {
- return (int)42L;
- }
- public static int _SC_LINE_MAX() {
- return (int)43L;
- }
- public static int _SC_RE_DUP_MAX() {
- return (int)44L;
- }
- public static int _SC_CHARCLASS_NAME_MAX() {
- return (int)45L;
- }
- public static int _SC_2_VERSION() {
- return (int)46L;
- }
- public static int _SC_2_C_BIND() {
- return (int)47L;
- }
- public static int _SC_2_C_DEV() {
- return (int)48L;
- }
- public static int _SC_2_FORT_DEV() {
- return (int)49L;
- }
- public static int _SC_2_FORT_RUN() {
- return (int)50L;
- }
- public static int _SC_2_SW_DEV() {
- return (int)51L;
- }
- public static int _SC_2_LOCALEDEF() {
- return (int)52L;
- }
- public static int _SC_PII() {
- return (int)53L;
- }
- public static int _SC_PII_XTI() {
- return (int)54L;
- }
- public static int _SC_PII_SOCKET() {
- return (int)55L;
- }
- public static int _SC_PII_INTERNET() {
- return (int)56L;
- }
- public static int _SC_PII_OSI() {
- return (int)57L;
- }
- public static int _SC_POLL() {
- return (int)58L;
- }
- public static int _SC_SELECT() {
- return (int)59L;
- }
- public static int _SC_UIO_MAXIOV() {
- return (int)60L;
- }
- public static int _SC_IOV_MAX() {
- return (int)60L;
- }
- public static int _SC_PII_INTERNET_STREAM() {
- return (int)61L;
- }
- public static int _SC_PII_INTERNET_DGRAM() {
- return (int)62L;
- }
- public static int _SC_PII_OSI_COTS() {
- return (int)63L;
- }
- public static int _SC_PII_OSI_CLTS() {
- return (int)64L;
- }
- public static int _SC_PII_OSI_M() {
- return (int)65L;
- }
- public static int _SC_T_IOV_MAX() {
- return (int)66L;
- }
- public static int _SC_THREADS() {
- return (int)67L;
- }
- public static int _SC_THREAD_SAFE_FUNCTIONS() {
- return (int)68L;
- }
- public static int _SC_GETGR_R_SIZE_MAX() {
- return (int)69L;
- }
- public static int _SC_GETPW_R_SIZE_MAX() {
- return (int)70L;
- }
- public static int _SC_LOGIN_NAME_MAX() {
- return (int)71L;
- }
- public static int _SC_TTY_NAME_MAX() {
- return (int)72L;
- }
- public static int _SC_THREAD_DESTRUCTOR_ITERATIONS() {
- return (int)73L;
- }
- public static int _SC_THREAD_KEYS_MAX() {
- return (int)74L;
- }
- public static int _SC_THREAD_STACK_MIN() {
- return (int)75L;
- }
- public static int _SC_THREAD_THREADS_MAX() {
- return (int)76L;
- }
- public static int _SC_THREAD_ATTR_STACKADDR() {
- return (int)77L;
- }
- public static int _SC_THREAD_ATTR_STACKSIZE() {
- return (int)78L;
- }
- public static int _SC_THREAD_PRIORITY_SCHEDULING() {
- return (int)79L;
- }
- public static int _SC_THREAD_PRIO_INHERIT() {
- return (int)80L;
- }
- public static int _SC_THREAD_PRIO_PROTECT() {
- return (int)81L;
- }
- public static int _SC_THREAD_PROCESS_SHARED() {
- return (int)82L;
- }
- public static int _SC_NPROCESSORS_CONF() {
- return (int)83L;
- }
- public static int _SC_NPROCESSORS_ONLN() {
- return (int)84L;
- }
- public static int _SC_PHYS_PAGES() {
- return (int)85L;
- }
- public static int _SC_AVPHYS_PAGES() {
- return (int)86L;
- }
- public static int _SC_ATEXIT_MAX() {
- return (int)87L;
- }
- public static int _SC_PASS_MAX() {
- return (int)88L;
- }
- public static int _SC_XOPEN_VERSION() {
- return (int)89L;
- }
- public static int _SC_XOPEN_XCU_VERSION() {
- return (int)90L;
- }
- public static int _SC_XOPEN_UNIX() {
- return (int)91L;
- }
- public static int _SC_XOPEN_CRYPT() {
- return (int)92L;
- }
- public static int _SC_XOPEN_ENH_I18N() {
- return (int)93L;
- }
- public static int _SC_XOPEN_SHM() {
- return (int)94L;
- }
- public static int _SC_2_CHAR_TERM() {
- return (int)95L;
- }
- public static int _SC_2_C_VERSION() {
- return (int)96L;
- }
- public static int _SC_2_UPE() {
- return (int)97L;
- }
- public static int _SC_XOPEN_XPG2() {
- return (int)98L;
- }
- public static int _SC_XOPEN_XPG3() {
- return (int)99L;
- }
- public static int _SC_XOPEN_XPG4() {
- return (int)100L;
- }
- public static int _SC_CHAR_BIT() {
- return (int)101L;
- }
- public static int _SC_CHAR_MAX() {
- return (int)102L;
- }
- public static int _SC_CHAR_MIN() {
- return (int)103L;
- }
- public static int _SC_INT_MAX() {
- return (int)104L;
- }
- public static int _SC_INT_MIN() {
- return (int)105L;
- }
- public static int _SC_LONG_BIT() {
- return (int)106L;
- }
- public static int _SC_WORD_BIT() {
- return (int)107L;
- }
- public static int _SC_MB_LEN_MAX() {
- return (int)108L;
- }
- public static int _SC_NZERO() {
- return (int)109L;
- }
- public static int _SC_SSIZE_MAX() {
- return (int)110L;
- }
- public static int _SC_SCHAR_MAX() {
- return (int)111L;
- }
- public static int _SC_SCHAR_MIN() {
- return (int)112L;
- }
- public static int _SC_SHRT_MAX() {
- return (int)113L;
- }
- public static int _SC_SHRT_MIN() {
- return (int)114L;
- }
- public static int _SC_UCHAR_MAX() {
- return (int)115L;
- }
- public static int _SC_UINT_MAX() {
- return (int)116L;
- }
- public static int _SC_ULONG_MAX() {
- return (int)117L;
- }
- public static int _SC_USHRT_MAX() {
- return (int)118L;
- }
- public static int _SC_NL_ARGMAX() {
- return (int)119L;
- }
- public static int _SC_NL_LANGMAX() {
- return (int)120L;
- }
- public static int _SC_NL_MSGMAX() {
- return (int)121L;
- }
- public static int _SC_NL_NMAX() {
- return (int)122L;
- }
- public static int _SC_NL_SETMAX() {
- return (int)123L;
- }
- public static int _SC_NL_TEXTMAX() {
- return (int)124L;
- }
- public static int _SC_XBS5_ILP32_OFF32() {
- return (int)125L;
- }
- public static int _SC_XBS5_ILP32_OFFBIG() {
- return (int)126L;
- }
- public static int _SC_XBS5_LP64_OFF64() {
- return (int)127L;
- }
- public static int _SC_XBS5_LPBIG_OFFBIG() {
- return (int)128L;
- }
- public static int _SC_XOPEN_LEGACY() {
- return (int)129L;
- }
- public static int _SC_XOPEN_REALTIME() {
- return (int)130L;
- }
- public static int _SC_XOPEN_REALTIME_THREADS() {
- return (int)131L;
- }
- public static int _SC_ADVISORY_INFO() {
- return (int)132L;
- }
- public static int _SC_BARRIERS() {
- return (int)133L;
- }
- public static int _SC_BASE() {
- return (int)134L;
- }
- public static int _SC_C_LANG_SUPPORT() {
- return (int)135L;
- }
- public static int _SC_C_LANG_SUPPORT_R() {
- return (int)136L;
- }
- public static int _SC_CLOCK_SELECTION() {
- return (int)137L;
- }
- public static int _SC_CPUTIME() {
- return (int)138L;
- }
- public static int _SC_THREAD_CPUTIME() {
- return (int)139L;
- }
- public static int _SC_DEVICE_IO() {
- return (int)140L;
- }
- public static int _SC_DEVICE_SPECIFIC() {
- return (int)141L;
- }
- public static int _SC_DEVICE_SPECIFIC_R() {
- return (int)142L;
- }
- public static int _SC_FD_MGMT() {
- return (int)143L;
- }
- public static int _SC_FIFO() {
- return (int)144L;
- }
- public static int _SC_PIPE() {
- return (int)145L;
- }
- public static int _SC_FILE_ATTRIBUTES() {
- return (int)146L;
- }
- public static int _SC_FILE_LOCKING() {
- return (int)147L;
- }
- public static int _SC_FILE_SYSTEM() {
- return (int)148L;
- }
- public static int _SC_MONOTONIC_CLOCK() {
- return (int)149L;
- }
- public static int _SC_MULTI_PROCESS() {
- return (int)150L;
- }
- public static int _SC_SINGLE_PROCESS() {
- return (int)151L;
- }
- public static int _SC_NETWORKING() {
- return (int)152L;
- }
- public static int _SC_READER_WRITER_LOCKS() {
- return (int)153L;
- }
- public static int _SC_SPIN_LOCKS() {
- return (int)154L;
- }
- public static int _SC_REGEXP() {
- return (int)155L;
- }
- public static int _SC_REGEX_VERSION() {
- return (int)156L;
- }
- public static int _SC_SHELL() {
- return (int)157L;
- }
- public static int _SC_SIGNALS() {
- return (int)158L;
- }
- public static int _SC_SPAWN() {
- return (int)159L;
- }
- public static int _SC_SPORADIC_SERVER() {
- return (int)160L;
- }
- public static int _SC_THREAD_SPORADIC_SERVER() {
- return (int)161L;
- }
- public static int _SC_SYSTEM_DATABASE() {
- return (int)162L;
- }
- public static int _SC_SYSTEM_DATABASE_R() {
- return (int)163L;
- }
- public static int _SC_TIMEOUTS() {
- return (int)164L;
- }
- public static int _SC_TYPED_MEMORY_OBJECTS() {
- return (int)165L;
- }
- public static int _SC_USER_GROUPS() {
- return (int)166L;
- }
- public static int _SC_USER_GROUPS_R() {
- return (int)167L;
- }
- public static int _SC_2_PBS() {
- return (int)168L;
- }
- public static int _SC_2_PBS_ACCOUNTING() {
- return (int)169L;
- }
- public static int _SC_2_PBS_LOCATE() {
- return (int)170L;
- }
- public static int _SC_2_PBS_MESSAGE() {
- return (int)171L;
- }
- public static int _SC_2_PBS_TRACK() {
- return (int)172L;
- }
- public static int _SC_SYMLOOP_MAX() {
- return (int)173L;
- }
- public static int _SC_STREAMS() {
- return (int)174L;
- }
- public static int _SC_2_PBS_CHECKPOINT() {
- return (int)175L;
- }
- public static int _SC_V6_ILP32_OFF32() {
- return (int)176L;
- }
- public static int _SC_V6_ILP32_OFFBIG() {
- return (int)177L;
- }
- public static int _SC_V6_LP64_OFF64() {
- return (int)178L;
- }
- public static int _SC_V6_LPBIG_OFFBIG() {
- return (int)179L;
- }
- public static int _SC_HOST_NAME_MAX() {
- return (int)180L;
- }
- public static int _SC_TRACE() {
- return (int)181L;
- }
- public static int _SC_TRACE_EVENT_FILTER() {
- return (int)182L;
- }
- public static int _SC_TRACE_INHERIT() {
- return (int)183L;
- }
- public static int _SC_TRACE_LOG() {
- return (int)184L;
- }
- public static int _SC_LEVEL1_ICACHE_SIZE() {
- return (int)185L;
- }
- public static int _SC_LEVEL1_ICACHE_ASSOC() {
- return (int)186L;
- }
- public static int _SC_LEVEL1_ICACHE_LINESIZE() {
- return (int)187L;
- }
- public static int _SC_LEVEL1_DCACHE_SIZE() {
- return (int)188L;
- }
- public static int _SC_LEVEL1_DCACHE_ASSOC() {
- return (int)189L;
- }
- public static int _SC_LEVEL1_DCACHE_LINESIZE() {
- return (int)190L;
- }
- public static int _SC_LEVEL2_CACHE_SIZE() {
- return (int)191L;
- }
- public static int _SC_LEVEL2_CACHE_ASSOC() {
- return (int)192L;
- }
- public static int _SC_LEVEL2_CACHE_LINESIZE() {
- return (int)193L;
- }
- public static int _SC_LEVEL3_CACHE_SIZE() {
- return (int)194L;
- }
- public static int _SC_LEVEL3_CACHE_ASSOC() {
- return (int)195L;
- }
- public static int _SC_LEVEL3_CACHE_LINESIZE() {
- return (int)196L;
- }
- public static int _SC_LEVEL4_CACHE_SIZE() {
- return (int)197L;
- }
- public static int _SC_LEVEL4_CACHE_ASSOC() {
- return (int)198L;
- }
- public static int _SC_LEVEL4_CACHE_LINESIZE() {
- return (int)199L;
- }
- public static int _SC_IPV6() {
- return (int)235L;
- }
- public static int _SC_RAW_SOCKETS() {
- return (int)236L;
- }
- public static int _SC_V7_ILP32_OFF32() {
- return (int)237L;
- }
- public static int _SC_V7_ILP32_OFFBIG() {
- return (int)238L;
- }
- public static int _SC_V7_LP64_OFF64() {
- return (int)239L;
- }
- public static int _SC_V7_LPBIG_OFFBIG() {
- return (int)240L;
- }
- public static int _SC_SS_REPL_MAX() {
- return (int)241L;
- }
- public static int _SC_TRACE_EVENT_NAME_MAX() {
- return (int)242L;
- }
- public static int _SC_TRACE_NAME_MAX() {
- return (int)243L;
- }
- public static int _SC_TRACE_SYS_MAX() {
- return (int)244L;
- }
- public static int _SC_TRACE_USER_EVENT_MAX() {
- return (int)245L;
- }
- public static int _SC_XOPEN_STREAMS() {
- return (int)246L;
- }
- public static int _SC_THREAD_ROBUST_PRIO_INHERIT() {
- return (int)247L;
- }
- public static int _SC_THREAD_ROBUST_PRIO_PROTECT() {
- return (int)248L;
- }
- public static int _SC_MINSIGSTKSZ() {
- return (int)249L;
- }
- public static int _SC_SIGSTKSZ() {
- return (int)250L;
- }
- public static int _CS_PATH() {
- return (int)0L;
- }
- public static int _CS_V6_WIDTH_RESTRICTED_ENVS() {
- return (int)1L;
- }
- public static int _CS_GNU_LIBC_VERSION() {
- return (int)2L;
- }
- public static int _CS_GNU_LIBPTHREAD_VERSION() {
- return (int)3L;
- }
- public static int _CS_V5_WIDTH_RESTRICTED_ENVS() {
- return (int)4L;
- }
- public static int _CS_V7_WIDTH_RESTRICTED_ENVS() {
- return (int)5L;
- }
- public static int _CS_LFS_CFLAGS() {
- return (int)1000L;
- }
- public static int _CS_LFS_LDFLAGS() {
- return (int)1001L;
- }
- public static int _CS_LFS_LIBS() {
- return (int)1002L;
- }
- public static int _CS_LFS_LINTFLAGS() {
- return (int)1003L;
- }
- public static int _CS_LFS64_CFLAGS() {
- return (int)1004L;
- }
- public static int _CS_LFS64_LDFLAGS() {
- return (int)1005L;
- }
- public static int _CS_LFS64_LIBS() {
- return (int)1006L;
- }
- public static int _CS_LFS64_LINTFLAGS() {
- return (int)1007L;
- }
- public static int _CS_XBS5_ILP32_OFF32_CFLAGS() {
- return (int)1100L;
- }
- public static int _CS_XBS5_ILP32_OFF32_LDFLAGS() {
- return (int)1101L;
- }
- public static int _CS_XBS5_ILP32_OFF32_LIBS() {
- return (int)1102L;
- }
- public static int _CS_XBS5_ILP32_OFF32_LINTFLAGS() {
- return (int)1103L;
- }
- public static int _CS_XBS5_ILP32_OFFBIG_CFLAGS() {
- return (int)1104L;
- }
- public static int _CS_XBS5_ILP32_OFFBIG_LDFLAGS() {
- return (int)1105L;
- }
- public static int _CS_XBS5_ILP32_OFFBIG_LIBS() {
- return (int)1106L;
- }
- public static int _CS_XBS5_ILP32_OFFBIG_LINTFLAGS() {
- return (int)1107L;
- }
- public static int _CS_XBS5_LP64_OFF64_CFLAGS() {
- return (int)1108L;
- }
- public static int _CS_XBS5_LP64_OFF64_LDFLAGS() {
- return (int)1109L;
- }
- public static int _CS_XBS5_LP64_OFF64_LIBS() {
- return (int)1110L;
- }
- public static int _CS_XBS5_LP64_OFF64_LINTFLAGS() {
- return (int)1111L;
- }
- public static int _CS_XBS5_LPBIG_OFFBIG_CFLAGS() {
- return (int)1112L;
- }
- public static int _CS_XBS5_LPBIG_OFFBIG_LDFLAGS() {
- return (int)1113L;
- }
- public static int _CS_XBS5_LPBIG_OFFBIG_LIBS() {
- return (int)1114L;
- }
- public static int _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS() {
- return (int)1115L;
- }
- public static int _CS_POSIX_V6_ILP32_OFF32_CFLAGS() {
- return (int)1116L;
- }
- public static int _CS_POSIX_V6_ILP32_OFF32_LDFLAGS() {
- return (int)1117L;
- }
- public static int _CS_POSIX_V6_ILP32_OFF32_LIBS() {
- return (int)1118L;
- }
- public static int _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS() {
- return (int)1119L;
- }
- public static int _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS() {
- return (int)1120L;
- }
- public static int _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS() {
- return (int)1121L;
- }
- public static int _CS_POSIX_V6_ILP32_OFFBIG_LIBS() {
- return (int)1122L;
- }
- public static int _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS() {
- return (int)1123L;
- }
- public static int _CS_POSIX_V6_LP64_OFF64_CFLAGS() {
- return (int)1124L;
- }
- public static int _CS_POSIX_V6_LP64_OFF64_LDFLAGS() {
- return (int)1125L;
- }
- public static int _CS_POSIX_V6_LP64_OFF64_LIBS() {
- return (int)1126L;
- }
- public static int _CS_POSIX_V6_LP64_OFF64_LINTFLAGS() {
- return (int)1127L;
- }
- public static int _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS() {
- return (int)1128L;
- }
- public static int _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS() {
- return (int)1129L;
- }
- public static int _CS_POSIX_V6_LPBIG_OFFBIG_LIBS() {
- return (int)1130L;
- }
- public static int _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS() {
- return (int)1131L;
- }
- public static int _CS_POSIX_V7_ILP32_OFF32_CFLAGS() {
- return (int)1132L;
- }
- public static int _CS_POSIX_V7_ILP32_OFF32_LDFLAGS() {
- return (int)1133L;
- }
- public static int _CS_POSIX_V7_ILP32_OFF32_LIBS() {
- return (int)1134L;
- }
- public static int _CS_POSIX_V7_ILP32_OFF32_LINTFLAGS() {
- return (int)1135L;
- }
- public static int _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS() {
- return (int)1136L;
- }
- public static int _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS() {
- return (int)1137L;
- }
- public static int _CS_POSIX_V7_ILP32_OFFBIG_LIBS() {
- return (int)1138L;
- }
- public static int _CS_POSIX_V7_ILP32_OFFBIG_LINTFLAGS() {
- return (int)1139L;
- }
- public static int _CS_POSIX_V7_LP64_OFF64_CFLAGS() {
- return (int)1140L;
- }
- public static int _CS_POSIX_V7_LP64_OFF64_LDFLAGS() {
- return (int)1141L;
- }
- public static int _CS_POSIX_V7_LP64_OFF64_LIBS() {
- return (int)1142L;
- }
- public static int _CS_POSIX_V7_LP64_OFF64_LINTFLAGS() {
- return (int)1143L;
- }
- public static int _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS() {
- return (int)1144L;
- }
- public static int _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS() {
- return (int)1145L;
- }
- public static int _CS_POSIX_V7_LPBIG_OFFBIG_LIBS() {
- return (int)1146L;
- }
- public static int _CS_POSIX_V7_LPBIG_OFFBIG_LINTFLAGS() {
- return (int)1147L;
- }
- public static int _CS_V6_ENV() {
- return (int)1148L;
- }
- public static int _CS_V7_ENV() {
- return (int)1149L;
- }
- public static MethodHandle pathconf$MH() {
- return RuntimeHelper.requireNonNull(constants$5.pathconf$MH,"pathconf");
- }
- public static long pathconf ( Addressable __path, int __name) {
- var mh$ = pathconf$MH();
- try {
- return (long)mh$.invokeExact(__path, __name);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle fpathconf$MH() {
- return RuntimeHelper.requireNonNull(constants$6.fpathconf$MH,"fpathconf");
- }
- public static long fpathconf ( int __fd, int __name) {
- var mh$ = fpathconf$MH();
- try {
- return (long)mh$.invokeExact(__fd, __name);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle sysconf$MH() {
- return RuntimeHelper.requireNonNull(constants$6.sysconf$MH,"sysconf");
- }
- public static long sysconf ( int __name) {
- var mh$ = sysconf$MH();
- try {
- return (long)mh$.invokeExact(__name);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle confstr$MH() {
- return RuntimeHelper.requireNonNull(constants$6.confstr$MH,"confstr");
- }
- public static long confstr ( int __name, Addressable __buf, long __len) {
- var mh$ = confstr$MH();
- try {
- return (long)mh$.invokeExact(__name, __buf, __len);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle getpid$MH() {
- return RuntimeHelper.requireNonNull(constants$6.getpid$MH,"getpid");
- }
- public static int getpid () {
- var mh$ = getpid$MH();
- try {
- return (int)mh$.invokeExact();
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle getppid$MH() {
- return RuntimeHelper.requireNonNull(constants$6.getppid$MH,"getppid");
- }
- public static int getppid () {
- var mh$ = getppid$MH();
- try {
- return (int)mh$.invokeExact();
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle getpgrp$MH() {
- return RuntimeHelper.requireNonNull(constants$6.getpgrp$MH,"getpgrp");
- }
- public static int getpgrp () {
- var mh$ = getpgrp$MH();
- try {
- return (int)mh$.invokeExact();
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle __getpgid$MH() {
- return RuntimeHelper.requireNonNull(constants$7.__getpgid$MH,"__getpgid");
- }
- public static int __getpgid ( int __pid) {
- var mh$ = __getpgid$MH();
- try {
- return (int)mh$.invokeExact(__pid);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle getpgid$MH() {
- return RuntimeHelper.requireNonNull(constants$7.getpgid$MH,"getpgid");
- }
- public static int getpgid ( int __pid) {
- var mh$ = getpgid$MH();
- try {
- return (int)mh$.invokeExact(__pid);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle setpgid$MH() {
- return RuntimeHelper.requireNonNull(constants$7.setpgid$MH,"setpgid");
- }
- public static int setpgid ( int __pid, int __pgid) {
- var mh$ = setpgid$MH();
- try {
- return (int)mh$.invokeExact(__pid, __pgid);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle setpgrp$MH() {
- return RuntimeHelper.requireNonNull(constants$7.setpgrp$MH,"setpgrp");
- }
- public static int setpgrp () {
- var mh$ = setpgrp$MH();
- try {
- return (int)mh$.invokeExact();
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle setsid$MH() {
- return RuntimeHelper.requireNonNull(constants$7.setsid$MH,"setsid");
- }
- public static int setsid () {
- var mh$ = setsid$MH();
- try {
- return (int)mh$.invokeExact();
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle getsid$MH() {
- return RuntimeHelper.requireNonNull(constants$7.getsid$MH,"getsid");
- }
- public static int getsid ( int __pid) {
- var mh$ = getsid$MH();
- try {
- return (int)mh$.invokeExact(__pid);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle getuid$MH() {
- return RuntimeHelper.requireNonNull(constants$8.getuid$MH,"getuid");
- }
- public static int getuid () {
- var mh$ = getuid$MH();
- try {
- return (int)mh$.invokeExact();
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle geteuid$MH() {
- return RuntimeHelper.requireNonNull(constants$8.geteuid$MH,"geteuid");
- }
- public static int geteuid () {
- var mh$ = geteuid$MH();
- try {
- return (int)mh$.invokeExact();
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle getgid$MH() {
- return RuntimeHelper.requireNonNull(constants$8.getgid$MH,"getgid");
- }
- public static int getgid () {
- var mh$ = getgid$MH();
- try {
- return (int)mh$.invokeExact();
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle getegid$MH() {
- return RuntimeHelper.requireNonNull(constants$8.getegid$MH,"getegid");
- }
- public static int getegid () {
- var mh$ = getegid$MH();
- try {
- return (int)mh$.invokeExact();
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle getgroups$MH() {
- return RuntimeHelper.requireNonNull(constants$8.getgroups$MH,"getgroups");
- }
- public static int getgroups ( int __size, Addressable __list) {
- var mh$ = getgroups$MH();
- try {
- return (int)mh$.invokeExact(__size, __list);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle setuid$MH() {
- return RuntimeHelper.requireNonNull(constants$8.setuid$MH,"setuid");
- }
- public static int setuid ( int __uid) {
- var mh$ = setuid$MH();
- try {
- return (int)mh$.invokeExact(__uid);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle setreuid$MH() {
- return RuntimeHelper.requireNonNull(constants$9.setreuid$MH,"setreuid");
- }
- public static int setreuid ( int __ruid, int __euid) {
- var mh$ = setreuid$MH();
- try {
- return (int)mh$.invokeExact(__ruid, __euid);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle seteuid$MH() {
- return RuntimeHelper.requireNonNull(constants$9.seteuid$MH,"seteuid");
- }
- public static int seteuid ( int __uid) {
- var mh$ = seteuid$MH();
- try {
- return (int)mh$.invokeExact(__uid);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle setgid$MH() {
- return RuntimeHelper.requireNonNull(constants$9.setgid$MH,"setgid");
- }
- public static int setgid ( int __gid) {
- var mh$ = setgid$MH();
- try {
- return (int)mh$.invokeExact(__gid);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle setregid$MH() {
- return RuntimeHelper.requireNonNull(constants$9.setregid$MH,"setregid");
- }
- public static int setregid ( int __rgid, int __egid) {
- var mh$ = setregid$MH();
- try {
- return (int)mh$.invokeExact(__rgid, __egid);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle setegid$MH() {
- return RuntimeHelper.requireNonNull(constants$9.setegid$MH,"setegid");
- }
- public static int setegid ( int __gid) {
- var mh$ = setegid$MH();
- try {
- return (int)mh$.invokeExact(__gid);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle fork$MH() {
- return RuntimeHelper.requireNonNull(constants$9.fork$MH,"fork");
- }
- public static int fork () {
- var mh$ = fork$MH();
- try {
- return (int)mh$.invokeExact();
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle vfork$MH() {
- return RuntimeHelper.requireNonNull(constants$10.vfork$MH,"vfork");
- }
- public static int vfork () {
- var mh$ = vfork$MH();
- try {
- return (int)mh$.invokeExact();
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle ttyname$MH() {
- return RuntimeHelper.requireNonNull(constants$10.ttyname$MH,"ttyname");
- }
- public static MemoryAddress ttyname ( int __fd) {
- var mh$ = ttyname$MH();
- try {
- return (java.lang.foreign.MemoryAddress)mh$.invokeExact(__fd);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle ttyname_r$MH() {
- return RuntimeHelper.requireNonNull(constants$10.ttyname_r$MH,"ttyname_r");
- }
- public static int ttyname_r ( int __fd, Addressable __buf, long __buflen) {
- var mh$ = ttyname_r$MH();
- try {
- return (int)mh$.invokeExact(__fd, __buf, __buflen);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle isatty$MH() {
- return RuntimeHelper.requireNonNull(constants$10.isatty$MH,"isatty");
- }
- public static int isatty ( int __fd) {
- var mh$ = isatty$MH();
- try {
- return (int)mh$.invokeExact(__fd);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle ttyslot$MH() {
- return RuntimeHelper.requireNonNull(constants$10.ttyslot$MH,"ttyslot");
- }
- public static int ttyslot () {
- var mh$ = ttyslot$MH();
- try {
- return (int)mh$.invokeExact();
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle link$MH() {
- return RuntimeHelper.requireNonNull(constants$10.link$MH,"link");
- }
- public static int link ( Addressable __from, Addressable __to) {
- var mh$ = link$MH();
- try {
- return (int)mh$.invokeExact(__from, __to);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle linkat$MH() {
- return RuntimeHelper.requireNonNull(constants$11.linkat$MH,"linkat");
- }
- public static int linkat ( int __fromfd, Addressable __from, int __tofd, Addressable __to, int __flags) {
- var mh$ = linkat$MH();
- try {
- return (int)mh$.invokeExact(__fromfd, __from, __tofd, __to, __flags);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle symlink$MH() {
- return RuntimeHelper.requireNonNull(constants$11.symlink$MH,"symlink");
- }
- public static int symlink ( Addressable __from, Addressable __to) {
- var mh$ = symlink$MH();
- try {
- return (int)mh$.invokeExact(__from, __to);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle readlink$MH() {
- return RuntimeHelper.requireNonNull(constants$11.readlink$MH,"readlink");
- }
- public static long readlink ( Addressable __path, Addressable __buf, long __len) {
- var mh$ = readlink$MH();
- try {
- return (long)mh$.invokeExact(__path, __buf, __len);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle symlinkat$MH() {
- return RuntimeHelper.requireNonNull(constants$11.symlinkat$MH,"symlinkat");
- }
- public static int symlinkat ( Addressable __from, int __tofd, Addressable __to) {
- var mh$ = symlinkat$MH();
- try {
- return (int)mh$.invokeExact(__from, __tofd, __to);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle readlinkat$MH() {
- return RuntimeHelper.requireNonNull(constants$11.readlinkat$MH,"readlinkat");
- }
- public static long readlinkat ( int __fd, Addressable __path, Addressable __buf, long __len) {
- var mh$ = readlinkat$MH();
- try {
- return (long)mh$.invokeExact(__fd, __path, __buf, __len);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle unlink$MH() {
- return RuntimeHelper.requireNonNull(constants$11.unlink$MH,"unlink");
- }
- public static int unlink ( Addressable __name) {
- var mh$ = unlink$MH();
- try {
- return (int)mh$.invokeExact(__name);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle unlinkat$MH() {
- return RuntimeHelper.requireNonNull(constants$12.unlinkat$MH,"unlinkat");
- }
- public static int unlinkat ( int __fd, Addressable __name, int __flag) {
- var mh$ = unlinkat$MH();
- try {
- return (int)mh$.invokeExact(__fd, __name, __flag);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle rmdir$MH() {
- return RuntimeHelper.requireNonNull(constants$12.rmdir$MH,"rmdir");
- }
- public static int rmdir ( Addressable __path) {
- var mh$ = rmdir$MH();
- try {
- return (int)mh$.invokeExact(__path);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle tcgetpgrp$MH() {
- return RuntimeHelper.requireNonNull(constants$12.tcgetpgrp$MH,"tcgetpgrp");
- }
- public static int tcgetpgrp ( int __fd) {
- var mh$ = tcgetpgrp$MH();
- try {
- return (int)mh$.invokeExact(__fd);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle tcsetpgrp$MH() {
- return RuntimeHelper.requireNonNull(constants$12.tcsetpgrp$MH,"tcsetpgrp");
- }
- public static int tcsetpgrp ( int __fd, int __pgrp_id) {
- var mh$ = tcsetpgrp$MH();
- try {
- return (int)mh$.invokeExact(__fd, __pgrp_id);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle getlogin$MH() {
- return RuntimeHelper.requireNonNull(constants$12.getlogin$MH,"getlogin");
- }
- public static MemoryAddress getlogin () {
- var mh$ = getlogin$MH();
- try {
- return (java.lang.foreign.MemoryAddress)mh$.invokeExact();
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle getlogin_r$MH() {
- return RuntimeHelper.requireNonNull(constants$12.getlogin_r$MH,"getlogin_r");
- }
- public static int getlogin_r ( Addressable __name, long __name_len) {
- var mh$ = getlogin_r$MH();
- try {
- return (int)mh$.invokeExact(__name, __name_len);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle setlogin$MH() {
- return RuntimeHelper.requireNonNull(constants$13.setlogin$MH,"setlogin");
- }
- public static int setlogin ( Addressable __name) {
- var mh$ = setlogin$MH();
- try {
- return (int)mh$.invokeExact(__name);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MemoryLayout optarg$LAYOUT() {
- return constants$13.optarg$LAYOUT;
- }
- public static VarHandle optarg$VH() {
- return constants$13.optarg$VH;
- }
- public static MemorySegment optarg$SEGMENT() {
- return RuntimeHelper.requireNonNull(constants$13.optarg$SEGMENT,"optarg");
- }
- public static MemoryAddress optarg$get() {
- return (java.lang.foreign.MemoryAddress) constants$13.optarg$VH.get(RuntimeHelper.requireNonNull(constants$13.optarg$SEGMENT, "optarg"));
- }
- public static void optarg$set( MemoryAddress x) {
- constants$13.optarg$VH.set(RuntimeHelper.requireNonNull(constants$13.optarg$SEGMENT, "optarg"), x);
- }
- public static MemoryLayout optind$LAYOUT() {
- return constants$13.optind$LAYOUT;
- }
- public static VarHandle optind$VH() {
- return constants$13.optind$VH;
- }
- public static MemorySegment optind$SEGMENT() {
- return RuntimeHelper.requireNonNull(constants$13.optind$SEGMENT,"optind");
- }
- public static int optind$get() {
- return (int) constants$13.optind$VH.get(RuntimeHelper.requireNonNull(constants$13.optind$SEGMENT, "optind"));
- }
- public static void optind$set( int x) {
- constants$13.optind$VH.set(RuntimeHelper.requireNonNull(constants$13.optind$SEGMENT, "optind"), x);
- }
- public static MemoryLayout opterr$LAYOUT() {
- return constants$13.opterr$LAYOUT;
- }
- public static VarHandle opterr$VH() {
- return constants$13.opterr$VH;
- }
- public static MemorySegment opterr$SEGMENT() {
- return RuntimeHelper.requireNonNull(constants$13.opterr$SEGMENT,"opterr");
- }
- public static int opterr$get() {
- return (int) constants$13.opterr$VH.get(RuntimeHelper.requireNonNull(constants$13.opterr$SEGMENT, "opterr"));
- }
- public static void opterr$set( int x) {
- constants$13.opterr$VH.set(RuntimeHelper.requireNonNull(constants$13.opterr$SEGMENT, "opterr"), x);
- }
- public static MemoryLayout optopt$LAYOUT() {
- return constants$13.optopt$LAYOUT;
- }
- public static VarHandle optopt$VH() {
- return constants$13.optopt$VH;
- }
- public static MemorySegment optopt$SEGMENT() {
- return RuntimeHelper.requireNonNull(constants$13.optopt$SEGMENT,"optopt");
- }
- public static int optopt$get() {
- return (int) constants$13.optopt$VH.get(RuntimeHelper.requireNonNull(constants$13.optopt$SEGMENT, "optopt"));
- }
- public static void optopt$set( int x) {
- constants$13.optopt$VH.set(RuntimeHelper.requireNonNull(constants$13.optopt$SEGMENT, "optopt"), x);
- }
- public static MethodHandle getopt$MH() {
- return RuntimeHelper.requireNonNull(constants$13.getopt$MH,"getopt");
- }
- public static int getopt ( int ___argc, Addressable ___argv, Addressable __shortopts) {
- var mh$ = getopt$MH();
- try {
- return (int)mh$.invokeExact(___argc, ___argv, __shortopts);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle gethostname$MH() {
- return RuntimeHelper.requireNonNull(constants$14.gethostname$MH,"gethostname");
- }
- public static int gethostname ( Addressable __name, long __len) {
- var mh$ = gethostname$MH();
- try {
- return (int)mh$.invokeExact(__name, __len);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle sethostname$MH() {
- return RuntimeHelper.requireNonNull(constants$14.sethostname$MH,"sethostname");
- }
- public static int sethostname ( Addressable __name, long __len) {
- var mh$ = sethostname$MH();
- try {
- return (int)mh$.invokeExact(__name, __len);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle sethostid$MH() {
- return RuntimeHelper.requireNonNull(constants$14.sethostid$MH,"sethostid");
- }
- public static int sethostid ( long __id) {
- var mh$ = sethostid$MH();
- try {
- return (int)mh$.invokeExact(__id);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle getdomainname$MH() {
- return RuntimeHelper.requireNonNull(constants$14.getdomainname$MH,"getdomainname");
- }
- public static int getdomainname ( Addressable __name, long __len) {
- var mh$ = getdomainname$MH();
- try {
- return (int)mh$.invokeExact(__name, __len);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle setdomainname$MH() {
- return RuntimeHelper.requireNonNull(constants$14.setdomainname$MH,"setdomainname");
- }
- public static int setdomainname ( Addressable __name, long __len) {
- var mh$ = setdomainname$MH();
- try {
- return (int)mh$.invokeExact(__name, __len);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle vhangup$MH() {
- return RuntimeHelper.requireNonNull(constants$14.vhangup$MH,"vhangup");
- }
- public static int vhangup () {
- var mh$ = vhangup$MH();
- try {
- return (int)mh$.invokeExact();
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle revoke$MH() {
- return RuntimeHelper.requireNonNull(constants$15.revoke$MH,"revoke");
- }
- public static int revoke ( Addressable __file) {
- var mh$ = revoke$MH();
- try {
- return (int)mh$.invokeExact(__file);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle profil$MH() {
- return RuntimeHelper.requireNonNull(constants$15.profil$MH,"profil");
- }
- public static int profil ( Addressable __sample_buffer, long __size, long __offset, int __scale) {
- var mh$ = profil$MH();
- try {
- return (int)mh$.invokeExact(__sample_buffer, __size, __offset, __scale);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle acct$MH() {
- return RuntimeHelper.requireNonNull(constants$15.acct$MH,"acct");
- }
- public static int acct ( Addressable __name) {
- var mh$ = acct$MH();
- try {
- return (int)mh$.invokeExact(__name);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle getusershell$MH() {
- return RuntimeHelper.requireNonNull(constants$15.getusershell$MH,"getusershell");
- }
- public static MemoryAddress getusershell () {
- var mh$ = getusershell$MH();
- try {
- return (java.lang.foreign.MemoryAddress)mh$.invokeExact();
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle endusershell$MH() {
- return RuntimeHelper.requireNonNull(constants$15.endusershell$MH,"endusershell");
- }
- public static void endusershell () {
- var mh$ = endusershell$MH();
- try {
- mh$.invokeExact();
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle setusershell$MH() {
- return RuntimeHelper.requireNonNull(constants$15.setusershell$MH,"setusershell");
- }
- public static void setusershell () {
- var mh$ = setusershell$MH();
- try {
- mh$.invokeExact();
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle daemon$MH() {
- return RuntimeHelper.requireNonNull(constants$16.daemon$MH,"daemon");
- }
- public static int daemon ( int __nochdir, int __noclose) {
- var mh$ = daemon$MH();
- try {
- return (int)mh$.invokeExact(__nochdir, __noclose);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle chroot$MH() {
- return RuntimeHelper.requireNonNull(constants$16.chroot$MH,"chroot");
- }
- public static int chroot ( Addressable __path) {
- var mh$ = chroot$MH();
- try {
- return (int)mh$.invokeExact(__path);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle getpass$MH() {
- return RuntimeHelper.requireNonNull(constants$16.getpass$MH,"getpass");
- }
- public static MemoryAddress getpass ( Addressable __prompt) {
- var mh$ = getpass$MH();
- try {
- return (java.lang.foreign.MemoryAddress)mh$.invokeExact(__prompt);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle fsync$MH() {
- return RuntimeHelper.requireNonNull(constants$16.fsync$MH,"fsync");
- }
- public static int fsync ( int __fd) {
- var mh$ = fsync$MH();
- try {
- return (int)mh$.invokeExact(__fd);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle gethostid$MH() {
- return RuntimeHelper.requireNonNull(constants$16.gethostid$MH,"gethostid");
- }
- public static long gethostid () {
- var mh$ = gethostid$MH();
- try {
- return (long)mh$.invokeExact();
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle sync$MH() {
- return RuntimeHelper.requireNonNull(constants$16.sync$MH,"sync");
- }
- public static void sync () {
- var mh$ = sync$MH();
- try {
- mh$.invokeExact();
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle getpagesize$MH() {
- return RuntimeHelper.requireNonNull(constants$17.getpagesize$MH,"getpagesize");
- }
- public static int getpagesize () {
- var mh$ = getpagesize$MH();
- try {
- return (int)mh$.invokeExact();
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle getdtablesize$MH() {
- return RuntimeHelper.requireNonNull(constants$17.getdtablesize$MH,"getdtablesize");
- }
- public static int getdtablesize () {
- var mh$ = getdtablesize$MH();
- try {
- return (int)mh$.invokeExact();
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle truncate$MH() {
- return RuntimeHelper.requireNonNull(constants$17.truncate$MH,"truncate");
- }
- public static int truncate ( Addressable __file, long __length) {
- var mh$ = truncate$MH();
- try {
- return (int)mh$.invokeExact(__file, __length);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle ftruncate$MH() {
- return RuntimeHelper.requireNonNull(constants$17.ftruncate$MH,"ftruncate");
- }
- public static int ftruncate ( int __fd, long __length) {
- var mh$ = ftruncate$MH();
- try {
- return (int)mh$.invokeExact(__fd, __length);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle brk$MH() {
- return RuntimeHelper.requireNonNull(constants$17.brk$MH,"brk");
- }
- public static int brk ( Addressable __addr) {
- var mh$ = brk$MH();
- try {
- return (int)mh$.invokeExact(__addr);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle sbrk$MH() {
- return RuntimeHelper.requireNonNull(constants$17.sbrk$MH,"sbrk");
- }
- public static MemoryAddress sbrk ( long __delta) {
- var mh$ = sbrk$MH();
- try {
- return (java.lang.foreign.MemoryAddress)mh$.invokeExact(__delta);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle syscall$MH() {
- return RuntimeHelper.requireNonNull(constants$18.syscall$MH,"syscall");
- }
- public static long syscall ( long __sysno, Object... x1) {
- var mh$ = syscall$MH();
- try {
- return (long)mh$.invokeExact(__sysno, x1);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle lockf$MH() {
- return RuntimeHelper.requireNonNull(constants$18.lockf$MH,"lockf");
- }
- public static int lockf ( int __fd, int __cmd, long __len) {
- var mh$ = lockf$MH();
- try {
- return (int)mh$.invokeExact(__fd, __cmd, __len);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle fdatasync$MH() {
- return RuntimeHelper.requireNonNull(constants$18.fdatasync$MH,"fdatasync");
- }
- public static int fdatasync ( int __fildes) {
- var mh$ = fdatasync$MH();
- try {
- return (int)mh$.invokeExact(__fildes);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle crypt$MH() {
- return RuntimeHelper.requireNonNull(constants$18.crypt$MH,"crypt");
- }
- public static MemoryAddress crypt ( Addressable __key, Addressable __salt) {
- var mh$ = crypt$MH();
- try {
- return (java.lang.foreign.MemoryAddress)mh$.invokeExact(__key, __salt);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle getentropy$MH() {
- return RuntimeHelper.requireNonNull(constants$18.getentropy$MH,"getentropy");
- }
- public static int getentropy ( Addressable __buffer, long __length) {
- var mh$ = getentropy$MH();
- try {
- return (int)mh$.invokeExact(__buffer, __length);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static long _POSIX_C_SOURCE() {
- return 200809L;
- }
- public static int __TIMESIZE() {
- return (int)64L;
- }
- public static long __STDC_IEC_60559_BFP__() {
- return 201404L;
- }
- public static long __STDC_IEC_60559_COMPLEX__() {
- return 201404L;
- }
- public static long __STDC_ISO_10646__() {
- return 201706L;
- }
- public static long _POSIX_VERSION() {
- return 200809L;
- }
- public static long __POSIX2_THIS_VERSION() {
- return 200809L;
- }
- public static long _POSIX2_VERSION() {
- return 200809L;
- }
- public static long _POSIX2_C_VERSION() {
- return 200809L;
- }
- public static long _POSIX2_C_BIND() {
- return 200809L;
- }
- public static long _POSIX2_C_DEV() {
- return 200809L;
- }
- public static long _POSIX2_SW_DEV() {
- return 200809L;
- }
- public static long _POSIX2_LOCALEDEF() {
- return 200809L;
- }
- public static long _POSIX_PRIORITY_SCHEDULING() {
- return 200809L;
- }
- public static long _POSIX_SYNCHRONIZED_IO() {
- return 200809L;
- }
- public static long _POSIX_FSYNC() {
- return 200809L;
- }
- public static long _POSIX_MAPPED_FILES() {
- return 200809L;
- }
- public static long _POSIX_MEMLOCK() {
- return 200809L;
- }
- public static long _POSIX_MEMLOCK_RANGE() {
- return 200809L;
- }
- public static long _POSIX_MEMORY_PROTECTION() {
- return 200809L;
- }
- public static int _POSIX_VDISABLE() {
- return (int)0L;
- }
- public static long _POSIX_THREADS() {
- return 200809L;
- }
- public static long _POSIX_THREAD_SAFE_FUNCTIONS() {
- return 200809L;
- }
- public static long _POSIX_THREAD_PRIORITY_SCHEDULING() {
- return 200809L;
- }
- public static long _POSIX_THREAD_ATTR_STACKSIZE() {
- return 200809L;
- }
- public static long _POSIX_THREAD_ATTR_STACKADDR() {
- return 200809L;
- }
- public static long _POSIX_THREAD_PRIO_INHERIT() {
- return 200809L;
- }
- public static long _POSIX_THREAD_PRIO_PROTECT() {
- return 200809L;
- }
- public static long _POSIX_THREAD_ROBUST_PRIO_INHERIT() {
- return 200809L;
- }
- public static int _POSIX_THREAD_ROBUST_PRIO_PROTECT() {
- return (int)-1L;
- }
- public static long _POSIX_SEMAPHORES() {
- return 200809L;
- }
- public static long _POSIX_REALTIME_SIGNALS() {
- return 200809L;
- }
- public static long _POSIX_ASYNCHRONOUS_IO() {
- return 200809L;
- }
- public static long _POSIX_PRIORITIZED_IO() {
- return 200809L;
- }
- public static long _POSIX_SHARED_MEMORY_OBJECTS() {
- return 200809L;
- }
- public static long _POSIX_READER_WRITER_LOCKS() {
- return 200809L;
- }
- public static long _POSIX_TIMEOUTS() {
- return 200809L;
- }
- public static long _POSIX_SPIN_LOCKS() {
- return 200809L;
- }
- public static long _POSIX_SPAWN() {
- return 200809L;
- }
- public static long _POSIX_TIMERS() {
- return 200809L;
- }
- public static long _POSIX_BARRIERS() {
- return 200809L;
- }
- public static long _POSIX_MESSAGE_PASSING() {
- return 200809L;
- }
- public static long _POSIX_THREAD_PROCESS_SHARED() {
- return 200809L;
- }
- public static long _POSIX_CLOCK_SELECTION() {
- return 200809L;
- }
- public static long _POSIX_ADVISORY_INFO() {
- return 200809L;
- }
- public static long _POSIX_IPV6() {
- return 200809L;
- }
- public static long _POSIX_RAW_SOCKETS() {
- return 200809L;
- }
- public static long _POSIX2_CHAR_TERM() {
- return 200809L;
- }
- public static int _POSIX_SPORADIC_SERVER() {
- return (int)-1L;
- }
- public static int _POSIX_THREAD_SPORADIC_SERVER() {
- return (int)-1L;
- }
- public static int _POSIX_TRACE() {
- return (int)-1L;
- }
- public static int _POSIX_TRACE_EVENT_FILTER() {
- return (int)-1L;
- }
- public static int _POSIX_TRACE_INHERIT() {
- return (int)-1L;
- }
- public static int _POSIX_TRACE_LOG() {
- return (int)-1L;
- }
- public static int _POSIX_TYPED_MEMORY_OBJECTS() {
- return (int)-1L;
- }
- public static int _POSIX_V7_LPBIG_OFFBIG() {
- return (int)-1L;
- }
- public static int _POSIX_V6_LPBIG_OFFBIG() {
- return (int)-1L;
- }
- public static int _XBS5_LPBIG_OFFBIG() {
- return (int)-1L;
- }
- public static MemorySegment __ILP32_OFF32_CFLAGS() {
- return constants$18.__ILP32_OFF32_CFLAGS$SEGMENT;
- }
- public static MemorySegment __ILP32_OFF32_LDFLAGS() {
- return constants$19.__ILP32_OFF32_LDFLAGS$SEGMENT;
- }
- public static MemorySegment __ILP32_OFFBIG_CFLAGS() {
- return constants$19.__ILP32_OFFBIG_CFLAGS$SEGMENT;
- }
- public static MemorySegment __ILP32_OFFBIG_LDFLAGS() {
- return constants$19.__ILP32_OFFBIG_LDFLAGS$SEGMENT;
- }
- public static MemorySegment __LP64_OFF64_CFLAGS() {
- return constants$19.__LP64_OFF64_CFLAGS$SEGMENT;
- }
- public static MemorySegment __LP64_OFF64_LDFLAGS() {
- return constants$19.__LP64_OFF64_LDFLAGS$SEGMENT;
- }
- public static MemoryAddress NULL() {
- return constants$19.NULL$ADDR;
- }
- public static int L_SET() {
- return (int)0L;
- }
- public static int L_INCR() {
- return (int)1L;
- }
- public static int L_XTND() {
- return (int)2L;
- }
- public static int _SC_PAGE_SIZE() {
- return (int)30L;
- }
- public static int _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS() {
- return (int)1L;
- }
- public static int _CS_POSIX_V5_WIDTH_RESTRICTED_ENVS() {
- return (int)4L;
- }
- public static int _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS() {
- return (int)5L;
- }
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/__kernel_fd_set.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/__kernel_fd_set.java
deleted file mode 100644
index 3d447c24..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/__kernel_fd_set.java
+++ /dev/null
@@ -1,25 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.usbdevice_fs;
-
-import java.lang.foreign.*;
-public class __kernel_fd_set {
-
- static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
- MemoryLayout.sequenceLayout(16, Constants$root.C_LONG_LONG$LAYOUT).withName("fds_bits")
- );
- public static MemoryLayout $LAYOUT() {
- return __kernel_fd_set.$struct$LAYOUT;
- }
- public static MemorySegment fds_bits$slice(MemorySegment seg) {
- return seg.asSlice(0, 128);
- }
- public static long sizeof() { return $LAYOUT().byteSize(); }
- public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
- public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
- return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
- }
- public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/__kernel_fsid_t.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/__kernel_fsid_t.java
deleted file mode 100644
index 1122a232..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/__kernel_fsid_t.java
+++ /dev/null
@@ -1,25 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.usbdevice_fs;
-
-import java.lang.foreign.*;
-public class __kernel_fsid_t {
-
- static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
- MemoryLayout.sequenceLayout(2, Constants$root.C_INT$LAYOUT).withName("val")
- );
- public static MemoryLayout $LAYOUT() {
- return __kernel_fsid_t.$struct$LAYOUT;
- }
- public static MemorySegment val$slice(MemorySegment seg) {
- return seg.asSlice(0, 8);
- }
- public static long sizeof() { return $LAYOUT().byteSize(); }
- public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
- public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
- return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
- }
- public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/__kernel_sighandler_t.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/__kernel_sighandler_t.java
deleted file mode 100644
index 43fc2525..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/__kernel_sighandler_t.java
+++ /dev/null
@@ -1,27 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.usbdevice_fs;
-
-import java.lang.foreign.Addressable;
-import java.lang.foreign.MemoryAddress;
-import java.lang.foreign.MemorySegment;
-import java.lang.foreign.MemorySession;
-public interface __kernel_sighandler_t {
-
- void apply(int _x0);
- static MemorySegment allocate(__kernel_sighandler_t fi, MemorySession session) {
- return RuntimeHelper.upcallStub(__kernel_sighandler_t.class, fi, constants$0.__kernel_sighandler_t$FUNC, session);
- }
- static __kernel_sighandler_t ofAddress(MemoryAddress addr, MemorySession session) {
- MemorySegment symbol = MemorySegment.ofAddress(addr, 0, session);
- return (int __x0) -> {
- try {
- constants$0.__kernel_sighandler_t$MH.invokeExact((Addressable)symbol, __x0);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- };
- }
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$0.java
deleted file mode 100644
index d455d82c..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/constants$0.java
+++ /dev/null
@@ -1,21 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.usbdevice_fs;
-
-import java.lang.foreign.FunctionDescriptor;
-import java.lang.foreign.MemorySegment;
-import java.lang.invoke.MethodHandle;
-class constants$0 {
-
- static final FunctionDescriptor __kernel_sighandler_t$FUNC = FunctionDescriptor.ofVoid(
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle __kernel_sighandler_t$MH = RuntimeHelper.downcallHandle(
- constants$0.__kernel_sighandler_t$FUNC
- );
- static final MemorySegment REISERFS_SUPER_MAGIC_STRING$SEGMENT = RuntimeHelper.CONSTANT_ALLOCATOR.allocateUtf8String("ReIsErFs");
- static final MemorySegment REISER2FS_SUPER_MAGIC_STRING$SEGMENT = RuntimeHelper.CONSTANT_ALLOCATOR.allocateUtf8String("ReIsEr2Fs");
- static final MemorySegment REISER2FS_JR_SUPER_MAGIC_STRING$SEGMENT = RuntimeHelper.CONSTANT_ALLOCATOR.allocateUtf8String("ReIsEr3Fs");
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_connectinfo.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_connectinfo.java
deleted file mode 100644
index 0ad90f26..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_connectinfo.java
+++ /dev/null
@@ -1,57 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.usbdevice_fs;
-
-import java.lang.foreign.*;
-import java.lang.invoke.VarHandle;
-public class usbdevfs_connectinfo {
-
- static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
- Constants$root.C_INT$LAYOUT.withName("devnum"),
- Constants$root.C_CHAR$LAYOUT.withName("slow"),
- MemoryLayout.paddingLayout(24)
- ).withName("usbdevfs_connectinfo");
- public static MemoryLayout $LAYOUT() {
- return usbdevfs_connectinfo.$struct$LAYOUT;
- }
- static final VarHandle devnum$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("devnum"));
- public static VarHandle devnum$VH() {
- return usbdevfs_connectinfo.devnum$VH;
- }
- public static int devnum$get(MemorySegment seg) {
- return (int)usbdevfs_connectinfo.devnum$VH.get(seg);
- }
- public static void devnum$set( MemorySegment seg, int x) {
- usbdevfs_connectinfo.devnum$VH.set(seg, x);
- }
- public static int devnum$get(MemorySegment seg, long index) {
- return (int)usbdevfs_connectinfo.devnum$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void devnum$set(MemorySegment seg, long index, int x) {
- usbdevfs_connectinfo.devnum$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle slow$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("slow"));
- public static VarHandle slow$VH() {
- return usbdevfs_connectinfo.slow$VH;
- }
- public static byte slow$get(MemorySegment seg) {
- return (byte)usbdevfs_connectinfo.slow$VH.get(seg);
- }
- public static void slow$set( MemorySegment seg, byte x) {
- usbdevfs_connectinfo.slow$VH.set(seg, x);
- }
- public static byte slow$get(MemorySegment seg, long index) {
- return (byte)usbdevfs_connectinfo.slow$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void slow$set(MemorySegment seg, long index, byte x) {
- usbdevfs_connectinfo.slow$VH.set(seg.asSlice(index*sizeof()), x);
- }
- public static long sizeof() { return $LAYOUT().byteSize(); }
- public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
- public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
- return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
- }
- public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_conninfo_ex.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_conninfo_ex.java
deleted file mode 100644
index 3279b19a..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_conninfo_ex.java
+++ /dev/null
@@ -1,111 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.usbdevice_fs;
-
-import java.lang.foreign.*;
-import java.lang.invoke.VarHandle;
-public class usbdevfs_conninfo_ex {
-
- static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
- Constants$root.C_INT$LAYOUT.withName("size"),
- Constants$root.C_INT$LAYOUT.withName("busnum"),
- Constants$root.C_INT$LAYOUT.withName("devnum"),
- Constants$root.C_INT$LAYOUT.withName("speed"),
- Constants$root.C_CHAR$LAYOUT.withName("num_ports"),
- MemoryLayout.sequenceLayout(7, Constants$root.C_CHAR$LAYOUT).withName("ports")
- ).withName("usbdevfs_conninfo_ex");
- public static MemoryLayout $LAYOUT() {
- return usbdevfs_conninfo_ex.$struct$LAYOUT;
- }
- static final VarHandle size$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("size"));
- public static VarHandle size$VH() {
- return usbdevfs_conninfo_ex.size$VH;
- }
- public static int size$get(MemorySegment seg) {
- return (int)usbdevfs_conninfo_ex.size$VH.get(seg);
- }
- public static void size$set( MemorySegment seg, int x) {
- usbdevfs_conninfo_ex.size$VH.set(seg, x);
- }
- public static int size$get(MemorySegment seg, long index) {
- return (int)usbdevfs_conninfo_ex.size$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void size$set(MemorySegment seg, long index, int x) {
- usbdevfs_conninfo_ex.size$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle busnum$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("busnum"));
- public static VarHandle busnum$VH() {
- return usbdevfs_conninfo_ex.busnum$VH;
- }
- public static int busnum$get(MemorySegment seg) {
- return (int)usbdevfs_conninfo_ex.busnum$VH.get(seg);
- }
- public static void busnum$set( MemorySegment seg, int x) {
- usbdevfs_conninfo_ex.busnum$VH.set(seg, x);
- }
- public static int busnum$get(MemorySegment seg, long index) {
- return (int)usbdevfs_conninfo_ex.busnum$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void busnum$set(MemorySegment seg, long index, int x) {
- usbdevfs_conninfo_ex.busnum$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle devnum$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("devnum"));
- public static VarHandle devnum$VH() {
- return usbdevfs_conninfo_ex.devnum$VH;
- }
- public static int devnum$get(MemorySegment seg) {
- return (int)usbdevfs_conninfo_ex.devnum$VH.get(seg);
- }
- public static void devnum$set( MemorySegment seg, int x) {
- usbdevfs_conninfo_ex.devnum$VH.set(seg, x);
- }
- public static int devnum$get(MemorySegment seg, long index) {
- return (int)usbdevfs_conninfo_ex.devnum$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void devnum$set(MemorySegment seg, long index, int x) {
- usbdevfs_conninfo_ex.devnum$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle speed$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("speed"));
- public static VarHandle speed$VH() {
- return usbdevfs_conninfo_ex.speed$VH;
- }
- public static int speed$get(MemorySegment seg) {
- return (int)usbdevfs_conninfo_ex.speed$VH.get(seg);
- }
- public static void speed$set( MemorySegment seg, int x) {
- usbdevfs_conninfo_ex.speed$VH.set(seg, x);
- }
- public static int speed$get(MemorySegment seg, long index) {
- return (int)usbdevfs_conninfo_ex.speed$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void speed$set(MemorySegment seg, long index, int x) {
- usbdevfs_conninfo_ex.speed$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle num_ports$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("num_ports"));
- public static VarHandle num_ports$VH() {
- return usbdevfs_conninfo_ex.num_ports$VH;
- }
- public static byte num_ports$get(MemorySegment seg) {
- return (byte)usbdevfs_conninfo_ex.num_ports$VH.get(seg);
- }
- public static void num_ports$set( MemorySegment seg, byte x) {
- usbdevfs_conninfo_ex.num_ports$VH.set(seg, x);
- }
- public static byte num_ports$get(MemorySegment seg, long index) {
- return (byte)usbdevfs_conninfo_ex.num_ports$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void num_ports$set(MemorySegment seg, long index, byte x) {
- usbdevfs_conninfo_ex.num_ports$VH.set(seg.asSlice(index*sizeof()), x);
- }
- public static MemorySegment ports$slice(MemorySegment seg) {
- return seg.asSlice(17, 7);
- }
- public static long sizeof() { return $LAYOUT().byteSize(); }
- public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
- public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
- return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
- }
- public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_disconnect_claim.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_disconnect_claim.java
deleted file mode 100644
index 023757d7..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_disconnect_claim.java
+++ /dev/null
@@ -1,60 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.usbdevice_fs;
-
-import java.lang.foreign.*;
-import java.lang.invoke.VarHandle;
-public class usbdevfs_disconnect_claim {
-
- static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
- Constants$root.C_INT$LAYOUT.withName("interface"),
- Constants$root.C_INT$LAYOUT.withName("flags"),
- MemoryLayout.sequenceLayout(256, Constants$root.C_CHAR$LAYOUT).withName("driver")
- ).withName("usbdevfs_disconnect_claim");
- public static MemoryLayout $LAYOUT() {
- return usbdevfs_disconnect_claim.$struct$LAYOUT;
- }
- static final VarHandle interface_$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("interface"));
- public static VarHandle interface_$VH() {
- return usbdevfs_disconnect_claim.interface_$VH;
- }
- public static int interface_$get(MemorySegment seg) {
- return (int)usbdevfs_disconnect_claim.interface_$VH.get(seg);
- }
- public static void interface_$set( MemorySegment seg, int x) {
- usbdevfs_disconnect_claim.interface_$VH.set(seg, x);
- }
- public static int interface_$get(MemorySegment seg, long index) {
- return (int)usbdevfs_disconnect_claim.interface_$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void interface_$set(MemorySegment seg, long index, int x) {
- usbdevfs_disconnect_claim.interface_$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle flags$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("flags"));
- public static VarHandle flags$VH() {
- return usbdevfs_disconnect_claim.flags$VH;
- }
- public static int flags$get(MemorySegment seg) {
- return (int)usbdevfs_disconnect_claim.flags$VH.get(seg);
- }
- public static void flags$set( MemorySegment seg, int x) {
- usbdevfs_disconnect_claim.flags$VH.set(seg, x);
- }
- public static int flags$get(MemorySegment seg, long index) {
- return (int)usbdevfs_disconnect_claim.flags$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void flags$set(MemorySegment seg, long index, int x) {
- usbdevfs_disconnect_claim.flags$VH.set(seg.asSlice(index*sizeof()), x);
- }
- public static MemorySegment driver$slice(MemorySegment seg) {
- return seg.asSlice(8, 256);
- }
- public static long sizeof() { return $LAYOUT().byteSize(); }
- public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
- public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
- return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
- }
- public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_disconnectsignal.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_disconnectsignal.java
deleted file mode 100644
index 97bf5c5e..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_disconnectsignal.java
+++ /dev/null
@@ -1,57 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.usbdevice_fs;
-
-import java.lang.foreign.*;
-import java.lang.invoke.VarHandle;
-public class usbdevfs_disconnectsignal {
-
- static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
- Constants$root.C_INT$LAYOUT.withName("signr"),
- MemoryLayout.paddingLayout(32),
- Constants$root.C_POINTER$LAYOUT.withName("context")
- ).withName("usbdevfs_disconnectsignal");
- public static MemoryLayout $LAYOUT() {
- return usbdevfs_disconnectsignal.$struct$LAYOUT;
- }
- static final VarHandle signr$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("signr"));
- public static VarHandle signr$VH() {
- return usbdevfs_disconnectsignal.signr$VH;
- }
- public static int signr$get(MemorySegment seg) {
- return (int)usbdevfs_disconnectsignal.signr$VH.get(seg);
- }
- public static void signr$set( MemorySegment seg, int x) {
- usbdevfs_disconnectsignal.signr$VH.set(seg, x);
- }
- public static int signr$get(MemorySegment seg, long index) {
- return (int)usbdevfs_disconnectsignal.signr$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void signr$set(MemorySegment seg, long index, int x) {
- usbdevfs_disconnectsignal.signr$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle context$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("context"));
- public static VarHandle context$VH() {
- return usbdevfs_disconnectsignal.context$VH;
- }
- public static MemoryAddress context$get(MemorySegment seg) {
- return (java.lang.foreign.MemoryAddress)usbdevfs_disconnectsignal.context$VH.get(seg);
- }
- public static void context$set( MemorySegment seg, MemoryAddress x) {
- usbdevfs_disconnectsignal.context$VH.set(seg, x);
- }
- public static MemoryAddress context$get(MemorySegment seg, long index) {
- return (java.lang.foreign.MemoryAddress)usbdevfs_disconnectsignal.context$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void context$set(MemorySegment seg, long index, MemoryAddress x) {
- usbdevfs_disconnectsignal.context$VH.set(seg.asSlice(index*sizeof()), x);
- }
- public static long sizeof() { return $LAYOUT().byteSize(); }
- public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
- public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
- return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
- }
- public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_getdriver.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_getdriver.java
deleted file mode 100644
index 50208d87..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_getdriver.java
+++ /dev/null
@@ -1,43 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.usbdevice_fs;
-
-import java.lang.foreign.*;
-import java.lang.invoke.VarHandle;
-public class usbdevfs_getdriver {
-
- static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
- Constants$root.C_INT$LAYOUT.withName("interface"),
- MemoryLayout.sequenceLayout(256, Constants$root.C_CHAR$LAYOUT).withName("driver")
- ).withName("usbdevfs_getdriver");
- public static MemoryLayout $LAYOUT() {
- return usbdevfs_getdriver.$struct$LAYOUT;
- }
- static final VarHandle interface_$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("interface"));
- public static VarHandle interface_$VH() {
- return usbdevfs_getdriver.interface_$VH;
- }
- public static int interface_$get(MemorySegment seg) {
- return (int)usbdevfs_getdriver.interface_$VH.get(seg);
- }
- public static void interface_$set( MemorySegment seg, int x) {
- usbdevfs_getdriver.interface_$VH.set(seg, x);
- }
- public static int interface_$get(MemorySegment seg, long index) {
- return (int)usbdevfs_getdriver.interface_$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void interface_$set(MemorySegment seg, long index, int x) {
- usbdevfs_getdriver.interface_$VH.set(seg.asSlice(index*sizeof()), x);
- }
- public static MemorySegment driver$slice(MemorySegment seg) {
- return seg.asSlice(4, 256);
- }
- public static long sizeof() { return $LAYOUT().byteSize(); }
- public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
- public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
- return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
- }
- public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_hub_portinfo.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_hub_portinfo.java
deleted file mode 100644
index e7c195cd..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_hub_portinfo.java
+++ /dev/null
@@ -1,43 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.usbdevice_fs;
-
-import java.lang.foreign.*;
-import java.lang.invoke.VarHandle;
-public class usbdevfs_hub_portinfo {
-
- static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
- Constants$root.C_CHAR$LAYOUT.withName("nports"),
- MemoryLayout.sequenceLayout(127, Constants$root.C_CHAR$LAYOUT).withName("port")
- ).withName("usbdevfs_hub_portinfo");
- public static MemoryLayout $LAYOUT() {
- return usbdevfs_hub_portinfo.$struct$LAYOUT;
- }
- static final VarHandle nports$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("nports"));
- public static VarHandle nports$VH() {
- return usbdevfs_hub_portinfo.nports$VH;
- }
- public static byte nports$get(MemorySegment seg) {
- return (byte)usbdevfs_hub_portinfo.nports$VH.get(seg);
- }
- public static void nports$set( MemorySegment seg, byte x) {
- usbdevfs_hub_portinfo.nports$VH.set(seg, x);
- }
- public static byte nports$get(MemorySegment seg, long index) {
- return (byte)usbdevfs_hub_portinfo.nports$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void nports$set(MemorySegment seg, long index, byte x) {
- usbdevfs_hub_portinfo.nports$VH.set(seg.asSlice(index*sizeof()), x);
- }
- public static MemorySegment port$slice(MemorySegment seg) {
- return seg.asSlice(1, 127);
- }
- public static long sizeof() { return $LAYOUT().byteSize(); }
- public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
- public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
- return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
- }
- public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_ioctl.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_ioctl.java
deleted file mode 100644
index 35caf795..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_ioctl.java
+++ /dev/null
@@ -1,73 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.usbdevice_fs;
-
-import java.lang.foreign.*;
-import java.lang.invoke.VarHandle;
-public class usbdevfs_ioctl {
-
- static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
- Constants$root.C_INT$LAYOUT.withName("ifno"),
- Constants$root.C_INT$LAYOUT.withName("ioctl_code"),
- Constants$root.C_POINTER$LAYOUT.withName("data")
- ).withName("usbdevfs_ioctl");
- public static MemoryLayout $LAYOUT() {
- return usbdevfs_ioctl.$struct$LAYOUT;
- }
- static final VarHandle ifno$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("ifno"));
- public static VarHandle ifno$VH() {
- return usbdevfs_ioctl.ifno$VH;
- }
- public static int ifno$get(MemorySegment seg) {
- return (int)usbdevfs_ioctl.ifno$VH.get(seg);
- }
- public static void ifno$set( MemorySegment seg, int x) {
- usbdevfs_ioctl.ifno$VH.set(seg, x);
- }
- public static int ifno$get(MemorySegment seg, long index) {
- return (int)usbdevfs_ioctl.ifno$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void ifno$set(MemorySegment seg, long index, int x) {
- usbdevfs_ioctl.ifno$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle ioctl_code$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("ioctl_code"));
- public static VarHandle ioctl_code$VH() {
- return usbdevfs_ioctl.ioctl_code$VH;
- }
- public static int ioctl_code$get(MemorySegment seg) {
- return (int)usbdevfs_ioctl.ioctl_code$VH.get(seg);
- }
- public static void ioctl_code$set( MemorySegment seg, int x) {
- usbdevfs_ioctl.ioctl_code$VH.set(seg, x);
- }
- public static int ioctl_code$get(MemorySegment seg, long index) {
- return (int)usbdevfs_ioctl.ioctl_code$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void ioctl_code$set(MemorySegment seg, long index, int x) {
- usbdevfs_ioctl.ioctl_code$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle data$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("data"));
- public static VarHandle data$VH() {
- return usbdevfs_ioctl.data$VH;
- }
- public static MemoryAddress data$get(MemorySegment seg) {
- return (java.lang.foreign.MemoryAddress)usbdevfs_ioctl.data$VH.get(seg);
- }
- public static void data$set( MemorySegment seg, MemoryAddress x) {
- usbdevfs_ioctl.data$VH.set(seg, x);
- }
- public static MemoryAddress data$get(MemorySegment seg, long index) {
- return (java.lang.foreign.MemoryAddress)usbdevfs_ioctl.data$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void data$set(MemorySegment seg, long index, MemoryAddress x) {
- usbdevfs_ioctl.data$VH.set(seg.asSlice(index*sizeof()), x);
- }
- public static long sizeof() { return $LAYOUT().byteSize(); }
- public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
- public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
- return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
- }
- public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_iso_packet_desc.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_iso_packet_desc.java
deleted file mode 100644
index dcbb988b..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_iso_packet_desc.java
+++ /dev/null
@@ -1,73 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.usbdevice_fs;
-
-import java.lang.foreign.*;
-import java.lang.invoke.VarHandle;
-public class usbdevfs_iso_packet_desc {
-
- static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
- Constants$root.C_INT$LAYOUT.withName("length"),
- Constants$root.C_INT$LAYOUT.withName("actual_length"),
- Constants$root.C_INT$LAYOUT.withName("status")
- ).withName("usbdevfs_iso_packet_desc");
- public static MemoryLayout $LAYOUT() {
- return usbdevfs_iso_packet_desc.$struct$LAYOUT;
- }
- static final VarHandle length$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("length"));
- public static VarHandle length$VH() {
- return usbdevfs_iso_packet_desc.length$VH;
- }
- public static int length$get(MemorySegment seg) {
- return (int)usbdevfs_iso_packet_desc.length$VH.get(seg);
- }
- public static void length$set( MemorySegment seg, int x) {
- usbdevfs_iso_packet_desc.length$VH.set(seg, x);
- }
- public static int length$get(MemorySegment seg, long index) {
- return (int)usbdevfs_iso_packet_desc.length$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void length$set(MemorySegment seg, long index, int x) {
- usbdevfs_iso_packet_desc.length$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle actual_length$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("actual_length"));
- public static VarHandle actual_length$VH() {
- return usbdevfs_iso_packet_desc.actual_length$VH;
- }
- public static int actual_length$get(MemorySegment seg) {
- return (int)usbdevfs_iso_packet_desc.actual_length$VH.get(seg);
- }
- public static void actual_length$set( MemorySegment seg, int x) {
- usbdevfs_iso_packet_desc.actual_length$VH.set(seg, x);
- }
- public static int actual_length$get(MemorySegment seg, long index) {
- return (int)usbdevfs_iso_packet_desc.actual_length$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void actual_length$set(MemorySegment seg, long index, int x) {
- usbdevfs_iso_packet_desc.actual_length$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle status$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("status"));
- public static VarHandle status$VH() {
- return usbdevfs_iso_packet_desc.status$VH;
- }
- public static int status$get(MemorySegment seg) {
- return (int)usbdevfs_iso_packet_desc.status$VH.get(seg);
- }
- public static void status$set( MemorySegment seg, int x) {
- usbdevfs_iso_packet_desc.status$VH.set(seg, x);
- }
- public static int status$get(MemorySegment seg, long index) {
- return (int)usbdevfs_iso_packet_desc.status$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void status$set(MemorySegment seg, long index, int x) {
- usbdevfs_iso_packet_desc.status$VH.set(seg.asSlice(index*sizeof()), x);
- }
- public static long sizeof() { return $LAYOUT().byteSize(); }
- public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
- public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
- return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
- }
- public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_setinterface.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_setinterface.java
deleted file mode 100644
index 0aec7f05..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_setinterface.java
+++ /dev/null
@@ -1,56 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.usbdevice_fs;
-
-import java.lang.foreign.*;
-import java.lang.invoke.VarHandle;
-public class usbdevfs_setinterface {
-
- static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
- Constants$root.C_INT$LAYOUT.withName("interface"),
- Constants$root.C_INT$LAYOUT.withName("altsetting")
- ).withName("usbdevfs_setinterface");
- public static MemoryLayout $LAYOUT() {
- return usbdevfs_setinterface.$struct$LAYOUT;
- }
- static final VarHandle interface_$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("interface"));
- public static VarHandle interface_$VH() {
- return usbdevfs_setinterface.interface_$VH;
- }
- public static int interface_$get(MemorySegment seg) {
- return (int)usbdevfs_setinterface.interface_$VH.get(seg);
- }
- public static void interface_$set( MemorySegment seg, int x) {
- usbdevfs_setinterface.interface_$VH.set(seg, x);
- }
- public static int interface_$get(MemorySegment seg, long index) {
- return (int)usbdevfs_setinterface.interface_$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void interface_$set(MemorySegment seg, long index, int x) {
- usbdevfs_setinterface.interface_$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle altsetting$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("altsetting"));
- public static VarHandle altsetting$VH() {
- return usbdevfs_setinterface.altsetting$VH;
- }
- public static int altsetting$get(MemorySegment seg) {
- return (int)usbdevfs_setinterface.altsetting$VH.get(seg);
- }
- public static void altsetting$set( MemorySegment seg, int x) {
- usbdevfs_setinterface.altsetting$VH.set(seg, x);
- }
- public static int altsetting$get(MemorySegment seg, long index) {
- return (int)usbdevfs_setinterface.altsetting$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void altsetting$set(MemorySegment seg, long index, int x) {
- usbdevfs_setinterface.altsetting$VH.set(seg.asSlice(index*sizeof()), x);
- }
- public static long sizeof() { return $LAYOUT().byteSize(); }
- public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
- public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
- return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
- }
- public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_streams.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_streams.java
deleted file mode 100644
index 463692b3..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_streams.java
+++ /dev/null
@@ -1,57 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.usbdevice_fs;
-
-import java.lang.foreign.*;
-import java.lang.invoke.VarHandle;
-public class usbdevfs_streams {
-
- static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
- Constants$root.C_INT$LAYOUT.withName("num_streams"),
- Constants$root.C_INT$LAYOUT.withName("num_eps"),
- MemoryLayout.sequenceLayout(0, Constants$root.C_CHAR$LAYOUT).withName("eps")
- ).withName("usbdevfs_streams");
- public static MemoryLayout $LAYOUT() {
- return usbdevfs_streams.$struct$LAYOUT;
- }
- static final VarHandle num_streams$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("num_streams"));
- public static VarHandle num_streams$VH() {
- return usbdevfs_streams.num_streams$VH;
- }
- public static int num_streams$get(MemorySegment seg) {
- return (int)usbdevfs_streams.num_streams$VH.get(seg);
- }
- public static void num_streams$set( MemorySegment seg, int x) {
- usbdevfs_streams.num_streams$VH.set(seg, x);
- }
- public static int num_streams$get(MemorySegment seg, long index) {
- return (int)usbdevfs_streams.num_streams$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void num_streams$set(MemorySegment seg, long index, int x) {
- usbdevfs_streams.num_streams$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle num_eps$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("num_eps"));
- public static VarHandle num_eps$VH() {
- return usbdevfs_streams.num_eps$VH;
- }
- public static int num_eps$get(MemorySegment seg) {
- return (int)usbdevfs_streams.num_eps$VH.get(seg);
- }
- public static void num_eps$set( MemorySegment seg, int x) {
- usbdevfs_streams.num_eps$VH.set(seg, x);
- }
- public static int num_eps$get(MemorySegment seg, long index) {
- return (int)usbdevfs_streams.num_eps$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void num_eps$set(MemorySegment seg, long index, int x) {
- usbdevfs_streams.num_eps$VH.set(seg.asSlice(index*sizeof()), x);
- }
- public static long sizeof() { return $LAYOUT().byteSize(); }
- public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
- public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
- return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
- }
- public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_urb.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_urb.java
deleted file mode 100644
index 5ffb8ae3..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevfs_urb.java
+++ /dev/null
@@ -1,252 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.linux.gen.usbdevice_fs;
-
-import java.lang.foreign.*;
-import java.lang.invoke.VarHandle;
-public class usbdevfs_urb {
-
- static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
- Constants$root.C_CHAR$LAYOUT.withName("type"),
- Constants$root.C_CHAR$LAYOUT.withName("endpoint"),
- MemoryLayout.paddingLayout(16),
- Constants$root.C_INT$LAYOUT.withName("status"),
- Constants$root.C_INT$LAYOUT.withName("flags"),
- MemoryLayout.paddingLayout(32),
- Constants$root.C_POINTER$LAYOUT.withName("buffer"),
- Constants$root.C_INT$LAYOUT.withName("buffer_length"),
- Constants$root.C_INT$LAYOUT.withName("actual_length"),
- Constants$root.C_INT$LAYOUT.withName("start_frame"),
- MemoryLayout.unionLayout(
- Constants$root.C_INT$LAYOUT.withName("number_of_packets"),
- Constants$root.C_INT$LAYOUT.withName("stream_id")
- ).withName("$anon$0"),
- Constants$root.C_INT$LAYOUT.withName("error_count"),
- Constants$root.C_INT$LAYOUT.withName("signr"),
- Constants$root.C_POINTER$LAYOUT.withName("usercontext"),
- MemoryLayout.sequenceLayout(0, MemoryLayout.structLayout(
- Constants$root.C_INT$LAYOUT.withName("length"),
- Constants$root.C_INT$LAYOUT.withName("actual_length"),
- Constants$root.C_INT$LAYOUT.withName("status")
- ).withName("usbdevfs_iso_packet_desc")).withName("iso_frame_desc")
- ).withName("usbdevfs_urb");
- public static MemoryLayout $LAYOUT() {
- return usbdevfs_urb.$struct$LAYOUT;
- }
- static final VarHandle type$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("type"));
- public static VarHandle type$VH() {
- return usbdevfs_urb.type$VH;
- }
- public static byte type$get(MemorySegment seg) {
- return (byte)usbdevfs_urb.type$VH.get(seg);
- }
- public static void type$set( MemorySegment seg, byte x) {
- usbdevfs_urb.type$VH.set(seg, x);
- }
- public static byte type$get(MemorySegment seg, long index) {
- return (byte)usbdevfs_urb.type$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void type$set(MemorySegment seg, long index, byte x) {
- usbdevfs_urb.type$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle endpoint$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("endpoint"));
- public static VarHandle endpoint$VH() {
- return usbdevfs_urb.endpoint$VH;
- }
- public static byte endpoint$get(MemorySegment seg) {
- return (byte)usbdevfs_urb.endpoint$VH.get(seg);
- }
- public static void endpoint$set( MemorySegment seg, byte x) {
- usbdevfs_urb.endpoint$VH.set(seg, x);
- }
- public static byte endpoint$get(MemorySegment seg, long index) {
- return (byte)usbdevfs_urb.endpoint$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void endpoint$set(MemorySegment seg, long index, byte x) {
- usbdevfs_urb.endpoint$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle status$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("status"));
- public static VarHandle status$VH() {
- return usbdevfs_urb.status$VH;
- }
- public static int status$get(MemorySegment seg) {
- return (int)usbdevfs_urb.status$VH.get(seg);
- }
- public static void status$set( MemorySegment seg, int x) {
- usbdevfs_urb.status$VH.set(seg, x);
- }
- public static int status$get(MemorySegment seg, long index) {
- return (int)usbdevfs_urb.status$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void status$set(MemorySegment seg, long index, int x) {
- usbdevfs_urb.status$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle flags$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("flags"));
- public static VarHandle flags$VH() {
- return usbdevfs_urb.flags$VH;
- }
- public static int flags$get(MemorySegment seg) {
- return (int)usbdevfs_urb.flags$VH.get(seg);
- }
- public static void flags$set( MemorySegment seg, int x) {
- usbdevfs_urb.flags$VH.set(seg, x);
- }
- public static int flags$get(MemorySegment seg, long index) {
- return (int)usbdevfs_urb.flags$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void flags$set(MemorySegment seg, long index, int x) {
- usbdevfs_urb.flags$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle buffer$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("buffer"));
- public static VarHandle buffer$VH() {
- return usbdevfs_urb.buffer$VH;
- }
- public static MemoryAddress buffer$get(MemorySegment seg) {
- return (java.lang.foreign.MemoryAddress)usbdevfs_urb.buffer$VH.get(seg);
- }
- public static void buffer$set( MemorySegment seg, MemoryAddress x) {
- usbdevfs_urb.buffer$VH.set(seg, x);
- }
- public static MemoryAddress buffer$get(MemorySegment seg, long index) {
- return (java.lang.foreign.MemoryAddress)usbdevfs_urb.buffer$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void buffer$set(MemorySegment seg, long index, MemoryAddress x) {
- usbdevfs_urb.buffer$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle buffer_length$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("buffer_length"));
- public static VarHandle buffer_length$VH() {
- return usbdevfs_urb.buffer_length$VH;
- }
- public static int buffer_length$get(MemorySegment seg) {
- return (int)usbdevfs_urb.buffer_length$VH.get(seg);
- }
- public static void buffer_length$set( MemorySegment seg, int x) {
- usbdevfs_urb.buffer_length$VH.set(seg, x);
- }
- public static int buffer_length$get(MemorySegment seg, long index) {
- return (int)usbdevfs_urb.buffer_length$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void buffer_length$set(MemorySegment seg, long index, int x) {
- usbdevfs_urb.buffer_length$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle actual_length$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("actual_length"));
- public static VarHandle actual_length$VH() {
- return usbdevfs_urb.actual_length$VH;
- }
- public static int actual_length$get(MemorySegment seg) {
- return (int)usbdevfs_urb.actual_length$VH.get(seg);
- }
- public static void actual_length$set( MemorySegment seg, int x) {
- usbdevfs_urb.actual_length$VH.set(seg, x);
- }
- public static int actual_length$get(MemorySegment seg, long index) {
- return (int)usbdevfs_urb.actual_length$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void actual_length$set(MemorySegment seg, long index, int x) {
- usbdevfs_urb.actual_length$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle start_frame$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("start_frame"));
- public static VarHandle start_frame$VH() {
- return usbdevfs_urb.start_frame$VH;
- }
- public static int start_frame$get(MemorySegment seg) {
- return (int)usbdevfs_urb.start_frame$VH.get(seg);
- }
- public static void start_frame$set( MemorySegment seg, int x) {
- usbdevfs_urb.start_frame$VH.set(seg, x);
- }
- public static int start_frame$get(MemorySegment seg, long index) {
- return (int)usbdevfs_urb.start_frame$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void start_frame$set(MemorySegment seg, long index, int x) {
- usbdevfs_urb.start_frame$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle number_of_packets$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("$anon$0"), MemoryLayout.PathElement.groupElement("number_of_packets"));
- public static VarHandle number_of_packets$VH() {
- return usbdevfs_urb.number_of_packets$VH;
- }
- public static int number_of_packets$get(MemorySegment seg) {
- return (int)usbdevfs_urb.number_of_packets$VH.get(seg);
- }
- public static void number_of_packets$set( MemorySegment seg, int x) {
- usbdevfs_urb.number_of_packets$VH.set(seg, x);
- }
- public static int number_of_packets$get(MemorySegment seg, long index) {
- return (int)usbdevfs_urb.number_of_packets$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void number_of_packets$set(MemorySegment seg, long index, int x) {
- usbdevfs_urb.number_of_packets$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle stream_id$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("$anon$0"), MemoryLayout.PathElement.groupElement("stream_id"));
- public static VarHandle stream_id$VH() {
- return usbdevfs_urb.stream_id$VH;
- }
- public static int stream_id$get(MemorySegment seg) {
- return (int)usbdevfs_urb.stream_id$VH.get(seg);
- }
- public static void stream_id$set( MemorySegment seg, int x) {
- usbdevfs_urb.stream_id$VH.set(seg, x);
- }
- public static int stream_id$get(MemorySegment seg, long index) {
- return (int)usbdevfs_urb.stream_id$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void stream_id$set(MemorySegment seg, long index, int x) {
- usbdevfs_urb.stream_id$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle error_count$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("error_count"));
- public static VarHandle error_count$VH() {
- return usbdevfs_urb.error_count$VH;
- }
- public static int error_count$get(MemorySegment seg) {
- return (int)usbdevfs_urb.error_count$VH.get(seg);
- }
- public static void error_count$set( MemorySegment seg, int x) {
- usbdevfs_urb.error_count$VH.set(seg, x);
- }
- public static int error_count$get(MemorySegment seg, long index) {
- return (int)usbdevfs_urb.error_count$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void error_count$set(MemorySegment seg, long index, int x) {
- usbdevfs_urb.error_count$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle signr$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("signr"));
- public static VarHandle signr$VH() {
- return usbdevfs_urb.signr$VH;
- }
- public static int signr$get(MemorySegment seg) {
- return (int)usbdevfs_urb.signr$VH.get(seg);
- }
- public static void signr$set( MemorySegment seg, int x) {
- usbdevfs_urb.signr$VH.set(seg, x);
- }
- public static int signr$get(MemorySegment seg, long index) {
- return (int)usbdevfs_urb.signr$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void signr$set(MemorySegment seg, long index, int x) {
- usbdevfs_urb.signr$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle usercontext$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("usercontext"));
- public static VarHandle usercontext$VH() {
- return usbdevfs_urb.usercontext$VH;
- }
- public static MemoryAddress usercontext$get(MemorySegment seg) {
- return (java.lang.foreign.MemoryAddress)usbdevfs_urb.usercontext$VH.get(seg);
- }
- public static void usercontext$set( MemorySegment seg, MemoryAddress x) {
- usbdevfs_urb.usercontext$VH.set(seg, x);
- }
- public static MemoryAddress usercontext$get(MemorySegment seg, long index) {
- return (java.lang.foreign.MemoryAddress)usbdevfs_urb.usercontext$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void usercontext$set(MemorySegment seg, long index, MemoryAddress x) {
- usbdevfs_urb.usercontext$VH.set(seg.asSlice(index*sizeof()), x);
- }
- public static long sizeof() { return $LAYOUT().byteSize(); }
- public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
- public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
- return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
- }
- public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevice_fs.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevice_fs.java
index 034c4d1b..e396cb35 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevice_fs.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/usbdevice_fs/usbdevice_fs.java
@@ -2,8 +2,6 @@
package net.codecrete.usb.linux.gen.usbdevice_fs;
-import java.lang.foreign.MemorySegment;
-
import static java.lang.foreign.ValueLayout.*;
public class usbdevice_fs {
@@ -16,351 +14,6 @@ public class usbdevice_fs {
public static OfFloat C_FLOAT = Constants$root.C_FLOAT$LAYOUT;
public static OfDouble C_DOUBLE = Constants$root.C_DOUBLE$LAYOUT;
public static OfAddress C_POINTER = Constants$root.C_POINTER$LAYOUT;
- public static int __BITS_PER_LONG() {
- return (int)64L;
- }
- public static int __FD_SETSIZE() {
- return (int)1024L;
- }
- public static int ADFS_SUPER_MAGIC() {
- return (int)44533L;
- }
- public static int AFFS_SUPER_MAGIC() {
- return (int)44543L;
- }
- public static int AFS_SUPER_MAGIC() {
- return (int)1397113167L;
- }
- public static int AUTOFS_SUPER_MAGIC() {
- return (int)391L;
- }
- public static int CODA_SUPER_MAGIC() {
- return (int)1937076805L;
- }
- public static int CRAMFS_MAGIC() {
- return (int)684539205L;
- }
- public static int CRAMFS_MAGIC_WEND() {
- return (int)1161678120L;
- }
- public static int DEBUGFS_MAGIC() {
- return (int)1684170528L;
- }
- public static int SECURITYFS_MAGIC() {
- return (int)1935894131L;
- }
- public static int SMACK_MAGIC() {
- return (int)1128357203L;
- }
- public static int TMPFS_MAGIC() {
- return (int)16914836L;
- }
- public static int SQUASHFS_MAGIC() {
- return (int)1936814952L;
- }
- public static int ECRYPTFS_SUPER_MAGIC() {
- return (int)61791L;
- }
- public static int EFS_SUPER_MAGIC() {
- return (int)4278867L;
- }
- public static int EXT2_SUPER_MAGIC() {
- return (int)61267L;
- }
- public static int EXT3_SUPER_MAGIC() {
- return (int)61267L;
- }
- public static int EXT4_SUPER_MAGIC() {
- return (int)61267L;
- }
- public static int NILFS_SUPER_MAGIC() {
- return (int)13364L;
- }
- public static int ISOFS_SUPER_MAGIC() {
- return (int)38496L;
- }
- public static int JFFS2_SUPER_MAGIC() {
- return (int)29366L;
- }
- public static int XFS_SUPER_MAGIC() {
- return (int)1481003842L;
- }
- public static int PSTOREFS_MAGIC() {
- return (int)1634035564L;
- }
- public static int HOSTFS_SUPER_MAGIC() {
- return (int)12648430L;
- }
- public static int OVERLAYFS_SUPER_MAGIC() {
- return (int)2035054128L;
- }
- public static int MINIX_SUPER_MAGIC() {
- return (int)4991L;
- }
- public static int MINIX_SUPER_MAGIC2() {
- return (int)5007L;
- }
- public static int MINIX2_SUPER_MAGIC() {
- return (int)9320L;
- }
- public static int MINIX2_SUPER_MAGIC2() {
- return (int)9336L;
- }
- public static int MINIX3_SUPER_MAGIC() {
- return (int)19802L;
- }
- public static int MSDOS_SUPER_MAGIC() {
- return (int)19780L;
- }
- public static int NCP_SUPER_MAGIC() {
- return (int)22092L;
- }
- public static int NFS_SUPER_MAGIC() {
- return (int)26985L;
- }
- public static int OCFS2_SUPER_MAGIC() {
- return (int)1952539503L;
- }
- public static int OPENPROM_SUPER_MAGIC() {
- return (int)40865L;
- }
- public static int QNX4_SUPER_MAGIC() {
- return (int)47L;
- }
- public static int QNX6_SUPER_MAGIC() {
- return (int)1746473250L;
- }
- public static int AFS_FS_MAGIC() {
- return (int)1799439955L;
- }
- public static int REISERFS_SUPER_MAGIC() {
- return (int)1382369651L;
- }
- public static int SMB_SUPER_MAGIC() {
- return (int)20859L;
- }
- public static int CGROUP_SUPER_MAGIC() {
- return (int)2613483L;
- }
- public static int CGROUP2_SUPER_MAGIC() {
- return (int)1667723888L;
- }
- public static int RDTGROUP_SUPER_MAGIC() {
- return (int)124082209L;
- }
- public static int STACK_END_MAGIC() {
- return (int)1470918301L;
- }
- public static int TRACEFS_MAGIC() {
- return (int)1953653091L;
- }
- public static int V9FS_MAGIC() {
- return (int)16914839L;
- }
- public static int BDEVFS_MAGIC() {
- return (int)1650746742L;
- }
- public static int DAXFS_MAGIC() {
- return (int)1684300152L;
- }
- public static int BINFMTFS_MAGIC() {
- return (int)1112100429L;
- }
- public static int DEVPTS_SUPER_MAGIC() {
- return (int)7377L;
- }
- public static int BINDERFS_SUPER_MAGIC() {
- return (int)1819242352L;
- }
- public static int FUTEXFS_SUPER_MAGIC() {
- return (int)195894762L;
- }
- public static int PIPEFS_MAGIC() {
- return (int)1346981957L;
- }
- public static int PROC_SUPER_MAGIC() {
- return (int)40864L;
- }
- public static int SOCKFS_MAGIC() {
- return (int)1397703499L;
- }
- public static int SYSFS_MAGIC() {
- return (int)1650812274L;
- }
- public static int USBDEVICE_SUPER_MAGIC() {
- return (int)40866L;
- }
- public static int MTD_INODE_FS_MAGIC() {
- return (int)288389204L;
- }
- public static int ANON_INODE_FS_MAGIC() {
- return (int)151263540L;
- }
- public static int BTRFS_TEST_MAGIC() {
- return (int)1936880249L;
- }
- public static int NSFS_MAGIC() {
- return (int)1853056627L;
- }
- public static int AAFS_MAGIC() {
- return (int)1513908720L;
- }
- public static int ZONEFS_MAGIC() {
- return (int)1515144787L;
- }
- public static int UDF_SUPER_MAGIC() {
- return (int)352400198L;
- }
- public static int BALLOON_KVM_MAGIC() {
- return (int)325456742L;
- }
- public static int ZSMALLOC_MAGIC() {
- return (int)1479104553L;
- }
- public static int DMA_BUF_MAGIC() {
- return (int)1145913666L;
- }
- public static int DEVMEM_MAGIC() {
- return (int)1162691661L;
- }
- public static int Z3FOLD_MAGIC() {
- return (int)51L;
- }
- public static int SECRETMEM_MAGIC() {
- return (int)1397048141L;
- }
- public static int SHIFTFS_MAGIC() {
- return (int)1785031266L;
- }
- public static int USBDEVFS_MAXDRIVERNAME() {
- return (int)255L;
- }
- public static int USBDEVFS_URB_SHORT_NOT_OK() {
- return (int)1L;
- }
- public static int USBDEVFS_URB_ISO_ASAP() {
- return (int)2L;
- }
- public static int USBDEVFS_URB_BULK_CONTINUATION() {
- return (int)4L;
- }
- public static int USBDEVFS_URB_NO_FSBR() {
- return (int)32L;
- }
- public static int USBDEVFS_URB_ZERO_PACKET() {
- return (int)64L;
- }
- public static int USBDEVFS_URB_NO_INTERRUPT() {
- return (int)128L;
- }
- public static int USBDEVFS_URB_TYPE_ISO() {
- return (int)0L;
- }
- public static int USBDEVFS_URB_TYPE_INTERRUPT() {
- return (int)1L;
- }
- public static int USBDEVFS_URB_TYPE_CONTROL() {
- return (int)2L;
- }
- public static int USBDEVFS_URB_TYPE_BULK() {
- return (int)3L;
- }
- public static int USBDEVFS_CAP_ZERO_PACKET() {
- return (int)1L;
- }
- public static int USBDEVFS_CAP_BULK_CONTINUATION() {
- return (int)2L;
- }
- public static int USBDEVFS_CAP_NO_PACKET_SIZE_LIM() {
- return (int)4L;
- }
- public static int USBDEVFS_CAP_BULK_SCATTER_GATHER() {
- return (int)8L;
- }
- public static int USBDEVFS_CAP_REAP_AFTER_DISCONNECT() {
- return (int)16L;
- }
- public static int USBDEVFS_CAP_MMAP() {
- return (int)32L;
- }
- public static int USBDEVFS_CAP_DROP_PRIVILEGES() {
- return (int)64L;
- }
- public static int USBDEVFS_CAP_CONNINFO_EX() {
- return (int)128L;
- }
- public static int USBDEVFS_CAP_SUSPEND() {
- return (int)256L;
- }
- public static int USBDEVFS_DISCONNECT_CLAIM_IF_DRIVER() {
- return (int)1L;
- }
- public static int USBDEVFS_DISCONNECT_CLAIM_EXCEPT_DRIVER() {
- return (int)2L;
- }
- public static OfShort __s16 = Constants$root.C_SHORT$LAYOUT;
- public static OfInt __s32 = Constants$root.C_INT$LAYOUT;
- public static OfLong __s64 = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfInt __kernel_key_t = Constants$root.C_INT$LAYOUT;
- public static OfInt __kernel_mqd_t = Constants$root.C_INT$LAYOUT;
- public static OfLong __kernel_long_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfInt __kernel_pid_t = Constants$root.C_INT$LAYOUT;
- public static OfInt __kernel_ipc_pid_t = Constants$root.C_INT$LAYOUT;
- public static OfLong __kernel_suseconds_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfInt __kernel_daddr_t = Constants$root.C_INT$LAYOUT;
- public static OfLong __kernel_ssize_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __kernel_ptrdiff_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __kernel_off_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __kernel_loff_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __kernel_old_time_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __kernel_time_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __kernel_time64_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfLong __kernel_clock_t = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfInt __kernel_timer_t = Constants$root.C_INT$LAYOUT;
- public static OfInt __kernel_clockid_t = Constants$root.C_INT$LAYOUT;
- public static OfAddress __kernel_caddr_t = Constants$root.C_POINTER$LAYOUT;
- public static int SELINUX_MAGIC() {
- return (int)4185718668L;
- }
- public static int RAMFS_MAGIC() {
- return (int)2240043254L;
- }
- public static int HUGETLBFS_MAGIC() {
- return (int)2508478710L;
- }
- public static int EROFS_SUPER_MAGIC_V1() {
- return (int)3774210530L;
- }
- public static int XENFS_SUPER_MAGIC() {
- return (int)2881100148L;
- }
- public static int BTRFS_SUPER_MAGIC() {
- return (int)2435016766L;
- }
- public static int F2FS_SUPER_MAGIC() {
- return (int)4076150800L;
- }
- public static int HPFS_SUPER_MAGIC() {
- return (int)4187351113L;
- }
- public static int EFIVARFS_MAGIC() {
- return (int)3730735588L;
- }
- public static MemorySegment REISERFS_SUPER_MAGIC_STRING() {
- return constants$0.REISERFS_SUPER_MAGIC_STRING$SEGMENT;
- }
- public static MemorySegment REISER2FS_SUPER_MAGIC_STRING() {
- return constants$0.REISER2FS_SUPER_MAGIC_STRING$SEGMENT;
- }
- public static MemorySegment REISER2FS_JR_SUPER_MAGIC_STRING() {
- return constants$0.REISER2FS_JR_SUPER_MAGIC_STRING$SEGMENT;
- }
- public static int BPF_FS_MAGIC() {
- return (int)3405662737L;
- }
- public static int PPC_CMM_MAGIC() {
- return (int)3344373136L;
- }
}
From cc9a697b6a224cb800595fef26a767f558803a89 Mon Sep 17 00:00:00 2001
From: Manuel Bl
Date: Tue, 23 Aug 2022 20:00:10 +0200
Subject: [PATCH 007/433] jextract on Windows
---
java-does-usb/jextract/gen_win_cfgmgr32.cmd | 12 +
java-does-usb/jextract/gen_win_kernel32.cmd | 22 ++
java-does-usb/jextract/gen_win_setupapi.cmd | 22 ++
java-does-usb/jextract/gen_win_stdlib.cmd | 7 +
java-does-usb/jextract/gen_win_usbioctl.cmd | 14 ++
java-does-usb/jextract/gen_win_winusb.cmd | 16 ++
java-does-usb/jextract/gen_windows.cmd | 50 +---
java-does-usb/jextract/windows_cfgmgr32.h | 2 +
java-does-usb/jextract/windows_kernel32.h | 1 +
java-does-usb/jextract/windows_setupapi.h | 2 +
java-does-usb/jextract/windows_stdlib.h | 1 +
java-does-usb/jextract/windows_usbioctl.h | 2 +
java-does-usb/jextract/windows_winusb.h | 2 +
.../net/codecrete/usb/windows/CfgMgr32.java | 77 ------
.../net/codecrete/usb/windows/SetupApi.java | 232 +-----------------
.../java/net/codecrete/usb/windows/Win.java | 176 +------------
.../net/codecrete/usb/windows/WinUSB.java | 204 ---------------
.../usb/windows/WindowsUSBDevice.java | 42 ++--
.../usb/windows/WindowsUSBDeviceRegistry.java | 71 +++---
.../usb/windows/gen/cfgmgr32/CfgMgr32.java | 44 ++++
.../windows/gen/cfgmgr32/Constants$root.java | 19 ++
.../windows/gen/cfgmgr32/RuntimeHelper.java | 216 ++++++++++++++++
.../usb/windows/gen/cfgmgr32/constants$0.java | 30 +++
.../windows/gen/kernel32/Constants$root.java | 19 ++
.../usb/windows/gen/kernel32/Kernel32.java | 91 +++++++
.../windows/gen/kernel32/RuntimeHelper.java | 216 ++++++++++++++++
.../usb/windows/gen/kernel32/constants$0.java | 50 ++++
.../windows/gen/setupapi/Constants$root.java | 19 ++
.../windows/gen/setupapi/RuntimeHelper.java | 216 ++++++++++++++++
.../usb/windows/gen/setupapi/SetupAPI.java | 98 ++++++++
.../setupapi/_SP_DEVICE_INTERFACE_DATA.java | 82 +++++++
.../_SP_DEVICE_INTERFACE_DETAIL_DATA_W.java | 44 ++++
.../gen/setupapi/_SP_DEVINFO_DATA.java | 82 +++++++
.../usb/windows/gen/setupapi/constants$0.java | 73 ++++++
.../windows/gen/stdlib/Constants$root.java | 19 ++
.../usb/windows/gen/stdlib/RuntimeHelper.java | 216 ++++++++++++++++
.../usb/windows/gen/stdlib/StdLib.java | 33 +++
.../usb/windows/gen/stdlib/constants$0.java | 18 ++
.../windows/gen/usbioctl/Constants$root.java | 19 ++
.../windows/gen/usbioctl/RuntimeHelper.java | 216 ++++++++++++++++
.../usb/windows/gen/usbioctl/USBIoctl.java | 19 ++
.../_USB_NODE_CONNECTION_INFORMATION_EX.java | 171 +++++++++++++
.../windows/gen/winusb/Constants$root.java | 19 ++
.../usb/windows/gen/winusb/RuntimeHelper.java | 216 ++++++++++++++++
.../usb/windows/gen/winusb/WinUSB.java | 89 +++++++
.../usb/windows/gen/winusb/constants$0.java | 82 +++++++
46 files changed, 2586 insertions(+), 785 deletions(-)
create mode 100644 java-does-usb/jextract/gen_win_cfgmgr32.cmd
create mode 100644 java-does-usb/jextract/gen_win_kernel32.cmd
create mode 100644 java-does-usb/jextract/gen_win_setupapi.cmd
create mode 100644 java-does-usb/jextract/gen_win_stdlib.cmd
create mode 100644 java-does-usb/jextract/gen_win_usbioctl.cmd
create mode 100644 java-does-usb/jextract/gen_win_winusb.cmd
create mode 100644 java-does-usb/jextract/windows_cfgmgr32.h
create mode 100644 java-does-usb/jextract/windows_kernel32.h
create mode 100644 java-does-usb/jextract/windows_setupapi.h
create mode 100644 java-does-usb/jextract/windows_stdlib.h
create mode 100644 java-does-usb/jextract/windows_usbioctl.h
create mode 100644 java-does-usb/jextract/windows_winusb.h
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/CfgMgr32.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/WinUSB.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/CfgMgr32.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/Constants$root.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/RuntimeHelper.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/constants$0.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/Constants$root.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/Kernel32.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/RuntimeHelper.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/constants$0.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/Constants$root.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/RuntimeHelper.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SetupAPI.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_SP_DEVICE_INTERFACE_DATA.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_SP_DEVICE_INTERFACE_DETAIL_DATA_W.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_SP_DEVINFO_DATA.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$0.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/stdlib/Constants$root.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/stdlib/RuntimeHelper.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/stdlib/StdLib.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/stdlib/constants$0.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/Constants$root.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/RuntimeHelper.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/USBIoctl.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/_USB_NODE_CONNECTION_INFORMATION_EX.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/winusb/Constants$root.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/winusb/RuntimeHelper.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/winusb/WinUSB.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/winusb/constants$0.java
diff --git a/java-does-usb/jextract/gen_win_cfgmgr32.cmd b/java-does-usb/jextract/gen_win_cfgmgr32.cmd
new file mode 100644
index 00000000..e4bd1db9
--- /dev/null
+++ b/java-does-usb/jextract/gen_win_cfgmgr32.cmd
@@ -0,0 +1,12 @@
+set JEXTRACT=..\..\..\jextract\build\jextract\bin\jextract.bat
+set SDK_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0
+%JEXTRACT% --source --output ../src/main/java ^
+ -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
+ -I "%SDK_DIR%\um" ^
+ -I "%SDK_DIR%\shared" ^
+ -l Cfgmgr32 ^
+ --header-class-name CfgMgr32 ^
+ --target-package net.codecrete.usb.windows.gen.cfgmgr32 ^
+ --include-function CM_Get_Parent ^
+ --include-function CM_Get_Device_IDW ^
+ windows_cfgmgr32.h
diff --git a/java-does-usb/jextract/gen_win_kernel32.cmd b/java-does-usb/jextract/gen_win_kernel32.cmd
new file mode 100644
index 00000000..90af5039
--- /dev/null
+++ b/java-does-usb/jextract/gen_win_kernel32.cmd
@@ -0,0 +1,22 @@
+set JEXTRACT=..\..\..\jextract\build\jextract\bin\jextract.bat
+set SDK_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0
+%JEXTRACT% --source --output ../src/main/java ^
+ -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
+ -I "%SDK_DIR%\um" ^
+ -I "%SDK_DIR%\shared" ^
+ -l Kernel32 ^
+ --header-class-name Kernel32 ^
+ --target-package net.codecrete.usb.windows.gen.kernel32 ^
+ --include-function CreateFileW ^
+ --include-function CloseHandle ^
+ --include-function DeviceIoControl ^
+ --include-function GetLastError ^
+ --include-macro ERROR_NO_MORE_ITEMS ^
+ --include-macro GENERIC_READ ^
+ --include-macro GENERIC_WRITE ^
+ --include-macro FILE_SHARE_READ ^
+ --include-macro FILE_SHARE_WRITE ^
+ --include-macro FILE_ATTRIBUTE_NORMAL ^
+ --include-macro FILE_FLAG_OVERLAPPED ^
+ --include-macro OPEN_EXISTING ^
+ windows_kernel32.h
diff --git a/java-does-usb/jextract/gen_win_setupapi.cmd b/java-does-usb/jextract/gen_win_setupapi.cmd
new file mode 100644
index 00000000..baf7983a
--- /dev/null
+++ b/java-does-usb/jextract/gen_win_setupapi.cmd
@@ -0,0 +1,22 @@
+set JEXTRACT=..\..\..\jextract\build\jextract\bin\jextract.bat
+set SDK_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0
+%JEXTRACT% --source --output ../src/main/java ^
+ -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
+ -I "%SDK_DIR%\um" ^
+ -I "%SDK_DIR%\shared" ^
+ -l SetupAPI ^
+ --header-class-name SetupAPI ^
+ --target-package net.codecrete.usb.windows.gen.setupapi ^
+ --include-function SetupDiGetClassDevsW ^
+ --include-function SetupDiDestroyDeviceInfoList ^
+ --include-function SetupDiEnumDeviceInfo ^
+ --include-function SetupDiEnumDeviceInterfaces ^
+ --include-function SetupDiGetDeviceInterfaceDetailW ^
+ --include-function SetupDiGetDeviceRegistryPropertyW ^
+ --include-struct _SP_DEVINFO_DATA ^
+ --include-struct _SP_DEVICE_INTERFACE_DATA ^
+ --include-struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W ^
+ --include-macro DIGCF_PRESENT ^
+ --include-macro DIGCF_DEVICEINTERFACE ^
+ --include-macro SPDRP_ADDRESS ^
+ windows_setupapi.h
diff --git a/java-does-usb/jextract/gen_win_stdlib.cmd b/java-does-usb/jextract/gen_win_stdlib.cmd
new file mode 100644
index 00000000..cd387688
--- /dev/null
+++ b/java-does-usb/jextract/gen_win_stdlib.cmd
@@ -0,0 +1,7 @@
+set JEXTRACT=..\..\..\jextract\build\jextract\bin\jextract.bat
+%JEXTRACT% --source --output ../src/main/java ^
+ -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
+ --header-class-name StdLib ^
+ --target-package net.codecrete.usb.windows.gen.stdlib ^
+ --include-function wcslen ^
+ windows_stdlib.h
diff --git a/java-does-usb/jextract/gen_win_usbioctl.cmd b/java-does-usb/jextract/gen_win_usbioctl.cmd
new file mode 100644
index 00000000..b31b59b2
--- /dev/null
+++ b/java-does-usb/jextract/gen_win_usbioctl.cmd
@@ -0,0 +1,14 @@
+set JEXTRACT=..\..\..\jextract\build\jextract\bin\jextract.bat
+set SDK_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0
+%JEXTRACT% --source --output ../src/main/java ^
+ -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
+ -I "%SDK_DIR%\um" ^
+ -I "%SDK_DIR%\shared" ^
+ --header-class-name USBIoctl ^
+ --target-package net.codecrete.usb.windows.gen.usbioctl ^
+ --include-struct _USB_NODE_CONNECTION_INFORMATION_EX ^
+ windows_usbioctl.h
+
+:: Generated code is invalid: No instance of type _USB_NODE_CONNECTION_INFORMATION_EX can be created.0
+:: They crash with:
+:: java.lang.UnsupportedOperationException: Invalid alignment requirements for layout s16(DeviceAddress)
diff --git a/java-does-usb/jextract/gen_win_winusb.cmd b/java-does-usb/jextract/gen_win_winusb.cmd
new file mode 100644
index 00000000..bb52c94d
--- /dev/null
+++ b/java-does-usb/jextract/gen_win_winusb.cmd
@@ -0,0 +1,16 @@
+set JEXTRACT=..\..\..\jextract\build\jextract\bin\jextract.bat
+set SDK_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0
+%JEXTRACT% --source --output ../src/main/java ^
+ -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
+ -I "%SDK_DIR%\um" ^
+ -I "%SDK_DIR%\shared" ^
+ -l Winusb ^
+ --header-class-name WinUSB ^
+ --target-package net.codecrete.usb.windows.gen.winusb ^
+ --include-function WinUsb_Initialize ^
+ --include-function WinUsb_Free ^
+ --include-function WinUsb_GetDescriptor ^
+ --include-function WinUsb_ControlTransfer ^
+ --include-function WinUsb_WritePipe ^
+ --include-function WinUsb_ReadPipe ^
+ windows_winusb.h
diff --git a/java-does-usb/jextract/gen_windows.cmd b/java-does-usb/jextract/gen_windows.cmd
index 399b9408..f75288f1 100644
--- a/java-does-usb/jextract/gen_windows.cmd
+++ b/java-does-usb/jextract/gen_windows.cmd
@@ -1,43 +1,4 @@
-#!/bin/sh
-
-set JEXTRACT=..\..\..\jextract\build\jextract\bin\jextract
-
-:: handleapi.h
-:: Generates more than 1000 files
-:: Functions like CloseHandle() are generated multiple times but none of them in a public class
-::%JEXTRACT% --source --output ../src/main/java ^
-:: -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
-:: --header-class-name handleapi ^
-:: --target-package net.codecrete.usb.windows.gen.handleapi ^
-:: "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\handleapi.h"
-
-:: Generates code that produces run-time error:
-:: java.lang.UnsatisfiedLinkError: unresolved symbol: CloseHandle
-::%JEXTRACT% --source --output ../src/main/java ^
-:: -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
-:: --header-class-name handleapi ^
-:: --target-package net.codecrete.usb.windows.gen.handleapi ^
-:: --include-function CloseHandle ^
-:: "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\handleapi.h"
-
-:: Generates code that produces run-time error:
-:: java.lang.UnsatisfiedLinkError: unresolved symbol: CloseHandle
-::%JEXTRACT% --source --output ../src/main/java ^
-:: -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
-:: --header-class-name handleapi ^
-:: --target-package net.codecrete.usb.windows.gen.handleapi ^
-:: --include-function CloseHandle ^
-:: "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\Windows.h"
-
-:: winusb.h
-:: Fails with error:
-:: C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\shared\usb.h:32:9: error: unknown type name 'LARGE_INTEGER'
-:: winusb.h requires that certain other header files (like Windows.h) are processed first
-::%JEXTRACT% --source --output ../src/main/java ^
-:: -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
-:: --header-class-name WinUSB ^
-:: --target-package net.codecrete.usb.windows.gen.winusb ^
-:: "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\winusb.h"
+set JEXTRACT=..\..\..\jextract\build\jextract\bin\jextract.bat
:: cfgmgr32.h
:: Fails with error:
@@ -56,12 +17,3 @@ set JEXTRACT=..\..\..\jextract\build\jextract\bin\jextract
:: --header-class-name SetupApi ^
:: --target-package net.codecrete.usb.windows.gen.setupapi ^
:: "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\setupapi.h"
-
-:: usbioctl.h
-:: Fails with error:
-:: C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\setupapi.h:65:9: error: unknown type name 'GUID'
-::%JEXTRACT% --source --output ../src/main/java ^
-:: -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
-:: --header-class-name USBIOCtl ^
-:: --target-package net.codecrete.usb.windows.gen.usbioctl ^
-:: "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\shared\usbioctl.h"
diff --git a/java-does-usb/jextract/windows_cfgmgr32.h b/java-does-usb/jextract/windows_cfgmgr32.h
new file mode 100644
index 00000000..102a2987
--- /dev/null
+++ b/java-does-usb/jextract/windows_cfgmgr32.h
@@ -0,0 +1,2 @@
+#include
+#include
diff --git a/java-does-usb/jextract/windows_kernel32.h b/java-does-usb/jextract/windows_kernel32.h
new file mode 100644
index 00000000..198556f6
--- /dev/null
+++ b/java-does-usb/jextract/windows_kernel32.h
@@ -0,0 +1 @@
+#include
diff --git a/java-does-usb/jextract/windows_setupapi.h b/java-does-usb/jextract/windows_setupapi.h
new file mode 100644
index 00000000..7597c78f
--- /dev/null
+++ b/java-does-usb/jextract/windows_setupapi.h
@@ -0,0 +1,2 @@
+#include
+#include
diff --git a/java-does-usb/jextract/windows_stdlib.h b/java-does-usb/jextract/windows_stdlib.h
new file mode 100644
index 00000000..3b2f5900
--- /dev/null
+++ b/java-does-usb/jextract/windows_stdlib.h
@@ -0,0 +1 @@
+#include
diff --git a/java-does-usb/jextract/windows_usbioctl.h b/java-does-usb/jextract/windows_usbioctl.h
new file mode 100644
index 00000000..2a284d46
--- /dev/null
+++ b/java-does-usb/jextract/windows_usbioctl.h
@@ -0,0 +1,2 @@
+#include
+#include
diff --git a/java-does-usb/jextract/windows_winusb.h b/java-does-usb/jextract/windows_winusb.h
new file mode 100644
index 00000000..2fd0d78b
--- /dev/null
+++ b/java-does-usb/jextract/windows_winusb.h
@@ -0,0 +1,2 @@
+#include
+#include
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/CfgMgr32.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/CfgMgr32.java
deleted file mode 100644
index 91f85f77..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/CfgMgr32.java
+++ /dev/null
@@ -1,77 +0,0 @@
-//
-// Java Does USB
-// Copyright (c) 2022 Manuel Bleichenbacher
-// Licensed under MIT License
-// https://opensource.org/licenses/MIT
-//
-
-package net.codecrete.usb.windows;
-
-import java.lang.foreign.*;
-import java.lang.invoke.MethodHandle;
-
-import static java.lang.foreign.ValueLayout.ADDRESS;
-import static java.lang.foreign.ValueLayout.JAVA_INT;
-
-/**
- * Windows CfgMgr32 functions and structures
- */
-public class CfgMgr32 {
-
- private static final MethodHandle CM_Get_Parent$Func;
- private static final MethodHandle CM_Get_Device_IDW$Func;
-
- static {
- var session = MemorySession.openShared();
- Linker linker = Linker.nativeLinker();
- SymbolLookup lookup = SymbolLookup.libraryLookup("CfgMgr32", session);
-
- // CMAPI CONFIGRET CM_Get_Parent(
- // [out] PDEVINST pdnDevInst,
- // [in] DEVINST dnDevInst,
- // [in] ULONG ulFlags
- //);
- CM_Get_Parent$Func = linker.downcallHandle(
- lookup.lookup("CM_Get_Parent").get(),
- FunctionDescriptor.of(JAVA_INT, ADDRESS, JAVA_INT, JAVA_INT)
- );
-
- // CMAPI CONFIGRET CM_Get_Device_IDW(
- // [in] DEVINST dnDevInst,
- // [out] PWSTR Buffer,
- // [in] ULONG BufferLen,
- // [in] ULONG ulFlags
- //);
- CM_Get_Device_IDW$Func = linker.downcallHandle(
- lookup.lookup("CM_Get_Device_IDW").get(),
- FunctionDescriptor.of(JAVA_INT, JAVA_INT, ADDRESS, JAVA_INT, JAVA_INT)
- );
- }
-
- // CMAPI CONFIGRET CM_Get_Parent(
- // [out] PDEVINST pdnDevInst,
- // [in] DEVINST dnDevInst,
- // [in] ULONG ulFlags
- //);
- public static int CM_Get_Parent(Addressable pdnDevInst, int dnDevInst, int ulFlags) {
- try {
- return (int) CM_Get_Parent$Func.invokeExact(pdnDevInst, dnDevInst, ulFlags);
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- // CMAPI CONFIGRET CM_Get_Device_IDW(
- // [in] DEVINST dnDevInst,
- // [out] PWSTR Buffer,
- // [in] ULONG BufferLen,
- // [in] ULONG ulFlags
- //);
- public static int CM_Get_Device_IDW(int dnDevInst, Addressable buffer, int bufferLen, int ulFlags) {
- try {
- return (int) CM_Get_Device_IDW$Func.invokeExact(dnDevInst, buffer, bufferLen, ulFlags);
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/SetupApi.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/SetupApi.java
index 8ea584e2..1424553b 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/SetupApi.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/SetupApi.java
@@ -8,7 +8,6 @@
package net.codecrete.usb.windows;
import java.lang.foreign.*;
-import java.lang.invoke.MethodHandle;
import java.lang.invoke.VarHandle;
import static java.lang.foreign.MemoryLayout.PathElement.groupElement;
@@ -19,38 +18,17 @@
*/
public class SetupApi {
- public static final int DIGCF_DEFAULT = 0x00000001;
- public static final int DIGCF_PRESENT = 0x00000002;
- public static final int DIGCF_ALLCLASSES = 0x00000004;
- public static final int DIGCF_PROFILE = 0x00000008;
- public static final int DIGCF_DEVICEINTERFACE = 0x00000010;
-
- public static final int SPDRP_ADDRESS = 0x0000001C; // Device Address (R)
-
private static final GroupLayout GUID$Struct;
private static final VarHandle GUID_Data1;
private static final VarHandle GUID_Data2;
private static final VarHandle GUID_Data3;
private static final long GUID_Data4$Offset;
- public static final GroupLayout SP_DEVINFO_DATA$Struct;
- public static final VarHandle SP_DEVINFO_DATA_cbSize;
- public static final VarHandle SP_DEVINFO_DATA_DevInst;
-
- public static final GroupLayout SP_DEVICE_INTERFACE_DATA$Struct;
- public static final VarHandle SP_DEVICE_INTERFACE_DATA_cbSize;
-
public static final GroupLayout SP_DEVICE_INTERFACE_DETAIL_DATA_W$Struct;
- public static final VarHandle SP_DEVICE_INTERFACE_DETAIL_DATA_cbSize;
- public static final long SP_DEVICE_INTERFACE_DETAIL_DATA_DevicePath$Offset;
+ public static final VarHandle SP_DEVICE_INTERFACE_DETAIL_DATA_W_cbSize;
+ public static final long SP_DEVICE_INTERFACE_DETAIL_DATA_W_DevicePath$Offset;
- private static final MethodHandle SetupDiGetClassDevsW$Func;
- private static final MethodHandle SetupDiDestroyDeviceInfoList$Func;
public static final MemorySegment GUID_DEVINTERFACE_USB_DEVICE;
- private static final MethodHandle SetupDiEnumDeviceInfo$Func;
- private static final MethodHandle SetupDiEnumDeviceInterfaces$Func;
- private static final MethodHandle SetupDiGetDeviceInterfaceDetailW$Func;
- private static final MethodHandle SetupDiGetDeviceRegistryPropertyW$Func;
static {
var session = MemorySession.openShared();
@@ -74,35 +52,6 @@ public class SetupApi {
GUID_Data3 = GUID$Struct.varHandle(groupElement("Data3"));
GUID_Data4$Offset = GUID$Struct.byteOffset(groupElement("Data4"));
- // typedef struct _SP_DEVINFO_DATA {
- // DWORD cbSize;
- // GUID ClassGuid;
- // DWORD DevInst; // DEVINST handle
- // ULONG_PTR Reserved;
- // } SP_DEVINFO_DATA, *PSP_DEVINFO_DATA;
- SP_DEVINFO_DATA$Struct = MemoryLayout.structLayout(
- JAVA_INT.withName("cbSize"),
- GUID$Struct.withName("ClassGuid"),
- JAVA_INT.withName("DevInst"),
- ADDRESS.withName("Reserved")
- );
- SP_DEVINFO_DATA_cbSize = SP_DEVINFO_DATA$Struct.varHandle(groupElement("cbSize"));
- SP_DEVINFO_DATA_DevInst = SP_DEVINFO_DATA$Struct.varHandle(groupElement("DevInst"));
-
- // typedef struct _SP_DEVICE_INTERFACE_DATA {
- // DWORD cbSize;
- // GUID InterfaceClassGuid;
- // DWORD Flags;
- // ULONG_PTR Reserved;
- // } SP_DEVICE_INTERFACE_DATA, *PSP_DEVICE_INTERFACE_DATA;
- SP_DEVICE_INTERFACE_DATA$Struct = MemoryLayout.structLayout(
- JAVA_INT.withName("cbSize"),
- GUID$Struct.withName("InterfaceClassGuid"),
- JAVA_INT.withName("Flags"),
- ADDRESS.withName("Reserved")
- );
- SP_DEVICE_INTERFACE_DATA_cbSize = SP_DEVICE_INTERFACE_DATA$Struct.varHandle(groupElement("cbSize"));
-
// typedef struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W {
// DWORD cbSize;
// WCHAR DevicePath[ANYSIZE_ARRAY];
@@ -111,78 +60,8 @@ public class SetupApi {
JAVA_INT.withName("cbSize"),
MemoryLayout.sequenceLayout(260, JAVA_CHAR).withName("DevicePath")
);
- SP_DEVICE_INTERFACE_DETAIL_DATA_cbSize = SP_DEVICE_INTERFACE_DETAIL_DATA_W$Struct.varHandle(groupElement("cbSize"));
- SP_DEVICE_INTERFACE_DETAIL_DATA_DevicePath$Offset = SP_DEVICE_INTERFACE_DETAIL_DATA_W$Struct.byteOffset(groupElement("DevicePath"));
-
- // WINSETUPAPI HDEVINFO SetupDiGetClassDevsW(
- // [in, optional] const GUID *ClassGuid,
- // [in, optional] PCWSTR Enumerator,
- // [in, optional] HWND hwndParent,
- // [in] DWORD Flags
- //);
- SetupDiGetClassDevsW$Func = linker.downcallHandle(
- lookup.lookup("SetupDiGetClassDevsW").get(),
- FunctionDescriptor.of(ADDRESS, ADDRESS, ADDRESS, ADDRESS, JAVA_INT)
- );
-
- // BOOL
- // SetupDiDestroyDeviceInfoList(
- // _In_ HDEVINFO DeviceInfoSet
- // );
- SetupDiDestroyDeviceInfoList$Func = linker.downcallHandle(
- lookup.lookup("SetupDiDestroyDeviceInfoList").get(),
- FunctionDescriptor.of(JAVA_INT, ADDRESS)
- );
-
- //BOOL
- //SetupDiEnumDeviceInfo(
- // _In_ HDEVINFO DeviceInfoSet,
- // _In_ DWORD MemberIndex,
- // _Out_ PSP_DEVINFO_DATA DeviceInfoData
- // );
- SetupDiEnumDeviceInfo$Func = linker.downcallHandle(
- lookup.lookup("SetupDiEnumDeviceInfo").get(),
- FunctionDescriptor.of(JAVA_INT, ADDRESS, JAVA_INT, ADDRESS)
- );
-
- // WINSETUPAPI BOOL SetupDiEnumDeviceInterfaces(
- // [in] HDEVINFO DeviceInfoSet,
- // [in, optional] PSP_DEVINFO_DATA DeviceInfoData,
- // [in] const GUID *InterfaceClassGuid,
- // [in] DWORD MemberIndex,
- // [out] PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
- //);
- SetupDiEnumDeviceInterfaces$Func = linker.downcallHandle(
- lookup.lookup("SetupDiEnumDeviceInterfaces").get(),
- FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS, ADDRESS, JAVA_INT, ADDRESS)
- );
-
- // WINSETUPAPI BOOL SetupDiGetDeviceInterfaceDetailW(
- // [in] HDEVINFO DeviceInfoSet,
- // [in] PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
- // [out, optional] PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData,
- // [in] DWORD DeviceInterfaceDetailDataSize,
- // [out, optional] PDWORD RequiredSize,
- // [out, optional] PSP_DEVINFO_DATA DeviceInfoData
- //);
- SetupDiGetDeviceInterfaceDetailW$Func = linker.downcallHandle(
- lookup.lookup("SetupDiGetDeviceInterfaceDetailW").get(),
- FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS, ADDRESS, JAVA_INT, ADDRESS, ADDRESS)
- );
-
- // WINSETUPAPI BOOL SetupDiGetDeviceRegistryPropertyW(
- // [in] HDEVINFO DeviceInfoSet,
- // [in] PSP_DEVINFO_DATA DeviceInfoData,
- // [in] DWORD Property,
- // [out, optional] PDWORD PropertyRegDataType,
- // [out, optional] PBYTE PropertyBuffer,
- // [in] DWORD PropertyBufferSize,
- // [out, optional] PDWORD RequiredSize
- //);
- SetupDiGetDeviceRegistryPropertyW$Func = linker.downcallHandle(
- lookup.lookup("SetupDiGetDeviceRegistryPropertyW").get(),
- FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS, JAVA_INT, ADDRESS, ADDRESS, JAVA_INT, ADDRESS)
- );
+ SP_DEVICE_INTERFACE_DETAIL_DATA_W_cbSize = SP_DEVICE_INTERFACE_DETAIL_DATA_W$Struct.varHandle(groupElement("cbSize"));
+ SP_DEVICE_INTERFACE_DETAIL_DATA_W_DevicePath$Offset = SP_DEVICE_INTERFACE_DETAIL_DATA_W$Struct.byteOffset(groupElement("DevicePath"));
// A5DCBF10-6530-11D2-901F-00C04FB951ED
GUID_DEVINTERFACE_USB_DEVICE = CreateGUID(0xA5DCBF10, (short) 0x6530, (short) 0x11D2,
@@ -190,109 +69,6 @@ public class SetupApi {
(byte) 0x4F, (byte) 0xB9, (byte) 0x51, (byte) 0xED);
}
- // WINSETUPAPI HDEVINFO SetupDiGetClassDevsW(
- // [in, optional] const GUID *ClassGuid,
- // [in, optional] PCWSTR Enumerator,
- // [in, optional] HWND hwndParent,
- // [in] DWORD Flags
- //);
- public static MemoryAddress SetupDiGetClassDevsW(Addressable classGuid, Addressable enumerator,
- Addressable hwndParent, int flags) {
- try {
- return (MemoryAddress) SetupDiGetClassDevsW$Func.invokeExact(classGuid, enumerator,
- hwndParent, flags);
- } catch (Throwable t) {
- throw new RuntimeException(t);
- }
- }
-
- // BOOL
- // SetupDiDestroyDeviceInfoList(
- // _In_ HDEVINFO DeviceInfoSet
- // );
- public static boolean SetupDiDestroyDeviceInfoList(Addressable deviceInfoSet) {
- try {
- return (int) SetupDiDestroyDeviceInfoList$Func.invokeExact(deviceInfoSet) != 0;
- } catch (Throwable t) {
- throw new RuntimeException(t);
- }
- }
-
- //BOOL
- //SetupDiEnumDeviceInfo(
- // _In_ HDEVINFO DeviceInfoSet,
- // _In_ DWORD MemberIndex,
- // _Out_ PSP_DEVINFO_DATA DeviceInfoData
- // );
- public static boolean SetupDiEnumDeviceInfo(Addressable deviceInfoSet, int memberIndex, Addressable deviceInfoData) {
- try {
- return (int) SetupDiEnumDeviceInfo$Func.invokeExact(deviceInfoSet, memberIndex, deviceInfoData) != 0;
- } catch (Throwable t) {
- throw new RuntimeException(t);
- }
- }
-
- // WINSETUPAPI BOOL SetupDiEnumDeviceInterfaces(
- // [in] HDEVINFO DeviceInfoSet,
- // [in, optional] PSP_DEVINFO_DATA DeviceInfoData,
- // [in] const GUID *InterfaceClassGuid,
- // [in] DWORD MemberIndex,
- // [out] PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
- //);
- public static boolean SetupDiEnumDeviceInterfaces(Addressable deviceInfoSet, Addressable deviceInfoData,
- Addressable interfaceClassGuid, int memberIndex,
- Addressable deviceInterfaceData) {
- try {
- return (int) SetupDiEnumDeviceInterfaces$Func.invokeExact(deviceInfoSet, deviceInfoData,
- interfaceClassGuid, memberIndex,
- deviceInterfaceData) != 0;
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- // WINSETUPAPI BOOL SetupDiGetDeviceInterfaceDetailW(
- // [in] HDEVINFO DeviceInfoSet,
- // [in] PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
- // [out, optional] PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData,
- // [in] DWORD DeviceInterfaceDetailDataSize,
- // [out, optional] PDWORD RequiredSize,
- // [out, optional] PSP_DEVINFO_DATA DeviceInfoData
- //);
- public static boolean SetupDiGetDeviceInterfaceDetailW(Addressable deviceInfoSet, Addressable deviceInterfaceData,
- Addressable deviceInterfaceDetailData, int deviceInterfaceDetailDataSize,
- Addressable requiredSize, Addressable deviceInfoData) {
- try {
- return (int) SetupDiGetDeviceInterfaceDetailW$Func.invokeExact(deviceInfoSet, deviceInterfaceData,
- deviceInterfaceDetailData, deviceInterfaceDetailDataSize,
- requiredSize, deviceInfoData) != 0;
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- // WINSETUPAPI BOOL SetupDiGetDeviceRegistryPropertyW(
- // [in] HDEVINFO DeviceInfoSet,
- // [in] PSP_DEVINFO_DATA DeviceInfoData,
- // [in] DWORD Property,
- // [out, optional] PDWORD PropertyRegDataType,
- // [out, optional] PBYTE PropertyBuffer,
- // [in] DWORD PropertyBufferSize,
- // [out, optional] PDWORD RequiredSize
- //);
- public static boolean SetupDiGetDeviceRegistryPropertyW(Addressable deviceInfoSet, Addressable deviceInfoData,
- int property, Addressable propertyRegDataType,
- Addressable propertyBuffer, int propertyBufferSize,
- Addressable requiredSize) {
- try {
- return (int) SetupDiGetDeviceRegistryPropertyW$Func.invokeExact(deviceInfoSet, deviceInfoData,
- property, propertyRegDataType,
- propertyBuffer, propertyBufferSize,
- requiredSize) != 0;
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
/**
* Creates a GUID in native memory.
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/Win.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/Win.java
index 3670b51f..b7df23db 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/Win.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/Win.java
@@ -7,120 +7,13 @@
package net.codecrete.usb.windows;
-import java.lang.foreign.*;
-import java.lang.invoke.MethodHandle;
-
-import static java.lang.foreign.ValueLayout.*;
+import java.lang.foreign.MemoryAddress;
/**
- * Windows Kernel32 functions and Windows helpers.
+ * Windows helpers.
*/
public class Win {
- public static final int ERROR_NO_MORE_ITEMS = 259;
-
- public static final int GENERIC_READ = 0x80000000;
- public static final int GENERIC_WRITE = 0x40000000;
- public static final int GENERIC_EXECUTE = 0x20000000;
- public static final int GENERIC_ALL = 0x10000000;
-
- public static final int FILE_SHARE_READ = 0x00000001;
- public static final int FILE_SHARE_WRITE = 0x00000002;
- public static final int FILE_SHARE_DELETE = 0x00000004;
-
- public static final int FILE_ATTRIBUTE_READONLY = 0x00000001;
- public static final int FILE_ATTRIBUTE_HIDDEN = 0x00000002;
- public static final int FILE_ATTRIBUTE_SYSTEM = 0x00000004;
- public static final int FILE_ATTRIBUTE_DIRECTORY = 0x00000010;
- public static final int FILE_ATTRIBUTE_ARCHIVE = 0x00000020;
- public static final int FILE_ATTRIBUTE_DEVICE = 0x00000040;
- public static final int FILE_ATTRIBUTE_NORMAL = 0x00000080;
- public static final int FILE_ATTRIBUTE_TEMPORARY = 0x00000100;
-
- public static final int FILE_FLAG_WRITE_THROUGH = 0x80000000;
- public static final int FILE_FLAG_OVERLAPPED = 0x40000000;
- public static final int FILE_FLAG_NO_BUFFERING = 0x20000000;
- public static final int FILE_FLAG_RANDOM_ACCESS = 0x10000000;
- public static final int FILE_FLAG_SEQUENTIAL_SCAN = 0x08000000;
- public static final int FILE_FLAG_DELETE_ON_CLOSE = 0x04000000;
-
- public static final int CREATE_NEW = 1;
- public static final int CREATE_ALWAYS = 2;
- public static final int OPEN_EXISTING = 3;
- public static final int OPEN_ALWAYS = 4;
- public static final int TRUNCATE_EXISTING = 5;
-
- private static final MethodHandle GetLastError$Func;
- private static final MethodHandle CreateFileW$Func;
- private static final MethodHandle CloseHandle$Func;
- private static final MethodHandle DeviceIoControl$Func;
- private static final MethodHandle wcslen$Func;
-
-
- static {
- var session = MemorySession.openShared();
- Linker linker = Linker.nativeLinker();
- SymbolLookup kernelLookup = SymbolLookup.libraryLookup("Kernel32", session);
-
- GetLastError$Func = linker.downcallHandle(
- kernelLookup.lookup("GetLastError").get(),
- FunctionDescriptor.of(JAVA_INT)
- );
-
- // HANDLE CreateFileW(
- // [in] LPCWSTR lpFileName,
- // [in] DWORD dwDesiredAccess,
- // [in] DWORD dwShareMode,
- // [in, optional] LPSECURITY_ATTRIBUTES lpSecurityAttributes,
- // [in] DWORD dwCreationDisposition,
- // [in] DWORD dwFlagsAndAttributes,
- // [in, optional] HANDLE hTemplateFile
- //);
- CreateFileW$Func = linker.downcallHandle(
- kernelLookup.lookup("CreateFileW").get(),
- FunctionDescriptor.of(ADDRESS, ADDRESS, JAVA_INT, JAVA_INT, ADDRESS, JAVA_INT, JAVA_INT, ADDRESS)
- );
-
- // BOOL CloseHandle(
- // [in] HANDLE hObject
- //);
- CloseHandle$Func = linker.downcallHandle(
- kernelLookup.lookup("CloseHandle").get(),
- FunctionDescriptor.of(JAVA_INT, ADDRESS)
- );
-
- // BOOL DeviceIoControl(
- // [in] HANDLE hDevice,
- // [in] DWORD dwIoControlCode,
- // [in, optional] LPVOID lpInBuffer,
- // [in] DWORD nInBufferSize,
- // [out, optional] LPVOID lpOutBuffer,
- // [in] DWORD nOutBufferSize,
- // [out, optional] LPDWORD lpBytesReturned,
- // [in, out, optional] LPOVERLAPPED lpOverlapped
- //);
- DeviceIoControl$Func = linker.downcallHandle(
- kernelLookup.lookup("DeviceIoControl").get(),
- FunctionDescriptor.of(JAVA_INT, ADDRESS, JAVA_INT, ADDRESS, JAVA_INT, ADDRESS, JAVA_INT, ADDRESS, ADDRESS)
- );
-
- // size_t wcslen(
- // const wchar_t *str
- //);
- wcslen$Func = linker.downcallHandle(
- linker.defaultLookup().lookup("wcslen").get(),
- FunctionDescriptor.of(JAVA_LONG, ADDRESS)
- );
- }
-
- public static int GetLastError() {
- try {
- return (int) GetLastError$Func.invokeExact();
- } catch (Throwable t) {
- throw new RuntimeException(t);
- }
- }
-
/**
* Checks if a Windows handle is invalid.
*
@@ -130,69 +23,4 @@ public static int GetLastError() {
public static boolean IsInvalidHandle(MemoryAddress handle) {
return handle.toRawLongValue() == -1L;
}
-
- // HANDLE CreateFileW(
- // [in] LPCWSTR lpFileName,
- // [in] DWORD dwDesiredAccess,
- // [in] DWORD dwShareMode,
- // [in, optional] LPSECURITY_ATTRIBUTES lpSecurityAttributes,
- // [in] DWORD dwCreationDisposition,
- // [in] DWORD dwFlagsAndAttributes,
- // [in, optional] HANDLE hTemplateFile
- //);
- public static MemoryAddress CreateFileW(Addressable lpFileName, int dwDesiredAccess, int dwShareMode,
- Addressable lpSecurityAttriubtes, int dwCreationDisposition,
- int dwFlagsAndAttributes, Addressable hTemplateFile) {
- try {
- return (MemoryAddress) CreateFileW$Func.invokeExact(lpFileName, dwDesiredAccess, dwShareMode,
- lpSecurityAttriubtes, dwCreationDisposition,
- dwFlagsAndAttributes, hTemplateFile);
- } catch (Throwable t) {
- throw new RuntimeException(t);
- }
- }
-
- public static boolean CloseHandle(Addressable handle) {
- try {
- return (int) CloseHandle$Func.invokeExact(handle) != 0;
- } catch (Throwable t) {
- throw new RuntimeException(t);
- }
- }
-
- // BOOL DeviceIoControl(
- // [in] HANDLE hDevice,
- // [in] DWORD dwIoControlCode,
- // [in, optional] LPVOID lpInBuffer,
- // [in] DWORD nInBufferSize,
- // [out, optional] LPVOID lpOutBuffer,
- // [in] DWORD nOutBufferSize,
- // [out, optional] LPDWORD lpBytesReturned,
- // [in, out, optional] LPOVERLAPPED lpOverlapped
- //);
- public static boolean DeviceIoControl(Addressable hDevice, int dwIOControlCode,
- Addressable lpInBuffer, int nInBufferSize,
- Addressable lpPoutBuffer, int nOutBufferSize,
- Addressable lpBytesReturned, Addressable lpOverlapped) {
- try {
- return (int) DeviceIoControl$Func.invokeExact(hDevice, dwIOControlCode,
- lpInBuffer, nInBufferSize,
- lpPoutBuffer, nOutBufferSize,
- lpBytesReturned, lpOverlapped) != 0;
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
-
- // size_t wcslen(
- // const wchar_t *str
- //);
- public static long wcslen(Addressable str) {
- try {
- return (long) wcslen$Func.invokeExact(str);
- } catch (Throwable t) {
- throw new RuntimeException(t);
- }
- }
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/WinUSB.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/WinUSB.java
deleted file mode 100644
index f28b4f8f..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/WinUSB.java
+++ /dev/null
@@ -1,204 +0,0 @@
-//
-// Java Does USB
-// Copyright (c) 2022 Manuel Bleichenbacher
-// Licensed under MIT License
-// https://opensource.org/licenses/MIT
-//
-
-package net.codecrete.usb.windows;
-
-import net.codecrete.usb.common.USBStructs;
-
-import java.lang.foreign.*;
-import java.lang.invoke.MethodHandle;
-
-import static java.lang.foreign.ValueLayout.*;
-
-/**
- * WinUSB functions.
- */
-public class WinUSB {
-
- private static final MethodHandle Initialize$Func;
- private static final MethodHandle Free$Func;
- private static final MethodHandle GetDescriptor$Func;
- private static final MethodHandle ControlTransfer$Func;
- private static final MethodHandle WritePipe$Func;
- private static final MethodHandle ReadPipe$Func;
-
- static {
- var session = MemorySession.openShared();
- Linker linker = Linker.nativeLinker();
- SymbolLookup lookup = SymbolLookup.libraryLookup("Winusb", session);
-
- // BOOL WinUsb_Initialize(
- // [in] HANDLE DeviceHandle,
- // [out] PWINUSB_INTERFACE_HANDLE InterfaceHandle
- //);
- Initialize$Func = linker.downcallHandle(
- lookup.lookup("WinUsb_Initialize").get(),
- FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS)
- );
-
- // BOOL WinUsb_Free(
- // [in] WINUSB_INTERFACE_HANDLE InterfaceHandle
- //);
- Free$Func = linker.downcallHandle(
- lookup.lookup("WinUsb_Free").get(),
- FunctionDescriptor.of(JAVA_INT, ADDRESS)
- );
-
- // BOOL WinUsb_GetDescriptor(
- // [in] WINUSB_INTERFACE_HANDLE InterfaceHandle,
- // [in] UCHAR DescriptorType,
- // [in] UCHAR Index,
- // [in] USHORT LanguageID,
- // [out] PUCHAR Buffer,
- // [in] ULONG BufferLength,
- // [out] PULONG LengthTransferred
- //);
- GetDescriptor$Func = linker.downcallHandle(
- lookup.lookup("WinUsb_GetDescriptor").get(),
- FunctionDescriptor.of(JAVA_INT, ADDRESS, JAVA_BYTE, JAVA_BYTE, JAVA_SHORT, ADDRESS, JAVA_INT, ADDRESS)
- );
-
- // BOOL WinUsb_ControlTransfer(
- // [in] WINUSB_INTERFACE_HANDLE InterfaceHandle,
- // [in] WINUSB_SETUP_PACKET SetupPacket,
- // [out] PUCHAR Buffer,
- // [in] ULONG BufferLength,
- // [out, optional] PULONG LengthTransferred,
- // [in, optional] LPOVERLAPPED Overlapped
- //);
- ControlTransfer$Func = linker.downcallHandle(
- lookup.lookup("WinUsb_ControlTransfer").get(),
- FunctionDescriptor.of(JAVA_INT, ADDRESS, USBStructs.SetupPacket$Struct, ADDRESS, JAVA_INT, ADDRESS, ADDRESS)
- );
-
- // BOOL WinUsb_WritePipe(
- // [in] WINUSB_INTERFACE_HANDLE InterfaceHandle,
- // [in] UCHAR PipeID,
- // [in] PUCHAR Buffer,
- // [in] ULONG BufferLength,
- // [out, optional] PULONG LengthTransferred,
- // [in, optional] LPOVERLAPPED Overlapped
- //);
- WritePipe$Func = linker.downcallHandle(
- lookup.lookup("WinUsb_WritePipe").get(),
- FunctionDescriptor.of(JAVA_INT, ADDRESS, JAVA_BYTE, ADDRESS, JAVA_INT, ADDRESS, ADDRESS)
- );
-
- // BOOL WinUsb_ReadPipe(
- // [in] WINUSB_INTERFACE_HANDLE InterfaceHandle,
- // [in] UCHAR PipeID,
- // [out] PUCHAR Buffer,
- // [in] ULONG BufferLength,
- // [out, optional] PULONG LengthTransferred,
- // [in, optional] LPOVERLAPPED Overlapped
- //);
- ReadPipe$Func = linker.downcallHandle(
- lookup.lookup("WinUsb_ReadPipe").get(),
- FunctionDescriptor.of(JAVA_INT, ADDRESS, JAVA_BYTE, ADDRESS, JAVA_INT, ADDRESS, ADDRESS)
- );
- }
-
- // BOOL WinUsb_Initialize(
- // [in] HANDLE DeviceHandle,
- // [out] PWINUSB_INTERFACE_HANDLE InterfaceHandle
- //);
- public static boolean Initialize(Addressable deviceHandle, Addressable interfaceHandleHolder) {
- try {
- return (int) Initialize$Func.invokeExact(deviceHandle, interfaceHandleHolder) != 0;
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- // BOOL WinUsb_Free(
- // [in] WINUSB_INTERFACE_HANDLE InterfaceHandle
- //);
- public static boolean Free(Addressable interfaceHandle) {
- try {
- return (int) Free$Func.invokeExact(interfaceHandle) != 0;
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- // BOOL WinUsb_GetDescriptor(
- // [in] WINUSB_INTERFACE_HANDLE InterfaceHandle,
- // [in] UCHAR DescriptorType,
- // [in] UCHAR Index,
- // [in] USHORT LanguageID,
- // [out] PUCHAR Buffer,
- // [in] ULONG BufferLength,
- // [out] PULONG LengthTransferred
- //);
- public static boolean GetDescriptor(Addressable interfaceHandle, byte descriptorType, byte index,
- short languageID, Addressable buffer, int bufferLength,
- Addressable lengthTransferredHolder) {
- try {
- return (int) GetDescriptor$Func.invokeExact(interfaceHandle, descriptorType, index,
- languageID, buffer, bufferLength, lengthTransferredHolder) != 0;
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- // BOOL WinUsb_ControlTransfer(
- // [in] WINUSB_INTERFACE_HANDLE InterfaceHandle,
- // [in] WINUSB_SETUP_PACKET SetupPacket,
- // [out] PUCHAR Buffer,
- // [in] ULONG BufferLength,
- // [out, optional] PULONG LengthTransferred,
- // [in, optional] LPOVERLAPPED Overlapped
- //);
- public static boolean ControlTransfer(Addressable interfaceHandle, MemorySegment setupPacket,
- Addressable buffer, int bufferLength,
- Addressable lengthTransferredHolder, Addressable overlapped) {
- try {
- return (int) ControlTransfer$Func.invokeExact(interfaceHandle, setupPacket,
- buffer, bufferLength, lengthTransferredHolder, overlapped) != 0;
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- // BOOL WinUsb_WritePipe(
- // [in] WINUSB_INTERFACE_HANDLE InterfaceHandle,
- // [in] UCHAR PipeID,
- // [in] PUCHAR Buffer,
- // [in] ULONG BufferLength,
- // [out, optional] PULONG LengthTransferred,
- // [in, optional] LPOVERLAPPED Overlapped
- //);
- public static boolean WritePipe(Addressable interfaceHandle, byte pipeID,
- Addressable buffer, int bufferLength,
- Addressable lengthTransferredHolder, Addressable overlapped) {
- try {
- return (int) WritePipe$Func.invokeExact(interfaceHandle, pipeID,
- buffer, bufferLength, lengthTransferredHolder, overlapped) != 0;
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- // BOOL WinUsb_ReadPipe(
- // [in] WINUSB_INTERFACE_HANDLE InterfaceHandle,
- // [in] UCHAR PipeID,
- // [out] PUCHAR Buffer,
- // [in] ULONG BufferLength,
- // [out, optional] PULONG LengthTransferred,
- // [in, optional] LPOVERLAPPED Overlapped
- //);
- public static boolean ReadPipe(Addressable interfaceHandle, byte pipeID,
- Addressable buffer, int bufferLength,
- Addressable lengthTransferredHolder, Addressable overlapped) {
- try {
- return (int) ReadPipe$Func.invokeExact(interfaceHandle, pipeID,
- buffer, bufferLength, lengthTransferredHolder, overlapped) != 0;
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDevice.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDevice.java
index 90b210b9..1b413694 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDevice.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDevice.java
@@ -17,6 +17,8 @@
import net.codecrete.usb.common.USBDescriptors;
import net.codecrete.usb.common.USBDeviceImpl;
import net.codecrete.usb.common.USBStructs;
+import net.codecrete.usb.windows.gen.kernel32.Kernel32;
+import net.codecrete.usb.windows.gen.winusb.WinUSB;
import java.lang.foreign.MemoryAddress;
import java.lang.foreign.MemorySegment;
@@ -51,22 +53,22 @@ public class WindowsUSBDevice extends USBDeviceImpl {
var chars = path.toCharArray();
var pathSegment = session.allocateArray(ValueLayout.JAVA_CHAR, chars.length + 1);
pathSegment.copyFrom(MemorySegment.ofArray(chars));
- device = Win.CreateFileW(pathSegment,
- Win.GENERIC_WRITE | Win.GENERIC_READ,
- Win.FILE_SHARE_WRITE | Win.FILE_SHARE_READ,
+ device = Kernel32.CreateFileW(pathSegment,
+ Kernel32.GENERIC_WRITE() | Kernel32.GENERIC_READ(),
+ Kernel32.FILE_SHARE_WRITE() | Kernel32.FILE_SHARE_READ(),
NULL,
- Win.OPEN_EXISTING,
- Win.FILE_ATTRIBUTE_NORMAL | Win.FILE_FLAG_OVERLAPPED,
+ Kernel32.OPEN_EXISTING(),
+ Kernel32.FILE_ATTRIBUTE_NORMAL() | Kernel32.FILE_FLAG_OVERLAPPED(),
NULL);
if (Win.IsInvalidHandle(device))
- throw new USBException("Cannot open USB device", Win.GetLastError());
+ throw new USBException("Cannot open USB device", Kernel32.GetLastError());
try {
// open first USB interface
var interfaceHandleHolder = session.allocate(ADDRESS);
- if (!WinUSB.Initialize(device, interfaceHandleHolder))
- throw new USBException("Cannot open USB device", Win.GetLastError());
+ if (WinUSB.WinUsb_Initialize(device, interfaceHandleHolder) == 0)
+ throw new USBException("Cannot open USB device", Kernel32.GetLastError());
firstInterface = interfaceHandleHolder.get(ADDRESS, 0);
@@ -76,12 +78,12 @@ public class WindowsUSBDevice extends USBDeviceImpl {
configuration = DescriptorParser.parseConfigurationDescriptor(desc);
} catch (Throwable e) {
- WinUSB.Free(firstInterface);
+ WinUSB.WinUsb_Free(firstInterface);
throw e;
}
} catch (Throwable e) {
- Win.CloseHandle(device);
+ Kernel32.CloseHandle(device);
throw e;
}
}
@@ -142,8 +144,8 @@ public byte[] controlTransferIn(USBControlTransfer setup, int length) {
var setupPacket = createSetupPacket(session, USBDirection.IN, setup, buffer);
var lengthHolder = session.allocate(JAVA_INT);
- if (!WinUSB.ControlTransfer(firstInterface, setupPacket, buffer, (int) buffer.byteSize(), lengthHolder, NULL))
- throw new USBException("Control transfer IN failed", Win.GetLastError());
+ if (WinUSB.WinUsb_ControlTransfer(firstInterface, setupPacket, buffer, (int) buffer.byteSize(), lengthHolder, NULL) == 0)
+ throw new USBException("Control transfer IN failed", Kernel32.GetLastError());
int rxLength = lengthHolder.get(JAVA_INT, 0);
return buffer.asSlice(0, rxLength).toArray(JAVA_BYTE);
@@ -164,8 +166,8 @@ public void controlTransferOut(USBControlTransfer setup, byte[] data) {
var setupPacket = createSetupPacket(session, USBDirection.OUT, setup, buffer);
var lengthHolder = session.allocate(JAVA_INT);
- if (!WinUSB.ControlTransfer(firstInterface, setupPacket, buffer, (int) buffer.byteSize(), lengthHolder, NULL))
- throw new USBException("Control transfer OUT failed", Win.GetLastError());
+ if (WinUSB.WinUsb_ControlTransfer(firstInterface, setupPacket, buffer, (int) buffer.byteSize(), lengthHolder, NULL) == 0)
+ throw new USBException("Control transfer OUT failed", Kernel32.GetLastError());
}
}
@@ -178,8 +180,8 @@ public void transferOut(int endpointNumber, byte[] data) {
buffer.copyFrom(MemorySegment.ofArray(data));
var lengthHolder = session.allocate(JAVA_INT);
- if (!WinUSB.WritePipe(firstInterface, endpointAddress, buffer, (int) buffer.byteSize(), lengthHolder, NULL))
- throw new USBException("Control transfer IN failed", Win.GetLastError());
+ if (WinUSB.WinUsb_WritePipe(firstInterface, endpointAddress, buffer, (int) buffer.byteSize(), lengthHolder, NULL) == 0)
+ throw new USBException("Control transfer IN failed", Kernel32.GetLastError());
}
}
@@ -191,8 +193,8 @@ public byte[] transferIn(int endpointNumber, int maxLength) {
var buffer = session.allocate(maxLength);
var lengthHolder = session.allocate(JAVA_INT);
- if (!WinUSB.ReadPipe(firstInterface, endpointAddress, buffer, (int) buffer.byteSize(), lengthHolder, NULL))
- throw new USBException("Control transfer IN failed", Win.GetLastError());
+ if (WinUSB.WinUsb_ReadPipe(firstInterface, endpointAddress, buffer, (int) buffer.byteSize(), lengthHolder, NULL) == 0)
+ throw new USBException("Control transfer IN failed", Kernel32.GetLastError());
int len = lengthHolder.get(JAVA_INT, 0);
return buffer.asSlice(0, len).toArray(JAVA_BYTE);
@@ -201,7 +203,7 @@ public byte[] transferIn(int endpointNumber, int maxLength) {
@Override
public void close() throws Exception {
- WinUSB.Free(firstInterface);
- Win.CloseHandle(device);
+ WinUSB.WinUsb_Free(firstInterface);
+ Kernel32.CloseHandle(device);
}
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
index f11471d5..9c48636d 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
@@ -12,6 +12,11 @@
import net.codecrete.usb.common.USBDescriptors;
import net.codecrete.usb.common.USBDeviceRegistry;
import net.codecrete.usb.common.USBStructs;
+import net.codecrete.usb.windows.gen.cfgmgr32.CfgMgr32;
+import net.codecrete.usb.windows.gen.kernel32.Kernel32;
+import net.codecrete.usb.windows.gen.setupapi.SetupAPI;
+import net.codecrete.usb.windows.gen.setupapi._SP_DEVINFO_DATA;
+import net.codecrete.usb.windows.gen.stdlib.StdLib;
import java.lang.foreign.Addressable;
import java.lang.foreign.MemoryAddress;
@@ -32,23 +37,23 @@ public List getAllDevices() {
try (var outerSession = MemorySession.openConfined()) {
// get as set of all USB devices present
- final var devInfoSetHandle = SetupApi.SetupDiGetClassDevsW(SetupApi.GUID_DEVINTERFACE_USB_DEVICE, NULL, NULL, SetupApi.DIGCF_PRESENT | SetupApi.DIGCF_DEVICEINTERFACE);
+ final var devInfoSetHandle = SetupAPI.SetupDiGetClassDevsW(SetupApi.GUID_DEVINTERFACE_USB_DEVICE, NULL, NULL, SetupAPI.DIGCF_PRESENT() | SetupAPI.DIGCF_DEVICEINTERFACE());
if (Win.IsInvalidHandle(devInfoSetHandle))
throw new USBException("internal error (SetupDiGetClassDevsW)");
// ensure the result is destroyed when the scope is left
- outerSession.addCloseAction(() -> SetupApi.SetupDiDestroyDeviceInfoList(devInfoSetHandle));
+ outerSession.addCloseAction(() -> SetupAPI.SetupDiDestroyDeviceInfoList(devInfoSetHandle));
- var devInfo = MemorySegment.allocateNative(SetupApi.SP_DEVINFO_DATA$Struct, outerSession);
- SetupApi.SP_DEVINFO_DATA_cbSize.set(devInfo, (int) SetupApi.SP_DEVINFO_DATA$Struct.byteSize());
+ var devInfo = MemorySegment.allocateNative(_SP_DEVINFO_DATA.$LAYOUT(), outerSession);
+ _SP_DEVINFO_DATA.cbSize$set(devInfo, (int) _SP_DEVINFO_DATA.$LAYOUT().byteSize());
- var devInfoData = MemorySegment.allocateNative(SetupApi.SP_DEVINFO_DATA$Struct, outerSession);
- SetupApi.SP_DEVINFO_DATA_cbSize.set(devInfoData, (int) SetupApi.SP_DEVINFO_DATA$Struct.byteSize());
+ var devInfoData = MemorySegment.allocateNative(_SP_DEVINFO_DATA.$LAYOUT(), outerSession);
+ _SP_DEVINFO_DATA.cbSize$set(devInfoData, (int) _SP_DEVINFO_DATA.$LAYOUT().byteSize());
for (int i = 0; true; i++) {
- if (!SetupApi.SetupDiEnumDeviceInfo(devInfoSetHandle, i, devInfo)) {
- int err = Win.GetLastError();
- if (err != Win.ERROR_NO_MORE_ITEMS) {
+ if (SetupAPI.SetupDiEnumDeviceInfo(devInfoSetHandle, i, devInfo) == 0) {
+ int err = Kernel32.GetLastError();
+ if (err != Kernel32.ERROR_NO_MORE_ITEMS()) {
throw new USBException("Internal error (SetupDiEnumDeviceInfo) ");
}
break;
@@ -58,7 +63,7 @@ public List getAllDevices() {
// get the parent device (a USB hub)
var parentDevInstHolder = session.allocate(JAVA_INT);
- int devInst = (int) SetupApi.SP_DEVINFO_DATA_DevInst.get(devInfo);
+ int devInst = (int) _SP_DEVINFO_DATA.DevInst$get(devInfo);
int cmRet = CfgMgr32.CM_Get_Parent(parentDevInstHolder, devInst, 0);
if (cmRet != 0)
throw new USBException("Internal error (CM_Get_Parent)");
@@ -82,41 +87,41 @@ public List getAllDevices() {
var hubPathSeg = session.allocateArray(JAVA_CHAR, hubPath.length());
hubPathSeg.copyFrom(MemorySegment.ofArray(hubPath.toCharArray()));
- final var hubHandle = Win.CreateFileW(hubPathSeg, Win.GENERIC_WRITE, Win.FILE_SHARE_WRITE,
- NULL, Win.OPEN_EXISTING, 0, NULL);
+ final var hubHandle = Kernel32.CreateFileW(hubPathSeg, Kernel32.GENERIC_WRITE(), Kernel32.FILE_SHARE_WRITE(),
+ NULL, Kernel32.OPEN_EXISTING(), 0, NULL);
if (Win.IsInvalidHandle(hubHandle))
throw new USBException("Cannot open USB hub");
- session.addCloseAction(() -> Win.CloseHandle(hubHandle));
+ session.addCloseAction(() -> Kernel32.CloseHandle(hubHandle));
// get the interface data
- if (!SetupApi.SetupDiEnumDeviceInterfaces(devInfoSetHandle, devInfo,
- SetupApi.GUID_DEVINTERFACE_USB_DEVICE, 0, devInfoData)) {
- int lastError = Win.GetLastError();
- if (lastError == Win.ERROR_NO_MORE_ITEMS)
+ if (SetupAPI.SetupDiEnumDeviceInterfaces(devInfoSetHandle, devInfo,
+ SetupApi.GUID_DEVINTERFACE_USB_DEVICE, 0, devInfoData) == 0) {
+ int lastError = Kernel32.GetLastError();
+ if (lastError == Kernel32.ERROR_NO_MORE_ITEMS())
throw new USBException("Internal error (SetupDiEnumDeviceInterfaces)");
continue;
}
// get path of first interface
var intfDetailData = MemorySegment.allocateNative(SetupApi.SP_DEVICE_INTERFACE_DETAIL_DATA_W$Struct, session);
- SetupApi.SP_DEVICE_INTERFACE_DETAIL_DATA_cbSize.set(intfDetailData, 8);
+ SetupApi.SP_DEVICE_INTERFACE_DETAIL_DATA_W_cbSize.set(intfDetailData, 8);
int intfDatailDataSize = (int) SetupApi.SP_DEVICE_INTERFACE_DETAIL_DATA_W$Struct.byteSize();
- if (!SetupApi.SetupDiGetDeviceInterfaceDetailW(devInfoSetHandle, devInfoData,
- intfDetailData, intfDatailDataSize, NULL, NULL))
- throw new USBException("Internal error (SetupDiGetDeviceInterfaceDetailA - 2)", Win.GetLastError());
+ if (SetupAPI.SetupDiGetDeviceInterfaceDetailW(devInfoSetHandle, devInfoData,
+ intfDetailData, intfDatailDataSize, NULL, NULL) == 0)
+ throw new USBException("Internal error (SetupDiGetDeviceInterfaceDetailA - 2)", Kernel32.GetLastError());
- long pathLen = Win.wcslen(intfDetailData.address().addOffset(SetupApi.SP_DEVICE_INTERFACE_DETAIL_DATA_DevicePath$Offset));
- char[] devicePathChars = intfDetailData.asSlice(SetupApi.SP_DEVICE_INTERFACE_DETAIL_DATA_DevicePath$Offset, pathLen * 2).toArray(JAVA_CHAR);
+ long pathLen = StdLib.wcslen(intfDetailData.address().addOffset(SetupApi.SP_DEVICE_INTERFACE_DETAIL_DATA_W_DevicePath$Offset));
+ char[] devicePathChars = intfDetailData.asSlice(SetupApi.SP_DEVICE_INTERFACE_DETAIL_DATA_W_DevicePath$Offset, pathLen * 2).toArray(JAVA_CHAR);
String devicePath = new String(devicePathChars);
// get device's hub port number
var usbPortNumHolder = session.allocate(JAVA_INT);
var sizeHolder = session.allocate(JAVA_INT);
- if (!SetupApi.SetupDiGetDeviceRegistryPropertyW(devInfoSetHandle, devInfo,
- SetupApi.SPDRP_ADDRESS, NULL, usbPortNumHolder,
- (int) usbPortNumHolder.byteSize(), sizeHolder))
- throw new USBException("Internal error (cannot get device hub port)", Win.GetLastError());
+ if (SetupAPI.SetupDiGetDeviceRegistryPropertyW(devInfoSetHandle, devInfo,
+ SetupAPI.SPDRP_ADDRESS(), NULL, usbPortNumHolder,
+ (int) usbPortNumHolder.byteSize(), sizeHolder) == 0)
+ throw new USBException("Internal error (cannot get device hub port)", Kernel32.GetLastError());
int usbPortNum = usbPortNumHolder.get(JAVA_INT, 0);
result.add(createDeviceInfo(devicePath, hubHandle, usbPortNum));
@@ -135,11 +140,11 @@ private USBDeviceInfo createDeviceInfo(String devicePath, MemoryAddress hubHandl
var connInfo = session.allocate(USBIOCtl.USB_NODE_CONNECTION_INFORMATION_EX$Struct);
USBIOCtl.USB_NODE_CONNECTION_INFORMATION_EX_ConnectionIndex.set(connInfo, usbPortNum);
var sizeHolder = session.allocate(JAVA_INT);
- if (!Win.DeviceIoControl(hubHandle, USBIOCtl.IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX,
+ if (Kernel32.DeviceIoControl(hubHandle, USBIOCtl.IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX,
connInfo, (int) connInfo.byteSize(),
connInfo, (int) connInfo.byteSize(),
- sizeHolder, NULL))
- throw new USBException("Internal error (cannot get device descriptor)", Win.GetLastError());
+ sizeHolder, NULL) == 0)
+ throw new USBException("Internal error (cannot get device descriptor)", Kernel32.GetLastError());
byte currentConfigurationValue =
(byte) USBIOCtl.USB_NODE_CONNECTION_INFORMATION_EX_CurrentConfigurationValue.get(connInfo);
@@ -188,11 +193,11 @@ private String getStringDescriptor(Addressable hubHandle, int usbPortNumber, int
USBStructs.SetupPacket_wLength.set(setupPacket, (short) dataLen);
var sizeHolder = session.allocate(JAVA_INT);
- if (!Win.DeviceIoControl(hubHandle, USBIOCtl.IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION,
+ if (Kernel32.DeviceIoControl(hubHandle, USBIOCtl.IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION,
descriptorRequest, (int) descriptorRequest.byteSize(),
descriptorRequest, (int) descriptorRequest.byteSize(),
- sizeHolder, NULL))
- throw new USBException(String.format("Cannot retrieve string descriptor %d", index), Win.GetLastError());
+ sizeHolder, NULL) == 0)
+ throw new USBException(String.format("Cannot retrieve string descriptor %d", index), Kernel32.GetLastError());
var stringDesc = descriptorRequest.asSlice(USBIOCtl.USB_DESCRIPTOR_REQUEST_Data$Offset, dataLen);
int stringLen = 255 & (byte) USBIOCtl.USB_STRING_DESCRIPTOR_bLength.get(stringDesc);
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/CfgMgr32.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/CfgMgr32.java
new file mode 100644
index 00000000..b7b83db0
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/CfgMgr32.java
@@ -0,0 +1,44 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.cfgmgr32;
+
+import java.lang.foreign.Addressable;
+import java.lang.invoke.MethodHandle;
+
+import static java.lang.foreign.ValueLayout.*;
+public class CfgMgr32 {
+
+ /* package-private */ CfgMgr32() {}
+ public static OfByte C_CHAR = Constants$root.C_CHAR$LAYOUT;
+ public static OfShort C_SHORT = Constants$root.C_SHORT$LAYOUT;
+ public static OfInt C_INT = Constants$root.C_LONG$LAYOUT;
+ public static OfInt C_LONG = Constants$root.C_LONG$LAYOUT;
+ public static OfLong C_LONG_LONG = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfFloat C_FLOAT = Constants$root.C_FLOAT$LAYOUT;
+ public static OfDouble C_DOUBLE = Constants$root.C_DOUBLE$LAYOUT;
+ public static OfAddress C_POINTER = Constants$root.C_POINTER$LAYOUT;
+ public static MethodHandle CM_Get_Device_IDW$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.CM_Get_Device_IDW$MH,"CM_Get_Device_IDW");
+ }
+ public static int CM_Get_Device_IDW ( int dnDevInst, Addressable Buffer, int BufferLen, int ulFlags) {
+ var mh$ = CM_Get_Device_IDW$MH();
+ try {
+ return (int)mh$.invokeExact(dnDevInst, Buffer, BufferLen, ulFlags);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle CM_Get_Parent$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.CM_Get_Parent$MH,"CM_Get_Parent");
+ }
+ public static int CM_Get_Parent ( Addressable pdnDevInst, int dnDevInst, int ulFlags) {
+ var mh$ = CM_Get_Parent$MH();
+ try {
+ return (int)mh$.invokeExact(pdnDevInst, dnDevInst, ulFlags);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/Constants$root.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/Constants$root.java
new file mode 100644
index 00000000..0f04844e
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/Constants$root.java
@@ -0,0 +1,19 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.cfgmgr32;
+
+import static java.lang.foreign.ValueLayout.*;
+public class Constants$root {
+
+ static final OfBoolean C_BOOL$LAYOUT = JAVA_BOOLEAN;
+ static final OfByte C_CHAR$LAYOUT = JAVA_BYTE;
+ static final OfShort C_SHORT$LAYOUT = JAVA_SHORT.withBitAlignment(16);
+ static final OfInt C_INT$LAYOUT = JAVA_INT.withBitAlignment(32);
+ static final OfInt C_LONG$LAYOUT = JAVA_INT.withBitAlignment(32);
+ static final OfLong C_LONG_LONG$LAYOUT = JAVA_LONG.withBitAlignment(64);
+ static final OfFloat C_FLOAT$LAYOUT = JAVA_FLOAT.withBitAlignment(32);
+ static final OfDouble C_DOUBLE$LAYOUT = JAVA_DOUBLE.withBitAlignment(64);
+ static final OfAddress C_POINTER$LAYOUT = ADDRESS.withBitAlignment(64);
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/RuntimeHelper.java
new file mode 100644
index 00000000..3ac64e04
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/RuntimeHelper.java
@@ -0,0 +1,216 @@
+package net.codecrete.usb.windows.gen.cfgmgr32;
+// Generated by jextract
+
+import java.lang.foreign.*;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+
+import static java.lang.foreign.ValueLayout.*;
+
+final class RuntimeHelper {
+
+ private RuntimeHelper() {}
+ private final static Linker LINKER = Linker.nativeLinker();
+ private final static ClassLoader LOADER = RuntimeHelper.class.getClassLoader();
+ private final static MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup();
+ private final static SymbolLookup SYMBOL_LOOKUP;
+
+ final static SegmentAllocator CONSTANT_ALLOCATOR =
+ (size, align) -> MemorySegment.allocateNative(size, align, MemorySession.openImplicit());
+
+ static {
+ System.loadLibrary("Cfgmgr32");
+ SymbolLookup loaderLookup = SymbolLookup.loaderLookup();
+ SYMBOL_LOOKUP = name -> loaderLookup.lookup(name).or(() -> LINKER.defaultLookup().lookup(name));
+ }
+
+ static T requireNonNull(T obj, String symbolName) {
+ if (obj == null) {
+ throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName);
+ }
+ return obj;
+ }
+
+ private final static SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); };
+
+ static final MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) {
+ return SYMBOL_LOOKUP.lookup(name).map(symbol -> MemorySegment.ofAddress(symbol.address(), layout.byteSize(), MemorySession.openShared())).orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> LINKER.downcallHandle(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(FunctionDescriptor fdesc) {
+ return LINKER.downcallHandle(fdesc);
+ }
+
+ static final MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> VarargsInvoker.make(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MemorySegment upcallStub(Class fi, Z z, FunctionDescriptor fdesc, MemorySession session) {
+ try {
+ MethodHandle handle = MH_LOOKUP.findVirtual(fi, "apply", Linker.upcallType(fdesc));
+ handle = handle.bindTo(z);
+ return LINKER.upcallStub(handle, fdesc, session);
+ } catch (Throwable ex) {
+ throw new AssertionError(ex);
+ }
+ }
+
+ static MemorySegment asArray(MemoryAddress addr, MemoryLayout layout, int numElements, MemorySession session) {
+ return MemorySegment.ofAddress(addr, numElements * layout.byteSize(), session);
+ }
+
+ // Internals only below this point
+
+ private static class VarargsInvoker {
+ private static final MethodHandle INVOKE_MH;
+ private final MemorySegment symbol;
+ private final FunctionDescriptor function;
+
+ private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) {
+ this.symbol = symbol;
+ this.function = function;
+ }
+
+ static {
+ try {
+ INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class));
+ } catch (ReflectiveOperationException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) {
+ VarargsInvoker invoker = new VarargsInvoker(symbol, function);
+ MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1);
+ MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class);
+ for (MemoryLayout layout : function.argumentLayouts()) {
+ mtype = mtype.appendParameterTypes(carrier(layout, false));
+ }
+ mtype = mtype.appendParameterTypes(Object[].class);
+ if (mtype.returnType().equals(MemorySegment.class)) {
+ mtype = mtype.insertParameterTypes(0, SegmentAllocator.class);
+ } else {
+ handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR);
+ }
+ return handle.asType(mtype);
+ }
+
+ static Class> carrier(MemoryLayout layout, boolean ret) {
+ if (layout instanceof ValueLayout valueLayout) {
+ return (ret || valueLayout.carrier() != MemoryAddress.class) ?
+ valueLayout.carrier() : Addressable.class;
+ } else if (layout instanceof GroupLayout) {
+ return MemorySegment.class;
+ } else {
+ throw new AssertionError("Cannot get here!");
+ }
+ }
+
+ private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable {
+ // one trailing Object[]
+ int nNamedArgs = function.argumentLayouts().size();
+ assert(args.length == nNamedArgs + 1);
+ // The last argument is the array of vararg collector
+ Object[] unnamedArgs = (Object[]) args[args.length - 1];
+
+ int argsCount = nNamedArgs + unnamedArgs.length;
+ Class>[] argTypes = new Class>[argsCount];
+ MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length];
+
+ int pos = 0;
+ for (pos = 0; pos < nNamedArgs; pos++) {
+ argLayouts[pos] = function.argumentLayouts().get(pos);
+ }
+
+ assert pos == nNamedArgs;
+ for (Object o: unnamedArgs) {
+ argLayouts[pos] = variadicLayout(normalize(o.getClass()));
+ pos++;
+ }
+ assert pos == argsCount;
+
+ FunctionDescriptor f = (function.returnLayout().isEmpty()) ?
+ FunctionDescriptor.ofVoid(argLayouts) :
+ FunctionDescriptor.of(function.returnLayout().get(), argLayouts);
+ MethodHandle mh = LINKER.downcallHandle(symbol, f);
+ if (mh.type().returnType() == MemorySegment.class) {
+ mh = mh.bindTo(allocator);
+ }
+ // flatten argument list so that it can be passed to an asSpreader MH
+ Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length];
+ System.arraycopy(args, 0, allArgs, 0, nNamedArgs);
+ System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length);
+
+ return mh.asSpreader(Object[].class, argsCount).invoke(allArgs);
+ }
+
+ private static Class> unboxIfNeeded(Class> clazz) {
+ if (clazz == Boolean.class) {
+ return boolean.class;
+ } else if (clazz == Void.class) {
+ return void.class;
+ } else if (clazz == Byte.class) {
+ return byte.class;
+ } else if (clazz == Character.class) {
+ return char.class;
+ } else if (clazz == Short.class) {
+ return short.class;
+ } else if (clazz == Integer.class) {
+ return int.class;
+ } else if (clazz == Long.class) {
+ return long.class;
+ } else if (clazz == Float.class) {
+ return float.class;
+ } else if (clazz == Double.class) {
+ return double.class;
+ } else {
+ return clazz;
+ }
+ }
+
+ private Class> promote(Class> c) {
+ if (c == byte.class || c == char.class || c == short.class || c == int.class) {
+ return long.class;
+ } else if (c == float.class) {
+ return double.class;
+ } else {
+ return c;
+ }
+ }
+
+ private Class> normalize(Class> c) {
+ c = unboxIfNeeded(c);
+ if (c.isPrimitive()) {
+ return promote(c);
+ }
+ if (MemoryAddress.class.isAssignableFrom(c)) {
+ return MemoryAddress.class;
+ }
+ if (MemorySegment.class.isAssignableFrom(c)) {
+ return MemorySegment.class;
+ }
+ throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName());
+ }
+
+ private MemoryLayout variadicLayout(Class> c) {
+ if (c == long.class) {
+ return JAVA_LONG;
+ } else if (c == double.class) {
+ return JAVA_DOUBLE;
+ } else if (MemoryAddress.class.isAssignableFrom(c)) {
+ return ADDRESS;
+ } else {
+ throw new IllegalArgumentException("Unhandled variadic argument class: " + c);
+ }
+ }
+ }
+}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/constants$0.java
new file mode 100644
index 00000000..de3dd42c
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/constants$0.java
@@ -0,0 +1,30 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.cfgmgr32;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$0 {
+
+ static final FunctionDescriptor CM_Get_Device_IDW$FUNC = FunctionDescriptor.of(Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_LONG$LAYOUT
+ );
+ static final MethodHandle CM_Get_Device_IDW$MH = RuntimeHelper.downcallHandle(
+ "CM_Get_Device_IDW",
+ constants$0.CM_Get_Device_IDW$FUNC
+ );
+ static final FunctionDescriptor CM_Get_Parent$FUNC = FunctionDescriptor.of(Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_LONG$LAYOUT
+ );
+ static final MethodHandle CM_Get_Parent$MH = RuntimeHelper.downcallHandle(
+ "CM_Get_Parent",
+ constants$0.CM_Get_Parent$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/Constants$root.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/Constants$root.java
new file mode 100644
index 00000000..bfc827c7
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/Constants$root.java
@@ -0,0 +1,19 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.kernel32;
+
+import static java.lang.foreign.ValueLayout.*;
+public class Constants$root {
+
+ static final OfBoolean C_BOOL$LAYOUT = JAVA_BOOLEAN;
+ static final OfByte C_CHAR$LAYOUT = JAVA_BYTE;
+ static final OfShort C_SHORT$LAYOUT = JAVA_SHORT.withBitAlignment(16);
+ static final OfInt C_INT$LAYOUT = JAVA_INT.withBitAlignment(32);
+ static final OfInt C_LONG$LAYOUT = JAVA_INT.withBitAlignment(32);
+ static final OfLong C_LONG_LONG$LAYOUT = JAVA_LONG.withBitAlignment(64);
+ static final OfFloat C_FLOAT$LAYOUT = JAVA_FLOAT.withBitAlignment(32);
+ static final OfDouble C_DOUBLE$LAYOUT = JAVA_DOUBLE.withBitAlignment(64);
+ static final OfAddress C_POINTER$LAYOUT = ADDRESS.withBitAlignment(64);
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/Kernel32.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/Kernel32.java
new file mode 100644
index 00000000..21d2b421
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/Kernel32.java
@@ -0,0 +1,91 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.kernel32;
+
+import java.lang.foreign.Addressable;
+import java.lang.foreign.MemoryAddress;
+import java.lang.invoke.MethodHandle;
+
+import static java.lang.foreign.ValueLayout.*;
+public class Kernel32 {
+
+ /* package-private */ Kernel32() {}
+ public static OfByte C_CHAR = Constants$root.C_CHAR$LAYOUT;
+ public static OfShort C_SHORT = Constants$root.C_SHORT$LAYOUT;
+ public static OfInt C_INT = Constants$root.C_LONG$LAYOUT;
+ public static OfInt C_LONG = Constants$root.C_LONG$LAYOUT;
+ public static OfLong C_LONG_LONG = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfFloat C_FLOAT = Constants$root.C_FLOAT$LAYOUT;
+ public static OfDouble C_DOUBLE = Constants$root.C_DOUBLE$LAYOUT;
+ public static OfAddress C_POINTER = Constants$root.C_POINTER$LAYOUT;
+ public static int FILE_SHARE_READ() {
+ return (int)1L;
+ }
+ public static int FILE_SHARE_WRITE() {
+ return (int)2L;
+ }
+ public static int FILE_ATTRIBUTE_NORMAL() {
+ return (int)128L;
+ }
+ public static int OPEN_EXISTING() {
+ return (int)3L;
+ }
+ public static int FILE_FLAG_OVERLAPPED() {
+ return (int)1073741824L;
+ }
+ public static MethodHandle CreateFileW$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.CreateFileW$MH,"CreateFileW");
+ }
+ public static MemoryAddress CreateFileW ( Addressable lpFileName, int dwDesiredAccess, int dwShareMode, Addressable lpSecurityAttributes, int dwCreationDisposition, int dwFlagsAndAttributes, Addressable hTemplateFile) {
+ var mh$ = CreateFileW$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle CloseHandle$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.CloseHandle$MH,"CloseHandle");
+ }
+ public static int CloseHandle ( Addressable hObject) {
+ var mh$ = CloseHandle$MH();
+ try {
+ return (int)mh$.invokeExact(hObject);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle GetLastError$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.GetLastError$MH,"GetLastError");
+ }
+ public static int GetLastError () {
+ var mh$ = GetLastError$MH();
+ try {
+ return (int)mh$.invokeExact();
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle DeviceIoControl$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.DeviceIoControl$MH,"DeviceIoControl");
+ }
+ public static int DeviceIoControl ( Addressable hDevice, int dwIoControlCode, Addressable lpInBuffer, int nInBufferSize, Addressable lpOutBuffer, int nOutBufferSize, Addressable lpBytesReturned, Addressable lpOverlapped) {
+ var mh$ = DeviceIoControl$MH();
+ try {
+ return (int)mh$.invokeExact(hDevice, dwIoControlCode, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, lpBytesReturned, lpOverlapped);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static int GENERIC_READ() {
+ return (int)2147483648L;
+ }
+ public static int GENERIC_WRITE() {
+ return (int)1073741824L;
+ }
+ public static int ERROR_NO_MORE_ITEMS() {
+ return (int)259L;
+ }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/RuntimeHelper.java
new file mode 100644
index 00000000..2ed328fb
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/RuntimeHelper.java
@@ -0,0 +1,216 @@
+package net.codecrete.usb.windows.gen.kernel32;
+// Generated by jextract
+
+import java.lang.foreign.*;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+
+import static java.lang.foreign.ValueLayout.*;
+
+final class RuntimeHelper {
+
+ private RuntimeHelper() {}
+ private final static Linker LINKER = Linker.nativeLinker();
+ private final static ClassLoader LOADER = RuntimeHelper.class.getClassLoader();
+ private final static MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup();
+ private final static SymbolLookup SYMBOL_LOOKUP;
+
+ final static SegmentAllocator CONSTANT_ALLOCATOR =
+ (size, align) -> MemorySegment.allocateNative(size, align, MemorySession.openImplicit());
+
+ static {
+ System.loadLibrary("Kernel32");
+ SymbolLookup loaderLookup = SymbolLookup.loaderLookup();
+ SYMBOL_LOOKUP = name -> loaderLookup.lookup(name).or(() -> LINKER.defaultLookup().lookup(name));
+ }
+
+ static T requireNonNull(T obj, String symbolName) {
+ if (obj == null) {
+ throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName);
+ }
+ return obj;
+ }
+
+ private final static SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); };
+
+ static final MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) {
+ return SYMBOL_LOOKUP.lookup(name).map(symbol -> MemorySegment.ofAddress(symbol.address(), layout.byteSize(), MemorySession.openShared())).orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> LINKER.downcallHandle(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(FunctionDescriptor fdesc) {
+ return LINKER.downcallHandle(fdesc);
+ }
+
+ static final MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> VarargsInvoker.make(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MemorySegment upcallStub(Class fi, Z z, FunctionDescriptor fdesc, MemorySession session) {
+ try {
+ MethodHandle handle = MH_LOOKUP.findVirtual(fi, "apply", Linker.upcallType(fdesc));
+ handle = handle.bindTo(z);
+ return LINKER.upcallStub(handle, fdesc, session);
+ } catch (Throwable ex) {
+ throw new AssertionError(ex);
+ }
+ }
+
+ static MemorySegment asArray(MemoryAddress addr, MemoryLayout layout, int numElements, MemorySession session) {
+ return MemorySegment.ofAddress(addr, numElements * layout.byteSize(), session);
+ }
+
+ // Internals only below this point
+
+ private static class VarargsInvoker {
+ private static final MethodHandle INVOKE_MH;
+ private final MemorySegment symbol;
+ private final FunctionDescriptor function;
+
+ private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) {
+ this.symbol = symbol;
+ this.function = function;
+ }
+
+ static {
+ try {
+ INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class));
+ } catch (ReflectiveOperationException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) {
+ VarargsInvoker invoker = new VarargsInvoker(symbol, function);
+ MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1);
+ MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class);
+ for (MemoryLayout layout : function.argumentLayouts()) {
+ mtype = mtype.appendParameterTypes(carrier(layout, false));
+ }
+ mtype = mtype.appendParameterTypes(Object[].class);
+ if (mtype.returnType().equals(MemorySegment.class)) {
+ mtype = mtype.insertParameterTypes(0, SegmentAllocator.class);
+ } else {
+ handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR);
+ }
+ return handle.asType(mtype);
+ }
+
+ static Class> carrier(MemoryLayout layout, boolean ret) {
+ if (layout instanceof ValueLayout valueLayout) {
+ return (ret || valueLayout.carrier() != MemoryAddress.class) ?
+ valueLayout.carrier() : Addressable.class;
+ } else if (layout instanceof GroupLayout) {
+ return MemorySegment.class;
+ } else {
+ throw new AssertionError("Cannot get here!");
+ }
+ }
+
+ private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable {
+ // one trailing Object[]
+ int nNamedArgs = function.argumentLayouts().size();
+ assert(args.length == nNamedArgs + 1);
+ // The last argument is the array of vararg collector
+ Object[] unnamedArgs = (Object[]) args[args.length - 1];
+
+ int argsCount = nNamedArgs + unnamedArgs.length;
+ Class>[] argTypes = new Class>[argsCount];
+ MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length];
+
+ int pos = 0;
+ for (pos = 0; pos < nNamedArgs; pos++) {
+ argLayouts[pos] = function.argumentLayouts().get(pos);
+ }
+
+ assert pos == nNamedArgs;
+ for (Object o: unnamedArgs) {
+ argLayouts[pos] = variadicLayout(normalize(o.getClass()));
+ pos++;
+ }
+ assert pos == argsCount;
+
+ FunctionDescriptor f = (function.returnLayout().isEmpty()) ?
+ FunctionDescriptor.ofVoid(argLayouts) :
+ FunctionDescriptor.of(function.returnLayout().get(), argLayouts);
+ MethodHandle mh = LINKER.downcallHandle(symbol, f);
+ if (mh.type().returnType() == MemorySegment.class) {
+ mh = mh.bindTo(allocator);
+ }
+ // flatten argument list so that it can be passed to an asSpreader MH
+ Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length];
+ System.arraycopy(args, 0, allArgs, 0, nNamedArgs);
+ System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length);
+
+ return mh.asSpreader(Object[].class, argsCount).invoke(allArgs);
+ }
+
+ private static Class> unboxIfNeeded(Class> clazz) {
+ if (clazz == Boolean.class) {
+ return boolean.class;
+ } else if (clazz == Void.class) {
+ return void.class;
+ } else if (clazz == Byte.class) {
+ return byte.class;
+ } else if (clazz == Character.class) {
+ return char.class;
+ } else if (clazz == Short.class) {
+ return short.class;
+ } else if (clazz == Integer.class) {
+ return int.class;
+ } else if (clazz == Long.class) {
+ return long.class;
+ } else if (clazz == Float.class) {
+ return float.class;
+ } else if (clazz == Double.class) {
+ return double.class;
+ } else {
+ return clazz;
+ }
+ }
+
+ private Class> promote(Class> c) {
+ if (c == byte.class || c == char.class || c == short.class || c == int.class) {
+ return long.class;
+ } else if (c == float.class) {
+ return double.class;
+ } else {
+ return c;
+ }
+ }
+
+ private Class> normalize(Class> c) {
+ c = unboxIfNeeded(c);
+ if (c.isPrimitive()) {
+ return promote(c);
+ }
+ if (MemoryAddress.class.isAssignableFrom(c)) {
+ return MemoryAddress.class;
+ }
+ if (MemorySegment.class.isAssignableFrom(c)) {
+ return MemorySegment.class;
+ }
+ throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName());
+ }
+
+ private MemoryLayout variadicLayout(Class> c) {
+ if (c == long.class) {
+ return JAVA_LONG;
+ } else if (c == double.class) {
+ return JAVA_DOUBLE;
+ } else if (MemoryAddress.class.isAssignableFrom(c)) {
+ return ADDRESS;
+ } else {
+ throw new IllegalArgumentException("Unhandled variadic argument class: " + c);
+ }
+ }
+ }
+}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/constants$0.java
new file mode 100644
index 00000000..a350bf86
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/constants$0.java
@@ -0,0 +1,50 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.kernel32;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$0 {
+
+ static final FunctionDescriptor CreateFileW$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle CreateFileW$MH = RuntimeHelper.downcallHandle(
+ "CreateFileW",
+ constants$0.CreateFileW$FUNC
+ );
+ static final FunctionDescriptor CloseHandle$FUNC = FunctionDescriptor.of(Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle CloseHandle$MH = RuntimeHelper.downcallHandle(
+ "CloseHandle",
+ constants$0.CloseHandle$FUNC
+ );
+ static final FunctionDescriptor GetLastError$FUNC = FunctionDescriptor.of(Constants$root.C_LONG$LAYOUT);
+ static final MethodHandle GetLastError$MH = RuntimeHelper.downcallHandle(
+ "GetLastError",
+ constants$0.GetLastError$FUNC
+ );
+ static final FunctionDescriptor DeviceIoControl$FUNC = FunctionDescriptor.of(Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle DeviceIoControl$MH = RuntimeHelper.downcallHandle(
+ "DeviceIoControl",
+ constants$0.DeviceIoControl$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/Constants$root.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/Constants$root.java
new file mode 100644
index 00000000..b6bb6431
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/Constants$root.java
@@ -0,0 +1,19 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.setupapi;
+
+import static java.lang.foreign.ValueLayout.*;
+public class Constants$root {
+
+ static final OfBoolean C_BOOL$LAYOUT = JAVA_BOOLEAN;
+ static final OfByte C_CHAR$LAYOUT = JAVA_BYTE;
+ static final OfShort C_SHORT$LAYOUT = JAVA_SHORT.withBitAlignment(16);
+ static final OfInt C_INT$LAYOUT = JAVA_INT.withBitAlignment(32);
+ static final OfInt C_LONG$LAYOUT = JAVA_INT.withBitAlignment(32);
+ static final OfLong C_LONG_LONG$LAYOUT = JAVA_LONG.withBitAlignment(64);
+ static final OfFloat C_FLOAT$LAYOUT = JAVA_FLOAT.withBitAlignment(32);
+ static final OfDouble C_DOUBLE$LAYOUT = JAVA_DOUBLE.withBitAlignment(64);
+ static final OfAddress C_POINTER$LAYOUT = ADDRESS.withBitAlignment(64);
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/RuntimeHelper.java
new file mode 100644
index 00000000..55f8e04a
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/RuntimeHelper.java
@@ -0,0 +1,216 @@
+package net.codecrete.usb.windows.gen.setupapi;
+// Generated by jextract
+
+import java.lang.foreign.*;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+
+import static java.lang.foreign.ValueLayout.*;
+
+final class RuntimeHelper {
+
+ private RuntimeHelper() {}
+ private final static Linker LINKER = Linker.nativeLinker();
+ private final static ClassLoader LOADER = RuntimeHelper.class.getClassLoader();
+ private final static MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup();
+ private final static SymbolLookup SYMBOL_LOOKUP;
+
+ final static SegmentAllocator CONSTANT_ALLOCATOR =
+ (size, align) -> MemorySegment.allocateNative(size, align, MemorySession.openImplicit());
+
+ static {
+ System.loadLibrary("SetupAPI");
+ SymbolLookup loaderLookup = SymbolLookup.loaderLookup();
+ SYMBOL_LOOKUP = name -> loaderLookup.lookup(name).or(() -> LINKER.defaultLookup().lookup(name));
+ }
+
+ static T requireNonNull(T obj, String symbolName) {
+ if (obj == null) {
+ throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName);
+ }
+ return obj;
+ }
+
+ private final static SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); };
+
+ static final MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) {
+ return SYMBOL_LOOKUP.lookup(name).map(symbol -> MemorySegment.ofAddress(symbol.address(), layout.byteSize(), MemorySession.openShared())).orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> LINKER.downcallHandle(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(FunctionDescriptor fdesc) {
+ return LINKER.downcallHandle(fdesc);
+ }
+
+ static final MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> VarargsInvoker.make(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MemorySegment upcallStub(Class fi, Z z, FunctionDescriptor fdesc, MemorySession session) {
+ try {
+ MethodHandle handle = MH_LOOKUP.findVirtual(fi, "apply", Linker.upcallType(fdesc));
+ handle = handle.bindTo(z);
+ return LINKER.upcallStub(handle, fdesc, session);
+ } catch (Throwable ex) {
+ throw new AssertionError(ex);
+ }
+ }
+
+ static MemorySegment asArray(MemoryAddress addr, MemoryLayout layout, int numElements, MemorySession session) {
+ return MemorySegment.ofAddress(addr, numElements * layout.byteSize(), session);
+ }
+
+ // Internals only below this point
+
+ private static class VarargsInvoker {
+ private static final MethodHandle INVOKE_MH;
+ private final MemorySegment symbol;
+ private final FunctionDescriptor function;
+
+ private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) {
+ this.symbol = symbol;
+ this.function = function;
+ }
+
+ static {
+ try {
+ INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class));
+ } catch (ReflectiveOperationException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) {
+ VarargsInvoker invoker = new VarargsInvoker(symbol, function);
+ MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1);
+ MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class);
+ for (MemoryLayout layout : function.argumentLayouts()) {
+ mtype = mtype.appendParameterTypes(carrier(layout, false));
+ }
+ mtype = mtype.appendParameterTypes(Object[].class);
+ if (mtype.returnType().equals(MemorySegment.class)) {
+ mtype = mtype.insertParameterTypes(0, SegmentAllocator.class);
+ } else {
+ handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR);
+ }
+ return handle.asType(mtype);
+ }
+
+ static Class> carrier(MemoryLayout layout, boolean ret) {
+ if (layout instanceof ValueLayout valueLayout) {
+ return (ret || valueLayout.carrier() != MemoryAddress.class) ?
+ valueLayout.carrier() : Addressable.class;
+ } else if (layout instanceof GroupLayout) {
+ return MemorySegment.class;
+ } else {
+ throw new AssertionError("Cannot get here!");
+ }
+ }
+
+ private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable {
+ // one trailing Object[]
+ int nNamedArgs = function.argumentLayouts().size();
+ assert(args.length == nNamedArgs + 1);
+ // The last argument is the array of vararg collector
+ Object[] unnamedArgs = (Object[]) args[args.length - 1];
+
+ int argsCount = nNamedArgs + unnamedArgs.length;
+ Class>[] argTypes = new Class>[argsCount];
+ MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length];
+
+ int pos = 0;
+ for (pos = 0; pos < nNamedArgs; pos++) {
+ argLayouts[pos] = function.argumentLayouts().get(pos);
+ }
+
+ assert pos == nNamedArgs;
+ for (Object o: unnamedArgs) {
+ argLayouts[pos] = variadicLayout(normalize(o.getClass()));
+ pos++;
+ }
+ assert pos == argsCount;
+
+ FunctionDescriptor f = (function.returnLayout().isEmpty()) ?
+ FunctionDescriptor.ofVoid(argLayouts) :
+ FunctionDescriptor.of(function.returnLayout().get(), argLayouts);
+ MethodHandle mh = LINKER.downcallHandle(symbol, f);
+ if (mh.type().returnType() == MemorySegment.class) {
+ mh = mh.bindTo(allocator);
+ }
+ // flatten argument list so that it can be passed to an asSpreader MH
+ Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length];
+ System.arraycopy(args, 0, allArgs, 0, nNamedArgs);
+ System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length);
+
+ return mh.asSpreader(Object[].class, argsCount).invoke(allArgs);
+ }
+
+ private static Class> unboxIfNeeded(Class> clazz) {
+ if (clazz == Boolean.class) {
+ return boolean.class;
+ } else if (clazz == Void.class) {
+ return void.class;
+ } else if (clazz == Byte.class) {
+ return byte.class;
+ } else if (clazz == Character.class) {
+ return char.class;
+ } else if (clazz == Short.class) {
+ return short.class;
+ } else if (clazz == Integer.class) {
+ return int.class;
+ } else if (clazz == Long.class) {
+ return long.class;
+ } else if (clazz == Float.class) {
+ return float.class;
+ } else if (clazz == Double.class) {
+ return double.class;
+ } else {
+ return clazz;
+ }
+ }
+
+ private Class> promote(Class> c) {
+ if (c == byte.class || c == char.class || c == short.class || c == int.class) {
+ return long.class;
+ } else if (c == float.class) {
+ return double.class;
+ } else {
+ return c;
+ }
+ }
+
+ private Class> normalize(Class> c) {
+ c = unboxIfNeeded(c);
+ if (c.isPrimitive()) {
+ return promote(c);
+ }
+ if (MemoryAddress.class.isAssignableFrom(c)) {
+ return MemoryAddress.class;
+ }
+ if (MemorySegment.class.isAssignableFrom(c)) {
+ return MemorySegment.class;
+ }
+ throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName());
+ }
+
+ private MemoryLayout variadicLayout(Class> c) {
+ if (c == long.class) {
+ return JAVA_LONG;
+ } else if (c == double.class) {
+ return JAVA_DOUBLE;
+ } else if (MemoryAddress.class.isAssignableFrom(c)) {
+ return ADDRESS;
+ } else {
+ throw new IllegalArgumentException("Unhandled variadic argument class: " + c);
+ }
+ }
+ }
+}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SetupAPI.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SetupAPI.java
new file mode 100644
index 00000000..88cd7162
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SetupAPI.java
@@ -0,0 +1,98 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.setupapi;
+
+import java.lang.foreign.Addressable;
+import java.lang.foreign.MemoryAddress;
+import java.lang.invoke.MethodHandle;
+
+import static java.lang.foreign.ValueLayout.*;
+public class SetupAPI {
+
+ /* package-private */ SetupAPI() {}
+ public static OfByte C_CHAR = Constants$root.C_CHAR$LAYOUT;
+ public static OfShort C_SHORT = Constants$root.C_SHORT$LAYOUT;
+ public static OfInt C_INT = Constants$root.C_LONG$LAYOUT;
+ public static OfInt C_LONG = Constants$root.C_LONG$LAYOUT;
+ public static OfLong C_LONG_LONG = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfFloat C_FLOAT = Constants$root.C_FLOAT$LAYOUT;
+ public static OfDouble C_DOUBLE = Constants$root.C_DOUBLE$LAYOUT;
+ public static OfAddress C_POINTER = Constants$root.C_POINTER$LAYOUT;
+ public static int DIGCF_PRESENT() {
+ return (int)2L;
+ }
+ public static int DIGCF_DEVICEINTERFACE() {
+ return (int)16L;
+ }
+ public static MethodHandle SetupDiEnumDeviceInfo$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.SetupDiEnumDeviceInfo$MH,"SetupDiEnumDeviceInfo");
+ }
+ public static int SetupDiEnumDeviceInfo ( Addressable DeviceInfoSet, int MemberIndex, Addressable DeviceInfoData) {
+ var mh$ = SetupDiEnumDeviceInfo$MH();
+ try {
+ return (int)mh$.invokeExact(DeviceInfoSet, MemberIndex, DeviceInfoData);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle SetupDiDestroyDeviceInfoList$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.SetupDiDestroyDeviceInfoList$MH,"SetupDiDestroyDeviceInfoList");
+ }
+ public static int SetupDiDestroyDeviceInfoList ( Addressable DeviceInfoSet) {
+ var mh$ = SetupDiDestroyDeviceInfoList$MH();
+ try {
+ return (int)mh$.invokeExact(DeviceInfoSet);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle SetupDiEnumDeviceInterfaces$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.SetupDiEnumDeviceInterfaces$MH,"SetupDiEnumDeviceInterfaces");
+ }
+ public static int SetupDiEnumDeviceInterfaces ( Addressable DeviceInfoSet, Addressable DeviceInfoData, Addressable InterfaceClassGuid, int MemberIndex, Addressable DeviceInterfaceData) {
+ var mh$ = SetupDiEnumDeviceInterfaces$MH();
+ try {
+ return (int)mh$.invokeExact(DeviceInfoSet, DeviceInfoData, InterfaceClassGuid, MemberIndex, DeviceInterfaceData);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle SetupDiGetDeviceInterfaceDetailW$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.SetupDiGetDeviceInterfaceDetailW$MH,"SetupDiGetDeviceInterfaceDetailW");
+ }
+ public static int SetupDiGetDeviceInterfaceDetailW ( Addressable DeviceInfoSet, Addressable DeviceInterfaceData, Addressable DeviceInterfaceDetailData, int DeviceInterfaceDetailDataSize, Addressable RequiredSize, Addressable DeviceInfoData) {
+ var mh$ = SetupDiGetDeviceInterfaceDetailW$MH();
+ try {
+ return (int)mh$.invokeExact(DeviceInfoSet, DeviceInterfaceData, DeviceInterfaceDetailData, DeviceInterfaceDetailDataSize, RequiredSize, DeviceInfoData);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle SetupDiGetClassDevsW$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.SetupDiGetClassDevsW$MH,"SetupDiGetClassDevsW");
+ }
+ public static MemoryAddress SetupDiGetClassDevsW ( Addressable ClassGuid, Addressable Enumerator, Addressable hwndParent, int Flags) {
+ var mh$ = SetupDiGetClassDevsW$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact(ClassGuid, Enumerator, hwndParent, Flags);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle SetupDiGetDeviceRegistryPropertyW$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.SetupDiGetDeviceRegistryPropertyW$MH,"SetupDiGetDeviceRegistryPropertyW");
+ }
+ public static int SetupDiGetDeviceRegistryPropertyW ( Addressable DeviceInfoSet, Addressable DeviceInfoData, int Property, Addressable PropertyRegDataType, Addressable PropertyBuffer, int PropertyBufferSize, Addressable RequiredSize) {
+ var mh$ = SetupDiGetDeviceRegistryPropertyW$MH();
+ try {
+ return (int)mh$.invokeExact(DeviceInfoSet, DeviceInfoData, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static int SPDRP_ADDRESS() {
+ return (int)28L;
+ }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_SP_DEVICE_INTERFACE_DATA.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_SP_DEVICE_INTERFACE_DATA.java
new file mode 100644
index 00000000..de057457
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_SP_DEVICE_INTERFACE_DATA.java
@@ -0,0 +1,82 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.setupapi;
+
+import java.lang.foreign.*;
+import java.lang.invoke.VarHandle;
+public class _SP_DEVICE_INTERFACE_DATA {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ Constants$root.C_LONG$LAYOUT.withName("cbSize"),
+ MemoryLayout.structLayout(
+ Constants$root.C_LONG$LAYOUT.withName("Data1"),
+ Constants$root.C_SHORT$LAYOUT.withName("Data2"),
+ Constants$root.C_SHORT$LAYOUT.withName("Data3"),
+ MemoryLayout.sequenceLayout(8, Constants$root.C_CHAR$LAYOUT).withName("Data4")
+ ).withName("InterfaceClassGuid"),
+ Constants$root.C_LONG$LAYOUT.withName("Flags"),
+ Constants$root.C_LONG_LONG$LAYOUT.withName("Reserved")
+ ).withName("_SP_DEVICE_INTERFACE_DATA");
+ public static MemoryLayout $LAYOUT() {
+ return _SP_DEVICE_INTERFACE_DATA.$struct$LAYOUT;
+ }
+ static final VarHandle cbSize$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("cbSize"));
+ public static VarHandle cbSize$VH() {
+ return _SP_DEVICE_INTERFACE_DATA.cbSize$VH;
+ }
+ public static int cbSize$get(MemorySegment seg) {
+ return (int)_SP_DEVICE_INTERFACE_DATA.cbSize$VH.get(seg);
+ }
+ public static void cbSize$set( MemorySegment seg, int x) {
+ _SP_DEVICE_INTERFACE_DATA.cbSize$VH.set(seg, x);
+ }
+ public static int cbSize$get(MemorySegment seg, long index) {
+ return (int)_SP_DEVICE_INTERFACE_DATA.cbSize$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void cbSize$set(MemorySegment seg, long index, int x) {
+ _SP_DEVICE_INTERFACE_DATA.cbSize$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static MemorySegment InterfaceClassGuid$slice(MemorySegment seg) {
+ return seg.asSlice(4, 16);
+ }
+ static final VarHandle Flags$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("Flags"));
+ public static VarHandle Flags$VH() {
+ return _SP_DEVICE_INTERFACE_DATA.Flags$VH;
+ }
+ public static int Flags$get(MemorySegment seg) {
+ return (int)_SP_DEVICE_INTERFACE_DATA.Flags$VH.get(seg);
+ }
+ public static void Flags$set( MemorySegment seg, int x) {
+ _SP_DEVICE_INTERFACE_DATA.Flags$VH.set(seg, x);
+ }
+ public static int Flags$get(MemorySegment seg, long index) {
+ return (int)_SP_DEVICE_INTERFACE_DATA.Flags$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void Flags$set(MemorySegment seg, long index, int x) {
+ _SP_DEVICE_INTERFACE_DATA.Flags$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle Reserved$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("Reserved"));
+ public static VarHandle Reserved$VH() {
+ return _SP_DEVICE_INTERFACE_DATA.Reserved$VH;
+ }
+ public static long Reserved$get(MemorySegment seg) {
+ return (long)_SP_DEVICE_INTERFACE_DATA.Reserved$VH.get(seg);
+ }
+ public static void Reserved$set( MemorySegment seg, long x) {
+ _SP_DEVICE_INTERFACE_DATA.Reserved$VH.set(seg, x);
+ }
+ public static long Reserved$get(MemorySegment seg, long index) {
+ return (long)_SP_DEVICE_INTERFACE_DATA.Reserved$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void Reserved$set(MemorySegment seg, long index, long x) {
+ _SP_DEVICE_INTERFACE_DATA.Reserved$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_SP_DEVICE_INTERFACE_DETAIL_DATA_W.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_SP_DEVICE_INTERFACE_DETAIL_DATA_W.java
new file mode 100644
index 00000000..bc3ac979
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_SP_DEVICE_INTERFACE_DETAIL_DATA_W.java
@@ -0,0 +1,44 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.setupapi;
+
+import java.lang.foreign.*;
+import java.lang.invoke.VarHandle;
+public class _SP_DEVICE_INTERFACE_DETAIL_DATA_W {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ Constants$root.C_LONG$LAYOUT.withName("cbSize"),
+ MemoryLayout.sequenceLayout(1, Constants$root.C_SHORT$LAYOUT).withName("DevicePath"),
+ MemoryLayout.paddingLayout(16)
+ ).withName("_SP_DEVICE_INTERFACE_DETAIL_DATA_W");
+ public static MemoryLayout $LAYOUT() {
+ return _SP_DEVICE_INTERFACE_DETAIL_DATA_W.$struct$LAYOUT;
+ }
+ static final VarHandle cbSize$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("cbSize"));
+ public static VarHandle cbSize$VH() {
+ return _SP_DEVICE_INTERFACE_DETAIL_DATA_W.cbSize$VH;
+ }
+ public static int cbSize$get(MemorySegment seg) {
+ return (int)_SP_DEVICE_INTERFACE_DETAIL_DATA_W.cbSize$VH.get(seg);
+ }
+ public static void cbSize$set( MemorySegment seg, int x) {
+ _SP_DEVICE_INTERFACE_DETAIL_DATA_W.cbSize$VH.set(seg, x);
+ }
+ public static int cbSize$get(MemorySegment seg, long index) {
+ return (int)_SP_DEVICE_INTERFACE_DETAIL_DATA_W.cbSize$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void cbSize$set(MemorySegment seg, long index, int x) {
+ _SP_DEVICE_INTERFACE_DETAIL_DATA_W.cbSize$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static MemorySegment DevicePath$slice(MemorySegment seg) {
+ return seg.asSlice(4, 2);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_SP_DEVINFO_DATA.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_SP_DEVINFO_DATA.java
new file mode 100644
index 00000000..dbba0ab5
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/_SP_DEVINFO_DATA.java
@@ -0,0 +1,82 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.setupapi;
+
+import java.lang.foreign.*;
+import java.lang.invoke.VarHandle;
+public class _SP_DEVINFO_DATA {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ Constants$root.C_LONG$LAYOUT.withName("cbSize"),
+ MemoryLayout.structLayout(
+ Constants$root.C_LONG$LAYOUT.withName("Data1"),
+ Constants$root.C_SHORT$LAYOUT.withName("Data2"),
+ Constants$root.C_SHORT$LAYOUT.withName("Data3"),
+ MemoryLayout.sequenceLayout(8, Constants$root.C_CHAR$LAYOUT).withName("Data4")
+ ).withName("ClassGuid"),
+ Constants$root.C_LONG$LAYOUT.withName("DevInst"),
+ Constants$root.C_LONG_LONG$LAYOUT.withName("Reserved")
+ ).withName("_SP_DEVINFO_DATA");
+ public static MemoryLayout $LAYOUT() {
+ return _SP_DEVINFO_DATA.$struct$LAYOUT;
+ }
+ static final VarHandle cbSize$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("cbSize"));
+ public static VarHandle cbSize$VH() {
+ return _SP_DEVINFO_DATA.cbSize$VH;
+ }
+ public static int cbSize$get(MemorySegment seg) {
+ return (int)_SP_DEVINFO_DATA.cbSize$VH.get(seg);
+ }
+ public static void cbSize$set( MemorySegment seg, int x) {
+ _SP_DEVINFO_DATA.cbSize$VH.set(seg, x);
+ }
+ public static int cbSize$get(MemorySegment seg, long index) {
+ return (int)_SP_DEVINFO_DATA.cbSize$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void cbSize$set(MemorySegment seg, long index, int x) {
+ _SP_DEVINFO_DATA.cbSize$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static MemorySegment ClassGuid$slice(MemorySegment seg) {
+ return seg.asSlice(4, 16);
+ }
+ static final VarHandle DevInst$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("DevInst"));
+ public static VarHandle DevInst$VH() {
+ return _SP_DEVINFO_DATA.DevInst$VH;
+ }
+ public static int DevInst$get(MemorySegment seg) {
+ return (int)_SP_DEVINFO_DATA.DevInst$VH.get(seg);
+ }
+ public static void DevInst$set( MemorySegment seg, int x) {
+ _SP_DEVINFO_DATA.DevInst$VH.set(seg, x);
+ }
+ public static int DevInst$get(MemorySegment seg, long index) {
+ return (int)_SP_DEVINFO_DATA.DevInst$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void DevInst$set(MemorySegment seg, long index, int x) {
+ _SP_DEVINFO_DATA.DevInst$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle Reserved$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("Reserved"));
+ public static VarHandle Reserved$VH() {
+ return _SP_DEVINFO_DATA.Reserved$VH;
+ }
+ public static long Reserved$get(MemorySegment seg) {
+ return (long)_SP_DEVINFO_DATA.Reserved$VH.get(seg);
+ }
+ public static void Reserved$set( MemorySegment seg, long x) {
+ _SP_DEVINFO_DATA.Reserved$VH.set(seg, x);
+ }
+ public static long Reserved$get(MemorySegment seg, long index) {
+ return (long)_SP_DEVINFO_DATA.Reserved$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void Reserved$set(MemorySegment seg, long index, long x) {
+ _SP_DEVINFO_DATA.Reserved$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$0.java
new file mode 100644
index 00000000..1c6554b3
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$0.java
@@ -0,0 +1,73 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.setupapi;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$0 {
+
+ static final FunctionDescriptor SetupDiEnumDeviceInfo$FUNC = FunctionDescriptor.of(Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle SetupDiEnumDeviceInfo$MH = RuntimeHelper.downcallHandle(
+ "SetupDiEnumDeviceInfo",
+ constants$0.SetupDiEnumDeviceInfo$FUNC
+ );
+ static final FunctionDescriptor SetupDiDestroyDeviceInfoList$FUNC = FunctionDescriptor.of(Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle SetupDiDestroyDeviceInfoList$MH = RuntimeHelper.downcallHandle(
+ "SetupDiDestroyDeviceInfoList",
+ constants$0.SetupDiDestroyDeviceInfoList$FUNC
+ );
+ static final FunctionDescriptor SetupDiEnumDeviceInterfaces$FUNC = FunctionDescriptor.of(Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle SetupDiEnumDeviceInterfaces$MH = RuntimeHelper.downcallHandle(
+ "SetupDiEnumDeviceInterfaces",
+ constants$0.SetupDiEnumDeviceInterfaces$FUNC
+ );
+ static final FunctionDescriptor SetupDiGetDeviceInterfaceDetailW$FUNC = FunctionDescriptor.of(Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle SetupDiGetDeviceInterfaceDetailW$MH = RuntimeHelper.downcallHandle(
+ "SetupDiGetDeviceInterfaceDetailW",
+ constants$0.SetupDiGetDeviceInterfaceDetailW$FUNC
+ );
+ static final FunctionDescriptor SetupDiGetClassDevsW$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT
+ );
+ static final MethodHandle SetupDiGetClassDevsW$MH = RuntimeHelper.downcallHandle(
+ "SetupDiGetClassDevsW",
+ constants$0.SetupDiGetClassDevsW$FUNC
+ );
+ static final FunctionDescriptor SetupDiGetDeviceRegistryPropertyW$FUNC = FunctionDescriptor.of(Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle SetupDiGetDeviceRegistryPropertyW$MH = RuntimeHelper.downcallHandle(
+ "SetupDiGetDeviceRegistryPropertyW",
+ constants$0.SetupDiGetDeviceRegistryPropertyW$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/stdlib/Constants$root.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/stdlib/Constants$root.java
new file mode 100644
index 00000000..80f6c451
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/stdlib/Constants$root.java
@@ -0,0 +1,19 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.stdlib;
+
+import static java.lang.foreign.ValueLayout.*;
+public class Constants$root {
+
+ static final OfBoolean C_BOOL$LAYOUT = JAVA_BOOLEAN;
+ static final OfByte C_CHAR$LAYOUT = JAVA_BYTE;
+ static final OfShort C_SHORT$LAYOUT = JAVA_SHORT.withBitAlignment(16);
+ static final OfInt C_INT$LAYOUT = JAVA_INT.withBitAlignment(32);
+ static final OfInt C_LONG$LAYOUT = JAVA_INT.withBitAlignment(32);
+ static final OfLong C_LONG_LONG$LAYOUT = JAVA_LONG.withBitAlignment(64);
+ static final OfFloat C_FLOAT$LAYOUT = JAVA_FLOAT.withBitAlignment(32);
+ static final OfDouble C_DOUBLE$LAYOUT = JAVA_DOUBLE.withBitAlignment(64);
+ static final OfAddress C_POINTER$LAYOUT = ADDRESS.withBitAlignment(64);
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/stdlib/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/stdlib/RuntimeHelper.java
new file mode 100644
index 00000000..ffabd418
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/stdlib/RuntimeHelper.java
@@ -0,0 +1,216 @@
+package net.codecrete.usb.windows.gen.stdlib;
+// Generated by jextract
+
+import java.lang.foreign.*;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+
+import static java.lang.foreign.ValueLayout.*;
+
+final class RuntimeHelper {
+
+ private RuntimeHelper() {}
+ private final static Linker LINKER = Linker.nativeLinker();
+ private final static ClassLoader LOADER = RuntimeHelper.class.getClassLoader();
+ private final static MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup();
+ private final static SymbolLookup SYMBOL_LOOKUP;
+
+ final static SegmentAllocator CONSTANT_ALLOCATOR =
+ (size, align) -> MemorySegment.allocateNative(size, align, MemorySession.openImplicit());
+
+ static {
+
+ SymbolLookup loaderLookup = SymbolLookup.loaderLookup();
+ SYMBOL_LOOKUP = name -> loaderLookup.lookup(name).or(() -> LINKER.defaultLookup().lookup(name));
+ }
+
+ static T requireNonNull(T obj, String symbolName) {
+ if (obj == null) {
+ throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName);
+ }
+ return obj;
+ }
+
+ private final static SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); };
+
+ static final MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) {
+ return SYMBOL_LOOKUP.lookup(name).map(symbol -> MemorySegment.ofAddress(symbol.address(), layout.byteSize(), MemorySession.openShared())).orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> LINKER.downcallHandle(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(FunctionDescriptor fdesc) {
+ return LINKER.downcallHandle(fdesc);
+ }
+
+ static final MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> VarargsInvoker.make(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MemorySegment upcallStub(Class fi, Z z, FunctionDescriptor fdesc, MemorySession session) {
+ try {
+ MethodHandle handle = MH_LOOKUP.findVirtual(fi, "apply", Linker.upcallType(fdesc));
+ handle = handle.bindTo(z);
+ return LINKER.upcallStub(handle, fdesc, session);
+ } catch (Throwable ex) {
+ throw new AssertionError(ex);
+ }
+ }
+
+ static MemorySegment asArray(MemoryAddress addr, MemoryLayout layout, int numElements, MemorySession session) {
+ return MemorySegment.ofAddress(addr, numElements * layout.byteSize(), session);
+ }
+
+ // Internals only below this point
+
+ private static class VarargsInvoker {
+ private static final MethodHandle INVOKE_MH;
+ private final MemorySegment symbol;
+ private final FunctionDescriptor function;
+
+ private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) {
+ this.symbol = symbol;
+ this.function = function;
+ }
+
+ static {
+ try {
+ INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class));
+ } catch (ReflectiveOperationException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) {
+ VarargsInvoker invoker = new VarargsInvoker(symbol, function);
+ MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1);
+ MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class);
+ for (MemoryLayout layout : function.argumentLayouts()) {
+ mtype = mtype.appendParameterTypes(carrier(layout, false));
+ }
+ mtype = mtype.appendParameterTypes(Object[].class);
+ if (mtype.returnType().equals(MemorySegment.class)) {
+ mtype = mtype.insertParameterTypes(0, SegmentAllocator.class);
+ } else {
+ handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR);
+ }
+ return handle.asType(mtype);
+ }
+
+ static Class> carrier(MemoryLayout layout, boolean ret) {
+ if (layout instanceof ValueLayout valueLayout) {
+ return (ret || valueLayout.carrier() != MemoryAddress.class) ?
+ valueLayout.carrier() : Addressable.class;
+ } else if (layout instanceof GroupLayout) {
+ return MemorySegment.class;
+ } else {
+ throw new AssertionError("Cannot get here!");
+ }
+ }
+
+ private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable {
+ // one trailing Object[]
+ int nNamedArgs = function.argumentLayouts().size();
+ assert(args.length == nNamedArgs + 1);
+ // The last argument is the array of vararg collector
+ Object[] unnamedArgs = (Object[]) args[args.length - 1];
+
+ int argsCount = nNamedArgs + unnamedArgs.length;
+ Class>[] argTypes = new Class>[argsCount];
+ MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length];
+
+ int pos = 0;
+ for (pos = 0; pos < nNamedArgs; pos++) {
+ argLayouts[pos] = function.argumentLayouts().get(pos);
+ }
+
+ assert pos == nNamedArgs;
+ for (Object o: unnamedArgs) {
+ argLayouts[pos] = variadicLayout(normalize(o.getClass()));
+ pos++;
+ }
+ assert pos == argsCount;
+
+ FunctionDescriptor f = (function.returnLayout().isEmpty()) ?
+ FunctionDescriptor.ofVoid(argLayouts) :
+ FunctionDescriptor.of(function.returnLayout().get(), argLayouts);
+ MethodHandle mh = LINKER.downcallHandle(symbol, f);
+ if (mh.type().returnType() == MemorySegment.class) {
+ mh = mh.bindTo(allocator);
+ }
+ // flatten argument list so that it can be passed to an asSpreader MH
+ Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length];
+ System.arraycopy(args, 0, allArgs, 0, nNamedArgs);
+ System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length);
+
+ return mh.asSpreader(Object[].class, argsCount).invoke(allArgs);
+ }
+
+ private static Class> unboxIfNeeded(Class> clazz) {
+ if (clazz == Boolean.class) {
+ return boolean.class;
+ } else if (clazz == Void.class) {
+ return void.class;
+ } else if (clazz == Byte.class) {
+ return byte.class;
+ } else if (clazz == Character.class) {
+ return char.class;
+ } else if (clazz == Short.class) {
+ return short.class;
+ } else if (clazz == Integer.class) {
+ return int.class;
+ } else if (clazz == Long.class) {
+ return long.class;
+ } else if (clazz == Float.class) {
+ return float.class;
+ } else if (clazz == Double.class) {
+ return double.class;
+ } else {
+ return clazz;
+ }
+ }
+
+ private Class> promote(Class> c) {
+ if (c == byte.class || c == char.class || c == short.class || c == int.class) {
+ return long.class;
+ } else if (c == float.class) {
+ return double.class;
+ } else {
+ return c;
+ }
+ }
+
+ private Class> normalize(Class> c) {
+ c = unboxIfNeeded(c);
+ if (c.isPrimitive()) {
+ return promote(c);
+ }
+ if (MemoryAddress.class.isAssignableFrom(c)) {
+ return MemoryAddress.class;
+ }
+ if (MemorySegment.class.isAssignableFrom(c)) {
+ return MemorySegment.class;
+ }
+ throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName());
+ }
+
+ private MemoryLayout variadicLayout(Class> c) {
+ if (c == long.class) {
+ return JAVA_LONG;
+ } else if (c == double.class) {
+ return JAVA_DOUBLE;
+ } else if (MemoryAddress.class.isAssignableFrom(c)) {
+ return ADDRESS;
+ } else {
+ throw new IllegalArgumentException("Unhandled variadic argument class: " + c);
+ }
+ }
+ }
+}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/stdlib/StdLib.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/stdlib/StdLib.java
new file mode 100644
index 00000000..e76fe363
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/stdlib/StdLib.java
@@ -0,0 +1,33 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.stdlib;
+
+import java.lang.foreign.Addressable;
+import java.lang.invoke.MethodHandle;
+
+import static java.lang.foreign.ValueLayout.*;
+public class StdLib {
+
+ /* package-private */ StdLib() {}
+ public static OfByte C_CHAR = Constants$root.C_CHAR$LAYOUT;
+ public static OfShort C_SHORT = Constants$root.C_SHORT$LAYOUT;
+ public static OfInt C_INT = Constants$root.C_LONG$LAYOUT;
+ public static OfInt C_LONG = Constants$root.C_LONG$LAYOUT;
+ public static OfLong C_LONG_LONG = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfFloat C_FLOAT = Constants$root.C_FLOAT$LAYOUT;
+ public static OfDouble C_DOUBLE = Constants$root.C_DOUBLE$LAYOUT;
+ public static OfAddress C_POINTER = Constants$root.C_POINTER$LAYOUT;
+ public static MethodHandle wcslen$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.wcslen$MH,"wcslen");
+ }
+ public static long wcslen ( Addressable _String) {
+ var mh$ = wcslen$MH();
+ try {
+ return (long)mh$.invokeExact(_String);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/stdlib/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/stdlib/constants$0.java
new file mode 100644
index 00000000..5ca00b1c
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/stdlib/constants$0.java
@@ -0,0 +1,18 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.stdlib;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$0 {
+
+ static final FunctionDescriptor wcslen$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle wcslen$MH = RuntimeHelper.downcallHandle(
+ "wcslen",
+ constants$0.wcslen$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/Constants$root.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/Constants$root.java
new file mode 100644
index 00000000..66ce20c5
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/Constants$root.java
@@ -0,0 +1,19 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.usbioctl;
+
+import static java.lang.foreign.ValueLayout.*;
+public class Constants$root {
+
+ static final OfBoolean C_BOOL$LAYOUT = JAVA_BOOLEAN;
+ static final OfByte C_CHAR$LAYOUT = JAVA_BYTE;
+ static final OfShort C_SHORT$LAYOUT = JAVA_SHORT.withBitAlignment(16);
+ static final OfInt C_INT$LAYOUT = JAVA_INT.withBitAlignment(32);
+ static final OfInt C_LONG$LAYOUT = JAVA_INT.withBitAlignment(32);
+ static final OfLong C_LONG_LONG$LAYOUT = JAVA_LONG.withBitAlignment(64);
+ static final OfFloat C_FLOAT$LAYOUT = JAVA_FLOAT.withBitAlignment(32);
+ static final OfDouble C_DOUBLE$LAYOUT = JAVA_DOUBLE.withBitAlignment(64);
+ static final OfAddress C_POINTER$LAYOUT = ADDRESS.withBitAlignment(64);
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/RuntimeHelper.java
new file mode 100644
index 00000000..5e1c6f71
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/RuntimeHelper.java
@@ -0,0 +1,216 @@
+package net.codecrete.usb.windows.gen.usbioctl;
+// Generated by jextract
+
+import java.lang.foreign.*;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+
+import static java.lang.foreign.ValueLayout.*;
+
+final class RuntimeHelper {
+
+ private RuntimeHelper() {}
+ private final static Linker LINKER = Linker.nativeLinker();
+ private final static ClassLoader LOADER = RuntimeHelper.class.getClassLoader();
+ private final static MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup();
+ private final static SymbolLookup SYMBOL_LOOKUP;
+
+ final static SegmentAllocator CONSTANT_ALLOCATOR =
+ (size, align) -> MemorySegment.allocateNative(size, align, MemorySession.openImplicit());
+
+ static {
+
+ SymbolLookup loaderLookup = SymbolLookup.loaderLookup();
+ SYMBOL_LOOKUP = name -> loaderLookup.lookup(name).or(() -> LINKER.defaultLookup().lookup(name));
+ }
+
+ static T requireNonNull(T obj, String symbolName) {
+ if (obj == null) {
+ throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName);
+ }
+ return obj;
+ }
+
+ private final static SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); };
+
+ static final MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) {
+ return SYMBOL_LOOKUP.lookup(name).map(symbol -> MemorySegment.ofAddress(symbol.address(), layout.byteSize(), MemorySession.openShared())).orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> LINKER.downcallHandle(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(FunctionDescriptor fdesc) {
+ return LINKER.downcallHandle(fdesc);
+ }
+
+ static final MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> VarargsInvoker.make(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MemorySegment upcallStub(Class fi, Z z, FunctionDescriptor fdesc, MemorySession session) {
+ try {
+ MethodHandle handle = MH_LOOKUP.findVirtual(fi, "apply", Linker.upcallType(fdesc));
+ handle = handle.bindTo(z);
+ return LINKER.upcallStub(handle, fdesc, session);
+ } catch (Throwable ex) {
+ throw new AssertionError(ex);
+ }
+ }
+
+ static MemorySegment asArray(MemoryAddress addr, MemoryLayout layout, int numElements, MemorySession session) {
+ return MemorySegment.ofAddress(addr, numElements * layout.byteSize(), session);
+ }
+
+ // Internals only below this point
+
+ private static class VarargsInvoker {
+ private static final MethodHandle INVOKE_MH;
+ private final MemorySegment symbol;
+ private final FunctionDescriptor function;
+
+ private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) {
+ this.symbol = symbol;
+ this.function = function;
+ }
+
+ static {
+ try {
+ INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class));
+ } catch (ReflectiveOperationException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) {
+ VarargsInvoker invoker = new VarargsInvoker(symbol, function);
+ MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1);
+ MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class);
+ for (MemoryLayout layout : function.argumentLayouts()) {
+ mtype = mtype.appendParameterTypes(carrier(layout, false));
+ }
+ mtype = mtype.appendParameterTypes(Object[].class);
+ if (mtype.returnType().equals(MemorySegment.class)) {
+ mtype = mtype.insertParameterTypes(0, SegmentAllocator.class);
+ } else {
+ handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR);
+ }
+ return handle.asType(mtype);
+ }
+
+ static Class> carrier(MemoryLayout layout, boolean ret) {
+ if (layout instanceof ValueLayout valueLayout) {
+ return (ret || valueLayout.carrier() != MemoryAddress.class) ?
+ valueLayout.carrier() : Addressable.class;
+ } else if (layout instanceof GroupLayout) {
+ return MemorySegment.class;
+ } else {
+ throw new AssertionError("Cannot get here!");
+ }
+ }
+
+ private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable {
+ // one trailing Object[]
+ int nNamedArgs = function.argumentLayouts().size();
+ assert(args.length == nNamedArgs + 1);
+ // The last argument is the array of vararg collector
+ Object[] unnamedArgs = (Object[]) args[args.length - 1];
+
+ int argsCount = nNamedArgs + unnamedArgs.length;
+ Class>[] argTypes = new Class>[argsCount];
+ MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length];
+
+ int pos = 0;
+ for (pos = 0; pos < nNamedArgs; pos++) {
+ argLayouts[pos] = function.argumentLayouts().get(pos);
+ }
+
+ assert pos == nNamedArgs;
+ for (Object o: unnamedArgs) {
+ argLayouts[pos] = variadicLayout(normalize(o.getClass()));
+ pos++;
+ }
+ assert pos == argsCount;
+
+ FunctionDescriptor f = (function.returnLayout().isEmpty()) ?
+ FunctionDescriptor.ofVoid(argLayouts) :
+ FunctionDescriptor.of(function.returnLayout().get(), argLayouts);
+ MethodHandle mh = LINKER.downcallHandle(symbol, f);
+ if (mh.type().returnType() == MemorySegment.class) {
+ mh = mh.bindTo(allocator);
+ }
+ // flatten argument list so that it can be passed to an asSpreader MH
+ Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length];
+ System.arraycopy(args, 0, allArgs, 0, nNamedArgs);
+ System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length);
+
+ return mh.asSpreader(Object[].class, argsCount).invoke(allArgs);
+ }
+
+ private static Class> unboxIfNeeded(Class> clazz) {
+ if (clazz == Boolean.class) {
+ return boolean.class;
+ } else if (clazz == Void.class) {
+ return void.class;
+ } else if (clazz == Byte.class) {
+ return byte.class;
+ } else if (clazz == Character.class) {
+ return char.class;
+ } else if (clazz == Short.class) {
+ return short.class;
+ } else if (clazz == Integer.class) {
+ return int.class;
+ } else if (clazz == Long.class) {
+ return long.class;
+ } else if (clazz == Float.class) {
+ return float.class;
+ } else if (clazz == Double.class) {
+ return double.class;
+ } else {
+ return clazz;
+ }
+ }
+
+ private Class> promote(Class> c) {
+ if (c == byte.class || c == char.class || c == short.class || c == int.class) {
+ return long.class;
+ } else if (c == float.class) {
+ return double.class;
+ } else {
+ return c;
+ }
+ }
+
+ private Class> normalize(Class> c) {
+ c = unboxIfNeeded(c);
+ if (c.isPrimitive()) {
+ return promote(c);
+ }
+ if (MemoryAddress.class.isAssignableFrom(c)) {
+ return MemoryAddress.class;
+ }
+ if (MemorySegment.class.isAssignableFrom(c)) {
+ return MemorySegment.class;
+ }
+ throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName());
+ }
+
+ private MemoryLayout variadicLayout(Class> c) {
+ if (c == long.class) {
+ return JAVA_LONG;
+ } else if (c == double.class) {
+ return JAVA_DOUBLE;
+ } else if (MemoryAddress.class.isAssignableFrom(c)) {
+ return ADDRESS;
+ } else {
+ throw new IllegalArgumentException("Unhandled variadic argument class: " + c);
+ }
+ }
+ }
+}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/USBIoctl.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/USBIoctl.java
new file mode 100644
index 00000000..d6a326fe
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/USBIoctl.java
@@ -0,0 +1,19 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.usbioctl;
+
+import static java.lang.foreign.ValueLayout.*;
+public class USBIoctl {
+
+ /* package-private */ USBIoctl() {}
+ public static OfByte C_CHAR = Constants$root.C_CHAR$LAYOUT;
+ public static OfShort C_SHORT = Constants$root.C_SHORT$LAYOUT;
+ public static OfInt C_INT = Constants$root.C_LONG$LAYOUT;
+ public static OfInt C_LONG = Constants$root.C_LONG$LAYOUT;
+ public static OfLong C_LONG_LONG = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfFloat C_FLOAT = Constants$root.C_FLOAT$LAYOUT;
+ public static OfDouble C_DOUBLE = Constants$root.C_DOUBLE$LAYOUT;
+ public static OfAddress C_POINTER = Constants$root.C_POINTER$LAYOUT;
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/_USB_NODE_CONNECTION_INFORMATION_EX.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/_USB_NODE_CONNECTION_INFORMATION_EX.java
new file mode 100644
index 00000000..892dd93d
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/_USB_NODE_CONNECTION_INFORMATION_EX.java
@@ -0,0 +1,171 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.usbioctl;
+
+import java.lang.foreign.*;
+import java.lang.invoke.VarHandle;
+public class _USB_NODE_CONNECTION_INFORMATION_EX {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ Constants$root.C_LONG$LAYOUT.withName("ConnectionIndex"),
+ MemoryLayout.structLayout(
+ Constants$root.C_CHAR$LAYOUT.withName("bLength"),
+ Constants$root.C_CHAR$LAYOUT.withName("bDescriptorType"),
+ Constants$root.C_SHORT$LAYOUT.withName("bcdUSB"),
+ Constants$root.C_CHAR$LAYOUT.withName("bDeviceClass"),
+ Constants$root.C_CHAR$LAYOUT.withName("bDeviceSubClass"),
+ Constants$root.C_CHAR$LAYOUT.withName("bDeviceProtocol"),
+ Constants$root.C_CHAR$LAYOUT.withName("bMaxPacketSize0"),
+ Constants$root.C_SHORT$LAYOUT.withName("idVendor"),
+ Constants$root.C_SHORT$LAYOUT.withName("idProduct"),
+ Constants$root.C_SHORT$LAYOUT.withName("bcdDevice"),
+ Constants$root.C_CHAR$LAYOUT.withName("iManufacturer"),
+ Constants$root.C_CHAR$LAYOUT.withName("iProduct"),
+ Constants$root.C_CHAR$LAYOUT.withName("iSerialNumber"),
+ Constants$root.C_CHAR$LAYOUT.withName("bNumConfigurations")
+ ).withName("DeviceDescriptor"),
+ Constants$root.C_CHAR$LAYOUT.withName("CurrentConfigurationValue"),
+ Constants$root.C_CHAR$LAYOUT.withName("Speed"),
+ Constants$root.C_CHAR$LAYOUT.withName("DeviceIsHub"),
+ Constants$root.C_SHORT$LAYOUT.withName("DeviceAddress"),
+ Constants$root.C_LONG$LAYOUT.withName("NumberOfOpenPipes"),
+ Constants$root.C_LONG$LAYOUT.withName("ConnectionStatus"),
+ MemoryLayout.sequenceLayout(0, MemoryLayout.structLayout(
+ MemoryLayout.structLayout(
+ Constants$root.C_CHAR$LAYOUT.withName("bLength"),
+ Constants$root.C_CHAR$LAYOUT.withName("bDescriptorType"),
+ Constants$root.C_CHAR$LAYOUT.withName("bEndpointAddress"),
+ Constants$root.C_CHAR$LAYOUT.withName("bmAttributes"),
+ Constants$root.C_SHORT$LAYOUT.withName("wMaxPacketSize"),
+ Constants$root.C_CHAR$LAYOUT.withName("bInterval")
+ ).withName("EndpointDescriptor"),
+ Constants$root.C_LONG$LAYOUT.withName("ScheduleOffset")
+ ).withName("_USB_PIPE_INFO")).withName("PipeList")
+ ).withName("_USB_NODE_CONNECTION_INFORMATION_EX");
+ public static MemoryLayout $LAYOUT() {
+ return _USB_NODE_CONNECTION_INFORMATION_EX.$struct$LAYOUT;
+ }
+ static final VarHandle ConnectionIndex$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("ConnectionIndex"));
+ public static VarHandle ConnectionIndex$VH() {
+ return _USB_NODE_CONNECTION_INFORMATION_EX.ConnectionIndex$VH;
+ }
+ public static int ConnectionIndex$get(MemorySegment seg) {
+ return (int)_USB_NODE_CONNECTION_INFORMATION_EX.ConnectionIndex$VH.get(seg);
+ }
+ public static void ConnectionIndex$set( MemorySegment seg, int x) {
+ _USB_NODE_CONNECTION_INFORMATION_EX.ConnectionIndex$VH.set(seg, x);
+ }
+ public static int ConnectionIndex$get(MemorySegment seg, long index) {
+ return (int)_USB_NODE_CONNECTION_INFORMATION_EX.ConnectionIndex$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void ConnectionIndex$set(MemorySegment seg, long index, int x) {
+ _USB_NODE_CONNECTION_INFORMATION_EX.ConnectionIndex$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static MemorySegment DeviceDescriptor$slice(MemorySegment seg) {
+ return seg.asSlice(4, 18);
+ }
+ static final VarHandle CurrentConfigurationValue$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("CurrentConfigurationValue"));
+ public static VarHandle CurrentConfigurationValue$VH() {
+ return _USB_NODE_CONNECTION_INFORMATION_EX.CurrentConfigurationValue$VH;
+ }
+ public static byte CurrentConfigurationValue$get(MemorySegment seg) {
+ return (byte)_USB_NODE_CONNECTION_INFORMATION_EX.CurrentConfigurationValue$VH.get(seg);
+ }
+ public static void CurrentConfigurationValue$set( MemorySegment seg, byte x) {
+ _USB_NODE_CONNECTION_INFORMATION_EX.CurrentConfigurationValue$VH.set(seg, x);
+ }
+ public static byte CurrentConfigurationValue$get(MemorySegment seg, long index) {
+ return (byte)_USB_NODE_CONNECTION_INFORMATION_EX.CurrentConfigurationValue$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void CurrentConfigurationValue$set(MemorySegment seg, long index, byte x) {
+ _USB_NODE_CONNECTION_INFORMATION_EX.CurrentConfigurationValue$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle Speed$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("Speed"));
+ public static VarHandle Speed$VH() {
+ return _USB_NODE_CONNECTION_INFORMATION_EX.Speed$VH;
+ }
+ public static byte Speed$get(MemorySegment seg) {
+ return (byte)_USB_NODE_CONNECTION_INFORMATION_EX.Speed$VH.get(seg);
+ }
+ public static void Speed$set( MemorySegment seg, byte x) {
+ _USB_NODE_CONNECTION_INFORMATION_EX.Speed$VH.set(seg, x);
+ }
+ public static byte Speed$get(MemorySegment seg, long index) {
+ return (byte)_USB_NODE_CONNECTION_INFORMATION_EX.Speed$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void Speed$set(MemorySegment seg, long index, byte x) {
+ _USB_NODE_CONNECTION_INFORMATION_EX.Speed$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle DeviceIsHub$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("DeviceIsHub"));
+ public static VarHandle DeviceIsHub$VH() {
+ return _USB_NODE_CONNECTION_INFORMATION_EX.DeviceIsHub$VH;
+ }
+ public static byte DeviceIsHub$get(MemorySegment seg) {
+ return (byte)_USB_NODE_CONNECTION_INFORMATION_EX.DeviceIsHub$VH.get(seg);
+ }
+ public static void DeviceIsHub$set( MemorySegment seg, byte x) {
+ _USB_NODE_CONNECTION_INFORMATION_EX.DeviceIsHub$VH.set(seg, x);
+ }
+ public static byte DeviceIsHub$get(MemorySegment seg, long index) {
+ return (byte)_USB_NODE_CONNECTION_INFORMATION_EX.DeviceIsHub$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void DeviceIsHub$set(MemorySegment seg, long index, byte x) {
+ _USB_NODE_CONNECTION_INFORMATION_EX.DeviceIsHub$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle DeviceAddress$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("DeviceAddress"));
+ public static VarHandle DeviceAddress$VH() {
+ return _USB_NODE_CONNECTION_INFORMATION_EX.DeviceAddress$VH;
+ }
+ public static short DeviceAddress$get(MemorySegment seg) {
+ return (short)_USB_NODE_CONNECTION_INFORMATION_EX.DeviceAddress$VH.get(seg);
+ }
+ public static void DeviceAddress$set( MemorySegment seg, short x) {
+ _USB_NODE_CONNECTION_INFORMATION_EX.DeviceAddress$VH.set(seg, x);
+ }
+ public static short DeviceAddress$get(MemorySegment seg, long index) {
+ return (short)_USB_NODE_CONNECTION_INFORMATION_EX.DeviceAddress$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void DeviceAddress$set(MemorySegment seg, long index, short x) {
+ _USB_NODE_CONNECTION_INFORMATION_EX.DeviceAddress$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle NumberOfOpenPipes$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("NumberOfOpenPipes"));
+ public static VarHandle NumberOfOpenPipes$VH() {
+ return _USB_NODE_CONNECTION_INFORMATION_EX.NumberOfOpenPipes$VH;
+ }
+ public static int NumberOfOpenPipes$get(MemorySegment seg) {
+ return (int)_USB_NODE_CONNECTION_INFORMATION_EX.NumberOfOpenPipes$VH.get(seg);
+ }
+ public static void NumberOfOpenPipes$set( MemorySegment seg, int x) {
+ _USB_NODE_CONNECTION_INFORMATION_EX.NumberOfOpenPipes$VH.set(seg, x);
+ }
+ public static int NumberOfOpenPipes$get(MemorySegment seg, long index) {
+ return (int)_USB_NODE_CONNECTION_INFORMATION_EX.NumberOfOpenPipes$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void NumberOfOpenPipes$set(MemorySegment seg, long index, int x) {
+ _USB_NODE_CONNECTION_INFORMATION_EX.NumberOfOpenPipes$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle ConnectionStatus$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("ConnectionStatus"));
+ public static VarHandle ConnectionStatus$VH() {
+ return _USB_NODE_CONNECTION_INFORMATION_EX.ConnectionStatus$VH;
+ }
+ public static int ConnectionStatus$get(MemorySegment seg) {
+ return (int)_USB_NODE_CONNECTION_INFORMATION_EX.ConnectionStatus$VH.get(seg);
+ }
+ public static void ConnectionStatus$set( MemorySegment seg, int x) {
+ _USB_NODE_CONNECTION_INFORMATION_EX.ConnectionStatus$VH.set(seg, x);
+ }
+ public static int ConnectionStatus$get(MemorySegment seg, long index) {
+ return (int)_USB_NODE_CONNECTION_INFORMATION_EX.ConnectionStatus$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void ConnectionStatus$set(MemorySegment seg, long index, int x) {
+ _USB_NODE_CONNECTION_INFORMATION_EX.ConnectionStatus$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/winusb/Constants$root.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/winusb/Constants$root.java
new file mode 100644
index 00000000..3568e394
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/winusb/Constants$root.java
@@ -0,0 +1,19 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.winusb;
+
+import static java.lang.foreign.ValueLayout.*;
+public class Constants$root {
+
+ static final OfBoolean C_BOOL$LAYOUT = JAVA_BOOLEAN;
+ static final OfByte C_CHAR$LAYOUT = JAVA_BYTE;
+ static final OfShort C_SHORT$LAYOUT = JAVA_SHORT.withBitAlignment(16);
+ static final OfInt C_INT$LAYOUT = JAVA_INT.withBitAlignment(32);
+ static final OfInt C_LONG$LAYOUT = JAVA_INT.withBitAlignment(32);
+ static final OfLong C_LONG_LONG$LAYOUT = JAVA_LONG.withBitAlignment(64);
+ static final OfFloat C_FLOAT$LAYOUT = JAVA_FLOAT.withBitAlignment(32);
+ static final OfDouble C_DOUBLE$LAYOUT = JAVA_DOUBLE.withBitAlignment(64);
+ static final OfAddress C_POINTER$LAYOUT = ADDRESS.withBitAlignment(64);
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/winusb/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/winusb/RuntimeHelper.java
new file mode 100644
index 00000000..f4a55475
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/winusb/RuntimeHelper.java
@@ -0,0 +1,216 @@
+package net.codecrete.usb.windows.gen.winusb;
+// Generated by jextract
+
+import java.lang.foreign.*;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+
+import static java.lang.foreign.ValueLayout.*;
+
+final class RuntimeHelper {
+
+ private RuntimeHelper() {}
+ private final static Linker LINKER = Linker.nativeLinker();
+ private final static ClassLoader LOADER = RuntimeHelper.class.getClassLoader();
+ private final static MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup();
+ private final static SymbolLookup SYMBOL_LOOKUP;
+
+ final static SegmentAllocator CONSTANT_ALLOCATOR =
+ (size, align) -> MemorySegment.allocateNative(size, align, MemorySession.openImplicit());
+
+ static {
+ System.loadLibrary("Winusb");
+ SymbolLookup loaderLookup = SymbolLookup.loaderLookup();
+ SYMBOL_LOOKUP = name -> loaderLookup.lookup(name).or(() -> LINKER.defaultLookup().lookup(name));
+ }
+
+ static T requireNonNull(T obj, String symbolName) {
+ if (obj == null) {
+ throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName);
+ }
+ return obj;
+ }
+
+ private final static SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); };
+
+ static final MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) {
+ return SYMBOL_LOOKUP.lookup(name).map(symbol -> MemorySegment.ofAddress(symbol.address(), layout.byteSize(), MemorySession.openShared())).orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> LINKER.downcallHandle(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(FunctionDescriptor fdesc) {
+ return LINKER.downcallHandle(fdesc);
+ }
+
+ static final MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> VarargsInvoker.make(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MemorySegment upcallStub(Class fi, Z z, FunctionDescriptor fdesc, MemorySession session) {
+ try {
+ MethodHandle handle = MH_LOOKUP.findVirtual(fi, "apply", Linker.upcallType(fdesc));
+ handle = handle.bindTo(z);
+ return LINKER.upcallStub(handle, fdesc, session);
+ } catch (Throwable ex) {
+ throw new AssertionError(ex);
+ }
+ }
+
+ static MemorySegment asArray(MemoryAddress addr, MemoryLayout layout, int numElements, MemorySession session) {
+ return MemorySegment.ofAddress(addr, numElements * layout.byteSize(), session);
+ }
+
+ // Internals only below this point
+
+ private static class VarargsInvoker {
+ private static final MethodHandle INVOKE_MH;
+ private final MemorySegment symbol;
+ private final FunctionDescriptor function;
+
+ private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) {
+ this.symbol = symbol;
+ this.function = function;
+ }
+
+ static {
+ try {
+ INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class));
+ } catch (ReflectiveOperationException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) {
+ VarargsInvoker invoker = new VarargsInvoker(symbol, function);
+ MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1);
+ MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class);
+ for (MemoryLayout layout : function.argumentLayouts()) {
+ mtype = mtype.appendParameterTypes(carrier(layout, false));
+ }
+ mtype = mtype.appendParameterTypes(Object[].class);
+ if (mtype.returnType().equals(MemorySegment.class)) {
+ mtype = mtype.insertParameterTypes(0, SegmentAllocator.class);
+ } else {
+ handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR);
+ }
+ return handle.asType(mtype);
+ }
+
+ static Class> carrier(MemoryLayout layout, boolean ret) {
+ if (layout instanceof ValueLayout valueLayout) {
+ return (ret || valueLayout.carrier() != MemoryAddress.class) ?
+ valueLayout.carrier() : Addressable.class;
+ } else if (layout instanceof GroupLayout) {
+ return MemorySegment.class;
+ } else {
+ throw new AssertionError("Cannot get here!");
+ }
+ }
+
+ private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable {
+ // one trailing Object[]
+ int nNamedArgs = function.argumentLayouts().size();
+ assert(args.length == nNamedArgs + 1);
+ // The last argument is the array of vararg collector
+ Object[] unnamedArgs = (Object[]) args[args.length - 1];
+
+ int argsCount = nNamedArgs + unnamedArgs.length;
+ Class>[] argTypes = new Class>[argsCount];
+ MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length];
+
+ int pos = 0;
+ for (pos = 0; pos < nNamedArgs; pos++) {
+ argLayouts[pos] = function.argumentLayouts().get(pos);
+ }
+
+ assert pos == nNamedArgs;
+ for (Object o: unnamedArgs) {
+ argLayouts[pos] = variadicLayout(normalize(o.getClass()));
+ pos++;
+ }
+ assert pos == argsCount;
+
+ FunctionDescriptor f = (function.returnLayout().isEmpty()) ?
+ FunctionDescriptor.ofVoid(argLayouts) :
+ FunctionDescriptor.of(function.returnLayout().get(), argLayouts);
+ MethodHandle mh = LINKER.downcallHandle(symbol, f);
+ if (mh.type().returnType() == MemorySegment.class) {
+ mh = mh.bindTo(allocator);
+ }
+ // flatten argument list so that it can be passed to an asSpreader MH
+ Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length];
+ System.arraycopy(args, 0, allArgs, 0, nNamedArgs);
+ System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length);
+
+ return mh.asSpreader(Object[].class, argsCount).invoke(allArgs);
+ }
+
+ private static Class> unboxIfNeeded(Class> clazz) {
+ if (clazz == Boolean.class) {
+ return boolean.class;
+ } else if (clazz == Void.class) {
+ return void.class;
+ } else if (clazz == Byte.class) {
+ return byte.class;
+ } else if (clazz == Character.class) {
+ return char.class;
+ } else if (clazz == Short.class) {
+ return short.class;
+ } else if (clazz == Integer.class) {
+ return int.class;
+ } else if (clazz == Long.class) {
+ return long.class;
+ } else if (clazz == Float.class) {
+ return float.class;
+ } else if (clazz == Double.class) {
+ return double.class;
+ } else {
+ return clazz;
+ }
+ }
+
+ private Class> promote(Class> c) {
+ if (c == byte.class || c == char.class || c == short.class || c == int.class) {
+ return long.class;
+ } else if (c == float.class) {
+ return double.class;
+ } else {
+ return c;
+ }
+ }
+
+ private Class> normalize(Class> c) {
+ c = unboxIfNeeded(c);
+ if (c.isPrimitive()) {
+ return promote(c);
+ }
+ if (MemoryAddress.class.isAssignableFrom(c)) {
+ return MemoryAddress.class;
+ }
+ if (MemorySegment.class.isAssignableFrom(c)) {
+ return MemorySegment.class;
+ }
+ throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName());
+ }
+
+ private MemoryLayout variadicLayout(Class> c) {
+ if (c == long.class) {
+ return JAVA_LONG;
+ } else if (c == double.class) {
+ return JAVA_DOUBLE;
+ } else if (MemoryAddress.class.isAssignableFrom(c)) {
+ return ADDRESS;
+ } else {
+ throw new IllegalArgumentException("Unhandled variadic argument class: " + c);
+ }
+ }
+ }
+}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/winusb/WinUSB.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/winusb/WinUSB.java
new file mode 100644
index 00000000..43250a47
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/winusb/WinUSB.java
@@ -0,0 +1,89 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.winusb;
+
+import java.lang.foreign.Addressable;
+import java.lang.foreign.MemorySegment;
+import java.lang.invoke.MethodHandle;
+
+import static java.lang.foreign.ValueLayout.*;
+public class WinUSB {
+
+ /* package-private */ WinUSB() {}
+ public static OfByte C_CHAR = Constants$root.C_CHAR$LAYOUT;
+ public static OfShort C_SHORT = Constants$root.C_SHORT$LAYOUT;
+ public static OfInt C_INT = Constants$root.C_LONG$LAYOUT;
+ public static OfInt C_LONG = Constants$root.C_LONG$LAYOUT;
+ public static OfLong C_LONG_LONG = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfFloat C_FLOAT = Constants$root.C_FLOAT$LAYOUT;
+ public static OfDouble C_DOUBLE = Constants$root.C_DOUBLE$LAYOUT;
+ public static OfAddress C_POINTER = Constants$root.C_POINTER$LAYOUT;
+ public static MethodHandle WinUsb_Initialize$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.WinUsb_Initialize$MH,"WinUsb_Initialize");
+ }
+ public static int WinUsb_Initialize ( Addressable DeviceHandle, Addressable InterfaceHandle) {
+ var mh$ = WinUsb_Initialize$MH();
+ try {
+ return (int)mh$.invokeExact(DeviceHandle, InterfaceHandle);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle WinUsb_Free$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.WinUsb_Free$MH,"WinUsb_Free");
+ }
+ public static int WinUsb_Free ( Addressable InterfaceHandle) {
+ var mh$ = WinUsb_Free$MH();
+ try {
+ return (int)mh$.invokeExact(InterfaceHandle);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle WinUsb_GetDescriptor$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.WinUsb_GetDescriptor$MH,"WinUsb_GetDescriptor");
+ }
+ public static int WinUsb_GetDescriptor ( Addressable InterfaceHandle, byte DescriptorType, byte Index, short LanguageID, Addressable Buffer, int BufferLength, Addressable LengthTransferred) {
+ var mh$ = WinUsb_GetDescriptor$MH();
+ try {
+ return (int)mh$.invokeExact(InterfaceHandle, DescriptorType, Index, LanguageID, Buffer, BufferLength, LengthTransferred);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle WinUsb_ReadPipe$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.WinUsb_ReadPipe$MH,"WinUsb_ReadPipe");
+ }
+ public static int WinUsb_ReadPipe ( Addressable InterfaceHandle, byte PipeID, Addressable Buffer, int BufferLength, Addressable LengthTransferred, Addressable Overlapped) {
+ var mh$ = WinUsb_ReadPipe$MH();
+ try {
+ return (int)mh$.invokeExact(InterfaceHandle, PipeID, Buffer, BufferLength, LengthTransferred, Overlapped);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle WinUsb_WritePipe$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.WinUsb_WritePipe$MH,"WinUsb_WritePipe");
+ }
+ public static int WinUsb_WritePipe ( Addressable InterfaceHandle, byte PipeID, Addressable Buffer, int BufferLength, Addressable LengthTransferred, Addressable Overlapped) {
+ var mh$ = WinUsb_WritePipe$MH();
+ try {
+ return (int)mh$.invokeExact(InterfaceHandle, PipeID, Buffer, BufferLength, LengthTransferred, Overlapped);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle WinUsb_ControlTransfer$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.WinUsb_ControlTransfer$MH,"WinUsb_ControlTransfer");
+ }
+ public static int WinUsb_ControlTransfer ( Addressable InterfaceHandle, MemorySegment SetupPacket, Addressable Buffer, int BufferLength, Addressable LengthTransferred, Addressable Overlapped) {
+ var mh$ = WinUsb_ControlTransfer$MH();
+ try {
+ return (int)mh$.invokeExact(InterfaceHandle, SetupPacket, Buffer, BufferLength, LengthTransferred, Overlapped);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/winusb/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/winusb/constants$0.java
new file mode 100644
index 00000000..57e13e9a
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/winusb/constants$0.java
@@ -0,0 +1,82 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.winusb;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.foreign.MemoryLayout;
+import java.lang.invoke.MethodHandle;
+class constants$0 {
+
+ static final FunctionDescriptor WinUsb_Initialize$FUNC = FunctionDescriptor.of(Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle WinUsb_Initialize$MH = RuntimeHelper.downcallHandle(
+ "WinUsb_Initialize",
+ constants$0.WinUsb_Initialize$FUNC
+ );
+ static final FunctionDescriptor WinUsb_Free$FUNC = FunctionDescriptor.of(Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle WinUsb_Free$MH = RuntimeHelper.downcallHandle(
+ "WinUsb_Free",
+ constants$0.WinUsb_Free$FUNC
+ );
+ static final FunctionDescriptor WinUsb_GetDescriptor$FUNC = FunctionDescriptor.of(Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_CHAR$LAYOUT,
+ Constants$root.C_CHAR$LAYOUT,
+ Constants$root.C_SHORT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle WinUsb_GetDescriptor$MH = RuntimeHelper.downcallHandle(
+ "WinUsb_GetDescriptor",
+ constants$0.WinUsb_GetDescriptor$FUNC
+ );
+ static final FunctionDescriptor WinUsb_ReadPipe$FUNC = FunctionDescriptor.of(Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_CHAR$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle WinUsb_ReadPipe$MH = RuntimeHelper.downcallHandle(
+ "WinUsb_ReadPipe",
+ constants$0.WinUsb_ReadPipe$FUNC
+ );
+ static final FunctionDescriptor WinUsb_WritePipe$FUNC = FunctionDescriptor.of(Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_CHAR$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle WinUsb_WritePipe$MH = RuntimeHelper.downcallHandle(
+ "WinUsb_WritePipe",
+ constants$0.WinUsb_WritePipe$FUNC
+ );
+ static final FunctionDescriptor WinUsb_ControlTransfer$FUNC = FunctionDescriptor.of(Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ MemoryLayout.structLayout(
+ Constants$root.C_CHAR$LAYOUT.withName("RequestType"),
+ Constants$root.C_CHAR$LAYOUT.withName("Request"),
+ Constants$root.C_SHORT$LAYOUT.withName("Value"),
+ Constants$root.C_SHORT$LAYOUT.withName("Index"),
+ Constants$root.C_SHORT$LAYOUT.withName("Length")
+ ).withName("_WINUSB_SETUP_PACKET"),
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle WinUsb_ControlTransfer$MH = RuntimeHelper.downcallHandle(
+ "WinUsb_ControlTransfer",
+ constants$0.WinUsb_ControlTransfer$FUNC
+ );
+}
+
+
From 4b741a9eca6d8b3e983f17dca6114d8e0e7fb47a Mon Sep 17 00:00:00 2001
From: Manuel Bleichenbacher
Date: Tue, 23 Aug 2022 22:16:55 +0200
Subject: [PATCH 008/433] Windows: remove old file
---
java-does-usb/jextract/gen_windows.cmd | 19 -------------------
1 file changed, 19 deletions(-)
delete mode 100644 java-does-usb/jextract/gen_windows.cmd
diff --git a/java-does-usb/jextract/gen_windows.cmd b/java-does-usb/jextract/gen_windows.cmd
deleted file mode 100644
index f75288f1..00000000
--- a/java-does-usb/jextract/gen_windows.cmd
+++ /dev/null
@@ -1,19 +0,0 @@
-set JEXTRACT=..\..\..\jextract\build\jextract\bin\jextract.bat
-
-:: cfgmgr32.h
-:: Fails with error:
-:: C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\shared\devpropdef.h:33:9: error: unknown type name 'ULONG'
-::%JEXTRACT% --source --output ../src/main/java ^
-:: -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
-:: --header-class-name CfgMgr32 ^
-:: --target-package net.codecrete.usb.windows.gen.cfgmgr32 ^
-:: "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\cfgmgr32.h"
-
-:: setupapi.h
-:: Fails with error:
-:: C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\setupapi.h:65:9: error: unknown type name 'GUID'
-::%JEXTRACT% --source --output ../src/main/java ^
-:: -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
-:: --header-class-name SetupApi ^
-:: --target-package net.codecrete.usb.windows.gen.setupapi ^
-:: "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\setupapi.h"
From a6bb67c02b5ca0d305f963dc4b28d9a819acf038 Mon Sep 17 00:00:00 2001
From: Manuel Bl
Date: Wed, 24 Aug 2022 19:58:07 +0200
Subject: [PATCH 009/433] Windows: use more generated code
---
java-does-usb/jextract/gen_win_cfgmgr32.cmd | 2 +-
java-does-usb/jextract/gen_win_kernel32.cmd | 3 +-
java-does-usb/jextract/gen_win_setupapi.cmd | 2 +-
java-does-usb/jextract/gen_win_stdlib.cmd | 2 +-
java-does-usb/jextract/gen_win_usbioctl.cmd | 4 +-
java-does-usb/jextract/gen_win_winusb.cmd | 2 +-
java-does-usb/jextract/windows_cfgmgr32.h | 2 -
java-does-usb/jextract/windows_headers.h | 6 +
java-does-usb/jextract/windows_kernel32.h | 1 -
java-does-usb/jextract/windows_setupapi.h | 2 -
java-does-usb/jextract/windows_stdlib.h | 1 -
java-does-usb/jextract/windows_usbioctl.h | 2 -
java-does-usb/jextract/windows_winusb.h | 2 -
.../SP_DEVICE_INTERFACE_DETAIL_DATA_W.java | 48 ++++++++
.../net/codecrete/usb/windows/SetupApi.java | 106 ------------------
.../windows/{USBIOCtl.java => USBHelper.java} | 16 ++-
.../java/net/codecrete/usb/windows/Win.java | 41 +++++++
.../usb/windows/WindowsUSBDeviceRegistry.java | 43 +++----
.../usb/windows/gen/kernel32/_GUID.java | 77 +++++++++++++
.../usb/windows/gen/usbioctl/USBIoctl.java | 6 +
20 files changed, 220 insertions(+), 148 deletions(-)
delete mode 100644 java-does-usb/jextract/windows_cfgmgr32.h
create mode 100644 java-does-usb/jextract/windows_headers.h
delete mode 100644 java-does-usb/jextract/windows_kernel32.h
delete mode 100644 java-does-usb/jextract/windows_setupapi.h
delete mode 100644 java-does-usb/jextract/windows_stdlib.h
delete mode 100644 java-does-usb/jextract/windows_usbioctl.h
delete mode 100644 java-does-usb/jextract/windows_winusb.h
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/SP_DEVICE_INTERFACE_DETAIL_DATA_W.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/SetupApi.java
rename java-does-usb/src/main/java/net/codecrete/usb/windows/{USBIOCtl.java => USBHelper.java} (90%)
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/_GUID.java
diff --git a/java-does-usb/jextract/gen_win_cfgmgr32.cmd b/java-does-usb/jextract/gen_win_cfgmgr32.cmd
index e4bd1db9..320f0d0b 100644
--- a/java-does-usb/jextract/gen_win_cfgmgr32.cmd
+++ b/java-does-usb/jextract/gen_win_cfgmgr32.cmd
@@ -9,4 +9,4 @@ set SDK_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0
--target-package net.codecrete.usb.windows.gen.cfgmgr32 ^
--include-function CM_Get_Parent ^
--include-function CM_Get_Device_IDW ^
- windows_cfgmgr32.h
+ windows_headers.h
diff --git a/java-does-usb/jextract/gen_win_kernel32.cmd b/java-does-usb/jextract/gen_win_kernel32.cmd
index 90af5039..173e672f 100644
--- a/java-does-usb/jextract/gen_win_kernel32.cmd
+++ b/java-does-usb/jextract/gen_win_kernel32.cmd
@@ -19,4 +19,5 @@ set SDK_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0
--include-macro FILE_ATTRIBUTE_NORMAL ^
--include-macro FILE_FLAG_OVERLAPPED ^
--include-macro OPEN_EXISTING ^
- windows_kernel32.h
+ --include-struct _GUID ^
+ windows_headers.h
diff --git a/java-does-usb/jextract/gen_win_setupapi.cmd b/java-does-usb/jextract/gen_win_setupapi.cmd
index baf7983a..baf0813b 100644
--- a/java-does-usb/jextract/gen_win_setupapi.cmd
+++ b/java-does-usb/jextract/gen_win_setupapi.cmd
@@ -19,4 +19,4 @@ set SDK_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0
--include-macro DIGCF_PRESENT ^
--include-macro DIGCF_DEVICEINTERFACE ^
--include-macro SPDRP_ADDRESS ^
- windows_setupapi.h
+ windows_headers.h
diff --git a/java-does-usb/jextract/gen_win_stdlib.cmd b/java-does-usb/jextract/gen_win_stdlib.cmd
index cd387688..8a80e5e0 100644
--- a/java-does-usb/jextract/gen_win_stdlib.cmd
+++ b/java-does-usb/jextract/gen_win_stdlib.cmd
@@ -4,4 +4,4 @@ set JEXTRACT=..\..\..\jextract\build\jextract\bin\jextract.bat
--header-class-name StdLib ^
--target-package net.codecrete.usb.windows.gen.stdlib ^
--include-function wcslen ^
- windows_stdlib.h
+ windows_headers.h
diff --git a/java-does-usb/jextract/gen_win_usbioctl.cmd b/java-does-usb/jextract/gen_win_usbioctl.cmd
index b31b59b2..76cb7589 100644
--- a/java-does-usb/jextract/gen_win_usbioctl.cmd
+++ b/java-does-usb/jextract/gen_win_usbioctl.cmd
@@ -7,7 +7,9 @@ set SDK_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0
--header-class-name USBIoctl ^
--target-package net.codecrete.usb.windows.gen.usbioctl ^
--include-struct _USB_NODE_CONNECTION_INFORMATION_EX ^
- windows_usbioctl.h
+ --include-macro IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX ^
+ --include-macro IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION ^
+ windows_headers.h
:: Generated code is invalid: No instance of type _USB_NODE_CONNECTION_INFORMATION_EX can be created.0
:: They crash with:
diff --git a/java-does-usb/jextract/gen_win_winusb.cmd b/java-does-usb/jextract/gen_win_winusb.cmd
index bb52c94d..a8975263 100644
--- a/java-does-usb/jextract/gen_win_winusb.cmd
+++ b/java-does-usb/jextract/gen_win_winusb.cmd
@@ -13,4 +13,4 @@ set SDK_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0
--include-function WinUsb_ControlTransfer ^
--include-function WinUsb_WritePipe ^
--include-function WinUsb_ReadPipe ^
- windows_winusb.h
+ windows_headers.h
diff --git a/java-does-usb/jextract/windows_cfgmgr32.h b/java-does-usb/jextract/windows_cfgmgr32.h
deleted file mode 100644
index 102a2987..00000000
--- a/java-does-usb/jextract/windows_cfgmgr32.h
+++ /dev/null
@@ -1,2 +0,0 @@
-#include
-#include
diff --git a/java-does-usb/jextract/windows_headers.h b/java-does-usb/jextract/windows_headers.h
new file mode 100644
index 00000000..aa8d0648
--- /dev/null
+++ b/java-does-usb/jextract/windows_headers.h
@@ -0,0 +1,6 @@
+#include
+#include
+#include
+#include
+#include
+#include
diff --git a/java-does-usb/jextract/windows_kernel32.h b/java-does-usb/jextract/windows_kernel32.h
deleted file mode 100644
index 198556f6..00000000
--- a/java-does-usb/jextract/windows_kernel32.h
+++ /dev/null
@@ -1 +0,0 @@
-#include
diff --git a/java-does-usb/jextract/windows_setupapi.h b/java-does-usb/jextract/windows_setupapi.h
deleted file mode 100644
index 7597c78f..00000000
--- a/java-does-usb/jextract/windows_setupapi.h
+++ /dev/null
@@ -1,2 +0,0 @@
-#include
-#include
diff --git a/java-does-usb/jextract/windows_stdlib.h b/java-does-usb/jextract/windows_stdlib.h
deleted file mode 100644
index 3b2f5900..00000000
--- a/java-does-usb/jextract/windows_stdlib.h
+++ /dev/null
@@ -1 +0,0 @@
-#include
diff --git a/java-does-usb/jextract/windows_usbioctl.h b/java-does-usb/jextract/windows_usbioctl.h
deleted file mode 100644
index 2a284d46..00000000
--- a/java-does-usb/jextract/windows_usbioctl.h
+++ /dev/null
@@ -1,2 +0,0 @@
-#include
-#include
diff --git a/java-does-usb/jextract/windows_winusb.h b/java-does-usb/jextract/windows_winusb.h
deleted file mode 100644
index 2fd0d78b..00000000
--- a/java-does-usb/jextract/windows_winusb.h
+++ /dev/null
@@ -1,2 +0,0 @@
-#include
-#include
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/SP_DEVICE_INTERFACE_DETAIL_DATA_W.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/SP_DEVICE_INTERFACE_DETAIL_DATA_W.java
new file mode 100644
index 00000000..f59344c3
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/SP_DEVICE_INTERFACE_DETAIL_DATA_W.java
@@ -0,0 +1,48 @@
+//
+// Java Does USB
+// Copyright (c) 2022 Manuel Bleichenbacher
+// Licensed under MIT License
+// https://opensource.org/licenses/MIT
+//
+
+package net.codecrete.usb.windows;
+
+import java.lang.foreign.GroupLayout;
+import java.lang.foreign.MemoryLayout;
+import java.lang.foreign.MemorySegment;
+import java.lang.invoke.VarHandle;
+
+import static java.lang.foreign.MemoryLayout.PathElement.groupElement;
+import static java.lang.foreign.ValueLayout.JAVA_CHAR;
+import static java.lang.foreign.ValueLayout.JAVA_INT;
+
+/**
+ * SP_DEVICE_INTERFACE_DETAIL_DATA_W struct with a path length of 260 characters.
+ */
+public class SP_DEVICE_INTERFACE_DETAIL_DATA_W {
+
+ // typedef struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W {
+ // DWORD cbSize;
+ // WCHAR DevicePath[ANYSIZE_ARRAY];
+ //} SP_DEVICE_INTERFACE_DETAIL_DATA_W, *PSP_DEVICE_INTERFACE_DETAIL_DATA_W;
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ JAVA_INT.withName("cbSize"),
+ MemoryLayout.sequenceLayout(260, JAVA_CHAR).withName("DevicePath")
+ );
+
+ public static GroupLayout $LAYOUT() {
+ return $struct$LAYOUT;
+ }
+
+ static final VarHandle cbSize$VH = $struct$LAYOUT.varHandle(groupElement("cbSize"));
+
+ public static int cbSize$get(MemorySegment seg) {
+ return (int) cbSize$VH.get(seg);
+ }
+
+ public static void cbSize$set(MemorySegment seg, int x) {
+ cbSize$VH.set(seg, x);
+ }
+
+ public static final long DevicePath$Offset = $struct$LAYOUT.byteOffset(groupElement("DevicePath"));
+}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/SetupApi.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/SetupApi.java
deleted file mode 100644
index 1424553b..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/SetupApi.java
+++ /dev/null
@@ -1,106 +0,0 @@
-//
-// Java Does USB
-// Copyright (c) 2022 Manuel Bleichenbacher
-// Licensed under MIT License
-// https://opensource.org/licenses/MIT
-//
-
-package net.codecrete.usb.windows;
-
-import java.lang.foreign.*;
-import java.lang.invoke.VarHandle;
-
-import static java.lang.foreign.MemoryLayout.PathElement.groupElement;
-import static java.lang.foreign.ValueLayout.*;
-
-/**
- * Windows Setup API functions, constants and structures.
- */
-public class SetupApi {
-
- private static final GroupLayout GUID$Struct;
- private static final VarHandle GUID_Data1;
- private static final VarHandle GUID_Data2;
- private static final VarHandle GUID_Data3;
- private static final long GUID_Data4$Offset;
-
- public static final GroupLayout SP_DEVICE_INTERFACE_DETAIL_DATA_W$Struct;
- public static final VarHandle SP_DEVICE_INTERFACE_DETAIL_DATA_W_cbSize;
- public static final long SP_DEVICE_INTERFACE_DETAIL_DATA_W_DevicePath$Offset;
-
- public static final MemorySegment GUID_DEVINTERFACE_USB_DEVICE;
-
- static {
- var session = MemorySession.openShared();
- Linker linker = Linker.nativeLinker();
- SymbolLookup lookup = SymbolLookup.libraryLookup("SetupAPI", session);
-
- // typedef struct _GUID {
- // unsigned long Data1;
- // unsigned short Data2;
- // unsigned short Data3;
- // unsigned char Data4[ 8 ];
- //} GUID;
- GUID$Struct = MemoryLayout.structLayout(
- JAVA_INT.withName("Data1"),
- JAVA_SHORT.withName("Data2"),
- JAVA_SHORT.withName("Data3"),
- MemoryLayout.sequenceLayout(8, JAVA_BYTE).withName("Data4")
- );
- GUID_Data1 = GUID$Struct.varHandle(groupElement("Data1"));
- GUID_Data2 = GUID$Struct.varHandle(groupElement("Data2"));
- GUID_Data3 = GUID$Struct.varHandle(groupElement("Data3"));
- GUID_Data4$Offset = GUID$Struct.byteOffset(groupElement("Data4"));
-
- // typedef struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W {
- // DWORD cbSize;
- // WCHAR DevicePath[ANYSIZE_ARRAY];
- //} SP_DEVICE_INTERFACE_DETAIL_DATA_W, *PSP_DEVICE_INTERFACE_DETAIL_DATA_W;
- SP_DEVICE_INTERFACE_DETAIL_DATA_W$Struct = MemoryLayout.structLayout(
- JAVA_INT.withName("cbSize"),
- MemoryLayout.sequenceLayout(260, JAVA_CHAR).withName("DevicePath")
- );
- SP_DEVICE_INTERFACE_DETAIL_DATA_W_cbSize = SP_DEVICE_INTERFACE_DETAIL_DATA_W$Struct.varHandle(groupElement("cbSize"));
- SP_DEVICE_INTERFACE_DETAIL_DATA_W_DevicePath$Offset = SP_DEVICE_INTERFACE_DETAIL_DATA_W$Struct.byteOffset(groupElement("DevicePath"));
-
- // A5DCBF10-6530-11D2-901F-00C04FB951ED
- GUID_DEVINTERFACE_USB_DEVICE = CreateGUID(0xA5DCBF10, (short) 0x6530, (short) 0x11D2,
- (byte) 0x90, (byte) 0x1F, (byte) 0x00, (byte) 0xC0,
- (byte) 0x4F, (byte) 0xB9, (byte) 0x51, (byte) 0xED);
- }
-
-
- /**
- * Creates a GUID in native memory.
- *
- * @param data1 Group 1 (4 bytes).
- * @param data2 Group 2 (2 bytes).
- * @param data3 Group 3 (2 bytes).
- * @param data4_0 Byte 0 of group 4
- * @param data4_1 Byte 1 of group 4
- * @param data4_2 Byte 2 of group 4
- * @param data4_3 Byte 3 of group 4
- * @param data4_4 Byte 4 of group 4
- * @param data4_5 Byte 5 of group 4
- * @param data4_6 Byte 6 of group 4
- * @param data4_7 Byte 7 of group 4
- * @return GUID as memory segment
- */
- public static MemorySegment CreateGUID(int data1, short data2, short data3,
- byte data4_0, byte data4_1, byte data4_2, byte data4_3,
- byte data4_4, byte data4_5, byte data4_6, byte data4_7) {
- var guid = MemorySegment.allocateNative(GUID$Struct, MemorySession.global());
- GUID_Data1.set(guid, data1);
- GUID_Data2.set(guid, data2);
- GUID_Data3.set(guid, data3);
- guid.set(JAVA_BYTE, GUID_Data4$Offset, data4_0);
- guid.set(JAVA_BYTE, GUID_Data4$Offset + 1, data4_1);
- guid.set(JAVA_BYTE, GUID_Data4$Offset + 2, data4_2);
- guid.set(JAVA_BYTE, GUID_Data4$Offset + 3, data4_3);
- guid.set(JAVA_BYTE, GUID_Data4$Offset + 4, data4_4);
- guid.set(JAVA_BYTE, GUID_Data4$Offset + 5, data4_5);
- guid.set(JAVA_BYTE, GUID_Data4$Offset + 6, data4_6);
- guid.set(JAVA_BYTE, GUID_Data4$Offset + 7, data4_7);
- return guid;
- }
-}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/USBIOCtl.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/USBHelper.java
similarity index 90%
rename from java-does-usb/src/main/java/net/codecrete/usb/windows/USBIOCtl.java
rename to java-does-usb/src/main/java/net/codecrete/usb/windows/USBHelper.java
index 7e1b061f..095f47e2 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/USBIOCtl.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/USBHelper.java
@@ -11,6 +11,7 @@
import net.codecrete.usb.common.USBStructs;
import java.lang.foreign.GroupLayout;
+import java.lang.foreign.MemorySegment;
import java.lang.invoke.VarHandle;
import static java.lang.foreign.MemoryLayout.PathElement.groupElement;
@@ -18,12 +19,13 @@
import static java.lang.foreign.ValueLayout.*;
/**
- * USB IO Control functions and structures
+ * USB constants and struct
+ *
+ * Mainly used to work around an alignment problem with the generated
+ * USB_NODE_CONNECTION_INFORMATION_EX struct.
+ *
*/
-public class USBIOCtl {
-
- public static final int IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX = 2229320;
- public static final int IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION = 2229264;
+public class USBHelper {
public static final byte USB_REQUEST_GET_DESCRIPTOR = 0x06;
@@ -43,6 +45,10 @@ public class USBIOCtl {
public static final VarHandle USB_STRING_DESCRIPTOR_bLength;
public static final VarHandle USB_STRING_DESCRIPTOR_bDescriptorType;
public static final long USB_STRING_DESCRIPTOR_bString$Offset;
+ // A5DCBF10-6530-11D2-901F-00C04FB951ED
+ public static final MemorySegment GUID_DEVINTERFACE_USB_DEVICE = Win.CreateGUID(0xA5DCBF10, (short) 0x6530, (short) 0x11D2,
+ (byte) 0x90, (byte) 0x1F, (byte) 0x00, (byte) 0xC0,
+ (byte) 0x4F, (byte) 0xB9, (byte) 0x51, (byte) 0xED);
static {
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/Win.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/Win.java
index b7df23db..22ecb309 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/Win.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/Win.java
@@ -7,7 +7,13 @@
package net.codecrete.usb.windows;
+import net.codecrete.usb.windows.gen.kernel32._GUID;
+
import java.lang.foreign.MemoryAddress;
+import java.lang.foreign.MemorySegment;
+import java.lang.foreign.MemorySession;
+
+import static java.lang.foreign.ValueLayout.JAVA_BYTE;
/**
* Windows helpers.
@@ -23,4 +29,39 @@ public class Win {
public static boolean IsInvalidHandle(MemoryAddress handle) {
return handle.toRawLongValue() == -1L;
}
+
+ /**
+ * Creates a GUID in native memory.
+ *
+ * @param data1 Group 1 (4 bytes).
+ * @param data2 Group 2 (2 bytes).
+ * @param data3 Group 3 (2 bytes).
+ * @param data4_0 Byte 0 of group 4
+ * @param data4_1 Byte 1 of group 4
+ * @param data4_2 Byte 2 of group 4
+ * @param data4_3 Byte 3 of group 4
+ * @param data4_4 Byte 4 of group 4
+ * @param data4_5 Byte 5 of group 4
+ * @param data4_6 Byte 6 of group 4
+ * @param data4_7 Byte 7 of group 4
+ * @return GUID as memory segment
+ */
+ public static MemorySegment CreateGUID(int data1, short data2, short data3,
+ byte data4_0, byte data4_1, byte data4_2, byte data4_3,
+ byte data4_4, byte data4_5, byte data4_6, byte data4_7) {
+ var guid = MemorySegment.allocateNative(_GUID.$LAYOUT(), MemorySession.global());
+ _GUID.Data1$set(guid, data1);
+ _GUID.Data2$set(guid, data2);
+ _GUID.Data3$set(guid, data3);
+ var data4 = _GUID.Data4$slice(guid);
+ data4.set(JAVA_BYTE, 0, data4_0);
+ data4.set(JAVA_BYTE, 1, data4_1);
+ data4.set(JAVA_BYTE, 2, data4_2);
+ data4.set(JAVA_BYTE, 3, data4_3);
+ data4.set(JAVA_BYTE, 4, data4_4);
+ data4.set(JAVA_BYTE, 5, data4_5);
+ data4.set(JAVA_BYTE, 6, data4_6);
+ data4.set(JAVA_BYTE, 7, data4_7);
+ return guid;
+ }
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
index 9c48636d..508d5de4 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
@@ -17,6 +17,7 @@
import net.codecrete.usb.windows.gen.setupapi.SetupAPI;
import net.codecrete.usb.windows.gen.setupapi._SP_DEVINFO_DATA;
import net.codecrete.usb.windows.gen.stdlib.StdLib;
+import net.codecrete.usb.windows.gen.usbioctl.USBIoctl;
import java.lang.foreign.Addressable;
import java.lang.foreign.MemoryAddress;
@@ -37,7 +38,7 @@ public List getAllDevices() {
try (var outerSession = MemorySession.openConfined()) {
// get as set of all USB devices present
- final var devInfoSetHandle = SetupAPI.SetupDiGetClassDevsW(SetupApi.GUID_DEVINTERFACE_USB_DEVICE, NULL, NULL, SetupAPI.DIGCF_PRESENT() | SetupAPI.DIGCF_DEVICEINTERFACE());
+ final var devInfoSetHandle = SetupAPI.SetupDiGetClassDevsW(USBHelper.GUID_DEVINTERFACE_USB_DEVICE, NULL, NULL, SetupAPI.DIGCF_PRESENT() | SetupAPI.DIGCF_DEVICEINTERFACE());
if (Win.IsInvalidHandle(devInfoSetHandle))
throw new USBException("internal error (SetupDiGetClassDevsW)");
@@ -96,7 +97,7 @@ public List getAllDevices() {
// get the interface data
if (SetupAPI.SetupDiEnumDeviceInterfaces(devInfoSetHandle, devInfo,
- SetupApi.GUID_DEVINTERFACE_USB_DEVICE, 0, devInfoData) == 0) {
+ USBHelper.GUID_DEVINTERFACE_USB_DEVICE, 0, devInfoData) == 0) {
int lastError = Kernel32.GetLastError();
if (lastError == Kernel32.ERROR_NO_MORE_ITEMS())
throw new USBException("Internal error (SetupDiEnumDeviceInterfaces)");
@@ -104,15 +105,15 @@ public List getAllDevices() {
}
// get path of first interface
- var intfDetailData = MemorySegment.allocateNative(SetupApi.SP_DEVICE_INTERFACE_DETAIL_DATA_W$Struct, session);
- SetupApi.SP_DEVICE_INTERFACE_DETAIL_DATA_W_cbSize.set(intfDetailData, 8);
- int intfDatailDataSize = (int) SetupApi.SP_DEVICE_INTERFACE_DETAIL_DATA_W$Struct.byteSize();
+ var intfDetailData = MemorySegment.allocateNative(SP_DEVICE_INTERFACE_DETAIL_DATA_W.$LAYOUT(), session);
+ SP_DEVICE_INTERFACE_DETAIL_DATA_W.cbSize$set(intfDetailData, 8);
+ int intfDatailDataSize = (int) SP_DEVICE_INTERFACE_DETAIL_DATA_W.$LAYOUT().byteSize();
if (SetupAPI.SetupDiGetDeviceInterfaceDetailW(devInfoSetHandle, devInfoData,
intfDetailData, intfDatailDataSize, NULL, NULL) == 0)
throw new USBException("Internal error (SetupDiGetDeviceInterfaceDetailA - 2)", Kernel32.GetLastError());
- long pathLen = StdLib.wcslen(intfDetailData.address().addOffset(SetupApi.SP_DEVICE_INTERFACE_DETAIL_DATA_W_DevicePath$Offset));
- char[] devicePathChars = intfDetailData.asSlice(SetupApi.SP_DEVICE_INTERFACE_DETAIL_DATA_W_DevicePath$Offset, pathLen * 2).toArray(JAVA_CHAR);
+ long pathLen = StdLib.wcslen(intfDetailData.address().addOffset(SP_DEVICE_INTERFACE_DETAIL_DATA_W.DevicePath$Offset));
+ char[] devicePathChars = intfDetailData.asSlice(SP_DEVICE_INTERFACE_DETAIL_DATA_W.DevicePath$Offset, pathLen * 2).toArray(JAVA_CHAR);
String devicePath = new String(devicePathChars);
// get device's hub port number
@@ -137,20 +138,20 @@ private USBDeviceInfo createDeviceInfo(String devicePath, MemoryAddress hubHandl
try (var session = MemorySession.openConfined()) {
// get device descriptor
- var connInfo = session.allocate(USBIOCtl.USB_NODE_CONNECTION_INFORMATION_EX$Struct);
- USBIOCtl.USB_NODE_CONNECTION_INFORMATION_EX_ConnectionIndex.set(connInfo, usbPortNum);
+ var connInfo = session.allocate(USBHelper.USB_NODE_CONNECTION_INFORMATION_EX$Struct);
+ USBHelper.USB_NODE_CONNECTION_INFORMATION_EX_ConnectionIndex.set(connInfo, usbPortNum);
var sizeHolder = session.allocate(JAVA_INT);
- if (Kernel32.DeviceIoControl(hubHandle, USBIOCtl.IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX,
+ if (Kernel32.DeviceIoControl(hubHandle, USBIoctl.IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX(),
connInfo, (int) connInfo.byteSize(),
connInfo, (int) connInfo.byteSize(),
sizeHolder, NULL) == 0)
throw new USBException("Internal error (cannot get device descriptor)", Kernel32.GetLastError());
byte currentConfigurationValue =
- (byte) USBIOCtl.USB_NODE_CONNECTION_INFORMATION_EX_CurrentConfigurationValue.get(connInfo);
+ (byte) USBHelper.USB_NODE_CONNECTION_INFORMATION_EX_CurrentConfigurationValue.get(connInfo);
var deviceDesc = connInfo.asSlice(
- USBIOCtl.USB_NODE_CONNECTION_INFORMATION_EX_DeviceDescriptor$Offset,
+ USBHelper.USB_NODE_CONNECTION_INFORMATION_EX_DeviceDescriptor$Offset,
USBDescriptors.Device$Struct.byteSize());
// extract info from device descriptor
@@ -181,27 +182,27 @@ private String getStringDescriptor(Addressable hubHandle, int usbPortNumber, int
try (var session = MemorySession.openConfined()) {
final int dataLen = 32;
- var descriptorRequest = session.allocate(USBIOCtl.USB_DESCRIPTOR_REQUEST_Data$Offset + dataLen);
- USBIOCtl.USB_DESCRIPTOR_REQUEST_ConnectionIndex.set(descriptorRequest, usbPortNumber);
+ var descriptorRequest = session.allocate(USBHelper.USB_DESCRIPTOR_REQUEST_Data$Offset + dataLen);
+ USBHelper.USB_DESCRIPTOR_REQUEST_ConnectionIndex.set(descriptorRequest, usbPortNumber);
var setupPacket = descriptorRequest.asSlice(
- USBIOCtl.USB_DESCRIPTOR_REQUEST_SetupPacket$Offset,
+ USBHelper.USB_DESCRIPTOR_REQUEST_SetupPacket$Offset,
USBStructs.SetupPacket$Struct.byteSize());
USBStructs.SetupPacket_bmRequest.set(setupPacket, (byte) 0x80);
- USBStructs.SetupPacket_bRequest.set(setupPacket, USBIOCtl.USB_REQUEST_GET_DESCRIPTOR);
- USBStructs.SetupPacket_wValue.set(setupPacket, (short) ((USBIOCtl.USB_STRING_DESCRIPTOR_TYPE << 8) | index));
+ USBStructs.SetupPacket_bRequest.set(setupPacket, USBHelper.USB_REQUEST_GET_DESCRIPTOR);
+ USBStructs.SetupPacket_wValue.set(setupPacket, (short) ((USBHelper.USB_STRING_DESCRIPTOR_TYPE << 8) | index));
USBStructs.SetupPacket_wIndex.set(setupPacket, (short) 0x0409);
USBStructs.SetupPacket_wLength.set(setupPacket, (short) dataLen);
var sizeHolder = session.allocate(JAVA_INT);
- if (Kernel32.DeviceIoControl(hubHandle, USBIOCtl.IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION,
+ if (Kernel32.DeviceIoControl(hubHandle, USBIoctl.IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION(),
descriptorRequest, (int) descriptorRequest.byteSize(),
descriptorRequest, (int) descriptorRequest.byteSize(),
sizeHolder, NULL) == 0)
throw new USBException(String.format("Cannot retrieve string descriptor %d", index), Kernel32.GetLastError());
- var stringDesc = descriptorRequest.asSlice(USBIOCtl.USB_DESCRIPTOR_REQUEST_Data$Offset, dataLen);
- int stringLen = 255 & (byte) USBIOCtl.USB_STRING_DESCRIPTOR_bLength.get(stringDesc);
- var chars = stringDesc.asSlice(USBIOCtl.USB_STRING_DESCRIPTOR_bString$Offset, stringLen - 2)
+ var stringDesc = descriptorRequest.asSlice(USBHelper.USB_DESCRIPTOR_REQUEST_Data$Offset, dataLen);
+ int stringLen = 255 & (byte) USBHelper.USB_STRING_DESCRIPTOR_bLength.get(stringDesc);
+ var chars = stringDesc.asSlice(USBHelper.USB_STRING_DESCRIPTOR_bString$Offset, stringLen - 2)
.toArray(JAVA_CHAR);
return new String(chars);
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/_GUID.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/_GUID.java
new file mode 100644
index 00000000..98826c26
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/_GUID.java
@@ -0,0 +1,77 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.kernel32;
+
+import java.lang.foreign.*;
+import java.lang.invoke.VarHandle;
+public class _GUID {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ Constants$root.C_LONG$LAYOUT.withName("Data1"),
+ Constants$root.C_SHORT$LAYOUT.withName("Data2"),
+ Constants$root.C_SHORT$LAYOUT.withName("Data3"),
+ MemoryLayout.sequenceLayout(8, Constants$root.C_CHAR$LAYOUT).withName("Data4")
+ ).withName("_GUID");
+ public static MemoryLayout $LAYOUT() {
+ return _GUID.$struct$LAYOUT;
+ }
+ static final VarHandle Data1$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("Data1"));
+ public static VarHandle Data1$VH() {
+ return _GUID.Data1$VH;
+ }
+ public static int Data1$get(MemorySegment seg) {
+ return (int)_GUID.Data1$VH.get(seg);
+ }
+ public static void Data1$set( MemorySegment seg, int x) {
+ _GUID.Data1$VH.set(seg, x);
+ }
+ public static int Data1$get(MemorySegment seg, long index) {
+ return (int)_GUID.Data1$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void Data1$set(MemorySegment seg, long index, int x) {
+ _GUID.Data1$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle Data2$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("Data2"));
+ public static VarHandle Data2$VH() {
+ return _GUID.Data2$VH;
+ }
+ public static short Data2$get(MemorySegment seg) {
+ return (short)_GUID.Data2$VH.get(seg);
+ }
+ public static void Data2$set( MemorySegment seg, short x) {
+ _GUID.Data2$VH.set(seg, x);
+ }
+ public static short Data2$get(MemorySegment seg, long index) {
+ return (short)_GUID.Data2$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void Data2$set(MemorySegment seg, long index, short x) {
+ _GUID.Data2$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle Data3$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("Data3"));
+ public static VarHandle Data3$VH() {
+ return _GUID.Data3$VH;
+ }
+ public static short Data3$get(MemorySegment seg) {
+ return (short)_GUID.Data3$VH.get(seg);
+ }
+ public static void Data3$set( MemorySegment seg, short x) {
+ _GUID.Data3$VH.set(seg, x);
+ }
+ public static short Data3$get(MemorySegment seg, long index) {
+ return (short)_GUID.Data3$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void Data3$set(MemorySegment seg, long index, short x) {
+ _GUID.Data3$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static MemorySegment Data4$slice(MemorySegment seg) {
+ return seg.asSlice(8, 8);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/USBIoctl.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/USBIoctl.java
index d6a326fe..bbb4e966 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/USBIoctl.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/USBIoctl.java
@@ -14,6 +14,12 @@ public class USBIoctl {
public static OfFloat C_FLOAT = Constants$root.C_FLOAT$LAYOUT;
public static OfDouble C_DOUBLE = Constants$root.C_DOUBLE$LAYOUT;
public static OfAddress C_POINTER = Constants$root.C_POINTER$LAYOUT;
+ public static int IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION() {
+ return (int)2229264L;
+ }
+ public static int IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX() {
+ return (int)2229320L;
+ }
}
From 744384938e61276bef5352fd4f952fdefb1af59b Mon Sep 17 00:00:00 2001
From: Manuel Bleichenbacher
Date: Fri, 26 Aug 2022 17:54:08 +0200
Subject: [PATCH 010/433] macOS: monitor connect/disconnect
---
java-does-usb/jextract/gen_macos.sh | 18 +-
.../src/main/java/net/codecrete/usb/USB.java | 19 +
.../java/net/codecrete/usb/USBDeviceInfo.java | 4 +
.../codecrete/usb/common/USBDeviceImpl.java | 20 +-
.../usb/common/USBDeviceInfoImpl.java | 20 +-
.../usb/common/USBDeviceRegistry.java | 5 +
.../codecrete/usb/linux/LinuxUSBDevice.java | 6 +-
.../usb/linux/LinuxUSBDeviceInfo.java | 6 +-
.../usb/linux/LinuxUSBDeviceRegistry.java | 9 +
.../codecrete/usb/macos/CoreFoundation.java | 291 ++++++------
.../java/net/codecrete/usb/macos/IoKit.java | 441 ++++++++++--------
.../net/codecrete/usb/macos/IoKitHelper.java | 118 +++++
.../codecrete/usb/macos/MacosUSBDevice.java | 55 ++-
.../usb/macos/MacosUSBDeviceInfo.java | 6 +-
.../usb/macos/MacosUSBDeviceRegistry.java | 236 +++++++---
.../usb/macos/MacosUSBException.java | 29 ++
.../macos/gen/{ => mach}/Constants$root.java | 2 +-
.../macos/gen/{ => mach}/RuntimeHelper.java | 2 +-
.../usb/macos/gen/{ => mach}/constants$0.java | 9 +-
.../usb/macos/gen/{ => mach}/mach.java | 14 +-
.../usb/windows/WindowsUSBDevice.java | 10 +-
.../usb/windows/WindowsUSBDeviceInfo.java | 6 +-
.../usb/windows/WindowsUSBDeviceRegistry.java | 9 +
.../codecrete/usb/sample/MonitorDevices.java | 22 +
24 files changed, 887 insertions(+), 470 deletions(-)
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/macos/IoKitHelper.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBException.java
rename java-does-usb/src/main/java/net/codecrete/usb/macos/gen/{ => mach}/Constants$root.java (94%)
rename java-does-usb/src/main/java/net/codecrete/usb/macos/gen/{ => mach}/RuntimeHelper.java (99%)
rename java-does-usb/src/main/java/net/codecrete/usb/macos/gen/{ => mach}/constants$0.java (54%)
rename java-does-usb/src/main/java/net/codecrete/usb/macos/gen/{ => mach}/mach.java (67%)
create mode 100644 java-does-usb/src/test/java/net/codecrete/usb/sample/MonitorDevices.java
diff --git a/java-does-usb/jextract/gen_macos.sh b/java-does-usb/jextract/gen_macos.sh
index 2aabdfc6..31907319 100755
--- a/java-does-usb/jextract/gen_macos.sh
+++ b/java-does-usb/jextract/gen_macos.sh
@@ -1,16 +1,20 @@
#!/bin/sh
JEXTRACT=../../../jextract/build/jextract/bin/jextract
+SDK_DIR=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
# CoreFoundation
-#$JEXTRACT --source --target-package net.codecrete.usb.macos.gen --output ../src/main/java \
-# -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include \
+#$JEXTRACT --source --output ../src/main/java \
+# -I $SDK_DIR/usr/include \
+# --target-package net.codecrete.usb.macos.gen.corefoundation
# --include-function CFUUIDCreateFromUUIDBytes \
-# /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Versions/A/Headers/CoreFoundation.h
+# $SDK_DIR/System/Library/Frameworks/CoreFoundation.framework/Versions/A/Headers/CoreFoundation.h
-## mach_error
-$JEXTRACT --source --target-package net.codecrete.usb.macos.gen --output ../src/main/java \
- -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include \
+# mach.h
+$JEXTRACT --source --output ../src/main/java \
+ -I $SDK_DIR/usr/include \
--header-class-name mach \
+ --target-package net.codecrete.usb.macos.gen.mach \
--include-function mach_error \
- /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/mach/mach.h
+ --include-function mach_error_string \
+ $SDK_DIR/usr/include/mach/mach.h
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/USB.java b/java-does-usb/src/main/java/net/codecrete/usb/USB.java
index c5f22ccc..5f9b7d35 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/USB.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/USB.java
@@ -13,6 +13,7 @@
import net.codecrete.usb.windows.WindowsUSBDeviceRegistry;
import java.util.List;
+import java.util.function.Consumer;
import java.util.stream.Collectors;
/**
@@ -104,4 +105,22 @@ public static USBDeviceInfo getDevice(List filters) {
return instance().getAllDevices().stream().filter(dev -> USBDeviceFilter.matchesAny(dev, filters))
.findFirst().orElse(null);
}
+
+ /**
+ * Sets the handler to be called when a USB device is connected.
+ *
+ * @param handler handler function, or {@code null} to remove a previous handler
+ */
+ public static void setOnDeviceConnected(Consumer handler) {
+ instance().setOnDeviceConnected(handler);
+ }
+
+ /**
+ * Sets the handler to be called when a USB device is disconnected.
+ *
+ * @param handler handler function, or {@code null} to remove a previous handler
+ */
+ public static void setOnDeviceDisconnected(Consumer handler) {
+ instance().setOnDeviceDisconnected(handler);
+ }
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/USBDeviceInfo.java b/java-does-usb/src/main/java/net/codecrete/usb/USBDeviceInfo.java
index 880a32bd..c9eac5b1 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/USBDeviceInfo.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/USBDeviceInfo.java
@@ -18,6 +18,10 @@
* Instances of this class are not associated with any native resources
* and can thus be easily handled in Java.
*
+ *
+ * Multiple instances of the class might exist for the same USB device.
+ * Use {@code equals()} to test if they refer to the same device.
+ *
*/
public interface USBDeviceInfo {
/**
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceImpl.java b/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceImpl.java
index 938c798e..a4a04ca7 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceImpl.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceImpl.java
@@ -9,12 +9,10 @@
import net.codecrete.usb.*;
-import java.util.Objects;
-
public abstract class USBDeviceImpl implements USBDevice {
- protected final String path;
+ protected final Object id;
protected final int productId;
protected final int vendorId;
protected final String product;
@@ -27,14 +25,16 @@ public abstract class USBDeviceImpl implements USBDevice {
/**
* Creates a new instance.
*
- * @param path device path
+ * @param id unique identifier
* @param info USB device information
*/
protected USBDeviceImpl(
- String path,
+ Object id,
USBDeviceInfo info) {
- this.path = path;
+ assert id != null;
+
+ this.id = id;
this.productId = info.getProductId();
this.vendorId = info.getVendorId();
this.product = info.getProduct();
@@ -117,12 +117,12 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
USBDeviceImpl that = (USBDeviceImpl) o;
- return productId == that.productId && vendorId == that.vendorId && classCode == that.classCode && subclassCode == that.subclassCode && protocolCode == that.protocolCode && path.equals(that.path) && Objects.equals(product, that.product) && Objects.equals(manufacturer, that.manufacturer) && Objects.equals(serial, that.serial);
+ return id.equals(that.id);
}
@Override
public int hashCode() {
- return Objects.hash(path, productId, vendorId, product, manufacturer, serial, classCode, subclassCode, protocolCode);
+ return id.hashCode();
}
@Override
@@ -137,7 +137,7 @@ public String toString() {
product +
", serial: " +
serial +
- ", path: " +
- path;
+ ", ID: " +
+ id.toString();
}
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceInfoImpl.java b/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceInfoImpl.java
index 55da0781..0e55dca6 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceInfoImpl.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceInfoImpl.java
@@ -10,12 +10,10 @@
import net.codecrete.usb.USBDevice;
import net.codecrete.usb.USBDeviceInfo;
-import java.util.Objects;
-
public abstract class USBDeviceInfoImpl implements USBDeviceInfo {
- protected final String path;
+ protected final Object id;
protected final int productId;
protected final int vendorId;
protected final String product;
@@ -28,7 +26,7 @@ public abstract class USBDeviceInfoImpl implements USBDeviceInfo {
/**
* Creates a new instance.
*
- * @param path device path
+ * @param id unique device ID
* @param vendorId USB vendor ID
* @param productId USB product ID
* @param manufacturer manufacturer name
@@ -39,11 +37,13 @@ public abstract class USBDeviceInfoImpl implements USBDeviceInfo {
* @param protocolCode USB device protocol
*/
protected USBDeviceInfoImpl(
- String path, int vendorId, int productId,
+ Object id, int vendorId, int productId,
String manufacturer, String product, String serial,
int classCode, int subclassCode, int protocolCode) {
- this.path = path;
+ assert id != null;
+
+ this.id = id;
this.productId = productId;
this.vendorId = vendorId;
this.product = product;
@@ -93,12 +93,12 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
USBDeviceInfoImpl that = (USBDeviceInfoImpl) o;
- return productId == that.productId && vendorId == that.vendorId && classCode == that.classCode && subclassCode == that.subclassCode && protocolCode == that.protocolCode && path.equals(that.path) && Objects.equals(product, that.product) && Objects.equals(manufacturer, that.manufacturer) && Objects.equals(serial, that.serial);
+ return id.equals(that.id);
}
@Override
public int hashCode() {
- return Objects.hash(path, productId, vendorId, product, manufacturer, serial, classCode, subclassCode, protocolCode);
+ return id.hashCode();
}
@Override
@@ -113,7 +113,7 @@ public String toString() {
product +
", serial: " +
serial +
- ", path: " +
- path;
+ ", ID: " +
+ id;
}
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceRegistry.java
index 4e314f7a..685797d0 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceRegistry.java
@@ -10,10 +10,15 @@
import net.codecrete.usb.USBDeviceInfo;
import java.util.List;
+import java.util.function.Consumer;
/**
* USB device registry.
*/
public interface USBDeviceRegistry {
List getAllDevices();
+
+ void setOnDeviceConnected(Consumer handler);
+
+ void setOnDeviceDisconnected(Consumer handler);
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDevice.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDevice.java
index e1b7c622..119bc478 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDevice.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDevice.java
@@ -28,11 +28,11 @@ public class LinuxUSBDevice extends USBDeviceImpl {
private final int fd;
- LinuxUSBDevice(String path, USBDeviceInfo info) {
- super(path, info);
+ LinuxUSBDevice(Object id, USBDeviceInfo info) {
+ super(id, info);
try (var session = MemorySession.openConfined()) {
- var pathUtf8 = session.allocateUtf8String(path);
+ var pathUtf8 = session.allocateUtf8String(id.toString());
fd = fcntl.open(pathUtf8, fcntl.O_RDWR() | fcntl.O_CLOEXEC());
if (fd == -1)
throw new USBException("Cannot open USB device", IO.getErrno());
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceInfo.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceInfo.java
index c7b5a2da..1d8c3d22 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceInfo.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceInfo.java
@@ -13,17 +13,17 @@
public class LinuxUSBDeviceInfo extends USBDeviceInfoImpl {
LinuxUSBDeviceInfo(
- String path, int vendorId, int productId,
+ Object id, int vendorId, int productId,
String manufacturer, String product, String serial,
int classCode, int subclassCode, int protocolCode) {
- super(path, vendorId, productId,
+ super(id, vendorId, productId,
manufacturer, product, serial,
classCode, subclassCode, protocolCode);
}
@Override
public USBDevice open() {
- return new LinuxUSBDevice(path, this);
+ return new LinuxUSBDevice(id, this);
}
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceRegistry.java
index 4a120556..c786705a 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceRegistry.java
@@ -15,6 +15,7 @@
import java.lang.foreign.MemorySession;
import java.util.ArrayList;
import java.util.List;
+import java.util.function.Consumer;
import static java.lang.foreign.MemoryAddress.NULL;
import static java.lang.foreign.ValueLayout.ADDRESS;
@@ -96,4 +97,12 @@ private static String getDeviceName(Addressable device) {
return ret.getUtf8String(0);
}
}
+
+ @Override
+ public void setOnDeviceConnected(Consumer handler) {
+ }
+
+ @Override
+ public void setOnDeviceDisconnected(Consumer handler) {
+ }
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/CoreFoundation.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/CoreFoundation.java
index 4cccd5b4..3f2857ae 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/CoreFoundation.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/CoreFoundation.java
@@ -37,147 +37,129 @@ public class CoreFoundation {
public static final long kCFNumberNSIntegerType = 15;
public static final long kCFNumberCGFloatType = 16;
- public static final GroupLayout CFUUIDBytes;
-
- public static final GroupLayout CFUUID;
- public static final long CFUUID_bytes$Offset;
-
- public static final GroupLayout CFRange;
- public static final VarHandle CFRange_location;
- public static final VarHandle CFRange_range;
-
-
- // private static final MethodHandle CFUUIDGetConstantUUIDWithBytes$Func;
- private static final MethodHandle CFUUIDCreateFromUUIDBytes$Func;
- private static final MethodHandle CFUUIDCreateString$Func;
- private static final MethodHandle CFRelease$Func;
- private static final MethodHandle CFStringGetLength$Func;
- private static final MethodHandle CFStringGetCharacters$Func;
- private static final MethodHandle CFStringCreateWithCharacters$Func;
- private static final MethodHandle CFGetTypeID$Func;
- private static final MethodHandle CFNumberGetTypeID$Func;
- private static final MethodHandle CFStringGetTypeID$Func;
- private static final MethodHandle CFNumberGetType$Func;
- private static final MethodHandle CFNumberGetValue$Func;
-
- static {
- var linker = Linker.nativeLinker();
- var cfSession = MemorySession.openShared();
- var coreFoundationLookup = SymbolLookup.libraryLookup("CoreFoundation.framework/CoreFoundation", cfSession);
-
- CFUUIDBytes = structLayout(
- JAVA_BYTE.withName("byte0"),
- JAVA_BYTE.withName("byte1"),
- JAVA_BYTE.withName("byte2"),
- JAVA_BYTE.withName("byte3"),
- JAVA_BYTE.withName("byte4"),
- JAVA_BYTE.withName("byte5"),
- JAVA_BYTE.withName("byte6"),
- JAVA_BYTE.withName("byte7"),
- JAVA_BYTE.withName("byte8"),
- JAVA_BYTE.withName("byte9"),
- JAVA_BYTE.withName("byte10"),
- JAVA_BYTE.withName("byte11"),
- JAVA_BYTE.withName("byte12"),
- JAVA_BYTE.withName("byte13"),
- JAVA_BYTE.withName("byte14"),
- JAVA_BYTE.withName("byte15")
- );
- CFUUID = structLayout(
- ADDRESS.withName("_cfisa"), // uintptr_t _cfisa;
- sequenceLayout(4, JAVA_BYTE).withName("_cfinfo"), // uint8_t _cfinfo[4];
- JAVA_INT.withName("_rc"), // uint32_t _rc;
- CFUUIDBytes.withName("_bytes") // CFUUIDBytes _bytes;
- );
- CFUUID_bytes$Offset = CFUUID.byteOffset(MemoryLayout.PathElement.groupElement("_bytes"));
- CFRange = structLayout(
- JAVA_LONG.withName("location"),
- JAVA_LONG.withName("range")
- );
- CFRange_location = CFRange.varHandle(MemoryLayout.PathElement.groupElement("location"));
- CFRange_range = CFRange.varHandle(MemoryLayout.PathElement.groupElement("range"));
-
- // CFUUIDRef CFUUIDGetConstantUUIDWithBytes(CFAllocatorRef alloc, uint8_t byte0, uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4, uint8_t byte5, uint8_t byte6, uint8_t byte7, uint8_t byte8, uint8_t byte9, uint8_t byte10, uint8_t byte11, uint8_t byte12, uint8_t byte13, uint8_t byte14, uint8_t byte15)
-// CFUUIDGetConstantUUIDWithBytes$Func = linker.downcallHandle(
-// coreFoundationLookup.lookup("CFUUIDGetConstantUUIDWithBytes").get(),
-// FunctionDescriptor.of(
-// ADDRESS, ADDRESS,
-// JAVA_BYTE, JAVA_BYTE, JAVA_BYTE, JAVA_BYTE,
-// JAVA_BYTE, JAVA_BYTE, JAVA_BYTE, JAVA_BYTE,
-// JAVA_BYTE, JAVA_BYTE, JAVA_BYTE, JAVA_BYTE,
-// JAVA_BYTE, JAVA_BYTE, JAVA_BYTE, JAVA_BYTE)
-// );
-
- // CFUUIDRef CFUUIDCreateFromUUIDBytes(CFAllocatorRef alloc, CFUUIDBytes bytes);
- CFUUIDCreateFromUUIDBytes$Func = linker.downcallHandle(
- coreFoundationLookup.lookup("CFUUIDCreateFromUUIDBytes").get(),
- FunctionDescriptor.of(
- ADDRESS, ADDRESS, CFUUIDBytes
- )
- );
-
- // CFStringRef CFUUIDCreateString(CFAllocatorRef alloc, CFUUIDRef uuid);
- CFUUIDCreateString$Func = linker.downcallHandle(
- coreFoundationLookup.lookup("CFUUIDCreateString").get(),
- FunctionDescriptor.of(
- ADDRESS, ADDRESS, ADDRESS
- )
- );
-
- // void CFRelease(CFTypeRef cf);
- CFRelease$Func = linker.downcallHandle(
- coreFoundationLookup.lookup("CFRelease").get(),
- FunctionDescriptor.ofVoid(ADDRESS)
- );
-
- // CFIndex CFStringGetLength(CFStringRef theString);
- CFStringGetLength$Func = linker.downcallHandle(
- coreFoundationLookup.lookup("CFStringGetLength").get(),
- FunctionDescriptor.of(JAVA_LONG, ADDRESS)
- );
-
- // void CFStringGetCharacters(CFStringRef theString, CFRange range, UniChar *buffer);
- CFStringGetCharacters$Func = linker.downcallHandle(
- coreFoundationLookup.lookup("CFStringGetCharacters").get(),
- FunctionDescriptor.ofVoid(ADDRESS, CFRange, ADDRESS)
- );
-
- // CFStringRef CFStringCreateWithCharacters(CFAllocatorRef alloc, const UniChar *chars, CFIndex numChars);
- CFStringCreateWithCharacters$Func = linker.downcallHandle(
- coreFoundationLookup.lookup("CFStringCreateWithCharacters").get(),
- FunctionDescriptor.of(ADDRESS, ADDRESS, ADDRESS, JAVA_LONG)
- );
-
- // CFTypeID CFGetTypeID(CFTypeRef cf);
- CFGetTypeID$Func = linker.downcallHandle(
- coreFoundationLookup.lookup("CFGetTypeID").get(),
- FunctionDescriptor.of(JAVA_LONG, ADDRESS)
- );
-
- // CFTypeID CFNumberGetTypeID(void);
- CFNumberGetTypeID$Func = linker.downcallHandle(
- coreFoundationLookup.lookup("CFNumberGetTypeID").get(),
- FunctionDescriptor.of(JAVA_LONG)
- );
-
- // CFTypeID CFStringGetTypeID(void);
- CFStringGetTypeID$Func = linker.downcallHandle(
- coreFoundationLookup.lookup("CFStringGetTypeID").get(),
- FunctionDescriptor.of(JAVA_LONG)
- );
-
- // CFNumberType CFNumberGetType(CFNumberRef number);
- CFNumberGetType$Func = linker.downcallHandle(
- coreFoundationLookup.lookup("CFNumberGetType").get(),
- FunctionDescriptor.of(JAVA_LONG, ADDRESS)
- );
-
- // Boolean CFNumberGetValue(CFNumberRef number, CFNumberType theType, void *valuePtr);
- CFNumberGetValue$Func = linker.downcallHandle(
- coreFoundationLookup.lookup("CFNumberGetValue").get(),
- FunctionDescriptor.of(JAVA_BOOLEAN, ADDRESS, JAVA_LONG, ADDRESS)
- );
- }
+ private static final Linker linker = Linker.nativeLinker();
+ private static final MemorySession cfSession = MemorySession.openShared();
+ private static final SymbolLookup coreFoundationLookup = SymbolLookup.libraryLookup("CoreFoundation.framework/CoreFoundation", cfSession);
+
+ public static final GroupLayout CFUUIDBytes = structLayout(
+ JAVA_BYTE.withName("byte0"),
+ JAVA_BYTE.withName("byte1"),
+ JAVA_BYTE.withName("byte2"),
+ JAVA_BYTE.withName("byte3"),
+ JAVA_BYTE.withName("byte4"),
+ JAVA_BYTE.withName("byte5"),
+ JAVA_BYTE.withName("byte6"),
+ JAVA_BYTE.withName("byte7"),
+ JAVA_BYTE.withName("byte8"),
+ JAVA_BYTE.withName("byte9"),
+ JAVA_BYTE.withName("byte10"),
+ JAVA_BYTE.withName("byte11"),
+ JAVA_BYTE.withName("byte12"),
+ JAVA_BYTE.withName("byte13"),
+ JAVA_BYTE.withName("byte14"),
+ JAVA_BYTE.withName("byte15")
+ );
+
+ public static final GroupLayout CFUUID = structLayout(
+ ADDRESS.withName("_cfisa"), // uintptr_t _cfisa;
+ sequenceLayout(4, JAVA_BYTE).withName("_cfinfo"), // uint8_t _cfinfo[4];
+ JAVA_INT.withName("_rc"), // uint32_t _rc;
+ CFUUIDBytes.withName("_bytes") // CFUUIDBytes _bytes;
+ );
+ public static final long CFUUID_bytes$Offset = CFUUID.byteOffset(MemoryLayout.PathElement.groupElement("_bytes"));
+
+ public static final GroupLayout CFRange = structLayout(
+ JAVA_LONG.withName("location"),
+ JAVA_LONG.withName("range")
+ );
+ public static final VarHandle CFRange_location = CFRange.varHandle(MemoryLayout.PathElement.groupElement("location"));
+ public static final VarHandle CFRange_range = CFRange.varHandle(MemoryLayout.PathElement.groupElement("range"));
+
+ // CFUUIDRef CFUUIDCreateFromUUIDBytes(CFAllocatorRef alloc, CFUUIDBytes bytes);
+ private static final MethodHandle CFUUIDCreateFromUUIDBytes$Func = linker.downcallHandle(
+ coreFoundationLookup.lookup("CFUUIDCreateFromUUIDBytes").get(),
+ FunctionDescriptor.of(
+ ADDRESS, ADDRESS, CFUUIDBytes
+ )
+ );
+
+ // CFStringRef CFUUIDCreateString(CFAllocatorRef alloc, CFUUIDRef uuid);
+ private static final MethodHandle CFUUIDCreateString$Func = linker.downcallHandle(
+ coreFoundationLookup.lookup("CFUUIDCreateString").get(),
+ FunctionDescriptor.of(
+ ADDRESS, ADDRESS, ADDRESS
+ )
+ );
+
+ // void CFRelease(CFTypeRef cf);
+ private static final MethodHandle CFRelease$Func = linker.downcallHandle(
+ coreFoundationLookup.lookup("CFRelease").get(),
+ FunctionDescriptor.ofVoid(ADDRESS)
+ );
+
+ // CFIndex CFStringGetLength(CFStringRef theString);
+ private static final MethodHandle CFStringGetLength$Func = linker.downcallHandle(
+ coreFoundationLookup.lookup("CFStringGetLength").get(),
+ FunctionDescriptor.of(JAVA_LONG, ADDRESS)
+ );
+
+ // void CFStringGetCharacters(CFStringRef theString, CFRange range, UniChar *buffer);
+ private static final MethodHandle CFStringGetCharacters$Func = linker.downcallHandle(
+ coreFoundationLookup.lookup("CFStringGetCharacters").get(),
+ FunctionDescriptor.ofVoid(ADDRESS, CFRange, ADDRESS)
+ );
+
+ // CFStringRef CFStringCreateWithCharacters(CFAllocatorRef alloc, const UniChar *chars, CFIndex numChars);
+ private static final MethodHandle CFStringCreateWithCharacters$Func = linker.downcallHandle(
+ coreFoundationLookup.lookup("CFStringCreateWithCharacters").get(),
+ FunctionDescriptor.of(ADDRESS, ADDRESS, ADDRESS, JAVA_LONG)
+ );
+
+ // CFTypeID CFGetTypeID(CFTypeRef cf);
+ private static final MethodHandle CFGetTypeID$Func = linker.downcallHandle(
+ coreFoundationLookup.lookup("CFGetTypeID").get(),
+ FunctionDescriptor.of(JAVA_LONG, ADDRESS)
+ );
+
+ // CFTypeID CFNumberGetTypeID(void);
+ private static final MethodHandle CFNumberGetTypeID$Func = linker.downcallHandle(
+ coreFoundationLookup.lookup("CFNumberGetTypeID").get(),
+ FunctionDescriptor.of(JAVA_LONG)
+ );
+
+ // CFTypeID CFStringGetTypeID(void);
+ private static final MethodHandle CFStringGetTypeID$Func = linker.downcallHandle(
+ coreFoundationLookup.lookup("CFStringGetTypeID").get(),
+ FunctionDescriptor.of(JAVA_LONG)
+ );
+
+ // CFNumberType CFNumberGetType(CFNumberRef number);
+ private static final MethodHandle CFNumberGetType$Func = linker.downcallHandle(
+ coreFoundationLookup.lookup("CFNumberGetType").get(),
+ FunctionDescriptor.of(JAVA_LONG, ADDRESS)
+ );
+
+ // Boolean CFNumberGetValue(CFNumberRef number, CFNumberType theType, void *valuePtr);
+ private static final MethodHandle CFNumberGetValue$Func = linker.downcallHandle(
+ coreFoundationLookup.lookup("CFNumberGetValue").get(),
+ FunctionDescriptor.of(JAVA_BOOLEAN, ADDRESS, JAVA_LONG, ADDRESS)
+ );
+ // CFRunLoopRef CFRunLoopGetCurrent(void);
+ private static final MethodHandle CFRunLoopGetCurrent$Func = linker.downcallHandle(
+ coreFoundationLookup.lookup("CFRunLoopGetCurrent").get(),
+ FunctionDescriptor.of(ADDRESS)
+ );
+ // void CFRunLoopAddSource(CFRunLoopRef rl, CFRunLoopSourceRef source, CFRunLoopMode mode);
+ private static final MethodHandle CFRunLoopAddSource$Func = linker.downcallHandle(
+ coreFoundationLookup.lookup("CFRunLoopAddSource").get(),
+ FunctionDescriptor.ofVoid(ADDRESS, ADDRESS, ADDRESS)
+ );
+ // void CFRunLoopRun(void);
+ private static final MethodHandle CFRunLoopRun$Func = linker.downcallHandle(
+ coreFoundationLookup.lookup("CFRunLoopRun").get(),
+ FunctionDescriptor.ofVoid()
+ );
+
public static String cfStringToJavaString(MemoryAddress string) {
try (var session = MemorySession.openConfined()) {
@@ -305,4 +287,31 @@ public static boolean CFNumberGetValue(Addressable number, long theType, Address
throw new RuntimeException(t);
}
}
+
+ // CFRunLoopRef CFRunLoopGetCurrent(void);
+ public static MemoryAddress CFRunLoopGetCurrent() {
+ try {
+ return (MemoryAddress) CFRunLoopGetCurrent$Func.invokeExact();
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
+ }
+ }
+
+ // void CFRunLoopAddSource(CFRunLoopRef rl, CFRunLoopSourceRef source, CFRunLoopMode mode);
+ public static void CFRunLoopAddSource(Addressable runLoop, Addressable source, Addressable mode) {
+ try {
+ CFRunLoopAddSource$Func.invokeExact(runLoop, source, mode);
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
+ }
+ }
+
+ // void CFRunLoopRun(void);
+ public static void CFRunLoopRun() {
+ try {
+ CFRunLoopRun$Func.invokeExact();
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
+ }
+ }
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKit.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKit.java
index bc5a87b2..7d8dc238 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKit.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKit.java
@@ -7,8 +7,6 @@
package net.codecrete.usb.macos;
-import net.codecrete.usb.common.Foreign;
-
import java.lang.foreign.*;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.VarHandle;
@@ -16,175 +14,198 @@
import static java.lang.foreign.MemoryAddress.NULL;
import static java.lang.foreign.MemoryLayout.PathElement.groupElement;
import static java.lang.foreign.ValueLayout.*;
-import static net.codecrete.usb.macos.CoreFoundation.*;
+import static net.codecrete.usb.macos.CoreFoundation.CFUUIDBytes;
+import static net.codecrete.usb.macos.CoreFoundation.javaStringToCfString;
public class IoKit {
+ private static final Linker linker = Linker.nativeLinker();
+ private static final MemorySession ioKitSession = MemorySession.openShared();
+ private static final SymbolLookup ioKitLookup = SymbolLookup.libraryLookup("IOKit.framework/IOKit", ioKitSession);
+
+ public static final Addressable kIOUSBPlane = ioKitSession.allocateUtf8String("IOUSB");
+ public static final Addressable kIOServicePlane = ioKitSession.allocateUtf8String("IOService");
+
+ public static final GroupLayout IOCFPlugInInterface$Struct = MemoryLayout.structLayout(
+ ADDRESS.withName("_reserved"), // void *_reserved;
+ ADDRESS.withName("QueryInterface"), // HRESULT (STDMETHODCALLTYPE *QueryInterface)(void *thisPointer, REFIID iid, LPVOID *ppv);
+ ADDRESS.withName("AddRef"), // ULONG (STDMETHODCALLTYPE *AddRef)(void *thisPointer);
+ ADDRESS.withName("Release"), // ULONG (STDMETHODCALLTYPE *Release)(void *thisPointer);
+ JAVA_SHORT.withName("version"), // UInt16 version;
+ JAVA_SHORT.withName("revision"), // UInt16 revision;
+ ADDRESS.withName("Probe"), // IOReturn (*Probe)(void *thisPointer, CFDictionaryRef propertyTable, io_service_t service, SInt32 * order);
+ ADDRESS.withName("Start"), // IOReturn (*Start)(void *thisPointer, CFDictionaryRef propertyTable, io_service_t service);
+ ADDRESS.withName("Stop") // IOReturn (*Stop)(void *thisPointer);
+ );
+
+ private static final VarHandle IUnknown_QueryInterface = IOCFPlugInInterface$Struct.varHandle(groupElement("QueryInterface"));
+ private static final VarHandle IUnknown_AddRef = IOCFPlugInInterface$Struct.varHandle(groupElement("AddRef"));
+ private static final VarHandle IUnknown_Release = IOCFPlugInInterface$Struct.varHandle(groupElement("Release"));
+
+ // HRESULT (STDMETHODCALLTYPE *QueryInterface)(void *thisPointer, REFIID iid, LPVOID *ppv);
+ private static final MethodHandle QueryInterface$Func = linker.downcallHandle(
+ FunctionDescriptor.of(JAVA_INT, ADDRESS, CFUUIDBytes, ADDRESS)
+ );
+
+ // ULONG (STDMETHODCALLTYPE *AddRef)(void *thisPointer);
+ private static final MethodHandle AddRef$Func = linker.downcallHandle(
+ FunctionDescriptor.of(JAVA_INT, ADDRESS)
+ );
+
+ // ULONG (STDMETHODCALLTYPE *Release)(void *thisPointer);
+ private static final MethodHandle Release$Func = linker.downcallHandle(
+ FunctionDescriptor.of(JAVA_INT, ADDRESS)
+ );
+
+ // io_registry_entry_t IORegistryGetRootEntry(mach_port_t mainPort);
+ private static final MethodHandle IORegistryGetRootEntry$Func = linker.downcallHandle(
+ ioKitLookup.lookup("IORegistryGetRootEntry").get(),
+ FunctionDescriptor.of(JAVA_INT, JAVA_INT)
+ );
+
+ // kern_return_t IOObjectRelease(io_object_t object);
+ private static final MethodHandle IOObjectRelease$Func = linker.downcallHandle(
+ ioKitLookup.lookup("IOObjectRelease").get(),
+ FunctionDescriptor.of(JAVA_INT, JAVA_INT)
+ );
+
+ // kern_return_t IORegistryEntryCreateIterator(io_registry_entry_t entry, const io_name_t plane, IOOptionBits options, io_iterator_t *iterator);
+ private static final MethodHandle IORegistryCreateIterator$Func = linker.downcallHandle(
+ ioKitLookup.lookup("IORegistryCreateIterator").get(),
+ FunctionDescriptor.of(JAVA_INT, JAVA_INT, ADDRESS, JAVA_INT, ADDRESS)
+ );
+
+ // io_object_t IOIteratorNext(io_iterator_t iterator);
+ private static final MethodHandle IOIteratorNext$Func = linker.downcallHandle(
+ ioKitLookup.lookup("IOIteratorNext").get(),
+ FunctionDescriptor.of(JAVA_INT, JAVA_INT)
+ );
+
+ // kern_return_t IORegistryEntryGetPath(io_registry_entry_t entry, const io_name_t plane, io_string_t path);
+ private static final MethodHandle IORegistryEntryGetPath$Func = linker.downcallHandle(
+ ioKitLookup.lookup("IORegistryEntryGetPath").get(),
+ FunctionDescriptor.of(JAVA_INT, JAVA_INT, ADDRESS, ADDRESS)
+ );
+
+ // CFTypeRef IORegistryEntryCreateCFProperty(io_registry_entry_t entry, CFStringRef key, CFAllocatorRef allocator, IOOptionBits options);
+ private static final MethodHandle IORegistryEntryCreateCFProperty$Func = linker.downcallHandle(
+ ioKitLookup.lookup("IORegistryEntryCreateCFProperty").get(),
+ FunctionDescriptor.of(ADDRESS, JAVA_INT, ADDRESS, ADDRESS, JAVA_INT)
+ );
+
+ // kern_return_t IOCreatePlugInInterfaceForService(io_service_t service, CFUUIDRef pluginType, CFUUIDRef interfaceType, IOCFPlugInInterface ***theInterface, SInt32 *theScore);
+ private static final MethodHandle IOCreatePlugInInterfaceForService$Func = linker.downcallHandle(
+ ioKitLookup.lookup("IOCreatePlugInInterfaceForService").get(),
+ FunctionDescriptor.of(JAVA_INT, JAVA_INT, ADDRESS, ADDRESS, ADDRESS, ADDRESS)
+ );
+
+ // io_registry_entry_t IORegistryEntryFromPath(mach_port_t mainPort, const io_string_t path);
+ private static final MethodHandle IORegistryEntryFromPath$Func = linker.downcallHandle(
+ ioKitLookup.lookup("IORegistryEntryFromPath").get(),
+ FunctionDescriptor.of(JAVA_INT, JAVA_INT, ADDRESS)
+ );
+
+ // IONotificationPortRef IONotificationPortCreate(mach_port_t mainPort);
+ private static final MethodHandle IONotificationPortCreate$Func = linker.downcallHandle(
+ ioKitLookup.lookup("IONotificationPortCreate").get(),
+ FunctionDescriptor.of(ADDRESS, JAVA_INT)
+ );
+
+ // CFRunLoopSourceRef IONotificationPortGetRunLoopSource(IONotificationPortRef notify);
+ private static final MethodHandle IONotificationPortGetRunLoopSource$Func = linker.downcallHandle(
+ ioKitLookup.lookup("IONotificationPortGetRunLoopSource").get(),
+ FunctionDescriptor.of(ADDRESS, ADDRESS)
+ );
+
+ // io_service_t IOServiceGetMatchingService(mach_port_t mainPort, CFDictionaryRef matching);
+ private static final MethodHandle IOServiceGetMatchingService$Func = linker.downcallHandle(
+ ioKitLookup.lookup("IOServiceGetMatchingService").get(),
+ FunctionDescriptor.of(JAVA_INT, JAVA_INT, ADDRESS)
+ );
+
+ // kern_return_t IOServiceAddMatchingNotification(IONotificationPortRef notifyPort, const io_name_t notificationType, CFDictionaryRef matching, IOServiceMatchingCallback callback, void *refCon, io_iterator_t *notification);
+ private static final MethodHandle IOServiceAddMatchingNotification$Func = linker.downcallHandle(
+ ioKitLookup.lookup("IOServiceAddMatchingNotification").get(),
+ FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS, ADDRESS, ADDRESS, ADDRESS, ADDRESS)
+ );
+
+ // CFMutableDictionaryRef IOServiceMatching(const char *name);
+ private static final MethodHandle IOServiceMatching$Func = linker.downcallHandle(
+ ioKitLookup.lookup("IOServiceMatching").get(),
+ FunctionDescriptor.of(ADDRESS, ADDRESS)
+ );
+
+ // CFMutableDictionaryRef IORegistryEntryIDMatching(uint64_t entryID);
+ private static final MethodHandle IORegistryEntryIDMatching$Func = linker.downcallHandle(
+ ioKitLookup.lookup("IORegistryEntryIDMatching").get(),
+ FunctionDescriptor.of(ADDRESS, JAVA_LONG)
+ );
+
+ // kern_return_t IORegistryEntryGetRegistryEntryID(io_registry_entry_t entry, uint64_t *entryID);
+ private static final MethodHandle IORegistryEntryGetRegistryEntryID$Func = linker.downcallHandle(
+ ioKitLookup.lookup("IORegistryEntryGetRegistryEntryID").get(),
+ FunctionDescriptor.of(JAVA_INT, JAVA_INT, ADDRESS)
+ );
+
+ public static final MemoryAddress kIOUSBDeviceUserClientTypeID = CoreFoundation.CFUUIDCreateFromUUIDBytes(
+ NULL,
+ new byte[]{
+ (byte) 0x9d, (byte) 0xc7, (byte) 0xb7, (byte) 0x80,
+ (byte) 0x9e, (byte) 0xc0, (byte) 0x11, (byte) 0xD4,
+ (byte) 0xa5, (byte) 0x4f, (byte) 0x00, (byte) 0x0a,
+ (byte) 0x27, (byte) 0x05, (byte) 0x28, (byte) 0x61
+ });
+
+ public static final MemoryAddress kIOUSBInterfaceUserClientTypeID = CoreFoundation.CFUUIDCreateFromUUIDBytes(
+ NULL,
+ new byte[]{
+ (byte) 0x2d, (byte) 0x97, (byte) 0x86, (byte) 0xc6,
+ (byte) 0x9e, (byte) 0xf3, (byte) 0x11, (byte) 0xD4,
+ (byte) 0xad, (byte) 0x51, (byte) 0x00, (byte) 0x0a,
+ (byte) 0x27, (byte) 0x05, (byte) 0x28, (byte) 0x61
+ });
+
+ public static final MemoryAddress kIOUSBDeviceInterfaceID100 = CoreFoundation.CFUUIDCreateFromUUIDBytes(
+ NULL,
+ new byte[]{
+ (byte) 0x5c, (byte) 0x81, (byte) 0x87, (byte) 0xd0,
+ (byte) 0x9e, (byte) 0xf3, (byte) 0x11, (byte) 0xD4,
+ (byte) 0x8b, (byte) 0x45, (byte) 0x00, (byte) 0x0a,
+ (byte) 0x27, (byte) 0x05, (byte) 0x28, (byte) 0x61
+ });
+
+ public static final MemoryAddress kIOUSBInterfaceInterfaceID100 = CoreFoundation.CFUUIDCreateFromUUIDBytes(
+ NULL,
+ new byte[]{
+ (byte) 0x73, (byte) 0xc9, (byte) 0x7a, (byte) 0xe8,
+ (byte) 0x9e, (byte) 0xf3, (byte) 0x11, (byte) 0xD4,
+ (byte) 0xb1, (byte) 0xd0, (byte) 0x00, (byte) 0x0a,
+ (byte) 0x27, (byte) 0x05, (byte) 0x28, (byte) 0x61
+ });
+
+ public static final MemoryAddress kIOCFPlugInInterfaceID = CoreFoundation.CFUUIDCreateFromUUIDBytes(
+ NULL,
+ new byte[]{
+ (byte) 0xC2, (byte) 0x44, (byte) 0xE8, (byte) 0x58,
+ (byte) 0x10, (byte) 0x9C, (byte) 0x11, (byte) 0xD4,
+ (byte) 0x91, (byte) 0xD4, (byte) 0x00, (byte) 0x50,
+ (byte) 0xE4, (byte) 0xC6, (byte) 0x42, (byte) 0x6F
+ });
public static final int kIOMasterPortDefault;
- public static final Addressable kIOUSBPlane;
- public static final Addressable kIOServicePlane;
public static final int kIORegistryIterateRecursively = 1;
- public static final MemoryAddress kIOUSBDeviceUserClientTypeID;
- public static final MemoryAddress kIOUSBInterfaceUserClientTypeID;
- public static final MemoryAddress kIOUSBDeviceInterfaceID100;
- public static final MemoryAddress kIOUSBInterfaceInterfaceID100;
- public static final MemoryAddress kIOCFPlugInInterfaceID;
-
- public static final GroupLayout IOCFPlugInInterface$Struct;
- private static final VarHandle IUnknown_QueryInterface;
- private static final VarHandle IUnknown_AddRef;
- private static final VarHandle IUnknown_Release;
-
- private static final MethodHandle QueryInterface$Func;
- private static final MethodHandle AddRef$Func;
- private static final MethodHandle Release$Func;
-
- private static final MethodHandle IORegistryGetRootEntry$Func;
- private static final MethodHandle IOObjectRelease$Func;
- private static final MethodHandle IORegistryCreateIterator$Func;
- private static final MethodHandle IOIteratorNext$Func;
- private static final MethodHandle IORegistryEntryCreateCFProperty$Func;
- private static final MethodHandle IORegistryEntryGetPath$Func;
- private static final MethodHandle IOCreatePlugInInterfaceForService$Func;
- private static final MethodHandle IORegistryEntryFromPath$Func;
- static {
- var linker = Linker.nativeLinker();
- var ioKitSession = MemorySession.openShared();
- var ioKitLookup = SymbolLookup.libraryLookup("IOKit.framework/IOKit", ioKitSession);
+ public static final MemorySegment kIOUSBDeviceClassName = ioKitSession.allocateUtf8String("IOUSBDevice");
+ public static final MemorySegment kIOFirstMatchNotification = ioKitSession.allocateUtf8String("IOServiceFirstMatch");
+ public static final MemorySegment kIOTerminatedNotification = ioKitSession.allocateUtf8String("IOServiceTerminate");
+
+ public static final MemoryAddress kCFRunLoopDefaultMode = javaStringToCfString("kCFRunLoopDefaultMode");
+
+ static {
try (var session = MemorySession.openConfined()) {
var kIOMasterPortDefaultAddress = ioKitLookup.lookup("kIOMasterPortDefault").get().address();
kIOMasterPortDefault = MemorySegment.ofAddress(kIOMasterPortDefaultAddress, 4, session).get(JAVA_INT, 0);
}
-
- kIOUSBPlane = ioKitSession.allocateUtf8String("IOUSB");
- kIOServicePlane = ioKitSession.allocateUtf8String("IOService");
-
- IOCFPlugInInterface$Struct = MemoryLayout.structLayout(
- ADDRESS.withName("_reserved"), // void *_reserved;
- ADDRESS.withName("QueryInterface"), // HRESULT (STDMETHODCALLTYPE *QueryInterface)(void *thisPointer, REFIID iid, LPVOID *ppv);
- ADDRESS.withName("AddRef"), // ULONG (STDMETHODCALLTYPE *AddRef)(void *thisPointer);
- ADDRESS.withName("Release"), // ULONG (STDMETHODCALLTYPE *Release)(void *thisPointer);
- JAVA_SHORT.withName("version"), // UInt16 version;
- JAVA_SHORT.withName("revision"), // UInt16 revision;
- ADDRESS.withName("Probe"), // IOReturn (*Probe)(void *thisPointer, CFDictionaryRef propertyTable, io_service_t service, SInt32 * order);
- ADDRESS.withName("Start"), // IOReturn (*Start)(void *thisPointer, CFDictionaryRef propertyTable, io_service_t service);
- ADDRESS.withName("Stop") // IOReturn (*Stop)(void *thisPointer);
- );
-
- IUnknown_QueryInterface = IOCFPlugInInterface$Struct.varHandle(groupElement("QueryInterface"));
- IUnknown_AddRef = IOCFPlugInInterface$Struct.varHandle(groupElement("AddRef"));
- IUnknown_Release = IOCFPlugInInterface$Struct.varHandle(groupElement("Release"));
-
- // HRESULT (STDMETHODCALLTYPE *QueryInterface)(void *thisPointer, REFIID iid, LPVOID *ppv);
- QueryInterface$Func = linker.downcallHandle(
- FunctionDescriptor.of(JAVA_INT, ADDRESS, CFUUIDBytes, ADDRESS)
- );
-
- // ULONG (STDMETHODCALLTYPE *AddRef)(void *thisPointer);
- AddRef$Func = linker.downcallHandle(
- FunctionDescriptor.of(JAVA_INT, ADDRESS)
- );
-
- // ULONG (STDMETHODCALLTYPE *Release)(void *thisPointer);
- Release$Func = linker.downcallHandle(
- FunctionDescriptor.of(JAVA_INT, ADDRESS)
- );
-
-
- // io_registry_entry_t IORegistryGetRootEntry(mach_port_t mainPort);
- IORegistryGetRootEntry$Func = linker.downcallHandle(
- ioKitLookup.lookup("IORegistryGetRootEntry").get(),
- FunctionDescriptor.of(JAVA_INT, JAVA_INT)
- );
-
- // kern_return_t IOObjectRelease(io_object_t object);
- IOObjectRelease$Func = linker.downcallHandle(
- ioKitLookup.lookup("IOObjectRelease").get(),
- FunctionDescriptor.of(JAVA_INT, JAVA_INT)
- );
-
- // kern_return_t IORegistryEntryCreateIterator(io_registry_entry_t entry, const io_name_t plane, IOOptionBits options, io_iterator_t *iterator);
- IORegistryCreateIterator$Func = linker.downcallHandle(
- ioKitLookup.lookup("IORegistryCreateIterator").get(),
- FunctionDescriptor.of(JAVA_INT, JAVA_INT, ADDRESS, JAVA_INT, ADDRESS)
- );
-
- // io_object_t IOIteratorNext(io_iterator_t iterator);
- IOIteratorNext$Func = linker.downcallHandle(
- ioKitLookup.lookup("IOIteratorNext").get(),
- FunctionDescriptor.of(JAVA_INT, JAVA_INT)
- );
-
- // kern_return_t IORegistryEntryGetPath(io_registry_entry_t entry, const io_name_t plane, io_string_t path);
- IORegistryEntryGetPath$Func = linker.downcallHandle(
- ioKitLookup.lookup("IORegistryEntryGetPath").get(),
- FunctionDescriptor.of(JAVA_INT, JAVA_INT, ADDRESS, ADDRESS)
- );
-
- // CFTypeRef IORegistryEntryCreateCFProperty(io_registry_entry_t entry, CFStringRef key, CFAllocatorRef allocator, IOOptionBits options);
- IORegistryEntryCreateCFProperty$Func = linker.downcallHandle(
- ioKitLookup.lookup("IORegistryEntryCreateCFProperty").get(),
- FunctionDescriptor.of(ADDRESS, JAVA_INT, ADDRESS, ADDRESS, JAVA_INT)
- );
-
- // kern_return_t IOCreatePlugInInterfaceForService(io_service_t service, CFUUIDRef pluginType, CFUUIDRef interfaceType, IOCFPlugInInterface ***theInterface, SInt32 *theScore);
- IOCreatePlugInInterfaceForService$Func = linker.downcallHandle(
- ioKitLookup.lookup("IOCreatePlugInInterfaceForService").get(),
- FunctionDescriptor.of(JAVA_INT, JAVA_INT, ADDRESS, ADDRESS, ADDRESS, ADDRESS)
- );
-
- // io_registry_entry_t IORegistryEntryFromPath(mach_port_t mainPort, const io_string_t path);
- IORegistryEntryFromPath$Func = linker.downcallHandle(
- ioKitLookup.lookup("IORegistryEntryFromPath").get(),
- FunctionDescriptor.of(JAVA_INT, JAVA_INT, ADDRESS)
- );
-
- kIOUSBDeviceUserClientTypeID = CoreFoundation.CFUUIDCreateFromUUIDBytes(
- NULL,
- new byte[]{
- (byte) 0x9d, (byte) 0xc7, (byte) 0xb7, (byte) 0x80,
- (byte) 0x9e, (byte) 0xc0, (byte) 0x11, (byte) 0xD4,
- (byte) 0xa5, (byte) 0x4f, (byte) 0x00, (byte) 0x0a,
- (byte) 0x27, (byte) 0x05, (byte) 0x28, (byte) 0x61
- });
-
- kIOUSBInterfaceUserClientTypeID = CoreFoundation.CFUUIDCreateFromUUIDBytes(
- NULL,
- new byte[]{
- (byte) 0x2d, (byte) 0x97, (byte) 0x86, (byte) 0xc6,
- (byte) 0x9e, (byte) 0xf3, (byte) 0x11, (byte) 0xD4,
- (byte) 0xad, (byte) 0x51, (byte) 0x00, (byte) 0x0a,
- (byte) 0x27, (byte) 0x05, (byte) 0x28, (byte) 0x61
- });
-
- kIOUSBDeviceInterfaceID100 = CoreFoundation.CFUUIDCreateFromUUIDBytes(
- NULL,
- new byte[]{
- (byte) 0x5c, (byte) 0x81, (byte) 0x87, (byte) 0xd0,
- (byte) 0x9e, (byte) 0xf3, (byte) 0x11, (byte) 0xD4,
- (byte) 0x8b, (byte) 0x45, (byte) 0x00, (byte) 0x0a,
- (byte) 0x27, (byte) 0x05, (byte) 0x28, (byte) 0x61
- });
-
- kIOUSBInterfaceInterfaceID100 = CoreFoundation.CFUUIDCreateFromUUIDBytes(
- NULL,
- new byte[]{
- (byte) 0x73, (byte) 0xc9, (byte) 0x7a, (byte) 0xe8,
- (byte) 0x9e, (byte) 0xf3, (byte) 0x11, (byte) 0xD4,
- (byte) 0xb1, (byte) 0xd0, (byte) 0x00, (byte) 0x0a,
- (byte) 0x27, (byte) 0x05, (byte) 0x28, (byte) 0x61
- });
-
- kIOCFPlugInInterfaceID = CoreFoundation.CFUUIDCreateFromUUIDBytes(
- NULL,
- new byte[]{
- (byte) 0xC2, (byte) 0x44, (byte) 0xE8, (byte) 0x58,
- (byte) 0x10, (byte) 0x9C, (byte) 0x11, (byte) 0xD4,
- (byte) 0x91, (byte) 0xD4, (byte) 0x00, (byte) 0x50,
- (byte) 0xE4, (byte) 0xC6, (byte) 0x42, (byte) 0x6F
- });
}
// io_registry_entry_t IORegistryGetRootEntry(mach_port_t mainPort);
@@ -270,6 +291,70 @@ public static int IORegistryEntryFromPath(int mainPort, String path) {
return (MemoryAddress) varHandle.get(obj);
}
+ // IONotificationPortRef IONotificationPortCreate(mach_port_t mainPort);
+ public static MemoryAddress IONotificationPortCreate(int mainPort) {
+ try {
+ return (MemoryAddress) IONotificationPortCreate$Func.invokeExact(mainPort);
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
+ }
+ }
+
+ // CFRunLoopSourceRef IONotificationPortGetRunLoopSource(IONotificationPortRef notify);
+ public static MemoryAddress IONotificationPortGetRunLoopSource(Addressable notify) {
+ try {
+ return (MemoryAddress) IONotificationPortGetRunLoopSource$Func.invokeExact(notify);
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
+ }
+ }
+
+ // kern_return_t IOServiceAddMatchingNotification(IONotificationPortRef notifyPort, const io_name_t notificationType, CFDictionaryRef matching, IOServiceMatchingCallback callback, void *refCon, io_iterator_t *notification);
+ public static int IOServiceAddMatchingNotification(Addressable notifyPort, Addressable notificationType, Addressable matching, Addressable callback, Addressable refCon, Addressable notificationHolder) {
+ try {
+ return (int) IOServiceAddMatchingNotification$Func.invokeExact(notifyPort, notificationType, matching, callback, refCon, notificationHolder);
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
+ }
+ }
+
+ // CFMutableDictionaryRef IOServiceMatching(const char *name);
+ public static MemoryAddress IOServiceMatching(Addressable name) {
+ try {
+ return (MemoryAddress) IOServiceMatching$Func.invokeExact(name);
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
+ }
+ }
+
+ // CFMutableDictionaryRef IORegistryEntryIDMatching(uint64_t entryID);
+ public static MemoryAddress IORegistryEntryIDMatching(long entryID) {
+ try {
+ return (MemoryAddress) IORegistryEntryIDMatching$Func.invokeExact(entryID);
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
+ }
+ }
+
+ // io_service_t IOServiceGetMatchingService(mach_port_t mainPort, CFDictionaryRef matching);
+ public static int IOServiceGetMatchingService(int mainPort, Addressable matching) {
+ try {
+ return (int) IOServiceGetMatchingService$Func.invokeExact(mainPort, matching);
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
+ }
+ }
+
+ // kern_return_t IORegistryEntryGetRegistryEntryID(io_registry_entry_t entry, uint64_t *entryID);
+ public static int IORegistryEntryGetRegistryEntryID(int entry, Addressable entryIdHolder) {
+ try {
+ return (int) IORegistryEntryGetRegistryEntryID$Func.invokeExact(entry, entryIdHolder);
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
+ }
+ }
+
+
// HRESULT (STDMETHODCALLTYPE *QueryInterface)(void *thisPointer, REFIID iid, LPVOID *ppv);
public static int QueryInterface(MemoryAddress thisPointer, MemorySegment iid, Addressable ppv) {
try (var session = MemorySession.openShared()) {
@@ -300,40 +385,4 @@ public static int Release(MemoryAddress thisPointer) {
}
}
- /**
- * Get an interface of the specified service.
- *
- * This method first request the specified plugin interfaces and then
- * queries for the specified interface.
- *
- *
- * @param service the service
- * @param pluginType the plugin interface type
- * @param interfaceId the interface ID
- * @return the interface, or null if the plugin type or interface is not available
- */
- public static MemoryAddress GetInterface(int service, Addressable pluginType, MemoryAddress interfaceId) {
- try (var session = MemorySession.openConfined()) {
- // MemorySegment for holding IOCFPlugInInterface**
- var plugPointer = session.allocate(ADDRESS, NULL);
- // MemorySegment for holding score
- var score = session.allocate(JAVA_INT, 0);
- int ret = IOCreatePlugInInterfaceForService(service, pluginType, kIOCFPlugInInterfaceID, plugPointer, score);
- if (ret != 0)
- return null;
-
- var plug = Foreign.derefAddress(plugPointer.address(), session);
- // MemorySegment for holding XXXInterface**
- var intf = session.allocate(ADDRESS, NULL);
- // UUID bytes
- var refiid = MemorySegment.ofAddress(interfaceId.addOffset(CFUUID_bytes$Offset), CFUUID.byteSize(), session);
- ret = QueryInterface(plug, refiid, intf);
- Release(plug);
-
- if (ret != 0)
- return null;
- return Foreign.derefAddress(intf.address(), session);
- }
-
- }
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKitHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKitHelper.java
new file mode 100644
index 00000000..513b1d1f
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKitHelper.java
@@ -0,0 +1,118 @@
+//
+// Java Does USB
+// Copyright (c) 2022 Manuel Bleichenbacher
+// Licensed under MIT License
+// https://opensource.org/licenses/MIT
+//
+
+package net.codecrete.usb.macos;
+
+import net.codecrete.usb.common.Foreign;
+
+import java.lang.foreign.Addressable;
+import java.lang.foreign.MemoryAddress;
+import java.lang.foreign.MemorySegment;
+import java.lang.foreign.MemorySession;
+
+import static java.lang.foreign.MemoryAddress.NULL;
+import static java.lang.foreign.ValueLayout.ADDRESS;
+import static java.lang.foreign.ValueLayout.JAVA_INT;
+import static net.codecrete.usb.macos.CoreFoundation.CFUUID;
+import static net.codecrete.usb.macos.CoreFoundation.CFUUID_bytes$Offset;
+
+/**
+ * Helper functions for the IOKit framework.
+ */
+public class IoKitHelper {
+ private static final long NUMBER_TYPE_ID = CoreFoundation.CFNumberGetTypeID();
+ private static final long STRING_TYPE_ID = CoreFoundation.CFStringGetTypeID();
+
+ /**
+ * Get an interface of the specified service.
+ *
+ * This method first request the specified plugin interfaces and then
+ * queries for the specified interface.
+ *
+ *
+ * @param service the service
+ * @param pluginType the plugin interface type
+ * @param interfaceId the interface ID
+ * @return the interface, or null if the plugin type or interface is not available
+ */
+ public static MemoryAddress GetInterface(int service, Addressable pluginType, MemoryAddress interfaceId) {
+ try (var session = MemorySession.openConfined()) {
+ // MemorySegment for holding IOCFPlugInInterface**
+ var plugPointer = session.allocate(ADDRESS, NULL);
+ // MemorySegment for holding score
+ var score = session.allocate(JAVA_INT, 0);
+ int ret = IoKit.IOCreatePlugInInterfaceForService(service, pluginType, IoKit.kIOCFPlugInInterfaceID, plugPointer, score);
+ if (ret != 0)
+ return null;
+
+ var plug = Foreign.derefAddress(plugPointer.address(), session);
+ // MemorySegment for holding XXXInterface**
+ var intf = session.allocate(ADDRESS, NULL);
+ // UUID bytes
+ var refiid = MemorySegment.ofAddress(interfaceId.addOffset(CFUUID_bytes$Offset), CFUUID.byteSize(), session);
+ ret = IoKit.QueryInterface(plug, refiid, intf);
+ IoKit.Release(plug);
+
+ if (ret != 0)
+ return null;
+ return Foreign.derefAddress(intf.address(), session);
+ }
+
+ }
+
+ /**
+ * Gets a property of the specified IO registry service.
+ *
+ * The property must be of numeric type.
+ *
+ * @param service the service
+ * @param key the property key
+ * @return the property value, or {@code null} if the service doesn't have the property
+ */
+ public static Integer GetPropertyInt(int service, String key) {
+ var value = IoKit.IORegistryEntryCreateCFProperty(service, key, NULL, 0);
+ if (value == NULL)
+ return null;
+
+ Integer result = null;
+ var type = CoreFoundation.CFGetTypeID(value);
+ if (type == NUMBER_TYPE_ID) {
+
+ try (var session = MemorySession.openConfined()) {
+ var numberValue = session.allocate(JAVA_INT, 0);
+ if (CoreFoundation.CFNumberGetValue(value, CoreFoundation.kCFNumberSInt32Type, numberValue))
+ result = numberValue.get(JAVA_INT, 0);
+ }
+ }
+
+ CoreFoundation.CFRelease(value);
+ return result;
+ }
+
+ /**
+ * Gets a property of the specified IO registry service.
+ *
+ * The property must be of string type.
+ *
+ * @param service the service
+ * @param key the property key
+ * @return the property value, or {@code null} if the service doesn't have the property
+ */
+ public static String GetPropertyString(int service, String key) {
+ var value = IoKit.IORegistryEntryCreateCFProperty(service, key, NULL, 0);
+ if (value == NULL)
+ return null;
+
+ String result = null;
+ var type = CoreFoundation.CFGetTypeID(value);
+ if (type == STRING_TYPE_ID)
+ result = CoreFoundation.cfStringToJavaString(value);
+
+ CoreFoundation.CFRelease(value);
+ return result;
+ }
+}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDevice.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDevice.java
index 17e254ea..aa4e1d8d 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDevice.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDevice.java
@@ -10,7 +10,6 @@
import net.codecrete.usb.USBControlTransfer;
import net.codecrete.usb.USBDeviceInfo;
import net.codecrete.usb.USBDirection;
-import net.codecrete.usb.USBException;
import net.codecrete.usb.common.USBDescriptors;
import net.codecrete.usb.common.USBDeviceImpl;
@@ -20,6 +19,8 @@
import java.util.ArrayList;
import java.util.List;
+import static java.lang.foreign.MemoryAddress.NULL;
+import static java.lang.foreign.MemoryAddress.ofLong;
import static java.lang.foreign.ValueLayout.*;
public class MacosUSBDevice extends USBDeviceImpl {
@@ -29,27 +30,33 @@ public class MacosUSBDevice extends USBDeviceImpl {
private List claimedInterfaces;
private List endpoints;
- MacosUSBDevice(String path, USBDeviceInfo info) {
- super(path, info);
+ MacosUSBDevice(Object id, USBDeviceInfo info) {
+ super(id, info);
try (var session = MemorySession.openConfined()) {
- // get service from IO registry
- final int service = IoKit.IORegistryEntryFromPath(0, path);
+// // get service from IO registry
+// final int service = IoKit.IORegistryEntryFromPath(0, path);
+ var matching = IoKit.IORegistryEntryIDMatching((Long) id);
+ if (matching == NULL)
+ throw new MacosUSBException("IORegistryEntryIDMatching failed");
+
+ // Consumes matching instance
+ int service = IoKit.IOServiceGetMatchingService(IoKit.kIOMasterPortDefault, matching);
if (service == 0)
- throw new USBException("unable to open USB device (IORegistryEntryFromPath)");
+ throw new MacosUSBException("unable to open USB device (IOServiceGetMatchingService)");
session.addCloseAction(() -> IoKit.IOObjectRelease(service));
// get user client interface
- device = IoKit.GetInterface(service, IoKit.kIOUSBDeviceUserClientTypeID, IoKit.kIOUSBDeviceInterfaceID100);
+ device = IoKitHelper.GetInterface(service, IoKit.kIOUSBDeviceUserClientTypeID, IoKit.kIOUSBDeviceInterfaceID100);
if (device == null)
- throw new USBException("unable to open USB device (get client interface)");
+ throw new MacosUSBException("unable to open USB device (get client interface)");
// open device
int ret = IoKitUSB.USBDeviceOpen(device);
if (ret != 0) {
IoKit.Release(device);
- throw new USBException("unable to open USB device", ret);
+ throw new MacosUSBException("unable to open USB device", ret);
}
try {
@@ -57,7 +64,7 @@ public class MacosUSBDevice extends USBDeviceImpl {
var descPtrHolder = session.allocate(ADDRESS);
ret = IoKitUSB.GetConfigurationDescriptorPtr(device, (byte) 0, descPtrHolder);
if (ret != 0)
- throw new USBException("failed to query first configuration", ret);
+ throw new MacosUSBException("failed to query first configuration", ret);
// get value of first configuration
var configDesc = MemorySegment.ofAddress(descPtrHolder.get(ADDRESS, 0), USBDescriptors.Configuration.byteSize(), session);
@@ -66,7 +73,7 @@ public class MacosUSBDevice extends USBDeviceImpl {
// set configuration
ret = IoKitUSB.SetConfiguration(device, (byte) configurationValue);
if (ret != 0)
- throw new USBException("failed to set configuration", ret);
+ throw new MacosUSBException("failed to set configuration", ret);
} catch (Throwable e) {
IoKitUSB.USBDeviceClose(device);
@@ -99,7 +106,7 @@ private InterfaceInfo findInterface(int interfaceNumber) {
final int service_final = service;
session.addCloseAction(() -> IoKit.IOObjectRelease(service_final));
- final MemoryAddress intf = IoKit.GetInterface(service, IoKit.kIOUSBInterfaceUserClientTypeID, IoKit.kIOUSBInterfaceInterfaceID100);
+ final MemoryAddress intf = IoKitHelper.GetInterface(service, IoKit.kIOUSBInterfaceUserClientTypeID, IoKit.kIOUSBInterfaceInterfaceID100);
if (intf == null)
continue;
@@ -118,7 +125,7 @@ private InterfaceInfo findInterface(int interfaceNumber) {
}
}
- throw new USBException(String.format("Invalid interface number: %d", interfaceNumber));
+ throw new MacosUSBException(String.format("Invalid interface number: %d", interfaceNumber));
}
public void claimInterface(int interfaceNumber) {
@@ -127,7 +134,7 @@ public void claimInterface(int interfaceNumber) {
try {
var ret = IoKitUSB.USBInterfaceOpen(interfaceInfo.asMemoryAddress());
if (ret != 0)
- throw new USBException("Failed to claim interface", ret);
+ throw new MacosUSBException("Failed to claim interface", ret);
} catch (Throwable t) {
IoKit.Release(interfaceInfo.asMemoryAddress());
throw t;
@@ -144,13 +151,13 @@ public void releaseInterface(int interfaceNumber) {
var interfaceInfoOptional =
claimedInterfaces.stream().filter(info -> info.interfaceNumber == interfaceNumber).findFirst();
if (interfaceInfoOptional.isEmpty())
- throw new USBException(String.format("Invalid interface number: %d", interfaceNumber));
+ throw new MacosUSBException(String.format("Invalid interface number: %d", interfaceNumber));
var interfaceInfo = interfaceInfoOptional.get();
int ret = IoKitUSB.USBInterfaceClose(interfaceInfo.asMemoryAddress());
if (ret != 0)
- throw new USBException("Failed to release interface", ret);
+ throw new MacosUSBException("Failed to release interface", ret);
claimedInterfaces.remove(interfaceInfo);
IoKit.Release(interfaceInfo.asMemoryAddress());
@@ -168,7 +175,7 @@ private void updateEndpointList() {
var numEndpointsHolder = session.allocate(JAVA_BYTE);
int ret = IoKitUSB.GetNumEndpoints(intf, numEndpointsHolder);
if (ret != 0)
- throw new USBException("Failed to get number of endpoints", ret);
+ throw new MacosUSBException("Failed to get number of endpoints", ret);
int numEndpoints = numEndpointsHolder.get(JAVA_BYTE, 0) & 255;
for (int pipeIndex = 1; pipeIndex <= numEndpoints; pipeIndex++) {
@@ -182,7 +189,7 @@ private void updateEndpointList() {
ret = IoKitUSB.GetPipeProperties(intf, (byte) pipeIndex, directionHolder,
numberHolder, transferTypeHolder, maxPacketSizeHolder, intervalHolder);
if (ret != 0)
- throw new USBException("Failed to get pipe properties", ret);
+ throw new MacosUSBException("Failed to get pipe properties", ret);
var endpointInfo = new EndpointInfo();
endpointInfo.pipeIndex = pipeIndex;
@@ -204,7 +211,7 @@ private EndpointInfo getEndpointInfo(int endpointNumber) {
return endpointOptional.get();
}
- throw new USBException(String.format("Endpoint number %d is not part of a claimed interface or invalid", endpointNumber));
+ throw new MacosUSBException(String.format("Endpoint number %d is not part of a claimed interface or invalid", endpointNumber));
}
private static MemorySegment createDeviceRequest(MemorySession session, USBDirection direction, USBControlTransfer setup, MemorySegment data) {
@@ -227,7 +234,7 @@ public byte[] controlTransferIn(USBControlTransfer setup, int length) {
int ret = IoKitUSB.DeviceRequest(device, deviceRequest);
if (ret != 0)
- throw new USBException("Control IN transfer failed", ret);
+ throw new MacosUSBException("Control IN transfer failed", ret);
int lenDone = (int) IoKitUSB.IOUSBDevRequest_wLenDone.get(deviceRequest);
return data.asSlice(0, lenDone).toArray(JAVA_BYTE);
@@ -245,7 +252,7 @@ public void controlTransferOut(USBControlTransfer setup, byte[] data) {
int ret = IoKitUSB.DeviceRequest(device, deviceRequest);
if (ret != 0)
- throw new USBException("Control IN transfer failed", ret);
+ throw new MacosUSBException("Control IN transfer failed", ret);
}
}
@@ -260,7 +267,7 @@ public void transferOut(int endpointNumber, byte[] data) {
int ret = IoKitUSB.WritePipe(endpointInfo.interfaceInfo.asMemoryAddress(), (byte) endpointInfo.pipeIndex,
nativeData, data.length);
if (ret != 0)
- throw new USBException(String.format("Sending data to endpoint %d failed", endpointNumber), ret);
+ throw new MacosUSBException(String.format("Sending data to endpoint %d failed", endpointNumber), ret);
}
}
@@ -274,7 +281,7 @@ public byte[] transferIn(int endpointNumber, int maxLength) {
int ret = IoKitUSB.ReadPipe(endpointInfo.interfaceInfo.asMemoryAddress(), (byte) endpointInfo.pipeIndex,
nativeData, sizeHolder);
if (ret != 0)
- throw new USBException(String.format("Receiving data from endpoint %d failed", endpointNumber), ret);
+ throw new MacosUSBException(String.format("Receiving data from endpoint %d failed", endpointNumber), ret);
int size = sizeHolder.get(JAVA_INT, 0);
var result = new byte[size];
@@ -301,7 +308,7 @@ static class InterfaceInfo {
int interfaceNumber;
MemoryAddress asMemoryAddress() {
- return MemoryAddress.ofLong(addr);
+ return ofLong(addr);
}
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceInfo.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceInfo.java
index 516254fb..877f3296 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceInfo.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceInfo.java
@@ -13,17 +13,17 @@
public class MacosUSBDeviceInfo extends USBDeviceInfoImpl {
MacosUSBDeviceInfo(
- String path, int vendorId, int productId,
+ Object id, int vendorId, int productId,
String manufacturer, String product, String serial,
int classCode, int subclassCode, int protocolCode) {
- super(path, vendorId, productId,
+ super(id, vendorId, productId,
manufacturer, product, serial,
classCode, subclassCode, protocolCode);
}
@Override
public USBDevice open() {
- return new MacosUSBDevice(path, this);
+ return new MacosUSBDevice(id, this);
}
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceRegistry.java
index f266b472..7ca6960f 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceRegistry.java
@@ -10,114 +10,228 @@
import net.codecrete.usb.USBDeviceInfo;
import net.codecrete.usb.common.USBDeviceRegistry;
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.foreign.Linker;
import java.lang.foreign.MemoryAddress;
import java.lang.foreign.MemorySession;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
import java.util.ArrayList;
import java.util.List;
+import java.util.function.Consumer;
import static java.lang.foreign.MemoryAddress.NULL;
-import static java.lang.foreign.ValueLayout.JAVA_BYTE;
-import static java.lang.foreign.ValueLayout.JAVA_INT;
+import static java.lang.foreign.ValueLayout.*;
public class MacosUSBDeviceRegistry implements USBDeviceRegistry {
- private static final long NUMBER_TYPE_ID = CoreFoundation.CFNumberGetTypeID();
- private static final long STRING_TYPE_ID = CoreFoundation.CFStringGetTypeID();
+ private Consumer onDeviceConnectedHandler;
+ private Consumer onDeviceDisconnectedHandler;
+ private boolean isMonitorThreadStarted;
public List getAllDevices() {
- List result = new ArrayList<>();
- try (var outerSession = MemorySession.openConfined()) {
+ try (var session = MemorySession.openConfined()) {
final int entry = IoKit.IORegistryGetRootEntry(IoKit.kIOMasterPortDefault);
if (entry == 0)
throw new RuntimeException("IORegistryGetRootEntry failed");
- outerSession.addCloseAction(() -> IoKit.IOObjectRelease(entry));
+ session.addCloseAction(() -> IoKit.IOObjectRelease(entry));
- var iterHolder = outerSession.allocate(JAVA_INT);
+ var iterHolder = session.allocate(JAVA_INT);
int ret = IoKit.IORegistryCreateIterator(0, IoKit.kIOUSBPlane, IoKit.kIORegistryIterateRecursively, iterHolder);
final var iter = iterHolder.get(JAVA_INT, 0);
if (ret != 0)
throw new RuntimeException("IORegistryCreateIterator failed");
- outerSession.addCloseAction(() -> IoKit.IOObjectRelease(iter));
+ session.addCloseAction(() -> IoKit.IOObjectRelease(iter));
+
+ return iterateDevices(iter, false);
+ }
+ }
- int svc;
- while ((svc = IoKit.IOIteratorNext(iter)) != 0) {
- try (var session = MemorySession.openConfined()) {
+ /**
+ * Return all devices of the iterator in a list
+ */
+ private List iterateDevices(int iter, boolean isDisconnected) {
- final int service = svc;
- session.addCloseAction(() -> IoKit.IOObjectRelease(service));
+ List result = new ArrayList<>();
- // Test if service has user client interface (if not, it is likely a hub)
- final MemoryAddress device = IoKit.GetInterface(service, IoKit.kIOUSBDeviceUserClientTypeID, IoKit.kIOUSBDeviceInterfaceID100);
+ int svc;
+ while ((svc = IoKit.IOIteratorNext(iter)) != 0) {
+ try (var session = MemorySession.openConfined()) {
+
+ final int service = svc;
+ session.addCloseAction(() -> IoKit.IOObjectRelease(service));
+
+ // Test if service has user client interface (if not, it is likely a hub)
+ if (!isDisconnected) {
+ final MemoryAddress device = IoKitHelper.GetInterface(service, IoKit.kIOUSBDeviceUserClientTypeID, IoKit.kIOUSBDeviceInterfaceID100);
if (device == null)
continue;
IoKit.Release(device);
+ }
- // Get registry path
- var path = session.allocateArray(JAVA_BYTE, 512);
- ret = IoKit.IORegistryEntryGetPath(service, IoKit.kIOServicePlane, path);
- if (ret != 0)
- continue;
+ // Get registry path
+ String path;
+ var pathSegment = session.allocateArray(JAVA_BYTE, 512);
+ int ret = IoKit.IORegistryEntryGetPath(service, IoKit.kIOServicePlane, pathSegment);
+ if (ret == 0) {
+ path = pathSegment.getUtf8String(0);
+ } else if (isDisconnected) {
+ path = "";
+ } else {
+ continue;
+ }
- var deviceInfo = createDeviceInfo(path.getUtf8String(0), service);
+ // Get entry ID
+ var entryIdHolder = session.allocate(JAVA_LONG);
+ ret = IoKit.IORegistryEntryGetRegistryEntryID(service, entryIdHolder);
+ if (ret != 0)
+ throw new MacosUSBException("IORegistryEntryGetRegistryEntryID failed", ret);
+ var entryId = entryIdHolder.get(JAVA_LONG, 0);
- if (deviceInfo != null)
- result.add(deviceInfo);
- }
+ var deviceInfo = createDeviceInfo(entryId, service);
+
+ if (deviceInfo != null)
+ result.add(deviceInfo);
}
}
return result;
}
- private USBDeviceInfo createDeviceInfo(String path, int service) {
- Integer vendorId = GetPropertyInt(service, "idVendor");
- Integer productId = GetPropertyInt(service, "idProduct");
- String manufacturer = GetPropertyString(service, "kUSBVendorString");
- String product = GetPropertyString(service, "kUSBProductString");
- String serial = GetPropertyString(service, "kUSBSerialNumberString");
- Integer classCode = GetPropertyInt(service, "bDeviceClass");
- Integer subclassCode = GetPropertyInt(service, "bDeviceSubClass");
- Integer protocolCode = GetPropertyInt(service, "bDeviceProtocol");
-
- if (vendorId == null || productId == null || classCode == null || subclassCode == null || protocolCode == null)
- return null;
+ private synchronized void startDeviceMonitor() {
+ if (isMonitorThreadStarted)
+ return;
- return new MacosUSBDeviceInfo(path, vendorId, productId, manufacturer, product, serial, classCode, subclassCode, protocolCode);
+ isMonitorThreadStarted = true;
+ Thread t = new Thread(this::monitorDevices, "USB device monitor");
+ t.start();
}
- private static Integer GetPropertyInt(int service, String key) {
- var value = IoKit.IORegistryEntryCreateCFProperty(service, key, NULL, 0);
- if (value == NULL)
- return null;
+ private void monitorDevices() {
- Integer result = null;
- var type = CoreFoundation.CFGetTypeID(value);
- if (type == NUMBER_TYPE_ID) {
+ try (var session = MemorySession.openConfined()) {
- try (var session = MemorySession.openConfined()) {
- var numberValue = session.allocate(JAVA_INT, 0);
- if (CoreFoundation.CFNumberGetValue(value, CoreFoundation.kCFNumberSInt32Type, numberValue))
- result = numberValue.get(JAVA_INT, 0);
- }
+ var notifyPort = IoKit.IONotificationPortCreate(IoKit.kIOMasterPortDefault);
+ var runLoopSource = IoKit.IONotificationPortGetRunLoopSource(notifyPort);
+
+ var runLoop = CoreFoundation.CFRunLoopGetCurrent();
+ CoreFoundation.CFRunLoopAddSource(runLoop, runLoopSource, IoKit.kCFRunLoopDefaultMode);
+
+ var matchingDict = IoKit.IOServiceMatching(IoKit.kIOUSBDeviceClassName);
+
+ // create callback stub (connected devices)
+ var onDeviceConnectedMH = MethodHandles.lookup().findVirtual(
+ MacosUSBDeviceRegistry.class,
+ "onDeviceConnected",
+ MethodType.methodType(void.class, MemoryAddress.class, int.class)
+ ).bindTo(this);
+ var onDeviceConnectedStub = Linker.nativeLinker().upcallStub(
+ onDeviceConnectedMH,
+ FunctionDescriptor.ofVoid(ADDRESS, JAVA_INT),
+ session
+ );
+
+ // Set up a notification to be called when a device is first matched by I/O Kit.
+ // This method consumes the matchingDict reference.
+ var deviceIterHolder = session.allocate(JAVA_INT);
+ int ret = IoKit.IOServiceAddMatchingNotification(notifyPort, IoKit.kIOFirstMatchNotification,
+ matchingDict, onDeviceConnectedStub, NULL, deviceIterHolder);
+ if (ret != 0)
+ throw new MacosUSBException("IOServiceAddMatchingNotification failed", ret);
+ var deviceConnectedIter = deviceIterHolder.get(JAVA_INT, 0);
+
+ // iterate current devices in order to arm the notifications
+ onDeviceConnected(NULL, deviceConnectedIter);
+
+ // new matching dictionary for disconnected notifications
+ matchingDict = IoKit.IOServiceMatching(IoKit.kIOUSBDeviceClassName);
+
+ // create callback stub (connected devices)
+ var onDeviceDisconnectedMH = MethodHandles.lookup().findVirtual(
+ MacosUSBDeviceRegistry.class,
+ "onDeviceDisconnected",
+ MethodType.methodType(void.class, MemoryAddress.class, int.class)
+ ).bindTo(this);
+ var onDeviceDisconnectedStub = Linker.nativeLinker().upcallStub(
+ onDeviceDisconnectedMH,
+ FunctionDescriptor.ofVoid(ADDRESS, JAVA_INT),
+ session
+ );
+
+ // Set up a notification to be called when a device is terminated by I/O Kit.
+ // This method consumes the matchingDict reference.
+ deviceIterHolder.set(JAVA_INT, 0, 0);
+ ret = IoKit.IOServiceAddMatchingNotification(notifyPort, IoKit.kIOTerminatedNotification,
+ matchingDict, onDeviceDisconnectedStub, NULL, deviceIterHolder);
+ if (ret != 0)
+ throw new MacosUSBException("IOServiceAddMatchingNotification (2) failed", ret);
+ var deviceDisconnectedIter = deviceIterHolder.get(JAVA_INT, 0);
+
+ // iterate current devices in order to arm the notifications
+ onDeviceDisconnected(NULL, deviceDisconnectedIter);
+
+ CoreFoundation.CFRunLoopRun();
+
+ } catch (NoSuchMethodException | IllegalAccessException e) {
+ throw new RuntimeException(e);
}
+ }
- CoreFoundation.CFRelease(value);
- return result;
+ private void onDeviceConnected(MemoryAddress ignoredRefCon, int iterator) {
+ var devices = iterateDevices(iterator, false);
+ if (onDeviceConnectedHandler == null)
+ return;
+
+ for (var device : devices)
+ onDeviceConnectedHandler.accept(device);
+ }
+
+ private void onDeviceDisconnected(MemoryAddress ignoredRefCon, int iterator) {
+ var devices = iterateDevices(iterator, true);
+ if (onDeviceDisconnectedHandler == null)
+ return;
+
+ for (var device : devices)
+ onDeviceDisconnectedHandler.accept(device);
}
- private static String GetPropertyString(int service, String key) {
- var value = IoKit.IORegistryEntryCreateCFProperty(service, key, NULL, 0);
- if (value == NULL)
+ private USBDeviceInfo createDeviceInfo(long entryID, int service) {
+ Integer vendorId = IoKitHelper.GetPropertyInt(service, "idVendor");
+ Integer productId = IoKitHelper.GetPropertyInt(service, "idProduct");
+ String manufacturer = IoKitHelper.GetPropertyString(service, "kUSBVendorString");
+ String product = IoKitHelper.GetPropertyString(service, "kUSBProductString");
+ String serial = IoKitHelper.GetPropertyString(service, "kUSBSerialNumberString");
+ Integer classCode = IoKitHelper.GetPropertyInt(service, "bDeviceClass");
+ Integer subclassCode = IoKitHelper.GetPropertyInt(service, "bDeviceSubClass");
+ Integer protocolCode = IoKitHelper.GetPropertyInt(service, "bDeviceProtocol");
+
+ if (vendorId == null || productId == null || classCode == null || subclassCode == null || protocolCode == null)
return null;
- String result = null;
- var type = CoreFoundation.CFGetTypeID(value);
- if (type == STRING_TYPE_ID)
- result = CoreFoundation.cfStringToJavaString(value);
+ return new MacosUSBDeviceInfo(entryID, vendorId, productId, manufacturer, product, serial, classCode, subclassCode, protocolCode);
+ }
- CoreFoundation.CFRelease(value);
- return result;
+ @Override
+ public void setOnDeviceConnected(Consumer handler) {
+ if (handler == null) {
+ onDeviceConnectedHandler = null;
+ return;
+ }
+
+ onDeviceConnectedHandler = handler;
+ startDeviceMonitor();
+ }
+
+ @Override
+ public void setOnDeviceDisconnected(Consumer handler) {
+ if (handler == null) {
+ onDeviceDisconnectedHandler = null;
+ return;
+ }
+
+ onDeviceDisconnectedHandler = handler;
+ startDeviceMonitor();
}
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBException.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBException.java
new file mode 100644
index 00000000..3d59df8d
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBException.java
@@ -0,0 +1,29 @@
+//
+// Java Does USB
+// Copyright (c) 2022 Manuel Bleichenbacher
+// Licensed under MIT License
+// https://opensource.org/licenses/MIT
+//
+package net.codecrete.usb.macos;
+
+import net.codecrete.usb.USBException;
+import net.codecrete.usb.macos.gen.mach.mach;
+
+public class MacosUSBException extends USBException {
+ public MacosUSBException(String message) {
+ super(message);
+ }
+
+ public MacosUSBException(String message, int errorCode) {
+ super(String.format("%s - %s", message, machErrorMessage(errorCode)), errorCode);
+ }
+
+ public MacosUSBException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ private static String machErrorMessage(int errorCode) {
+ var msg = mach.mach_error_string(errorCode);
+ return msg.getUtf8String(0);
+ }
+}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/Constants$root.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/Constants$root.java
similarity index 94%
rename from java-does-usb/src/main/java/net/codecrete/usb/macos/gen/Constants$root.java
rename to java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/Constants$root.java
index 7697ff6a..7ac0bc7e 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/Constants$root.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/Constants$root.java
@@ -1,6 +1,6 @@
// Generated by jextract
-package net.codecrete.usb.macos.gen;
+package net.codecrete.usb.macos.gen.mach;
import static java.lang.foreign.ValueLayout.*;
public class Constants$root {
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/RuntimeHelper.java
similarity index 99%
rename from java-does-usb/src/main/java/net/codecrete/usb/macos/gen/RuntimeHelper.java
rename to java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/RuntimeHelper.java
index 9cf8e4d1..cb43e170 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/RuntimeHelper.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/RuntimeHelper.java
@@ -1,4 +1,4 @@
-package net.codecrete.usb.macos.gen;
+package net.codecrete.usb.macos.gen.mach;
// Generated by jextract
import java.lang.foreign.*;
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/constants$0.java
similarity index 54%
rename from java-does-usb/src/main/java/net/codecrete/usb/macos/gen/constants$0.java
rename to java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/constants$0.java
index 7e25031b..3d61da92 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/constants$0.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/constants$0.java
@@ -1,11 +1,18 @@
// Generated by jextract
-package net.codecrete.usb.macos.gen;
+package net.codecrete.usb.macos.gen.mach;
import java.lang.foreign.FunctionDescriptor;
import java.lang.invoke.MethodHandle;
class constants$0 {
+ static final FunctionDescriptor mach_error_string$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_INT$LAYOUT
+ );
+ static final MethodHandle mach_error_string$MH = RuntimeHelper.downcallHandle(
+ "mach_error_string",
+ constants$0.mach_error_string$FUNC
+ );
static final FunctionDescriptor mach_error$FUNC = FunctionDescriptor.ofVoid(
Constants$root.C_POINTER$LAYOUT,
Constants$root.C_INT$LAYOUT
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/mach.java
similarity index 67%
rename from java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach.java
rename to java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/mach.java
index c9d09ce1..8e162bc9 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/mach.java
@@ -1,8 +1,9 @@
// Generated by jextract
-package net.codecrete.usb.macos.gen;
+package net.codecrete.usb.macos.gen.mach;
import java.lang.foreign.Addressable;
+import java.lang.foreign.MemoryAddress;
import java.lang.invoke.MethodHandle;
import static java.lang.foreign.ValueLayout.*;
@@ -17,6 +18,17 @@ public class mach {
public static OfFloat C_FLOAT = Constants$root.C_FLOAT$LAYOUT;
public static OfDouble C_DOUBLE = Constants$root.C_DOUBLE$LAYOUT;
public static OfAddress C_POINTER = Constants$root.C_POINTER$LAYOUT;
+ public static MethodHandle mach_error_string$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.mach_error_string$MH,"mach_error_string");
+ }
+ public static MemoryAddress mach_error_string ( int error_value) {
+ var mh$ = mach_error_string$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact(error_value);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
public static MethodHandle mach_error$MH() {
return RuntimeHelper.requireNonNull(constants$0.mach_error$MH,"mach_error");
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDevice.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDevice.java
index 1b413694..a637c22e 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDevice.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDevice.java
@@ -43,16 +43,16 @@ public class WindowsUSBDevice extends USBDeviceImpl {
private List claimedInterfaces;
- WindowsUSBDevice(String path, USBDeviceInfo info, byte currentConfigurationValue) {
- super(path, info);
+ WindowsUSBDevice(Object id, USBDeviceInfo info, byte currentConfigurationValue) {
+ super(id, info);
this.currentConfigurationValue = currentConfigurationValue;
try (var session = MemorySession.openConfined()) {
// open Windows device
- var chars = path.toCharArray();
- var pathSegment = session.allocateArray(ValueLayout.JAVA_CHAR, chars.length + 1);
- pathSegment.copyFrom(MemorySegment.ofArray(chars));
+ var pathChars = id.toString().toCharArray();
+ var pathSegment = session.allocateArray(ValueLayout.JAVA_CHAR, pathChars.length + 1);
+ pathSegment.copyFrom(MemorySegment.ofArray(pathChars));
device = Kernel32.CreateFileW(pathSegment,
Kernel32.GENERIC_WRITE() | Kernel32.GENERIC_READ(),
Kernel32.FILE_SHARE_WRITE() | Kernel32.FILE_SHARE_READ(),
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceInfo.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceInfo.java
index 39c3a22b..1c0a3763 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceInfo.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceInfo.java
@@ -15,12 +15,12 @@ public class WindowsUSBDeviceInfo extends USBDeviceInfoImpl {
private final byte currentConfigurationValue;
WindowsUSBDeviceInfo(
- String path, int vendorId, int productId,
+ Object id, int vendorId, int productId,
String manufacturer, String product, String serial,
int classCode, int subclassCode, int protocolCode,
byte currentConfigurationValue) {
- super(path, vendorId, productId,
+ super(id, vendorId, productId,
manufacturer, product, serial,
classCode, subclassCode, protocolCode);
this.currentConfigurationValue = currentConfigurationValue;
@@ -28,6 +28,6 @@ public class WindowsUSBDeviceInfo extends USBDeviceInfoImpl {
@Override
public USBDevice open() {
- return new WindowsUSBDevice(path, this, currentConfigurationValue);
+ return new WindowsUSBDevice(id, this, currentConfigurationValue);
}
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
index 508d5de4..04e8586b 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
@@ -25,6 +25,7 @@
import java.lang.foreign.MemorySession;
import java.util.ArrayList;
import java.util.List;
+import java.util.function.Consumer;
import static java.lang.foreign.MemoryAddress.NULL;
import static java.lang.foreign.ValueLayout.JAVA_CHAR;
@@ -207,4 +208,12 @@ private String getStringDescriptor(Addressable hubHandle, int usbPortNumber, int
return new String(chars);
}
}
+
+ @Override
+ public void setOnDeviceConnected(Consumer handler) {
+ }
+
+ @Override
+ public void setOnDeviceDisconnected(Consumer handler) {
+ }
}
diff --git a/java-does-usb/src/test/java/net/codecrete/usb/sample/MonitorDevices.java b/java-does-usb/src/test/java/net/codecrete/usb/sample/MonitorDevices.java
new file mode 100644
index 00000000..bf1ef2ef
--- /dev/null
+++ b/java-does-usb/src/test/java/net/codecrete/usb/sample/MonitorDevices.java
@@ -0,0 +1,22 @@
+//
+// Java Does USB
+// Copyright (c) 2022 Manuel Bleichenbacher
+// Licensed under MIT License
+// https://opensource.org/licenses/MIT
+//
+
+package net.codecrete.usb.sample;
+
+import net.codecrete.usb.USB;
+import net.codecrete.usb.USBDeviceInfo;
+
+/**
+ * Sample program enumerating the connected USB devices
+ */
+public class MonitorDevices {
+
+ public static void main(String[] args) {
+ USB.setOnDeviceConnected((dev) -> System.out.println("Connected: " + dev.toString()));
+ USB.setOnDeviceDisconnected((dev) -> System.out.println("Disconnected: " + dev.toString()));
+ }
+}
From 45c6f2131055d5b740c2e0c796bb403e30620e8d Mon Sep 17 00:00:00 2001
From: Manuel Bleichenbacher
Date: Fri, 26 Aug 2022 19:35:27 +0200
Subject: [PATCH 011/433] macOS: suppress initial list of devices when
monitoring
---
.../usb/macos/MacosUSBDeviceRegistry.java | 39 +++++++++----------
.../usb/windows/WindowsUSBDeviceRegistry.java | 2 +-
.../usb/sample/EnumerateDevices.java | 2 +-
.../codecrete/usb/sample/MonitorDevices.java | 7 +++-
4 files changed, 25 insertions(+), 25 deletions(-)
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceRegistry.java
index 7ca6960f..407757dc 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceRegistry.java
@@ -28,6 +28,7 @@ public class MacosUSBDeviceRegistry implements USBDeviceRegistry {
private Consumer onDeviceConnectedHandler;
private Consumer onDeviceDisconnectedHandler;
private boolean isMonitorThreadStarted;
+ private boolean isMonitoringReady;
public List getAllDevices() {
@@ -38,7 +39,9 @@ public List getAllDevices() {
throw new RuntimeException("IORegistryGetRootEntry failed");
session.addCloseAction(() -> IoKit.IOObjectRelease(entry));
+ // create an iterator for USB devices
var iterHolder = session.allocate(JAVA_INT);
+ // TODO: passing 'entry' as the first argument does not work - why?
int ret = IoKit.IORegistryCreateIterator(0, IoKit.kIOUSBPlane, IoKit.kIORegistryIterateRecursively, iterHolder);
final var iter = iterHolder.get(JAVA_INT, 0);
if (ret != 0)
@@ -50,42 +53,34 @@ public List getAllDevices() {
}
/**
- * Return all devices of the iterator in a list
+ * Process the iterator and return a list of devices ({@link USBDeviceInfo}).
+ *
+ * @param iterator iterator
+ * @param isDisconnected flag is the iterator is for disconnected devices
+ * @return list of devices
*/
- private List iterateDevices(int iter, boolean isDisconnected) {
+ private List iterateDevices(int iterator, boolean isDisconnected) {
List result = new ArrayList<>();
int svc;
- while ((svc = IoKit.IOIteratorNext(iter)) != 0) {
+ while ((svc = IoKit.IOIteratorNext(iterator)) != 0) {
try (var session = MemorySession.openConfined()) {
final int service = svc;
session.addCloseAction(() -> IoKit.IOObjectRelease(service));
- // Test if service has user client interface (if not, it is likely a hub)
+ // test if service has user client interface (if not, it is likely a controller)
if (!isDisconnected) {
- final MemoryAddress device = IoKitHelper.GetInterface(service, IoKit.kIOUSBDeviceUserClientTypeID, IoKit.kIOUSBDeviceInterfaceID100);
+ final var device = IoKitHelper.GetInterface(service, IoKit.kIOUSBDeviceUserClientTypeID, IoKit.kIOUSBDeviceInterfaceID100);
if (device == null)
continue;
IoKit.Release(device);
}
- // Get registry path
- String path;
- var pathSegment = session.allocateArray(JAVA_BYTE, 512);
- int ret = IoKit.IORegistryEntryGetPath(service, IoKit.kIOServicePlane, pathSegment);
- if (ret == 0) {
- path = pathSegment.getUtf8String(0);
- } else if (isDisconnected) {
- path = "";
- } else {
- continue;
- }
-
- // Get entry ID
+ // get entry ID (as unique ID)
var entryIdHolder = session.allocate(JAVA_LONG);
- ret = IoKit.IORegistryEntryGetRegistryEntryID(service, entryIdHolder);
+ int ret = IoKit.IORegistryEntryGetRegistryEntryID(service, entryIdHolder);
if (ret != 0)
throw new MacosUSBException("IORegistryEntryGetRegistryEntryID failed", ret);
var entryId = entryIdHolder.get(JAVA_LONG, 0);
@@ -172,6 +167,7 @@ private void monitorDevices() {
// iterate current devices in order to arm the notifications
onDeviceDisconnected(NULL, deviceDisconnectedIter);
+ isMonitoringReady = true;
CoreFoundation.CFRunLoopRun();
} catch (NoSuchMethodException | IllegalAccessException e) {
@@ -181,7 +177,7 @@ private void monitorDevices() {
private void onDeviceConnected(MemoryAddress ignoredRefCon, int iterator) {
var devices = iterateDevices(iterator, false);
- if (onDeviceConnectedHandler == null)
+ if (onDeviceConnectedHandler == null || !isMonitoringReady)
return;
for (var device : devices)
@@ -190,7 +186,7 @@ private void onDeviceConnected(MemoryAddress ignoredRefCon, int iterator) {
private void onDeviceDisconnected(MemoryAddress ignoredRefCon, int iterator) {
var devices = iterateDevices(iterator, true);
- if (onDeviceDisconnectedHandler == null)
+ if (onDeviceDisconnectedHandler == null || !isMonitoringReady)
return;
for (var device : devices)
@@ -198,6 +194,7 @@ private void onDeviceDisconnected(MemoryAddress ignoredRefCon, int iterator) {
}
private USBDeviceInfo createDeviceInfo(long entryID, int service) {
+
Integer vendorId = IoKitHelper.GetPropertyInt(service, "idVendor");
Integer productId = IoKitHelper.GetPropertyInt(service, "idProduct");
String manufacturer = IoKitHelper.GetPropertyString(service, "kUSBVendorString");
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
index 04e8586b..e71c550a 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
@@ -65,7 +65,7 @@ public List getAllDevices() {
// get the parent device (a USB hub)
var parentDevInstHolder = session.allocate(JAVA_INT);
- int devInst = (int) _SP_DEVINFO_DATA.DevInst$get(devInfo);
+ int devInst = _SP_DEVINFO_DATA.DevInst$get(devInfo);
int cmRet = CfgMgr32.CM_Get_Parent(parentDevInstHolder, devInst, 0);
if (cmRet != 0)
throw new USBException("Internal error (CM_Get_Parent)");
diff --git a/java-does-usb/src/test/java/net/codecrete/usb/sample/EnumerateDevices.java b/java-does-usb/src/test/java/net/codecrete/usb/sample/EnumerateDevices.java
index 536044b6..c18a3b45 100644
--- a/java-does-usb/src/test/java/net/codecrete/usb/sample/EnumerateDevices.java
+++ b/java-does-usb/src/test/java/net/codecrete/usb/sample/EnumerateDevices.java
@@ -10,7 +10,7 @@
import net.codecrete.usb.USB;
/**
- * Sample program enumerating the connected USB devices
+ * Sample program displaying the connected USB devices
*/
public class EnumerateDevices {
diff --git a/java-does-usb/src/test/java/net/codecrete/usb/sample/MonitorDevices.java b/java-does-usb/src/test/java/net/codecrete/usb/sample/MonitorDevices.java
index bf1ef2ef..983c4a0a 100644
--- a/java-does-usb/src/test/java/net/codecrete/usb/sample/MonitorDevices.java
+++ b/java-does-usb/src/test/java/net/codecrete/usb/sample/MonitorDevices.java
@@ -8,14 +8,17 @@
package net.codecrete.usb.sample;
import net.codecrete.usb.USB;
-import net.codecrete.usb.USBDeviceInfo;
/**
- * Sample program enumerating the connected USB devices
+ * Sample program displaying information when USB devices are connected or disconnected.
+ *
+ * Quit with Ctrl-C or whatever stops a program on your platform.
+ *
*/
public class MonitorDevices {
public static void main(String[] args) {
+ System.out.println("Monitoring USB devices...");
USB.setOnDeviceConnected((dev) -> System.out.println("Connected: " + dev.toString()));
USB.setOnDeviceDisconnected((dev) -> System.out.println("Disconnected: " + dev.toString()));
}
From b419048a904be596121478436c0388dbc5d6c2ff Mon Sep 17 00:00:00 2001
From: Manuel Bleichenbacher
Date: Fri, 26 Aug 2022 22:26:40 +0200
Subject: [PATCH 012/433] isSameDevice() for easy comparison
---
.../java/net/codecrete/usb/USBDevice.java | 19 ++++++++
.../java/net/codecrete/usb/USBDeviceInfo.java | 23 +++++++++-
.../codecrete/usb/common/USBDeviceImpl.java | 14 +++++-
.../usb/common/USBDeviceInfoImpl.java | 15 +++++-
.../codecrete/usb/macos/MacosUSBDevice.java | 8 ++--
.../net/codecrete/usb/IsSameDeviceTest.java | 46 +++++++++++++++++++
6 files changed, 118 insertions(+), 7 deletions(-)
create mode 100644 java-does-usb/src/test/java/net/codecrete/usb/IsSameDeviceTest.java
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/USBDevice.java b/java-does-usb/src/main/java/net/codecrete/usb/USBDevice.java
index cf211508..43f37e7e 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/USBDevice.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/USBDevice.java
@@ -151,4 +151,23 @@ public interface USBDevice extends AutoCloseable {
* @return received data
*/
byte[] transferIn(int endpointNumber, int maxLength);
+
+
+ /**
+ * Returns if this instance and another {@link USBDeviceInfo} instance
+ * represent the same USB device.
+ *
+ * @param device other device instance
+ * @return {@code true} if they are the same, {@code false} otherwise
+ */
+ boolean isSameDevice(USBDeviceInfo device);
+
+ /**
+ * Returns if this instance and another {@link USBDevice} instance
+ * represent the same USB device.
+ *
+ * @param device other device info instance
+ * @return {@code true} if they are the same, {@code false} otherwise
+ */
+ boolean isSameDevice(USBDevice device);
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/USBDeviceInfo.java b/java-does-usb/src/main/java/net/codecrete/usb/USBDeviceInfo.java
index c9eac5b1..70572e34 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/USBDeviceInfo.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/USBDeviceInfo.java
@@ -19,8 +19,9 @@
* and can thus be easily handled in Java.
*
*
- * Multiple instances of the class might exist for the same USB device.
- * Use {@code equals()} to test if they refer to the same device.
+ * Multiple instances of this class might exist for the same USB device.
+ * Use {@code equals()} or {@code isSameDevice()} to test if two instances
+ * represent the same USB device.
*
*/
public interface USBDeviceInfo {
@@ -94,4 +95,22 @@ public interface USBDeviceInfo {
* @return USB device
*/
USBDevice open();
+
+ /**
+ * Returns if this instance and another {@link USBDevice} instance
+ * represent the same USB device.
+ *
+ * @param device other device instance
+ * @return {@code true} if they are the same, {@code false} otherwise
+ */
+ boolean isSameDevice(USBDevice device);
+
+ /**
+ * Returns if this instance and another {@link USBDeviceInfo} instance
+ * represent the same USB device.
+ *
+ * @param device other device info instance
+ * @return {@code true} if they are the same, {@code false} otherwise
+ */
+ boolean isSameDevice(USBDeviceInfo device);
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceImpl.java b/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceImpl.java
index a4a04ca7..833ac2d5 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceImpl.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceImpl.java
@@ -11,7 +11,6 @@
public abstract class USBDeviceImpl implements USBDevice {
-
protected final Object id;
protected final int productId;
protected final int vendorId;
@@ -111,6 +110,19 @@ protected byte[] getDescriptor(int descriptorType, int index, int language) {
return result;
}
+ @Override
+ public boolean isSameDevice(USBDeviceInfo device) {
+ if (device instanceof USBDeviceInfoImpl)
+ return id.equals(((USBDeviceInfoImpl)device).id);
+ return false;
+ }
+
+ @Override
+ public boolean isSameDevice(USBDevice device) {
+ if (device instanceof USBDeviceImpl)
+ return id.equals(((USBDeviceImpl)device).id);
+ return false;
+ }
@Override
public boolean equals(Object o) {
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceInfoImpl.java b/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceInfoImpl.java
index 0e55dca6..21f34bc0 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceInfoImpl.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceInfoImpl.java
@@ -12,7 +12,6 @@
public abstract class USBDeviceInfoImpl implements USBDeviceInfo {
-
protected final Object id;
protected final int productId;
protected final int vendorId;
@@ -88,6 +87,20 @@ public int getProtocolCode() {
return protocolCode;
}
+ @Override
+ public boolean isSameDevice(USBDeviceInfo device) {
+ if (device instanceof USBDeviceInfoImpl)
+ return id.equals(((USBDeviceInfoImpl)device).id);
+ return false;
+ }
+
+ @Override
+ public boolean isSameDevice(USBDevice device) {
+ if (device instanceof USBDeviceImpl)
+ return id.equals(((USBDeviceImpl)device).id);
+ return false;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDevice.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDevice.java
index aa4e1d8d..3153465e 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDevice.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDevice.java
@@ -294,9 +294,11 @@ public byte[] transferIn(int endpointNumber, int maxLength) {
@Override
public void close() throws Exception {
- for (InterfaceInfo interfaceInfo : claimedInterfaces) {
- IoKitUSB.USBInterfaceClose(interfaceInfo.asMemoryAddress());
- IoKit.Release(interfaceInfo.asMemoryAddress());
+ if (claimedInterfaces != null) {
+ for (InterfaceInfo interfaceInfo : claimedInterfaces) {
+ IoKitUSB.USBInterfaceClose(interfaceInfo.asMemoryAddress());
+ IoKit.Release(interfaceInfo.asMemoryAddress());
+ }
}
IoKitUSB.USBDeviceClose(device);
diff --git a/java-does-usb/src/test/java/net/codecrete/usb/IsSameDeviceTest.java b/java-does-usb/src/test/java/net/codecrete/usb/IsSameDeviceTest.java
new file mode 100644
index 00000000..f91b813d
--- /dev/null
+++ b/java-does-usb/src/test/java/net/codecrete/usb/IsSameDeviceTest.java
@@ -0,0 +1,46 @@
+//
+// Java Does USB
+// Copyright (c) 2022 Manuel Bleichenbacher
+// Licensed under MIT License
+// https://opensource.org/licenses/MIT
+//
+// Unit test for isSame()
+//
+
+package net.codecrete.usb;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class IsSameDeviceTest {
+
+ @Test
+ void getAllDevices_includesTestDevice() throws Exception {
+ var testDeviceInfo = USB.getDevice(new USBDeviceFilter(0xcafe, 0xceaf));
+ try (var testDevice = testDeviceInfo.open()) {
+ var deviceList = USB.getAllDevices();
+
+ long count = deviceList.stream().filter(testDevice::isSameDevice).count();
+ assertEquals(1, count);
+
+ count = deviceList.stream().filter((info) -> info.isSameDevice(testDevice)).count();
+ assertEquals(1, count);
+
+ count = deviceList.stream().filter(testDeviceInfo::isSameDevice).count();
+ assertEquals(1, count);
+
+ count = deviceList.stream().filter((info) -> info.isSameDevice(testDeviceInfo)).count();
+ assertEquals(1, count);
+ }
+ }
+
+ @Test
+ void openDevice_isSameAsDeviceInfo() throws Exception {
+ var testDeviceInfo = USB.getDevice(new USBDeviceFilter(0xcafe, 0xceaf));
+ try (var testDevice = testDeviceInfo.open()) {
+ assertTrue(testDevice.isSameDevice(testDeviceInfo));
+ assertTrue(testDeviceInfo.isSameDevice(testDevice));
+ }
+ }
+}
From 164a18fc215f78da1885087349126bf1970a86fd Mon Sep 17 00:00:00 2001
From: Manuel Bleichenbacher
Date: Sat, 27 Aug 2022 09:49:26 +0200
Subject: [PATCH 013/433] macOS: clean up native API wrappers
---
.../codecrete/usb/macos/CoreFoundation.java | 167 ++---
.../usb/macos/CoreFoundationHelper.java | 63 ++
.../java/net/codecrete/usb/macos/IoKit.java | 384 ++++++-----
.../net/codecrete/usb/macos/IoKitHelper.java | 2 +-
.../net/codecrete/usb/macos/IoKitUSB.java | 608 ++++++++----------
.../java/net/codecrete/usb/macos/Kernel.java | 41 --
6 files changed, 578 insertions(+), 687 deletions(-)
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/macos/CoreFoundationHelper.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/macos/Kernel.java
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/CoreFoundation.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/CoreFoundation.java
index 3f2857ae..de430987 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/CoreFoundation.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/CoreFoundation.java
@@ -11,11 +11,17 @@
import java.lang.invoke.MethodHandle;
import java.lang.invoke.VarHandle;
-import static java.lang.foreign.MemoryAddress.NULL;
import static java.lang.foreign.MemoryLayout.sequenceLayout;
import static java.lang.foreign.MemoryLayout.structLayout;
import static java.lang.foreign.ValueLayout.*;
+/**
+ * Constants and functions for the Core Foundation framework.
+ *
+ * In the future, jextract will hopefully be able to generate code for
+ * macOS frameworks in order to generate most of this.
+ *
+ */
public class CoreFoundation {
// Fixed-width types
public static final long kCFNumberSInt8Type = 1;
@@ -82,109 +88,6 @@ public class CoreFoundation {
ADDRESS, ADDRESS, CFUUIDBytes
)
);
-
- // CFStringRef CFUUIDCreateString(CFAllocatorRef alloc, CFUUIDRef uuid);
- private static final MethodHandle CFUUIDCreateString$Func = linker.downcallHandle(
- coreFoundationLookup.lookup("CFUUIDCreateString").get(),
- FunctionDescriptor.of(
- ADDRESS, ADDRESS, ADDRESS
- )
- );
-
- // void CFRelease(CFTypeRef cf);
- private static final MethodHandle CFRelease$Func = linker.downcallHandle(
- coreFoundationLookup.lookup("CFRelease").get(),
- FunctionDescriptor.ofVoid(ADDRESS)
- );
-
- // CFIndex CFStringGetLength(CFStringRef theString);
- private static final MethodHandle CFStringGetLength$Func = linker.downcallHandle(
- coreFoundationLookup.lookup("CFStringGetLength").get(),
- FunctionDescriptor.of(JAVA_LONG, ADDRESS)
- );
-
- // void CFStringGetCharacters(CFStringRef theString, CFRange range, UniChar *buffer);
- private static final MethodHandle CFStringGetCharacters$Func = linker.downcallHandle(
- coreFoundationLookup.lookup("CFStringGetCharacters").get(),
- FunctionDescriptor.ofVoid(ADDRESS, CFRange, ADDRESS)
- );
-
- // CFStringRef CFStringCreateWithCharacters(CFAllocatorRef alloc, const UniChar *chars, CFIndex numChars);
- private static final MethodHandle CFStringCreateWithCharacters$Func = linker.downcallHandle(
- coreFoundationLookup.lookup("CFStringCreateWithCharacters").get(),
- FunctionDescriptor.of(ADDRESS, ADDRESS, ADDRESS, JAVA_LONG)
- );
-
- // CFTypeID CFGetTypeID(CFTypeRef cf);
- private static final MethodHandle CFGetTypeID$Func = linker.downcallHandle(
- coreFoundationLookup.lookup("CFGetTypeID").get(),
- FunctionDescriptor.of(JAVA_LONG, ADDRESS)
- );
-
- // CFTypeID CFNumberGetTypeID(void);
- private static final MethodHandle CFNumberGetTypeID$Func = linker.downcallHandle(
- coreFoundationLookup.lookup("CFNumberGetTypeID").get(),
- FunctionDescriptor.of(JAVA_LONG)
- );
-
- // CFTypeID CFStringGetTypeID(void);
- private static final MethodHandle CFStringGetTypeID$Func = linker.downcallHandle(
- coreFoundationLookup.lookup("CFStringGetTypeID").get(),
- FunctionDescriptor.of(JAVA_LONG)
- );
-
- // CFNumberType CFNumberGetType(CFNumberRef number);
- private static final MethodHandle CFNumberGetType$Func = linker.downcallHandle(
- coreFoundationLookup.lookup("CFNumberGetType").get(),
- FunctionDescriptor.of(JAVA_LONG, ADDRESS)
- );
-
- // Boolean CFNumberGetValue(CFNumberRef number, CFNumberType theType, void *valuePtr);
- private static final MethodHandle CFNumberGetValue$Func = linker.downcallHandle(
- coreFoundationLookup.lookup("CFNumberGetValue").get(),
- FunctionDescriptor.of(JAVA_BOOLEAN, ADDRESS, JAVA_LONG, ADDRESS)
- );
- // CFRunLoopRef CFRunLoopGetCurrent(void);
- private static final MethodHandle CFRunLoopGetCurrent$Func = linker.downcallHandle(
- coreFoundationLookup.lookup("CFRunLoopGetCurrent").get(),
- FunctionDescriptor.of(ADDRESS)
- );
- // void CFRunLoopAddSource(CFRunLoopRef rl, CFRunLoopSourceRef source, CFRunLoopMode mode);
- private static final MethodHandle CFRunLoopAddSource$Func = linker.downcallHandle(
- coreFoundationLookup.lookup("CFRunLoopAddSource").get(),
- FunctionDescriptor.ofVoid(ADDRESS, ADDRESS, ADDRESS)
- );
- // void CFRunLoopRun(void);
- private static final MethodHandle CFRunLoopRun$Func = linker.downcallHandle(
- coreFoundationLookup.lookup("CFRunLoopRun").get(),
- FunctionDescriptor.ofVoid()
- );
-
-
- public static String cfStringToJavaString(MemoryAddress string) {
- try (var session = MemorySession.openConfined()) {
- long strLen = CFStringGetLength(string);
- var buffer = session.allocateArray(JAVA_CHAR, strLen);
- var range = session.allocate(CFRange);
- CFRange_location.set(range, 0);
- CFRange_range.set(range, strLen);
- CFStringGetCharacters(string, range, buffer);
- return new String(buffer.toArray(JAVA_CHAR));
- } catch (Throwable t) {
- throw new RuntimeException(t);
- }
- }
-
- public static MemoryAddress javaStringToCfString(String string) {
- try (var session = MemorySession.openConfined()) {
- char[] charArray = string.toCharArray();
- var chars = session.allocateArray(JAVA_CHAR, charArray.length);
- chars.copyFrom(MemorySegment.ofArray(charArray));
- return CFStringCreateWithCharacters(NULL, chars, string.length());
- }
- }
-
- // CFUUIDRef CFUUIDCreateFromUUIDBytes(CFAllocatorRef alloc, CFUUIDBytes bytes);
public static MemoryAddress CFUUIDCreateFromUUIDBytes(Addressable allocator, byte[] bytes) {
try (var session = MemorySession.openConfined()) {
var uuidBytes = session.allocate(16);
@@ -196,10 +99,16 @@ public static MemoryAddress CFUUIDCreateFromUUIDBytes(Addressable allocator, byt
}
// CFStringRef CFUUIDCreateString(CFAllocatorRef alloc, CFUUIDRef uuid);
+ private static final MethodHandle CFUUIDCreateString$Func = linker.downcallHandle(
+ coreFoundationLookup.lookup("CFUUIDCreateString").get(),
+ FunctionDescriptor.of(
+ ADDRESS, ADDRESS, ADDRESS
+ )
+ );
public static String CFUUIDCreateString(Addressable allocator, Addressable uuid) {
try {
MemoryAddress str = (MemoryAddress) CFUUIDCreateString$Func.invokeExact(allocator, uuid);
- String result = cfStringToJavaString(str);
+ String result = CoreFoundationHelper.stringFromCFStringRef(str);
CFRelease(str);
return result;
} catch (Throwable t) {
@@ -208,6 +117,10 @@ public static String CFUUIDCreateString(Addressable allocator, Addressable uuid)
}
// void CFRelease(CFTypeRef cf);
+ private static final MethodHandle CFRelease$Func = linker.downcallHandle(
+ coreFoundationLookup.lookup("CFRelease").get(),
+ FunctionDescriptor.ofVoid(ADDRESS)
+ );
public static void CFRelease(Addressable object) {
try {
CFRelease$Func.invokeExact(object);
@@ -217,6 +130,10 @@ public static void CFRelease(Addressable object) {
}
// CFIndex CFStringGetLength(CFStringRef theString);
+ private static final MethodHandle CFStringGetLength$Func = linker.downcallHandle(
+ coreFoundationLookup.lookup("CFStringGetLength").get(),
+ FunctionDescriptor.of(JAVA_LONG, ADDRESS)
+ );
public static long CFStringGetLength(Addressable str) {
try {
return (long) CFStringGetLength$Func.invokeExact(str);
@@ -226,6 +143,10 @@ public static long CFStringGetLength(Addressable str) {
}
// void CFStringGetCharacters(CFStringRef theString, CFRange range, UniChar *buffer);
+ private static final MethodHandle CFStringGetCharacters$Func = linker.downcallHandle(
+ coreFoundationLookup.lookup("CFStringGetCharacters").get(),
+ FunctionDescriptor.ofVoid(ADDRESS, CFRange, ADDRESS)
+ );
public static void CFStringGetCharacters(Addressable str, MemorySegment range, Addressable buffer) {
try {
CFStringGetCharacters$Func.invokeExact(str, range, buffer);
@@ -235,6 +156,10 @@ public static void CFStringGetCharacters(Addressable str, MemorySegment range, A
}
// CFStringRef CFStringCreateWithCharacters(CFAllocatorRef alloc, const UniChar *chars, CFIndex numChars);
+ private static final MethodHandle CFStringCreateWithCharacters$Func = linker.downcallHandle(
+ coreFoundationLookup.lookup("CFStringCreateWithCharacters").get(),
+ FunctionDescriptor.of(ADDRESS, ADDRESS, ADDRESS, JAVA_LONG)
+ );
public static MemoryAddress CFStringCreateWithCharacters(Addressable allocator, Addressable chars, long numChars) {
try {
return (MemoryAddress) CFStringCreateWithCharacters$Func.invokeExact(allocator, chars, numChars);
@@ -244,6 +169,10 @@ public static MemoryAddress CFStringCreateWithCharacters(Addressable allocator,
}
// CFTypeID CFGetTypeID(CFTypeRef cf);
+ private static final MethodHandle CFGetTypeID$Func = linker.downcallHandle(
+ coreFoundationLookup.lookup("CFGetTypeID").get(),
+ FunctionDescriptor.of(JAVA_LONG, ADDRESS)
+ );
public static long CFGetTypeID(Addressable cf) {
try {
return (long) CFGetTypeID$Func.invokeExact(cf);
@@ -253,6 +182,10 @@ public static long CFGetTypeID(Addressable cf) {
}
// CFTypeID CFNumberGetTypeID(void);
+ private static final MethodHandle CFNumberGetTypeID$Func = linker.downcallHandle(
+ coreFoundationLookup.lookup("CFNumberGetTypeID").get(),
+ FunctionDescriptor.of(JAVA_LONG)
+ );
public static long CFNumberGetTypeID() {
try {
return (long) CFNumberGetTypeID$Func.invokeExact();
@@ -262,6 +195,10 @@ public static long CFNumberGetTypeID() {
}
// CFTypeID CFStringGetTypeID(void);
+ private static final MethodHandle CFStringGetTypeID$Func = linker.downcallHandle(
+ coreFoundationLookup.lookup("CFStringGetTypeID").get(),
+ FunctionDescriptor.of(JAVA_LONG)
+ );
public static long CFStringGetTypeID() {
try {
return (long) CFStringGetTypeID$Func.invokeExact();
@@ -271,6 +208,10 @@ public static long CFStringGetTypeID() {
}
// CFNumberType CFNumberGetType(CFNumberRef number);
+ private static final MethodHandle CFNumberGetType$Func = linker.downcallHandle(
+ coreFoundationLookup.lookup("CFNumberGetType").get(),
+ FunctionDescriptor.of(JAVA_LONG, ADDRESS)
+ );
public static long CFNumberGetType(Addressable number) {
try {
return (long) CFNumberGetType$Func.invokeExact(number);
@@ -280,6 +221,10 @@ public static long CFNumberGetType(Addressable number) {
}
// Boolean CFNumberGetValue(CFNumberRef number, CFNumberType theType, void *valuePtr);
+ private static final MethodHandle CFNumberGetValue$Func = linker.downcallHandle(
+ coreFoundationLookup.lookup("CFNumberGetValue").get(),
+ FunctionDescriptor.of(JAVA_BOOLEAN, ADDRESS, JAVA_LONG, ADDRESS)
+ );
public static boolean CFNumberGetValue(Addressable number, long theType, Addressable valuePtr) {
try {
return (boolean) CFNumberGetValue$Func.invokeExact(number, theType, valuePtr);
@@ -289,6 +234,10 @@ public static boolean CFNumberGetValue(Addressable number, long theType, Address
}
// CFRunLoopRef CFRunLoopGetCurrent(void);
+ private static final MethodHandle CFRunLoopGetCurrent$Func = linker.downcallHandle(
+ coreFoundationLookup.lookup("CFRunLoopGetCurrent").get(),
+ FunctionDescriptor.of(ADDRESS)
+ );
public static MemoryAddress CFRunLoopGetCurrent() {
try {
return (MemoryAddress) CFRunLoopGetCurrent$Func.invokeExact();
@@ -298,6 +247,10 @@ public static MemoryAddress CFRunLoopGetCurrent() {
}
// void CFRunLoopAddSource(CFRunLoopRef rl, CFRunLoopSourceRef source, CFRunLoopMode mode);
+ private static final MethodHandle CFRunLoopAddSource$Func = linker.downcallHandle(
+ coreFoundationLookup.lookup("CFRunLoopAddSource").get(),
+ FunctionDescriptor.ofVoid(ADDRESS, ADDRESS, ADDRESS)
+ );
public static void CFRunLoopAddSource(Addressable runLoop, Addressable source, Addressable mode) {
try {
CFRunLoopAddSource$Func.invokeExact(runLoop, source, mode);
@@ -307,6 +260,10 @@ public static void CFRunLoopAddSource(Addressable runLoop, Addressable source, A
}
// void CFRunLoopRun(void);
+ private static final MethodHandle CFRunLoopRun$Func = linker.downcallHandle(
+ coreFoundationLookup.lookup("CFRunLoopRun").get(),
+ FunctionDescriptor.ofVoid()
+ );
public static void CFRunLoopRun() {
try {
CFRunLoopRun$Func.invokeExact();
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/CoreFoundationHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/CoreFoundationHelper.java
new file mode 100644
index 00000000..b589abdd
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/CoreFoundationHelper.java
@@ -0,0 +1,63 @@
+//
+// Java Does USB
+// Copyright (c) 2022 Manuel Bleichenbacher
+// Licensed under MIT License
+// https://opensource.org/licenses/MIT
+//
+
+package net.codecrete.usb.macos;
+
+import java.lang.foreign.MemoryAddress;
+import java.lang.foreign.MemorySegment;
+import java.lang.foreign.MemorySession;
+
+import static java.lang.foreign.MemoryAddress.NULL;
+import static java.lang.foreign.ValueLayout.JAVA_CHAR;
+
+/**
+ * Core Foundation helper functions
+ */
+public class CoreFoundationHelper {
+
+ /**
+ * Gets Java string as a copy of the {@code CFStringRef}.
+ *
+ * @param string the string to copy ({@code CFStringRef})
+ * @return copied string
+ */
+ public static String stringFromCFStringRef(MemoryAddress string) {
+
+ try (var session = MemorySession.openConfined()) {
+
+ long strLen = CoreFoundation.CFStringGetLength(string);
+ var buffer = session.allocateArray(JAVA_CHAR, strLen);
+ var range = session.allocate(CoreFoundation.CFRange);
+ CoreFoundation.CFRange_location.set(range, 0);
+ CoreFoundation.CFRange_range.set(range, strLen);
+ CoreFoundation.CFStringGetCharacters(string, range, buffer);
+ return new String(buffer.toArray(JAVA_CHAR));
+
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
+ }
+ }
+
+ /**
+ * Creates a {@code CFStringRef} with a copy of the specified string
+ *
+ * Ownership follows the Create Rule, i.e. the caller takes
+ * ownership without incrementing the reference count.
+ *
+ *
+ * @param string the string
+ * @return {@code CFStringRef}
+ */
+ public static MemoryAddress createCFStringRef(String string) {
+ try (var session = MemorySession.openConfined()) {
+ char[] charArray = string.toCharArray();
+ var chars = session.allocateArray(JAVA_CHAR, charArray.length);
+ chars.copyFrom(MemorySegment.ofArray(charArray));
+ return CoreFoundation.CFStringCreateWithCharacters(NULL, chars, string.length());
+ }
+ }
+}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKit.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKit.java
index 7d8dc238..c386f077 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKit.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKit.java
@@ -15,8 +15,15 @@
import static java.lang.foreign.MemoryLayout.PathElement.groupElement;
import static java.lang.foreign.ValueLayout.*;
import static net.codecrete.usb.macos.CoreFoundation.CFUUIDBytes;
-import static net.codecrete.usb.macos.CoreFoundation.javaStringToCfString;
-
+import static net.codecrete.usb.macos.CoreFoundationHelper.createCFStringRef;
+
+/**
+ * Constants and functions for the IOKit framework.
+ *
+ * In the future, jextract will hopefully be able to generate code for
+ * macOS frameworks in order to generate most of this.
+ *
+ */
public class IoKit {
private static final Linker linker = Linker.nativeLinker();
@@ -26,6 +33,15 @@ public class IoKit {
public static final Addressable kIOUSBPlane = ioKitSession.allocateUtf8String("IOUSB");
public static final Addressable kIOServicePlane = ioKitSession.allocateUtf8String("IOService");
+ public static final int kIOMasterPortDefault;
+ public static final int kIORegistryIterateRecursively = 1;
+
+ public static final MemorySegment kIOUSBDeviceClassName = ioKitSession.allocateUtf8String("IOUSBDevice");
+ public static final MemorySegment kIOFirstMatchNotification = ioKitSession.allocateUtf8String("IOServiceFirstMatch");
+ public static final MemorySegment kIOTerminatedNotification = ioKitSession.allocateUtf8String("IOServiceTerminate");
+
+ public static final MemoryAddress kCFRunLoopDefaultMode = createCFStringRef("kCFRunLoopDefaultMode");
+
public static final GroupLayout IOCFPlugInInterface$Struct = MemoryLayout.structLayout(
ADDRESS.withName("_reserved"), // void *_reserved;
ADDRESS.withName("QueryInterface"), // HRESULT (STDMETHODCALLTYPE *QueryInterface)(void *thisPointer, REFIID iid, LPVOID *ppv);
@@ -38,114 +54,261 @@ public class IoKit {
ADDRESS.withName("Stop") // IOReturn (*Stop)(void *thisPointer);
);
- private static final VarHandle IUnknown_QueryInterface = IOCFPlugInInterface$Struct.varHandle(groupElement("QueryInterface"));
- private static final VarHandle IUnknown_AddRef = IOCFPlugInInterface$Struct.varHandle(groupElement("AddRef"));
- private static final VarHandle IUnknown_Release = IOCFPlugInInterface$Struct.varHandle(groupElement("Release"));
+ /**
+ * Looks up the address of the specified virtual function in the {@code IOCFPlugInInterface} object
+ * @param thisPointer pointer to pointer to object
+ * @param varHandle variable handle to virtual function
+ * @param session memory session
+ * @return function address
+ */
+ private static Addressable IOCFPlugInInterfaceFunctionAddress(MemoryAddress thisPointer, VarHandle varHandle, MemorySession session) {
+ var seg = MemorySegment.ofAddress(thisPointer, ADDRESS.byteSize(), session);
+ var thisValue = seg.get(ADDRESS, 0);
+ var obj = MemorySegment.ofAddress(thisValue, IOCFPlugInInterface$Struct.byteSize(), session);
+ return (MemoryAddress) varHandle.get(obj);
+ }
// HRESULT (STDMETHODCALLTYPE *QueryInterface)(void *thisPointer, REFIID iid, LPVOID *ppv);
+ private static final VarHandle IUnknown_QueryInterface = IOCFPlugInInterface$Struct.varHandle(groupElement("QueryInterface"));
private static final MethodHandle QueryInterface$Func = linker.downcallHandle(
FunctionDescriptor.of(JAVA_INT, ADDRESS, CFUUIDBytes, ADDRESS)
);
+ public static int QueryInterface(MemoryAddress thisPointer, MemorySegment iid, Addressable ppv) {
+ try (var session = MemorySession.openShared()) {
+ var funcPtr = IOCFPlugInInterfaceFunctionAddress(thisPointer, IUnknown_QueryInterface, session);
+ return (int) QueryInterface$Func.invokeExact(funcPtr, (Addressable) thisPointer, iid, ppv);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
// ULONG (STDMETHODCALLTYPE *AddRef)(void *thisPointer);
+ private static final VarHandle IUnknown_AddRef = IOCFPlugInInterface$Struct.varHandle(groupElement("AddRef"));
private static final MethodHandle AddRef$Func = linker.downcallHandle(
FunctionDescriptor.of(JAVA_INT, ADDRESS)
);
+ public static int AddRef(MemoryAddress thisPointer) {
+ try (var session = MemorySession.openShared()) {
+ var funcPtr = IOCFPlugInInterfaceFunctionAddress(thisPointer, IUnknown_AddRef, session);
+ return (int) AddRef$Func.invokeExact(funcPtr, (Addressable) thisPointer);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
// ULONG (STDMETHODCALLTYPE *Release)(void *thisPointer);
+ private static final VarHandle IUnknown_Release = IOCFPlugInInterface$Struct.varHandle(groupElement("Release"));
private static final MethodHandle Release$Func = linker.downcallHandle(
FunctionDescriptor.of(JAVA_INT, ADDRESS)
);
+ public static int Release(MemoryAddress thisPointer) {
+ try (var session = MemorySession.openShared()) {
+ var funcPtr = IOCFPlugInInterfaceFunctionAddress(thisPointer, IUnknown_Release, session);
+ return (int) Release$Func.invokeExact(funcPtr, (Addressable) thisPointer);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
// io_registry_entry_t IORegistryGetRootEntry(mach_port_t mainPort);
private static final MethodHandle IORegistryGetRootEntry$Func = linker.downcallHandle(
ioKitLookup.lookup("IORegistryGetRootEntry").get(),
FunctionDescriptor.of(JAVA_INT, JAVA_INT)
);
+ public static int IORegistryGetRootEntry(int mainPort) {
+ try {
+ return (int) IORegistryGetRootEntry$Func.invokeExact(mainPort);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
// kern_return_t IOObjectRelease(io_object_t object);
private static final MethodHandle IOObjectRelease$Func = linker.downcallHandle(
ioKitLookup.lookup("IOObjectRelease").get(),
FunctionDescriptor.of(JAVA_INT, JAVA_INT)
);
+ public static int IOObjectRelease(int object) {
+ try {
+ return (int) IOObjectRelease$Func.invokeExact(object);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
// kern_return_t IORegistryEntryCreateIterator(io_registry_entry_t entry, const io_name_t plane, IOOptionBits options, io_iterator_t *iterator);
private static final MethodHandle IORegistryCreateIterator$Func = linker.downcallHandle(
ioKitLookup.lookup("IORegistryCreateIterator").get(),
FunctionDescriptor.of(JAVA_INT, JAVA_INT, ADDRESS, JAVA_INT, ADDRESS)
);
+ public static int IORegistryCreateIterator(int entry, Addressable plane, int options, Addressable iterator) {
+ try {
+ return (int) IORegistryCreateIterator$Func.invokeExact(entry, plane, options, iterator);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
// io_object_t IOIteratorNext(io_iterator_t iterator);
private static final MethodHandle IOIteratorNext$Func = linker.downcallHandle(
ioKitLookup.lookup("IOIteratorNext").get(),
FunctionDescriptor.of(JAVA_INT, JAVA_INT)
);
+ public static int IOIteratorNext(int iter) {
+ try {
+ return (int) IOIteratorNext$Func.invokeExact(iter);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
// kern_return_t IORegistryEntryGetPath(io_registry_entry_t entry, const io_name_t plane, io_string_t path);
private static final MethodHandle IORegistryEntryGetPath$Func = linker.downcallHandle(
ioKitLookup.lookup("IORegistryEntryGetPath").get(),
FunctionDescriptor.of(JAVA_INT, JAVA_INT, ADDRESS, ADDRESS)
);
-
- // CFTypeRef IORegistryEntryCreateCFProperty(io_registry_entry_t entry, CFStringRef key, CFAllocatorRef allocator, IOOptionBits options);
- private static final MethodHandle IORegistryEntryCreateCFProperty$Func = linker.downcallHandle(
- ioKitLookup.lookup("IORegistryEntryCreateCFProperty").get(),
- FunctionDescriptor.of(ADDRESS, JAVA_INT, ADDRESS, ADDRESS, JAVA_INT)
- );
+ public static int IORegistryEntryGetPath(int entry, Addressable plane, Addressable path) {
+ try {
+ return (int) IORegistryEntryGetPath$Func.invokeExact(entry, plane, path);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
// kern_return_t IOCreatePlugInInterfaceForService(io_service_t service, CFUUIDRef pluginType, CFUUIDRef interfaceType, IOCFPlugInInterface ***theInterface, SInt32 *theScore);
private static final MethodHandle IOCreatePlugInInterfaceForService$Func = linker.downcallHandle(
ioKitLookup.lookup("IOCreatePlugInInterfaceForService").get(),
FunctionDescriptor.of(JAVA_INT, JAVA_INT, ADDRESS, ADDRESS, ADDRESS, ADDRESS)
);
+ public static int IOCreatePlugInInterfaceForService(int service, Addressable pluginType, Addressable interfaceType, Addressable intf, Addressable score) {
+ try {
+ return (int) IOCreatePlugInInterfaceForService$Func.invokeExact(service, pluginType, interfaceType, intf, score);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ // CFTypeRef IORegistryEntryCreateCFProperty(io_registry_entry_t entry, CFStringRef key, CFAllocatorRef allocator, IOOptionBits options);
+ private static final MethodHandle IORegistryEntryCreateCFProperty$Func = linker.downcallHandle(
+ ioKitLookup.lookup("IORegistryEntryCreateCFProperty").get(),
+ FunctionDescriptor.of(ADDRESS, JAVA_INT, ADDRESS, ADDRESS, JAVA_INT)
+ );
+ public static MemoryAddress IORegistryEntryCreateCFProperty(int entry, String key, Addressable allocator, int options) {
+ try {
+ var keyStr = CoreFoundationHelper.createCFStringRef(key);
+ var propValue = (MemoryAddress) IORegistryEntryCreateCFProperty$Func.invokeExact(entry, (Addressable) keyStr, allocator, options);
+ CoreFoundation.CFRelease(keyStr);
+ return propValue;
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
// io_registry_entry_t IORegistryEntryFromPath(mach_port_t mainPort, const io_string_t path);
private static final MethodHandle IORegistryEntryFromPath$Func = linker.downcallHandle(
ioKitLookup.lookup("IORegistryEntryFromPath").get(),
FunctionDescriptor.of(JAVA_INT, JAVA_INT, ADDRESS)
);
+ public static int IORegistryEntryFromPath(int mainPort, String path) {
+ try (var session = MemorySession.openConfined()) {
+ var pathCStr = session.allocateUtf8String(path);
+ return (int) IORegistryEntryFromPath$Func.invokeExact(mainPort, (Addressable) pathCStr);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
// IONotificationPortRef IONotificationPortCreate(mach_port_t mainPort);
private static final MethodHandle IONotificationPortCreate$Func = linker.downcallHandle(
ioKitLookup.lookup("IONotificationPortCreate").get(),
FunctionDescriptor.of(ADDRESS, JAVA_INT)
);
+ public static MemoryAddress IONotificationPortCreate(int mainPort) {
+ try {
+ return (MemoryAddress) IONotificationPortCreate$Func.invokeExact(mainPort);
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
+ }
+ }
// CFRunLoopSourceRef IONotificationPortGetRunLoopSource(IONotificationPortRef notify);
private static final MethodHandle IONotificationPortGetRunLoopSource$Func = linker.downcallHandle(
ioKitLookup.lookup("IONotificationPortGetRunLoopSource").get(),
FunctionDescriptor.of(ADDRESS, ADDRESS)
);
+ public static MemoryAddress IONotificationPortGetRunLoopSource(Addressable notify) {
+ try {
+ return (MemoryAddress) IONotificationPortGetRunLoopSource$Func.invokeExact(notify);
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
+ }
+ }
// io_service_t IOServiceGetMatchingService(mach_port_t mainPort, CFDictionaryRef matching);
private static final MethodHandle IOServiceGetMatchingService$Func = linker.downcallHandle(
ioKitLookup.lookup("IOServiceGetMatchingService").get(),
FunctionDescriptor.of(JAVA_INT, JAVA_INT, ADDRESS)
);
+ public static int IOServiceGetMatchingService(int mainPort, Addressable matching) {
+ try {
+ return (int) IOServiceGetMatchingService$Func.invokeExact(mainPort, matching);
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
+ }
+ }
+
+ // kern_return_t IORegistryEntryGetRegistryEntryID(io_registry_entry_t entry, uint64_t *entryID);
+ private static final MethodHandle IORegistryEntryGetRegistryEntryID$Func = linker.downcallHandle(
+ ioKitLookup.lookup("IORegistryEntryGetRegistryEntryID").get(),
+ FunctionDescriptor.of(JAVA_INT, JAVA_INT, ADDRESS)
+ );
+
+ public static int IORegistryEntryGetRegistryEntryID(int entry, Addressable entryIdHolder) {
+ try {
+ return (int) IORegistryEntryGetRegistryEntryID$Func.invokeExact(entry, entryIdHolder);
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
+ }
+ }
// kern_return_t IOServiceAddMatchingNotification(IONotificationPortRef notifyPort, const io_name_t notificationType, CFDictionaryRef matching, IOServiceMatchingCallback callback, void *refCon, io_iterator_t *notification);
private static final MethodHandle IOServiceAddMatchingNotification$Func = linker.downcallHandle(
ioKitLookup.lookup("IOServiceAddMatchingNotification").get(),
FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS, ADDRESS, ADDRESS, ADDRESS, ADDRESS)
);
+ public static int IOServiceAddMatchingNotification(Addressable notifyPort, Addressable notificationType, Addressable matching, Addressable callback, Addressable refCon, Addressable notificationHolder) {
+ try {
+ return (int) IOServiceAddMatchingNotification$Func.invokeExact(notifyPort, notificationType, matching, callback, refCon, notificationHolder);
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
+ }
+ }
// CFMutableDictionaryRef IOServiceMatching(const char *name);
private static final MethodHandle IOServiceMatching$Func = linker.downcallHandle(
ioKitLookup.lookup("IOServiceMatching").get(),
FunctionDescriptor.of(ADDRESS, ADDRESS)
);
+ public static MemoryAddress IOServiceMatching(Addressable name) {
+ try {
+ return (MemoryAddress) IOServiceMatching$Func.invokeExact(name);
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
+ }
+ }
// CFMutableDictionaryRef IORegistryEntryIDMatching(uint64_t entryID);
private static final MethodHandle IORegistryEntryIDMatching$Func = linker.downcallHandle(
ioKitLookup.lookup("IORegistryEntryIDMatching").get(),
FunctionDescriptor.of(ADDRESS, JAVA_LONG)
);
-
- // kern_return_t IORegistryEntryGetRegistryEntryID(io_registry_entry_t entry, uint64_t *entryID);
- private static final MethodHandle IORegistryEntryGetRegistryEntryID$Func = linker.downcallHandle(
- ioKitLookup.lookup("IORegistryEntryGetRegistryEntryID").get(),
- FunctionDescriptor.of(JAVA_INT, JAVA_INT, ADDRESS)
- );
+ public static MemoryAddress IORegistryEntryIDMatching(long entryID) {
+ try {
+ return (MemoryAddress) IORegistryEntryIDMatching$Func.invokeExact(entryID);
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
+ }
+ }
public static final MemoryAddress kIOUSBDeviceUserClientTypeID = CoreFoundation.CFUUIDCreateFromUUIDBytes(
NULL,
@@ -191,15 +354,6 @@ public class IoKit {
(byte) 0x91, (byte) 0xD4, (byte) 0x00, (byte) 0x50,
(byte) 0xE4, (byte) 0xC6, (byte) 0x42, (byte) 0x6F
});
- public static final int kIOMasterPortDefault;
- public static final int kIORegistryIterateRecursively = 1;
-
- public static final MemorySegment kIOUSBDeviceClassName = ioKitSession.allocateUtf8String("IOUSBDevice");
- public static final MemorySegment kIOFirstMatchNotification = ioKitSession.allocateUtf8String("IOServiceFirstMatch");
- public static final MemorySegment kIOTerminatedNotification = ioKitSession.allocateUtf8String("IOServiceTerminate");
-
-
- public static final MemoryAddress kCFRunLoopDefaultMode = javaStringToCfString("kCFRunLoopDefaultMode");
static {
try (var session = MemorySession.openConfined()) {
@@ -207,182 +361,4 @@ public class IoKit {
kIOMasterPortDefault = MemorySegment.ofAddress(kIOMasterPortDefaultAddress, 4, session).get(JAVA_INT, 0);
}
}
-
- // io_registry_entry_t IORegistryGetRootEntry(mach_port_t mainPort);
- public static int IORegistryGetRootEntry(int mainPort) {
- try {
- return (int) IORegistryGetRootEntry$Func.invokeExact(mainPort);
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- // kern_return_t IOObjectRelease(io_object_t object);
- public static int IOObjectRelease(int object) {
- try {
- return (int) IOObjectRelease$Func.invokeExact(object);
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- // kern_return_t IORegistryEntryCreateIterator(io_registry_entry_t entry, const io_name_t plane, IOOptionBits options, io_iterator_t *iterator);
- public static int IORegistryCreateIterator(int entry, Addressable plane, int options, Addressable iterator) {
- try {
- return (int) IORegistryCreateIterator$Func.invokeExact(entry, plane, options, iterator);
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- // io_object_t IOIteratorNext(io_iterator_t iterator);
- public static int IOIteratorNext(int iter) {
- try {
- return (int) IOIteratorNext$Func.invokeExact(iter);
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- // CFTypeRef IORegistryEntryCreateCFProperty(io_registry_entry_t entry, CFStringRef key, CFAllocatorRef allocator, IOOptionBits options);
- public static MemoryAddress IORegistryEntryCreateCFProperty(int entry, String key, Addressable allocator, int options) {
- try {
- var keyStr = CoreFoundation.javaStringToCfString(key);
- var propValue = (MemoryAddress) IORegistryEntryCreateCFProperty$Func.invokeExact(entry, (Addressable) keyStr, allocator, options);
- CoreFoundation.CFRelease(keyStr);
- return propValue;
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- // kern_return_t IORegistryEntryGetPath(io_registry_entry_t entry, const io_name_t plane, io_string_t path);
- public static int IORegistryEntryGetPath(int entry, Addressable plane, Addressable path) {
- try {
- return (int) IORegistryEntryGetPath$Func.invokeExact(entry, plane, path);
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- // kern_return_t IOCreatePlugInInterfaceForService(io_service_t service, CFUUIDRef pluginType, CFUUIDRef interfaceType, IOCFPlugInInterface ***theInterface, SInt32 *theScore);
- public static int IOCreatePlugInInterfaceForService(int service, Addressable pluginType, Addressable interfaceType, Addressable intf, Addressable score) {
- try {
- return (int) IOCreatePlugInInterfaceForService$Func.invokeExact(service, pluginType, interfaceType, intf, score);
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- // io_registry_entry_t IORegistryEntryFromPath(mach_port_t mainPort, const io_string_t path);
- public static int IORegistryEntryFromPath(int mainPort, String path) {
- try (var session = MemorySession.openConfined()) {
- var pathCStr = session.allocateUtf8String(path);
- return (int) IORegistryEntryFromPath$Func.invokeExact(mainPort, (Addressable) pathCStr);
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- private static Addressable IOCFPlugInInterface$VirtFunc(MemoryAddress thisPointer, VarHandle varHandle, MemorySession session) {
- var seg = MemorySegment.ofAddress(thisPointer, ADDRESS.byteSize(), session);
- var thisValue = seg.get(ADDRESS, 0);
- var obj = MemorySegment.ofAddress(thisValue, IOCFPlugInInterface$Struct.byteSize(), session);
- return (MemoryAddress) varHandle.get(obj);
- }
-
- // IONotificationPortRef IONotificationPortCreate(mach_port_t mainPort);
- public static MemoryAddress IONotificationPortCreate(int mainPort) {
- try {
- return (MemoryAddress) IONotificationPortCreate$Func.invokeExact(mainPort);
- } catch (Throwable t) {
- throw new RuntimeException(t);
- }
- }
-
- // CFRunLoopSourceRef IONotificationPortGetRunLoopSource(IONotificationPortRef notify);
- public static MemoryAddress IONotificationPortGetRunLoopSource(Addressable notify) {
- try {
- return (MemoryAddress) IONotificationPortGetRunLoopSource$Func.invokeExact(notify);
- } catch (Throwable t) {
- throw new RuntimeException(t);
- }
- }
-
- // kern_return_t IOServiceAddMatchingNotification(IONotificationPortRef notifyPort, const io_name_t notificationType, CFDictionaryRef matching, IOServiceMatchingCallback callback, void *refCon, io_iterator_t *notification);
- public static int IOServiceAddMatchingNotification(Addressable notifyPort, Addressable notificationType, Addressable matching, Addressable callback, Addressable refCon, Addressable notificationHolder) {
- try {
- return (int) IOServiceAddMatchingNotification$Func.invokeExact(notifyPort, notificationType, matching, callback, refCon, notificationHolder);
- } catch (Throwable t) {
- throw new RuntimeException(t);
- }
- }
-
- // CFMutableDictionaryRef IOServiceMatching(const char *name);
- public static MemoryAddress IOServiceMatching(Addressable name) {
- try {
- return (MemoryAddress) IOServiceMatching$Func.invokeExact(name);
- } catch (Throwable t) {
- throw new RuntimeException(t);
- }
- }
-
- // CFMutableDictionaryRef IORegistryEntryIDMatching(uint64_t entryID);
- public static MemoryAddress IORegistryEntryIDMatching(long entryID) {
- try {
- return (MemoryAddress) IORegistryEntryIDMatching$Func.invokeExact(entryID);
- } catch (Throwable t) {
- throw new RuntimeException(t);
- }
- }
-
- // io_service_t IOServiceGetMatchingService(mach_port_t mainPort, CFDictionaryRef matching);
- public static int IOServiceGetMatchingService(int mainPort, Addressable matching) {
- try {
- return (int) IOServiceGetMatchingService$Func.invokeExact(mainPort, matching);
- } catch (Throwable t) {
- throw new RuntimeException(t);
- }
- }
-
- // kern_return_t IORegistryEntryGetRegistryEntryID(io_registry_entry_t entry, uint64_t *entryID);
- public static int IORegistryEntryGetRegistryEntryID(int entry, Addressable entryIdHolder) {
- try {
- return (int) IORegistryEntryGetRegistryEntryID$Func.invokeExact(entry, entryIdHolder);
- } catch (Throwable t) {
- throw new RuntimeException(t);
- }
- }
-
-
- // HRESULT (STDMETHODCALLTYPE *QueryInterface)(void *thisPointer, REFIID iid, LPVOID *ppv);
- public static int QueryInterface(MemoryAddress thisPointer, MemorySegment iid, Addressable ppv) {
- try (var session = MemorySession.openShared()) {
- var funcPtr = IOCFPlugInInterface$VirtFunc(thisPointer, IUnknown_QueryInterface, session);
- return (int) QueryInterface$Func.invokeExact(funcPtr, (Addressable) thisPointer, iid, ppv);
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- // ULONG (STDMETHODCALLTYPE *AddRef)(void *thisPointer);
- public static int AddRef(MemoryAddress thisPointer) {
- try (var session = MemorySession.openShared()) {
- var funcPtr = IOCFPlugInInterface$VirtFunc(thisPointer, IUnknown_AddRef, session);
- return (int) AddRef$Func.invokeExact(funcPtr, (Addressable) thisPointer);
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- // ULONG (STDMETHODCALLTYPE *Release)(void *thisPointer);
- public static int Release(MemoryAddress thisPointer) {
- try (var session = MemorySession.openShared()) {
- var funcPtr = IOCFPlugInInterface$VirtFunc(thisPointer, IUnknown_Release, session);
- return (int) Release$Func.invokeExact(funcPtr, (Addressable) thisPointer);
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKitHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKitHelper.java
index 513b1d1f..124f17e1 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKitHelper.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKitHelper.java
@@ -110,7 +110,7 @@ public static String GetPropertyString(int service, String key) {
String result = null;
var type = CoreFoundation.CFGetTypeID(value);
if (type == STRING_TYPE_ID)
- result = CoreFoundation.cfStringToJavaString(value);
+ result = CoreFoundationHelper.stringFromCFStringRef(value);
CoreFoundation.CFRelease(value);
return result;
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKitUSB.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKitUSB.java
index 99436446..2d6fa7a1 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKitUSB.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKitUSB.java
@@ -15,327 +15,95 @@
import static java.lang.foreign.MemoryLayout.structLayout;
import static java.lang.foreign.ValueLayout.*;
+/**
+ * Constants and functions for the USB specifict parts of IOKit framework.
+ *
+ * In the future, jextract will hopefully be able to generate code for
+ * macOS frameworks in order to generate most of this.
+ *
+ */
public class IoKitUSB {
+ private static final Linker linker = Linker.nativeLinker();
public static final short kIOUSBFindInterfaceDontCare = (short) 0xFFFF;
- public static final GroupLayout IOUSBFindInterfaceRequest$Struct;
- public static final VarHandle IOUSBFindInterfaceRequest_bInterfaceClass;
- public static final VarHandle IOUSBFindInterfaceRequest_bInterfaceSubClass;
- public static final VarHandle IOUSBFindInterfaceRequest_bInterfaceProtocol;
- public static final VarHandle IOUSBFindInterfaceRequest_bAlternateSetting;
-
- private static final GroupLayout IOUSBDevice$Struct;
-
- private static final VarHandle IOUSBDevice_USBDeviceOpen;
- private static final VarHandle IOUSBDevice_USBDeviceClose;
- private static final VarHandle IOUSBDevice_SetConfiguration;
- private static final VarHandle IOUSBDevice_GetConfigurationDescriptorPtr;
- private static final VarHandle IOUSBDevice_GetNumberOfConfigurations;
- private static final VarHandle IOUSBDevice_CreateInterfaceIterator;
- private static final VarHandle IOUSBDevice_DeviceRequest;
-
- private static final MethodHandle USBDeviceOpen$Func;
- private static final MethodHandle USBDeviceClose$Func;
- private static final MethodHandle SetConfiguration$Func;
- private static final MethodHandle GetConfigurationDescriptorPtr$Func;
- private static final MethodHandle GetNumberOfConfigurations$Func;
- private static final MethodHandle CreateInterfaceIterator$Func;
- private static final MethodHandle DeviceRequest$Func;
-
- private static final GroupLayout IOUSBInterface$Struct;
-
- private static final VarHandle IOUSBInterface_USBInterfaceOpen;
- private static final VarHandle IOUSBInterface_USBInterfaceClose;
- private static final VarHandle IOUSBInterface_GetInterfaceNumber;
- private static final VarHandle IOUSBInterface_GetNumEndpoints;
- private static final VarHandle IOUSBInterface_GetPipeProperties;
- private static final VarHandle IOUSBInterface_ReadPipe;
- private static final VarHandle IOUSBInterface_WritePipe;
-
- private static final MethodHandle USBInterfaceOpen$Func;
- private static final MethodHandle USBInterfaceClose$Func;
- private static final MethodHandle GetInterfaceNumber$Func;
- private static final MethodHandle GetNumEndpoints$Func;
- private static final MethodHandle GetPipeProperties$Func;
- private static final MethodHandle ReadPipe$Func;
- private static final MethodHandle WritePipe$Func;
-
- public static final GroupLayout IOUSBDevRequest$Struct;
- public static final VarHandle IOUSBDevRequest_bmRequestType;
- public static final VarHandle IOUSBDevRequest_bRequest;
- public static final VarHandle IOUSBDevRequest_wValue;
- public static final VarHandle IOUSBDevRequest_wIndex;
- public static final VarHandle IOUSBDevRequest_wLength;
- public static final VarHandle IOUSBDevRequest_pData;
- public static final VarHandle IOUSBDevRequest_wLenDone;
-
-
- static {
- var linker = Linker.nativeLinker();
-
- // typedef struct {
- // UInt16 bInterfaceClass; // requested class
- // UInt16 bInterfaceSubClass; // requested subclass
- // UInt16 bInterfaceProtocol; // requested protocol
- // UInt16 bAlternateSetting; // requested alt setting
- // } IOUSBFindInterfaceRequest;
- IOUSBFindInterfaceRequest$Struct = structLayout(
- JAVA_SHORT.withName("bInterfaceClass"),
- JAVA_SHORT.withName("bInterfaceSubClass"),
- JAVA_SHORT.withName("bInterfaceProtocol"),
- JAVA_SHORT.withName("bAlternateSetting")
- );
-
- IOUSBFindInterfaceRequest_bInterfaceClass = IOUSBFindInterfaceRequest$Struct.varHandle(groupElement("bInterfaceClass"));
- IOUSBFindInterfaceRequest_bInterfaceSubClass = IOUSBFindInterfaceRequest$Struct.varHandle(groupElement("bInterfaceSubClass"));
- IOUSBFindInterfaceRequest_bInterfaceProtocol = IOUSBFindInterfaceRequest$Struct.varHandle(groupElement("bInterfaceProtocol"));
- IOUSBFindInterfaceRequest_bAlternateSetting = IOUSBFindInterfaceRequest$Struct.varHandle(groupElement("bAlternateSetting"));
-
- IOUSBDevice$Struct = structLayout(
- ADDRESS.withName("_reserved"), // void *_reserved;
- ADDRESS.withName("QueryInterface"), // HRESULT (STDMETHODCALLTYPE *QueryInterface)(void *thisPointer, REFIID iid, LPVOID *ppv);
- ADDRESS.withName("AddRef"), // ULONG (STDMETHODCALLTYPE *AddRef)(void *thisPointer);
- ADDRESS.withName("Release"), // ULONG (STDMETHODCALLTYPE *Release)(void *thisPointer);
- ADDRESS.withName("CreateDeviceAsyncEventSource"), // IOReturn (*CreateDeviceAsyncEventSource)(void *self, CFRunLoopSourceRef *source);
- ADDRESS.withName("GetDeviceAsyncEventSource"), // CFRunLoopSourceRef (*GetDeviceAsyncEventSource)(void *self);
- ADDRESS.withName("CreateDeviceAsyncPort"), // IOReturn (*CreateDeviceAsyncPort)(void *self, mach_port_t *port);
- ADDRESS.withName("GetDeviceAsyncPort"), // mach_port_t (*GetDeviceAsyncPort)(void *self);
- ADDRESS.withName("USBDeviceOpen"), // IOReturn (*USBDeviceOpen)(void *self);
- ADDRESS.withName("USBDeviceClose"), // IOReturn (*USBDeviceClose)(void *self);
- ADDRESS.withName("GetDeviceClass"), // IOReturn (*GetDeviceClass)(void *self, UInt8 *devClass);
- ADDRESS.withName("GetDeviceSubClass"), // IOReturn (*GetDeviceSubClass)(void *self, UInt8 *devSubClass);
- ADDRESS.withName("GetDeviceProtocol"), // IOReturn (*GetDeviceProtocol)(void *self, UInt8 *devProtocol);
- ADDRESS.withName("GetDeviceVendor"), // IOReturn (*GetDeviceVendor)(void *self, UInt16 *devVendor);
- ADDRESS.withName("GetDeviceProduct"), // IOReturn (*GetDeviceProduct)(void *self, UInt16 *devProduct);
- ADDRESS.withName("GetDeviceReleaseNumber"), // IOReturn (*GetDeviceReleaseNumber)(void *self, UInt16 *devRelNum);
- ADDRESS.withName("GetDeviceAddress"), // IOReturn (*GetDeviceAddress)(void *self, USBDeviceAddress *addr);
- ADDRESS.withName("GetDeviceBusPowerAvailable"), // IOReturn (*GetDeviceBusPowerAvailable)(void *self, UInt32 *powerAvailable);
- ADDRESS.withName("GetDeviceSpeed"), // IOReturn (*GetDeviceSpeed)(void *self, UInt8 *devSpeed);
- ADDRESS.withName("GetNumberOfConfigurations"), // IOReturn (*GetNumberOfConfigurations)(void *self, UInt8 *numConfig);
- ADDRESS.withName("GetLocationID"), // IOReturn (*GetLocationID)(void *self, UInt32 *locationID);
- ADDRESS.withName("GetConfigurationDescriptorPtr"), // IOReturn (*GetConfigurationDescriptorPtr)(void *self, UInt8 configIndex, IOUSBConfigurationDescriptorPtr *desc);
- ADDRESS.withName("GetConfiguration"), // IOReturn (*GetConfiguration)(void *self, UInt8 *configNum);
- ADDRESS.withName("SetConfiguration"), // IOReturn (*SetConfiguration)(void *self, UInt8 configNum);
- ADDRESS.withName("GetBusFrameNumber"), // IOReturn (*GetBusFrameNumber)(void *self, UInt64 *frame, AbsoluteTime *atTime);
- ADDRESS.withName("ResetDevice"), // IOReturn (*ResetDevice)(void *self);
- ADDRESS.withName("DeviceRequest"), // IOReturn (*DeviceRequest)(void *self, IOUSBDevRequest *req);
- ADDRESS.withName("DeviceRequestAsync"), // IOReturn (*DeviceRequestAsync)(void *self, IOUSBDevRequest *req, IOAsyncCallback1 callback, void *refCon);
- ADDRESS.withName("CreateInterfaceIterator"), // IOReturn (*CreateInterfaceIterator)(void *self, IOUSBFindInterfaceRequest *req, io_iterator_t *iter);
- ADDRESS.withName("USBDeviceOpenSeize"), // IOReturn (*USBDeviceOpenSeize)(void *self);
- ADDRESS.withName("DeviceRequestTO"), // IOReturn (*DeviceRequestTO)(void *self, IOUSBDevRequestTO *req);
- ADDRESS.withName("DeviceRequestAsyncTO"), // IOReturn (*DeviceRequestAsyncTO)(void *self, IOUSBDevRequestTO *req, IOAsyncCallback1 callback, void *refCon);
- ADDRESS.withName("USBDeviceSuspend"), // IOReturn (*USBDeviceSuspend)(void *self, Boolean suspend);
- ADDRESS.withName("USBDeviceAbortPipeZero"), // IOReturn (*USBDeviceAbortPipeZero)(void *self);
- ADDRESS.withName("USBGetManufacturerStringIndex"), // IOReturn (*USBGetManufacturerStringIndex)(void *self, UInt8 *msi);
- ADDRESS.withName("USBGetProductStringIndex"), // IOReturn (*USBGetProductStringIndex)(void *self, UInt8 *psi);
- ADDRESS.withName("USBGetSerialNumberStringIndex"), // IOReturn (*USBGetSerialNumberStringIndex)(void *self, UInt8 *snsi);
- ADDRESS.withName("USBDeviceReEnumerate"), // IOReturn (*USBDeviceReEnumerate)(void *self, UInt32 options);
- ADDRESS.withName("GetBusMicroFrameNumber"), // IOReturn (*GetBusMicroFrameNumber)(void *self, UInt64 *microFrame, AbsoluteTime *atTime);
- ADDRESS.withName("GetIOUSBLibVersion"), // IOReturn (*GetIOUSBLibVersion)(void *self, NumVersion *ioUSBLibVersion, NumVersion *usbFamilyVersion);
- ADDRESS.withName("GetBusFrameNumberWithTime"), // IOReturn (*GetBusFrameNumberWithTime)(void *self, UInt64 *frame, AbsoluteTime *atTime);
- ADDRESS.withName("GetUSBDeviceInformation"), // IOReturn (*GetUSBDeviceInformation)(void *self, UInt32 *info);
- ADDRESS.withName("RequestExtraPower"), // IOReturn (*RequestExtraPower)(void *self, UInt32 type, UInt32 requestedPower, UInt32 *powerAvailable);
- ADDRESS.withName("ReturnExtraPower"), // IOReturn (*ReturnExtraPower)(void *self, UInt32 type, UInt32 powerReturned);
- ADDRESS.withName("GetExtraPowerAllocated"), // IOReturn (*GetExtraPowerAllocated)(void *self, UInt32 type, UInt32 *powerAllocated);
- ADDRESS.withName("GetBandwidthAvailableForDevice"), // IOReturn (*GetBandwidthAvailableForDevice)(void *self, UInt32 *bandwidth);
- ADDRESS.withName("SetConfigurationV2"), // IOReturn (*SetConfigurationV2)(void *self, UInt8 configNum, bool startInterfaceMatching, bool issueRemoteWakeup);
- ADDRESS.withName("RegisterForNotification"), // IOReturn (*RegisterForNotification)(void * self, UInt64 notificationMask, IOAsyncCallback2 callback, void *refCon, UInt64 *pRegistrationToken);
- ADDRESS.withName("UnregisterNotification"), // IOReturn (*UnregisterNotification)(void *self, UInt64 registrationToken);
- ADDRESS.withName("AcknowledgeNotification") // IOReturn (*AcknowledgeNotification)(void *self, UInt64 notificationToken);
- );
-
- IOUSBDevice_USBDeviceOpen = IOUSBDevice$Struct.varHandle(groupElement("USBDeviceOpen"));
- IOUSBDevice_USBDeviceClose = IOUSBDevice$Struct.varHandle(groupElement("USBDeviceClose"));
- IOUSBDevice_GetNumberOfConfigurations = IOUSBDevice$Struct.varHandle(groupElement("GetNumberOfConfigurations"));
- IOUSBDevice_GetConfigurationDescriptorPtr = IOUSBDevice$Struct.varHandle(groupElement("GetConfigurationDescriptorPtr"));
- IOUSBDevice_SetConfiguration = IOUSBDevice$Struct.varHandle(groupElement("SetConfiguration"));
- IOUSBDevice_CreateInterfaceIterator = IOUSBDevice$Struct.varHandle(groupElement("CreateInterfaceIterator"));
- IOUSBDevice_DeviceRequest = IOUSBDevice$Struct.varHandle(groupElement("DeviceRequest"));
-
- // IOReturn (*USBDeviceOpen)(void *self);
- USBDeviceOpen$Func = linker.downcallHandle(
- FunctionDescriptor.of(JAVA_INT, ADDRESS)
- );
-
- // IOReturn (*USBDeviceClose)(void *self);
- USBDeviceClose$Func = linker.downcallHandle(
- FunctionDescriptor.of(JAVA_INT, ADDRESS)
- );
-
- // IOReturn (*GetNumberOfConfigurations)(void *self, UInt8 *numConfig);
- GetNumberOfConfigurations$Func = linker.downcallHandle(
- FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS)
- );
-
- // IOReturn (*GetConfigurationDescriptorPtr)(void *self, UInt8 configIndex, IOUSBConfigurationDescriptorPtr *desc);
- GetConfigurationDescriptorPtr$Func = linker.downcallHandle(
- FunctionDescriptor.of(JAVA_INT, ADDRESS, JAVA_BYTE, ADDRESS)
- );
-
- // IOReturn (*SetConfiguration)(void *self, UInt8 configNum);
- SetConfiguration$Func = linker.downcallHandle(
- FunctionDescriptor.of(JAVA_INT, ADDRESS, JAVA_BYTE)
- );
-
- // IOReturn (*CreateInterfaceIterator)(void *self, IOUSBFindInterfaceRequest *req, io_iterator_t *iter);
- CreateInterfaceIterator$Func = linker.downcallHandle(
- FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS, ADDRESS)
- );
-
- // IOReturn (*DeviceRequest)(void *self, IOUSBDevRequest *req);
- DeviceRequest$Func = linker.downcallHandle(
- FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS)
- );
-
- IOUSBInterface$Struct = structLayout(
- ADDRESS.withName("_reserved"), // void *_reserved;
- ADDRESS.withName("QueryInterface"), // HRESULT (STDMETHODCALLTYPE *QueryInterface)(void *thisPointer, REFIID iid, LPVOID *ppv);
- ADDRESS.withName("AddRef"), // ULONG (STDMETHODCALLTYPE *AddRef)(void *thisPointer);
- ADDRESS.withName("Release"), // ULONG (STDMETHODCALLTYPE *Release)(void *thisPointer);
- ADDRESS.withName("CreateInterfaceAsyncEventSource"), // IOReturn (*CreateInterfaceAsyncEventSource)(void *self, CFRunLoopSourceRef *source);
- ADDRESS.withName("GetInterfaceAsyncEventSource"), // CFRunLoopSourceRef (*GetInterfaceAsyncEventSource)(void *self);
- ADDRESS.withName("CreateInterfaceAsyncPort"), // IOReturn (*CreateInterfaceAsyncPort)(void *self, mach_port_t *port);
- ADDRESS.withName("GetInterfaceAsyncPort"), // mach_port_t (*GetInterfaceAsyncPort)(void *self);
- ADDRESS.withName("USBInterfaceOpen"), // IOReturn (*USBInterfaceOpen)(void *self);
- ADDRESS.withName("USBInterfaceClose"), // IOReturn (*USBInterfaceClose)(void *self);
- ADDRESS.withName("GetInterfaceClass"), // IOReturn (*GetInterfaceClass)(void *self, UInt8 *intfClass);
- ADDRESS.withName("GetInterfaceSubClass"), // IOReturn (*GetInterfaceSubClass)(void *self, UInt8 *intfSubClass);
- ADDRESS.withName("GetInterfaceProtocol"), // IOReturn (*GetInterfaceProtocol)(void *self, UInt8 *intfProtocol);
- ADDRESS.withName("GetDeviceVendor"), // IOReturn (*GetDeviceVendor)(void *self, UInt16 *devVendor);
- ADDRESS.withName("GetDeviceProduct"), // IOReturn (*GetDeviceProduct)(void *self, UInt16 *devProduct);
- ADDRESS.withName("GetDeviceReleaseNumber"), // IOReturn (*GetDeviceReleaseNumber)(void *self, UInt16 *devRelNum);
- ADDRESS.withName("GetConfigurationValue"), // IOReturn (*GetConfigurationValue)(void *self, UInt8 *configVal);
- ADDRESS.withName("GetInterfaceNumber"), // IOReturn (*GetInterfaceNumber)(void *self, UInt8 *intfNumber);
- ADDRESS.withName("GetAlternateSetting"), // IOReturn (*GetAlternateSetting)(void *self, UInt8 *intfAltSetting);
- ADDRESS.withName("GetNumEndpoints"), // IOReturn (*GetNumEndpoints)(void *self, UInt8 *intfNumEndpoints);
- ADDRESS.withName("GetLocationID"), // IOReturn (*GetLocationID)(void *self, UInt32 *locationID);
- ADDRESS.withName("GetDevice"), // IOReturn (*GetDevice)(void *self, io_service_t *device);
- ADDRESS.withName("SetAlternateInterface"), // IOReturn (*SetAlternateInterface)(void *self, UInt8 alternateSetting);
- ADDRESS.withName("GetBusFrameNumber"), // IOReturn (*GetBusFrameNumber)(void *self, UInt64 *frame, AbsoluteTime *atTime);
- ADDRESS.withName("ControlRequest"), // IOReturn (*ControlRequest)(void *self, UInt8 pipeRef, IOUSBDevRequest *req);
- ADDRESS.withName("ControlRequestAsync"), // IOReturn (*ControlRequestAsync)(void *self, UInt8 pipeRef, IOUSBDevRequest *req, IOAsyncCallback1 callback, void *refCon);
- ADDRESS.withName("GetPipeProperties"), // IOReturn (*GetPipeProperties)(void *self, UInt8 pipeRef, UInt8 *direction, UInt8 *number, UInt8 *transferType, UInt16 *maxPacketSize, UInt8 *interval);
- ADDRESS.withName("GetPipeStatus"), // IOReturn (*GetPipeStatus)(void *self, UInt8 pipeRef);
- ADDRESS.withName("AbortPipe"), // IOReturn (*AbortPipe)(void *self, UInt8 pipeRef);
- ADDRESS.withName("ResetPipe"), // IOReturn (*ResetPipe)(void *self, UInt8 pipeRef);
- ADDRESS.withName("ClearPipeStall"), // IOReturn (*ClearPipeStall)(void *self, UInt8 pipeRef);
- ADDRESS.withName("ReadPipe"), // IOReturn (*ReadPipe)(void *self, UInt8 pipeRef, void *buf, UInt32 *size);
- ADDRESS.withName("WritePipe"), // IOReturn (*WritePipe)(void *self, UInt8 pipeRef, void *buf, UInt32 size);
- ADDRESS.withName("ReadPipeAsync"), // IOReturn (*ReadPipeAsync)(void *self, UInt8 pipeRef, void *buf, UInt32 size, IOAsyncCallback1 callback, void *refcon);
- ADDRESS.withName("WritePipeAsync"), // IOReturn (*WritePipeAsync)(void *self, UInt8 pipeRef, void *buf, UInt32 size, IOAsyncCallback1 callback, void *refcon);
- ADDRESS.withName("ReadIsochPipeAsync"), // IOReturn (*ReadIsochPipeAsync)(void *self, UInt8 pipeRef, void *buf, UInt64 frameStart, UInt32 numFrames, IOUSBIsocFrame *frameList, IOAsyncCallback1 callback, void *refcon);
- ADDRESS.withName("WriteIsochPipeAsync"), // IOReturn (*WriteIsochPipeAsync)(void *self, UInt8 pipeRef, void *buf, UInt64 frameStart, UInt32 numFrames, IOUSBIsocFrame *frameList, IOAsyncCallback1 callback, void *refcon);
- ADDRESS.withName("ControlRequestTO"), // IOReturn (*ControlRequestTO)(void *self, UInt8 pipeRef, IOUSBDevRequestTO *req);
- ADDRESS.withName("ControlRequestAsyncTO"), // IOReturn (*ControlRequestAsyncTO)(void *self, UInt8 pipeRef, IOUSBDevRequestTO *req, IOAsyncCallback1 callback, void *refCon);
- ADDRESS.withName("ReadPipeTO"), // IOReturn (*ReadPipeTO)(void *self, UInt8 pipeRef, void *buf, UInt32 *size, UInt32 noDataTimeout, UInt32 completionTimeout);
- ADDRESS.withName("WritePipeTO"), // IOReturn (*WritePipeTO)(void *self, UInt8 pipeRef, void *buf, UInt32 size, UInt32 noDataTimeout, UInt32 completionTimeout);
- ADDRESS.withName("ReadPipeAsyncTO"), // IOReturn (*ReadPipeAsyncTO)(void *self, UInt8 pipeRef, void *buf, UInt32 size, UInt32 noDataTimeout, UInt32 completionTimeout, IOAsyncCallback1 callback, void *refcon);
- ADDRESS.withName("WritePipeAsyncTO"), // IOReturn (*WritePipeAsyncTO)(void *self, UInt8 pipeRef, void *buf, UInt32 size, UInt32 noDataTimeout, UInt32 completionTimeout, IOAsyncCallback1 callback, void *refcon);
- ADDRESS.withName("USBInterfaceGetStringIndex"), // IOReturn (*USBInterfaceGetStringIndex)(void *self, UInt8 *si);
- ADDRESS.withName("USBInterfaceOpenSeize"), // IOReturn (*USBInterfaceOpenSeize)(void *self);
- ADDRESS.withName("ClearPipeStallBothEnds"), // IOReturn (*ClearPipeStallBothEnds)(void *self, UInt8 pipeRef);
- ADDRESS.withName("SetPipePolicy"), // IOReturn (*SetPipePolicy)(void *self, UInt8 pipeRef, UInt16 maxPacketSize, UInt8 maxInterval);
- ADDRESS.withName("GetBandwidthAvailable"), // IOReturn (*GetBandwidthAvailable)(void *self, UInt32 *bandwidth);
- ADDRESS.withName("GetEndpointProperties"), // IOReturn (*GetEndpointProperties)(void *self, UInt8 alternateSetting, UInt8 endpointNumber, UInt8 direction, UInt8 *transferType, UInt16 *maxPacketSize, UInt8 *interval);
- ADDRESS.withName("LowLatencyReadIsochPipeAsync"), // IOReturn (*LowLatencyReadIsochPipeAsync)(void *self, UInt8 pipeRef, void *buf, UInt64 frameStart, UInt32 numFrames, UInt32 updateFrequency, IOUSBLowLatencyIsocFrame *frameList, IOAsyncCallback1 callback, void *refcon);
- ADDRESS.withName("LowLatencyWriteIsochPipeAsync"), // IOReturn (*LowLatencyWriteIsochPipeAsync)(void *self, UInt8 pipeRef, void *buf, UInt64 frameStart, UInt32 numFrames, UInt32 updateFrequency, IOUSBLowLatencyIsocFrame *frameList, IOAsyncCallback1 callback, void *refcon);
- ADDRESS.withName("LowLatencyCreateBuffer"), // IOReturn (*LowLatencyCreateBuffer)(void * self, void **buffer, IOByteCount size, UInt32 bufferType);
- ADDRESS.withName("LowLatencyDestroyBuffer"), // IOReturn (*LowLatencyDestroyBuffer) (void * self, void * buffer );
- ADDRESS.withName("GetBusMicroFrameNumber"), // IOReturn (*GetBusMicroFrameNumber)(void *self, UInt64 *microFrame, AbsoluteTime *atTime);
- ADDRESS.withName("GetFrameListTime"), // IOReturn (*GetFrameListTime)(void *self, UInt32 *microsecondsInFrame);
- ADDRESS.withName("GetIOUSBLibVersion"), // IOReturn (*GetIOUSBLibVersion)(void *self, NumVersion *ioUSBLibVersion, NumVersion *usbFamilyVersion);
- ADDRESS.withName("FindNextAssociatedDescriptor"), // IOUSBDescriptorHeader * (*FindNextAssociatedDescriptor)(void *self, const void *currentDescriptor, UInt8 descriptorType);
- ADDRESS.withName("FindNextAltInterface"), // IOUSBDescriptorHeader * (*FindNextAltInterface)(void *self, const void *current, IOUSBFindInterfaceRequest *request);
- ADDRESS.withName("GetBusFrameNumberWithTime"), // IOReturn (*GetBusFrameNumberWithTime)(void *self, UInt64 *frame, AbsoluteTime *atTime);
- ADDRESS.withName("GetPipePropertiesV2"), // IOReturn (*GetPipePropertiesV2)(void *self, UInt8 pipeRef, UInt8 *direction, UInt8 *number, UInt8 *transferType, UInt16 *maxPacketSize, UInt8 *interval, UInt8 *maxBurst, UInt8 *mult, UInt16 *bytesPerInterval);
- ADDRESS.withName("GetPipePropertiesV3"), // IOReturn (*GetPipePropertiesV3)(void *self, UInt8 pipeRef, IOUSBEndpointProperties *properties);
- ADDRESS.withName("GetEndpointPropertiesV3"), // IOReturn (*GetEndpointPropertiesV3)(void *self, IOUSBEndpointProperties *properties);
- ADDRESS.withName("SupportsStreams"), // IOReturn (*SupportsStreams)(void *self, UInt8 pipeRef, UInt32 *supportsStreams);
- ADDRESS.withName("CreateStreams"), // IOReturn (*CreateStreams)(void *self, UInt8 pipeRef, UInt32 streamID);
- ADDRESS.withName("GetConfiguredStreams"), // IOReturn (*GetConfiguredStreams)(void *self, UInt8 pipeRef, UInt32 *configuredStreams);
- ADDRESS.withName("ReadStreamsPipeTO"), // IOReturn (*ReadStreamsPipeTO)(void *self, UInt8 pipeRef, UInt32 streamID, void *buf, UInt32 *size, UInt32 noDataTimeout, UInt32 completionTimeout);
- ADDRESS.withName("WriteStreamsPipeTO"), // IOReturn (*WriteStreamsPipeTO)(void *self, UInt8 pipeRef, UInt32 streamID, void *buf, UInt32 size, UInt32 noDataTimeout, UInt32 completionTimeout);
- ADDRESS.withName("ReadStreamsPipeAsyncTO"), // IOReturn (*ReadStreamsPipeAsyncTO)(void *self, UInt8 pipeRef, UInt32 streamID, void *buf, UInt32 size, UInt32 noDataTimeout, UInt32 completionTimeout, IOAsyncCallback1 callback, void *refcon);
- ADDRESS.withName("WriteStreamsPipeAsyncTO"), // IOReturn (*WriteStreamsPipeAsyncTO)(void *self, UInt8 pipeRef, UInt32 streamID, void *buf, UInt32 size, UInt32 noDataTimeout, UInt32 completionTimeout, IOAsyncCallback1 callback, void *refcon);
- ADDRESS.withName("AbortStreamsPipe"), // IOReturn (*AbortStreamsPipe)(void *self, UInt8 pipeRef, UInt32 streamID);
- ADDRESS.withName("RegisterForNotification"), // IOReturn (*RegisterForNotification)(void * self, UInt64 notificationMask, IOAsyncCallback2 callback, void *refCon, UInt64 *pRegistrationToken);
- ADDRESS.withName("UnregisterNotification"), // IOReturn (*UnregisterNotification)(void *self, UInt64 registrationToken);
- ADDRESS.withName("AcknowledgeNotification"), // IOReturn (*AcknowledgeNotification)(void *self, UInt64 notificationToken);
- ADDRESS.withName("RegisterDriver") // IOReturn (*RegisterDriver)(void *self);
- );
-
- IOUSBInterface_USBInterfaceOpen = IOUSBInterface$Struct.varHandle(groupElement("USBInterfaceOpen"));
- IOUSBInterface_USBInterfaceClose = IOUSBInterface$Struct.varHandle(groupElement("USBInterfaceClose"));
- IOUSBInterface_GetInterfaceNumber = IOUSBInterface$Struct.varHandle(groupElement("GetInterfaceNumber"));
- IOUSBInterface_GetNumEndpoints = IOUSBInterface$Struct.varHandle(groupElement("GetNumEndpoints"));
- IOUSBInterface_GetPipeProperties = IOUSBInterface$Struct.varHandle(groupElement("GetPipeProperties"));
- IOUSBInterface_ReadPipe = IOUSBInterface$Struct.varHandle(groupElement("ReadPipe"));
- IOUSBInterface_WritePipe = IOUSBInterface$Struct.varHandle(groupElement("WritePipe"));
-
- // IOReturn (*USBInterfaceOpen)(void *self);;
- USBInterfaceOpen$Func = linker.downcallHandle(
- FunctionDescriptor.of(JAVA_INT, ADDRESS)
- );
-
- // IOReturn (*USBInterfaceClose)(void *self);;
- USBInterfaceClose$Func = linker.downcallHandle(
- FunctionDescriptor.of(JAVA_INT, ADDRESS)
- );
-
- // IOReturn (*GetInterfaceNumber)(void *self, UInt8 *intfNumber);
- GetInterfaceNumber$Func = linker.downcallHandle(
- FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS)
- );
-
- // IOReturn (*GetNumEndpoints)(void *self, UInt8 *intfNumEndpoints);
- GetNumEndpoints$Func = linker.downcallHandle(
- FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS)
- );
-
- // IOReturn (*GetPipeProperties)(void *self, UInt8 pipeRef, UInt8 *direction, UInt8 *number, UInt8 *transferType, UInt16 *maxPacketSize, UInt8 *interval);
- GetPipeProperties$Func = linker.downcallHandle(
- FunctionDescriptor.of(JAVA_INT, ADDRESS, JAVA_BYTE, ADDRESS, ADDRESS, ADDRESS, ADDRESS, ADDRESS)
- );
-
- // IOReturn (*ReadPipe)(void *self, UInt8 pipeRef, void *buf, UInt32 *size);
- ReadPipe$Func = linker.downcallHandle(
- FunctionDescriptor.of(JAVA_INT, ADDRESS, JAVA_BYTE, ADDRESS, ADDRESS)
- );
-
- // IOReturn (*WritePipe)(void *self, UInt8 pipeRef, void *buf, UInt32 size);
- WritePipe$Func = linker.downcallHandle(
- FunctionDescriptor.of(JAVA_INT, ADDRESS, JAVA_BYTE, ADDRESS, JAVA_INT)
- );
-
- // typedef struct {
- // UInt8 bmRequestType;
- // UInt8 bRequest;
- // UInt16 wValue;
- // UInt16 wIndex;
- // UInt16 wLength;
- // void* pData;
- // UInt32 wLenDone;
- //} IOUSBDevRequest;
- IOUSBDevRequest$Struct = structLayout(
- JAVA_BYTE.withName("bmRequestType"),
- JAVA_BYTE.withName("bRequest"),
- JAVA_SHORT.withName("wValue"),
- JAVA_SHORT.withName("wIndex"),
- JAVA_SHORT.withName("wLength"),
- ADDRESS.withName("pData"),
- JAVA_INT.withName("wLenDone")
- );
-
- IOUSBDevRequest_bmRequestType = IOUSBDevRequest$Struct.varHandle(groupElement("bmRequestType"));
- IOUSBDevRequest_bRequest = IOUSBDevRequest$Struct.varHandle(groupElement("bRequest"));
- IOUSBDevRequest_wValue = IOUSBDevRequest$Struct.varHandle(groupElement("wValue"));
- IOUSBDevRequest_wIndex = IOUSBDevRequest$Struct.varHandle(groupElement("wIndex"));
- IOUSBDevRequest_wLength = IOUSBDevRequest$Struct.varHandle(groupElement("wLength"));
- IOUSBDevRequest_pData = IOUSBDevRequest$Struct.varHandle(groupElement("pData"));
- IOUSBDevRequest_wLenDone = IOUSBDevRequest$Struct.varHandle(groupElement("wLenDone"));
- }
-
- private static Addressable IOUSBDevice$VirtFunc(MemoryAddress thisPointer, VarHandle varHandle, MemorySession session) {
+ // typedef struct {
+ // UInt16 bInterfaceClass; // requested class
+ // UInt16 bInterfaceSubClass; // requested subclass
+ // UInt16 bInterfaceProtocol; // requested protocol
+ // UInt16 bAlternateSetting; // requested alt setting
+ // } IOUSBFindInterfaceRequest;
+ public static final GroupLayout IOUSBFindInterfaceRequest$Struct = structLayout(
+ JAVA_SHORT.withName("bInterfaceClass"),
+ JAVA_SHORT.withName("bInterfaceSubClass"),
+ JAVA_SHORT.withName("bInterfaceProtocol"),
+ JAVA_SHORT.withName("bAlternateSetting")
+ );
+ public static final VarHandle IOUSBFindInterfaceRequest_bInterfaceClass = IOUSBFindInterfaceRequest$Struct.varHandle(groupElement("bInterfaceClass"));
+ public static final VarHandle IOUSBFindInterfaceRequest_bInterfaceSubClass = IOUSBFindInterfaceRequest$Struct.varHandle(groupElement("bInterfaceSubClass"));
+ public static final VarHandle IOUSBFindInterfaceRequest_bInterfaceProtocol = IOUSBFindInterfaceRequest$Struct.varHandle(groupElement("bInterfaceProtocol"));
+ public static final VarHandle IOUSBFindInterfaceRequest_bAlternateSetting = IOUSBFindInterfaceRequest$Struct.varHandle(groupElement("bAlternateSetting"));
+
+ private static final GroupLayout IOUSBDevice$Struct = structLayout(
+ ADDRESS.withName("_reserved"), // void *_reserved;
+ ADDRESS.withName("QueryInterface"), // HRESULT (STDMETHODCALLTYPE *QueryInterface)(void *thisPointer, REFIID iid, LPVOID *ppv);
+ ADDRESS.withName("AddRef"), // ULONG (STDMETHODCALLTYPE *AddRef)(void *thisPointer);
+ ADDRESS.withName("Release"), // ULONG (STDMETHODCALLTYPE *Release)(void *thisPointer);
+ ADDRESS.withName("CreateDeviceAsyncEventSource"), // IOReturn (*CreateDeviceAsyncEventSource)(void *self, CFRunLoopSourceRef *source);
+ ADDRESS.withName("GetDeviceAsyncEventSource"), // CFRunLoopSourceRef (*GetDeviceAsyncEventSource)(void *self);
+ ADDRESS.withName("CreateDeviceAsyncPort"), // IOReturn (*CreateDeviceAsyncPort)(void *self, mach_port_t *port);
+ ADDRESS.withName("GetDeviceAsyncPort"), // mach_port_t (*GetDeviceAsyncPort)(void *self);
+ ADDRESS.withName("USBDeviceOpen"), // IOReturn (*USBDeviceOpen)(void *self);
+ ADDRESS.withName("USBDeviceClose"), // IOReturn (*USBDeviceClose)(void *self);
+ ADDRESS.withName("GetDeviceClass"), // IOReturn (*GetDeviceClass)(void *self, UInt8 *devClass);
+ ADDRESS.withName("GetDeviceSubClass"), // IOReturn (*GetDeviceSubClass)(void *self, UInt8 *devSubClass);
+ ADDRESS.withName("GetDeviceProtocol"), // IOReturn (*GetDeviceProtocol)(void *self, UInt8 *devProtocol);
+ ADDRESS.withName("GetDeviceVendor"), // IOReturn (*GetDeviceVendor)(void *self, UInt16 *devVendor);
+ ADDRESS.withName("GetDeviceProduct"), // IOReturn (*GetDeviceProduct)(void *self, UInt16 *devProduct);
+ ADDRESS.withName("GetDeviceReleaseNumber"), // IOReturn (*GetDeviceReleaseNumber)(void *self, UInt16 *devRelNum);
+ ADDRESS.withName("GetDeviceAddress"), // IOReturn (*GetDeviceAddress)(void *self, USBDeviceAddress *addr);
+ ADDRESS.withName("GetDeviceBusPowerAvailable"), // IOReturn (*GetDeviceBusPowerAvailable)(void *self, UInt32 *powerAvailable);
+ ADDRESS.withName("GetDeviceSpeed"), // IOReturn (*GetDeviceSpeed)(void *self, UInt8 *devSpeed);
+ ADDRESS.withName("GetNumberOfConfigurations"), // IOReturn (*GetNumberOfConfigurations)(void *self, UInt8 *numConfig);
+ ADDRESS.withName("GetLocationID"), // IOReturn (*GetLocationID)(void *self, UInt32 *locationID);
+ ADDRESS.withName("GetConfigurationDescriptorPtr"), // IOReturn (*GetConfigurationDescriptorPtr)(void *self, UInt8 configIndex, IOUSBConfigurationDescriptorPtr *desc);
+ ADDRESS.withName("GetConfiguration"), // IOReturn (*GetConfiguration)(void *self, UInt8 *configNum);
+ ADDRESS.withName("SetConfiguration"), // IOReturn (*SetConfiguration)(void *self, UInt8 configNum);
+ ADDRESS.withName("GetBusFrameNumber"), // IOReturn (*GetBusFrameNumber)(void *self, UInt64 *frame, AbsoluteTime *atTime);
+ ADDRESS.withName("ResetDevice"), // IOReturn (*ResetDevice)(void *self);
+ ADDRESS.withName("DeviceRequest"), // IOReturn (*DeviceRequest)(void *self, IOUSBDevRequest *req);
+ ADDRESS.withName("DeviceRequestAsync"), // IOReturn (*DeviceRequestAsync)(void *self, IOUSBDevRequest *req, IOAsyncCallback1 callback, void *refCon);
+ ADDRESS.withName("CreateInterfaceIterator"), // IOReturn (*CreateInterfaceIterator)(void *self, IOUSBFindInterfaceRequest *req, io_iterator_t *iter);
+ ADDRESS.withName("USBDeviceOpenSeize"), // IOReturn (*USBDeviceOpenSeize)(void *self);
+ ADDRESS.withName("DeviceRequestTO"), // IOReturn (*DeviceRequestTO)(void *self, IOUSBDevRequestTO *req);
+ ADDRESS.withName("DeviceRequestAsyncTO"), // IOReturn (*DeviceRequestAsyncTO)(void *self, IOUSBDevRequestTO *req, IOAsyncCallback1 callback, void *refCon);
+ ADDRESS.withName("USBDeviceSuspend"), // IOReturn (*USBDeviceSuspend)(void *self, Boolean suspend);
+ ADDRESS.withName("USBDeviceAbortPipeZero"), // IOReturn (*USBDeviceAbortPipeZero)(void *self);
+ ADDRESS.withName("USBGetManufacturerStringIndex"), // IOReturn (*USBGetManufacturerStringIndex)(void *self, UInt8 *msi);
+ ADDRESS.withName("USBGetProductStringIndex"), // IOReturn (*USBGetProductStringIndex)(void *self, UInt8 *psi);
+ ADDRESS.withName("USBGetSerialNumberStringIndex"), // IOReturn (*USBGetSerialNumberStringIndex)(void *self, UInt8 *snsi);
+ ADDRESS.withName("USBDeviceReEnumerate"), // IOReturn (*USBDeviceReEnumerate)(void *self, UInt32 options);
+ ADDRESS.withName("GetBusMicroFrameNumber"), // IOReturn (*GetBusMicroFrameNumber)(void *self, UInt64 *microFrame, AbsoluteTime *atTime);
+ ADDRESS.withName("GetIOUSBLibVersion"), // IOReturn (*GetIOUSBLibVersion)(void *self, NumVersion *ioUSBLibVersion, NumVersion *usbFamilyVersion);
+ ADDRESS.withName("GetBusFrameNumberWithTime"), // IOReturn (*GetBusFrameNumberWithTime)(void *self, UInt64 *frame, AbsoluteTime *atTime);
+ ADDRESS.withName("GetUSBDeviceInformation"), // IOReturn (*GetUSBDeviceInformation)(void *self, UInt32 *info);
+ ADDRESS.withName("RequestExtraPower"), // IOReturn (*RequestExtraPower)(void *self, UInt32 type, UInt32 requestedPower, UInt32 *powerAvailable);
+ ADDRESS.withName("ReturnExtraPower"), // IOReturn (*ReturnExtraPower)(void *self, UInt32 type, UInt32 powerReturned);
+ ADDRESS.withName("GetExtraPowerAllocated"), // IOReturn (*GetExtraPowerAllocated)(void *self, UInt32 type, UInt32 *powerAllocated);
+ ADDRESS.withName("GetBandwidthAvailableForDevice"), // IOReturn (*GetBandwidthAvailableForDevice)(void *self, UInt32 *bandwidth);
+ ADDRESS.withName("SetConfigurationV2"), // IOReturn (*SetConfigurationV2)(void *self, UInt8 configNum, bool startInterfaceMatching, bool issueRemoteWakeup);
+ ADDRESS.withName("RegisterForNotification"), // IOReturn (*RegisterForNotification)(void * self, UInt64 notificationMask, IOAsyncCallback2 callback, void *refCon, UInt64 *pRegistrationToken);
+ ADDRESS.withName("UnregisterNotification"), // IOReturn (*UnregisterNotification)(void *self, UInt64 registrationToken);
+ ADDRESS.withName("AcknowledgeNotification") // IOReturn (*AcknowledgeNotification)(void *self, UInt64 notificationToken);
+ );
+
+ /**
+ * Looks up the address of the specified virtual function in the {@code IOUSBDevice} object
+ * @param thisPointer pointer to pointer to object
+ * @param varHandle variable handle to virtual function
+ * @param session memory session
+ * @return function address
+ */
+ private static Addressable IOUSBDeviceFunctionAddress(MemoryAddress thisPointer, VarHandle varHandle, MemorySession session) {
var seg = MemorySegment.ofAddress(thisPointer, ADDRESS.byteSize(), session);
var thisValue = seg.get(ADDRESS, 0);
var obj = MemorySegment.ofAddress(thisValue, IOUSBDevice$Struct.byteSize(), session);
@@ -343,9 +111,13 @@ public class IoKitUSB {
}
// IOReturn (*USBDeviceOpen)(void *self);
+ private static final VarHandle IOUSBDevice_USBDeviceOpen = IOUSBDevice$Struct.varHandle(groupElement("USBDeviceOpen"));
+ private static final MethodHandle USBDeviceOpen$Func = linker.downcallHandle(
+ FunctionDescriptor.of(JAVA_INT, ADDRESS)
+ );
public static int USBDeviceOpen(MemoryAddress thisPointer) {
try (var session = MemorySession.openShared()) {
- var funcPtr = IOUSBDevice$VirtFunc(thisPointer, IOUSBDevice_USBDeviceOpen, session);
+ var funcPtr = IOUSBDeviceFunctionAddress(thisPointer, IOUSBDevice_USBDeviceOpen, session);
return (int) USBDeviceOpen$Func.invokeExact(funcPtr, (Addressable) thisPointer);
} catch (Throwable e) {
throw new RuntimeException(e);
@@ -353,19 +125,27 @@ public static int USBDeviceOpen(MemoryAddress thisPointer) {
}
// IOReturn (*USBDeviceClose)(void *self);
+ private static final VarHandle IOUSBDevice_USBDeviceClose = IOUSBDevice$Struct.varHandle(groupElement("USBDeviceClose"));
+ private static final MethodHandle USBDeviceClose$Func = linker.downcallHandle(
+ FunctionDescriptor.of(JAVA_INT, ADDRESS)
+ );
public static int USBDeviceClose(MemoryAddress thisPointer) {
try (var session = MemorySession.openShared()) {
- var funcPtr = IOUSBDevice$VirtFunc(thisPointer, IOUSBDevice_USBDeviceClose, session);
+ var funcPtr = IOUSBDeviceFunctionAddress(thisPointer, IOUSBDevice_USBDeviceClose, session);
return (int) USBDeviceClose$Func.invokeExact(funcPtr, (Addressable) thisPointer);
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
- // IOReturn (*GetNumberOfConfigurations)(void *self, UInt8 *numConfig);
+ // IOReturn (*GetNumberOfConfigurations)(void *self, UInt8 *numConfig);
+ private static final VarHandle IOUSBDevice_GetNumberOfConfigurations = IOUSBDevice$Struct.varHandle(groupElement("GetNumberOfConfigurations"));
+ private static final MethodHandle GetNumberOfConfigurations$Func = linker.downcallHandle(
+ FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS)
+ );
public static int GetNumberOfConfigurations(MemoryAddress thisPointer, Addressable numConfigHolder) {
try (var session = MemorySession.openShared()) {
- var funcPtr = IOUSBDevice$VirtFunc(thisPointer, IOUSBDevice_GetNumberOfConfigurations, session);
+ var funcPtr = IOUSBDeviceFunctionAddress(thisPointer, IOUSBDevice_GetNumberOfConfigurations, session);
return (int) GetNumberOfConfigurations$Func.invokeExact(funcPtr, (Addressable) thisPointer, numConfigHolder);
} catch (Throwable e) {
throw new RuntimeException(e);
@@ -373,9 +153,13 @@ public static int GetNumberOfConfigurations(MemoryAddress thisPointer, Addressab
}
// IOReturn (*GetConfigurationDescriptorPtr)(void *self, UInt8 configIndex, IOUSBConfigurationDescriptorPtr *desc);
+ private static final VarHandle IOUSBDevice_GetConfigurationDescriptorPtr = IOUSBDevice$Struct.varHandle(groupElement("GetConfigurationDescriptorPtr"));
+ private static final MethodHandle GetConfigurationDescriptorPtr$Func = linker.downcallHandle(
+ FunctionDescriptor.of(JAVA_INT, ADDRESS, JAVA_BYTE, ADDRESS)
+ );
public static int GetConfigurationDescriptorPtr(MemoryAddress thisPointer, byte configIndex, Addressable descHolder) {
try (var session = MemorySession.openShared()) {
- var funcPtr = IOUSBDevice$VirtFunc(thisPointer, IOUSBDevice_GetConfigurationDescriptorPtr, session);
+ var funcPtr = IOUSBDeviceFunctionAddress(thisPointer, IOUSBDevice_GetConfigurationDescriptorPtr, session);
return (int) GetConfigurationDescriptorPtr$Func.invokeExact(funcPtr, (Addressable) thisPointer, configIndex, descHolder);
} catch (Throwable e) {
throw new RuntimeException(e);
@@ -383,9 +167,13 @@ public static int GetConfigurationDescriptorPtr(MemoryAddress thisPointer, byte
}
// IOReturn (*SetConfiguration)(void *self, UInt8 configNum);
+ private static final VarHandle IOUSBDevice_SetConfiguration = IOUSBDevice$Struct.varHandle(groupElement("SetConfiguration"));
+ private static final MethodHandle SetConfiguration$Func = linker.downcallHandle(
+ FunctionDescriptor.of(JAVA_INT, ADDRESS, JAVA_BYTE)
+ );
public static int SetConfiguration(MemoryAddress thisPointer, byte configValue) {
try (var session = MemorySession.openShared()) {
- var funcPtr = IOUSBDevice$VirtFunc(thisPointer, IOUSBDevice_SetConfiguration, session);
+ var funcPtr = IOUSBDeviceFunctionAddress(thisPointer, IOUSBDevice_SetConfiguration, session);
return (int) SetConfiguration$Func.invokeExact(funcPtr, (Addressable) thisPointer, configValue);
} catch (Throwable e) {
throw new RuntimeException(e);
@@ -393,9 +181,13 @@ public static int SetConfiguration(MemoryAddress thisPointer, byte configValue)
}
// IOReturn (*CreateInterfaceIterator)(void *self, IOUSBFindInterfaceRequest *req, io_iterator_t *iter);
+ private static final VarHandle IOUSBDevice_CreateInterfaceIterator = IOUSBDevice$Struct.varHandle(groupElement("CreateInterfaceIterator"));
+ private static final MethodHandle CreateInterfaceIterator$Func = linker.downcallHandle(
+ FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS, ADDRESS)
+ );
public static int CreateInterfaceIterator(MemoryAddress thisPointer, Addressable req, Addressable iter) {
try (var session = MemorySession.openShared()) {
- var funcPtr = IOUSBDevice$VirtFunc(thisPointer, IOUSBDevice_CreateInterfaceIterator, session);
+ var funcPtr = IOUSBDeviceFunctionAddress(thisPointer, IOUSBDevice_CreateInterfaceIterator, session);
return (int) CreateInterfaceIterator$Func.invokeExact(funcPtr, (Addressable) thisPointer, req, iter);
} catch (Throwable e) {
throw new RuntimeException(e);
@@ -403,36 +195,132 @@ public static int CreateInterfaceIterator(MemoryAddress thisPointer, Addressable
}
// IOReturn (*DeviceRequest)(void *self, IOUSBDevRequest *req);
+ private static final VarHandle IOUSBDevice_DeviceRequest = IOUSBDevice$Struct.varHandle(groupElement("DeviceRequest"));
+ private static final MethodHandle DeviceRequest$Func = linker.downcallHandle(
+ FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS)
+ );
public static int DeviceRequest(MemoryAddress thisPointer, Addressable deviceRequest) {
try (var session = MemorySession.openShared()) {
- var funcPtr = IOUSBDevice$VirtFunc(thisPointer, IOUSBDevice_DeviceRequest, session);
+ var funcPtr = IOUSBDeviceFunctionAddress(thisPointer, IOUSBDevice_DeviceRequest, session);
return (int) DeviceRequest$Func.invokeExact(funcPtr, (Addressable) thisPointer, deviceRequest);
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
- private static Addressable IOUSBInterface$VirtFunc(MemoryAddress thisPointer, VarHandle varHandle, MemorySession session) {
+ private static final GroupLayout IOUSBInterface$Struct = structLayout(
+ ADDRESS.withName("_reserved"), // void *_reserved;
+ ADDRESS.withName("QueryInterface"), // HRESULT (STDMETHODCALLTYPE *QueryInterface)(void *thisPointer, REFIID iid, LPVOID *ppv);
+ ADDRESS.withName("AddRef"), // ULONG (STDMETHODCALLTYPE *AddRef)(void *thisPointer);
+ ADDRESS.withName("Release"), // ULONG (STDMETHODCALLTYPE *Release)(void *thisPointer);
+ ADDRESS.withName("CreateInterfaceAsyncEventSource"), // IOReturn (*CreateInterfaceAsyncEventSource)(void *self, CFRunLoopSourceRef *source);
+ ADDRESS.withName("GetInterfaceAsyncEventSource"), // CFRunLoopSourceRef (*GetInterfaceAsyncEventSource)(void *self);
+ ADDRESS.withName("CreateInterfaceAsyncPort"), // IOReturn (*CreateInterfaceAsyncPort)(void *self, mach_port_t *port);
+ ADDRESS.withName("GetInterfaceAsyncPort"), // mach_port_t (*GetInterfaceAsyncPort)(void *self);
+ ADDRESS.withName("USBInterfaceOpen"), // IOReturn (*USBInterfaceOpen)(void *self);
+ ADDRESS.withName("USBInterfaceClose"), // IOReturn (*USBInterfaceClose)(void *self);
+ ADDRESS.withName("GetInterfaceClass"), // IOReturn (*GetInterfaceClass)(void *self, UInt8 *intfClass);
+ ADDRESS.withName("GetInterfaceSubClass"), // IOReturn (*GetInterfaceSubClass)(void *self, UInt8 *intfSubClass);
+ ADDRESS.withName("GetInterfaceProtocol"), // IOReturn (*GetInterfaceProtocol)(void *self, UInt8 *intfProtocol);
+ ADDRESS.withName("GetDeviceVendor"), // IOReturn (*GetDeviceVendor)(void *self, UInt16 *devVendor);
+ ADDRESS.withName("GetDeviceProduct"), // IOReturn (*GetDeviceProduct)(void *self, UInt16 *devProduct);
+ ADDRESS.withName("GetDeviceReleaseNumber"), // IOReturn (*GetDeviceReleaseNumber)(void *self, UInt16 *devRelNum);
+ ADDRESS.withName("GetConfigurationValue"), // IOReturn (*GetConfigurationValue)(void *self, UInt8 *configVal);
+ ADDRESS.withName("GetInterfaceNumber"), // IOReturn (*GetInterfaceNumber)(void *self, UInt8 *intfNumber);
+ ADDRESS.withName("GetAlternateSetting"), // IOReturn (*GetAlternateSetting)(void *self, UInt8 *intfAltSetting);
+ ADDRESS.withName("GetNumEndpoints"), // IOReturn (*GetNumEndpoints)(void *self, UInt8 *intfNumEndpoints);
+ ADDRESS.withName("GetLocationID"), // IOReturn (*GetLocationID)(void *self, UInt32 *locationID);
+ ADDRESS.withName("GetDevice"), // IOReturn (*GetDevice)(void *self, io_service_t *device);
+ ADDRESS.withName("SetAlternateInterface"), // IOReturn (*SetAlternateInterface)(void *self, UInt8 alternateSetting);
+ ADDRESS.withName("GetBusFrameNumber"), // IOReturn (*GetBusFrameNumber)(void *self, UInt64 *frame, AbsoluteTime *atTime);
+ ADDRESS.withName("ControlRequest"), // IOReturn (*ControlRequest)(void *self, UInt8 pipeRef, IOUSBDevRequest *req);
+ ADDRESS.withName("ControlRequestAsync"), // IOReturn (*ControlRequestAsync)(void *self, UInt8 pipeRef, IOUSBDevRequest *req, IOAsyncCallback1 callback, void *refCon);
+ ADDRESS.withName("GetPipeProperties"), // IOReturn (*GetPipeProperties)(void *self, UInt8 pipeRef, UInt8 *direction, UInt8 *number, UInt8 *transferType, UInt16 *maxPacketSize, UInt8 *interval);
+ ADDRESS.withName("GetPipeStatus"), // IOReturn (*GetPipeStatus)(void *self, UInt8 pipeRef);
+ ADDRESS.withName("AbortPipe"), // IOReturn (*AbortPipe)(void *self, UInt8 pipeRef);
+ ADDRESS.withName("ResetPipe"), // IOReturn (*ResetPipe)(void *self, UInt8 pipeRef);
+ ADDRESS.withName("ClearPipeStall"), // IOReturn (*ClearPipeStall)(void *self, UInt8 pipeRef);
+ ADDRESS.withName("ReadPipe"), // IOReturn (*ReadPipe)(void *self, UInt8 pipeRef, void *buf, UInt32 *size);
+ ADDRESS.withName("WritePipe"), // IOReturn (*WritePipe)(void *self, UInt8 pipeRef, void *buf, UInt32 size);
+ ADDRESS.withName("ReadPipeAsync"), // IOReturn (*ReadPipeAsync)(void *self, UInt8 pipeRef, void *buf, UInt32 size, IOAsyncCallback1 callback, void *refcon);
+ ADDRESS.withName("WritePipeAsync"), // IOReturn (*WritePipeAsync)(void *self, UInt8 pipeRef, void *buf, UInt32 size, IOAsyncCallback1 callback, void *refcon);
+ ADDRESS.withName("ReadIsochPipeAsync"), // IOReturn (*ReadIsochPipeAsync)(void *self, UInt8 pipeRef, void *buf, UInt64 frameStart, UInt32 numFrames, IOUSBIsocFrame *frameList, IOAsyncCallback1 callback, void *refcon);
+ ADDRESS.withName("WriteIsochPipeAsync"), // IOReturn (*WriteIsochPipeAsync)(void *self, UInt8 pipeRef, void *buf, UInt64 frameStart, UInt32 numFrames, IOUSBIsocFrame *frameList, IOAsyncCallback1 callback, void *refcon);
+ ADDRESS.withName("ControlRequestTO"), // IOReturn (*ControlRequestTO)(void *self, UInt8 pipeRef, IOUSBDevRequestTO *req);
+ ADDRESS.withName("ControlRequestAsyncTO"), // IOReturn (*ControlRequestAsyncTO)(void *self, UInt8 pipeRef, IOUSBDevRequestTO *req, IOAsyncCallback1 callback, void *refCon);
+ ADDRESS.withName("ReadPipeTO"), // IOReturn (*ReadPipeTO)(void *self, UInt8 pipeRef, void *buf, UInt32 *size, UInt32 noDataTimeout, UInt32 completionTimeout);
+ ADDRESS.withName("WritePipeTO"), // IOReturn (*WritePipeTO)(void *self, UInt8 pipeRef, void *buf, UInt32 size, UInt32 noDataTimeout, UInt32 completionTimeout);
+ ADDRESS.withName("ReadPipeAsyncTO"), // IOReturn (*ReadPipeAsyncTO)(void *self, UInt8 pipeRef, void *buf, UInt32 size, UInt32 noDataTimeout, UInt32 completionTimeout, IOAsyncCallback1 callback, void *refcon);
+ ADDRESS.withName("WritePipeAsyncTO"), // IOReturn (*WritePipeAsyncTO)(void *self, UInt8 pipeRef, void *buf, UInt32 size, UInt32 noDataTimeout, UInt32 completionTimeout, IOAsyncCallback1 callback, void *refcon);
+ ADDRESS.withName("USBInterfaceGetStringIndex"), // IOReturn (*USBInterfaceGetStringIndex)(void *self, UInt8 *si);
+ ADDRESS.withName("USBInterfaceOpenSeize"), // IOReturn (*USBInterfaceOpenSeize)(void *self);
+ ADDRESS.withName("ClearPipeStallBothEnds"), // IOReturn (*ClearPipeStallBothEnds)(void *self, UInt8 pipeRef);
+ ADDRESS.withName("SetPipePolicy"), // IOReturn (*SetPipePolicy)(void *self, UInt8 pipeRef, UInt16 maxPacketSize, UInt8 maxInterval);
+ ADDRESS.withName("GetBandwidthAvailable"), // IOReturn (*GetBandwidthAvailable)(void *self, UInt32 *bandwidth);
+ ADDRESS.withName("GetEndpointProperties"), // IOReturn (*GetEndpointProperties)(void *self, UInt8 alternateSetting, UInt8 endpointNumber, UInt8 direction, UInt8 *transferType, UInt16 *maxPacketSize, UInt8 *interval);
+ ADDRESS.withName("LowLatencyReadIsochPipeAsync"), // IOReturn (*LowLatencyReadIsochPipeAsync)(void *self, UInt8 pipeRef, void *buf, UInt64 frameStart, UInt32 numFrames, UInt32 updateFrequency, IOUSBLowLatencyIsocFrame *frameList, IOAsyncCallback1 callback, void *refcon);
+ ADDRESS.withName("LowLatencyWriteIsochPipeAsync"), // IOReturn (*LowLatencyWriteIsochPipeAsync)(void *self, UInt8 pipeRef, void *buf, UInt64 frameStart, UInt32 numFrames, UInt32 updateFrequency, IOUSBLowLatencyIsocFrame *frameList, IOAsyncCallback1 callback, void *refcon);
+ ADDRESS.withName("LowLatencyCreateBuffer"), // IOReturn (*LowLatencyCreateBuffer)(void * self, void **buffer, IOByteCount size, UInt32 bufferType);
+ ADDRESS.withName("LowLatencyDestroyBuffer"), // IOReturn (*LowLatencyDestroyBuffer) (void * self, void * buffer );
+ ADDRESS.withName("GetBusMicroFrameNumber"), // IOReturn (*GetBusMicroFrameNumber)(void *self, UInt64 *microFrame, AbsoluteTime *atTime);
+ ADDRESS.withName("GetFrameListTime"), // IOReturn (*GetFrameListTime)(void *self, UInt32 *microsecondsInFrame);
+ ADDRESS.withName("GetIOUSBLibVersion"), // IOReturn (*GetIOUSBLibVersion)(void *self, NumVersion *ioUSBLibVersion, NumVersion *usbFamilyVersion);
+ ADDRESS.withName("FindNextAssociatedDescriptor"), // IOUSBDescriptorHeader * (*FindNextAssociatedDescriptor)(void *self, const void *currentDescriptor, UInt8 descriptorType);
+ ADDRESS.withName("FindNextAltInterface"), // IOUSBDescriptorHeader * (*FindNextAltInterface)(void *self, const void *current, IOUSBFindInterfaceRequest *request);
+ ADDRESS.withName("GetBusFrameNumberWithTime"), // IOReturn (*GetBusFrameNumberWithTime)(void *self, UInt64 *frame, AbsoluteTime *atTime);
+ ADDRESS.withName("GetPipePropertiesV2"), // IOReturn (*GetPipePropertiesV2)(void *self, UInt8 pipeRef, UInt8 *direction, UInt8 *number, UInt8 *transferType, UInt16 *maxPacketSize, UInt8 *interval, UInt8 *maxBurst, UInt8 *mult, UInt16 *bytesPerInterval);
+ ADDRESS.withName("GetPipePropertiesV3"), // IOReturn (*GetPipePropertiesV3)(void *self, UInt8 pipeRef, IOUSBEndpointProperties *properties);
+ ADDRESS.withName("GetEndpointPropertiesV3"), // IOReturn (*GetEndpointPropertiesV3)(void *self, IOUSBEndpointProperties *properties);
+ ADDRESS.withName("SupportsStreams"), // IOReturn (*SupportsStreams)(void *self, UInt8 pipeRef, UInt32 *supportsStreams);
+ ADDRESS.withName("CreateStreams"), // IOReturn (*CreateStreams)(void *self, UInt8 pipeRef, UInt32 streamID);
+ ADDRESS.withName("GetConfiguredStreams"), // IOReturn (*GetConfiguredStreams)(void *self, UInt8 pipeRef, UInt32 *configuredStreams);
+ ADDRESS.withName("ReadStreamsPipeTO"), // IOReturn (*ReadStreamsPipeTO)(void *self, UInt8 pipeRef, UInt32 streamID, void *buf, UInt32 *size, UInt32 noDataTimeout, UInt32 completionTimeout);
+ ADDRESS.withName("WriteStreamsPipeTO"), // IOReturn (*WriteStreamsPipeTO)(void *self, UInt8 pipeRef, UInt32 streamID, void *buf, UInt32 size, UInt32 noDataTimeout, UInt32 completionTimeout);
+ ADDRESS.withName("ReadStreamsPipeAsyncTO"), // IOReturn (*ReadStreamsPipeAsyncTO)(void *self, UInt8 pipeRef, UInt32 streamID, void *buf, UInt32 size, UInt32 noDataTimeout, UInt32 completionTimeout, IOAsyncCallback1 callback, void *refcon);
+ ADDRESS.withName("WriteStreamsPipeAsyncTO"), // IOReturn (*WriteStreamsPipeAsyncTO)(void *self, UInt8 pipeRef, UInt32 streamID, void *buf, UInt32 size, UInt32 noDataTimeout, UInt32 completionTimeout, IOAsyncCallback1 callback, void *refcon);
+ ADDRESS.withName("AbortStreamsPipe"), // IOReturn (*AbortStreamsPipe)(void *self, UInt8 pipeRef, UInt32 streamID);
+ ADDRESS.withName("RegisterForNotification"), // IOReturn (*RegisterForNotification)(void * self, UInt64 notificationMask, IOAsyncCallback2 callback, void *refCon, UInt64 *pRegistrationToken);
+ ADDRESS.withName("UnregisterNotification"), // IOReturn (*UnregisterNotification)(void *self, UInt64 registrationToken);
+ ADDRESS.withName("AcknowledgeNotification"), // IOReturn (*AcknowledgeNotification)(void *self, UInt64 notificationToken);
+ ADDRESS.withName("RegisterDriver") // IOReturn (*RegisterDriver)(void *self);
+ );
+
+ /**
+ * Looks up the address of the specified virtual function in the {@code IOUSBInterface} object
+ * @param thisPointer pointer to pointer to object
+ * @param varHandle variable handle to virtual function
+ * @param session memory session
+ * @return function address
+ */
+ private static Addressable IOUSBInterfaceFunctionAddress(MemoryAddress thisPointer, VarHandle varHandle, MemorySession session) {
var seg = MemorySegment.ofAddress(thisPointer, ADDRESS.byteSize(), session);
var thisValue = seg.get(ADDRESS, 0);
var obj = MemorySegment.ofAddress(thisValue, IOUSBInterface$Struct.byteSize(), session);
return (MemoryAddress) varHandle.get(obj);
}
- // IOReturn (*USBInterfaceOpen)(void *self);
+ // IOReturn (*USBInterfaceOpen)(void *self);;
+ private static final VarHandle IOUSBInterface_USBInterfaceOpen = IOUSBInterface$Struct.varHandle(groupElement("USBInterfaceOpen"));
+ private static final MethodHandle USBInterfaceOpen$Func = linker.downcallHandle(
+ FunctionDescriptor.of(JAVA_INT, ADDRESS)
+ );
public static int USBInterfaceOpen(MemoryAddress thisPointer) {
try (var session = MemorySession.openShared()) {
- var funcPtr = IOUSBInterface$VirtFunc(thisPointer, IOUSBInterface_USBInterfaceOpen, session);
+ var funcPtr = IOUSBInterfaceFunctionAddress(thisPointer, IOUSBInterface_USBInterfaceOpen, session);
return (int) USBInterfaceOpen$Func.invokeExact(funcPtr, (Addressable) thisPointer);
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
- // IOReturn (*USBInterfaceClose)(void *self);
+ // IOReturn (*USBInterfaceClose)(void *self);;
+ private static final VarHandle IOUSBInterface_USBInterfaceClose = IOUSBInterface$Struct.varHandle(groupElement("USBInterfaceClose"));
+ private static final MethodHandle USBInterfaceClose$Func = linker.downcallHandle(
+ FunctionDescriptor.of(JAVA_INT, ADDRESS)
+ );
public static int USBInterfaceClose(MemoryAddress thisPointer) {
try (var session = MemorySession.openShared()) {
- var funcPtr = IOUSBInterface$VirtFunc(thisPointer, IOUSBInterface_USBInterfaceClose, session);
+ var funcPtr = IOUSBInterfaceFunctionAddress(thisPointer, IOUSBInterface_USBInterfaceClose, session);
return (int) USBInterfaceClose$Func.invokeExact(funcPtr, (Addressable) thisPointer);
} catch (Throwable e) {
throw new RuntimeException(e);
@@ -440,9 +328,13 @@ public static int USBInterfaceClose(MemoryAddress thisPointer) {
}
// IOReturn (*GetInterfaceNumber)(void *self, UInt8 *intfNumber);
+ private static final VarHandle IOUSBInterface_GetInterfaceNumber = IOUSBInterface$Struct.varHandle(groupElement("GetInterfaceNumber"));
+ private static final MethodHandle GetInterfaceNumber$Func = linker.downcallHandle(
+ FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS)
+ );
public static int GetInterfaceNumber(MemoryAddress thisPointer, Addressable intfNumberHolder) {
try (var session = MemorySession.openShared()) {
- var funcPtr = IOUSBInterface$VirtFunc(thisPointer, IOUSBInterface_GetInterfaceNumber, session);
+ var funcPtr = IOUSBInterfaceFunctionAddress(thisPointer, IOUSBInterface_GetInterfaceNumber, session);
return (int) GetInterfaceNumber$Func.invokeExact(funcPtr, (Addressable) thisPointer, intfNumberHolder);
} catch (Throwable e) {
throw new RuntimeException(e);
@@ -450,9 +342,13 @@ public static int GetInterfaceNumber(MemoryAddress thisPointer, Addressable intf
}
// IOReturn (*GetNumEndpoints)(void *self, UInt8 *intfNumEndpoints);
+ private static final VarHandle IOUSBInterface_GetNumEndpoints = IOUSBInterface$Struct.varHandle(groupElement("GetNumEndpoints"));
+ private static final MethodHandle GetNumEndpoints$Func = linker.downcallHandle(
+ FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS)
+ );
public static int GetNumEndpoints(MemoryAddress thisPointer, Addressable intfNumEndpointsHolder) {
try (var session = MemorySession.openShared()) {
- var funcPtr = IOUSBInterface$VirtFunc(thisPointer, IOUSBInterface_GetNumEndpoints, session);
+ var funcPtr = IOUSBInterfaceFunctionAddress(thisPointer, IOUSBInterface_GetNumEndpoints, session);
return (int) GetNumEndpoints$Func.invokeExact(funcPtr, (Addressable) thisPointer, intfNumEndpointsHolder);
} catch (Throwable e) {
throw new RuntimeException(e);
@@ -460,11 +356,15 @@ public static int GetNumEndpoints(MemoryAddress thisPointer, Addressable intfNum
}
// IOReturn (*GetPipeProperties)(void *self, UInt8 pipeRef, UInt8 *direction, UInt8 *number, UInt8 *transferType, UInt16 *maxPacketSize, UInt8 *interval);
+ private static final VarHandle IOUSBInterface_GetPipeProperties = IOUSBInterface$Struct.varHandle(groupElement("GetPipeProperties"));
+ private static final MethodHandle GetPipeProperties$Func = linker.downcallHandle(
+ FunctionDescriptor.of(JAVA_INT, ADDRESS, JAVA_BYTE, ADDRESS, ADDRESS, ADDRESS, ADDRESS, ADDRESS)
+ );
public static int GetPipeProperties(MemoryAddress thisPointer, byte pipeRef, Addressable directionHolder,
Addressable numberHolder, Addressable transferTypeHolder,
Addressable maxPacketSizeHolder, Addressable intervalHolder) {
try (var session = MemorySession.openShared()) {
- var funcPtr = IOUSBInterface$VirtFunc(thisPointer, IOUSBInterface_GetPipeProperties, session);
+ var funcPtr = IOUSBInterfaceFunctionAddress(thisPointer, IOUSBInterface_GetPipeProperties, session);
return (int) GetPipeProperties$Func.invokeExact(funcPtr, (Addressable) thisPointer, pipeRef, directionHolder,
numberHolder, transferTypeHolder, maxPacketSizeHolder, intervalHolder);
} catch (Throwable e) {
@@ -473,9 +373,13 @@ public static int GetPipeProperties(MemoryAddress thisPointer, byte pipeRef, Add
}
// IOReturn (*ReadPipe)(void *self, UInt8 pipeRef, void *buf, UInt32 *size);
+ private static final VarHandle IOUSBInterface_ReadPipe = IOUSBInterface$Struct.varHandle(groupElement("ReadPipe"));
+ private static final MethodHandle ReadPipe$Func = linker.downcallHandle(
+ FunctionDescriptor.of(JAVA_INT, ADDRESS, JAVA_BYTE, ADDRESS, ADDRESS)
+ );
public static int ReadPipe(MemoryAddress thisPointer, byte pipeRef, Addressable buf, Addressable sizeHolder) {
try (var session = MemorySession.openShared()) {
- var funcPtr = IOUSBInterface$VirtFunc(thisPointer, IOUSBInterface_ReadPipe, session);
+ var funcPtr = IOUSBInterfaceFunctionAddress(thisPointer, IOUSBInterface_ReadPipe, session);
return (int) ReadPipe$Func.invokeExact(funcPtr, (Addressable) thisPointer, pipeRef, buf, sizeHolder);
} catch (Throwable e) {
throw new RuntimeException(e);
@@ -483,12 +387,44 @@ public static int ReadPipe(MemoryAddress thisPointer, byte pipeRef, Addressable
}
// IOReturn (*WritePipe)(void *self, UInt8 pipeRef, void *buf, UInt32 size);
+ private static final VarHandle IOUSBInterface_WritePipe = IOUSBInterface$Struct.varHandle(groupElement("WritePipe"));
+ private static final MethodHandle WritePipe$Func = linker.downcallHandle(
+ FunctionDescriptor.of(JAVA_INT, ADDRESS, JAVA_BYTE, ADDRESS, JAVA_INT)
+ );
public static int WritePipe(MemoryAddress thisPointer, byte pipeRef, Addressable buf, int size) {
try (var session = MemorySession.openShared()) {
- var funcPtr = IOUSBInterface$VirtFunc(thisPointer, IOUSBInterface_WritePipe, session);
+ var funcPtr = IOUSBInterfaceFunctionAddress(thisPointer, IOUSBInterface_WritePipe, session);
return (int) WritePipe$Func.invokeExact(funcPtr, (Addressable) thisPointer, pipeRef, buf, size);
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
+
+ // typedef struct {
+ // UInt8 bmRequestType;
+ // UInt8 bRequest;
+ // UInt16 wValue;
+ // UInt16 wIndex;
+ // UInt16 wLength;
+ // void* pData;
+ // UInt32 wLenDone;
+ //} IOUSBDevRequest;
+ public static final GroupLayout IOUSBDevRequest$Struct = structLayout(
+ JAVA_BYTE.withName("bmRequestType"),
+ JAVA_BYTE.withName("bRequest"),
+ JAVA_SHORT.withName("wValue"),
+ JAVA_SHORT.withName("wIndex"),
+ JAVA_SHORT.withName("wLength"),
+ ADDRESS.withName("pData"),
+ JAVA_INT.withName("wLenDone")
+ );
+
+ public static final VarHandle IOUSBDevRequest_bmRequestType = IOUSBDevRequest$Struct.varHandle(groupElement("bmRequestType"));
+ public static final VarHandle IOUSBDevRequest_bRequest = IOUSBDevRequest$Struct.varHandle(groupElement("bRequest"));
+ public static final VarHandle IOUSBDevRequest_wValue = IOUSBDevRequest$Struct.varHandle(groupElement("wValue"));
+ public static final VarHandle IOUSBDevRequest_wIndex = IOUSBDevRequest$Struct.varHandle(groupElement("wIndex"));
+ public static final VarHandle IOUSBDevRequest_wLength = IOUSBDevRequest$Struct.varHandle(groupElement("wLength"));
+ public static final VarHandle IOUSBDevRequest_pData = IOUSBDevRequest$Struct.varHandle(groupElement("pData"));
+ public static final VarHandle IOUSBDevRequest_wLenDone = IOUSBDevRequest$Struct.varHandle(groupElement("wLenDone"));
+
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/Kernel.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/Kernel.java
deleted file mode 100644
index f7c8103d..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/Kernel.java
+++ /dev/null
@@ -1,41 +0,0 @@
-//
-// Java Does USB
-// Copyright (c) 2022 Manuel Bleichenbacher
-// Licensed under MIT License
-// https://opensource.org/licenses/MIT
-//
-
-package net.codecrete.usb.macos;
-
-import java.lang.foreign.Addressable;
-import java.lang.foreign.FunctionDescriptor;
-import java.lang.foreign.Linker;
-import java.lang.foreign.MemorySession;
-import java.lang.invoke.MethodHandle;
-
-import static java.lang.foreign.ValueLayout.ADDRESS;
-import static java.lang.foreign.ValueLayout.JAVA_INT;
-
-/**
- * MacOS Kernel functions, and a workaround to load Cocoa frameworks
- */
-public class Kernel {
- private static final MethodHandle mach_error;
-
- static {
- var linker = Linker.nativeLinker();
- var defaultLookup = linker.defaultLookup();
- mach_error = linker.downcallHandle(
- defaultLookup.lookup("mach_error").get(),
- FunctionDescriptor.ofVoid(ADDRESS, JAVA_INT)
- );
- }
-
- public static void mach_error(String str, int errorValue) {
- try (var session = MemorySession.openConfined()) {
- mach_error.invokeExact((Addressable) session.allocateUtf8String(str), errorValue);
- } catch (Throwable t) {
- throw new RuntimeException(t);
- }
- }
-}
From b411ba81289d2524ee733f88c2882d58e0aa8127 Mon Sep 17 00:00:00 2001
From: Manuel Bleichenbacher
Date: Sat, 27 Aug 2022 16:17:23 +0200
Subject: [PATCH 014/433] Convert test device from STM32cube to libopencm3
framework
---
README.md | 10 +-
.../net/codecrete/usb/macos/IoKitUSB.java | 2 +-
stm32-loopback/.vscode/settings.json | 16 --
stm32-loopback/bin/firmware.bin | Bin 13416 -> 0 bytes
stm32-loopback/include/circ_buf.h | 55 ----
stm32-loopback/include/interrupts.h | 34 ---
stm32-loopback/include/main.h | 29 --
stm32-loopback/include/usbd_conf.h | 42 ---
stm32-loopback/include/usbd_desc.h | 28 --
stm32-loopback/include/usbd_loopback.h | 33 ---
stm32-loopback/src/circ_buf.c | 107 -------
stm32-loopback/src/interrupts.c | 51 ----
stm32-loopback/src/main.c | 105 -------
stm32-loopback/src/usbd_desc.c | 149 ----------
stm32-loopback/src/usbd_impl.c | 211 --------------
stm32-loopback/src/usbd_loopback.c | 266 ------------------
.../loopback-stm32}/.clang-format | 0
.../loopback-stm32}/.gitignore | 0
.../loopback-stm32}/.vscode/extensions.json | 0
.../loopback-stm32}/README.md | 2 +-
test-devices/loopback-stm32/bin/firmware.bin | Bin 0 -> 6328 bytes
.../loopback-stm32}/bin/save_bin.sh | 0
.../loopback-stm32}/bin/upload_firmware.sh | 0
.../loopback-stm32/include/circ_buf.h | 155 ++++++++++
test-devices/loopback-stm32/include/common.h | 32 +++
.../loopback-stm32/include/usb_descriptor.h | 30 ++
test-devices/loopback-stm32/include/wcid.h | 17 ++
.../loopback-stm32}/platformio.ini | 2 +-
test-devices/loopback-stm32/src/common.cpp | 37 +++
test-devices/loopback-stm32/src/main.cpp | 197 +++++++++++++
.../loopback-stm32/src/usb_descriptor.cpp | 138 +++++++++
test-devices/loopback-stm32/src/wcid.cpp | 81 ++++++
32 files changed, 695 insertions(+), 1134 deletions(-)
delete mode 100644 stm32-loopback/.vscode/settings.json
delete mode 100755 stm32-loopback/bin/firmware.bin
delete mode 100644 stm32-loopback/include/circ_buf.h
delete mode 100644 stm32-loopback/include/interrupts.h
delete mode 100644 stm32-loopback/include/main.h
delete mode 100644 stm32-loopback/include/usbd_conf.h
delete mode 100644 stm32-loopback/include/usbd_desc.h
delete mode 100644 stm32-loopback/include/usbd_loopback.h
delete mode 100644 stm32-loopback/src/circ_buf.c
delete mode 100644 stm32-loopback/src/interrupts.c
delete mode 100644 stm32-loopback/src/main.c
delete mode 100644 stm32-loopback/src/usbd_desc.c
delete mode 100644 stm32-loopback/src/usbd_impl.c
delete mode 100644 stm32-loopback/src/usbd_loopback.c
rename {stm32-loopback => test-devices/loopback-stm32}/.clang-format (100%)
rename {stm32-loopback => test-devices/loopback-stm32}/.gitignore (100%)
rename {stm32-loopback => test-devices/loopback-stm32}/.vscode/extensions.json (100%)
rename {stm32-loopback => test-devices/loopback-stm32}/README.md (93%)
create mode 100755 test-devices/loopback-stm32/bin/firmware.bin
rename {stm32-loopback => test-devices/loopback-stm32}/bin/save_bin.sh (100%)
rename {stm32-loopback => test-devices/loopback-stm32}/bin/upload_firmware.sh (100%)
create mode 100644 test-devices/loopback-stm32/include/circ_buf.h
create mode 100644 test-devices/loopback-stm32/include/common.h
create mode 100644 test-devices/loopback-stm32/include/usb_descriptor.h
create mode 100644 test-devices/loopback-stm32/include/wcid.h
rename {stm32-loopback => test-devices/loopback-stm32}/platformio.ini (73%)
create mode 100644 test-devices/loopback-stm32/src/common.cpp
create mode 100644 test-devices/loopback-stm32/src/main.cpp
create mode 100644 test-devices/loopback-stm32/src/usb_descriptor.cpp
create mode 100644 test-devices/loopback-stm32/src/wcid.cpp
diff --git a/README.md b/README.md
index 6d6d3c28..20b6879f 100644
--- a/README.md
+++ b/README.md
@@ -17,7 +17,7 @@ It has been tested with Azul Zulu 19.0.75 EA 33.
## Testing
-In order to run the unit tests, a special test device must be connected to the computer. See the [stm32-loopback](stm32-loopback) directory.
+In order to run the unit tests, a special test device must be connected to the computer. See the [loopback-stm32](test-devices/loopback-stm32) directory.
Tests can be run from the command line:
@@ -81,7 +81,7 @@ No special considerations apply. Using this library, a Java application can conn
### Linux
-*libsystemd* is used to discover USB devices. So it only runs on Linux distributions with systemd and the related library.
+*libsystemd* is used to discover USB devices. So it only runs on Linux distributions with systemd and the related library. The majority of Linux distributions suitable for desktop computing (as opposed to distributions optimized for containers) fulfills this.
Similar to macOS, a Java application can connect to any USB device and claim any interfaces that aren't claimed by an operating system driver or another application.
@@ -93,18 +93,18 @@ Create a file called `/etc/udev/rules.d/80-javadoesusb-udev.rules` with the belo
SUBSYSTEM=="usb", ATTRS{idVendor}=="cafe", MODE="0666"
```
-This adds the rule to assign permission mode 0666 to all USB devices with vendor ID 0xCAFE. This non-register vendor ID is used by test device.
+This adds the rule to assign permission mode 0666 to all USB devices with vendor ID `0xCAFE`. This non-register vendor ID is used by test device.
### Windows
-The Windows driver model is more rigid than the one in macOS or Linux. It's not possible to open any USB device by default. Instead, only devices using the WinUSB driver can be opened. This even applies to device with no installed driver.
+The Windows driver model is more rigid than the ones of macOS or Linux. It's not possible to open any USB device by default. Instead, only devices using the WinUSB driver can be opened. This even applies to devices with no installed driver.
USB devices can implement certain control requests to instruct Windows to automatically install the WinUSB driver (search for WCID or Microsoft OS Compatibility Descriptors). The driver can also be manually installed or replaced using a software called [Zadig](https://zadig.akeo.ie/).
The test device implements these control requests. So the driver is installed automatically.
-This library does not yet run reliably on Windows as the Foreign Function & Memory API as the Java VM sometimes overwrites the last error code, which is not just needed in error cases. It works incorrectly when run in the debugger and sometimes even without the debugger. A future version of the Foreign Function & Memory API will hopefully provide a way to save the last error code. The developers are aware of the issue.
+This library does not yet run reliably on Windows as Java VM sometimes overwrites the last error code, which is not just needed in error cases. It works incorrectly when run in the debugger and sometimes even without the debugger. A future version of the Foreign Function & Memory API will hopefully provide a way to save the last error code. The developers are aware of the issue.
The library has not been tested on Windows for ARM64. It might or might not work.
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKitUSB.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKitUSB.java
index 2d6fa7a1..49b841f3 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKitUSB.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/IoKitUSB.java
@@ -418,7 +418,7 @@ public static int WritePipe(MemoryAddress thisPointer, byte pipeRef, Addressable
ADDRESS.withName("pData"),
JAVA_INT.withName("wLenDone")
);
-
+
public static final VarHandle IOUSBDevRequest_bmRequestType = IOUSBDevRequest$Struct.varHandle(groupElement("bmRequestType"));
public static final VarHandle IOUSBDevRequest_bRequest = IOUSBDevRequest$Struct.varHandle(groupElement("bRequest"));
public static final VarHandle IOUSBDevRequest_wValue = IOUSBDevRequest$Struct.varHandle(groupElement("wValue"));
diff --git a/stm32-loopback/.vscode/settings.json b/stm32-loopback/.vscode/settings.json
deleted file mode 100644
index abad96db..00000000
--- a/stm32-loopback/.vscode/settings.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- "files.associations": {
- "usbd_core.h": "c",
- "usbd_conf.h": "c",
- "usbd_def.h": "c",
- "usbd_ioreq.h": "c",
- "usbd_ctlreq.h": "c",
- "main.h": "c",
- "stm32f1xx_hal.h": "c",
- "stm32f1xx.h": "c",
- "stm32f1xx_ll_utils.h": "c",
- "usbd_desc.h": "c",
- "usbd_loopback.h": "c",
- "circ_buf.h": "c"
- }
-}
\ No newline at end of file
diff --git a/stm32-loopback/bin/firmware.bin b/stm32-loopback/bin/firmware.bin
deleted file mode 100755
index 9acc0506b15fbab7ab4ee265e99c259f5bf6a02c..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 13416
zcmcJ04OkS{x$rqNvp>Kh3yTecCbK)D%dR%KsG(^h>+UijpcqJ+1e-4lYPw*4HZf_p
zP40CR6EP;KG1_ZD8=If6CN=`Aq@tlqmE5)(n_b0Q)FhIhI*Ls?=#m{F?B4gxE(DX@
zw)c6y51+Gh=A8Gu|L2`^-g87t5&NPIX{k;NhuO-@l4bP2G
zK7z6TFUzz4A8?NG_cd{@dA(QG4(dBp6`Zf2lPNc}Go`IpkbpVPtMA%{5KDkR1zEKn
zba_rYy@*!&wOyqBRp=*ug&mX1ReYAOGW@gE`$nWIDP?+3+sG9ONxNi*zpFECc2Xb3
z=kb+NEFVd?%Ph~7PjeS`VfITA(6Bq8FiATTWwRkzkCHsA0qc
zO_s9LWlVXxC&!oKGPu1ZD3GO9cw}*TmS^m}u!G@akuPE@e)-hv15A02@6)VUA{L1ok@~gjx@=>zKHmn|^
zLUdc#1?lIN64q*m)iO1pr8XD;duXvIV>Xgr7trN(0tK~S2|w;b@N5z={B9R2rL?4&
z<%PgHUOgxjYi|w8sBKH20|jNK?M;+4tdgw*S}ilI8fpSrndH&|mFlRBmWE_zSGFYF
zyEy2ooFUQLu6pgDP+BZuRaY(4hlD~E)bTd8M5o}Ll>?hn`eg0Wq~VmSxdTZ_g^PDP
zmIqZs!phx_+QjqT#8VfbbD3P#aLQ2eK$7Z@Flw47J1i7s1|~bVIj6brfj5+RyT`qg
z^xY8e+v)y*^ue3OnL9vHXWV%HLn1xf6ilD}bm(0VGk1fSUD@SG3TE`3lkeZWxR?nh
z4GG^{T)Zayc)=;6_g;~ievgQ9e=XwN*F-A!6%jGmj`WlrY2k^CdW7acu|Y|PV$vtK<63V?5;G!7
z;K3W(^!ql;uiI!TM&)!0@@^9)WnazZY3@P(4q2bF9{R9!_tmuHY5!^UB1FAL7h2rtp3K
z^~Llcrl<9#9e}r17$gxhYPhTf{@H%-_`eE4zMHEmEbq24JhtkC
zI2UBCLeTrMoX4{~k_JWz>;of+T`%vZ3cDzX8vt+8cVG*{rv$NyXb14>$*AfCoL+&O
zeNn1p_$S*)&(aaZB%L}ZFMScpM%L3NyYh1wH2Aha@Gl%$s7gC!^02%g+PScxM1_~3
zPDwAy$jCxW>4_1@StBKk79bOFP7*x`9O=7$)*`%K>XXvp_Ymr0yWIOASF!c&NN!cwpE^S3;zFbJE4K4heqLTPOrS)
zn8zDjJy0idRK<**l%^b2(U5;{JILKD`)+IT2tLL|c!ilo7(DuCi=o~a8+`p%j=28q?OW(PYq$1yn
zw*)KS4pN0cJ}gnAZ}vYgubM+(DXU%DC|nm7$|?sAt3t9cM=%busYh^nwrhC#&+a$646eslVCi`|
z|F3bKT_@R-!2=(x95|v&zF!j-N|5vki3+;{{$7`EkkT!Xr*^-4B}uoncouN;@+BRW
zyuxgvM%0e<`%&JVp>1*=i!2L5L>6?JS(xt1!AHku)6uG@q|KXFlqZjm(*
z)#I^b7SzdmJf4s@MRUCEIRsJlXZ<&HHp&&=I{uW1Oi*K+SKQ3MCoZt)`YH#iCY^xj
zGHDP`svLOkyEhC!7lrZtABxa({RxOQlLli8N}*>^#5bNC(|*ZyF5rjFz=x{-q|C&C
z|9!BcdV&>q1mZS?*+>y9lG$kAMQmA=pA`|?UO(s
zd649a=JVbzGe@B55sX9fdh9I$47sEQq-D^Io{MQ5HUal{tcR$u9(28M$}21GTd|%*
zBEVr%a1?epAp&YtI~@#f?jur>?@u;pj4t?n7Us&mm`n9;A`+RJ9aDltKP-%Xax}M-
ztXxR_QbIP^(VEJgL^j%mT_BmUU&QPckZw?n(@CS6fzAwt4p60tbtX^H9Li1hKAX@U
zX&E}D%2lve|AzKH1sa!uh9v4igG7Ry0MP;-VHPqY7}>M5u;bnDebJxYNv;09
zfLO4BDMv@G#%rBxBciut_Qfj;RlK$nv$yoqp0gT#uhsLC<{tQ+qCtaO1*@k9p1%_=
z)FZQ9nza_O=Kh~oEceioj%KWyV7#WaCWV%JKBU#BIL{9HgHx+K$a*H!E3WeF8xo2#
zLY&7L7793bH1b(Y&2ygZ^s(M(M2rbJE6kD8G)s|{=-QS}&I79rfK#3vfj_0dzew*p
z6^*=?fIlzp8`^av=b=M@6`GIxYGl7XXw;k&eNiyPFd@*^(o+~
zp`Mdu+BtBT=G;$-min6VhIVYq2CB^p)t5AX11`4$RSLM=Ba)tHS=hQ7f?(7k^;|Z
zRo1CX9&DWv;u@S1rn$Ok+05taQnaySIW;UIY@Ru
zxS2~RbAj6$ibi^)8t|AG@eRG!2I5VsP@U&>5A2F;$<8`=eM6lm#c2vZnqhD*cVmvo
zb115U5zV-0X!qV|WPj8S_WR=WvGdW$-e@<}|8n{rsP9&wTJV~oZ2+7Y|V}};fMFGg1T4Vot+iH?C$e~e>d=--;q_mp^f?tJ*Zci_$<%e9&G`A
zc#k8KkA&=(F_*sRO_|9rCvyd)x-N9&N~1%)n{u6{Gi3cN-Klar1eOjA7{<<2sR^w3W
z?y4Ghjc1pKtehxkjk{B<^GsWUEd`$J5bXPkUJI`F#Qlk;4bIhIsq>>6ezm8LXo%i-
zXNTfThQSt1lc`%>OAlo>{)w79tYpt=gT@k7o8x
zm}?J=lDXEW`ZLV6AB~R9H98Ri8$49l{z$XqND#A=%D4u-n_#j(talshPHPUpd|Nz9
zG)U%Ov!)Gj6pzN|-v=TJD1HKS$qw^seH-2_K-P$9LnJ@RRfdZkyC6TZ3-$+Dytkx{
zWIMu7R4-$e>7XrNfda_&ZTb%SH|t?!*9E;Db4nk_w2^0g{L*|fUh2^KXg(iy^?&r4
z!hds^Bripq>ArIpkmOk8;$gjUSx{M=96(I+Z7wU2XV~XCGwrjWWrjWVah(s%woB`T
z<4sF^4`?4i^d%MM|Q?LSg$Pm!m|?g+z#le#HR&Sj7KbUyGZ
z$TdA)Mh##pE3i&tsW^lH5Yt(y3*H_dx~y~j;Lzk{xna3@HZxl{xq9-l;xH%=FIlV&Xa-|96%TC44U2$#>12Cx
z7#9~yf(o!M)%j945?v6jJfMBc&kPAG9zd@FKZ_@{Gec{k^)3Hv)fK)}-~K~HQ};pU
zYfNKyW#2+H7MJ4=_1EPX)9G|#Ek@D#HL{q%TDjvg_JfReDihj__Qk+;u6@NnpjPz{
zsEu22X);()^(_`m=oKQ#7G{g?cJb%1z6~VSxcUy=<7K`S-`j^SD?2qp>Du*uTrRR>
zOZLV0`rQ-q5<)yL0c#;L>UOa1wWH&Dn>bpcTbLHzIT2Z0Ap%?VPsjXF;pyA63}ZZf
zGgksupmf0T^zp2V!O6l~612g-HnA7VhBhPnOUPpUE1WF*UvLuNFO#gzL{8#6uxmMq
z=Y%@Na$mCVaj*i(6OHZE^y51!sV?hE
z3SAi(eb*M+P%|?umlQEYx(!tuYD&VWWJ6WmMliej;+d8Lt>w;YDWKp?`ryfqWzA9(_qDP
zQ-BKikHKE{2U8>JZI#-9ZZLLB$-px+uZY;(O*r%dhjzkYW7PrJ5hwNCsU?|>_{f{8
zOu*mT{yURSsGll}$4$q;2GbV*pG0K7Eg>P3kZ|6&N=PuoBG>&35*8{F&IAc{d=XZ=
zki{;k)*f6omajQjeQ+6(@?dq{#(faozb@w=6LK#5nw(t;Ihll<9pX}urwZgjgRy+a
zfB^FJ!gq>9E|P1S$&yUN3?Io>-Rzo=Tm1V#53xu`^xS#k3oSXs8{+w?iC)0f5ii*1
zCtl$8JqA8dIqm}*#Rm#P2Wr@`Y)1^z9jH1`V-F+yfrJk{6&>?|C&33yb%?X^b6mBx
z#0QY2DE#tXw~u(j%?eJUC5B&MsT|N;r*`G`Esa|(U!Vm4foe|Cj(5xpl-8q)b|iIX
zY1|9!1JA%78JhzM?TmTBZx!t%U!$Fa)x)qhUlW%1g2%X7Lfe6`&DB`-`FU9TKZ$S3_l%>&=+
z!PtD~z*AgUfpNrP;H-s21_E;{_z!_`3_N8DLuOF%GCkn6
z8|1@IWWQ4TGI+az-$*n7ng%ahNHjgt=@^f6jw*)|=^RzHK9djS-9)4(cCLfO58v^hq{V}=
zInIH#V5Pr^IByM{v=PrF-hqK?i+@v<4zfZ0pC;x4e7mF$^6k1utL3lbzspnk^E=OK
zTmhS$n~&wm`BK+SGEQ5emMB
zfo|BVzYT@laUkdO0zZjIGmr7-Tn!`v6@Q^r8>iP?sCn~xsLw}oaOgViQkw&
zfgYgw6>Zs>z9fyG>wzfd+TzA(6xsk|1aF0fQ@jF}^jqEvq0#lO_8x_a?L0%F5p^j~Bqmf6V
znI>e^?S``krIvb$0!sZ+xI|#W(0VpX6ZwY(9Qbo1e$4cE=(aa=bU)1U;*n%^1dEE*5zi?(f8V
za>}9Sw&r>V>~@-Ko9iif;w`wDv@p=pQcv+Ti0t(ao&z;yk-fLHuoNcv23v8OHKwCtn|L`f7x-R53MK333(Mf*enGR&r2Nt~E{ds29Z|AH*1wY7x0B&=+G$^<5Vtu^avdWd`s+AIfwn
z`VOWdnP*CkAgyBWI6D%A3$~W)+f_9gIW%{UAufV`Kd7#BeW+AiH`by{7cU+y6BDNk|f-?u83v!bAr|k#=
zj?u_lQQG{A098)0SwDoEX92IGe>NK17uxHrqp$XS=;6&u9?484AnM0xI>E*uj?(xq0XHmP`i!{X7ryH=zuUDK!Y7
z(dn52@$m2n%SXgV75&5_Cu5kWOJk9{A;(9-NTS=VfHM=u7j`7Wj)s!ll--iTe=n5W
zWWT&H{b`3L)ZCPPsIN(TsHSNOa8lR>?Z&4aNueE0Z+D()Vl0`V%tc5Vftx>)XutgX
zIZr!MpszydQ-^frsf%(vDQ+a48u?7D@!e!e0*s7B9XivbS!A}D17?$%|GPMaHv_*r
zMkw~UNaQ5)J_URicBptX9UEhjNwL4xtuvDKd{S)I3YIT~n@iy3xps~M|AIS)QEho1
zKh68sIyyxI<-Jt*(D
z8QRHw*>6i~@0Qy#;GE1W$UAJYNOhFlrX;thra;gB46@&(plCZ{ku^#m@tXa%luioZ
zay;8hka;*Li}BWF`zJJ68jF*v;foqaxxIXJ1x=#jVD_RD*1J@R(An|1?DcF&rV
z6uH$U37AOqc$Dss-|G58Cc22%*YYyu(CWP-uGz;VWrGg0q3oL+{92Gh&fj
zqZdU2*HUjyz+r$p2WMCx0!;&CwqZ??R|535nkdUHq2NVr)i#IW^c&e!-4uR{A4!LY
z3;1k)3fxMIMcmP?@-7?rzZHkp%eyFV*O7WSX&ItMCeK^h+3ZN}3(DI~FF4dEEWpWY
z!=RHYD}PSx1rE-7tnFJBPH~9kx0eWte|!dU8%YO;Plz`7lD-!bz@t7HJ*M!ytiB+@
zGX*>&_7A}IJ8+uojr-q>blwi%>%F4|ykP8+@4Br=UIFo)@cHT}f=GA3_FC*Qc8GCP*%Bm7?%y9frQIvvxp||xJ
zaZV?dXeX`ri3>d#;Fq`l$sdczqj|ns_j&PX6NWo?KWQaAkz06=w8HuRY1+Cb{6H(7
zM#Ifh#4VJyMTEo2S93%Hhrdr*i@vz0^;i=HaCf(2?ua`mziLZqr=dofm_Z$!&X+e~
z=%ri1S8e7A;}*8Yd%oCv_%yn-cMO(25C!5
zkc@1Ms`>%D3E~8J>t^uQ!mgSoOJ|vy4xVjFfe0Rj?;xyl>jQFH^UNtm;Y$(Uov0Rsq?bOpJ!!csRvPIH{C>Bc71&G9t?_
z6%6!B{?}Gm&z{lS=!@IW2z|&)p
z@(<@E^W^(Lpnv`~=nV?Awu6DM;#M2tNFZOOg{Us*tzq2e7N%UV`U+E{@eMi`}qp7%M$c*LOItPj)>ISzLWrI%tBH
zab-lLdCK*IlG%m#oU0;2y3*7|sb#R*?eD#-XDL(All6?_>dEA?quMdvjq>N%
z3g*t6e^cT27CM}+VjlQFkm;pj2-%}YTmKAcB8tWcF?14xD7cSIFGkgfN4KLnC?Eda
zgv?|JT$%x(_#eJ=(Go)AfA|A@4B;GZ&SRuag+fNc<#{xki?m5IkTwLR1In#XUWD>*
zP_pU&0Ub0aQ7mlr7-1M#R5({@RG6|Oq*1LSk3|-woegDM9_$a{FAtuJpgfj%Cv9VY
Ow@zrggVd*o(SHNbFZo>n
diff --git a/stm32-loopback/include/circ_buf.h b/stm32-loopback/include/circ_buf.h
deleted file mode 100644
index 3fa88648..00000000
--- a/stm32-loopback/include/circ_buf.h
+++ /dev/null
@@ -1,55 +0,0 @@
-//
-// Java Does USB
-// Loopback device for testing
-//
-// Copyright (c) 2022 Manuel Bleichenbacher
-// Licensed under MIT License
-// https://opensource.org/licenses/MIT
-//
-// Circular buffer for raw binary data.
-//
-// The circular buffer allows a reader and writer to
-// use the buffer concurrently.
-//
-
-#ifndef CIRC_BUF_H
-#define CIRC_BUF_H
-
-#include
-
-#define BUF_SIZE 1025
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/// Returns the maximum number of bytes that can be added to the buffer
-int circ_buf_avail_size();
-
-/// Returns the number of bytes in the buffer
-int circ_buf_data_size();
-
-/**
- * Gets the oldest data from the buffer and removes it.
- * @param buf buffer to copy data to
- * @param max_len maximum number of bytes to copy
- * @return the effective number of bytes
- */
-int circ_buf_get_data(uint8_t *buf, int max_len);
-
-/**
- * Adds data to the buffer
- *
- * @param buf the buffer with the data
- * @param len the number of bytes to add
- */
-void circ_buf_add_data(const uint8_t *buf, int len);
-
-/// Resets (empties) the circular buffer
-void circ_buf_reset();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/stm32-loopback/include/interrupts.h b/stm32-loopback/include/interrupts.h
deleted file mode 100644
index f6462198..00000000
--- a/stm32-loopback/include/interrupts.h
+++ /dev/null
@@ -1,34 +0,0 @@
-//
-// Java Does USB
-// Loopback device for testing
-//
-// Copyright (c) 2022 Manuel Bleichenbacher
-// Licensed under MIT License
-// https://opensource.org/licenses/MIT
-//
-// Interrupt handlers
-//
-
-#ifndef __INTERRUPTS_H
-#define __INTERRUPTS_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void NMI_Handler(void);
-void HardFault_Handler(void);
-void MemManage_Handler(void);
-void BusFault_Handler(void);
-void UsageFault_Handler(void);
-void SVC_Handler(void);
-void DebugMon_Handler(void);
-void PendSV_Handler(void);
-void SysTick_Handler(void);
-void USB_LP_CAN1_RX0_IRQHandler(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/stm32-loopback/include/main.h b/stm32-loopback/include/main.h
deleted file mode 100644
index 252cdddb..00000000
--- a/stm32-loopback/include/main.h
+++ /dev/null
@@ -1,29 +0,0 @@
-//
-// Java Does USB
-// Loopback device for testing
-//
-// Copyright (c) 2022 Manuel Bleichenbacher
-// Licensed under MIT License
-// https://opensource.org/licenses/MIT
-//
-// Main program
-//
-
-#ifndef MAIN_H
-#define MAIN_H
-
-#include
-
-#include "usbd_def.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void Error_Handler(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/stm32-loopback/include/usbd_conf.h b/stm32-loopback/include/usbd_conf.h
deleted file mode 100644
index c16c7f32..00000000
--- a/stm32-loopback/include/usbd_conf.h
+++ /dev/null
@@ -1,42 +0,0 @@
-//
-// Java Does USB
-// Loopback device for testing
-//
-// Copyright (c) 2022 Manuel Bleichenbacher
-// Licensed under MIT License
-// https://opensource.org/licenses/MIT
-//
-// Common configuration
-//
-
-#ifndef USBD_CONF_H
-#define USBD_CONF_H
-
-#include
-#include
-#include
-
-#include "stm32f1xx.h"
-#include "stm32f1xx_hal.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define USBD_MAX_NUM_INTERFACES 1
-#define USBD_MAX_NUM_CONFIGURATION 1
-#define USBD_MAX_STR_DESC_SIZ 512
-#define USBD_SUPPORT_USER_STRING_DESC 1
-#define USBD_DEBUG_LEVEL 0
-#define USBD_SELF_POWERED 1
-#define USBD_DFU_MAX_ITF_NUM 1
-#define USBD_DFU_XFER_SIZE 1024
-#define USBD_DFU_APP_DEFAULT_ADD 0x08000000
-
-#define DEVICE_FS 0
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/stm32-loopback/include/usbd_desc.h b/stm32-loopback/include/usbd_desc.h
deleted file mode 100644
index d69b5ba8..00000000
--- a/stm32-loopback/include/usbd_desc.h
+++ /dev/null
@@ -1,28 +0,0 @@
-//
-// Java Does USB
-// Loopback device for testing
-//
-// Copyright (c) 2022 Manuel Bleichenbacher
-// Licensed under MIT License
-// https://opensource.org/licenses/MIT
-//
-// USB device descriptor
-//
-
-#ifndef USBD_DESC_H
-#define USBD_DESC_H
-
-#include "usbd_def.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-// Descriptor functions
-extern USBD_DescriptorsTypeDef USBD_Descriptors;
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/stm32-loopback/include/usbd_loopback.h b/stm32-loopback/include/usbd_loopback.h
deleted file mode 100644
index e04d3d33..00000000
--- a/stm32-loopback/include/usbd_loopback.h
+++ /dev/null
@@ -1,33 +0,0 @@
-//
-// Java Does USB
-// Loopback device for testing
-//
-// Copyright (c) 2022 Manuel Bleichenbacher
-// Licensed under MIT License
-// https://opensource.org/licenses/MIT
-//
-// Loopback interface
-//
-
-#ifndef USB_LOOPBACK_H
-#define USB_LOOPBACK_H
-
-#include "usbd_ioreq.h"
-
-#define DATA_OUT_EP 0x01U
-#define DATA_IN_EP 0x82U
-#define DATA_PACKET_SIZE 64
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern USBD_ClassTypeDef USBD_Vendor_Class;
-
-void usbd_check(USBD_HandleTypeDef *pdev);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/stm32-loopback/src/circ_buf.c b/stm32-loopback/src/circ_buf.c
deleted file mode 100644
index 9210730e..00000000
--- a/stm32-loopback/src/circ_buf.c
+++ /dev/null
@@ -1,107 +0,0 @@
-//
-// Java Does USB
-// Loopback device for testing
-//
-// Copyright (c) 2022 Manuel Bleichenbacher
-// Licensed under MIT License
-// https://opensource.org/licenses/MIT
-//
-// Circular buffer for raw binary data.
-//
-// The circular buffer allows a reader and writer to
-// use the buffer concurrently.
-//
-
-#include "circ_buf.h"
-
-#include
-#include
-
-#define BUF_SIZE 1025
-
-// 0 <= head < BUF_SIZE
-// 0 <= tail < BUF_SIZE
-// head == tail: buffer is empty
-// Therefore, the buffer must never be filled completely.
-static volatile int buf_head = 0; // updated when adding data
-static volatile int buf_tail = 0; // updated when removing data
-
-static uint8_t buffer[BUF_SIZE];
-
-int circ_buf_avail_size() {
- int head = buf_head;
- int tail = buf_tail;
-
- if (head >= tail) {
- return BUF_SIZE - (head - tail) - 1;
- } else {
- return tail - head - 1;
- }
-}
-
-int circ_buf_data_size() {
- int head = buf_head;
- int tail = buf_tail;
-
- if (head >= tail) {
- return head - tail;
- } else {
- return BUF_SIZE - (tail - head);
- }
-}
-
-int circ_buf_get_data(uint8_t *buf, int max_len) {
- int tail = buf_tail;
- int head = buf_head;
-
- if (tail == head)
- return 0;
-
- // get available data (without wrap around)
- int len = (head > tail ? head : BUF_SIZE) - tail;
-
- // limit data to max_len
- if (len > max_len)
- len = max_len;
-
- // copy data
- memcpy(buf, buffer + tail, len);
-
- // update tail
- tail += len;
- if (tail >= BUF_SIZE)
- tail -= BUF_SIZE;
- buf_tail = tail;
-
- // sufficient data or no more data
- if (len == max_len || tail != 0)
- return len;
-
- // copy more data
- return circ_buf_get_data(buf + len, max_len - len) + len;
-}
-
-void circ_buf_add_data(const uint8_t *buf, int len) {
- int head = buf_head;
-
- // copy first part (from head to end of circular buffer)
- int n = len;
- if (n > BUF_SIZE - head)
- n = BUF_SIZE - head;
- memcpy(buffer + head, buf, n);
-
- // copy second part if needed (to start of circular buffer)
- if (n < len)
- memcpy(buffer, buf + n, len - n);
-
- // update head
- head += len;
- if (head >= BUF_SIZE)
- head -= BUF_SIZE;
- buf_head = head;
-}
-
-void circ_buf_reset() {
- buf_head = 0;
- buf_tail = 0;
-}
diff --git a/stm32-loopback/src/interrupts.c b/stm32-loopback/src/interrupts.c
deleted file mode 100644
index a61cc865..00000000
--- a/stm32-loopback/src/interrupts.c
+++ /dev/null
@@ -1,51 +0,0 @@
-//
-// Java Does USB
-// Loopback device for testing
-//
-// Copyright (c) 2022 Manuel Bleichenbacher
-// Licensed under MIT License
-// https://opensource.org/licenses/MIT
-//
-// Interrupt handlers
-//
-
-#include "interrupts.h"
-
-#include "main.h"
-
-extern PCD_HandleTypeDef usb_pcd;
-
-void SysTick_Handler(void) { HAL_IncTick(); }
-
-void USB_LP_CAN1_RX0_IRQHandler(void) { HAL_PCD_IRQHandler(&usb_pcd); }
-
-void NMI_Handler(void) {
- while (1) {
- }
-}
-
-void HardFault_Handler(void) {
- while (1) {
- }
-}
-
-void MemManage_Handler(void) {
- while (1) {
- }
-}
-
-void BusFault_Handler(void) {
- while (1) {
- }
-}
-
-void UsageFault_Handler(void) {
- while (1) {
- }
-}
-
-void SVC_Handler(void) {}
-
-void DebugMon_Handler(void) {}
-
-void PendSV_Handler(void) {}
diff --git a/stm32-loopback/src/main.c b/stm32-loopback/src/main.c
deleted file mode 100644
index 995f17b4..00000000
--- a/stm32-loopback/src/main.c
+++ /dev/null
@@ -1,105 +0,0 @@
-//
-// Java Does USB
-// Loopback device for testing
-//
-// Copyright (c) 2022 Manuel Bleichenbacher
-// Licensed under MIT License
-// https://opensource.org/licenses/MIT
-//
-// Main program
-//
-
-#include "main.h"
-
-#include "circ_buf.h"
-#include "usbd_desc.h"
-#include "usbd_loopback.h"
-
-static void SystemClock_Config(void);
-static void MX_GPIO_Init(void);
-static void USB_Device_Init(void);
-
-static USBD_HandleTypeDef USBD_Device;
-
-int main(void) {
- HAL_Init();
- SystemClock_Config();
- MX_GPIO_Init();
- USB_Device_Init();
-
- while (1) {
- usbd_check(&USBD_Device);
- }
-}
-
-void SystemClock_Config(void) {
- RCC_OscInitTypeDef RCC_OscInitStruct = {0};
- RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
- RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
-
- // Initializes the RCC Oscillators according to the specified parameters
- // in the RCC_OscInitTypeDef structure.
- RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_LSE;
- RCC_OscInitStruct.HSEState = RCC_HSE_ON;
- RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
- RCC_OscInitStruct.LSEState = RCC_LSE_ON;
- RCC_OscInitStruct.HSIState = RCC_HSI_ON;
- RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
- RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
- RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
- if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
- Error_Handler();
- }
-
- // Initializes the CPU, AHB and APB buses clocks
- RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
- RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
- RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
- RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
- RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
-
- if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) {
- Error_Handler();
- }
- PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC | RCC_PERIPHCLK_USB;
- PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
- PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5;
- if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) {
- Error_Handler();
- }
-}
-
-static void MX_GPIO_Init(void) {
- // GPIO Ports Clock Enable
- __HAL_RCC_GPIOD_CLK_ENABLE();
- __HAL_RCC_GPIOA_CLK_ENABLE();
-}
-
-void USB_Device_Init(void) {
- // Pull USB D+ (A12) low for 80ms to trigger device reenumeration
- HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET);
- GPIO_InitTypeDef GPIO_InitStruct = {0};
- GPIO_InitStruct.Pin = GPIO_PIN_12;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
- HAL_Delay(80);
-
- // Init USB Device Library, add supported class and start the library.
- USBD_Init(&USBD_Device, &USBD_Descriptors, DEVICE_FS);
- USBD_RegisterClass(&USBD_Device, &USBD_Vendor_Class);
- USBD_Start(&USBD_Device);
-}
-
-void HAL_MspInit(void) {
- __HAL_RCC_AFIO_CLK_ENABLE();
- __HAL_RCC_PWR_CLK_ENABLE();
- __HAL_AFIO_REMAP_SWJ_NOJTAG();
-}
-
-void Error_Handler(void) {
- __disable_irq();
- while (1) {
- }
-}
diff --git a/stm32-loopback/src/usbd_desc.c b/stm32-loopback/src/usbd_desc.c
deleted file mode 100644
index a703438b..00000000
--- a/stm32-loopback/src/usbd_desc.c
+++ /dev/null
@@ -1,149 +0,0 @@
-//
-// Java Does USB
-// Loopback device for testing
-//
-// Copyright (c) 2022 Manuel Bleichenbacher
-// Licensed under MIT License
-// https://opensource.org/licenses/MIT
-//
-// USB device descriptor
-//
-
-#include "usbd_desc.h"
-
-#include "stm32f1xx_ll_utils.h"
-#include "usbd_conf.h"
-#include "usbd_core.h"
-
-#define USBD_VID 0xcafe
-#define USBD_LANGID_STRING 1033
-#define USBD_MANUFACTURER_STRING "JavaDoesUSB"
-#define USBD_PID_FS 0xceaf
-#define USBD_PRODUCT_STRING_FS "Loopback"
-#define USBD_CONFIGURATION_STRING_FS "Loopback Config"
-#define USBD_INTERFACE_STRING_FS "Loopback Interface"
-#define USBD_DEV_RELESE 0x0061
-
-static void GetSerialNumber(void);
-static void IntToUnicode(uint32_t value, uint8_t *pbuf, uint8_t len);
-
-static uint8_t *GetDeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
-static uint8_t *GetLangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
-static uint8_t *GetManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
-static uint8_t *GetProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
-static uint8_t *GetSerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
-static uint8_t *GetConfigurationStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
-static uint8_t *GetInterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
-
-USBD_DescriptorsTypeDef USBD_Descriptors = {
- GetDeviceDescriptor, GetLangIDStrDescriptor, GetManufacturerStrDescriptor, GetProductStrDescriptor,
- GetSerialStrDescriptor, GetConfigurationStrDescriptor, GetInterfaceStrDescriptor,
-};
-
-// USB device descriptor.
-static const __ALIGN_BEGIN uint8_t deviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {
- 0x12, // bLength
- USB_DESC_TYPE_DEVICE, // bDescriptorType
- 0x00, // bcdUSB = 2.00
- 0x02, //
- 0xff, // bDeviceClass = vendor specific
- 0x00, // bDeviceSubClass
- 0x00, // bDeviceProtocol = vendor specific
- USB_MAX_EP0_SIZE, // bMaxPacketSize
- LOBYTE(USBD_VID), // idVendor
- HIBYTE(USBD_VID), //
- LOBYTE(USBD_PID_FS), // idProduct
- HIBYTE(USBD_PID_FS), //
- LOBYTE(USBD_DEV_RELESE), // bcdDevice
- HIBYTE(USBD_DEV_RELESE), //
- USBD_IDX_MFC_STR, // Index of manufacturer string
- USBD_IDX_PRODUCT_STR, // Index of product string
- USBD_IDX_SERIAL_STR, // Index of serial number string
- USBD_MAX_NUM_CONFIGURATION // bNumConfigurations
-};
-
-// USB lang indentifier descriptor.
-static const __ALIGN_BEGIN uint8_t langIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = {
- USB_LEN_LANGID_STR_DESC,
- USB_DESC_TYPE_STRING,
- LOBYTE(USBD_LANGID_STRING),
- HIBYTE(USBD_LANGID_STRING),
-};
-
-// Internal string descriptor.
-__ALIGN_BEGIN uint8_t stringDescBuffer[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
-
-#define USB_SIZ_STRING_SERIAL 0x1A
-
-static __ALIGN_BEGIN uint8_t serialStringDesc[USB_SIZ_STRING_SERIAL] __ALIGN_END = {
- USB_SIZ_STRING_SERIAL,
- USB_DESC_TYPE_STRING,
-};
-
-uint8_t *GetDeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
- UNUSED(speed);
- *length = sizeof(deviceDesc);
- return (uint8_t *)deviceDesc;
-}
-
-uint8_t *GetLangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
- UNUSED(speed);
- *length = sizeof(langIDDesc);
- return (uint8_t *)langIDDesc;
-}
-
-uint8_t *GetProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
- UNUSED(speed);
- USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_FS, stringDescBuffer, length);
- return stringDescBuffer;
-}
-
-uint8_t *GetManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
- UNUSED(speed);
- USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, stringDescBuffer, length);
- return stringDescBuffer;
-}
-
-uint8_t *GetSerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
- UNUSED(speed);
- *length = USB_SIZ_STRING_SERIAL;
- GetSerialNumber();
- return serialStringDesc;
-}
-
-uint8_t *GetConfigurationStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
- UNUSED(speed);
- USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_FS, stringDescBuffer, length);
- return stringDescBuffer;
-}
-
-uint8_t *GetInterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
- UNUSED(speed);
- USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_FS, stringDescBuffer, length);
- return stringDescBuffer;
-}
-
-static void GetSerialNumber(void) {
- uint32_t id0 = LL_GetUID_Word0();
- uint32_t id1 = LL_GetUID_Word1();
- uint32_t id2 = LL_GetUID_Word2();
-
- id0 += id2;
-
- if (id0 != 0) {
- IntToUnicode(id0, &serialStringDesc[2], 8);
- IntToUnicode(id1, &serialStringDesc[18], 4);
- }
-}
-
-const static char HEX_DIGITS[] = "0123456789ABCDEF";
-
-static void IntToUnicode(uint32_t value, uint8_t *pbuf, uint8_t len) {
- uint8_t idx = 0;
-
- for (idx = 0; idx < len; idx++) {
- pbuf[2 * idx] = HEX_DIGITS[value >> 28];
- value = value << 4;
- pbuf[2 * idx + 1] = 0;
- }
-}
diff --git a/stm32-loopback/src/usbd_impl.c b/stm32-loopback/src/usbd_impl.c
deleted file mode 100644
index bfc876da..00000000
--- a/stm32-loopback/src/usbd_impl.c
+++ /dev/null
@@ -1,211 +0,0 @@
-//
-// Java Does USB
-// Loopback device for testing
-//
-// Copyright (c) 2022 Manuel Bleichenbacher
-// Licensed under MIT License
-// https://opensource.org/licenses/MIT
-//
-// Low level USB implementation
-//
-
-#include "stm32f1xx.h"
-#include "stm32f1xx_hal.h"
-#include "usbd_core.h"
-#include "usbd_def.h"
-#include "usbd_loopback.h"
-
-PCD_HandleTypeDef usb_pcd;
-void Error_Handler(void);
-
-static USBD_StatusTypeDef Get_USB_Status(HAL_StatusTypeDef hal_status);
-
-void HAL_PCD_MspInit(PCD_HandleTypeDef *pcdHandle) {
- if (pcdHandle->Instance == USB) {
- // Enable USB clock
- __HAL_RCC_USB_CLK_ENABLE();
-
- // Configure USB interrupts
- HAL_NVIC_SetPriority(USB_LP_CAN1_RX0_IRQn, 0, 0);
- HAL_NVIC_EnableIRQ(USB_LP_CAN1_RX0_IRQn);
- }
-}
-
-void HAL_PCD_MspDeInit(PCD_HandleTypeDef *pcdHandle) {
- if (pcdHandle->Instance == USB) {
- __HAL_RCC_USB_CLK_DISABLE();
- HAL_NVIC_DisableIRQ(USB_LP_CAN1_RX0_IRQn);
- }
-}
-
-void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) {
- USBD_LL_SetupStage((USBD_HandleTypeDef *)hpcd->pData, (uint8_t *)hpcd->Setup);
-}
-
-void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) {
- USBD_LL_DataOutStage((USBD_HandleTypeDef *)hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff);
-}
-
-void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) {
- USBD_LL_DataInStage((USBD_HandleTypeDef *)hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff);
-}
-
-void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) { USBD_LL_SOF((USBD_HandleTypeDef *)hpcd->pData); }
-
-void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) {
- USBD_LL_SetSpeed((USBD_HandleTypeDef *)hpcd->pData, USBD_SPEED_FULL);
-
- USBD_LL_Reset((USBD_HandleTypeDef *)hpcd->pData);
-}
-
-void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) {
- // Inform USB library that core enters in suspend Mode
- USBD_LL_Suspend((USBD_HandleTypeDef *)hpcd->pData);
- // Enter STOP mode
- if (hpcd->Init.low_power_enable) {
- // Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register
- SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));
- }
-}
-
-void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) { USBD_LL_Resume((USBD_HandleTypeDef *)hpcd->pData); }
-
-void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) {
- USBD_LL_IsoOUTIncomplete((USBD_HandleTypeDef *)hpcd->pData, epnum);
-}
-
-void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) {
- USBD_LL_IsoINIncomplete((USBD_HandleTypeDef *)hpcd->pData, epnum);
-}
-
-void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) { USBD_LL_DevConnected((USBD_HandleTypeDef *)hpcd->pData); }
-
-void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) { USBD_LL_DevDisconnected((USBD_HandleTypeDef *)hpcd->pData); }
-
-USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev) {
- // Link the driver to the stack
- usb_pcd.pData = pdev;
- pdev->pData = &usb_pcd;
-
- usb_pcd.Instance = USB;
- usb_pcd.Init.dev_endpoints = 8;
- usb_pcd.Init.speed = PCD_SPEED_FULL;
- usb_pcd.Init.low_power_enable = DISABLE;
- usb_pcd.Init.lpm_enable = DISABLE;
- usb_pcd.Init.battery_charging_enable = DISABLE;
- if (HAL_PCD_Init(&usb_pcd) != HAL_OK) {
- Error_Handler();
- }
-
- // Configure endpoint 0
- HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, 0x00, PCD_SNG_BUF, 0x18);
- HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, 0x80, PCD_SNG_BUF, 0x58);
-
- // configure endpoint 1
- HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, 0x01, PCD_SNG_BUF, 0x100);
-
- // configure endpoint 2
- HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, 0x82, PCD_SNG_BUF, 0x140);
-
- return USBD_OK;
-}
-
-USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev) {
- HAL_StatusTypeDef hal_status = HAL_OK;
- USBD_StatusTypeDef usb_status = USBD_OK;
-
- hal_status = HAL_PCD_DeInit(pdev->pData);
-
- usb_status = Get_USB_Status(hal_status);
-
- return usb_status;
-}
-
-USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev) {
- HAL_StatusTypeDef hal_status = HAL_PCD_Start(pdev->pData);
- return Get_USB_Status(hal_status);
-}
-
-USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev) {
- HAL_StatusTypeDef hal_status = HAL_PCD_Stop(pdev->pData);
- return Get_USB_Status(hal_status);
-}
-
-USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps) {
- HAL_StatusTypeDef hal_status = HAL_PCD_EP_Open(pdev->pData, ep_addr, ep_mps, ep_type);
- return Get_USB_Status(hal_status);
-}
-
-USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) {
- HAL_StatusTypeDef hal_status = HAL_PCD_EP_Close(pdev->pData, ep_addr);
- return Get_USB_Status(hal_status);
-}
-
-USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) {
- HAL_StatusTypeDef hal_status = HAL_PCD_EP_Flush(pdev->pData, ep_addr);
- return Get_USB_Status(hal_status);
-}
-
-USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) {
- HAL_StatusTypeDef hal_status = HAL_PCD_EP_SetStall(pdev->pData, ep_addr);
- return Get_USB_Status(hal_status);
-}
-
-USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) {
- HAL_StatusTypeDef hal_status = HAL_PCD_EP_ClrStall(pdev->pData, ep_addr);
- return Get_USB_Status(hal_status);
-}
-
-uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) {
- PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef *)pdev->pData;
-
- if ((ep_addr & 0x80) == 0x80) {
- return hpcd->IN_ep[ep_addr & 0x7F].is_stall;
- } else {
- return hpcd->OUT_ep[ep_addr & 0x7F].is_stall;
- }
-}
-
-USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr) {
- HAL_StatusTypeDef hal_status = HAL_PCD_SetAddress(pdev->pData, dev_addr);
- return Get_USB_Status(hal_status);
-}
-
-USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size) {
- HAL_StatusTypeDef hal_status = HAL_PCD_EP_Transmit(pdev->pData, ep_addr, pbuf, size);
- return Get_USB_Status(hal_status);
-}
-
-USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size) {
- HAL_StatusTypeDef hal_status = HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size);
- return Get_USB_Status(hal_status);
-}
-
-uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr) {
- return HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef *)pdev->pData, ep_addr);
-}
-
-void USBD_LL_Delay(uint32_t delay) { HAL_Delay(delay); }
-
-USBD_StatusTypeDef Get_USB_Status(HAL_StatusTypeDef hal_status) {
- USBD_StatusTypeDef usb_status = USBD_OK;
-
- switch (hal_status) {
- case HAL_OK:
- usb_status = USBD_OK;
- break;
- case HAL_ERROR:
- usb_status = USBD_FAIL;
- break;
- case HAL_BUSY:
- usb_status = USBD_BUSY;
- break;
- case HAL_TIMEOUT:
- usb_status = USBD_FAIL;
- break;
- default:
- usb_status = USBD_FAIL;
- break;
- }
- return usb_status;
-}
diff --git a/stm32-loopback/src/usbd_loopback.c b/stm32-loopback/src/usbd_loopback.c
deleted file mode 100644
index a8b51b06..00000000
--- a/stm32-loopback/src/usbd_loopback.c
+++ /dev/null
@@ -1,266 +0,0 @@
-//
-// Java Does USB
-// Loopback device for testing
-//
-// Copyright (c) 2022 Manuel Bleichenbacher
-// Licensed under MIT License
-// https://opensource.org/licenses/MIT
-//
-// Loopback interface
-//
-
-#include "usbd_loopback.h"
-
-#include "circ_buf.h"
-#include "main.h"
-#include "usbd_ctlreq.h"
-
-static uint8_t USBD_Vendor_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
-static uint8_t USBD_Vendor_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
-static uint8_t USBD_Vendor_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
-static uint8_t USBD_Vendor_EP0_RxReady(USBD_HandleTypeDef *pdev);
-static uint8_t USBD_Vendor_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
-static uint8_t USBD_Vendor_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
-static uint8_t *USBD_Vendor_GetConfigDesc(uint16_t *length);
-static uint8_t *USBD_Vendor_GetStringDesc(USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length);
-
-static uint8_t data_packet_rx[DATA_PACKET_SIZE];
-static uint8_t data_packet_tx[DATA_PACKET_SIZE];
-static volatile bool is_transmitting = false;
-static volatile bool is_receiving = false;
-static volatile uint32_t ctrl_req_value = 0;
-static uint8_t ctrl_req_buf[4];
-
-USBD_ClassTypeDef USBD_Vendor_Class = {
- USBD_Vendor_Init,
- USBD_Vendor_DeInit,
- USBD_Vendor_Setup,
- NULL, // EP0_TxSent
- USBD_Vendor_EP0_RxReady,
- USBD_Vendor_DataIn,
- USBD_Vendor_DataOut,
- NULL, // SOF
- NULL,
- NULL,
- NULL,
- USBD_Vendor_GetConfigDesc,
- NULL,
- NULL,
- USBD_Vendor_GetStringDesc,
-};
-
-#define CONFIG_DESC_SIZE 32U
-
-// USB blinky device configuration descriptor
-__ALIGN_BEGIN static uint8_t Configuration_Desc[CONFIG_DESC_SIZE] __ALIGN_END = {
- 0x09, // bLength: Configuration Descriptor size
- USB_DESC_TYPE_CONFIGURATION, // bDescriptorType: Configuration
- LOBYTE(CONFIG_DESC_SIZE), // wTotalLength: Bytes returned
- HIBYTE(0x00), // (cont.)
- 0x01, // bNumInterfaces: 1 interface
- 0x01, // bConfigurationValue: Configuration value
- USBD_IDX_CONFIG_STR, // iConfiguration: Index of string descriptor for configuration
- 0x80, // bmAttributes: bus powered
- 0xfa, // MaxPower 500 mA: this current is used for detecting Vbus
-
- // Interface 0 descriptor
- // offset 09
- 0x09, // bLength: Interface Descriptor size
- USB_DESC_TYPE_INTERFACE, // bDescriptorType: Interface descriptor type
- 0x00, // bInterfaceNumber: Number of Interface
- 0x00, // bAlternateSetting: Alternate setting
- 0x02, // bNumEndpoints
- 0xff, // bInterfaceClass: vendor-specific
- 0x00, // bInterfaceSubClass : 1=BOOT, 0=no boot
- 0x00, // nInterfaceProtocol : 0=vendor specific
- USBD_IDX_INTERFACE_STR, // iInterface: Index of string descriptor
-
- // Endpoint 1 descriptor
- // offset 18
- 0x07, // bLength: endpoint descriptor size
- USB_DESC_TYPE_ENDPOINT, // bDescriptorType: endpoint
- DATA_OUT_EP, // bEndpointAddress: Endpoint Address (OUT)
- USBD_EP_TYPE_BULK, // bmAttributes: bulk endpoint
- LOBYTE(DATA_PACKET_SIZE), // wMaxPacketSize: maximum of 64
- HIBYTE(0x00), // (cont.)
- 0x00, // bInterval: Polling Interval
-
- // Endpoint 2 descriptor
- // offset 25
- 0x07, // bLength: endpoint descriptor size
- USB_DESC_TYPE_ENDPOINT, // bDescriptorType: endpoint
- DATA_IN_EP, // bEndpointAddress: Endpoint Address (IN)
- USBD_EP_TYPE_BULK, // bmAttributes: bulk endpoint
- LOBYTE(DATA_PACKET_SIZE), // wMaxPacketSize: maximum of 64
- HIBYTE(0x00), // (cont.)
- 0x00, // bInterval: Polling Interval
-
- // offset 32
-};
-
-#define WCID_VENDOR_CODE 0x37
-
-// Microsoft WCID string descriptor (string index 0xee)
-static const uint8_t msft_sig_desc[] = {
- 0x12, // length = 18 bytes
- USB_DESC_TYPE_STRING, // descriptor type string
- 'M',
- 0,
- 'S',
- 0,
- 'F',
- 0,
- 'T',
- 0, // 'M', 'S', 'F', 'T'
- '1',
- 0,
- '0',
- 0,
- '0',
- 0, // '1', '0', '0'
- WCID_VENDOR_CODE, // vendor code
- 0 // padding
-};
-
-// Microsoft WCID feature descriptor (index 0x0004)
-static const uint8_t wcid_feature_desc[] = {
- 0x28, 0x00, 0x00, 0x00, // length = 40 bytes
- 0x00, 0x01, // version 1.0 (in BCD)
- 0x04, 0x00, // compatibility descriptor index 0x0004
- 0x01, // number of sections
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // reserved (7 bytes)
- 0x00, // interface number 0
- 0x01, // reserved
- 0x57, 0x49, 0x4E, 0x55, 0x53, 0x42, 0x00, 0x00, // Compatible ID "WINUSB\0\0"
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Subcompatible ID (unused)
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // reserved 6 bytes
-};
-
-uint8_t USBD_Vendor_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx) {
- // open RX bulk endpoint
- USBD_LL_OpenEP(pdev, DATA_OUT_EP, USBD_EP_TYPE_BULK, DATA_PACKET_SIZE);
- pdev->ep_in[DATA_OUT_EP & 0x7F].is_used = 1;
-
- // Enable it to receive data (NAK -> VALID)
- is_receiving = true;
- USBD_LL_PrepareReceive(pdev, DATA_OUT_EP, data_packet_rx, sizeof(data_packet_rx));
-
- // open TX bulk endpoint
- USBD_LL_OpenEP(pdev, DATA_IN_EP, USBD_EP_TYPE_BULK, DATA_PACKET_SIZE);
- pdev->ep_in[DATA_IN_EP & 0x7F].is_used = 1;
-
- return USBD_OK;
-}
-
-uint8_t USBD_Vendor_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx) {
- // close bulk end points
- USBD_LL_CloseEP(pdev, DATA_OUT_EP);
- pdev->ep_in[DATA_OUT_EP & 0x7F].is_used = 0;
-
- USBD_LL_CloseEP(pdev, DATA_IN_EP);
- pdev->ep_in[DATA_IN_EP & 0x7F].is_used = 0;
-
- return USBD_OK;
-}
-
-uint8_t USBD_Vendor_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) {
- // Handle vendor control request
- USBD_StatusTypeDef ret = USBD_OK;
-
- switch (req->bmRequest & USB_REQ_TYPE_MASK) {
- case USB_REQ_TYPE_VENDOR:
- if (req->bmRequest == 0x41 && req->bRequest == 0x01 && req->wIndex == 0x0000 && req->wLength == 0) {
- // save value
- ctrl_req_value = req->wValue;
-
- } else if (req->bmRequest == 0x41 && req->bRequest == 0x02 && req->wIndex == 0x0000 && req->wLength == 4) {
- // receive 4 data bytes
- USBD_CtlPrepareRx(pdev, ctrl_req_buf, 4);
-
- } else if (req->bmRequest == 0xc1 && req->bRequest == 0x03 && req->wIndex == 0x0000 && req->wLength == 4) {
- // send saved value
- uint32_t* p_value = (uint32_t*)&ctrl_req_buf;
- *p_value = ctrl_req_value;
- USBD_CtlSendData(pdev, ctrl_req_buf, 4);
-
- } else if (req->bRequest == WCID_VENDOR_CODE && req->wIndex == 0x0004) {
- // WCID feature request
- uint16_t len = sizeof(wcid_feature_desc);
- if (len > req->wLength)
- len = req->wLength;
- USBD_CtlSendData(pdev, (uint8_t *)wcid_feature_desc, len);
-
- } else {
- USBD_CtlError(pdev, req);
- ret = USBD_FAIL;
- }
- break;
-
- default:
- USBD_CtlError(pdev, req);
- ret = USBD_FAIL;
- break;
- }
-
- return ret;
-}
-
-uint8_t USBD_Vendor_EP0_RxReady(USBD_HandleTypeDef *pdev) {
- uint32_t* p_value = (uint32_t*)&ctrl_req_buf;
- ctrl_req_value = *p_value;
- return USBD_OK;
-}
-
-
-uint8_t *USBD_Vendor_GetConfigDesc(uint16_t *length) {
- // Return configuration descriptor
- *length = sizeof(Configuration_Desc);
- return Configuration_Desc;
-}
-
-uint8_t *USBD_Vendor_GetStringDesc(USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length) {
- // Return Microsoft OS string descriptor for index 0xee
- if (index == 0xee) {
- *length = sizeof(msft_sig_desc);
- return (uint8_t *)msft_sig_desc;
- } else {
- *length = 0;
- USBD_CtlError(pdev, NULL);
- return NULL;
- }
-}
-
-uint8_t USBD_Vendor_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum) {
- uint32_t num_bytes_received = USBD_LL_GetRxDataSize(pdev, epnum);
-
- // add recievied data to circular buffer
- circ_buf_add_data(data_packet_rx, num_bytes_received);
- is_receiving = false;
-
- return USBD_OK;
-}
-
-uint8_t USBD_Vendor_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) {
- is_transmitting = false;
- return USBD_OK;
-}
-
-void usbd_check(USBD_HandleTypeDef *pdev) {
- if (!is_transmitting) {
- // get data from circular buffer
- int size = circ_buf_get_data(data_packet_tx, DATA_PACKET_SIZE);
- if (size != 0) {
- is_transmitting = true;
- USBD_LL_Transmit(pdev, DATA_IN_EP, data_packet_tx, size);
- }
- }
-
- if (!is_receiving) {
- // check for sufficient space to enable receiving
- bool has_space = circ_buf_avail_size() >= DATA_PACKET_SIZE;
- if (has_space) {
- is_receiving = true;
- USBD_LL_PrepareReceive(pdev, DATA_OUT_EP, data_packet_rx, sizeof(data_packet_rx));
- }
- }
-}
diff --git a/stm32-loopback/.clang-format b/test-devices/loopback-stm32/.clang-format
similarity index 100%
rename from stm32-loopback/.clang-format
rename to test-devices/loopback-stm32/.clang-format
diff --git a/stm32-loopback/.gitignore b/test-devices/loopback-stm32/.gitignore
similarity index 100%
rename from stm32-loopback/.gitignore
rename to test-devices/loopback-stm32/.gitignore
diff --git a/stm32-loopback/.vscode/extensions.json b/test-devices/loopback-stm32/.vscode/extensions.json
similarity index 100%
rename from stm32-loopback/.vscode/extensions.json
rename to test-devices/loopback-stm32/.vscode/extensions.json
diff --git a/stm32-loopback/README.md b/test-devices/loopback-stm32/README.md
similarity index 93%
rename from stm32-loopback/README.md
rename to test-devices/loopback-stm32/README.md
index 2484048a..e66aa28b 100644
--- a/stm32-loopback/README.md
+++ b/test-devices/loopback-stm32/README.md
@@ -7,7 +7,7 @@ For testing the *Java Does USB* library, a dedicated USB test device is needed.
### Loopback
-All data sent to endpoint 0x01 (OUT) is sent back on endpoint 0x82 (IN). Both endpoints use bulk transfer with a maximum packet size of 64 bytes. The device uses an internal buffer of about 500 bytes. Up to this amount, the data can be first sent and then received.
+All data sent to endpoint 0x01 (OUT) is sent back on endpoint 0x82 (IN). Both endpoints use bulk transfer with a maximum packet size of 64 bytes. The device uses an internal buffer of about 1000 bytes. Up to this amount, the data can be first sent and then received.
### Control requests
diff --git a/test-devices/loopback-stm32/bin/firmware.bin b/test-devices/loopback-stm32/bin/firmware.bin
new file mode 100755
index 0000000000000000000000000000000000000000..15033c10c180ab6736a7c7e5931924bee03c0f9b
GIT binary patch
literal 6328
zcmd@(k9$*9miNB*lD;%a`#bXh)@Ervo)6gm^ZJc&w~Zb9^?raX8)5HFinCl~`G(V&yS4cAgcn^27%y4rb-4
zdaH~pto}d^iW6Ssz&?8*P*VtXYm||Ya&9!=x4}_8jfeV!--9~eVIPQBIN;@8((0|clpF7^b4STn${z<)N3cp`fOz#SKq>cYhnYv)PZ
zxaQo>3{
z+UtF9B)InX@wLOj)^oNwey%HaUU`;`!@(FiQBJB~PnDVybZJ2XmkPaGLPZ}Q33a7|
zifEv_maELzmeBF;BO$tYiF--)Nb<$do^HnRu1fLt5dJk&x-)K<%tI7q2_e}Y#M`lQ
ze;V`unWXryl88T(1ZykJY4IZELdwo`<8XBVDchhFq5K7u9w!=Q+&s2{)7{OSFI*hd@
zA5xx58yie@ydOMsg_jwaIVU2;*bTmAu{aUtZ?qw{1mK?mYyiY2?}8uhxS%%XNSmcX
zsZoIyHpJ%sT%IrQcTY{6jEfhsXa68$Jh<=y>8;<CYa(Yd}#
zZa?(2yvKboe%#(^KRgm_rH8bN4Nm| B%mU=~7Ewx8BW;o}ku@C~DKPLaL5l)=O4qh$*3*QZNpC?hA*o4I6
zcx)mE<+J;jX4XU|j_M11OnH&qtTI!Ss720e$X{gjf{z@tq~iR)Eib~8?!)D5soIMK
zQ~oEmIm>Ycsb$L89|&qmF6W9Ews5TX6#?@+v2hgbsutV<8Ny-~@}^ITTfzbeskjogsd51-2^
zI*~JLXMDHRExi}n68Cx!Aoz=f;s+vmX=Y^RfX?v76e_J7!D(i=%;Oy}Fzl?d_zxsO
z!gq4BPWRIO8b7Sgb_0V~z^owmc$DC}O!na@QD5RX`PF%(ForysCWFKDw@JEw6adD#X$%_r1%;+<
z9u6d+I0NHmaKizsXCNpN>~&nQ!ZUzw!6Cqjx8Ot%@Vaj1^|yEidia}h{jDJHW}KqX
zfaAvL*eC-TWur#E|DqxIzNyjhZOeQg*D%yy%i#Mnn0SUVk-;3+D9BY0e4hg}FJ~xU
z&EWTITB;~hTMQIh>KTpkG4;ASt6x`N0ATgAF|@CqA$twFX9fio9yWB|V?atVg?V}?
z=%GiLiplaek@eV!-2m?~+}wjbll^wtF@O-EAp6E`5S2P9Bu$cb)#y8W)YDCe{W+aI
z7tkhpMNH*gFZkOx>V5P->3xS+>V54ikl#p!gfPh}9Vpy9pqno^~x;
zZL8tlgPM3iJ|J-)`D^Ay(F_Jg`E+AnTd6ctLN9BnZ?!LgcBZsU=3(5ktBS%jPqj$@D1;F5upnZB)D6hjVSU^VU3$jD_bE*5}!Y~1?$m-^Zc*k6S`
zdy4ezqi;rXy%jJY9Z;^eRSHgP{+@`?gM#JKRUx@=iS!-Z3_G36EKYL+SQQ%M4`BB#TvwT54Gw
z373;rX*g+@Cc`YWRHepbbgPVw)9jB2qUd%s_y^rPYs$j-PG*+co7LrcwSjwHUBn-J
zn3qyXpaRe99>xyv`jAVnrAoB3FFCu3bz}zUPIb0R=hXMEc!{irqmk@t7>|UkoNqo>qh_ft#7J#nS~lOl}c^kB%9}3
zy~x2yliRkt2TvVW4ctWh#1b541Gs!Ri3Dcoh<^XW!Xx`15mquoCv$$RGV`tBRUxuc
zf9p>5o=Q#*S!6u(xj3FSIe7RPXSiB6^Jt8=T2*#|HGug*jVo%N{^>KKyvAc*z<7Td
z;@h5gn~q`L7Tgm0LN%ZwT(pD^7p=#J?7a=8)e$(GHotu
zT)(cnA+({)c#`Cg=YHCux_EoIF0@QO8rf9?^7txfg0`5-
z@!Q?>N!Mg1LhR
zV^-?@Ak_wPSAbmT;rmoGcdP7Qhx^omj2>@+9>wX41kT!q
zPL<(`)0;1D2Mu(fL07U5WFH+g*!4S_z4Q+K9(uP$&Am1^GBY0J>GzPap@%1PqxX2g
z7CBsYhT-rr)p(;8>1N>40T&HixeWC3_W@VSRXq$t*zmh#p`z)SRpwrUus^^EX9GfD
zeu#0F#2I0JkQQ14bNtq1yIgeW6B*zAw!8R@c+ueA9NO--_qM1rno3}Vug0)TL_HB6
zIA=<`z{@tNGB`g}U$l(H^E=#qX9`q2pBZ#hEx}6=RbT)0@2wVC*-Egk^6|^MIPv}SeOg-EY5IJizH0{a0U2uTU-X|!UV6M0E
zwRZM=o^$Pd4zC{~<*QbLcrrP6#v8z%|4>?R3Rit{$!lqvB4W3~Q>$qhu=~%3-TzGu{m|1Z$ii@Si=epZBBsbB_(?nH5tIPk
z8EGFDTflD~xNFgZ-?_!+Eom?5Co)Sw=9AuLL=6Sq)JTt;^B0Fr4r)x_{K`s)Z1XyX
z``r%3MOhe&$>Dd%Xl528Qad6W!8Yz;9Pa+KWLPh#KpSi%pA65J?rH(bE~R`mM4vQ*%S4>~ml2rRBahzG4}o+XFEM_~KhN
zZEIZ9c&KyH&E2Tf6z8XN(@SeflN
zG-!8dM0}8wsuH)=T|`ECY9mB|cNrR6a`=*gKIqneX_T{=@0Waf$)F=GySLESjCLZ6L5~HZoI5jSpA|vw`-~N2UD2h6SR`gHV%XsvZAdDN0U{3XF`xC
z>lU0~1vnp5)vy}d;pWB;)>2llz2ZJqfLq!R6V*})oI$H}x)Y5TwRIJK=W05(m1Ck>+wg$=p{jNE*1b-Dj6&>UR-r?3F84``i0-c6o``6&uz(OJx7W)A<+
zBo_Xdyww&*2?lu1K`eN|A7roKqMqAwy<~sjVz4LsXcaf6lC)%1u@hd7du?`HN%FsI
zc6r5|xp&U1ysO&n@h+5*0dDM+2I=}FyjnqV!w+ArhoL7&hbi%TUyg3$jm`QMKU?8l
z`^dWcTHL5%?b^UYD_S2#1_~jJQ80Z3_%8!ckn_p=7!hN^nNh_npZ)uvpFo(Rv4viQ
zT9Ab9MYG{K(1qrq5<-X>G_D82KdD01z+kApigX
literal 0
HcmV?d00001
diff --git a/stm32-loopback/bin/save_bin.sh b/test-devices/loopback-stm32/bin/save_bin.sh
similarity index 100%
rename from stm32-loopback/bin/save_bin.sh
rename to test-devices/loopback-stm32/bin/save_bin.sh
diff --git a/stm32-loopback/bin/upload_firmware.sh b/test-devices/loopback-stm32/bin/upload_firmware.sh
similarity index 100%
rename from stm32-loopback/bin/upload_firmware.sh
rename to test-devices/loopback-stm32/bin/upload_firmware.sh
diff --git a/test-devices/loopback-stm32/include/circ_buf.h b/test-devices/loopback-stm32/include/circ_buf.h
new file mode 100644
index 00000000..4d9a6970
--- /dev/null
+++ b/test-devices/loopback-stm32/include/circ_buf.h
@@ -0,0 +1,155 @@
+//
+// Java Does USB
+// Loopback device for testing
+//
+// Copyright (c) 2022 Manuel Bleichenbacher
+// Licensed under MIT License
+// https://opensource.org/licenses/MIT
+//
+// Circular buffer for raw binary data.
+//
+// The circular buffer allows a reader and writer to
+// use the buffer concurrently.
+//
+
+#pragma once
+
+#include
+#include
+
+#include
+
+/**
+ * Circular buffer for raw binary data.
+ *
+ * The circular buffer allows a reader and writer to
+ * use the buffer concurrently.
+ *
+ * @param N number of bytes that fit into the buffer
+ */
+template
+struct circ_buf {
+ private:
+ static constexpr int BUF_SIZE = N + 1;
+
+ // 0 <= head < BUF_SIZE
+ // 0 <= tail < BUF_SIZE
+ // head == tail: buffer is empty
+ // Therefore, the buffer must never be filled completely.
+ volatile int buf_head = 0; // updated when adding data
+ volatile int buf_tail = 0; // updated when removing data
+
+ uint8_t buffer[BUF_SIZE];
+
+ public:
+ /// Creates a new instance
+ circ_buf();
+
+ /// Returns the maximum number of bytes that can be added to the buffer
+ int avail_size();
+
+ /// Returns the number of bytes in the buffer
+ int data_size();
+
+ /**
+ * Gets the oldest data from the buffer and removes it.
+ * @param buf buffer to copy data to
+ * @param max_len maximum number of bytes to copy
+ * @return the effective number of bytes
+ */
+ int get_data(uint8_t *buf, int max_len);
+
+ /**
+ * Adds data to the buffer
+ *
+ * @param buf the buffer with the data
+ * @param len the number of bytes to add
+ */
+ void add_data(const uint8_t *buf, int len);
+
+ /// Resets (empties) the circular buffer
+ void reset();
+};
+
+template
+circ_buf::circ_buf() : buf_head(0), buf_tail(0) {}
+
+template
+int circ_buf::avail_size() {
+ int head = buf_head;
+ int tail = buf_tail;
+
+ if (head >= tail) {
+ return BUF_SIZE - (head - tail) - 1;
+ } else {
+ return tail - head - 1;
+ }
+}
+
+template
+int circ_buf::data_size() {
+ int head = buf_head;
+ int tail = buf_tail;
+
+ if (head >= tail) {
+ return head - tail;
+ } else {
+ return BUF_SIZE - (tail - head);
+ }
+}
+
+template
+int circ_buf::get_data(uint8_t *buf, int max_len) {
+ int tail = buf_tail;
+ int head = buf_head;
+
+ if (tail == head)
+ return 0;
+
+ // get available data (without wrap around)
+ int len = (head > tail ? head : BUF_SIZE) - tail;
+
+ // limit data to max_len
+ len = std::min(len, max_len);
+
+ // copy data
+ memcpy(buf, buffer + tail, len);
+
+ // update tail
+ tail += len;
+ if (tail >= BUF_SIZE)
+ tail -= BUF_SIZE;
+ buf_tail = tail;
+
+ // sufficient data or no more data
+ if (len == max_len || tail != 0)
+ return len;
+
+ // copy more data
+ return get_data(buf + len, max_len - len) + len;
+}
+
+template
+void circ_buf::add_data(const uint8_t *buf, int len) {
+ int head = buf_head;
+
+ // copy first part (from head to end of circular buffer)
+ int n = std::min(len, BUF_SIZE - head);
+ memcpy(buffer + head, buf, n);
+
+ // copy second part if needed (to start of circular buffer)
+ if (n < len)
+ memcpy(buffer, buf + n, len - n);
+
+ // update head
+ head += len;
+ if (head >= BUF_SIZE)
+ head -= BUF_SIZE;
+ buf_head = head;
+}
+
+template
+void circ_buf::reset() {
+ buf_head = 0;
+ buf_tail = 0;
+}
diff --git a/test-devices/loopback-stm32/include/common.h b/test-devices/loopback-stm32/include/common.h
new file mode 100644
index 00000000..427b2eb4
--- /dev/null
+++ b/test-devices/loopback-stm32/include/common.h
@@ -0,0 +1,32 @@
+//
+// Java Does USB
+// Loopback device for testing
+//
+// Copyright (c) 2022 Manuel Bleichenbacher
+// Licensed under MIT License
+// https://opensource.org/licenses/MIT
+//
+// Commmon functions
+//
+
+#pragma once
+
+#include
+
+/**
+ * @brief Initializes systick services
+ */
+void systick_init();
+
+/**
+ * @brief Gets the time.
+ *
+ * @return number of milliseconds since a fixed time in the past
+ */
+uint32_t millis();
+
+/**
+ * @brief Delays execution (busy wait)
+ * @param ms delay length, in milliseconds
+ */
+void delay(uint32_t ms);
diff --git a/test-devices/loopback-stm32/include/usb_descriptor.h b/test-devices/loopback-stm32/include/usb_descriptor.h
new file mode 100644
index 00000000..6a5df74a
--- /dev/null
+++ b/test-devices/loopback-stm32/include/usb_descriptor.h
@@ -0,0 +1,30 @@
+//
+// Java Does USB
+// Loopback device for testing
+//
+// Copyright (c) 2022 Manuel Bleichenbacher
+// Licensed under MIT License
+// https://opensource.org/licenses/MIT
+//
+// USB descriptor
+//
+
+#pragma once
+
+#include
+
+#define INTR_MAX_PACKET_SIZE 16
+#define BULK_MAX_PACKET_SIZE 64
+
+// Endpoints
+#define EP_LOOPBACK_RX 0x01
+#define EP_LOOPBACK_TX 0x82
+
+// USB descriptor string table
+extern const char *const usb_desc_strings[4];
+// USB device descriptor
+extern const struct usb_device_descriptor usb_device_desc;
+// USB device configurations
+extern const struct usb_config_descriptor usb_config_descs[];
+
+void usb_init_serial_num();
diff --git a/test-devices/loopback-stm32/include/wcid.h b/test-devices/loopback-stm32/include/wcid.h
new file mode 100644
index 00000000..2c1041ef
--- /dev/null
+++ b/test-devices/loopback-stm32/include/wcid.h
@@ -0,0 +1,17 @@
+//
+// Java Does USB
+// Loopback device for testing
+//
+// Copyright (c) 2022 Manuel Bleichenbacher
+// Licensed under MIT License
+// https://opensource.org/licenses/MIT
+//
+// Microsoft WCID descriptors
+//
+
+#pragma once
+
+#include
+
+// Register control request handlers for Microsoft WCID descriptors
+void register_wcid_desc(usbd_device *usb_dev);
diff --git a/stm32-loopback/platformio.ini b/test-devices/loopback-stm32/platformio.ini
similarity index 73%
rename from stm32-loopback/platformio.ini
rename to test-devices/loopback-stm32/platformio.ini
index 4ffb4da2..58ade09b 100644
--- a/stm32-loopback/platformio.ini
+++ b/test-devices/loopback-stm32/platformio.ini
@@ -1,4 +1,4 @@
[env:stm32-loopback]
platform = ststm32
board = bluepill_f103c8
-framework = stm32cube
+framework = libopencm3
diff --git a/test-devices/loopback-stm32/src/common.cpp b/test-devices/loopback-stm32/src/common.cpp
new file mode 100644
index 00000000..5102b6bd
--- /dev/null
+++ b/test-devices/loopback-stm32/src/common.cpp
@@ -0,0 +1,37 @@
+//
+// Java Does USB
+// Loopback device for testing
+//
+// Copyright (c) 2022 Manuel Bleichenbacher
+// Licensed under MIT License
+// https://opensource.org/licenses/MIT
+//
+// Commmon functions
+//
+
+#include "common.h"
+
+#include
+
+static volatile uint32_t millis_count;
+
+uint32_t millis() { return millis_count; }
+
+void delay(uint32_t ms) {
+ int32_t target_time = millis_count + ms;
+ while (target_time - (int32_t)millis_count > 0)
+ ;
+}
+
+void systick_init() {
+ // Initialize SysTick
+ systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8);
+ systick_set_reload(rcc_ahb_frequency / 8 / 1000 - 1);
+
+ // Enable and start
+ systick_interrupt_enable();
+ systick_counter_enable();
+}
+
+// System tick timer interrupt handler
+extern "C" void sys_tick_handler() { millis_count++; }
diff --git a/test-devices/loopback-stm32/src/main.cpp b/test-devices/loopback-stm32/src/main.cpp
new file mode 100644
index 00000000..cc39f21f
--- /dev/null
+++ b/test-devices/loopback-stm32/src/main.cpp
@@ -0,0 +1,197 @@
+//
+// Java Does USB
+// Loopback device for testing
+//
+// Copyright (c) 2022 Manuel Bleichenbacher
+// Licensed under MIT License
+// https://opensource.org/licenses/MIT
+//
+// Main program
+//
+
+#include
+#include
+#include
+#include
+
+#include
+
+#include "circ_buf.h"
+#include "common.h"
+#include "usb_descriptor.h"
+#include "wcid.h"
+
+static void on_usb_set_config(usbd_device *usbd_dev, uint16_t wValue);
+static usbd_request_return_codes on_usb_control_request(usbd_device *usbd_dev, usb_setup_data *req, uint8_t **buf, uint16_t *len, usbd_control_complete_callback *complete);
+static void on_usb_data_received(usbd_device *usbd_dev, uint8_t ep);
+static void on_usb_data_transmitted(usbd_device *usbd_dev, uint8_t ep);
+static void check_buffers();
+
+// USB device instance
+static usbd_device *usb_device;
+
+// buffer for control requests
+static uint8_t usbd_control_buffer[256];
+
+// Circular buffer for data
+static circ_buf<1024> buffer;
+
+// Minimum free space in circular buffer for requesting more packets
+static constexpr int MIN_FREE_SPACE = 2 * BULK_MAX_PACKET_SIZE;
+
+// indicates if loopback data is being transmitted
+static volatile bool is_transmitting = false;
+
+// indicates if the endpoint is forced to NAK to prevent receiving further data
+static volatile bool is_forced_nak = false;
+
+// value that can be saved and retrieved with control requests
+static uint32_t saved_value;
+
+
+void init() {
+ // Enable required clocks
+ rcc_clock_setup_in_hse_8mhz_out_72mhz();
+ rcc_periph_clock_enable(RCC_GPIOA);
+ rcc_periph_clock_enable(RCC_GPIOC);
+ rcc_periph_clock_enable(RCC_AFIO);
+ rcc_periph_clock_enable(RCC_SPI1);
+ rcc_periph_clock_enable(RCC_USB);
+
+ // Initialize systick services
+ systick_init();
+}
+
+void usb_init() {
+ // reset USB peripheral
+ rcc_periph_reset_pulse(RST_USB);
+
+ // Pull USB D+ (A12) low for 80ms to trigger device reenumeration
+ gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO12);
+ gpio_clear(GPIOA, GPIO12);
+ delay(80);
+
+ usb_init_serial_num();
+
+ // create USB device
+ usb_device = usbd_init(&st_usbfs_v1_usb_driver, &usb_device_desc, usb_config_descs, usb_desc_strings,
+ sizeof(usb_desc_strings) / sizeof(usb_desc_strings[0]), usbd_control_buffer,
+ sizeof(usbd_control_buffer));
+
+ // Set callback for config calls
+ usbd_register_set_config_callback(usb_device, on_usb_set_config);
+ register_wcid_desc(usb_device);
+}
+
+// Called when the host connects to the device and selects a configuration
+void on_usb_set_config(usbd_device *usbd_dev, __attribute__((unused)) uint16_t wValue) {
+ register_wcid_desc(usbd_dev);
+ usbd_register_control_callback(usbd_dev,
+ USB_REQ_TYPE_VENDOR | USB_REQ_TYPE_INTERFACE,
+ USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
+ on_usb_control_request);
+ usbd_ep_setup(usbd_dev, EP_LOOPBACK_RX, USB_ENDPOINT_ATTR_BULK, BULK_MAX_PACKET_SIZE, on_usb_data_received);
+ usbd_ep_setup(usbd_dev, EP_LOOPBACK_TX, USB_ENDPOINT_ATTR_BULK, BULK_MAX_PACKET_SIZE, on_usb_data_transmitted);
+
+ buffer.reset();
+ is_transmitting = false;
+ is_forced_nak = false;
+ saved_value = 0;
+}
+
+// Called when data has been received
+void on_usb_data_received(__attribute__((unused)) usbd_device *usbd_dev, __attribute__((unused)) uint8_t ep) {
+ // Retrieve USB data (has side effect of setting endpoint to VALID)
+ uint8_t packet[BULK_MAX_PACKET_SIZE] __attribute__((aligned(4)));
+ int len = usbd_ep_read_packet(usb_device, EP_LOOPBACK_RX, packet, sizeof(packet));
+
+ // copy data into circular buffer
+ buffer.add_data(packet, len);
+
+}
+
+// Called when data has been transmitted
+void on_usb_data_transmitted(__attribute__((unused)) usbd_device *usbd_dev, __attribute__((unused)) uint8_t ep) {
+ is_transmitting = false;
+}
+
+void check_buffers() {
+
+ // If RX is stopped and there is sufficient space in the buffer, resume it
+ if (is_forced_nak) {
+ if (buffer.avail_size() >= MIN_FREE_SPACE) {
+ usbd_ep_nak_set(usb_device, EP_LOOPBACK_RX, 0);
+ is_forced_nak = false;
+ }
+
+ // If RX is enabled but the space in the buffer is low, stop it
+ } else {
+ // check if there is space for less than 2 packets
+ if (buffer.avail_size() < MIN_FREE_SPACE) {
+ // set endpoint from VALID to NAK
+ usbd_ep_nak_set(usb_device, EP_LOOPBACK_RX, 1);
+ is_forced_nak = true;
+ }
+ }
+
+ // If no data is being transmitted and there is data in the buffer, transmit a packet
+ if (!is_transmitting && buffer.data_size() >= 0) {
+ uint8_t packet[BULK_MAX_PACKET_SIZE] __attribute__((aligned(4)));
+ int len = buffer.get_data(packet, BULK_MAX_PACKET_SIZE);
+ usbd_ep_write_packet(usb_device, EP_LOOPBACK_TX, packet, len);
+ is_transmitting = true;
+ }
+}
+
+usbd_request_return_codes on_usb_control_request(
+ __attribute__((unused)) usbd_device *usbd_dev, usb_setup_data *req,
+ uint8_t **buf, uint16_t *len, __attribute__((unused)) usbd_control_complete_callback *complete) {
+
+ switch (req->bRequest) {
+ case 1:
+ if (req->wIndex == 0 && req->wLength == 0) {
+ saved_value = req->wValue;
+ return USBD_REQ_HANDLED;
+ } else {
+ return USBD_REQ_NOTSUPP;
+ }
+ break;
+
+ case 2:
+ if (req->wIndex == 0 && req->wLength == 4) {
+ uint32_t* value = reinterpret_cast(*buf);
+ saved_value = *value;
+ return USBD_REQ_HANDLED;
+ } else {
+ return USBD_REQ_NOTSUPP;
+ }
+ break;
+
+ case 3:
+ if (req->wIndex == 0) {
+ uint8_t* value = reinterpret_cast(&saved_value);
+ *len = std::min(*len, (uint16_t) 4);
+ memcpy(*buf, value, *len);
+ return USBD_REQ_HANDLED;
+ } else {
+ return USBD_REQ_NOTSUPP;
+ }
+ break;
+
+ default:
+ ; // fall through
+ }
+
+ return USBD_REQ_NEXT_CALLBACK;
+}
+
+
+int main() {
+ init();
+ usb_init();
+
+ while (true) {
+ usbd_poll(usb_device);
+ check_buffers();
+ }
+}
diff --git a/test-devices/loopback-stm32/src/usb_descriptor.cpp b/test-devices/loopback-stm32/src/usb_descriptor.cpp
new file mode 100644
index 00000000..1c19a7bd
--- /dev/null
+++ b/test-devices/loopback-stm32/src/usb_descriptor.cpp
@@ -0,0 +1,138 @@
+//
+// Java Does USB
+// Loopback device for testing
+//
+// Copyright (c) 2022 Manuel Bleichenbacher
+// Licensed under MIT License
+// https://opensource.org/licenses/MIT
+//
+// USB descriptor
+//
+
+#include "usb_descriptor.h"
+
+#include
+
+static void put_hex(uint32_t value, char *buf, int len);
+
+#define USB_VID 0xcafe // Vendor ID
+#define USB_PID 0xceaf // Product ID
+#define USB_DEVICE_REL 0x0071 // release 0.7.1
+
+// Interface index
+#define INTF_LOOPBACK 0
+
+static char serial_num[13];
+
+const char *const usb_desc_strings[] = {
+ "JavaDoesUSB", // USB Manufacturer
+ "Loopback", // USB Product
+ serial_num, // Serial number
+};
+
+enum usb_strings_index { // Index of USB strings. Must sync with above, starts from 1.
+ USB_STRINGS_MANUFACTURER_ID = 1,
+ USB_STRINGS_PRODUCT_ID,
+ USB_STRINGS_SERIAL_NUMBER_ID,
+};
+
+static const struct usb_endpoint_descriptor comm_endpoint_descs[] = {
+ {
+ .bLength = USB_DT_ENDPOINT_SIZE,
+ .bDescriptorType = USB_DT_ENDPOINT,
+ .bEndpointAddress = EP_LOOPBACK_RX,
+ .bmAttributes = USB_ENDPOINT_ATTR_BULK,
+ .wMaxPacketSize = BULK_MAX_PACKET_SIZE,
+ .bInterval = 0,
+ .extra = nullptr,
+ .extralen = 0,
+ },
+ {
+ .bLength = USB_DT_ENDPOINT_SIZE,
+ .bDescriptorType = USB_DT_ENDPOINT,
+ .bEndpointAddress = EP_LOOPBACK_TX,
+ .bmAttributes = USB_ENDPOINT_ATTR_BULK,
+ .wMaxPacketSize = BULK_MAX_PACKET_SIZE,
+ .bInterval = 0,
+ .extra = nullptr,
+ .extralen = 0,
+ },
+};
+
+static const struct usb_interface_descriptor comm_if_descs[] = {
+ {
+ .bLength = USB_DT_INTERFACE_SIZE,
+ .bDescriptorType = USB_DT_INTERFACE,
+ .bInterfaceNumber = INTF_LOOPBACK,
+ .bAlternateSetting = 0,
+ .bNumEndpoints = sizeof(comm_endpoint_descs) / sizeof(comm_endpoint_descs[0]),
+ .bInterfaceClass = USB_CLASS_VENDOR,
+ .bInterfaceSubClass = 0,
+ .bInterfaceProtocol = 0, // vendor specific
+ .iInterface = 0,
+ .endpoint = comm_endpoint_descs,
+ .extra = nullptr,
+ .extralen = 0,
+ },
+};
+
+static const struct usb_interface usb_interfaces[] = {
+ {
+ .cur_altsetting = nullptr,
+ .num_altsetting = sizeof(comm_if_descs) / sizeof(comm_if_descs[0]),
+ .iface_assoc = nullptr,
+ .altsetting = comm_if_descs,
+ },
+};
+
+const struct usb_config_descriptor usb_config_descs[] = {
+ {
+ .bLength = USB_DT_CONFIGURATION_SIZE,
+ .bDescriptorType = USB_DT_CONFIGURATION,
+ .wTotalLength = 0,
+ .bNumInterfaces = sizeof(usb_interfaces) / sizeof(usb_interfaces[0]),
+ .bConfigurationValue = 1,
+ .iConfiguration = 0,
+ .bmAttributes = 0x80, // bus-powered, i.e. it draws power from USB bus
+ .bMaxPower = 0xfa, // 500 mA
+ .interface = usb_interfaces,
+ },
+};
+
+const struct usb_device_descriptor usb_device_desc = {
+ .bLength = USB_DT_DEVICE_SIZE,
+ .bDescriptorType = USB_DT_DEVICE,
+ .bcdUSB = 0x0200, // USB version 2.00
+ .bDeviceClass = USB_CLASS_VENDOR,
+ .bDeviceSubClass = 0,
+ .bDeviceProtocol = 0, // no class specific protocol
+ .bMaxPacketSize0 = BULK_MAX_PACKET_SIZE,
+ .idVendor = USB_VID,
+ .idProduct = USB_PID,
+ .bcdDevice = USB_DEVICE_REL,
+ .iManufacturer = USB_STRINGS_MANUFACTURER_ID,
+ .iProduct = USB_STRINGS_PRODUCT_ID,
+ .iSerialNumber = USB_STRINGS_SERIAL_NUMBER_ID,
+ .bNumConfigurations = sizeof(usb_config_descs) / sizeof(usb_config_descs[0]),
+};
+
+void usb_init_serial_num() {
+ uint32_t id0 = DESIG_UNIQUE_ID0;
+ uint32_t id1 = DESIG_UNIQUE_ID1;
+ uint32_t id2 = DESIG_UNIQUE_ID2;
+
+ id0 += id2;
+
+ put_hex(id0, serial_num, 8);
+ put_hex(id1, serial_num + 8, 4);
+ serial_num[12] = 0;
+}
+
+const static char HEX_DIGITS[] = "0123456789ABCDEF";
+
+void put_hex(uint32_t value, char *buf, int len) {
+ for (int idx = 0; idx < len; idx++) {
+ buf[idx] = HEX_DIGITS[value >> 28];
+ value = value << 4;
+ }
+}
diff --git a/test-devices/loopback-stm32/src/wcid.cpp b/test-devices/loopback-stm32/src/wcid.cpp
new file mode 100644
index 00000000..2c284f36
--- /dev/null
+++ b/test-devices/loopback-stm32/src/wcid.cpp
@@ -0,0 +1,81 @@
+//
+// Java Does USB
+// Loopback device for testing
+//
+// Copyright (c) 2022 Manuel Bleichenbacher
+// Licensed under MIT License
+// https://opensource.org/licenses/MIT
+//
+// Microsoft WCID descriptors
+//
+
+#include
+
+#include
+
+static usbd_request_return_codes msft_string_desc(usbd_device *usbd_dev, usb_setup_data *req, uint8_t **buf, uint16_t *len, usbd_control_complete_callback *complete);
+static usbd_request_return_codes msft_feature_desc(usbd_device *usbd_dev, usb_setup_data *req, uint8_t **buf, uint16_t *len, usbd_control_complete_callback *complete);
+
+// Registers additional control request handlers to implement
+// See https://github.com/pbatard/libwdi/wiki/WCID-Devices
+void register_wcid_desc(usbd_device *usb_dev) {
+ usbd_register_control_callback(usb_dev,
+ USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_DEVICE, USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
+ msft_string_desc);
+ usbd_register_control_callback(usb_dev,
+ USB_REQ_TYPE_VENDOR, USB_REQ_TYPE_TYPE,
+ msft_feature_desc);
+}
+
+#define WCID_VENDOR_CODE 0x37
+
+// Microsoft WCID string descriptor (string index 0xee)
+static const uint8_t msft_sig_desc[] = {
+ 0x12, // length = 18 bytes
+ USB_DT_STRING, // descriptor type string
+ 'M', 0, 'S', 0, 'F', 0, 'T', 0, // 'M', 'S', 'F', 'T'
+ '1', 0, '0', 0, '0', 0, // '1', '0', '0'
+ WCID_VENDOR_CODE, // vendor code
+ 0 // padding
+};
+
+// Microsoft WCID feature descriptor (index 0x0004)
+static const uint8_t wcid_feature_desc[] = {
+ 0x28, 0x00, 0x00, 0x00, // length = 40 bytes
+ 0x00, 0x01, // version 1.0 (in BCD)
+ 0x04, 0x00, // compatibility descriptor index 0x0004
+ 0x01, // number of sections
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // reserved (7 bytes)
+ 0x00, // interface number 0
+ 0x01, // reserved
+ 0x57, 0x49, 0x4E, 0x55, 0x53, 0x42, 0x00, 0x00, // Compatible ID "WINUSB\0\0"
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Subcompatible ID (unused)
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // reserved 6 bytes
+};
+
+usbd_request_return_codes msft_string_desc(__attribute__((unused)) usbd_device *usbd_dev, usb_setup_data *req,
+ uint8_t **buf, uint16_t *len,
+ __attribute__((unused)) usbd_control_complete_callback *complete) {
+ // 0x03: descriptor type string
+ // 0xee: Microsoft WCID string index
+ if (req->bRequest == USB_REQ_GET_DESCRIPTOR && req->wValue == 0x03ee) {
+ *buf = const_cast(reinterpret_cast(&msft_sig_desc));
+ *len = std::min(*len, (uint16_t)msft_sig_desc[0]);
+ return USBD_REQ_HANDLED;
+ }
+
+ return USBD_REQ_NEXT_CALLBACK;
+}
+
+usbd_request_return_codes msft_feature_desc(__attribute__((unused)) usbd_device *usbd_dev, usb_setup_data *req,
+ uint8_t **buf, uint16_t *len,
+ __attribute__((unused)) usbd_control_complete_callback *complete) {
+ // 0x0004: Microsoft WCID index for feature descriptor
+ if (req->bRequest == WCID_VENDOR_CODE && req->wIndex == 0x0004) {
+ *buf = const_cast(reinterpret_cast(&wcid_feature_desc));
+ *len = std::min(*len, (uint16_t)wcid_feature_desc[0]);
+ return USBD_REQ_HANDLED;
+ }
+
+ return USBD_REQ_NEXT_CALLBACK;
+}
From a576a3f33ead182566684e0d6ceb1020f04a25f6 Mon Sep 17 00:00:00 2001
From: Manuel Bl
Date: Sun, 28 Aug 2022 20:03:00 +0200
Subject: [PATCH 015/433] Windows: Use SetupAPI functions instead of CfgMgr32
functions
---
java-does-usb/jextract/gen_win_kernel32.cmd | 2 +
java-does-usb/jextract/gen_win_setupapi.cmd | 3 +
java-does-usb/jextract/windows_headers.h | 1 -
.../codecrete/usb/windows/DeviceProperty.java | 134 +++++++++++
.../net/codecrete/usb/windows/USBHelper.java | 6 +
.../usb/windows/WindowsUSBDeviceRegistry.java | 85 ++-----
.../usb/windows/gen/cfgmgr32/CfgMgr32.java | 44 ----
.../windows/gen/cfgmgr32/Constants$root.java | 19 --
.../windows/gen/cfgmgr32/RuntimeHelper.java | 216 ------------------
.../usb/windows/gen/cfgmgr32/constants$0.java | 30 ---
.../usb/windows/gen/kernel32/Kernel32.java | 6 +
.../usb/windows/gen/setupapi/SetupAPI.java | 19 +-
.../usb/windows/gen/setupapi/constants$0.java | 13 +-
.../usb/windows/gen/setupapi/constants$1.java | 24 ++
14 files changed, 218 insertions(+), 384 deletions(-)
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/DeviceProperty.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/CfgMgr32.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/Constants$root.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/RuntimeHelper.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/constants$0.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$1.java
diff --git a/java-does-usb/jextract/gen_win_kernel32.cmd b/java-does-usb/jextract/gen_win_kernel32.cmd
index 173e672f..2f524df8 100644
--- a/java-does-usb/jextract/gen_win_kernel32.cmd
+++ b/java-does-usb/jextract/gen_win_kernel32.cmd
@@ -11,7 +11,9 @@ set SDK_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0
--include-function CloseHandle ^
--include-function DeviceIoControl ^
--include-function GetLastError ^
+ --include-macro ERROR_SUCCESS ^
--include-macro ERROR_NO_MORE_ITEMS ^
+ --include-macro ERROR_INSUFFICIENT_BUFFER ^
--include-macro GENERIC_READ ^
--include-macro GENERIC_WRITE ^
--include-macro FILE_SHARE_READ ^
diff --git a/java-does-usb/jextract/gen_win_setupapi.cmd b/java-does-usb/jextract/gen_win_setupapi.cmd
index baf0813b..187cb288 100644
--- a/java-does-usb/jextract/gen_win_setupapi.cmd
+++ b/java-does-usb/jextract/gen_win_setupapi.cmd
@@ -13,10 +13,13 @@ set SDK_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0
--include-function SetupDiEnumDeviceInterfaces ^
--include-function SetupDiGetDeviceInterfaceDetailW ^
--include-function SetupDiGetDeviceRegistryPropertyW ^
+ --include-function SetupDiGetDevicePropertyW ^
--include-struct _SP_DEVINFO_DATA ^
--include-struct _SP_DEVICE_INTERFACE_DATA ^
--include-struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W ^
--include-macro DIGCF_PRESENT ^
--include-macro DIGCF_DEVICEINTERFACE ^
--include-macro SPDRP_ADDRESS ^
+ --include-macro DEVPROP_TYPE_UINT32 ^
+ --include-macro DEVPROP_TYPE_STRING ^
windows_headers.h
diff --git a/java-does-usb/jextract/windows_headers.h b/java-does-usb/jextract/windows_headers.h
index aa8d0648..a863aa14 100644
--- a/java-does-usb/jextract/windows_headers.h
+++ b/java-does-usb/jextract/windows_headers.h
@@ -1,5 +1,4 @@
#include
-#include
#include
#include
#include
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/DeviceProperty.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/DeviceProperty.java
new file mode 100644
index 00000000..133651b3
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/DeviceProperty.java
@@ -0,0 +1,134 @@
+//
+// Java Does USB
+// Copyright (c) 2022 Manuel Bleichenbacher
+// Licensed under MIT License
+// https://opensource.org/licenses/MIT
+//
+
+package net.codecrete.usb.windows;
+
+import net.codecrete.usb.USBException;
+import net.codecrete.usb.windows.gen.kernel32.Kernel32;
+import net.codecrete.usb.windows.gen.kernel32._GUID;
+import net.codecrete.usb.windows.gen.setupapi.SetupAPI;
+import net.codecrete.usb.windows.gen.setupapi._SP_DEVICE_INTERFACE_DATA;
+import net.codecrete.usb.windows.gen.stdlib.StdLib;
+
+import java.lang.foreign.Addressable;
+import java.lang.foreign.MemorySegment;
+import java.lang.foreign.MemorySession;
+
+import static java.lang.foreign.MemoryAddress.NULL;
+import static java.lang.foreign.ValueLayout.*;
+
+/**
+ * Device property GUIDs and functions
+ */
+public class DeviceProperty {
+
+ public static final MemorySegment DEVPKEY_Device_Address = createDEVPROPKEY(0xa45c254e, (short) 0xdf1c, (short) 0x4efd,
+ (byte) 0x80, (byte) 0x20, (byte) 0x67, (byte) 0xd1,
+ (byte) 0x46, (byte) 0xa8, (byte) 0x50, (byte) 0xe0, 30);
+
+ public static final MemorySegment DEVPKEY_Device_InstanceId = createDEVPROPKEY(0x78c34fc8, (short) 0x104a, (short) 0x4aca,
+ (byte) 0x9e, (byte) 0xa4, (byte) 0x52, (byte) 0x4d,
+ (byte) 0x52, (byte) 0x99, (byte) 0x6e, (byte) 0x57, 256);
+
+ public static final MemorySegment DEVPKEY_Device_Parent = createDEVPROPKEY(0x4340a6c5, (short) 0x93fa, (short) 0x4706,
+ (byte) 0x97, (byte) 0x2c, (byte) 0x7b, (byte) 0x64,
+ (byte) 0x80, (byte) 0x08, (byte) 0xa5, (byte) 0xa7, 8);
+
+ public static int getDeviceIntProperty(Addressable devInfo, Addressable devInfoData, Addressable propertyKey) {
+ try (var session = MemorySession.openConfined()) {
+ var propertyTypeHolder = session.allocate(JAVA_INT);
+ var propertyValueHolder = session.allocate(JAVA_INT);
+ if (SetupAPI.SetupDiGetDevicePropertyW(devInfo, devInfoData, propertyKey, propertyTypeHolder,
+ propertyValueHolder, (int) propertyValueHolder.byteSize(), NULL, 0) == 0)
+ throw new USBException("Internal error (SetupDiGetDevicePropertyW)", Kernel32.GetLastError());
+
+ if (propertyTypeHolder.get(JAVA_INT, 0) != SetupAPI.DEVPROP_TYPE_UINT32())
+ throw new USBException("Internal error (expected property typ UINT32)");
+
+ return propertyValueHolder.get(JAVA_INT, 0);
+ }
+ }
+
+ public static String getDeviceStringProperty(Addressable devInfo, Addressable devInfoData, Addressable propertyKey) {
+ try (var session = MemorySession.openConfined()) {
+ var propertyTypeHolder = session.allocate(JAVA_INT);
+ var requiredSizeHolder = session.allocate(JAVA_INT);
+ if (SetupAPI.SetupDiGetDevicePropertyW(devInfo, devInfoData, propertyKey, propertyTypeHolder,
+ NULL, 0, requiredSizeHolder, 0) == 0) {
+ // TODO: Reactivate when proper GetLastError() handling is available
+// int err = Kernel32.GetLastError();
+// if (err != Kernel32.ERROR_INSUFFICIENT_BUFFER())
+// throw new USBException("Internal error (SetupDiGetDevicePropertyW)", Kernel32.GetLastError());
+ }
+
+ if (propertyTypeHolder.get(JAVA_INT, 0) != SetupAPI.DEVPROP_TYPE_STRING())
+ throw new USBException("Internal error (expected property typ UINT32)");
+
+ int stringLen = requiredSizeHolder.get(JAVA_INT, 0) / 2 - 1;
+
+ var propertyValueHolder = session.allocateArray(JAVA_CHAR, stringLen + 1);
+ if (SetupAPI.SetupDiGetDevicePropertyW(devInfo, devInfoData, propertyKey, propertyTypeHolder,
+ propertyValueHolder, (int) propertyValueHolder.byteSize(), NULL, 0) == 0)
+ throw new USBException("Internal error (SetupDiGetDevicePropertyW)", Kernel32.GetLastError());
+
+ return new String(propertyValueHolder.asSlice(0, 2L * stringLen).toArray(JAVA_CHAR));
+ }
+ }
+
+ public static String getDevicePath(String instanceID, Addressable interfaceGuid) {
+ try (var session = MemorySession.openConfined()) {
+ // get device info set for instance
+ var instanceIDSegment = session.allocateArray(JAVA_CHAR, instanceID.length() + 1);
+ instanceIDSegment.asSlice(0, instanceID.length() * 2L).copyFrom(MemorySegment.ofArray(instanceID.toCharArray()));
+ final var devInfoSetHandle = SetupAPI.SetupDiGetClassDevsW(interfaceGuid, instanceIDSegment, NULL, SetupAPI.DIGCF_PRESENT() | SetupAPI.DIGCF_DEVICEINTERFACE());
+ if (Win.IsInvalidHandle(devInfoSetHandle))
+ throw new USBException("internal error (SetupDiGetClassDevsW)");
+
+ // ensure the result is destroyed when the scope is left
+ session.addCloseAction(() -> SetupAPI.SetupDiDestroyDeviceInfoList(devInfoSetHandle));
+
+ // retrieve first element of enumeration
+ var devIntfData = session.allocate(_SP_DEVICE_INTERFACE_DATA.$LAYOUT());
+ _SP_DEVICE_INTERFACE_DATA.cbSize$set(devIntfData, (int) devIntfData.byteSize());
+ if (SetupAPI.SetupDiEnumDeviceInterfaces(devInfoSetHandle, NULL, interfaceGuid, 0, devIntfData) == 0)
+ throw new USBException("internal error (SetupDiEnumDeviceInterfaces)");
+
+ // get path
+ var intfDetailData = session.allocate(SP_DEVICE_INTERFACE_DETAIL_DATA_W.$LAYOUT());
+ SP_DEVICE_INTERFACE_DETAIL_DATA_W.cbSize$set(intfDetailData, 8);
+ int intfDetailDataSize = (int) SP_DEVICE_INTERFACE_DETAIL_DATA_W.$LAYOUT().byteSize();
+ if (SetupAPI.SetupDiGetDeviceInterfaceDetailW(devInfoSetHandle, devIntfData,
+ intfDetailData, intfDetailDataSize, NULL, NULL) == 0)
+ throw new USBException("Internal error (SetupDiGetDeviceInterfaceDetailW)", Kernel32.GetLastError());
+
+ long pathLen = StdLib.wcslen(intfDetailData.address().addOffset(SP_DEVICE_INTERFACE_DETAIL_DATA_W.DevicePath$Offset));
+ return new String(intfDetailData.asSlice(SP_DEVICE_INTERFACE_DETAIL_DATA_W.DevicePath$Offset, 2L * pathLen).toArray(JAVA_CHAR));
+ }
+ }
+
+ public static MemorySegment createDEVPROPKEY(int data1, short data2, short data3,
+ byte data4_0, byte data4_1, byte data4_2, byte data4_3,
+ byte data4_4, byte data4_5, byte data4_6, byte data4_7,
+ int pid) {
+ var propKey = MemorySession.global().allocate(_GUID.sizeof() + JAVA_INT.byteSize());
+ _GUID.Data1$set(propKey, data1);
+ _GUID.Data2$set(propKey, data2);
+ _GUID.Data3$set(propKey, data3);
+ var data4 = _GUID.Data4$slice(propKey);
+ data4.set(JAVA_BYTE, 0, data4_0);
+ data4.set(JAVA_BYTE, 1, data4_1);
+ data4.set(JAVA_BYTE, 2, data4_2);
+ data4.set(JAVA_BYTE, 3, data4_3);
+ data4.set(JAVA_BYTE, 4, data4_4);
+ data4.set(JAVA_BYTE, 5, data4_5);
+ data4.set(JAVA_BYTE, 6, data4_6);
+ data4.set(JAVA_BYTE, 7, data4_7);
+ propKey.set(JAVA_INT, 16, pid);
+ return propKey;
+ }
+
+}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/USBHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/USBHelper.java
index 095f47e2..162a680b 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/USBHelper.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/USBHelper.java
@@ -50,6 +50,12 @@ public class USBHelper {
(byte) 0x90, (byte) 0x1F, (byte) 0x00, (byte) 0xC0,
(byte) 0x4F, (byte) 0xB9, (byte) 0x51, (byte) 0xED);
+ // f18a0e88-c30c-11d0-8815-00a0c906bed8
+
+ public static final MemorySegment GUID_DEVINTERFACE_USB_HUB = Win.CreateGUID(0xf18a0e88, (short) 0xc30c, (short) 0x11d0,
+ (byte) 0x88, (byte) 0x15, (byte) 0x00, (byte) 0xa0,
+ (byte) 0xc9, (byte) 0x06, (byte) 0xbe, (byte) 0xd8);
+
static {
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
index e71c550a..3df7cbbd 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
@@ -12,11 +12,9 @@
import net.codecrete.usb.common.USBDescriptors;
import net.codecrete.usb.common.USBDeviceRegistry;
import net.codecrete.usb.common.USBStructs;
-import net.codecrete.usb.windows.gen.cfgmgr32.CfgMgr32;
import net.codecrete.usb.windows.gen.kernel32.Kernel32;
import net.codecrete.usb.windows.gen.setupapi.SetupAPI;
import net.codecrete.usb.windows.gen.setupapi._SP_DEVINFO_DATA;
-import net.codecrete.usb.windows.gen.stdlib.StdLib;
import net.codecrete.usb.windows.gen.usbioctl.USBIoctl;
import java.lang.foreign.Addressable;
@@ -38,8 +36,10 @@ public List getAllDevices() {
List result = new ArrayList<>();
try (var outerSession = MemorySession.openConfined()) {
- // get as set of all USB devices present
- final var devInfoSetHandle = SetupAPI.SetupDiGetClassDevsW(USBHelper.GUID_DEVINTERFACE_USB_DEVICE, NULL, NULL, SetupAPI.DIGCF_PRESENT() | SetupAPI.DIGCF_DEVICEINTERFACE());
+ // get device information set of all USB devices present
+ final var devInfoSetHandle = SetupAPI.SetupDiGetClassDevsW(
+ USBHelper.GUID_DEVINTERFACE_USB_DEVICE, NULL, NULL,
+ SetupAPI.DIGCF_PRESENT() | SetupAPI.DIGCF_DEVICEINTERFACE());
if (Win.IsInvalidHandle(devInfoSetHandle))
throw new USBException("internal error (SetupDiGetClassDevsW)");
@@ -49,83 +49,34 @@ public List getAllDevices() {
var devInfo = MemorySegment.allocateNative(_SP_DEVINFO_DATA.$LAYOUT(), outerSession);
_SP_DEVINFO_DATA.cbSize$set(devInfo, (int) _SP_DEVINFO_DATA.$LAYOUT().byteSize());
- var devInfoData = MemorySegment.allocateNative(_SP_DEVINFO_DATA.$LAYOUT(), outerSession);
- _SP_DEVINFO_DATA.cbSize$set(devInfoData, (int) _SP_DEVINFO_DATA.$LAYOUT().byteSize());
-
+ // iterate all devices
for (int i = 0; true; i++) {
if (SetupAPI.SetupDiEnumDeviceInfo(devInfoSetHandle, i, devInfo) == 0) {
int err = Kernel32.GetLastError();
- if (err != Kernel32.ERROR_NO_MORE_ITEMS()) {
- throw new USBException("Internal error (SetupDiEnumDeviceInfo) ");
- }
- break;
+ if (err == Kernel32.ERROR_NO_MORE_ITEMS() || err == Kernel32.ERROR_SUCCESS())
+ break;
+ throw new USBException("Internal error (SetupDiEnumDeviceInfo) ");
}
try (var session = MemorySession.openConfined()) {
- // get the parent device (a USB hub)
- var parentDevInstHolder = session.allocate(JAVA_INT);
- int devInst = _SP_DEVINFO_DATA.DevInst$get(devInfo);
- int cmRet = CfgMgr32.CM_Get_Parent(parentDevInstHolder, devInst, 0);
- if (cmRet != 0)
- throw new USBException("Internal error (CM_Get_Parent)");
- var parentDevInst = parentDevInstHolder.get(JAVA_INT, 0);
-
- // get parent device path
- var pathBuffer = session.allocateArray(JAVA_CHAR, 260);
- cmRet = CfgMgr32.CM_Get_Device_IDW(parentDevInst, pathBuffer, 260, 0);
- if (cmRet != 0)
- throw new USBException("Internal error (CM_Get_Device_ID)");
-
- // create hub path
- var pathChars = pathBuffer.toArray(JAVA_CHAR);
- var index = 0;
- for (; pathChars[index] != 0; index++) {
- if (pathChars[index] == '\\' || pathChars[index] == '$')
- pathChars[index] = '#';
- }
- var hubPath = "\\\\?\\" + new String(pathChars, 0, index) + "#{f18a0e88-c30c-11d0-8815-00a0c906bed8}\0";
-
- var hubPathSeg = session.allocateArray(JAVA_CHAR, hubPath.length());
- hubPathSeg.copyFrom(MemorySegment.ofArray(hubPath.toCharArray()));
+ var usbPortNum = DeviceProperty.getDeviceIntProperty(devInfoSetHandle, devInfo, DeviceProperty.DEVPKEY_Device_Address);
+ var instanceID = DeviceProperty.getDeviceStringProperty(devInfoSetHandle, devInfo, DeviceProperty.DEVPKEY_Device_InstanceId);
+ var devicePath = DeviceProperty.getDevicePath(instanceID, USBHelper.GUID_DEVINTERFACE_USB_DEVICE);
+ var parentInstanceID = DeviceProperty.getDeviceStringProperty(devInfoSetHandle, devInfo, DeviceProperty.DEVPKEY_Device_Parent);
+ var hubPath = DeviceProperty.getDevicePath(parentInstanceID, USBHelper.GUID_DEVINTERFACE_USB_HUB);
+ // open hub
+ var hubPathSeg = session.allocateArray(JAVA_CHAR, hubPath.length() + 2);
+ hubPathSeg.copyFrom(MemorySegment.ofArray(hubPath.toCharArray()));
final var hubHandle = Kernel32.CreateFileW(hubPathSeg, Kernel32.GENERIC_WRITE(), Kernel32.FILE_SHARE_WRITE(),
NULL, Kernel32.OPEN_EXISTING(), 0, NULL);
if (Win.IsInvalidHandle(hubHandle))
- throw new USBException("Cannot open USB hub");
+ throw new USBException("Cannot open USB hub", Kernel32.GetLastError());
+ // ensure the hub is closed later
session.addCloseAction(() -> Kernel32.CloseHandle(hubHandle));
- // get the interface data
- if (SetupAPI.SetupDiEnumDeviceInterfaces(devInfoSetHandle, devInfo,
- USBHelper.GUID_DEVINTERFACE_USB_DEVICE, 0, devInfoData) == 0) {
- int lastError = Kernel32.GetLastError();
- if (lastError == Kernel32.ERROR_NO_MORE_ITEMS())
- throw new USBException("Internal error (SetupDiEnumDeviceInterfaces)");
- continue;
- }
-
- // get path of first interface
- var intfDetailData = MemorySegment.allocateNative(SP_DEVICE_INTERFACE_DETAIL_DATA_W.$LAYOUT(), session);
- SP_DEVICE_INTERFACE_DETAIL_DATA_W.cbSize$set(intfDetailData, 8);
- int intfDatailDataSize = (int) SP_DEVICE_INTERFACE_DETAIL_DATA_W.$LAYOUT().byteSize();
- if (SetupAPI.SetupDiGetDeviceInterfaceDetailW(devInfoSetHandle, devInfoData,
- intfDetailData, intfDatailDataSize, NULL, NULL) == 0)
- throw new USBException("Internal error (SetupDiGetDeviceInterfaceDetailA - 2)", Kernel32.GetLastError());
-
- long pathLen = StdLib.wcslen(intfDetailData.address().addOffset(SP_DEVICE_INTERFACE_DETAIL_DATA_W.DevicePath$Offset));
- char[] devicePathChars = intfDetailData.asSlice(SP_DEVICE_INTERFACE_DETAIL_DATA_W.DevicePath$Offset, pathLen * 2).toArray(JAVA_CHAR);
- String devicePath = new String(devicePathChars);
-
- // get device's hub port number
- var usbPortNumHolder = session.allocate(JAVA_INT);
- var sizeHolder = session.allocate(JAVA_INT);
- if (SetupAPI.SetupDiGetDeviceRegistryPropertyW(devInfoSetHandle, devInfo,
- SetupAPI.SPDRP_ADDRESS(), NULL, usbPortNumHolder,
- (int) usbPortNumHolder.byteSize(), sizeHolder) == 0)
- throw new USBException("Internal error (cannot get device hub port)", Kernel32.GetLastError());
- int usbPortNum = usbPortNumHolder.get(JAVA_INT, 0);
-
result.add(createDeviceInfo(devicePath, hubHandle, usbPortNum));
}
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/CfgMgr32.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/CfgMgr32.java
deleted file mode 100644
index b7b83db0..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/CfgMgr32.java
+++ /dev/null
@@ -1,44 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.windows.gen.cfgmgr32;
-
-import java.lang.foreign.Addressable;
-import java.lang.invoke.MethodHandle;
-
-import static java.lang.foreign.ValueLayout.*;
-public class CfgMgr32 {
-
- /* package-private */ CfgMgr32() {}
- public static OfByte C_CHAR = Constants$root.C_CHAR$LAYOUT;
- public static OfShort C_SHORT = Constants$root.C_SHORT$LAYOUT;
- public static OfInt C_INT = Constants$root.C_LONG$LAYOUT;
- public static OfInt C_LONG = Constants$root.C_LONG$LAYOUT;
- public static OfLong C_LONG_LONG = Constants$root.C_LONG_LONG$LAYOUT;
- public static OfFloat C_FLOAT = Constants$root.C_FLOAT$LAYOUT;
- public static OfDouble C_DOUBLE = Constants$root.C_DOUBLE$LAYOUT;
- public static OfAddress C_POINTER = Constants$root.C_POINTER$LAYOUT;
- public static MethodHandle CM_Get_Device_IDW$MH() {
- return RuntimeHelper.requireNonNull(constants$0.CM_Get_Device_IDW$MH,"CM_Get_Device_IDW");
- }
- public static int CM_Get_Device_IDW ( int dnDevInst, Addressable Buffer, int BufferLen, int ulFlags) {
- var mh$ = CM_Get_Device_IDW$MH();
- try {
- return (int)mh$.invokeExact(dnDevInst, Buffer, BufferLen, ulFlags);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
- public static MethodHandle CM_Get_Parent$MH() {
- return RuntimeHelper.requireNonNull(constants$0.CM_Get_Parent$MH,"CM_Get_Parent");
- }
- public static int CM_Get_Parent ( Addressable pdnDevInst, int dnDevInst, int ulFlags) {
- var mh$ = CM_Get_Parent$MH();
- try {
- return (int)mh$.invokeExact(pdnDevInst, dnDevInst, ulFlags);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/Constants$root.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/Constants$root.java
deleted file mode 100644
index 0f04844e..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/Constants$root.java
+++ /dev/null
@@ -1,19 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.windows.gen.cfgmgr32;
-
-import static java.lang.foreign.ValueLayout.*;
-public class Constants$root {
-
- static final OfBoolean C_BOOL$LAYOUT = JAVA_BOOLEAN;
- static final OfByte C_CHAR$LAYOUT = JAVA_BYTE;
- static final OfShort C_SHORT$LAYOUT = JAVA_SHORT.withBitAlignment(16);
- static final OfInt C_INT$LAYOUT = JAVA_INT.withBitAlignment(32);
- static final OfInt C_LONG$LAYOUT = JAVA_INT.withBitAlignment(32);
- static final OfLong C_LONG_LONG$LAYOUT = JAVA_LONG.withBitAlignment(64);
- static final OfFloat C_FLOAT$LAYOUT = JAVA_FLOAT.withBitAlignment(32);
- static final OfDouble C_DOUBLE$LAYOUT = JAVA_DOUBLE.withBitAlignment(64);
- static final OfAddress C_POINTER$LAYOUT = ADDRESS.withBitAlignment(64);
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/RuntimeHelper.java
deleted file mode 100644
index 3ac64e04..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/RuntimeHelper.java
+++ /dev/null
@@ -1,216 +0,0 @@
-package net.codecrete.usb.windows.gen.cfgmgr32;
-// Generated by jextract
-
-import java.lang.foreign.*;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
-
-import static java.lang.foreign.ValueLayout.*;
-
-final class RuntimeHelper {
-
- private RuntimeHelper() {}
- private final static Linker LINKER = Linker.nativeLinker();
- private final static ClassLoader LOADER = RuntimeHelper.class.getClassLoader();
- private final static MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup();
- private final static SymbolLookup SYMBOL_LOOKUP;
-
- final static SegmentAllocator CONSTANT_ALLOCATOR =
- (size, align) -> MemorySegment.allocateNative(size, align, MemorySession.openImplicit());
-
- static {
- System.loadLibrary("Cfgmgr32");
- SymbolLookup loaderLookup = SymbolLookup.loaderLookup();
- SYMBOL_LOOKUP = name -> loaderLookup.lookup(name).or(() -> LINKER.defaultLookup().lookup(name));
- }
-
- static T requireNonNull(T obj, String symbolName) {
- if (obj == null) {
- throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName);
- }
- return obj;
- }
-
- private final static SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); };
-
- static final MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) {
- return SYMBOL_LOOKUP.lookup(name).map(symbol -> MemorySegment.ofAddress(symbol.address(), layout.byteSize(), MemorySession.openShared())).orElse(null);
- }
-
- static final MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) {
- return SYMBOL_LOOKUP.lookup(name).
- map(addr -> LINKER.downcallHandle(addr, fdesc)).
- orElse(null);
- }
-
- static final MethodHandle downcallHandle(FunctionDescriptor fdesc) {
- return LINKER.downcallHandle(fdesc);
- }
-
- static final MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) {
- return SYMBOL_LOOKUP.lookup(name).
- map(addr -> VarargsInvoker.make(addr, fdesc)).
- orElse(null);
- }
-
- static final MemorySegment upcallStub(Class fi, Z z, FunctionDescriptor fdesc, MemorySession session) {
- try {
- MethodHandle handle = MH_LOOKUP.findVirtual(fi, "apply", Linker.upcallType(fdesc));
- handle = handle.bindTo(z);
- return LINKER.upcallStub(handle, fdesc, session);
- } catch (Throwable ex) {
- throw new AssertionError(ex);
- }
- }
-
- static MemorySegment asArray(MemoryAddress addr, MemoryLayout layout, int numElements, MemorySession session) {
- return MemorySegment.ofAddress(addr, numElements * layout.byteSize(), session);
- }
-
- // Internals only below this point
-
- private static class VarargsInvoker {
- private static final MethodHandle INVOKE_MH;
- private final MemorySegment symbol;
- private final FunctionDescriptor function;
-
- private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) {
- this.symbol = symbol;
- this.function = function;
- }
-
- static {
- try {
- INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class));
- } catch (ReflectiveOperationException e) {
- throw new RuntimeException(e);
- }
- }
-
- static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) {
- VarargsInvoker invoker = new VarargsInvoker(symbol, function);
- MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1);
- MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class);
- for (MemoryLayout layout : function.argumentLayouts()) {
- mtype = mtype.appendParameterTypes(carrier(layout, false));
- }
- mtype = mtype.appendParameterTypes(Object[].class);
- if (mtype.returnType().equals(MemorySegment.class)) {
- mtype = mtype.insertParameterTypes(0, SegmentAllocator.class);
- } else {
- handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR);
- }
- return handle.asType(mtype);
- }
-
- static Class> carrier(MemoryLayout layout, boolean ret) {
- if (layout instanceof ValueLayout valueLayout) {
- return (ret || valueLayout.carrier() != MemoryAddress.class) ?
- valueLayout.carrier() : Addressable.class;
- } else if (layout instanceof GroupLayout) {
- return MemorySegment.class;
- } else {
- throw new AssertionError("Cannot get here!");
- }
- }
-
- private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable {
- // one trailing Object[]
- int nNamedArgs = function.argumentLayouts().size();
- assert(args.length == nNamedArgs + 1);
- // The last argument is the array of vararg collector
- Object[] unnamedArgs = (Object[]) args[args.length - 1];
-
- int argsCount = nNamedArgs + unnamedArgs.length;
- Class>[] argTypes = new Class>[argsCount];
- MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length];
-
- int pos = 0;
- for (pos = 0; pos < nNamedArgs; pos++) {
- argLayouts[pos] = function.argumentLayouts().get(pos);
- }
-
- assert pos == nNamedArgs;
- for (Object o: unnamedArgs) {
- argLayouts[pos] = variadicLayout(normalize(o.getClass()));
- pos++;
- }
- assert pos == argsCount;
-
- FunctionDescriptor f = (function.returnLayout().isEmpty()) ?
- FunctionDescriptor.ofVoid(argLayouts) :
- FunctionDescriptor.of(function.returnLayout().get(), argLayouts);
- MethodHandle mh = LINKER.downcallHandle(symbol, f);
- if (mh.type().returnType() == MemorySegment.class) {
- mh = mh.bindTo(allocator);
- }
- // flatten argument list so that it can be passed to an asSpreader MH
- Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length];
- System.arraycopy(args, 0, allArgs, 0, nNamedArgs);
- System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length);
-
- return mh.asSpreader(Object[].class, argsCount).invoke(allArgs);
- }
-
- private static Class> unboxIfNeeded(Class> clazz) {
- if (clazz == Boolean.class) {
- return boolean.class;
- } else if (clazz == Void.class) {
- return void.class;
- } else if (clazz == Byte.class) {
- return byte.class;
- } else if (clazz == Character.class) {
- return char.class;
- } else if (clazz == Short.class) {
- return short.class;
- } else if (clazz == Integer.class) {
- return int.class;
- } else if (clazz == Long.class) {
- return long.class;
- } else if (clazz == Float.class) {
- return float.class;
- } else if (clazz == Double.class) {
- return double.class;
- } else {
- return clazz;
- }
- }
-
- private Class> promote(Class> c) {
- if (c == byte.class || c == char.class || c == short.class || c == int.class) {
- return long.class;
- } else if (c == float.class) {
- return double.class;
- } else {
- return c;
- }
- }
-
- private Class> normalize(Class> c) {
- c = unboxIfNeeded(c);
- if (c.isPrimitive()) {
- return promote(c);
- }
- if (MemoryAddress.class.isAssignableFrom(c)) {
- return MemoryAddress.class;
- }
- if (MemorySegment.class.isAssignableFrom(c)) {
- return MemorySegment.class;
- }
- throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName());
- }
-
- private MemoryLayout variadicLayout(Class> c) {
- if (c == long.class) {
- return JAVA_LONG;
- } else if (c == double.class) {
- return JAVA_DOUBLE;
- } else if (MemoryAddress.class.isAssignableFrom(c)) {
- return ADDRESS;
- } else {
- throw new IllegalArgumentException("Unhandled variadic argument class: " + c);
- }
- }
- }
-}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/constants$0.java
deleted file mode 100644
index de3dd42c..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/cfgmgr32/constants$0.java
+++ /dev/null
@@ -1,30 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.windows.gen.cfgmgr32;
-
-import java.lang.foreign.FunctionDescriptor;
-import java.lang.invoke.MethodHandle;
-class constants$0 {
-
- static final FunctionDescriptor CM_Get_Device_IDW$FUNC = FunctionDescriptor.of(Constants$root.C_LONG$LAYOUT,
- Constants$root.C_LONG$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_LONG$LAYOUT,
- Constants$root.C_LONG$LAYOUT
- );
- static final MethodHandle CM_Get_Device_IDW$MH = RuntimeHelper.downcallHandle(
- "CM_Get_Device_IDW",
- constants$0.CM_Get_Device_IDW$FUNC
- );
- static final FunctionDescriptor CM_Get_Parent$FUNC = FunctionDescriptor.of(Constants$root.C_LONG$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_LONG$LAYOUT,
- Constants$root.C_LONG$LAYOUT
- );
- static final MethodHandle CM_Get_Parent$MH = RuntimeHelper.downcallHandle(
- "CM_Get_Parent",
- constants$0.CM_Get_Parent$FUNC
- );
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/Kernel32.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/Kernel32.java
index 21d2b421..e523709a 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/Kernel32.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/Kernel32.java
@@ -83,6 +83,12 @@ public static int GENERIC_READ() {
public static int GENERIC_WRITE() {
return (int)1073741824L;
}
+ public static int ERROR_SUCCESS() {
+ return (int)0L;
+ }
+ public static int ERROR_INSUFFICIENT_BUFFER() {
+ return (int)122L;
+ }
public static int ERROR_NO_MORE_ITEMS() {
return (int)259L;
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SetupAPI.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SetupAPI.java
index 88cd7162..ad616e12 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SetupAPI.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SetupAPI.java
@@ -18,6 +18,12 @@ public class SetupAPI {
public static OfFloat C_FLOAT = Constants$root.C_FLOAT$LAYOUT;
public static OfDouble C_DOUBLE = Constants$root.C_DOUBLE$LAYOUT;
public static OfAddress C_POINTER = Constants$root.C_POINTER$LAYOUT;
+ public static int DEVPROP_TYPE_UINT32() {
+ return (int)7L;
+ }
+ public static int DEVPROP_TYPE_STRING() {
+ return (int)18L;
+ }
public static int DIGCF_PRESENT() {
return (int)2L;
}
@@ -79,8 +85,19 @@ public static MemoryAddress SetupDiGetClassDevsW ( Addressable ClassGuid, Addre
throw new AssertionError("should not reach here", ex$);
}
}
+ public static MethodHandle SetupDiGetDevicePropertyW$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.SetupDiGetDevicePropertyW$MH,"SetupDiGetDevicePropertyW");
+ }
+ public static int SetupDiGetDevicePropertyW ( Addressable DeviceInfoSet, Addressable DeviceInfoData, Addressable PropertyKey, Addressable PropertyType, Addressable PropertyBuffer, int PropertyBufferSize, Addressable RequiredSize, int Flags) {
+ var mh$ = SetupDiGetDevicePropertyW$MH();
+ try {
+ return (int)mh$.invokeExact(DeviceInfoSet, DeviceInfoData, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
public static MethodHandle SetupDiGetDeviceRegistryPropertyW$MH() {
- return RuntimeHelper.requireNonNull(constants$0.SetupDiGetDeviceRegistryPropertyW$MH,"SetupDiGetDeviceRegistryPropertyW");
+ return RuntimeHelper.requireNonNull(constants$1.SetupDiGetDeviceRegistryPropertyW$MH,"SetupDiGetDeviceRegistryPropertyW");
}
public static int SetupDiGetDeviceRegistryPropertyW ( Addressable DeviceInfoSet, Addressable DeviceInfoData, int Property, Addressable PropertyRegDataType, Addressable PropertyBuffer, int PropertyBufferSize, Addressable RequiredSize) {
var mh$ = SetupDiGetDeviceRegistryPropertyW$MH();
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$0.java
index 1c6554b3..00f31e8b 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$0.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$0.java
@@ -55,18 +55,19 @@ class constants$0 {
"SetupDiGetClassDevsW",
constants$0.SetupDiGetClassDevsW$FUNC
);
- static final FunctionDescriptor SetupDiGetDeviceRegistryPropertyW$FUNC = FunctionDescriptor.of(Constants$root.C_LONG$LAYOUT,
+ static final FunctionDescriptor SetupDiGetDevicePropertyW$FUNC = FunctionDescriptor.of(Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
Constants$root.C_POINTER$LAYOUT,
Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_LONG$LAYOUT,
Constants$root.C_POINTER$LAYOUT,
Constants$root.C_POINTER$LAYOUT,
Constants$root.C_LONG$LAYOUT,
- Constants$root.C_POINTER$LAYOUT
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT
);
- static final MethodHandle SetupDiGetDeviceRegistryPropertyW$MH = RuntimeHelper.downcallHandle(
- "SetupDiGetDeviceRegistryPropertyW",
- constants$0.SetupDiGetDeviceRegistryPropertyW$FUNC
+ static final MethodHandle SetupDiGetDevicePropertyW$MH = RuntimeHelper.downcallHandle(
+ "SetupDiGetDevicePropertyW",
+ constants$0.SetupDiGetDevicePropertyW$FUNC
);
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$1.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$1.java
new file mode 100644
index 00000000..74594195
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$1.java
@@ -0,0 +1,24 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.setupapi;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$1 {
+
+ static final FunctionDescriptor SetupDiGetDeviceRegistryPropertyW$FUNC = FunctionDescriptor.of(Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle SetupDiGetDeviceRegistryPropertyW$MH = RuntimeHelper.downcallHandle(
+ "SetupDiGetDeviceRegistryPropertyW",
+ constants$1.SetupDiGetDeviceRegistryPropertyW$FUNC
+ );
+}
+
+
From 9f9ab90ed58a5b17c87d6ef74efcaaee640c0bdc Mon Sep 17 00:00:00 2001
From: Manuel Bl
Date: Sun, 28 Aug 2022 20:22:43 +0200
Subject: [PATCH 016/433] Windows: clean up string conversion
---
.../codecrete/usb/windows/DeviceProperty.java | 9 ++---
.../java/net/codecrete/usb/windows/Win.java | 33 +++++++++++++++++++
.../usb/windows/WindowsUSBDevice.java | 5 +--
.../usb/windows/WindowsUSBDeviceRegistry.java | 4 +--
4 files changed, 39 insertions(+), 12 deletions(-)
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/DeviceProperty.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/DeviceProperty.java
index 133651b3..ce0a54dc 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/DeviceProperty.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/DeviceProperty.java
@@ -12,7 +12,6 @@
import net.codecrete.usb.windows.gen.kernel32._GUID;
import net.codecrete.usb.windows.gen.setupapi.SetupAPI;
import net.codecrete.usb.windows.gen.setupapi._SP_DEVICE_INTERFACE_DATA;
-import net.codecrete.usb.windows.gen.stdlib.StdLib;
import java.lang.foreign.Addressable;
import java.lang.foreign.MemorySegment;
@@ -75,15 +74,14 @@ public static String getDeviceStringProperty(Addressable devInfo, Addressable de
propertyValueHolder, (int) propertyValueHolder.byteSize(), NULL, 0) == 0)
throw new USBException("Internal error (SetupDiGetDevicePropertyW)", Kernel32.GetLastError());
- return new String(propertyValueHolder.asSlice(0, 2L * stringLen).toArray(JAVA_CHAR));
+ return Win.createStringFromSegment(propertyValueHolder);
}
}
public static String getDevicePath(String instanceID, Addressable interfaceGuid) {
try (var session = MemorySession.openConfined()) {
// get device info set for instance
- var instanceIDSegment = session.allocateArray(JAVA_CHAR, instanceID.length() + 1);
- instanceIDSegment.asSlice(0, instanceID.length() * 2L).copyFrom(MemorySegment.ofArray(instanceID.toCharArray()));
+ var instanceIDSegment = Win.createSegmentFromString(instanceID, session);
final var devInfoSetHandle = SetupAPI.SetupDiGetClassDevsW(interfaceGuid, instanceIDSegment, NULL, SetupAPI.DIGCF_PRESENT() | SetupAPI.DIGCF_DEVICEINTERFACE());
if (Win.IsInvalidHandle(devInfoSetHandle))
throw new USBException("internal error (SetupDiGetClassDevsW)");
@@ -105,8 +103,7 @@ public static String getDevicePath(String instanceID, Addressable interfaceGuid)
intfDetailData, intfDetailDataSize, NULL, NULL) == 0)
throw new USBException("Internal error (SetupDiGetDeviceInterfaceDetailW)", Kernel32.GetLastError());
- long pathLen = StdLib.wcslen(intfDetailData.address().addOffset(SP_DEVICE_INTERFACE_DETAIL_DATA_W.DevicePath$Offset));
- return new String(intfDetailData.asSlice(SP_DEVICE_INTERFACE_DETAIL_DATA_W.DevicePath$Offset, 2L * pathLen).toArray(JAVA_CHAR));
+ return Win.createStringFromSegment(intfDetailData.asSlice(SP_DEVICE_INTERFACE_DETAIL_DATA_W.DevicePath$Offset));
}
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/Win.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/Win.java
index 22ecb309..c850dc72 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/Win.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/Win.java
@@ -8,12 +8,15 @@
package net.codecrete.usb.windows;
import net.codecrete.usb.windows.gen.kernel32._GUID;
+import net.codecrete.usb.windows.gen.stdlib.StdLib;
import java.lang.foreign.MemoryAddress;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.MemorySession;
+import java.lang.foreign.ValueLayout;
import static java.lang.foreign.ValueLayout.JAVA_BYTE;
+import static java.lang.foreign.ValueLayout.JAVA_CHAR;
/**
* Windows helpers.
@@ -30,6 +33,36 @@ public static boolean IsInvalidHandle(MemoryAddress handle) {
return handle.toRawLongValue() == -1L;
}
+ /**
+ * Creates a memory segment as a copy of a Java string.
+ *
+ * The memory segment contains a copy of the string (null-terminated, UTF-16/wide characters).
+ *
+ * @param str the string to copy
+ * @param session the memory session for the memory segment
+ * @return the resulting memory segment
+ */
+ public static MemorySegment createSegmentFromString(String str, MemorySession session) {
+ // allocate segment (including space for terminating null)
+ var segment = session.allocateArray(ValueLayout.JAVA_CHAR, str.length() + 1);
+ // copy characters
+ segment.copyFrom(MemorySegment.ofArray(str.toCharArray()));
+ return segment;
+ }
+
+ /**
+ * Creates a copy of the string in the memory segment.
+ *
+ * The string must be a null-terminated UTF-16 (wide character) string.
+ *
+ * @param segment the memory segment
+ * @return copied string
+ */
+ public static String createStringFromSegment(MemorySegment segment) {
+ long strLen = StdLib.wcslen(segment);
+ return new String(segment.asSlice(0, 2L * strLen).toArray(JAVA_CHAR));
+ }
+
/**
* Creates a GUID in native memory.
*
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDevice.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDevice.java
index a637c22e..eeee50b1 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDevice.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDevice.java
@@ -23,7 +23,6 @@
import java.lang.foreign.MemoryAddress;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.MemorySession;
-import java.lang.foreign.ValueLayout;
import java.util.ArrayList;
import java.util.List;
@@ -50,9 +49,7 @@ public class WindowsUSBDevice extends USBDeviceImpl {
try (var session = MemorySession.openConfined()) {
// open Windows device
- var pathChars = id.toString().toCharArray();
- var pathSegment = session.allocateArray(ValueLayout.JAVA_CHAR, pathChars.length + 1);
- pathSegment.copyFrom(MemorySegment.ofArray(pathChars));
+ var pathSegment = Win.createSegmentFromString(id.toString(), session);
device = Kernel32.CreateFileW(pathSegment,
Kernel32.GENERIC_WRITE() | Kernel32.GENERIC_READ(),
Kernel32.FILE_SHARE_WRITE() | Kernel32.FILE_SHARE_READ(),
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
index 3df7cbbd..2061d3c6 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
@@ -67,8 +67,7 @@ public List getAllDevices() {
var hubPath = DeviceProperty.getDevicePath(parentInstanceID, USBHelper.GUID_DEVINTERFACE_USB_HUB);
// open hub
- var hubPathSeg = session.allocateArray(JAVA_CHAR, hubPath.length() + 2);
- hubPathSeg.copyFrom(MemorySegment.ofArray(hubPath.toCharArray()));
+ var hubPathSeg = Win.createSegmentFromString(hubPath, session);
final var hubHandle = Kernel32.CreateFileW(hubPathSeg, Kernel32.GENERIC_WRITE(), Kernel32.FILE_SHARE_WRITE(),
NULL, Kernel32.OPEN_EXISTING(), 0, NULL);
if (Win.IsInvalidHandle(hubHandle))
@@ -152,6 +151,7 @@ private String getStringDescriptor(Addressable hubHandle, int usbPortNumber, int
sizeHolder, NULL) == 0)
throw new USBException(String.format("Cannot retrieve string descriptor %d", index), Kernel32.GetLastError());
+ // The string descriptor is not null terminated
var stringDesc = descriptorRequest.asSlice(USBHelper.USB_DESCRIPTOR_REQUEST_Data$Offset, dataLen);
int stringLen = 255 & (byte) USBHelper.USB_STRING_DESCRIPTOR_bLength.get(stringDesc);
var chars = stringDesc.asSlice(USBHelper.USB_STRING_DESCRIPTOR_bString$Offset, stringLen - 2)
From 4c8e2ea002a177051ce0284d4d4b9dd23902fbee Mon Sep 17 00:00:00 2001
From: Manuel Bl
Date: Sun, 28 Aug 2022 23:01:32 +0200
Subject: [PATCH 017/433] Windows: monitor connect/disconnect
---
java-does-usb/jextract/gen_win_cfgmgr32.cmd | 12 -
java-does-usb/jextract/gen_win_kernel32.cmd | 1 +
java-does-usb/jextract/gen_win_setupapi.cmd | 1 +
java-does-usb/jextract/gen_win_user32.cmd | 25 ++
java-does-usb/jextract/windows_headers.h | 1 +
.../usb/windows/WindowsUSBDeviceInfo.java | 8 +-
.../usb/windows/WindowsUSBDeviceRegistry.java | 258 ++++++++++++++++--
.../usb/windows/gen/kernel32/Kernel32.java | 11 +
.../usb/windows/gen/kernel32/constants$0.java | 7 +
.../usb/windows/gen/setupapi/SetupAPI.java | 13 +-
.../usb/windows/gen/setupapi/constants$0.java | 24 +-
.../usb/windows/gen/setupapi/constants$1.java | 14 +
.../windows/gen/user32/Constants$root.java | 19 ++
.../usb/windows/gen/user32/RuntimeHelper.java | 216 +++++++++++++++
.../usb/windows/gen/user32/User32.java | 96 +++++++
.../_DEV_BROADCAST_DEVICEINTERFACE_W.java | 87 ++++++
.../gen/user32/_DEV_BROADCAST_HDR.java | 73 +++++
.../usb/windows/gen/user32/constants$0.java | 67 +++++
.../usb/windows/gen/user32/tagMSG.java | 116 ++++++++
.../windows/gen/user32/tagWNDCLASSEXW.java | 226 +++++++++++++++
20 files changed, 1222 insertions(+), 53 deletions(-)
delete mode 100644 java-does-usb/jextract/gen_win_cfgmgr32.cmd
create mode 100644 java-does-usb/jextract/gen_win_user32.cmd
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/Constants$root.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/RuntimeHelper.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/User32.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/_DEV_BROADCAST_DEVICEINTERFACE_W.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/_DEV_BROADCAST_HDR.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/constants$0.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/tagMSG.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/tagWNDCLASSEXW.java
diff --git a/java-does-usb/jextract/gen_win_cfgmgr32.cmd b/java-does-usb/jextract/gen_win_cfgmgr32.cmd
deleted file mode 100644
index 320f0d0b..00000000
--- a/java-does-usb/jextract/gen_win_cfgmgr32.cmd
+++ /dev/null
@@ -1,12 +0,0 @@
-set JEXTRACT=..\..\..\jextract\build\jextract\bin\jextract.bat
-set SDK_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0
-%JEXTRACT% --source --output ../src/main/java ^
- -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
- -I "%SDK_DIR%\um" ^
- -I "%SDK_DIR%\shared" ^
- -l Cfgmgr32 ^
- --header-class-name CfgMgr32 ^
- --target-package net.codecrete.usb.windows.gen.cfgmgr32 ^
- --include-function CM_Get_Parent ^
- --include-function CM_Get_Device_IDW ^
- windows_headers.h
diff --git a/java-does-usb/jextract/gen_win_kernel32.cmd b/java-does-usb/jextract/gen_win_kernel32.cmd
index 2f524df8..08aa4d94 100644
--- a/java-does-usb/jextract/gen_win_kernel32.cmd
+++ b/java-does-usb/jextract/gen_win_kernel32.cmd
@@ -11,6 +11,7 @@ set SDK_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0
--include-function CloseHandle ^
--include-function DeviceIoControl ^
--include-function GetLastError ^
+ --include-function GetModuleHandleW ^
--include-macro ERROR_SUCCESS ^
--include-macro ERROR_NO_MORE_ITEMS ^
--include-macro ERROR_INSUFFICIENT_BUFFER ^
diff --git a/java-does-usb/jextract/gen_win_setupapi.cmd b/java-does-usb/jextract/gen_win_setupapi.cmd
index 187cb288..edaf3411 100644
--- a/java-does-usb/jextract/gen_win_setupapi.cmd
+++ b/java-does-usb/jextract/gen_win_setupapi.cmd
@@ -14,6 +14,7 @@ set SDK_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0
--include-function SetupDiGetDeviceInterfaceDetailW ^
--include-function SetupDiGetDeviceRegistryPropertyW ^
--include-function SetupDiGetDevicePropertyW ^
+ --include-function SetupDiOpenDeviceInterfaceW ^
--include-struct _SP_DEVINFO_DATA ^
--include-struct _SP_DEVICE_INTERFACE_DATA ^
--include-struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W ^
diff --git a/java-does-usb/jextract/gen_win_user32.cmd b/java-does-usb/jextract/gen_win_user32.cmd
new file mode 100644
index 00000000..14f5ad2a
--- /dev/null
+++ b/java-does-usb/jextract/gen_win_user32.cmd
@@ -0,0 +1,25 @@
+set JEXTRACT=..\..\..\jextract\build\jextract\bin\jextract.bat
+set SDK_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0
+%JEXTRACT% --source --output ../src/main/java ^
+ -D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
+ -I "%SDK_DIR%\um" ^
+ -I "%SDK_DIR%\shared" ^
+ -l User32 ^
+ --header-class-name User32 ^
+ --target-package net.codecrete.usb.windows.gen.user32 ^
+ --include-function RegisterClassExW ^
+ --include-function CreateWindowExW ^
+ --include-function RegisterDeviceNotificationW ^
+ --include-function GetMessageW ^
+ --include-function DefWindowProcW ^
+ --include-macro DEVICE_NOTIFY_WINDOW_HANDLE ^
+ --include-macro HWND_MESSAGE ^
+ --include-macro WM_DEVICECHANGE ^
+ --include-macro DBT_DEVICEARRIVAL ^
+ --include-macro DBT_DEVICEREMOVECOMPLETE ^
+ --include-macro DBT_DEVTYP_DEVICEINTERFACE ^
+ --include-struct tagMSG ^
+ --include-struct tagWNDCLASSEXW ^
+ --include-struct _DEV_BROADCAST_HDR ^
+ --include-struct _DEV_BROADCAST_DEVICEINTERFACE_W ^
+ windows_headers.h
diff --git a/java-does-usb/jextract/windows_headers.h b/java-does-usb/jextract/windows_headers.h
index a863aa14..fbc95ecb 100644
--- a/java-does-usb/jextract/windows_headers.h
+++ b/java-does-usb/jextract/windows_headers.h
@@ -3,3 +3,4 @@
#include
#include
#include
+#include
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceInfo.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceInfo.java
index 1c0a3763..b93ca796 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceInfo.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceInfo.java
@@ -15,17 +15,21 @@ public class WindowsUSBDeviceInfo extends USBDeviceInfoImpl {
private final byte currentConfigurationValue;
WindowsUSBDeviceInfo(
- Object id, int vendorId, int productId,
+ String devicePath, int vendorId, int productId,
String manufacturer, String product, String serial,
int classCode, int subclassCode, int protocolCode,
byte currentConfigurationValue) {
- super(id, vendorId, productId,
+ super(devicePath, vendorId, productId,
manufacturer, product, serial,
classCode, subclassCode, protocolCode);
this.currentConfigurationValue = currentConfigurationValue;
}
+ String devicePath() {
+ return (String) id;
+ }
+
@Override
public USBDevice open() {
return new WindowsUSBDevice(id, this, currentConfigurationValue);
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
index 2061d3c6..0f040c5c 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
@@ -14,26 +14,47 @@
import net.codecrete.usb.common.USBStructs;
import net.codecrete.usb.windows.gen.kernel32.Kernel32;
import net.codecrete.usb.windows.gen.setupapi.SetupAPI;
+import net.codecrete.usb.windows.gen.setupapi._SP_DEVICE_INTERFACE_DATA;
import net.codecrete.usb.windows.gen.setupapi._SP_DEVINFO_DATA;
import net.codecrete.usb.windows.gen.usbioctl.USBIoctl;
+import net.codecrete.usb.windows.gen.user32.*;
-import java.lang.foreign.Addressable;
-import java.lang.foreign.MemoryAddress;
-import java.lang.foreign.MemorySegment;
-import java.lang.foreign.MemorySession;
+import java.lang.foreign.*;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.function.Consumer;
import static java.lang.foreign.MemoryAddress.NULL;
-import static java.lang.foreign.ValueLayout.JAVA_CHAR;
-import static java.lang.foreign.ValueLayout.JAVA_INT;
+import static java.lang.foreign.ValueLayout.*;
public class WindowsUSBDeviceRegistry implements USBDeviceRegistry {
+ private volatile List devices;
+ private Consumer onDeviceConnectedHandler;
+ private Consumer onDeviceDisconnectedHandler;
+ private boolean isMonitorThreadStarted;
+
+ /**
+ * Create new instance
+ *
+ * Starts a second thread and immediately iterates all USB devices.
+ *
+ */
+ public WindowsUSBDeviceRegistry() {
+ startDeviceMonitor();
+ enumeratePresentDevices();
+ }
+
public List getAllDevices() {
+ return devices;
+ }
+
+ private void enumeratePresentDevices() {
- List result = new ArrayList<>();
+ List deviceList = new ArrayList<>();
try (var outerSession = MemorySession.openConfined()) {
// get device information set of all USB devices present
@@ -49,38 +70,49 @@ public List getAllDevices() {
var devInfo = MemorySegment.allocateNative(_SP_DEVINFO_DATA.$LAYOUT(), outerSession);
_SP_DEVINFO_DATA.cbSize$set(devInfo, (int) _SP_DEVINFO_DATA.$LAYOUT().byteSize());
+ // ensure all hubs are closed later
+ final var hubHandles = new HashMap();
+ outerSession.addCloseAction(() -> hubHandles.forEach((path, handle) -> Kernel32.CloseHandle(handle)));
+
// iterate all devices
for (int i = 0; true; i++) {
if (SetupAPI.SetupDiEnumDeviceInfo(devInfoSetHandle, i, devInfo) == 0) {
int err = Kernel32.GetLastError();
+ // TODO: Remove check for ERROR_SUCCESS if proper GetLastError() handling is available
if (err == Kernel32.ERROR_NO_MORE_ITEMS() || err == Kernel32.ERROR_SUCCESS())
break;
throw new USBException("Internal error (SetupDiEnumDeviceInfo) ");
}
- try (var session = MemorySession.openConfined()) {
+ var instanceID = DeviceProperty.getDeviceStringProperty(devInfoSetHandle, devInfo, DeviceProperty.DEVPKEY_Device_InstanceId);
+ var devicePath = DeviceProperty.getDevicePath(instanceID, USBHelper.GUID_DEVINTERFACE_USB_DEVICE);
- var usbPortNum = DeviceProperty.getDeviceIntProperty(devInfoSetHandle, devInfo, DeviceProperty.DEVPKEY_Device_Address);
- var instanceID = DeviceProperty.getDeviceStringProperty(devInfoSetHandle, devInfo, DeviceProperty.DEVPKEY_Device_InstanceId);
- var devicePath = DeviceProperty.getDevicePath(instanceID, USBHelper.GUID_DEVINTERFACE_USB_DEVICE);
- var parentInstanceID = DeviceProperty.getDeviceStringProperty(devInfoSetHandle, devInfo, DeviceProperty.DEVPKEY_Device_Parent);
- var hubPath = DeviceProperty.getDevicePath(parentInstanceID, USBHelper.GUID_DEVINTERFACE_USB_HUB);
+ deviceList.add(createDeviceInfo(devInfoSetHandle, devInfo, devicePath, hubHandles));
+ }
- // open hub
- var hubPathSeg = Win.createSegmentFromString(hubPath, session);
- final var hubHandle = Kernel32.CreateFileW(hubPathSeg, Kernel32.GENERIC_WRITE(), Kernel32.FILE_SHARE_WRITE(),
- NULL, Kernel32.OPEN_EXISTING(), 0, NULL);
- if (Win.IsInvalidHandle(hubHandle))
- throw new USBException("Cannot open USB hub", Kernel32.GetLastError());
+ devices = deviceList;
+ }
+ }
- // ensure the hub is closed later
- session.addCloseAction(() -> Kernel32.CloseHandle(hubHandle));
+ private USBDeviceInfo createDeviceInfo(MemoryAddress devInfoSetHandle, MemorySegment devInfo, String devicePath, HashMap hubHandles) {
+ try (var session = MemorySession.openConfined()) {
- result.add(createDeviceInfo(devicePath, hubHandle, usbPortNum));
- }
+ var usbPortNum = DeviceProperty.getDeviceIntProperty(devInfoSetHandle, devInfo, DeviceProperty.DEVPKEY_Device_Address);
+ var parentInstanceID = DeviceProperty.getDeviceStringProperty(devInfoSetHandle, devInfo, DeviceProperty.DEVPKEY_Device_Parent);
+ var hubPath = DeviceProperty.getDevicePath(parentInstanceID, USBHelper.GUID_DEVINTERFACE_USB_HUB);
+
+ // open hub if not open yet
+ var hubHandle = hubHandles.get(hubPath);
+ if (hubHandle == null) {
+ var hubPathSeg = Win.createSegmentFromString(hubPath, session);
+ hubHandle = Kernel32.CreateFileW(hubPathSeg, Kernel32.GENERIC_WRITE(), Kernel32.FILE_SHARE_WRITE(),
+ NULL, Kernel32.OPEN_EXISTING(), 0, NULL);
+ if (Win.IsInvalidHandle(hubHandle))
+ throw new USBException("Cannot open USB hub", Kernel32.GetLastError());
+ hubHandles.put(hubPath, hubHandle);
}
- return result;
+ return createDeviceInfo(devicePath, hubHandle, usbPortNum);
}
}
@@ -160,11 +192,189 @@ private String getStringDescriptor(Addressable hubHandle, int usbPortNumber, int
}
}
+ private synchronized void startDeviceMonitor() {
+ if (isMonitorThreadStarted)
+ return;
+
+ isMonitorThreadStarted = true;
+ Thread t = new Thread(this::monitorDevices, "USB device monitor");
+ t.start();
+ }
+
+ private void monitorDevices() {
+ try (var session = MemorySession.openConfined()) {
+
+ final var className = Win.createSegmentFromString("USB_MONITOR", session);
+ final var windowName = Win.createSegmentFromString("USB device monitor", session);
+ final var instance = Kernel32.GetModuleHandleW(NULL);
+
+ // create upcall for handling window messages
+ var handleWindowMessageMH = MethodHandles.lookup().findVirtual(
+ WindowsUSBDeviceRegistry.class,
+ "handleWindowMessage",
+ MethodType.methodType(long.class, MemoryAddress.class, int.class, long.class, long.class)
+ ).bindTo(this);
+ var handleWindowMessageStub = Linker.nativeLinker().upcallStub(
+ handleWindowMessageMH,
+ FunctionDescriptor.of(JAVA_LONG, ADDRESS, JAVA_INT, JAVA_LONG, JAVA_LONG),
+ session
+ );
+
+ // register window class
+ var wx = session.allocate(tagWNDCLASSEXW.$LAYOUT());
+ tagWNDCLASSEXW.cbSize$set(wx, (int) wx.byteSize());
+ tagWNDCLASSEXW.lpfnWndProc$set(wx, handleWindowMessageStub.address());
+ tagWNDCLASSEXW.hInstance$set(wx, instance);
+ tagWNDCLASSEXW.lpszClassName$set(wx, className.address());
+ User32.RegisterClassExW(wx);
+
+ // create message-only window
+ Addressable hwnd = User32.CreateWindowExW(0, className, windowName, 0,
+ 0, 0, 0, 0, User32.HWND_MESSAGE(), NULL, instance, NULL);
+ if (hwnd == NULL)
+ throw new USBException("internal error (CreateWindowExW)", Kernel32.GetLastError());
+
+ // configure notifications
+ var notificationFilter = session.allocate(_DEV_BROADCAST_DEVICEINTERFACE_W.$LAYOUT());
+ _DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_size$set(notificationFilter, (int) notificationFilter.byteSize());
+ _DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_devicetype$set(notificationFilter, User32.DBT_DEVTYP_DEVICEINTERFACE());
+ _DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_classguid$slice(notificationFilter).copyFrom(USBHelper.GUID_DEVINTERFACE_USB_DEVICE);
+
+ var notifyHandle = User32.RegisterDeviceNotificationW(hwnd, notificationFilter, User32.DEVICE_NOTIFY_WINDOW_HANDLE());
+ if (notifyHandle == NULL)
+ throw new USBException("internal error (RegisterDeviceNotificationW)", Kernel32.GetLastError());
+
+ // process messages
+ var msg = session.allocate(tagMSG.$LAYOUT());
+ while (User32.GetMessageW(msg, hwnd, 0, 0) > 0)
+ ; // do nothing
+
+ } catch (NoSuchMethodException | IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private long handleWindowMessage(MemoryAddress hWnd, int uMsg, long wParam, long lParam) {
+
+ // check for message related to connecting/disconnecting devices
+ if (uMsg == User32.WM_DEVICECHANGE() && (wParam == User32.DBT_DEVICEARRIVAL() || wParam == User32.DBT_DEVICEREMOVECOMPLETE())) {
+ try (var session = MemorySession.openConfined()) {
+ var data = MemorySegment.ofAddress(MemoryAddress.ofLong(lParam), _DEV_BROADCAST_DEVICEINTERFACE_W.sizeof(), session);
+ if (_DEV_BROADCAST_HDR.dbch_devicetype$get(data) == User32.DBT_DEVTYP_DEVICEINTERFACE()) {
+
+ // get device path
+ var nameSlice = MemorySegment.ofAddress(_DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_name$slice(data).address(), 500, session);
+ var devicePath = Win.createStringFromSegment(nameSlice);
+ if (wParam == User32.DBT_DEVICEARRIVAL())
+ onDeviceConnected(devicePath);
+ else
+ onDeviceDisconnected(devicePath);
+ return 0;
+ }
+ }
+ }
+
+ // default message handling
+ return User32.DefWindowProcW(hWnd, uMsg, wParam, lParam);
+ }
+
+ private void onDeviceConnected(String devicePath) {
+ try (var session = MemorySession.openConfined()) {
+
+ // get device information set of all USB devices present
+ final var devInfoSetHandle = SetupAPI.SetupDiGetClassDevsW(
+ USBHelper.GUID_DEVINTERFACE_USB_DEVICE, NULL, NULL,
+ SetupAPI.DIGCF_PRESENT() | SetupAPI.DIGCF_DEVICEINTERFACE());
+ if (Win.IsInvalidHandle(devInfoSetHandle))
+ throw new USBException("internal error (SetupDiGetClassDevsW)", Kernel32.GetLastError());
+
+ // ensure the result is destroyed when the scope is left
+ session.addCloseAction(() -> SetupAPI.SetupDiDestroyDeviceInfoList(devInfoSetHandle));
+
+ var devIntfData = session.allocate(_SP_DEVICE_INTERFACE_DATA.$LAYOUT());
+ _SP_DEVICE_INTERFACE_DATA.cbSize$set(devIntfData, (int) devIntfData.byteSize());
+ var devicePathSegment = Win.createSegmentFromString(devicePath, session);
+ if (SetupAPI.SetupDiOpenDeviceInterfaceW(devInfoSetHandle, devicePathSegment, 0, devIntfData) == 0)
+ throw new USBException("internal error (SetupDiOpenDeviceInterfaceW)", Kernel32.GetLastError());
+
+ var devInfo = session.allocate(_SP_DEVINFO_DATA.$LAYOUT());
+ _SP_DEVINFO_DATA.cbSize$set(devInfo, (int) devInfo.byteSize());
+ if (SetupAPI.SetupDiGetDeviceInterfaceDetailW(devInfoSetHandle, devIntfData, NULL, 0, NULL, devInfo) == 0) {
+ int err = Kernel32.GetLastError();
+ if (err != Kernel32.ERROR_INSUFFICIENT_BUFFER())
+ throw new USBException("internal error (SetupDiGetDeviceInterfaceDetailW)", err);
+ }
+
+ // ensure all hubs are closed later
+ final var hubHandles = new HashMap();
+ session.addCloseAction(() -> hubHandles.forEach((path, handle) -> Kernel32.CloseHandle(handle)));
+
+ // check for duplicates
+ if (findDeviceIndex(devicePath) >= 0)
+ return;
+
+ // create device info instance
+ var deviceInfo = createDeviceInfo(devInfoSetHandle, devInfo, devicePath, hubHandles);
+
+ // copy list
+ var newDeviceList = new ArrayList<>(devices);
+ newDeviceList.add(deviceInfo);
+ devices = newDeviceList;
+
+ // send notification
+ if (onDeviceConnectedHandler == null)
+ return;
+ onDeviceConnectedHandler.accept(deviceInfo);
+ }
+ }
+
+ private void onDeviceDisconnected(String devicePath) {
+ int index = findDeviceIndex(devicePath);
+ if (index < 0)
+ return; // strange
+
+ // copy list
+ var deviceInfo = devices.get(index);
+ var newDeviceList = new ArrayList<>(devices);
+ newDeviceList.remove(index);
+ devices = newDeviceList;
+
+ // send notification
+ if (onDeviceDisconnectedHandler == null)
+ return;
+ onDeviceDisconnectedHandler.accept(deviceInfo);
+ }
+
+ private int findDeviceIndex(String devicePath) {
+ if (devices == null)
+ return -1;
+ for (int i = 0; i < devices.size(); i++) {
+ var winInfo = (WindowsUSBDeviceInfo) devices.get(i);
+ if (winInfo.devicePath().equalsIgnoreCase(devicePath))
+ return i;
+ }
+ return -1;
+ }
+
@Override
public void setOnDeviceConnected(Consumer handler) {
+ if (handler == null) {
+ onDeviceConnectedHandler = null;
+ return;
+ }
+
+ onDeviceConnectedHandler = handler;
+ startDeviceMonitor();
}
@Override
public void setOnDeviceDisconnected(Consumer handler) {
+ if (handler == null) {
+ onDeviceDisconnectedHandler = null;
+ return;
+ }
+
+ onDeviceDisconnectedHandler = handler;
+ startDeviceMonitor();
}
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/Kernel32.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/Kernel32.java
index e523709a..1e481c41 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/Kernel32.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/Kernel32.java
@@ -77,6 +77,17 @@ public static int DeviceIoControl ( Addressable hDevice, int dwIoControlCode,
throw new AssertionError("should not reach here", ex$);
}
}
+ public static MethodHandle GetModuleHandleW$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.GetModuleHandleW$MH,"GetModuleHandleW");
+ }
+ public static MemoryAddress GetModuleHandleW ( Addressable lpModuleName) {
+ var mh$ = GetModuleHandleW$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact(lpModuleName);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
public static int GENERIC_READ() {
return (int)2147483648L;
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/constants$0.java
index a350bf86..44c3452b 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/constants$0.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/constants$0.java
@@ -45,6 +45,13 @@ class constants$0 {
"DeviceIoControl",
constants$0.DeviceIoControl$FUNC
);
+ static final FunctionDescriptor GetModuleHandleW$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle GetModuleHandleW$MH = RuntimeHelper.downcallHandle(
+ "GetModuleHandleW",
+ constants$0.GetModuleHandleW$FUNC
+ );
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SetupAPI.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SetupAPI.java
index ad616e12..ff69c87e 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SetupAPI.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SetupAPI.java
@@ -63,6 +63,17 @@ public static int SetupDiEnumDeviceInterfaces ( Addressable DeviceInfoSet, Addr
throw new AssertionError("should not reach here", ex$);
}
}
+ public static MethodHandle SetupDiOpenDeviceInterfaceW$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.SetupDiOpenDeviceInterfaceW$MH,"SetupDiOpenDeviceInterfaceW");
+ }
+ public static int SetupDiOpenDeviceInterfaceW ( Addressable DeviceInfoSet, Addressable DevicePath, int OpenFlags, Addressable DeviceInterfaceData) {
+ var mh$ = SetupDiOpenDeviceInterfaceW$MH();
+ try {
+ return (int)mh$.invokeExact(DeviceInfoSet, DevicePath, OpenFlags, DeviceInterfaceData);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
public static MethodHandle SetupDiGetDeviceInterfaceDetailW$MH() {
return RuntimeHelper.requireNonNull(constants$0.SetupDiGetDeviceInterfaceDetailW$MH,"SetupDiGetDeviceInterfaceDetailW");
}
@@ -86,7 +97,7 @@ public static MemoryAddress SetupDiGetClassDevsW ( Addressable ClassGuid, Addre
}
}
public static MethodHandle SetupDiGetDevicePropertyW$MH() {
- return RuntimeHelper.requireNonNull(constants$0.SetupDiGetDevicePropertyW$MH,"SetupDiGetDevicePropertyW");
+ return RuntimeHelper.requireNonNull(constants$1.SetupDiGetDevicePropertyW$MH,"SetupDiGetDevicePropertyW");
}
public static int SetupDiGetDevicePropertyW ( Addressable DeviceInfoSet, Addressable DeviceInfoData, Addressable PropertyKey, Addressable PropertyType, Addressable PropertyBuffer, int PropertyBufferSize, Addressable RequiredSize, int Flags) {
var mh$ = SetupDiGetDevicePropertyW$MH();
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$0.java
index 00f31e8b..4bec4d2c 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$0.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$0.java
@@ -33,6 +33,16 @@ class constants$0 {
"SetupDiEnumDeviceInterfaces",
constants$0.SetupDiEnumDeviceInterfaces$FUNC
);
+ static final FunctionDescriptor SetupDiOpenDeviceInterfaceW$FUNC = FunctionDescriptor.of(Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle SetupDiOpenDeviceInterfaceW$MH = RuntimeHelper.downcallHandle(
+ "SetupDiOpenDeviceInterfaceW",
+ constants$0.SetupDiOpenDeviceInterfaceW$FUNC
+ );
static final FunctionDescriptor SetupDiGetDeviceInterfaceDetailW$FUNC = FunctionDescriptor.of(Constants$root.C_LONG$LAYOUT,
Constants$root.C_POINTER$LAYOUT,
Constants$root.C_POINTER$LAYOUT,
@@ -55,20 +65,6 @@ class constants$0 {
"SetupDiGetClassDevsW",
constants$0.SetupDiGetClassDevsW$FUNC
);
- static final FunctionDescriptor SetupDiGetDevicePropertyW$FUNC = FunctionDescriptor.of(Constants$root.C_LONG$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_LONG$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_LONG$LAYOUT
- );
- static final MethodHandle SetupDiGetDevicePropertyW$MH = RuntimeHelper.downcallHandle(
- "SetupDiGetDevicePropertyW",
- constants$0.SetupDiGetDevicePropertyW$FUNC
- );
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$1.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$1.java
index 74594195..4b48fe18 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$1.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/constants$1.java
@@ -6,6 +6,20 @@
import java.lang.invoke.MethodHandle;
class constants$1 {
+ static final FunctionDescriptor SetupDiGetDevicePropertyW$FUNC = FunctionDescriptor.of(Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT
+ );
+ static final MethodHandle SetupDiGetDevicePropertyW$MH = RuntimeHelper.downcallHandle(
+ "SetupDiGetDevicePropertyW",
+ constants$1.SetupDiGetDevicePropertyW$FUNC
+ );
static final FunctionDescriptor SetupDiGetDeviceRegistryPropertyW$FUNC = FunctionDescriptor.of(Constants$root.C_LONG$LAYOUT,
Constants$root.C_POINTER$LAYOUT,
Constants$root.C_POINTER$LAYOUT,
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/Constants$root.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/Constants$root.java
new file mode 100644
index 00000000..91462c49
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/Constants$root.java
@@ -0,0 +1,19 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.user32;
+
+import static java.lang.foreign.ValueLayout.*;
+public class Constants$root {
+
+ static final OfBoolean C_BOOL$LAYOUT = JAVA_BOOLEAN;
+ static final OfByte C_CHAR$LAYOUT = JAVA_BYTE;
+ static final OfShort C_SHORT$LAYOUT = JAVA_SHORT.withBitAlignment(16);
+ static final OfInt C_INT$LAYOUT = JAVA_INT.withBitAlignment(32);
+ static final OfInt C_LONG$LAYOUT = JAVA_INT.withBitAlignment(32);
+ static final OfLong C_LONG_LONG$LAYOUT = JAVA_LONG.withBitAlignment(64);
+ static final OfFloat C_FLOAT$LAYOUT = JAVA_FLOAT.withBitAlignment(32);
+ static final OfDouble C_DOUBLE$LAYOUT = JAVA_DOUBLE.withBitAlignment(64);
+ static final OfAddress C_POINTER$LAYOUT = ADDRESS.withBitAlignment(64);
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/RuntimeHelper.java
new file mode 100644
index 00000000..6da1ee8a
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/RuntimeHelper.java
@@ -0,0 +1,216 @@
+package net.codecrete.usb.windows.gen.user32;
+// Generated by jextract
+
+import java.lang.foreign.*;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+
+import static java.lang.foreign.ValueLayout.*;
+
+final class RuntimeHelper {
+
+ private RuntimeHelper() {}
+ private final static Linker LINKER = Linker.nativeLinker();
+ private final static ClassLoader LOADER = RuntimeHelper.class.getClassLoader();
+ private final static MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup();
+ private final static SymbolLookup SYMBOL_LOOKUP;
+
+ final static SegmentAllocator CONSTANT_ALLOCATOR =
+ (size, align) -> MemorySegment.allocateNative(size, align, MemorySession.openImplicit());
+
+ static {
+ System.loadLibrary("User32");
+ SymbolLookup loaderLookup = SymbolLookup.loaderLookup();
+ SYMBOL_LOOKUP = name -> loaderLookup.lookup(name).or(() -> LINKER.defaultLookup().lookup(name));
+ }
+
+ static T requireNonNull(T obj, String symbolName) {
+ if (obj == null) {
+ throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName);
+ }
+ return obj;
+ }
+
+ private final static SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); };
+
+ static final MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) {
+ return SYMBOL_LOOKUP.lookup(name).map(symbol -> MemorySegment.ofAddress(symbol.address(), layout.byteSize(), MemorySession.openShared())).orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> LINKER.downcallHandle(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(FunctionDescriptor fdesc) {
+ return LINKER.downcallHandle(fdesc);
+ }
+
+ static final MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> VarargsInvoker.make(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MemorySegment upcallStub(Class fi, Z z, FunctionDescriptor fdesc, MemorySession session) {
+ try {
+ MethodHandle handle = MH_LOOKUP.findVirtual(fi, "apply", Linker.upcallType(fdesc));
+ handle = handle.bindTo(z);
+ return LINKER.upcallStub(handle, fdesc, session);
+ } catch (Throwable ex) {
+ throw new AssertionError(ex);
+ }
+ }
+
+ static MemorySegment asArray(MemoryAddress addr, MemoryLayout layout, int numElements, MemorySession session) {
+ return MemorySegment.ofAddress(addr, numElements * layout.byteSize(), session);
+ }
+
+ // Internals only below this point
+
+ private static class VarargsInvoker {
+ private static final MethodHandle INVOKE_MH;
+ private final MemorySegment symbol;
+ private final FunctionDescriptor function;
+
+ private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) {
+ this.symbol = symbol;
+ this.function = function;
+ }
+
+ static {
+ try {
+ INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class));
+ } catch (ReflectiveOperationException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) {
+ VarargsInvoker invoker = new VarargsInvoker(symbol, function);
+ MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1);
+ MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class);
+ for (MemoryLayout layout : function.argumentLayouts()) {
+ mtype = mtype.appendParameterTypes(carrier(layout, false));
+ }
+ mtype = mtype.appendParameterTypes(Object[].class);
+ if (mtype.returnType().equals(MemorySegment.class)) {
+ mtype = mtype.insertParameterTypes(0, SegmentAllocator.class);
+ } else {
+ handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR);
+ }
+ return handle.asType(mtype);
+ }
+
+ static Class> carrier(MemoryLayout layout, boolean ret) {
+ if (layout instanceof ValueLayout valueLayout) {
+ return (ret || valueLayout.carrier() != MemoryAddress.class) ?
+ valueLayout.carrier() : Addressable.class;
+ } else if (layout instanceof GroupLayout) {
+ return MemorySegment.class;
+ } else {
+ throw new AssertionError("Cannot get here!");
+ }
+ }
+
+ private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable {
+ // one trailing Object[]
+ int nNamedArgs = function.argumentLayouts().size();
+ assert(args.length == nNamedArgs + 1);
+ // The last argument is the array of vararg collector
+ Object[] unnamedArgs = (Object[]) args[args.length - 1];
+
+ int argsCount = nNamedArgs + unnamedArgs.length;
+ Class>[] argTypes = new Class>[argsCount];
+ MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length];
+
+ int pos = 0;
+ for (pos = 0; pos < nNamedArgs; pos++) {
+ argLayouts[pos] = function.argumentLayouts().get(pos);
+ }
+
+ assert pos == nNamedArgs;
+ for (Object o: unnamedArgs) {
+ argLayouts[pos] = variadicLayout(normalize(o.getClass()));
+ pos++;
+ }
+ assert pos == argsCount;
+
+ FunctionDescriptor f = (function.returnLayout().isEmpty()) ?
+ FunctionDescriptor.ofVoid(argLayouts) :
+ FunctionDescriptor.of(function.returnLayout().get(), argLayouts);
+ MethodHandle mh = LINKER.downcallHandle(symbol, f);
+ if (mh.type().returnType() == MemorySegment.class) {
+ mh = mh.bindTo(allocator);
+ }
+ // flatten argument list so that it can be passed to an asSpreader MH
+ Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length];
+ System.arraycopy(args, 0, allArgs, 0, nNamedArgs);
+ System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length);
+
+ return mh.asSpreader(Object[].class, argsCount).invoke(allArgs);
+ }
+
+ private static Class> unboxIfNeeded(Class> clazz) {
+ if (clazz == Boolean.class) {
+ return boolean.class;
+ } else if (clazz == Void.class) {
+ return void.class;
+ } else if (clazz == Byte.class) {
+ return byte.class;
+ } else if (clazz == Character.class) {
+ return char.class;
+ } else if (clazz == Short.class) {
+ return short.class;
+ } else if (clazz == Integer.class) {
+ return int.class;
+ } else if (clazz == Long.class) {
+ return long.class;
+ } else if (clazz == Float.class) {
+ return float.class;
+ } else if (clazz == Double.class) {
+ return double.class;
+ } else {
+ return clazz;
+ }
+ }
+
+ private Class> promote(Class> c) {
+ if (c == byte.class || c == char.class || c == short.class || c == int.class) {
+ return long.class;
+ } else if (c == float.class) {
+ return double.class;
+ } else {
+ return c;
+ }
+ }
+
+ private Class> normalize(Class> c) {
+ c = unboxIfNeeded(c);
+ if (c.isPrimitive()) {
+ return promote(c);
+ }
+ if (MemoryAddress.class.isAssignableFrom(c)) {
+ return MemoryAddress.class;
+ }
+ if (MemorySegment.class.isAssignableFrom(c)) {
+ return MemorySegment.class;
+ }
+ throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName());
+ }
+
+ private MemoryLayout variadicLayout(Class> c) {
+ if (c == long.class) {
+ return JAVA_LONG;
+ } else if (c == double.class) {
+ return JAVA_DOUBLE;
+ } else if (MemoryAddress.class.isAssignableFrom(c)) {
+ return ADDRESS;
+ } else {
+ throw new IllegalArgumentException("Unhandled variadic argument class: " + c);
+ }
+ }
+ }
+}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/User32.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/User32.java
new file mode 100644
index 00000000..92a80196
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/User32.java
@@ -0,0 +1,96 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.user32;
+
+import java.lang.foreign.Addressable;
+import java.lang.foreign.MemoryAddress;
+import java.lang.invoke.MethodHandle;
+
+import static java.lang.foreign.ValueLayout.*;
+public class User32 {
+
+ /* package-private */ User32() {}
+ public static OfByte C_CHAR = Constants$root.C_CHAR$LAYOUT;
+ public static OfShort C_SHORT = Constants$root.C_SHORT$LAYOUT;
+ public static OfInt C_INT = Constants$root.C_LONG$LAYOUT;
+ public static OfInt C_LONG = Constants$root.C_LONG$LAYOUT;
+ public static OfLong C_LONG_LONG = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfFloat C_FLOAT = Constants$root.C_FLOAT$LAYOUT;
+ public static OfDouble C_DOUBLE = Constants$root.C_DOUBLE$LAYOUT;
+ public static OfAddress C_POINTER = Constants$root.C_POINTER$LAYOUT;
+ public static int WM_DEVICECHANGE() {
+ return (int)537L;
+ }
+ public static int DEVICE_NOTIFY_WINDOW_HANDLE() {
+ return (int)0L;
+ }
+ public static int DBT_DEVICEARRIVAL() {
+ return (int)32768L;
+ }
+ public static int DBT_DEVICEREMOVECOMPLETE() {
+ return (int)32772L;
+ }
+ public static int DBT_DEVTYP_DEVICEINTERFACE() {
+ return (int)5L;
+ }
+ public static MethodHandle GetMessageW$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.GetMessageW$MH,"GetMessageW");
+ }
+ public static int GetMessageW ( Addressable lpMsg, Addressable hWnd, int wMsgFilterMin, int wMsgFilterMax) {
+ var mh$ = GetMessageW$MH();
+ try {
+ return (int)mh$.invokeExact(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle RegisterDeviceNotificationW$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.RegisterDeviceNotificationW$MH,"RegisterDeviceNotificationW");
+ }
+ public static MemoryAddress RegisterDeviceNotificationW ( Addressable hRecipient, Addressable NotificationFilter, int Flags) {
+ var mh$ = RegisterDeviceNotificationW$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact(hRecipient, NotificationFilter, Flags);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle DefWindowProcW$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.DefWindowProcW$MH,"DefWindowProcW");
+ }
+ public static long DefWindowProcW ( Addressable hWnd, int Msg, long wParam, long lParam) {
+ var mh$ = DefWindowProcW$MH();
+ try {
+ return (long)mh$.invokeExact(hWnd, Msg, wParam, lParam);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle RegisterClassExW$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.RegisterClassExW$MH,"RegisterClassExW");
+ }
+ public static short RegisterClassExW ( Addressable x0) {
+ var mh$ = RegisterClassExW$MH();
+ try {
+ return (short)mh$.invokeExact(x0);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle CreateWindowExW$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.CreateWindowExW$MH,"CreateWindowExW");
+ }
+ public static MemoryAddress CreateWindowExW ( int dwExStyle, Addressable lpClassName, Addressable lpWindowName, int dwStyle, int X, int Y, int nWidth, int nHeight, Addressable hWndParent, Addressable hMenu, Addressable hInstance, Addressable lpParam) {
+ var mh$ = CreateWindowExW$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MemoryAddress HWND_MESSAGE() {
+ return constants$0.HWND_MESSAGE$ADDR;
+ }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/_DEV_BROADCAST_DEVICEINTERFACE_W.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/_DEV_BROADCAST_DEVICEINTERFACE_W.java
new file mode 100644
index 00000000..3a3548fc
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/_DEV_BROADCAST_DEVICEINTERFACE_W.java
@@ -0,0 +1,87 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.user32;
+
+import java.lang.foreign.*;
+import java.lang.invoke.VarHandle;
+public class _DEV_BROADCAST_DEVICEINTERFACE_W {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ Constants$root.C_LONG$LAYOUT.withName("dbcc_size"),
+ Constants$root.C_LONG$LAYOUT.withName("dbcc_devicetype"),
+ Constants$root.C_LONG$LAYOUT.withName("dbcc_reserved"),
+ MemoryLayout.structLayout(
+ Constants$root.C_LONG$LAYOUT.withName("Data1"),
+ Constants$root.C_SHORT$LAYOUT.withName("Data2"),
+ Constants$root.C_SHORT$LAYOUT.withName("Data3"),
+ MemoryLayout.sequenceLayout(8, Constants$root.C_CHAR$LAYOUT).withName("Data4")
+ ).withName("dbcc_classguid"),
+ MemoryLayout.sequenceLayout(1, Constants$root.C_SHORT$LAYOUT).withName("dbcc_name"),
+ MemoryLayout.paddingLayout(16)
+ ).withName("_DEV_BROADCAST_DEVICEINTERFACE_W");
+ public static MemoryLayout $LAYOUT() {
+ return _DEV_BROADCAST_DEVICEINTERFACE_W.$struct$LAYOUT;
+ }
+ static final VarHandle dbcc_size$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("dbcc_size"));
+ public static VarHandle dbcc_size$VH() {
+ return _DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_size$VH;
+ }
+ public static int dbcc_size$get(MemorySegment seg) {
+ return (int)_DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_size$VH.get(seg);
+ }
+ public static void dbcc_size$set( MemorySegment seg, int x) {
+ _DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_size$VH.set(seg, x);
+ }
+ public static int dbcc_size$get(MemorySegment seg, long index) {
+ return (int)_DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_size$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void dbcc_size$set(MemorySegment seg, long index, int x) {
+ _DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_size$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle dbcc_devicetype$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("dbcc_devicetype"));
+ public static VarHandle dbcc_devicetype$VH() {
+ return _DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_devicetype$VH;
+ }
+ public static int dbcc_devicetype$get(MemorySegment seg) {
+ return (int)_DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_devicetype$VH.get(seg);
+ }
+ public static void dbcc_devicetype$set( MemorySegment seg, int x) {
+ _DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_devicetype$VH.set(seg, x);
+ }
+ public static int dbcc_devicetype$get(MemorySegment seg, long index) {
+ return (int)_DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_devicetype$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void dbcc_devicetype$set(MemorySegment seg, long index, int x) {
+ _DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_devicetype$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle dbcc_reserved$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("dbcc_reserved"));
+ public static VarHandle dbcc_reserved$VH() {
+ return _DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_reserved$VH;
+ }
+ public static int dbcc_reserved$get(MemorySegment seg) {
+ return (int)_DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_reserved$VH.get(seg);
+ }
+ public static void dbcc_reserved$set( MemorySegment seg, int x) {
+ _DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_reserved$VH.set(seg, x);
+ }
+ public static int dbcc_reserved$get(MemorySegment seg, long index) {
+ return (int)_DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_reserved$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void dbcc_reserved$set(MemorySegment seg, long index, int x) {
+ _DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_reserved$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static MemorySegment dbcc_classguid$slice(MemorySegment seg) {
+ return seg.asSlice(12, 16);
+ }
+ public static MemorySegment dbcc_name$slice(MemorySegment seg) {
+ return seg.asSlice(28, 2);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/_DEV_BROADCAST_HDR.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/_DEV_BROADCAST_HDR.java
new file mode 100644
index 00000000..85d5840e
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/_DEV_BROADCAST_HDR.java
@@ -0,0 +1,73 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.user32;
+
+import java.lang.foreign.*;
+import java.lang.invoke.VarHandle;
+public class _DEV_BROADCAST_HDR {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ Constants$root.C_LONG$LAYOUT.withName("dbch_size"),
+ Constants$root.C_LONG$LAYOUT.withName("dbch_devicetype"),
+ Constants$root.C_LONG$LAYOUT.withName("dbch_reserved")
+ ).withName("_DEV_BROADCAST_HDR");
+ public static MemoryLayout $LAYOUT() {
+ return _DEV_BROADCAST_HDR.$struct$LAYOUT;
+ }
+ static final VarHandle dbch_size$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("dbch_size"));
+ public static VarHandle dbch_size$VH() {
+ return _DEV_BROADCAST_HDR.dbch_size$VH;
+ }
+ public static int dbch_size$get(MemorySegment seg) {
+ return (int)_DEV_BROADCAST_HDR.dbch_size$VH.get(seg);
+ }
+ public static void dbch_size$set( MemorySegment seg, int x) {
+ _DEV_BROADCAST_HDR.dbch_size$VH.set(seg, x);
+ }
+ public static int dbch_size$get(MemorySegment seg, long index) {
+ return (int)_DEV_BROADCAST_HDR.dbch_size$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void dbch_size$set(MemorySegment seg, long index, int x) {
+ _DEV_BROADCAST_HDR.dbch_size$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle dbch_devicetype$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("dbch_devicetype"));
+ public static VarHandle dbch_devicetype$VH() {
+ return _DEV_BROADCAST_HDR.dbch_devicetype$VH;
+ }
+ public static int dbch_devicetype$get(MemorySegment seg) {
+ return (int)_DEV_BROADCAST_HDR.dbch_devicetype$VH.get(seg);
+ }
+ public static void dbch_devicetype$set( MemorySegment seg, int x) {
+ _DEV_BROADCAST_HDR.dbch_devicetype$VH.set(seg, x);
+ }
+ public static int dbch_devicetype$get(MemorySegment seg, long index) {
+ return (int)_DEV_BROADCAST_HDR.dbch_devicetype$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void dbch_devicetype$set(MemorySegment seg, long index, int x) {
+ _DEV_BROADCAST_HDR.dbch_devicetype$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle dbch_reserved$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("dbch_reserved"));
+ public static VarHandle dbch_reserved$VH() {
+ return _DEV_BROADCAST_HDR.dbch_reserved$VH;
+ }
+ public static int dbch_reserved$get(MemorySegment seg) {
+ return (int)_DEV_BROADCAST_HDR.dbch_reserved$VH.get(seg);
+ }
+ public static void dbch_reserved$set( MemorySegment seg, int x) {
+ _DEV_BROADCAST_HDR.dbch_reserved$VH.set(seg, x);
+ }
+ public static int dbch_reserved$get(MemorySegment seg, long index) {
+ return (int)_DEV_BROADCAST_HDR.dbch_reserved$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void dbch_reserved$set(MemorySegment seg, long index, int x) {
+ _DEV_BROADCAST_HDR.dbch_reserved$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/constants$0.java
new file mode 100644
index 00000000..f137ae31
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/constants$0.java
@@ -0,0 +1,67 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.user32;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.foreign.MemoryAddress;
+import java.lang.invoke.MethodHandle;
+class constants$0 {
+
+ static final FunctionDescriptor GetMessageW$FUNC = FunctionDescriptor.of(Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_LONG$LAYOUT
+ );
+ static final MethodHandle GetMessageW$MH = RuntimeHelper.downcallHandle(
+ "GetMessageW",
+ constants$0.GetMessageW$FUNC
+ );
+ static final FunctionDescriptor RegisterDeviceNotificationW$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT
+ );
+ static final MethodHandle RegisterDeviceNotificationW$MH = RuntimeHelper.downcallHandle(
+ "RegisterDeviceNotificationW",
+ constants$0.RegisterDeviceNotificationW$FUNC
+ );
+ static final FunctionDescriptor DefWindowProcW$FUNC = FunctionDescriptor.of(Constants$root.C_LONG_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT,
+ Constants$root.C_LONG_LONG$LAYOUT
+ );
+ static final MethodHandle DefWindowProcW$MH = RuntimeHelper.downcallHandle(
+ "DefWindowProcW",
+ constants$0.DefWindowProcW$FUNC
+ );
+ static final FunctionDescriptor RegisterClassExW$FUNC = FunctionDescriptor.of(Constants$root.C_SHORT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle RegisterClassExW$MH = RuntimeHelper.downcallHandle(
+ "RegisterClassExW",
+ constants$0.RegisterClassExW$FUNC
+ );
+ static final FunctionDescriptor CreateWindowExW$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_LONG$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle CreateWindowExW$MH = RuntimeHelper.downcallHandle(
+ "CreateWindowExW",
+ constants$0.CreateWindowExW$FUNC
+ );
+ static final MemoryAddress HWND_MESSAGE$ADDR = MemoryAddress.ofLong(-3L);
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/tagMSG.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/tagMSG.java
new file mode 100644
index 00000000..1fad57f8
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/tagMSG.java
@@ -0,0 +1,116 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.user32;
+
+import java.lang.foreign.*;
+import java.lang.invoke.VarHandle;
+public class tagMSG {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ Constants$root.C_POINTER$LAYOUT.withName("hwnd"),
+ Constants$root.C_LONG$LAYOUT.withName("message"),
+ MemoryLayout.paddingLayout(32),
+ Constants$root.C_LONG_LONG$LAYOUT.withName("wParam"),
+ Constants$root.C_LONG_LONG$LAYOUT.withName("lParam"),
+ Constants$root.C_LONG$LAYOUT.withName("time"),
+ MemoryLayout.structLayout(
+ Constants$root.C_LONG$LAYOUT.withName("x"),
+ Constants$root.C_LONG$LAYOUT.withName("y")
+ ).withName("pt"),
+ MemoryLayout.paddingLayout(32)
+ ).withName("tagMSG");
+ public static MemoryLayout $LAYOUT() {
+ return tagMSG.$struct$LAYOUT;
+ }
+ static final VarHandle hwnd$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("hwnd"));
+ public static VarHandle hwnd$VH() {
+ return tagMSG.hwnd$VH;
+ }
+ public static MemoryAddress hwnd$get(MemorySegment seg) {
+ return (java.lang.foreign.MemoryAddress)tagMSG.hwnd$VH.get(seg);
+ }
+ public static void hwnd$set( MemorySegment seg, MemoryAddress x) {
+ tagMSG.hwnd$VH.set(seg, x);
+ }
+ public static MemoryAddress hwnd$get(MemorySegment seg, long index) {
+ return (java.lang.foreign.MemoryAddress)tagMSG.hwnd$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void hwnd$set(MemorySegment seg, long index, MemoryAddress x) {
+ tagMSG.hwnd$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle message$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("message"));
+ public static VarHandle message$VH() {
+ return tagMSG.message$VH;
+ }
+ public static int message$get(MemorySegment seg) {
+ return (int)tagMSG.message$VH.get(seg);
+ }
+ public static void message$set( MemorySegment seg, int x) {
+ tagMSG.message$VH.set(seg, x);
+ }
+ public static int message$get(MemorySegment seg, long index) {
+ return (int)tagMSG.message$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void message$set(MemorySegment seg, long index, int x) {
+ tagMSG.message$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle wParam$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("wParam"));
+ public static VarHandle wParam$VH() {
+ return tagMSG.wParam$VH;
+ }
+ public static long wParam$get(MemorySegment seg) {
+ return (long)tagMSG.wParam$VH.get(seg);
+ }
+ public static void wParam$set( MemorySegment seg, long x) {
+ tagMSG.wParam$VH.set(seg, x);
+ }
+ public static long wParam$get(MemorySegment seg, long index) {
+ return (long)tagMSG.wParam$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void wParam$set(MemorySegment seg, long index, long x) {
+ tagMSG.wParam$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle lParam$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("lParam"));
+ public static VarHandle lParam$VH() {
+ return tagMSG.lParam$VH;
+ }
+ public static long lParam$get(MemorySegment seg) {
+ return (long)tagMSG.lParam$VH.get(seg);
+ }
+ public static void lParam$set( MemorySegment seg, long x) {
+ tagMSG.lParam$VH.set(seg, x);
+ }
+ public static long lParam$get(MemorySegment seg, long index) {
+ return (long)tagMSG.lParam$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void lParam$set(MemorySegment seg, long index, long x) {
+ tagMSG.lParam$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle time$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("time"));
+ public static VarHandle time$VH() {
+ return tagMSG.time$VH;
+ }
+ public static int time$get(MemorySegment seg) {
+ return (int)tagMSG.time$VH.get(seg);
+ }
+ public static void time$set( MemorySegment seg, int x) {
+ tagMSG.time$VH.set(seg, x);
+ }
+ public static int time$get(MemorySegment seg, long index) {
+ return (int)tagMSG.time$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void time$set(MemorySegment seg, long index, int x) {
+ tagMSG.time$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static MemorySegment pt$slice(MemorySegment seg) {
+ return seg.asSlice(36, 8);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/tagWNDCLASSEXW.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/tagWNDCLASSEXW.java
new file mode 100644
index 00000000..9612b1a7
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/tagWNDCLASSEXW.java
@@ -0,0 +1,226 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.user32;
+
+import java.lang.foreign.*;
+import java.lang.invoke.VarHandle;
+public class tagWNDCLASSEXW {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ Constants$root.C_LONG$LAYOUT.withName("cbSize"),
+ Constants$root.C_LONG$LAYOUT.withName("style"),
+ Constants$root.C_POINTER$LAYOUT.withName("lpfnWndProc"),
+ Constants$root.C_LONG$LAYOUT.withName("cbClsExtra"),
+ Constants$root.C_LONG$LAYOUT.withName("cbWndExtra"),
+ Constants$root.C_POINTER$LAYOUT.withName("hInstance"),
+ Constants$root.C_POINTER$LAYOUT.withName("hIcon"),
+ Constants$root.C_POINTER$LAYOUT.withName("hCursor"),
+ Constants$root.C_POINTER$LAYOUT.withName("hbrBackground"),
+ Constants$root.C_POINTER$LAYOUT.withName("lpszMenuName"),
+ Constants$root.C_POINTER$LAYOUT.withName("lpszClassName"),
+ Constants$root.C_POINTER$LAYOUT.withName("hIconSm")
+ ).withName("tagWNDCLASSEXW");
+ public static MemoryLayout $LAYOUT() {
+ return tagWNDCLASSEXW.$struct$LAYOUT;
+ }
+ static final VarHandle cbSize$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("cbSize"));
+ public static VarHandle cbSize$VH() {
+ return tagWNDCLASSEXW.cbSize$VH;
+ }
+ public static int cbSize$get(MemorySegment seg) {
+ return (int)tagWNDCLASSEXW.cbSize$VH.get(seg);
+ }
+ public static void cbSize$set( MemorySegment seg, int x) {
+ tagWNDCLASSEXW.cbSize$VH.set(seg, x);
+ }
+ public static int cbSize$get(MemorySegment seg, long index) {
+ return (int)tagWNDCLASSEXW.cbSize$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void cbSize$set(MemorySegment seg, long index, int x) {
+ tagWNDCLASSEXW.cbSize$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle style$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("style"));
+ public static VarHandle style$VH() {
+ return tagWNDCLASSEXW.style$VH;
+ }
+ public static int style$get(MemorySegment seg) {
+ return (int)tagWNDCLASSEXW.style$VH.get(seg);
+ }
+ public static void style$set( MemorySegment seg, int x) {
+ tagWNDCLASSEXW.style$VH.set(seg, x);
+ }
+ public static int style$get(MemorySegment seg, long index) {
+ return (int)tagWNDCLASSEXW.style$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void style$set(MemorySegment seg, long index, int x) {
+ tagWNDCLASSEXW.style$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle lpfnWndProc$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("lpfnWndProc"));
+ public static VarHandle lpfnWndProc$VH() {
+ return tagWNDCLASSEXW.lpfnWndProc$VH;
+ }
+ public static MemoryAddress lpfnWndProc$get(MemorySegment seg) {
+ return (java.lang.foreign.MemoryAddress)tagWNDCLASSEXW.lpfnWndProc$VH.get(seg);
+ }
+ public static void lpfnWndProc$set( MemorySegment seg, MemoryAddress x) {
+ tagWNDCLASSEXW.lpfnWndProc$VH.set(seg, x);
+ }
+ public static MemoryAddress lpfnWndProc$get(MemorySegment seg, long index) {
+ return (java.lang.foreign.MemoryAddress)tagWNDCLASSEXW.lpfnWndProc$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void lpfnWndProc$set(MemorySegment seg, long index, MemoryAddress x) {
+ tagWNDCLASSEXW.lpfnWndProc$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle cbClsExtra$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("cbClsExtra"));
+ public static VarHandle cbClsExtra$VH() {
+ return tagWNDCLASSEXW.cbClsExtra$VH;
+ }
+ public static int cbClsExtra$get(MemorySegment seg) {
+ return (int)tagWNDCLASSEXW.cbClsExtra$VH.get(seg);
+ }
+ public static void cbClsExtra$set( MemorySegment seg, int x) {
+ tagWNDCLASSEXW.cbClsExtra$VH.set(seg, x);
+ }
+ public static int cbClsExtra$get(MemorySegment seg, long index) {
+ return (int)tagWNDCLASSEXW.cbClsExtra$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void cbClsExtra$set(MemorySegment seg, long index, int x) {
+ tagWNDCLASSEXW.cbClsExtra$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle cbWndExtra$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("cbWndExtra"));
+ public static VarHandle cbWndExtra$VH() {
+ return tagWNDCLASSEXW.cbWndExtra$VH;
+ }
+ public static int cbWndExtra$get(MemorySegment seg) {
+ return (int)tagWNDCLASSEXW.cbWndExtra$VH.get(seg);
+ }
+ public static void cbWndExtra$set( MemorySegment seg, int x) {
+ tagWNDCLASSEXW.cbWndExtra$VH.set(seg, x);
+ }
+ public static int cbWndExtra$get(MemorySegment seg, long index) {
+ return (int)tagWNDCLASSEXW.cbWndExtra$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void cbWndExtra$set(MemorySegment seg, long index, int x) {
+ tagWNDCLASSEXW.cbWndExtra$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle hInstance$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("hInstance"));
+ public static VarHandle hInstance$VH() {
+ return tagWNDCLASSEXW.hInstance$VH;
+ }
+ public static MemoryAddress hInstance$get(MemorySegment seg) {
+ return (java.lang.foreign.MemoryAddress)tagWNDCLASSEXW.hInstance$VH.get(seg);
+ }
+ public static void hInstance$set( MemorySegment seg, MemoryAddress x) {
+ tagWNDCLASSEXW.hInstance$VH.set(seg, x);
+ }
+ public static MemoryAddress hInstance$get(MemorySegment seg, long index) {
+ return (java.lang.foreign.MemoryAddress)tagWNDCLASSEXW.hInstance$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void hInstance$set(MemorySegment seg, long index, MemoryAddress x) {
+ tagWNDCLASSEXW.hInstance$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle hIcon$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("hIcon"));
+ public static VarHandle hIcon$VH() {
+ return tagWNDCLASSEXW.hIcon$VH;
+ }
+ public static MemoryAddress hIcon$get(MemorySegment seg) {
+ return (java.lang.foreign.MemoryAddress)tagWNDCLASSEXW.hIcon$VH.get(seg);
+ }
+ public static void hIcon$set( MemorySegment seg, MemoryAddress x) {
+ tagWNDCLASSEXW.hIcon$VH.set(seg, x);
+ }
+ public static MemoryAddress hIcon$get(MemorySegment seg, long index) {
+ return (java.lang.foreign.MemoryAddress)tagWNDCLASSEXW.hIcon$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void hIcon$set(MemorySegment seg, long index, MemoryAddress x) {
+ tagWNDCLASSEXW.hIcon$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle hCursor$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("hCursor"));
+ public static VarHandle hCursor$VH() {
+ return tagWNDCLASSEXW.hCursor$VH;
+ }
+ public static MemoryAddress hCursor$get(MemorySegment seg) {
+ return (java.lang.foreign.MemoryAddress)tagWNDCLASSEXW.hCursor$VH.get(seg);
+ }
+ public static void hCursor$set( MemorySegment seg, MemoryAddress x) {
+ tagWNDCLASSEXW.hCursor$VH.set(seg, x);
+ }
+ public static MemoryAddress hCursor$get(MemorySegment seg, long index) {
+ return (java.lang.foreign.MemoryAddress)tagWNDCLASSEXW.hCursor$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void hCursor$set(MemorySegment seg, long index, MemoryAddress x) {
+ tagWNDCLASSEXW.hCursor$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle hbrBackground$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("hbrBackground"));
+ public static VarHandle hbrBackground$VH() {
+ return tagWNDCLASSEXW.hbrBackground$VH;
+ }
+ public static MemoryAddress hbrBackground$get(MemorySegment seg) {
+ return (java.lang.foreign.MemoryAddress)tagWNDCLASSEXW.hbrBackground$VH.get(seg);
+ }
+ public static void hbrBackground$set( MemorySegment seg, MemoryAddress x) {
+ tagWNDCLASSEXW.hbrBackground$VH.set(seg, x);
+ }
+ public static MemoryAddress hbrBackground$get(MemorySegment seg, long index) {
+ return (java.lang.foreign.MemoryAddress)tagWNDCLASSEXW.hbrBackground$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void hbrBackground$set(MemorySegment seg, long index, MemoryAddress x) {
+ tagWNDCLASSEXW.hbrBackground$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle lpszMenuName$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("lpszMenuName"));
+ public static VarHandle lpszMenuName$VH() {
+ return tagWNDCLASSEXW.lpszMenuName$VH;
+ }
+ public static MemoryAddress lpszMenuName$get(MemorySegment seg) {
+ return (java.lang.foreign.MemoryAddress)tagWNDCLASSEXW.lpszMenuName$VH.get(seg);
+ }
+ public static void lpszMenuName$set( MemorySegment seg, MemoryAddress x) {
+ tagWNDCLASSEXW.lpszMenuName$VH.set(seg, x);
+ }
+ public static MemoryAddress lpszMenuName$get(MemorySegment seg, long index) {
+ return (java.lang.foreign.MemoryAddress)tagWNDCLASSEXW.lpszMenuName$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void lpszMenuName$set(MemorySegment seg, long index, MemoryAddress x) {
+ tagWNDCLASSEXW.lpszMenuName$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle lpszClassName$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("lpszClassName"));
+ public static VarHandle lpszClassName$VH() {
+ return tagWNDCLASSEXW.lpszClassName$VH;
+ }
+ public static MemoryAddress lpszClassName$get(MemorySegment seg) {
+ return (java.lang.foreign.MemoryAddress)tagWNDCLASSEXW.lpszClassName$VH.get(seg);
+ }
+ public static void lpszClassName$set( MemorySegment seg, MemoryAddress x) {
+ tagWNDCLASSEXW.lpszClassName$VH.set(seg, x);
+ }
+ public static MemoryAddress lpszClassName$get(MemorySegment seg, long index) {
+ return (java.lang.foreign.MemoryAddress)tagWNDCLASSEXW.lpszClassName$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void lpszClassName$set(MemorySegment seg, long index, MemoryAddress x) {
+ tagWNDCLASSEXW.lpszClassName$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ static final VarHandle hIconSm$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("hIconSm"));
+ public static VarHandle hIconSm$VH() {
+ return tagWNDCLASSEXW.hIconSm$VH;
+ }
+ public static MemoryAddress hIconSm$get(MemorySegment seg) {
+ return (java.lang.foreign.MemoryAddress)tagWNDCLASSEXW.hIconSm$VH.get(seg);
+ }
+ public static void hIconSm$set( MemorySegment seg, MemoryAddress x) {
+ tagWNDCLASSEXW.hIconSm$VH.set(seg, x);
+ }
+ public static MemoryAddress hIconSm$get(MemorySegment seg, long index) {
+ return (java.lang.foreign.MemoryAddress)tagWNDCLASSEXW.hIconSm$VH.get(seg.asSlice(index*sizeof()));
+ }
+ public static void hIconSm$set(MemorySegment seg, long index, MemoryAddress x) {
+ tagWNDCLASSEXW.hIconSm$VH.set(seg.asSlice(index*sizeof()), x);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
From 81aafed17b49fd851bbaa1105c75b46d88afa380 Mon Sep 17 00:00:00 2001
From: Manuel Bl
Date: Sun, 28 Aug 2022 23:07:15 +0200
Subject: [PATCH 018/433] Windows: USBHelper cleanup
---
.../net/codecrete/usb/windows/USBHelper.java | 146 ++++++++----------
1 file changed, 64 insertions(+), 82 deletions(-)
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/USBHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/USBHelper.java
index 162a680b..68d25d54 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/USBHelper.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/USBHelper.java
@@ -21,8 +21,8 @@
/**
* USB constants and struct
*
- * Mainly used to work around an alignment problem with the generated
- * USB_NODE_CONNECTION_INFORMATION_EX struct.
+ * Mainly used to work around an alignment problem with the generated
+ * USB_NODE_CONNECTION_INFORMATION_EX struct.
*
*/
public class USBHelper {
@@ -31,99 +31,81 @@ public class USBHelper {
public static final short USB_STRING_DESCRIPTOR_TYPE = 0x03;
- public static final GroupLayout USB_NODE_CONNECTION_INFORMATION_EX$Struct;
- public static final VarHandle USB_NODE_CONNECTION_INFORMATION_EX_ConnectionIndex;
- public static final long USB_NODE_CONNECTION_INFORMATION_EX_DeviceDescriptor$Offset;
- public static final VarHandle USB_NODE_CONNECTION_INFORMATION_EX_CurrentConfigurationValue;
+ // typedef struct _USB_NODE_CONNECTION_INFORMATION_EX {
+ // ULONG ConnectionIndex; /* INPUT */
+ // /* usb device descriptor returned by this device
+ // during enumeration */
+ // USB_DEVICE_DESCRIPTOR DeviceDescriptor;/* OUTPUT */
+ // UCHAR CurrentConfigurationValue;/* OUTPUT */
+ // /* values for the speed field are defined in USB200.h */
+ // UCHAR Speed;/* OUTPUT */
+ // BOOLEAN DeviceIsHub;/* OUTPUT */
+ // USHORT DeviceAddress;/* OUTPUT */
+ // ULONG NumberOfOpenPipes;/* OUTPUT */
+ // USB_CONNECTION_STATUS ConnectionStatus;/* OUTPUT */
+ // USB_PIPE_INFO PipeList[0];/* OUTPUT */
+ //} USB_NODE_CONNECTION_INFORMATION_EX, *PUSB_NODE_CONNECTION_INFORMATION_EX;
+ public static final GroupLayout USB_NODE_CONNECTION_INFORMATION_EX$Struct = structLayout(
+ JAVA_INT.withName("ConnectionIndex"),
+ USBDescriptors.Device$Struct.withName("DeviceDescriptor"),
+ JAVA_BYTE.withName("CurrentConfigurationValue"),
+ JAVA_BYTE.withName("Speed"),
+ JAVA_BYTE.withName("DeviceIsHub"),
+ JAVA_SHORT.withName("DeviceAddress"),
+ JAVA_INT.withName("NumberOfOpenPipes"),
+ JAVA_INT.withName("ConnectionStatus")
+ // USB_PIPE_INFO PipeList[0]
+ );
+ public static final VarHandle USB_NODE_CONNECTION_INFORMATION_EX_ConnectionIndex
+ = USB_NODE_CONNECTION_INFORMATION_EX$Struct.varHandle(groupElement("ConnectionIndex"));
+ public static final long USB_NODE_CONNECTION_INFORMATION_EX_DeviceDescriptor$Offset
+ = USB_NODE_CONNECTION_INFORMATION_EX$Struct.byteOffset(groupElement("DeviceDescriptor"));
+ public static final VarHandle USB_NODE_CONNECTION_INFORMATION_EX_CurrentConfigurationValue
+ = USB_NODE_CONNECTION_INFORMATION_EX$Struct.varHandle(groupElement("CurrentConfigurationValue"));
- public static final GroupLayout USB_DESCRIPTOR_REQUEST$Struct;
- public static final VarHandle USB_DESCRIPTOR_REQUEST_ConnectionIndex;
- public static final long USB_DESCRIPTOR_REQUEST_SetupPacket$Offset;
- public static final long USB_DESCRIPTOR_REQUEST_Data$Offset;
+ // typedef struct _USB_DESCRIPTOR_REQUEST {
+ // ULONG ConnectionIndex;
+ // struct {
+ // UCHAR bmRequest;
+ // UCHAR bRequest;
+ // USHORT wValue;
+ // USHORT wIndex;
+ // USHORT wLength;
+ // } SetupPacket;
+ // UCHAR Data[0];
+ //} USB_DESCRIPTOR_REQUEST, *PUSB_DESCRIPTOR_REQUEST;
+ public static final GroupLayout USB_DESCRIPTOR_REQUEST$Struct = structLayout(
+ JAVA_INT.withName("ConnectionIndex"),
+ USBStructs.SetupPacket$Struct.withName("SetupPacket")
+ );
+ public static final VarHandle USB_DESCRIPTOR_REQUEST_ConnectionIndex = USB_DESCRIPTOR_REQUEST$Struct.varHandle(groupElement("ConnectionIndex"));
+ public static final long USB_DESCRIPTOR_REQUEST_SetupPacket$Offset = USB_DESCRIPTOR_REQUEST$Struct.byteOffset(groupElement("SetupPacket"));
+ public static final long USB_DESCRIPTOR_REQUEST_Data$Offset = USB_DESCRIPTOR_REQUEST$Struct.byteSize();
+
+ // typedef struct _USB_STRING_DESCRIPTOR {
+ // UCHAR bLength;
+ // UCHAR bDescriptorType;
+ // WCHAR bString[1];
+ //} USB_STRING_DESCRIPTOR, *PUSB_STRING_DESCRIPTOR;
+ public static final GroupLayout USB_STRING_DESCRIPTOR$Struct = structLayout(
+ JAVA_BYTE.withName("bLength"),
+ JAVA_BYTE.withName("bDescriptorType")
+ );
+ public static final VarHandle USB_STRING_DESCRIPTOR_bLength = USB_STRING_DESCRIPTOR$Struct.varHandle(groupElement("bLength"));
+ public static final VarHandle USB_STRING_DESCRIPTOR_bDescriptorType = USB_STRING_DESCRIPTOR$Struct.varHandle(groupElement("bDescriptorType"));
+ public static final long USB_STRING_DESCRIPTOR_bString$Offset = USB_STRING_DESCRIPTOR$Struct.byteSize();
- public static final GroupLayout USB_STRING_DESCRIPTOR$Struct;
- public static final VarHandle USB_STRING_DESCRIPTOR_bLength;
- public static final VarHandle USB_STRING_DESCRIPTOR_bDescriptorType;
- public static final long USB_STRING_DESCRIPTOR_bString$Offset;
// A5DCBF10-6530-11D2-901F-00C04FB951ED
public static final MemorySegment GUID_DEVINTERFACE_USB_DEVICE = Win.CreateGUID(0xA5DCBF10, (short) 0x6530, (short) 0x11D2,
(byte) 0x90, (byte) 0x1F, (byte) 0x00, (byte) 0xC0,
(byte) 0x4F, (byte) 0xB9, (byte) 0x51, (byte) 0xED);
// f18a0e88-c30c-11d0-8815-00a0c906bed8
-
public static final MemorySegment GUID_DEVINTERFACE_USB_HUB = Win.CreateGUID(0xf18a0e88, (short) 0xc30c, (short) 0x11d0,
(byte) 0x88, (byte) 0x15, (byte) 0x00, (byte) 0xa0,
(byte) 0xc9, (byte) 0x06, (byte) 0xbe, (byte) 0xd8);
-
static {
-
- // typedef struct _USB_NODE_CONNECTION_INFORMATION_EX {
- // ULONG ConnectionIndex; /* INPUT */
- // /* usb device descriptor returned by this device
- // during enumeration */
- // USB_DEVICE_DESCRIPTOR DeviceDescriptor;/* OUTPUT */
- // UCHAR CurrentConfigurationValue;/* OUTPUT */
- // /* values for the speed field are defined in USB200.h */
- // UCHAR Speed;/* OUTPUT */
- // BOOLEAN DeviceIsHub;/* OUTPUT */
- // USHORT DeviceAddress;/* OUTPUT */
- // ULONG NumberOfOpenPipes;/* OUTPUT */
- // USB_CONNECTION_STATUS ConnectionStatus;/* OUTPUT */
- // USB_PIPE_INFO PipeList[0];/* OUTPUT */
- //} USB_NODE_CONNECTION_INFORMATION_EX, *PUSB_NODE_CONNECTION_INFORMATION_EX;
- USB_NODE_CONNECTION_INFORMATION_EX$Struct = structLayout(
- JAVA_INT.withName("ConnectionIndex"),
- USBDescriptors.Device$Struct.withName("DeviceDescriptor"),
- JAVA_BYTE.withName("CurrentConfigurationValue"),
- JAVA_BYTE.withName("Speed"),
- JAVA_BYTE.withName("DeviceIsHub"),
- JAVA_SHORT.withName("DeviceAddress"),
- JAVA_INT.withName("NumberOfOpenPipes"),
- JAVA_INT.withName("ConnectionStatus")
- // USB_PIPE_INFO PipeList[0]
- );
assert USB_NODE_CONNECTION_INFORMATION_EX$Struct.byteSize() == 35;
-
- USB_NODE_CONNECTION_INFORMATION_EX_ConnectionIndex
- = USB_NODE_CONNECTION_INFORMATION_EX$Struct.varHandle(groupElement("ConnectionIndex"));
- USB_NODE_CONNECTION_INFORMATION_EX_DeviceDescriptor$Offset
- = USB_NODE_CONNECTION_INFORMATION_EX$Struct.byteOffset(groupElement("DeviceDescriptor"));
- USB_NODE_CONNECTION_INFORMATION_EX_CurrentConfigurationValue
- = USB_NODE_CONNECTION_INFORMATION_EX$Struct.varHandle(groupElement("CurrentConfigurationValue"));
-
- // typedef struct _USB_DESCRIPTOR_REQUEST {
- // ULONG ConnectionIndex;
- // struct {
- // UCHAR bmRequest;
- // UCHAR bRequest;
- // USHORT wValue;
- // USHORT wIndex;
- // USHORT wLength;
- // } SetupPacket;
- // UCHAR Data[0];
- //} USB_DESCRIPTOR_REQUEST, *PUSB_DESCRIPTOR_REQUEST;
- USB_DESCRIPTOR_REQUEST$Struct = structLayout(
- JAVA_INT.withName("ConnectionIndex"),
- USBStructs.SetupPacket$Struct.withName("SetupPacket")
- );
-
- USB_DESCRIPTOR_REQUEST_ConnectionIndex = USB_DESCRIPTOR_REQUEST$Struct.varHandle(groupElement("ConnectionIndex"));
- USB_DESCRIPTOR_REQUEST_SetupPacket$Offset = USB_DESCRIPTOR_REQUEST$Struct.byteOffset(groupElement("SetupPacket"));
- USB_DESCRIPTOR_REQUEST_Data$Offset = USB_DESCRIPTOR_REQUEST$Struct.byteSize();
-
- // typedef struct _USB_STRING_DESCRIPTOR {
- // UCHAR bLength;
- // UCHAR bDescriptorType;
- // WCHAR bString[1];
- //} USB_STRING_DESCRIPTOR, *PUSB_STRING_DESCRIPTOR;
- USB_STRING_DESCRIPTOR$Struct = structLayout(
- JAVA_BYTE.withName("bLength"),
- JAVA_BYTE.withName("bDescriptorType")
- );
- USB_STRING_DESCRIPTOR_bLength = USB_STRING_DESCRIPTOR$Struct.varHandle(groupElement("bLength"));
- USB_STRING_DESCRIPTOR_bDescriptorType = USB_STRING_DESCRIPTOR$Struct.varHandle(groupElement("bDescriptorType"));
- USB_STRING_DESCRIPTOR_bString$Offset = USB_STRING_DESCRIPTOR$Struct.byteSize();
}
}
From e4d4101823b0623872ca03d2223e55a04f457274 Mon Sep 17 00:00:00 2001
From: Manuel Bleichenbacher
Date: Mon, 29 Aug 2022 19:05:27 +0200
Subject: [PATCH 019/433] macOS: maintain list of connected USB devices
---
.../usb/common/USBDeviceRegistry.java | 25 +-
.../usb/linux/LinuxUSBDeviceRegistry.java | 2 +-
.../usb/macos/MacosUSBDeviceInfo.java | 4 +
.../usb/macos/MacosUSBDeviceRegistry.java | 284 ++++++++++--------
.../usb/windows/WindowsUSBDeviceRegistry.java | 2 +-
.../codecrete/usb/sample/MonitorDevices.java | 6 +-
6 files changed, 193 insertions(+), 130 deletions(-)
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceRegistry.java
index 685797d0..215e81ca 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceRegistry.java
@@ -15,10 +15,27 @@
/**
* USB device registry.
*/
-public interface USBDeviceRegistry {
- List getAllDevices();
+public abstract class USBDeviceRegistry {
+ protected Consumer onDeviceConnectedHandler;
+ protected Consumer onDeviceDisconnectedHandler;
- void setOnDeviceConnected(Consumer handler);
+ public abstract List getAllDevices();
- void setOnDeviceDisconnected(Consumer handler);
+ public void setOnDeviceConnected(Consumer handler) {
+ onDeviceConnectedHandler = handler;
+ }
+
+ public void setOnDeviceDisconnected(Consumer handler) {
+ onDeviceDisconnectedHandler = handler;
+ }
+
+ protected void emitOnDeviceConnected(USBDeviceInfo device) {
+ if (onDeviceConnectedHandler != null)
+ onDeviceConnectedHandler.accept(device);
+ }
+
+ protected void emitOnDeviceDisconnected(USBDeviceInfo device) {
+ if (onDeviceDisconnectedHandler != null)
+ onDeviceDisconnectedHandler.accept(device);
+ }
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceRegistry.java
index c786705a..8bb8d45d 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceRegistry.java
@@ -23,7 +23,7 @@
/**
* USB implementation for Linux
*/
-public class LinuxUSBDeviceRegistry implements USBDeviceRegistry {
+public class LinuxUSBDeviceRegistry extends USBDeviceRegistry {
@Override
public List getAllDevices() {
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceInfo.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceInfo.java
index 877f3296..f988475b 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceInfo.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceInfo.java
@@ -26,4 +26,8 @@ public class MacosUSBDeviceInfo extends USBDeviceInfoImpl {
public USBDevice open() {
return new MacosUSBDevice(id, this);
}
+
+ Object getId() {
+ return this.id;
+ }
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceRegistry.java
index 407757dc..30990f59 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceRegistry.java
@@ -10,50 +10,48 @@
import net.codecrete.usb.USBDeviceInfo;
import net.codecrete.usb.common.USBDeviceRegistry;
-import java.lang.foreign.FunctionDescriptor;
-import java.lang.foreign.Linker;
-import java.lang.foreign.MemoryAddress;
-import java.lang.foreign.MemorySession;
+import java.lang.foreign.*;
+import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.ArrayList;
import java.util.List;
-import java.util.function.Consumer;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
import static java.lang.foreign.MemoryAddress.NULL;
import static java.lang.foreign.ValueLayout.*;
-public class MacosUSBDeviceRegistry implements USBDeviceRegistry {
-
- private Consumer onDeviceConnectedHandler;
- private Consumer onDeviceDisconnectedHandler;
- private boolean isMonitorThreadStarted;
- private boolean isMonitoringReady;
+/**
+ * MacOS implementation of USB device registry.
+ *
+ * This singleton class maintains a list of connected USB devices.
+ * It start a background thread monitoring the USB devices that are
+ * connected and disconnected.
+ *
+ *
+ * The background thread also creates the initial devices list as
+ * setting up the notifications will initially deliver the connected
+ * devices anyway.
+ *
+ */
+public class MacosUSBDeviceRegistry extends USBDeviceRegistry {
+
+ private volatile List devices;
+ private final Lock lock = new ReentrantLock();
+ private final Condition enumerationComplete = lock.newCondition();
+
+ public MacosUSBDeviceRegistry() {
+ startDeviceMonitor();
+ }
public List getAllDevices() {
-
- try (var session = MemorySession.openConfined()) {
-
- final int entry = IoKit.IORegistryGetRootEntry(IoKit.kIOMasterPortDefault);
- if (entry == 0)
- throw new RuntimeException("IORegistryGetRootEntry failed");
- session.addCloseAction(() -> IoKit.IOObjectRelease(entry));
-
- // create an iterator for USB devices
- var iterHolder = session.allocate(JAVA_INT);
- // TODO: passing 'entry' as the first argument does not work - why?
- int ret = IoKit.IORegistryCreateIterator(0, IoKit.kIOUSBPlane, IoKit.kIORegistryIterateRecursively, iterHolder);
- final var iter = iterHolder.get(JAVA_INT, 0);
- if (ret != 0)
- throw new RuntimeException("IORegistryCreateIterator failed");
- session.addCloseAction(() -> IoKit.IOObjectRelease(iter));
-
- return iterateDevices(iter, false);
- }
+ return devices;
}
/**
- * Process the iterator and return a list of devices ({@link USBDeviceInfo}).
+ * Process the device iterator and return a list of devices ({@link USBDeviceInfo}).
*
* @param iterator iterator
* @param isDisconnected flag is the iterator is for disconnected devices
@@ -95,79 +93,87 @@ private List iterateDevices(int iterator, boolean isDisconnected)
return result;
}
- private synchronized void startDeviceMonitor() {
- if (isMonitorThreadStarted)
- return;
+ private USBDeviceInfo createDeviceInfo(long entryID, int service) {
- isMonitorThreadStarted = true;
+ Integer vendorId = IoKitHelper.GetPropertyInt(service, "idVendor");
+ Integer productId = IoKitHelper.GetPropertyInt(service, "idProduct");
+ String manufacturer = IoKitHelper.GetPropertyString(service, "kUSBVendorString");
+ String product = IoKitHelper.GetPropertyString(service, "kUSBProductString");
+ String serial = IoKitHelper.GetPropertyString(service, "kUSBSerialNumberString");
+ Integer classCode = IoKitHelper.GetPropertyInt(service, "bDeviceClass");
+ Integer subclassCode = IoKitHelper.GetPropertyInt(service, "bDeviceSubClass");
+ Integer protocolCode = IoKitHelper.GetPropertyInt(service, "bDeviceProtocol");
+
+ if (vendorId == null || productId == null || classCode == null || subclassCode == null || protocolCode == null)
+ return null;
+
+ return new MacosUSBDeviceInfo(entryID, vendorId, productId, manufacturer, product, serial, classCode, subclassCode, protocolCode);
+ }
+
+ /**
+ * Starts the background thread and waits until the first device enumeration is complete.
+ */
+ private void startDeviceMonitor() {
+ // start new thread
Thread t = new Thread(this::monitorDevices, "USB device monitor");
+ t.setDaemon(true);
t.start();
+
+ // wait for initial device enumeration
+ lock.lock();
+ try {
+ while (devices == null) {
+ enumerationComplete.awaitUninterruptibly();
+ }
+ } finally {
+ lock.unlock();
+ }
}
+ /**
+ * Monitors the USB devices.
+ *
+ * This method is the core of the background thread. It runs forever and does not terminate.
+ *
+ */
private void monitorDevices() {
+ // as the method runs forever, there is no need to clean up one-time allocations
try (var session = MemorySession.openConfined()) {
+ // setup run loop, run loop source and notification port
var notifyPort = IoKit.IONotificationPortCreate(IoKit.kIOMasterPortDefault);
var runLoopSource = IoKit.IONotificationPortGetRunLoopSource(notifyPort);
-
var runLoop = CoreFoundation.CFRunLoopGetCurrent();
CoreFoundation.CFRunLoopAddSource(runLoop, runLoopSource, IoKit.kCFRunLoopDefaultMode);
- var matchingDict = IoKit.IOServiceMatching(IoKit.kIOUSBDeviceClassName);
-
- // create callback stub (connected devices)
+ // setup notification for connected devices
var onDeviceConnectedMH = MethodHandles.lookup().findVirtual(
- MacosUSBDeviceRegistry.class,
- "onDeviceConnected",
- MethodType.methodType(void.class, MemoryAddress.class, int.class)
- ).bindTo(this);
- var onDeviceConnectedStub = Linker.nativeLinker().upcallStub(
- onDeviceConnectedMH,
- FunctionDescriptor.ofVoid(ADDRESS, JAVA_INT),
- session
- );
-
- // Set up a notification to be called when a device is first matched by I/O Kit.
- // This method consumes the matchingDict reference.
- var deviceIterHolder = session.allocate(JAVA_INT);
- int ret = IoKit.IOServiceAddMatchingNotification(notifyPort, IoKit.kIOFirstMatchNotification,
- matchingDict, onDeviceConnectedStub, NULL, deviceIterHolder);
- if (ret != 0)
- throw new MacosUSBException("IOServiceAddMatchingNotification failed", ret);
- var deviceConnectedIter = deviceIterHolder.get(JAVA_INT, 0);
+ MacosUSBDeviceRegistry.class, "onDevicesConnected",
+ MethodType.methodType(void.class, MemoryAddress.class, int.class));
+ int deviceConnectedIter = setupNotification(session, notifyPort, IoKit.kIOFirstMatchNotification, onDeviceConnectedMH);
// iterate current devices in order to arm the notifications
- onDeviceConnected(NULL, deviceConnectedIter);
-
- // new matching dictionary for disconnected notifications
- matchingDict = IoKit.IOServiceMatching(IoKit.kIOUSBDeviceClassName);
+ devices = iterateDevices(deviceConnectedIter, false);
+
+ // signal completion of initial device enumeration
+ lock.lock();
+ try {
+ enumerationComplete.signalAll();
+ } finally {
+ lock.unlock();
+ }
- // create callback stub (connected devices)
+ // setup notification for disconnected devices
var onDeviceDisconnectedMH = MethodHandles.lookup().findVirtual(
- MacosUSBDeviceRegistry.class,
- "onDeviceDisconnected",
- MethodType.methodType(void.class, MemoryAddress.class, int.class)
- ).bindTo(this);
- var onDeviceDisconnectedStub = Linker.nativeLinker().upcallStub(
- onDeviceDisconnectedMH,
- FunctionDescriptor.ofVoid(ADDRESS, JAVA_INT),
- session
- );
-
- // Set up a notification to be called when a device is terminated by I/O Kit.
- // This method consumes the matchingDict reference.
- deviceIterHolder.set(JAVA_INT, 0, 0);
- ret = IoKit.IOServiceAddMatchingNotification(notifyPort, IoKit.kIOTerminatedNotification,
- matchingDict, onDeviceDisconnectedStub, NULL, deviceIterHolder);
- if (ret != 0)
- throw new MacosUSBException("IOServiceAddMatchingNotification (2) failed", ret);
- var deviceDisconnectedIter = deviceIterHolder.get(JAVA_INT, 0);
+ MacosUSBDeviceRegistry.class, "onDevicesDisconnected",
+ MethodType.methodType(void.class, MemoryAddress.class, int.class));
+ int deviceDisconnectedIter = setupNotification(session, notifyPort, IoKit.kIOTerminatedNotification, onDeviceDisconnectedMH);
// iterate current devices in order to arm the notifications
- onDeviceDisconnected(NULL, deviceDisconnectedIter);
+ onDevicesDisconnected(NULL, deviceDisconnectedIter);
- isMonitoringReady = true;
+ // loop forever
CoreFoundation.CFRunLoopRun();
} catch (NoSuchMethodException | IllegalAccessException e) {
@@ -175,60 +181,92 @@ private void monitorDevices() {
}
}
- private void onDeviceConnected(MemoryAddress ignoredRefCon, int iterator) {
- var devices = iterateDevices(iterator, false);
- if (onDeviceConnectedHandler == null || !isMonitoringReady)
- return;
+ private int setupNotification(MemorySession session, MemoryAddress notifyPort, MemorySegment notificationType, MethodHandle callback)
+ throws NoSuchMethodException, IllegalAccessException {
- for (var device : devices)
- onDeviceConnectedHandler.accept(device);
- }
+ // new matching dictionary for (dis)connected device notifications
+ MemoryAddress matchingDict = IoKit.IOServiceMatching(IoKit.kIOUSBDeviceClassName);
- private void onDeviceDisconnected(MemoryAddress ignoredRefCon, int iterator) {
- var devices = iterateDevices(iterator, true);
- if (onDeviceDisconnectedHandler == null || !isMonitoringReady)
- return;
+ // create callback stub
+ var onDeviceCallbackStub = Linker.nativeLinker().upcallStub(
+ callback.bindTo(this),
+ FunctionDescriptor.ofVoid(ADDRESS, JAVA_INT),
+ session
+ );
- for (var device : devices)
- onDeviceDisconnectedHandler.accept(device);
- }
+ // Set up a notification to be called when a device is first matched / terminated by I/O Kit.
+ // This method consumes the matchingDict reference.
+ var deviceIterHolder = session.allocate(JAVA_INT);
+ int ret = IoKit.IOServiceAddMatchingNotification(notifyPort, notificationType,
+ matchingDict, onDeviceCallbackStub, NULL, deviceIterHolder);
+ if (ret != 0)
+ throw new MacosUSBException("IOServiceAddMatchingNotification failed", ret);
- private USBDeviceInfo createDeviceInfo(long entryID, int service) {
+ return deviceIterHolder.get(JAVA_INT, 0);
+ }
- Integer vendorId = IoKitHelper.GetPropertyInt(service, "idVendor");
- Integer productId = IoKitHelper.GetPropertyInt(service, "idProduct");
- String manufacturer = IoKitHelper.GetPropertyString(service, "kUSBVendorString");
- String product = IoKitHelper.GetPropertyString(service, "kUSBProductString");
- String serial = IoKitHelper.GetPropertyString(service, "kUSBSerialNumberString");
- Integer classCode = IoKitHelper.GetPropertyInt(service, "bDeviceClass");
- Integer subclassCode = IoKitHelper.GetPropertyInt(service, "bDeviceSubClass");
- Integer protocolCode = IoKitHelper.GetPropertyInt(service, "bDeviceProtocol");
+ /**
+ * Callback function for monitoring connected USB devices.
+ *
+ * This method is used in an upcall from native code.
+ *
+ * @param ignoredRefCon ignored parameter
+ * @param iterator device iterator
+ */
+ private void onDevicesConnected(MemoryAddress ignoredRefCon, int iterator) {
+ // retrieve device info for connected devices
+ var connectedDevices = iterateDevices(iterator, false);
- if (vendorId == null || productId == null || classCode == null || subclassCode == null || protocolCode == null)
- return null;
+ // create new device list with connected devices
+ var newDeviceList = new ArrayList<>(devices);
+ newDeviceList.addAll(connectedDevices);
+ devices = newDeviceList;
- return new MacosUSBDeviceInfo(entryID, vendorId, productId, manufacturer, product, serial, classCode, subclassCode, protocolCode);
+ // emit events
+ connectedDevices.forEach(this::emitOnDeviceConnected);
}
- @Override
- public void setOnDeviceConnected(Consumer handler) {
- if (handler == null) {
- onDeviceConnectedHandler = null;
- return;
+ /**
+ * Callback function for monitoring disconnected USB devices.
+ *
+ * This method is used in an upcall from native code.
+ *
+ * @param ignoredRefCon ignored parameter
+ * @param iterator device iterator
+ */
+ private void onDevicesDisconnected(MemoryAddress ignoredRefCon, int iterator) {
+ // retrieve device info for disconnected devices
+ var disconnectedDevices = iterateDevices(iterator, true);
+
+ // create new device list without the disconnected devices
+ var newDeviceList = new ArrayList<>(devices);
+ for (var device : disconnectedDevices) {
+ int index = findDeviceIndex(newDeviceList, device);
+ if (index >= 0)
+ newDeviceList.remove(index);
}
+ devices = newDeviceList;
- onDeviceConnectedHandler = handler;
- startDeviceMonitor();
+ // emit events
+ disconnectedDevices.forEach(this::emitOnDeviceDisconnected);
}
- @Override
- public void setOnDeviceDisconnected(Consumer handler) {
- if (handler == null) {
- onDeviceDisconnectedHandler = null;
- return;
+ /**
+ * Find the index of the device in the device list.
+ *
+ * Devices are compared by their IO registry entry ID.
+ *
+ * @param deviceList the device list
+ * @param device the device
+ * @return the index of the device, or -1 if it is not found
+ */
+ private static int findDeviceIndex(List deviceList, USBDeviceInfo device) {
+ Object id = ((MacosUSBDeviceInfo)device).getId();
+ for (int i = 0; i < deviceList.size(); i++) {
+ var macDevice = (MacosUSBDeviceInfo) deviceList.get(i);
+ if (id.equals(macDevice.getId()))
+ return i;
}
-
- onDeviceDisconnectedHandler = handler;
- startDeviceMonitor();
+ return -1;
}
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
index 0f040c5c..7e78807e 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
@@ -30,7 +30,7 @@
import static java.lang.foreign.MemoryAddress.NULL;
import static java.lang.foreign.ValueLayout.*;
-public class WindowsUSBDeviceRegistry implements USBDeviceRegistry {
+public class WindowsUSBDeviceRegistry extends USBDeviceRegistry {
private volatile List devices;
private Consumer onDeviceConnectedHandler;
diff --git a/java-does-usb/src/test/java/net/codecrete/usb/sample/MonitorDevices.java b/java-does-usb/src/test/java/net/codecrete/usb/sample/MonitorDevices.java
index 983c4a0a..ea152847 100644
--- a/java-does-usb/src/test/java/net/codecrete/usb/sample/MonitorDevices.java
+++ b/java-does-usb/src/test/java/net/codecrete/usb/sample/MonitorDevices.java
@@ -17,9 +17,13 @@
*/
public class MonitorDevices {
- public static void main(String[] args) {
+ public static void main(String[] args) throws InterruptedException {
System.out.println("Monitoring USB devices...");
USB.setOnDeviceConnected((dev) -> System.out.println("Connected: " + dev.toString()));
USB.setOnDeviceDisconnected((dev) -> System.out.println("Disconnected: " + dev.toString()));
+
+ while (true) {
+ Thread.sleep(1000000);
+ }
}
}
From 32de076bb0f53290a347a3f2fc75d157c3110110 Mon Sep 17 00:00:00 2001
From: Manuel Bl
Date: Mon, 29 Aug 2022 20:15:30 +0200
Subject: [PATCH 020/433] Factor out common Windows and macOS code
---
.../usb/common/USBDeviceRegistry.java | 40 +++++++++
.../usb/macos/MacosUSBDeviceRegistry.java | 38 +-------
.../usb/windows/WindowsUSBDeviceRegistry.java | 88 ++++++++-----------
3 files changed, 78 insertions(+), 88 deletions(-)
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceRegistry.java
index 215e81ca..e80ada9a 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceRegistry.java
@@ -10,15 +10,23 @@
import net.codecrete.usb.USBDeviceInfo;
import java.util.List;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Consumer;
/**
* USB device registry.
*/
public abstract class USBDeviceRegistry {
+
+ protected volatile List devices;
protected Consumer onDeviceConnectedHandler;
protected Consumer onDeviceDisconnectedHandler;
+ private final Lock lock = new ReentrantLock();
+ private final Condition enumerationComplete = lock.newCondition();
+
public abstract List getAllDevices();
public void setOnDeviceConnected(Consumer handler) {
@@ -38,4 +46,36 @@ protected void emitOnDeviceDisconnected(USBDeviceInfo device) {
if (onDeviceDisconnectedHandler != null)
onDeviceDisconnectedHandler.accept(device);
}
+
+ /**
+ * Starts the background thread and waits until the first device enumeration is complete.
+ */
+ protected void startDeviceMonitor(Runnable monitorTask) {
+ // start new thread
+ Thread t = new Thread(monitorTask, "USB device monitor");
+ t.setDaemon(true);
+ t.start();
+
+ // wait for initial device enumeration
+ lock.lock();
+ try {
+ while (devices == null) {
+ enumerationComplete.awaitUninterruptibly();
+ }
+ } finally {
+ lock.unlock();
+ }
+ }
+
+ /**
+ * Signals completion of initial device enumeration.
+ */
+ protected void signalEnumerationComplete() {
+ lock.lock();
+ try {
+ enumerationComplete.signalAll();
+ } finally {
+ lock.unlock();
+ }
+ }
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceRegistry.java
index 30990f59..31f027a7 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceRegistry.java
@@ -16,9 +16,6 @@
import java.lang.invoke.MethodType;
import java.util.ArrayList;
import java.util.List;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
import static java.lang.foreign.MemoryAddress.NULL;
import static java.lang.foreign.ValueLayout.*;
@@ -27,7 +24,7 @@
* MacOS implementation of USB device registry.
*
* This singleton class maintains a list of connected USB devices.
- * It start a background thread monitoring the USB devices that are
+ * It starts a background thread monitoring the USB devices being
* connected and disconnected.
*
*
@@ -38,12 +35,8 @@
*/
public class MacosUSBDeviceRegistry extends USBDeviceRegistry {
- private volatile List devices;
- private final Lock lock = new ReentrantLock();
- private final Condition enumerationComplete = lock.newCondition();
-
public MacosUSBDeviceRegistry() {
- startDeviceMonitor();
+ startDeviceMonitor(this::monitorDevices);
}
public List getAllDevices() {
@@ -110,26 +103,6 @@ private USBDeviceInfo createDeviceInfo(long entryID, int service) {
return new MacosUSBDeviceInfo(entryID, vendorId, productId, manufacturer, product, serial, classCode, subclassCode, protocolCode);
}
- /**
- * Starts the background thread and waits until the first device enumeration is complete.
- */
- private void startDeviceMonitor() {
- // start new thread
- Thread t = new Thread(this::monitorDevices, "USB device monitor");
- t.setDaemon(true);
- t.start();
-
- // wait for initial device enumeration
- lock.lock();
- try {
- while (devices == null) {
- enumerationComplete.awaitUninterruptibly();
- }
- } finally {
- lock.unlock();
- }
- }
-
/**
* Monitors the USB devices.
*
@@ -157,12 +130,7 @@ private void monitorDevices() {
devices = iterateDevices(deviceConnectedIter, false);
// signal completion of initial device enumeration
- lock.lock();
- try {
- enumerationComplete.signalAll();
- } finally {
- lock.unlock();
- }
+ signalEnumerationComplete();
// setup notification for disconnected devices
var onDeviceDisconnectedMH = MethodHandles.lookup().findVirtual(
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
index 7e78807e..c7d39cc0 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
@@ -25,18 +25,24 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
-import java.util.function.Consumer;
import static java.lang.foreign.MemoryAddress.NULL;
import static java.lang.foreign.ValueLayout.*;
+/**
+ * Windows implementation of USB device registry.
+ *
+ * This singleton class maintains a list of connected USB devices.
+ * It starts a background thread monitoring the USB devices being
+ * connected and disconnected.
+ *
+ *
+ * The background thread also enumerates the already present devices
+ * and builds the initial device list.
+ *
+ */
public class WindowsUSBDeviceRegistry extends USBDeviceRegistry {
- private volatile List devices;
- private Consumer onDeviceConnectedHandler;
- private Consumer onDeviceDisconnectedHandler;
- private boolean isMonitorThreadStarted;
-
/**
* Create new instance
*
@@ -44,8 +50,7 @@ public class WindowsUSBDeviceRegistry extends USBDeviceRegistry {
*
*/
public WindowsUSBDeviceRegistry() {
- startDeviceMonitor();
- enumeratePresentDevices();
+ startDeviceMonitor(this::monitorDevices);
}
public List getAllDevices() {
@@ -192,15 +197,6 @@ private String getStringDescriptor(Addressable hubHandle, int usbPortNumber, int
}
}
- private synchronized void startDeviceMonitor() {
- if (isMonitorThreadStarted)
- return;
-
- isMonitorThreadStarted = true;
- Thread t = new Thread(this::monitorDevices, "USB device monitor");
- t.start();
- }
-
private void monitorDevices() {
try (var session = MemorySession.openConfined()) {
@@ -244,6 +240,12 @@ private void monitorDevices() {
if (notifyHandle == NULL)
throw new USBException("internal error (RegisterDeviceNotificationW)", Kernel32.GetLastError());
+ // initial device enumeration
+ enumeratePresentDevices();
+
+ // signal that the enumeration is complete
+ signalEnumerationComplete();
+
// process messages
var msg = session.allocate(tagMSG.$LAYOUT());
while (User32.GetMessageW(msg, hwnd, 0, 0) > 0)
@@ -310,7 +312,7 @@ private void onDeviceConnected(String devicePath) {
session.addCloseAction(() -> hubHandles.forEach((path, handle) -> Kernel32.CloseHandle(handle)));
// check for duplicates
- if (findDeviceIndex(devicePath) >= 0)
+ if (findDeviceIndex(devices, devicePath) >= 0)
return;
// create device info instance
@@ -322,59 +324,39 @@ private void onDeviceConnected(String devicePath) {
devices = newDeviceList;
// send notification
- if (onDeviceConnectedHandler == null)
- return;
- onDeviceConnectedHandler.accept(deviceInfo);
+ emitOnDeviceConnected(deviceInfo);
}
}
private void onDeviceDisconnected(String devicePath) {
- int index = findDeviceIndex(devicePath);
+
+ // locate device to be removed
+ int index = findDeviceIndex(devices, devicePath);
if (index < 0)
return; // strange
- // copy list
+ // copy list and remove device
var deviceInfo = devices.get(index);
var newDeviceList = new ArrayList<>(devices);
newDeviceList.remove(index);
devices = newDeviceList;
// send notification
- if (onDeviceDisconnectedHandler == null)
- return;
- onDeviceDisconnectedHandler.accept(deviceInfo);
+ emitOnDeviceDisconnected(deviceInfo);
}
- private int findDeviceIndex(String devicePath) {
- if (devices == null)
- return -1;
- for (int i = 0; i < devices.size(); i++) {
- var winInfo = (WindowsUSBDeviceInfo) devices.get(i);
+ /**
+ * Finds the index of the device with the given path in the device list
+ * @param deviceList the device list
+ * @param devicePath the device path
+ * @return return the index, or -1 if the device is not found
+ */
+ private static int findDeviceIndex(List deviceList, String devicePath) {
+ for (int i = 0; i < deviceList.size(); i++) {
+ var winInfo = (WindowsUSBDeviceInfo) deviceList.get(i);
if (winInfo.devicePath().equalsIgnoreCase(devicePath))
return i;
}
return -1;
}
-
- @Override
- public void setOnDeviceConnected(Consumer handler) {
- if (handler == null) {
- onDeviceConnectedHandler = null;
- return;
- }
-
- onDeviceConnectedHandler = handler;
- startDeviceMonitor();
- }
-
- @Override
- public void setOnDeviceDisconnected(Consumer handler) {
- if (handler == null) {
- onDeviceDisconnectedHandler = null;
- return;
- }
-
- onDeviceDisconnectedHandler = handler;
- startDeviceMonitor();
- }
}
From 5107d490bcaa8d2ab8fb145f05239d4709ec0994 Mon Sep 17 00:00:00 2001
From: Manuel Bl
Date: Mon, 29 Aug 2022 21:30:14 +0200
Subject: [PATCH 021/433] Linux: convert from libsystemd to libudev
---
java-does-usb/jextract/gen_linux.sh | 19 ++
.../usb/linux/LinuxUSBDeviceRegistry.java | 142 +++++++-----
.../java/net/codecrete/usb/linux/Systemd.java | 140 -----------
.../usb/linux/gen/udev/Constants$root.java | 19 ++
.../usb/linux/gen/udev/RuntimeHelper.java | 217 ++++++++++++++++++
.../usb/linux/gen/udev/constants$0.java | 52 +++++
.../usb/linux/gen/udev/constants$1.java | 55 +++++
.../codecrete/usb/linux/gen/udev/udev.java | 155 +++++++++++++
8 files changed, 600 insertions(+), 199 deletions(-)
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/Systemd.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/Constants$root.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/RuntimeHelper.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$0.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$1.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/udev.java
diff --git a/java-does-usb/jextract/gen_linux.sh b/java-does-usb/jextract/gen_linux.sh
index cfd9db19..c85990cd 100755
--- a/java-does-usb/jextract/gen_linux.sh
+++ b/java-does-usb/jextract/gen_linux.sh
@@ -51,3 +51,22 @@ $JEXTRACT --source --output ../src/main/java \
--include-macro USBDEVFS_CLAIMINTERFACE \
--include-macro USBDEVFS_RELEASEINTERFACE \
/usr/include/linux/usbdevice_fs.h
+
+# libudev.h
+$JEXTRACT --source --output ../src/main/java \
+ --header-class-name udev \
+ --target-package net.codecrete.usb.linux.gen.udev \
+ -l udev \
+ --include-function udev_new \
+ --include-function udev_enumerate_new \
+ --include-function udev_enumerate_add_match_subsystem \
+ --include-function udev_enumerate_scan_devices \
+ --include-function udev_enumerate_get_list_entry \
+ --include-function udev_list_entry_get_next \
+ --include-function udev_list_entry_get_name \
+ --include-function udev_device_new_from_syspath \
+ --include-function udev_device_get_devnode \
+ --include-function udev_device_get_sysattr_value \
+ --include-function udev_device_unref \
+ --include-function udev_enumerate_unref \
+ /usr/include/libudev.h
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceRegistry.java
index 8bb8d45d..509359f6 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceRegistry.java
@@ -9,100 +9,124 @@
import net.codecrete.usb.USBDeviceInfo;
import net.codecrete.usb.common.USBDeviceRegistry;
+import net.codecrete.usb.linux.gen.udev.udev;
import java.lang.foreign.Addressable;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.MemorySession;
import java.util.ArrayList;
import java.util.List;
-import java.util.function.Consumer;
import static java.lang.foreign.MemoryAddress.NULL;
-import static java.lang.foreign.ValueLayout.ADDRESS;
/**
- * USB implementation for Linux
+ * Linux implementation of USB device registry.
+ *
+ * This singleton class maintains a list of connected USB devices.
+ * It starts a background thread monitoring the USB devices being
+ * connected and disconnected.
+ *
+ *
+ * The background thread also enumerates the already present devices
+ * and builds the initial device list.
+ *
*/
public class LinuxUSBDeviceRegistry extends USBDeviceRegistry {
+
+ private static final MemorySegment SUBSYSTEM_USB = MemorySession.global().allocateUtf8String("usb");
+
+ /**
+ * Creates a new instance.
+ */
+ public LinuxUSBDeviceRegistry() {
+ enumeratePresentDevices();
+ }
+
@Override
public List getAllDevices() {
+ return devices;
+ }
+ private void enumeratePresentDevices() {
List result = new ArrayList<>();
- try (var session = MemorySession.openConfined()) {
- // create enumerator
- var eHolder = session.allocate(ADDRESS);
- Systemd.sd_device_enumerator_new(eHolder);
- var e = eHolder.get(ADDRESS, 0);
- session.addCloseAction(() -> Systemd.sd_device_enumerator_unref(e));
-
- // restrict to USB devices
- Systemd.sd_device_enumerator_add_match_subsystem(e, "usb", 1);
-
- // iterate devices
- for (var dev = Systemd.sd_device_enumerator_get_device_first(e);
- dev != NULL;
- dev = Systemd.sd_device_enumerator_get_device_next(e)
- ) {
- // retrieve device attributes
- String idVendor = getDeviceAttribute(dev, "idVendor");
- if (idVendor == null)
- continue;
-
- String idProduct = getDeviceAttribute(dev, "idProduct");
- if (idProduct == null)
- continue;
-
- String devPath = getDeviceName(dev);
- if (devPath == null)
- continue;
-
- int vendorId = Integer.parseInt(idVendor, 16);
- int productId = Integer.parseInt(idProduct, 16);
-
- // add device to result list
- result.add(new LinuxUSBDeviceInfo(devPath, vendorId, productId,
- getDeviceAttribute(dev, "manufacturer"),
- getDeviceAttribute(dev, "product"),
- getDeviceAttribute(dev, "serial"),
- 0, 0, 0));
+ try (var outerSession = MemorySession.openConfined()) {
+
+ var udevInstance = udev.udev_new();
+
+ // create device enumerator
+ var enumerate = udev.udev_enumerate_new(udevInstance);
+ outerSession.addCloseAction(() -> udev.udev_enumerate_unref(enumerate));
+ udev.udev_enumerate_add_match_subsystem(enumerate, SUBSYSTEM_USB);
+ udev.udev_enumerate_scan_devices(enumerate);
+
+ // enumerate devices
+ for (var entry= udev.udev_enumerate_get_list_entry(enumerate);
+ entry != NULL;
+ entry = udev.udev_list_entry_get_next(entry)) {
+
+ try (var session = MemorySession.openConfined()) {
+
+ var path = udev.udev_list_entry_get_name(entry);
+ if (path == NULL)
+ continue;
+
+ // get device handle
+ var dev = udev.udev_device_new_from_syspath(udevInstance, path);
+ if (dev == NULL)
+ continue;
+
+ session.addCloseAction(() -> udev.udev_device_unref(dev));
+
+ // retrieve device attributes
+ String idVendor = getDeviceAttribute(dev, "idVendor");
+ if (idVendor == null)
+ continue;
+
+ String idProduct = getDeviceAttribute(dev, "idProduct");
+ if (idProduct == null)
+ continue;
+
+ // get device path
+ var devPath = getDeviceName(dev);
+ if (devPath == null)
+ continue;
+
+ int vendorId = Integer.parseInt(idVendor, 16);
+ int productId = Integer.parseInt(idProduct, 16);
+
+ // add device to result list
+ result.add(new LinuxUSBDeviceInfo(devPath, vendorId, productId,
+ getDeviceAttribute(dev, "manufacturer"),
+ getDeviceAttribute(dev, "product"),
+ getDeviceAttribute(dev, "serial"),
+ 0, 0, 0));
+ }
}
}
- return result;
+ devices = result;
}
private static String getDeviceAttribute(Addressable device, String attribute) {
try (var session = MemorySession.openConfined()) {
var sysattr = session.allocateUtf8String(attribute);
- var valueHolder = session.allocate(ADDRESS);
- int res = Systemd.sd_device_get_sysattr_value(device, sysattr, valueHolder);
- if (res != 0)
+ var valueAddr = udev.udev_device_get_sysattr_value(device, sysattr);
+ if (valueAddr == NULL)
return null;
- var valuePointer = valueHolder.get(ADDRESS, 0);
- var value = MemorySegment.ofAddress(valuePointer, 2000, session);
+ var value = MemorySegment.ofAddress(valueAddr, 2000, session);
return value.getUtf8String(0);
}
}
private static String getDeviceName(Addressable device) {
try (var session = MemorySession.openConfined()) {
- var retHolder = session.allocate(ADDRESS);
- int res = Systemd.sd_device_get_devname(device, retHolder);
- if (res != 0)
+ var devNameAddr = udev.udev_device_get_devnode(device);
+ if (devNameAddr == NULL)
return null;
- var retPointer = retHolder.get(ADDRESS, 0);
- var ret = MemorySegment.ofAddress(retPointer, 2000, session);
+ var ret = MemorySegment.ofAddress(devNameAddr, 2000, session);
return ret.getUtf8String(0);
}
}
-
- @Override
- public void setOnDeviceConnected(Consumer handler) {
- }
-
- @Override
- public void setOnDeviceDisconnected(Consumer handler) {
- }
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/Systemd.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/Systemd.java
deleted file mode 100644
index 12a2f4ca..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/Systemd.java
+++ /dev/null
@@ -1,140 +0,0 @@
-//
-// Java Does USB
-// Copyright (c) 2022 Manuel Bleichenbacher
-// Licensed under MIT License
-// https://opensource.org/licenses/MIT
-//
-
-package net.codecrete.usb.linux;
-
-import java.lang.foreign.*;
-import java.lang.invoke.MethodHandle;
-
-import static java.lang.foreign.ValueLayout.ADDRESS;
-import static java.lang.foreign.ValueLayout.JAVA_INT;
-
-/**
- * Functions and data structures of systemd.
- */
-public class Systemd {
-
- private static final MethodHandle sd_device_enumerator_new$Func;
- private static final MethodHandle sd_device_enumerator_unref$Func;
- private static final MethodHandle sd_device_enumerator_add_match_subsystem$Func;
- private static final MethodHandle sd_device_enumerator_get_device_first$Func;
- private static final MethodHandle sd_device_enumerator_get_device_next$Func;
- private static final MethodHandle sd_device_get_sysattr_value$Func;
- private static final MethodHandle sd_device_get_devname$Func;
-
- static {
- var session = MemorySession.openShared();
- Linker linker = Linker.nativeLinker();
- SymbolLookup lookup = SymbolLookup.libraryLookup("libsystemd.so.0", session);
-
- // int sd_device_enumerator_new(sd_device_enumerator **ret);
- sd_device_enumerator_new$Func = linker.downcallHandle(
- lookup.lookup("sd_device_enumerator_new").get(),
- FunctionDescriptor.of(JAVA_INT, ADDRESS)
- );
-
- // sd_device_enumerator *sd_device_enumerator_unref(sd_device_enumerator *enumerator);
- sd_device_enumerator_unref$Func = linker.downcallHandle(
- lookup.lookup("sd_device_enumerator_unref").get(),
- FunctionDescriptor.of(ADDRESS, ADDRESS)
- );
-
- // int sd_device_enumerator_add_match_subsystem(sd_device_enumerator *enumerator, const char *subsystem, int match);
- sd_device_enumerator_add_match_subsystem$Func = linker.downcallHandle(
- lookup.lookup("sd_device_enumerator_add_match_subsystem").get(),
- FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS, JAVA_INT)
- );
-
- // sd_device *sd_device_enumerator_get_device_first(sd_device_enumerator *enumerator);
- sd_device_enumerator_get_device_first$Func = linker.downcallHandle(
- lookup.lookup("sd_device_enumerator_get_device_first").get(),
- FunctionDescriptor.of(ADDRESS, ADDRESS)
- );
-
- // sd_device *sd_device_enumerator_get_device_next(sd_device_enumerator *enumerator);
- sd_device_enumerator_get_device_next$Func = linker.downcallHandle(
- lookup.lookup("sd_device_enumerator_get_device_next").get(),
- FunctionDescriptor.of(ADDRESS, ADDRESS)
- );
-
- // int sd_device_get_sysattr_value(sd_device *device, const char *sysattr, const char **_value);
- sd_device_get_sysattr_value$Func = linker.downcallHandle(
- lookup.lookup("sd_device_get_sysattr_value").get(),
- FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS, ADDRESS)
- );
-
- // int sd_device_get_devname(sd_device *device, const char **ret);
- sd_device_get_devname$Func = linker.downcallHandle(
- lookup.lookup("sd_device_get_devname").get(),
- FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS)
- );
- }
-
- // int sd_device_enumerator_new(sd_device_enumerator **ret);
- public static int sd_device_enumerator_new(Addressable ret) {
- try {
- return (int) sd_device_enumerator_new$Func.invokeExact(ret);
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- // sd_device_enumerator *sd_device_enumerator_unref(sd_device_enumerator *enumerator);
- public static MemoryAddress sd_device_enumerator_unref(Addressable enumerator) {
- try {
- return (MemoryAddress) sd_device_enumerator_unref$Func.invokeExact(enumerator);
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- // int sd_device_enumerator_add_match_subsystem(sd_device_enumerator *enumerator, const char *subsystem, int match);
- public static int sd_device_enumerator_add_match_subsystem(Addressable enumerator, String subsystem, int match) {
- try (var session = MemorySession.openConfined()) {
- var subsys = session.allocateUtf8String(subsystem);
- return (int) sd_device_enumerator_add_match_subsystem$Func.invokeExact(enumerator, (Addressable) subsys, match);
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- // sd_device *sd_device_enumerator_get_device_first(sd_device_enumerator *enumerator);
- public static MemoryAddress sd_device_enumerator_get_device_first(Addressable enumerator) {
- try {
- return (MemoryAddress) sd_device_enumerator_get_device_first$Func.invokeExact(enumerator);
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- // sd_device *sd_device_enumerator_get_device_next(sd_device_enumerator *enumerator);
- public static MemoryAddress sd_device_enumerator_get_device_next(Addressable enumerator) {
- try {
- return (MemoryAddress) sd_device_enumerator_get_device_next$Func.invokeExact(enumerator);
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- // int sd_device_get_sysattr_value(sd_device *device, const char *sysattr, const char **_value);
- public static int sd_device_get_sysattr_value(Addressable device, Addressable sysattr, Addressable value) {
- try {
- return (int) sd_device_get_sysattr_value$Func.invokeExact(device, sysattr, value);
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- // int sd_device_get_devname(sd_device *device, const char **ret);
- public static int sd_device_get_devname(Addressable device, Addressable ret) {
- try {
- return (int) sd_device_get_devname$Func.invokeExact(device, ret);
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/Constants$root.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/Constants$root.java
new file mode 100644
index 00000000..2a06330e
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/Constants$root.java
@@ -0,0 +1,19 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.udev;
+
+import static java.lang.foreign.ValueLayout.*;
+public class Constants$root {
+
+ static final OfBoolean C_BOOL$LAYOUT = JAVA_BOOLEAN;
+ static final OfByte C_CHAR$LAYOUT = JAVA_BYTE;
+ static final OfShort C_SHORT$LAYOUT = JAVA_SHORT.withBitAlignment(16);
+ static final OfInt C_INT$LAYOUT = JAVA_INT.withBitAlignment(32);
+ static final OfLong C_LONG$LAYOUT = JAVA_LONG.withBitAlignment(64);
+ static final OfLong C_LONG_LONG$LAYOUT = JAVA_LONG.withBitAlignment(64);
+ static final OfFloat C_FLOAT$LAYOUT = JAVA_FLOAT.withBitAlignment(32);
+ static final OfDouble C_DOUBLE$LAYOUT = JAVA_DOUBLE.withBitAlignment(64);
+ static final OfAddress C_POINTER$LAYOUT = ADDRESS.withBitAlignment(64);
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/RuntimeHelper.java
new file mode 100644
index 00000000..775c0b6c
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/RuntimeHelper.java
@@ -0,0 +1,217 @@
+package net.codecrete.usb.linux.gen.udev;
+// Generated by jextract
+
+import java.lang.foreign.*;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+
+import static java.lang.foreign.ValueLayout.*;
+
+final class RuntimeHelper {
+
+ private RuntimeHelper() {}
+ private final static Linker LINKER = Linker.nativeLinker();
+ private final static ClassLoader LOADER = RuntimeHelper.class.getClassLoader();
+ private final static MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup();
+ private final static SymbolLookup SYMBOL_LOOKUP;
+
+ final static SegmentAllocator CONSTANT_ALLOCATOR =
+ (size, align) -> MemorySegment.allocateNative(size, align, MemorySession.openImplicit());
+
+ static {
+// System.loadLibrary("udev");
+// SymbolLookup loaderLookup = SymbolLookup.loaderLookup();
+ SymbolLookup loaderLookup = SymbolLookup.libraryLookup("libudev.so", MemorySession.openImplicit());
+ SYMBOL_LOOKUP = name -> loaderLookup.lookup(name).or(() -> LINKER.defaultLookup().lookup(name));
+ }
+
+ static T requireNonNull(T obj, String symbolName) {
+ if (obj == null) {
+ throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName);
+ }
+ return obj;
+ }
+
+ private final static SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); };
+
+ static final MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) {
+ return SYMBOL_LOOKUP.lookup(name).map(symbol -> MemorySegment.ofAddress(symbol.address(), layout.byteSize(), MemorySession.openShared())).orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> LINKER.downcallHandle(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(FunctionDescriptor fdesc) {
+ return LINKER.downcallHandle(fdesc);
+ }
+
+ static final MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> VarargsInvoker.make(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MemorySegment upcallStub(Class fi, Z z, FunctionDescriptor fdesc, MemorySession session) {
+ try {
+ MethodHandle handle = MH_LOOKUP.findVirtual(fi, "apply", Linker.upcallType(fdesc));
+ handle = handle.bindTo(z);
+ return LINKER.upcallStub(handle, fdesc, session);
+ } catch (Throwable ex) {
+ throw new AssertionError(ex);
+ }
+ }
+
+ static MemorySegment asArray(MemoryAddress addr, MemoryLayout layout, int numElements, MemorySession session) {
+ return MemorySegment.ofAddress(addr, numElements * layout.byteSize(), session);
+ }
+
+ // Internals only below this point
+
+ private static class VarargsInvoker {
+ private static final MethodHandle INVOKE_MH;
+ private final MemorySegment symbol;
+ private final FunctionDescriptor function;
+
+ private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) {
+ this.symbol = symbol;
+ this.function = function;
+ }
+
+ static {
+ try {
+ INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class));
+ } catch (ReflectiveOperationException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) {
+ VarargsInvoker invoker = new VarargsInvoker(symbol, function);
+ MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1);
+ MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class);
+ for (MemoryLayout layout : function.argumentLayouts()) {
+ mtype = mtype.appendParameterTypes(carrier(layout, false));
+ }
+ mtype = mtype.appendParameterTypes(Object[].class);
+ if (mtype.returnType().equals(MemorySegment.class)) {
+ mtype = mtype.insertParameterTypes(0, SegmentAllocator.class);
+ } else {
+ handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR);
+ }
+ return handle.asType(mtype);
+ }
+
+ static Class> carrier(MemoryLayout layout, boolean ret) {
+ if (layout instanceof ValueLayout valueLayout) {
+ return (ret || valueLayout.carrier() != MemoryAddress.class) ?
+ valueLayout.carrier() : Addressable.class;
+ } else if (layout instanceof GroupLayout) {
+ return MemorySegment.class;
+ } else {
+ throw new AssertionError("Cannot get here!");
+ }
+ }
+
+ private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable {
+ // one trailing Object[]
+ int nNamedArgs = function.argumentLayouts().size();
+ assert(args.length == nNamedArgs + 1);
+ // The last argument is the array of vararg collector
+ Object[] unnamedArgs = (Object[]) args[args.length - 1];
+
+ int argsCount = nNamedArgs + unnamedArgs.length;
+ Class>[] argTypes = new Class>[argsCount];
+ MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length];
+
+ int pos = 0;
+ for (pos = 0; pos < nNamedArgs; pos++) {
+ argLayouts[pos] = function.argumentLayouts().get(pos);
+ }
+
+ assert pos == nNamedArgs;
+ for (Object o: unnamedArgs) {
+ argLayouts[pos] = variadicLayout(normalize(o.getClass()));
+ pos++;
+ }
+ assert pos == argsCount;
+
+ FunctionDescriptor f = (function.returnLayout().isEmpty()) ?
+ FunctionDescriptor.ofVoid(argLayouts) :
+ FunctionDescriptor.of(function.returnLayout().get(), argLayouts);
+ MethodHandle mh = LINKER.downcallHandle(symbol, f);
+ if (mh.type().returnType() == MemorySegment.class) {
+ mh = mh.bindTo(allocator);
+ }
+ // flatten argument list so that it can be passed to an asSpreader MH
+ Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length];
+ System.arraycopy(args, 0, allArgs, 0, nNamedArgs);
+ System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length);
+
+ return mh.asSpreader(Object[].class, argsCount).invoke(allArgs);
+ }
+
+ private static Class> unboxIfNeeded(Class> clazz) {
+ if (clazz == Boolean.class) {
+ return boolean.class;
+ } else if (clazz == Void.class) {
+ return void.class;
+ } else if (clazz == Byte.class) {
+ return byte.class;
+ } else if (clazz == Character.class) {
+ return char.class;
+ } else if (clazz == Short.class) {
+ return short.class;
+ } else if (clazz == Integer.class) {
+ return int.class;
+ } else if (clazz == Long.class) {
+ return long.class;
+ } else if (clazz == Float.class) {
+ return float.class;
+ } else if (clazz == Double.class) {
+ return double.class;
+ } else {
+ return clazz;
+ }
+ }
+
+ private Class> promote(Class> c) {
+ if (c == byte.class || c == char.class || c == short.class || c == int.class) {
+ return long.class;
+ } else if (c == float.class) {
+ return double.class;
+ } else {
+ return c;
+ }
+ }
+
+ private Class> normalize(Class> c) {
+ c = unboxIfNeeded(c);
+ if (c.isPrimitive()) {
+ return promote(c);
+ }
+ if (MemoryAddress.class.isAssignableFrom(c)) {
+ return MemoryAddress.class;
+ }
+ if (MemorySegment.class.isAssignableFrom(c)) {
+ return MemorySegment.class;
+ }
+ throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName());
+ }
+
+ private MemoryLayout variadicLayout(Class> c) {
+ if (c == long.class) {
+ return JAVA_LONG;
+ } else if (c == double.class) {
+ return JAVA_DOUBLE;
+ } else if (MemoryAddress.class.isAssignableFrom(c)) {
+ return ADDRESS;
+ } else {
+ throw new IllegalArgumentException("Unhandled variadic argument class: " + c);
+ }
+ }
+ }
+}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$0.java
new file mode 100644
index 00000000..a6258650
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$0.java
@@ -0,0 +1,52 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.udev;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$0 {
+
+ static final FunctionDescriptor udev_new$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT);
+ static final MethodHandle udev_new$MH = RuntimeHelper.downcallHandle(
+ "udev_new",
+ constants$0.udev_new$FUNC
+ );
+ static final FunctionDescriptor udev_list_entry_get_next$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle udev_list_entry_get_next$MH = RuntimeHelper.downcallHandle(
+ "udev_list_entry_get_next",
+ constants$0.udev_list_entry_get_next$FUNC
+ );
+ static final FunctionDescriptor udev_list_entry_get_name$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle udev_list_entry_get_name$MH = RuntimeHelper.downcallHandle(
+ "udev_list_entry_get_name",
+ constants$0.udev_list_entry_get_name$FUNC
+ );
+ static final FunctionDescriptor udev_device_unref$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle udev_device_unref$MH = RuntimeHelper.downcallHandle(
+ "udev_device_unref",
+ constants$0.udev_device_unref$FUNC
+ );
+ static final FunctionDescriptor udev_device_new_from_syspath$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle udev_device_new_from_syspath$MH = RuntimeHelper.downcallHandle(
+ "udev_device_new_from_syspath",
+ constants$0.udev_device_new_from_syspath$FUNC
+ );
+ static final FunctionDescriptor udev_device_get_devnode$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle udev_device_get_devnode$MH = RuntimeHelper.downcallHandle(
+ "udev_device_get_devnode",
+ constants$0.udev_device_get_devnode$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$1.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$1.java
new file mode 100644
index 00000000..9340bd78
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$1.java
@@ -0,0 +1,55 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.udev;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$1 {
+
+ static final FunctionDescriptor udev_device_get_sysattr_value$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle udev_device_get_sysattr_value$MH = RuntimeHelper.downcallHandle(
+ "udev_device_get_sysattr_value",
+ constants$1.udev_device_get_sysattr_value$FUNC
+ );
+ static final FunctionDescriptor udev_enumerate_unref$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle udev_enumerate_unref$MH = RuntimeHelper.downcallHandle(
+ "udev_enumerate_unref",
+ constants$1.udev_enumerate_unref$FUNC
+ );
+ static final FunctionDescriptor udev_enumerate_new$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle udev_enumerate_new$MH = RuntimeHelper.downcallHandle(
+ "udev_enumerate_new",
+ constants$1.udev_enumerate_new$FUNC
+ );
+ static final FunctionDescriptor udev_enumerate_add_match_subsystem$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle udev_enumerate_add_match_subsystem$MH = RuntimeHelper.downcallHandle(
+ "udev_enumerate_add_match_subsystem",
+ constants$1.udev_enumerate_add_match_subsystem$FUNC
+ );
+ static final FunctionDescriptor udev_enumerate_scan_devices$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle udev_enumerate_scan_devices$MH = RuntimeHelper.downcallHandle(
+ "udev_enumerate_scan_devices",
+ constants$1.udev_enumerate_scan_devices$FUNC
+ );
+ static final FunctionDescriptor udev_enumerate_get_list_entry$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle udev_enumerate_get_list_entry$MH = RuntimeHelper.downcallHandle(
+ "udev_enumerate_get_list_entry",
+ constants$1.udev_enumerate_get_list_entry$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/udev.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/udev.java
new file mode 100644
index 00000000..2b6bde54
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/udev.java
@@ -0,0 +1,155 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.udev;
+
+import java.lang.foreign.Addressable;
+import java.lang.foreign.MemoryAddress;
+import java.lang.invoke.MethodHandle;
+
+import static java.lang.foreign.ValueLayout.*;
+public class udev {
+
+ /* package-private */ udev() {}
+ public static OfByte C_CHAR = Constants$root.C_CHAR$LAYOUT;
+ public static OfShort C_SHORT = Constants$root.C_SHORT$LAYOUT;
+ public static OfInt C_INT = Constants$root.C_INT$LAYOUT;
+ public static OfLong C_LONG = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong C_LONG_LONG = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfFloat C_FLOAT = Constants$root.C_FLOAT$LAYOUT;
+ public static OfDouble C_DOUBLE = Constants$root.C_DOUBLE$LAYOUT;
+ public static OfAddress C_POINTER = Constants$root.C_POINTER$LAYOUT;
+ public static MethodHandle udev_new$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.udev_new$MH,"udev_new");
+ }
+ public static MemoryAddress udev_new () {
+ var mh$ = udev_new$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact();
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle udev_list_entry_get_next$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.udev_list_entry_get_next$MH,"udev_list_entry_get_next");
+ }
+ public static MemoryAddress udev_list_entry_get_next ( Addressable list_entry) {
+ var mh$ = udev_list_entry_get_next$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact(list_entry);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle udev_list_entry_get_name$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.udev_list_entry_get_name$MH,"udev_list_entry_get_name");
+ }
+ public static MemoryAddress udev_list_entry_get_name ( Addressable list_entry) {
+ var mh$ = udev_list_entry_get_name$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact(list_entry);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle udev_device_unref$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.udev_device_unref$MH,"udev_device_unref");
+ }
+ public static MemoryAddress udev_device_unref ( Addressable udev_device) {
+ var mh$ = udev_device_unref$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact(udev_device);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle udev_device_new_from_syspath$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.udev_device_new_from_syspath$MH,"udev_device_new_from_syspath");
+ }
+ public static MemoryAddress udev_device_new_from_syspath ( Addressable udev, Addressable syspath) {
+ var mh$ = udev_device_new_from_syspath$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact(udev, syspath);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle udev_device_get_devnode$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.udev_device_get_devnode$MH,"udev_device_get_devnode");
+ }
+ public static MemoryAddress udev_device_get_devnode ( Addressable udev_device) {
+ var mh$ = udev_device_get_devnode$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact(udev_device);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle udev_device_get_sysattr_value$MH() {
+ return RuntimeHelper.requireNonNull(constants$1.udev_device_get_sysattr_value$MH,"udev_device_get_sysattr_value");
+ }
+ public static MemoryAddress udev_device_get_sysattr_value ( Addressable udev_device, Addressable sysattr) {
+ var mh$ = udev_device_get_sysattr_value$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact(udev_device, sysattr);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle udev_enumerate_unref$MH() {
+ return RuntimeHelper.requireNonNull(constants$1.udev_enumerate_unref$MH,"udev_enumerate_unref");
+ }
+ public static MemoryAddress udev_enumerate_unref ( Addressable udev_enumerate) {
+ var mh$ = udev_enumerate_unref$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact(udev_enumerate);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle udev_enumerate_new$MH() {
+ return RuntimeHelper.requireNonNull(constants$1.udev_enumerate_new$MH,"udev_enumerate_new");
+ }
+ public static MemoryAddress udev_enumerate_new ( Addressable udev) {
+ var mh$ = udev_enumerate_new$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact(udev);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle udev_enumerate_add_match_subsystem$MH() {
+ return RuntimeHelper.requireNonNull(constants$1.udev_enumerate_add_match_subsystem$MH,"udev_enumerate_add_match_subsystem");
+ }
+ public static int udev_enumerate_add_match_subsystem ( Addressable udev_enumerate, Addressable subsystem) {
+ var mh$ = udev_enumerate_add_match_subsystem$MH();
+ try {
+ return (int)mh$.invokeExact(udev_enumerate, subsystem);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle udev_enumerate_scan_devices$MH() {
+ return RuntimeHelper.requireNonNull(constants$1.udev_enumerate_scan_devices$MH,"udev_enumerate_scan_devices");
+ }
+ public static int udev_enumerate_scan_devices ( Addressable udev_enumerate) {
+ var mh$ = udev_enumerate_scan_devices$MH();
+ try {
+ return (int)mh$.invokeExact(udev_enumerate);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle udev_enumerate_get_list_entry$MH() {
+ return RuntimeHelper.requireNonNull(constants$1.udev_enumerate_get_list_entry$MH,"udev_enumerate_get_list_entry");
+ }
+ public static MemoryAddress udev_enumerate_get_list_entry ( Addressable udev_enumerate) {
+ var mh$ = udev_enumerate_get_list_entry$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact(udev_enumerate);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+}
+
+
From 7cf90aea493d4506a00193cc034c70e5a1c8211c Mon Sep 17 00:00:00 2001
From: Manuel Bl
Date: Mon, 29 Aug 2022 23:26:44 +0200
Subject: [PATCH 022/433] Linux: USB device monitoring
---
java-does-usb/jextract/gen_linux.sh | 16 ++
.../usb/common/USBDeviceInfoImpl.java | 4 +
.../usb/common/USBDeviceRegistry.java | 48 ++++
.../usb/linux/LinuxUSBDeviceInfo.java | 4 +
.../usb/linux/LinuxUSBDeviceRegistry.java | 181 ++++++++++++---
.../usb/linux/gen/select/Constants$root.java | 19 ++
.../usb/linux/gen/select/RuntimeHelper.java | 216 ++++++++++++++++++
.../usb/linux/gen/select/constants$0.java | 22 ++
.../usb/linux/gen/select/select.java | 36 +++
.../usb/linux/gen/udev/constants$0.java | 8 +-
.../usb/linux/gen/udev/constants$1.java | 50 ++--
.../usb/linux/gen/udev/constants$2.java | 56 +++++
.../usb/linux/gen/udev/constants$3.java | 18 ++
.../codecrete/usb/linux/gen/udev/udev.java | 89 +++++++-
.../usb/windows/WindowsUSBDeviceInfo.java | 4 -
.../usb/windows/WindowsUSBDeviceRegistry.java | 44 +---
16 files changed, 715 insertions(+), 100 deletions(-)
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/select/Constants$root.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/select/RuntimeHelper.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/select/constants$0.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/select/select.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$2.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$3.java
diff --git a/java-does-usb/jextract/gen_linux.sh b/java-does-usb/jextract/gen_linux.sh
index c85990cd..55d983ba 100755
--- a/java-does-usb/jextract/gen_linux.sh
+++ b/java-does-usb/jextract/gen_linux.sh
@@ -5,6 +5,7 @@ JEXTRACT=../../../jextract/build/jextract/bin/jextract
# sd-device.h (install libsystemd-dev if file is missing)
# Error: /usr/include/inttypes.h:290:8: error: unknown type name 'intmax_t'
#$JEXTRACT --source --output ../src/main/java \
+#$JEXTRACT --source --output ../src/main/java \
# --header-class-name sd_device \
# --target-package net.codecrete.usb.linux.gen.sd-device
# /usr/include/systemd/sd-device.h
@@ -69,4 +70,19 @@ $JEXTRACT --source --output ../src/main/java \
--include-function udev_device_get_sysattr_value \
--include-function udev_device_unref \
--include-function udev_enumerate_unref \
+ --include-function udev_monitor_new_from_netlink \
+ --include-function udev_monitor_enable_receiving \
+ --include-function udev_monitor_filter_add_match_subsystem_devtype \
+ --include-function udev_monitor_receive_device \
+ --include-function udev_device_get_action \
+ --include-function udev_device_get_devtype \
+ --include-function udev_monitor_get_fd \
/usr/include/libudev.h
+
+# select.h
+$JEXTRACT --source --output ../src/main/java \
+ --header-class-name select \
+ --target-package net.codecrete.usb.linux.gen.select \
+ --include-function select \
+ --include-macro FD_SETSIZE \
+ /usr/include/x86_64-linux-gnu/sys/select.h
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceInfoImpl.java b/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceInfoImpl.java
index 21f34bc0..1d95882b 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceInfoImpl.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceInfoImpl.java
@@ -87,6 +87,10 @@ public int getProtocolCode() {
return protocolCode;
}
+ public Object getUniqueId() {
+ return id;
+ }
+
@Override
public boolean isSameDevice(USBDeviceInfo device) {
if (device instanceof USBDeviceInfoImpl)
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceRegistry.java
index e80ada9a..e7a113ee 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceRegistry.java
@@ -9,6 +9,7 @@
import net.codecrete.usb.USBDeviceInfo;
+import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
@@ -78,4 +79,51 @@ protected void signalEnumerationComplete() {
lock.unlock();
}
}
+
+ protected void addDevice(USBDeviceInfo device) {
+ // check for duplicates
+ if (findDeviceIndex(devices, ((USBDeviceInfoImpl)device).getUniqueId()) >= 0)
+ return;
+
+ // copy list
+ var newDeviceList = new ArrayList(devices.size() + 1);
+ newDeviceList.addAll(devices);
+ newDeviceList.add(device);
+ devices = newDeviceList;
+
+ // send notification
+ emitOnDeviceConnected(device);
+ }
+
+ protected void removeDevice(String deviceId) {
+ // locate device to be removed
+ int index = findDeviceIndex(devices, deviceId);
+ if (index < 0)
+ return; // strange
+
+ // copy list and remove device
+ var deviceInfo = devices.get(index);
+ var newDeviceList = new ArrayList<>(devices);
+ newDeviceList.remove(index);
+ devices = newDeviceList;
+
+ // send notification
+ emitOnDeviceDisconnected(deviceInfo);
+ }
+
+
+ /**
+ * Finds the index of the device with the given ID in the device list
+ * @param deviceList the device list
+ * @param deviceId the unique device ID
+ * @return return the index, or -1 if the device is not found
+ */
+ protected int findDeviceIndex(List deviceList, Object deviceId) {
+ for (int i = 0; i < deviceList.size(); i++) {
+ var dev = (USBDeviceInfoImpl) deviceList.get(i);
+ if (deviceId.equals(dev.getUniqueId()))
+ return i;
+ }
+ return -1;
+ }
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceInfo.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceInfo.java
index 1d8c3d22..45f9fd75 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceInfo.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceInfo.java
@@ -26,4 +26,8 @@ public class LinuxUSBDeviceInfo extends USBDeviceInfoImpl {
public USBDevice open() {
return new LinuxUSBDevice(id, this);
}
+
+ Object devicePath() {
+ return id;
+ }
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceRegistry.java
index 509359f6..ed739607 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceRegistry.java
@@ -8,16 +8,21 @@
package net.codecrete.usb.linux;
import net.codecrete.usb.USBDeviceInfo;
+import net.codecrete.usb.USBException;
import net.codecrete.usb.common.USBDeviceRegistry;
+import net.codecrete.usb.linux.gen.select.select;
import net.codecrete.usb.linux.gen.udev.udev;
import java.lang.foreign.Addressable;
+import java.lang.foreign.MemoryAddress;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.MemorySession;
+import java.lang.invoke.MethodHandle;
import java.util.ArrayList;
import java.util.List;
import static java.lang.foreign.MemoryAddress.NULL;
+import static java.lang.foreign.ValueLayout.JAVA_LONG;
/**
* Linux implementation of USB device registry.
@@ -34,12 +39,14 @@
public class LinuxUSBDeviceRegistry extends USBDeviceRegistry {
private static final MemorySegment SUBSYSTEM_USB = MemorySession.global().allocateUtf8String("usb");
+ private static final MemorySegment MONITOR_NAME = MemorySession.global().allocateUtf8String("udev");
+ private static final MemorySegment DEVTYPE_USB_DEVICE = MemorySession.global().allocateUtf8String("usb_device");
/**
* Creates a new instance.
*/
public LinuxUSBDeviceRegistry() {
- enumeratePresentDevices();
+ startDeviceMonitor(this::monitorDevices);
}
@Override
@@ -47,17 +54,22 @@ public List getAllDevices() {
return devices;
}
- private void enumeratePresentDevices() {
+ private void enumeratePresentDevices(Addressable udevInstance) {
List result = new ArrayList<>();
try (var outerSession = MemorySession.openConfined()) {
- var udevInstance = udev.udev_new();
-
// create device enumerator
var enumerate = udev.udev_enumerate_new(udevInstance);
+ if (enumerate == NULL)
+ throw new USBException("internal error (udev_enumerate_new)");
+
outerSession.addCloseAction(() -> udev.udev_enumerate_unref(enumerate));
- udev.udev_enumerate_add_match_subsystem(enumerate, SUBSYSTEM_USB);
- udev.udev_enumerate_scan_devices(enumerate);
+
+ if (udev.udev_enumerate_add_match_subsystem(enumerate, SUBSYSTEM_USB) < 0)
+ throw new USBException("internal error (udev_enumerate_add_match_subsystem)");
+
+ if (udev.udev_enumerate_scan_devices(enumerate) < 0)
+ throw new USBException("internal error (udev_enumerate_scan_devices)");
// enumerate devices
for (var entry= udev.udev_enumerate_get_list_entry(enumerate);
@@ -75,36 +87,125 @@ private void enumeratePresentDevices() {
if (dev == NULL)
continue;
+ // ensure the device is released
session.addCloseAction(() -> udev.udev_device_unref(dev));
- // retrieve device attributes
- String idVendor = getDeviceAttribute(dev, "idVendor");
- if (idVendor == null)
- continue;
+ // get device details
+ var deviceInfo = getDeviceDetails(dev);
+ if (deviceInfo != null)
+ result.add(deviceInfo);
+ }
+ }
+ }
- String idProduct = getDeviceAttribute(dev, "idProduct");
- if (idProduct == null)
- continue;
+ devices = result;
+ }
- // get device path
- var devPath = getDeviceName(dev);
- if (devPath == null)
- continue;
+ private void monitorDevices() {
+
+ // setup udev monitor
+ var udevInstance = udev.udev_new();
+ if (udevInstance == NULL)
+ throw new USBException("internal error (udev_new)");
- int vendorId = Integer.parseInt(idVendor, 16);
- int productId = Integer.parseInt(idProduct, 16);
+ var monitor = udev.udev_monitor_new_from_netlink(udevInstance, MONITOR_NAME);
+ if (monitor == NULL)
+ throw new USBException("internal error (udev_monitor_new_from_netlink)");
- // add device to result list
- result.add(new LinuxUSBDeviceInfo(devPath, vendorId, productId,
- getDeviceAttribute(dev, "manufacturer"),
- getDeviceAttribute(dev, "product"),
- getDeviceAttribute(dev, "serial"),
- 0, 0, 0));
+ if (udev.udev_monitor_filter_add_match_subsystem_devtype(monitor, SUBSYSTEM_USB, DEVTYPE_USB_DEVICE) < 0)
+ throw new USBException("internal error (udev_monitor_filter_add_match_subsystem_devtype)");
+
+ if (udev.udev_monitor_enable_receiving(monitor) < 0)
+ throw new USBException("internal error (udev_monitor_enable_receiving)");
+
+ int fd = udev.udev_monitor_get_fd(monitor);
+ if (fd < 0)
+ throw new USBException("internal error (udev_monitor_get_fd)");
+
+ // create initial list of devices
+ enumeratePresentDevices(udevInstance);
+
+ // signal initial enumeration is complete
+ signalEnumerationComplete();
+
+ // monitor device changes
+ while (true) {
+ try (var session = MemorySession.openConfined()) {
+
+ // wait for next change
+ waitForFileDescriptor(fd, session);
+
+ // retrieve change
+ var dev = udev.udev_monitor_receive_device(monitor);
+ if (dev == null)
+ continue; // shouldn't happen
+
+ session.addCloseAction(() -> udev.udev_device_unref(dev));
+
+ // get details
+ var action = getDeviceAction(dev);
+
+ if ("add".equals(action)) {
+ onDeviceConnected(dev);
+ } else if ("remove".equals(action)) {
+ onDeviceDisconnected(dev);
}
}
}
+ }
- devices = result;
+ private void onDeviceConnected(MemoryAddress device) {
+
+ var deviceInfo = getDeviceDetails(device);
+ if (deviceInfo == null)
+ return;
+
+ addDevice(deviceInfo);
+ }
+
+ private void onDeviceDisconnected(MemoryAddress device) {
+
+ var devPath = getDeviceName(device);
+ if (devPath == null)
+ return;
+
+ removeDevice(devPath);
+ }
+
+ /**
+ * Retrieves the device details and returns a {@code USBDeviceInfo} instance.
+ *
+ * If the device is missing one of vendor ID, product ID or device path,
+ * {@code null} is returned.
+ *
+ * @param device the device
+ * @return the device info
+ */
+ private static USBDeviceInfo getDeviceDetails(MemoryAddress device) {
+
+ // retrieve device attributes
+ String idVendor = getDeviceAttribute(device, "idVendor");
+ if (idVendor == null)
+ return null;
+
+ String idProduct = getDeviceAttribute(device, "idProduct");
+ if (idProduct == null)
+ return null;
+
+ // get device path
+ var devPath = getDeviceName(device);
+ if (devPath == null)
+ return null;
+
+ int vendorId = Integer.parseInt(idVendor, 16);
+ int productId = Integer.parseInt(idProduct, 16);
+
+ // create device info instance
+ return new LinuxUSBDeviceInfo(devPath, vendorId, productId,
+ getDeviceAttribute(device, "manufacturer"),
+ getDeviceAttribute(device, "product"),
+ getDeviceAttribute(device, "serial"),
+ 0, 0, 0);
}
private static String getDeviceAttribute(Addressable device, String attribute) {
@@ -120,13 +221,39 @@ private static String getDeviceAttribute(Addressable device, String attribute) {
}
private static String getDeviceName(Addressable device) {
+ return callStringFunction(device, udev.udev_device_get_devnode$MH());
+ }
+
+ private static String getDeviceAction(Addressable device) {
+ return callStringFunction(device, udev.udev_device_get_action$MH());
+ }
+
+ private static String callStringFunction(Addressable device, MethodHandle function) {
try (var session = MemorySession.openConfined()) {
- var devNameAddr = udev.udev_device_get_devnode(device);
+ var devNameAddr = (MemoryAddress) function.invokeExact(device);
if (devNameAddr == NULL)
return null;
var ret = MemorySegment.ofAddress(devNameAddr, 2000, session);
return ret.getUtf8String(0);
+
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
}
}
+
+ /**
+ * Waits until the specified file descriptor becomes ready for reading.
+ * @param fd the file descriptor
+ * @param session a memory session for allocating memory
+ */
+ private static void waitForFileDescriptor(int fd, MemorySession session) {
+ // fd_set is a bit array with a capacity of FD_SETSIZE bits
+ var fds = session.allocate(JAVA_LONG, select.FD_SETSIZE() / JAVA_LONG.bitSize());
+ fds.set(JAVA_LONG, fd / JAVA_LONG.bitSize(), 1L << (fd % JAVA_LONG.bitSize()));
+
+ int res = select.select(fd + 1, fds, NULL, NULL, NULL);
+ if (res <= 0)
+ throw new USBException("internal error (select)");
+ }
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/select/Constants$root.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/select/Constants$root.java
new file mode 100644
index 00000000..bd53659c
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/select/Constants$root.java
@@ -0,0 +1,19 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.select;
+
+import static java.lang.foreign.ValueLayout.*;
+public class Constants$root {
+
+ static final OfBoolean C_BOOL$LAYOUT = JAVA_BOOLEAN;
+ static final OfByte C_CHAR$LAYOUT = JAVA_BYTE;
+ static final OfShort C_SHORT$LAYOUT = JAVA_SHORT.withBitAlignment(16);
+ static final OfInt C_INT$LAYOUT = JAVA_INT.withBitAlignment(32);
+ static final OfLong C_LONG$LAYOUT = JAVA_LONG.withBitAlignment(64);
+ static final OfLong C_LONG_LONG$LAYOUT = JAVA_LONG.withBitAlignment(64);
+ static final OfFloat C_FLOAT$LAYOUT = JAVA_FLOAT.withBitAlignment(32);
+ static final OfDouble C_DOUBLE$LAYOUT = JAVA_DOUBLE.withBitAlignment(64);
+ static final OfAddress C_POINTER$LAYOUT = ADDRESS.withBitAlignment(64);
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/select/RuntimeHelper.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/select/RuntimeHelper.java
new file mode 100644
index 00000000..a634735c
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/select/RuntimeHelper.java
@@ -0,0 +1,216 @@
+package net.codecrete.usb.linux.gen.select;
+// Generated by jextract
+
+import java.lang.foreign.*;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+
+import static java.lang.foreign.ValueLayout.*;
+
+final class RuntimeHelper {
+
+ private RuntimeHelper() {}
+ private final static Linker LINKER = Linker.nativeLinker();
+ private final static ClassLoader LOADER = RuntimeHelper.class.getClassLoader();
+ private final static MethodHandles.Lookup MH_LOOKUP = MethodHandles.lookup();
+ private final static SymbolLookup SYMBOL_LOOKUP;
+
+ final static SegmentAllocator CONSTANT_ALLOCATOR =
+ (size, align) -> MemorySegment.allocateNative(size, align, MemorySession.openImplicit());
+
+ static {
+
+ SymbolLookup loaderLookup = SymbolLookup.loaderLookup();
+ SYMBOL_LOOKUP = name -> loaderLookup.lookup(name).or(() -> LINKER.defaultLookup().lookup(name));
+ }
+
+ static T requireNonNull(T obj, String symbolName) {
+ if (obj == null) {
+ throw new UnsatisfiedLinkError("unresolved symbol: " + symbolName);
+ }
+ return obj;
+ }
+
+ private final static SegmentAllocator THROWING_ALLOCATOR = (x, y) -> { throw new AssertionError("should not reach here"); };
+
+ static final MemorySegment lookupGlobalVariable(String name, MemoryLayout layout) {
+ return SYMBOL_LOOKUP.lookup(name).map(symbol -> MemorySegment.ofAddress(symbol.address(), layout.byteSize(), MemorySession.openShared())).orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> LINKER.downcallHandle(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MethodHandle downcallHandle(FunctionDescriptor fdesc) {
+ return LINKER.downcallHandle(fdesc);
+ }
+
+ static final MethodHandle downcallHandleVariadic(String name, FunctionDescriptor fdesc) {
+ return SYMBOL_LOOKUP.lookup(name).
+ map(addr -> VarargsInvoker.make(addr, fdesc)).
+ orElse(null);
+ }
+
+ static final MemorySegment upcallStub(Class fi, Z z, FunctionDescriptor fdesc, MemorySession session) {
+ try {
+ MethodHandle handle = MH_LOOKUP.findVirtual(fi, "apply", Linker.upcallType(fdesc));
+ handle = handle.bindTo(z);
+ return LINKER.upcallStub(handle, fdesc, session);
+ } catch (Throwable ex) {
+ throw new AssertionError(ex);
+ }
+ }
+
+ static MemorySegment asArray(MemoryAddress addr, MemoryLayout layout, int numElements, MemorySession session) {
+ return MemorySegment.ofAddress(addr, numElements * layout.byteSize(), session);
+ }
+
+ // Internals only below this point
+
+ private static class VarargsInvoker {
+ private static final MethodHandle INVOKE_MH;
+ private final MemorySegment symbol;
+ private final FunctionDescriptor function;
+
+ private VarargsInvoker(MemorySegment symbol, FunctionDescriptor function) {
+ this.symbol = symbol;
+ this.function = function;
+ }
+
+ static {
+ try {
+ INVOKE_MH = MethodHandles.lookup().findVirtual(VarargsInvoker.class, "invoke", MethodType.methodType(Object.class, SegmentAllocator.class, Object[].class));
+ } catch (ReflectiveOperationException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ static MethodHandle make(MemorySegment symbol, FunctionDescriptor function) {
+ VarargsInvoker invoker = new VarargsInvoker(symbol, function);
+ MethodHandle handle = INVOKE_MH.bindTo(invoker).asCollector(Object[].class, function.argumentLayouts().size() + 1);
+ MethodType mtype = MethodType.methodType(function.returnLayout().isPresent() ? carrier(function.returnLayout().get(), true) : void.class);
+ for (MemoryLayout layout : function.argumentLayouts()) {
+ mtype = mtype.appendParameterTypes(carrier(layout, false));
+ }
+ mtype = mtype.appendParameterTypes(Object[].class);
+ if (mtype.returnType().equals(MemorySegment.class)) {
+ mtype = mtype.insertParameterTypes(0, SegmentAllocator.class);
+ } else {
+ handle = MethodHandles.insertArguments(handle, 0, THROWING_ALLOCATOR);
+ }
+ return handle.asType(mtype);
+ }
+
+ static Class> carrier(MemoryLayout layout, boolean ret) {
+ if (layout instanceof ValueLayout valueLayout) {
+ return (ret || valueLayout.carrier() != MemoryAddress.class) ?
+ valueLayout.carrier() : Addressable.class;
+ } else if (layout instanceof GroupLayout) {
+ return MemorySegment.class;
+ } else {
+ throw new AssertionError("Cannot get here!");
+ }
+ }
+
+ private Object invoke(SegmentAllocator allocator, Object[] args) throws Throwable {
+ // one trailing Object[]
+ int nNamedArgs = function.argumentLayouts().size();
+ assert(args.length == nNamedArgs + 1);
+ // The last argument is the array of vararg collector
+ Object[] unnamedArgs = (Object[]) args[args.length - 1];
+
+ int argsCount = nNamedArgs + unnamedArgs.length;
+ Class>[] argTypes = new Class>[argsCount];
+ MemoryLayout[] argLayouts = new MemoryLayout[nNamedArgs + unnamedArgs.length];
+
+ int pos = 0;
+ for (pos = 0; pos < nNamedArgs; pos++) {
+ argLayouts[pos] = function.argumentLayouts().get(pos);
+ }
+
+ assert pos == nNamedArgs;
+ for (Object o: unnamedArgs) {
+ argLayouts[pos] = variadicLayout(normalize(o.getClass()));
+ pos++;
+ }
+ assert pos == argsCount;
+
+ FunctionDescriptor f = (function.returnLayout().isEmpty()) ?
+ FunctionDescriptor.ofVoid(argLayouts) :
+ FunctionDescriptor.of(function.returnLayout().get(), argLayouts);
+ MethodHandle mh = LINKER.downcallHandle(symbol, f);
+ if (mh.type().returnType() == MemorySegment.class) {
+ mh = mh.bindTo(allocator);
+ }
+ // flatten argument list so that it can be passed to an asSpreader MH
+ Object[] allArgs = new Object[nNamedArgs + unnamedArgs.length];
+ System.arraycopy(args, 0, allArgs, 0, nNamedArgs);
+ System.arraycopy(unnamedArgs, 0, allArgs, nNamedArgs, unnamedArgs.length);
+
+ return mh.asSpreader(Object[].class, argsCount).invoke(allArgs);
+ }
+
+ private static Class> unboxIfNeeded(Class> clazz) {
+ if (clazz == Boolean.class) {
+ return boolean.class;
+ } else if (clazz == Void.class) {
+ return void.class;
+ } else if (clazz == Byte.class) {
+ return byte.class;
+ } else if (clazz == Character.class) {
+ return char.class;
+ } else if (clazz == Short.class) {
+ return short.class;
+ } else if (clazz == Integer.class) {
+ return int.class;
+ } else if (clazz == Long.class) {
+ return long.class;
+ } else if (clazz == Float.class) {
+ return float.class;
+ } else if (clazz == Double.class) {
+ return double.class;
+ } else {
+ return clazz;
+ }
+ }
+
+ private Class> promote(Class> c) {
+ if (c == byte.class || c == char.class || c == short.class || c == int.class) {
+ return long.class;
+ } else if (c == float.class) {
+ return double.class;
+ } else {
+ return c;
+ }
+ }
+
+ private Class> normalize(Class> c) {
+ c = unboxIfNeeded(c);
+ if (c.isPrimitive()) {
+ return promote(c);
+ }
+ if (MemoryAddress.class.isAssignableFrom(c)) {
+ return MemoryAddress.class;
+ }
+ if (MemorySegment.class.isAssignableFrom(c)) {
+ return MemorySegment.class;
+ }
+ throw new IllegalArgumentException("Invalid type for ABI: " + c.getTypeName());
+ }
+
+ private MemoryLayout variadicLayout(Class> c) {
+ if (c == long.class) {
+ return JAVA_LONG;
+ } else if (c == double.class) {
+ return JAVA_DOUBLE;
+ } else if (MemoryAddress.class.isAssignableFrom(c)) {
+ return ADDRESS;
+ } else {
+ throw new IllegalArgumentException("Unhandled variadic argument class: " + c);
+ }
+ }
+ }
+}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/select/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/select/constants$0.java
new file mode 100644
index 00000000..1e095f2b
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/select/constants$0.java
@@ -0,0 +1,22 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.select;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$0 {
+
+ static final FunctionDescriptor select$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle select$MH = RuntimeHelper.downcallHandle(
+ "select",
+ constants$0.select$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/select/select.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/select/select.java
new file mode 100644
index 00000000..85d6f09d
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/select/select.java
@@ -0,0 +1,36 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.select;
+
+import java.lang.foreign.Addressable;
+import java.lang.invoke.MethodHandle;
+
+import static java.lang.foreign.ValueLayout.*;
+public class select {
+
+ /* package-private */ select() {}
+ public static OfByte C_CHAR = Constants$root.C_CHAR$LAYOUT;
+ public static OfShort C_SHORT = Constants$root.C_SHORT$LAYOUT;
+ public static OfInt C_INT = Constants$root.C_INT$LAYOUT;
+ public static OfLong C_LONG = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfLong C_LONG_LONG = Constants$root.C_LONG_LONG$LAYOUT;
+ public static OfFloat C_FLOAT = Constants$root.C_FLOAT$LAYOUT;
+ public static OfDouble C_DOUBLE = Constants$root.C_DOUBLE$LAYOUT;
+ public static OfAddress C_POINTER = Constants$root.C_POINTER$LAYOUT;
+ public static MethodHandle select$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.select$MH,"select");
+ }
+ public static int select ( int __nfds, Addressable __readfds, Addressable __writefds, Addressable __exceptfds, Addressable __timeout) {
+ var mh$ = select$MH();
+ try {
+ return (int)mh$.invokeExact(__nfds, __readfds, __writefds, __exceptfds, __timeout);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static int FD_SETSIZE() {
+ return (int)1024L;
+ }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$0.java
index a6258650..962ea187 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$0.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$0.java
@@ -40,12 +40,12 @@ class constants$0 {
"udev_device_new_from_syspath",
constants$0.udev_device_new_from_syspath$FUNC
);
- static final FunctionDescriptor udev_device_get_devnode$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ static final FunctionDescriptor udev_device_get_devtype$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
Constants$root.C_POINTER$LAYOUT
);
- static final MethodHandle udev_device_get_devnode$MH = RuntimeHelper.downcallHandle(
- "udev_device_get_devnode",
- constants$0.udev_device_get_devnode$FUNC
+ static final MethodHandle udev_device_get_devtype$MH = RuntimeHelper.downcallHandle(
+ "udev_device_get_devtype",
+ constants$0.udev_device_get_devtype$FUNC
);
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$1.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$1.java
index 9340bd78..986a90d3 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$1.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$1.java
@@ -6,49 +6,49 @@
import java.lang.invoke.MethodHandle;
class constants$1 {
- static final FunctionDescriptor udev_device_get_sysattr_value$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_POINTER$LAYOUT,
+ static final FunctionDescriptor udev_device_get_devnode$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
Constants$root.C_POINTER$LAYOUT
);
- static final MethodHandle udev_device_get_sysattr_value$MH = RuntimeHelper.downcallHandle(
- "udev_device_get_sysattr_value",
- constants$1.udev_device_get_sysattr_value$FUNC
+ static final MethodHandle udev_device_get_devnode$MH = RuntimeHelper.downcallHandle(
+ "udev_device_get_devnode",
+ constants$1.udev_device_get_devnode$FUNC
);
- static final FunctionDescriptor udev_enumerate_unref$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ static final FunctionDescriptor udev_device_get_action$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
Constants$root.C_POINTER$LAYOUT
);
- static final MethodHandle udev_enumerate_unref$MH = RuntimeHelper.downcallHandle(
- "udev_enumerate_unref",
- constants$1.udev_enumerate_unref$FUNC
+ static final MethodHandle udev_device_get_action$MH = RuntimeHelper.downcallHandle(
+ "udev_device_get_action",
+ constants$1.udev_device_get_action$FUNC
);
- static final FunctionDescriptor udev_enumerate_new$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ static final FunctionDescriptor udev_device_get_sysattr_value$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
Constants$root.C_POINTER$LAYOUT
);
- static final MethodHandle udev_enumerate_new$MH = RuntimeHelper.downcallHandle(
- "udev_enumerate_new",
- constants$1.udev_enumerate_new$FUNC
+ static final MethodHandle udev_device_get_sysattr_value$MH = RuntimeHelper.downcallHandle(
+ "udev_device_get_sysattr_value",
+ constants$1.udev_device_get_sysattr_value$FUNC
);
- static final FunctionDescriptor udev_enumerate_add_match_subsystem$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ static final FunctionDescriptor udev_monitor_new_from_netlink$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
Constants$root.C_POINTER$LAYOUT,
Constants$root.C_POINTER$LAYOUT
);
- static final MethodHandle udev_enumerate_add_match_subsystem$MH = RuntimeHelper.downcallHandle(
- "udev_enumerate_add_match_subsystem",
- constants$1.udev_enumerate_add_match_subsystem$FUNC
+ static final MethodHandle udev_monitor_new_from_netlink$MH = RuntimeHelper.downcallHandle(
+ "udev_monitor_new_from_netlink",
+ constants$1.udev_monitor_new_from_netlink$FUNC
);
- static final FunctionDescriptor udev_enumerate_scan_devices$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ static final FunctionDescriptor udev_monitor_enable_receiving$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
Constants$root.C_POINTER$LAYOUT
);
- static final MethodHandle udev_enumerate_scan_devices$MH = RuntimeHelper.downcallHandle(
- "udev_enumerate_scan_devices",
- constants$1.udev_enumerate_scan_devices$FUNC
+ static final MethodHandle udev_monitor_enable_receiving$MH = RuntimeHelper.downcallHandle(
+ "udev_monitor_enable_receiving",
+ constants$1.udev_monitor_enable_receiving$FUNC
);
- static final FunctionDescriptor udev_enumerate_get_list_entry$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ static final FunctionDescriptor udev_monitor_get_fd$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
Constants$root.C_POINTER$LAYOUT
);
- static final MethodHandle udev_enumerate_get_list_entry$MH = RuntimeHelper.downcallHandle(
- "udev_enumerate_get_list_entry",
- constants$1.udev_enumerate_get_list_entry$FUNC
+ static final MethodHandle udev_monitor_get_fd$MH = RuntimeHelper.downcallHandle(
+ "udev_monitor_get_fd",
+ constants$1.udev_monitor_get_fd$FUNC
);
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$2.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$2.java
new file mode 100644
index 00000000..47b95ed6
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$2.java
@@ -0,0 +1,56 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.udev;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$2 {
+
+ static final FunctionDescriptor udev_monitor_receive_device$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle udev_monitor_receive_device$MH = RuntimeHelper.downcallHandle(
+ "udev_monitor_receive_device",
+ constants$2.udev_monitor_receive_device$FUNC
+ );
+ static final FunctionDescriptor udev_monitor_filter_add_match_subsystem_devtype$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle udev_monitor_filter_add_match_subsystem_devtype$MH = RuntimeHelper.downcallHandle(
+ "udev_monitor_filter_add_match_subsystem_devtype",
+ constants$2.udev_monitor_filter_add_match_subsystem_devtype$FUNC
+ );
+ static final FunctionDescriptor udev_enumerate_unref$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle udev_enumerate_unref$MH = RuntimeHelper.downcallHandle(
+ "udev_enumerate_unref",
+ constants$2.udev_enumerate_unref$FUNC
+ );
+ static final FunctionDescriptor udev_enumerate_new$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle udev_enumerate_new$MH = RuntimeHelper.downcallHandle(
+ "udev_enumerate_new",
+ constants$2.udev_enumerate_new$FUNC
+ );
+ static final FunctionDescriptor udev_enumerate_add_match_subsystem$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle udev_enumerate_add_match_subsystem$MH = RuntimeHelper.downcallHandle(
+ "udev_enumerate_add_match_subsystem",
+ constants$2.udev_enumerate_add_match_subsystem$FUNC
+ );
+ static final FunctionDescriptor udev_enumerate_scan_devices$FUNC = FunctionDescriptor.of(Constants$root.C_INT$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle udev_enumerate_scan_devices$MH = RuntimeHelper.downcallHandle(
+ "udev_enumerate_scan_devices",
+ constants$2.udev_enumerate_scan_devices$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$3.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$3.java
new file mode 100644
index 00000000..862a7270
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/constants$3.java
@@ -0,0 +1,18 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.udev;
+
+import java.lang.foreign.FunctionDescriptor;
+import java.lang.invoke.MethodHandle;
+class constants$3 {
+
+ static final FunctionDescriptor udev_enumerate_get_list_entry$FUNC = FunctionDescriptor.of(Constants$root.C_POINTER$LAYOUT,
+ Constants$root.C_POINTER$LAYOUT
+ );
+ static final MethodHandle udev_enumerate_get_list_entry$MH = RuntimeHelper.downcallHandle(
+ "udev_enumerate_get_list_entry",
+ constants$3.udev_enumerate_get_list_entry$FUNC
+ );
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/udev.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/udev.java
index 2b6bde54..ea5160ae 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/udev.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/udev/udev.java
@@ -73,8 +73,19 @@ public static MemoryAddress udev_device_new_from_syspath ( Addressable udev, Ad
throw new AssertionError("should not reach here", ex$);
}
}
+ public static MethodHandle udev_device_get_devtype$MH() {
+ return RuntimeHelper.requireNonNull(constants$0.udev_device_get_devtype$MH,"udev_device_get_devtype");
+ }
+ public static MemoryAddress udev_device_get_devtype ( Addressable udev_device) {
+ var mh$ = udev_device_get_devtype$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact(udev_device);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
public static MethodHandle udev_device_get_devnode$MH() {
- return RuntimeHelper.requireNonNull(constants$0.udev_device_get_devnode$MH,"udev_device_get_devnode");
+ return RuntimeHelper.requireNonNull(constants$1.udev_device_get_devnode$MH,"udev_device_get_devnode");
}
public static MemoryAddress udev_device_get_devnode ( Addressable udev_device) {
var mh$ = udev_device_get_devnode$MH();
@@ -84,6 +95,17 @@ public static MemoryAddress udev_device_get_devnode ( Addressable udev_device) {
throw new AssertionError("should not reach here", ex$);
}
}
+ public static MethodHandle udev_device_get_action$MH() {
+ return RuntimeHelper.requireNonNull(constants$1.udev_device_get_action$MH,"udev_device_get_action");
+ }
+ public static MemoryAddress udev_device_get_action ( Addressable udev_device) {
+ var mh$ = udev_device_get_action$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact(udev_device);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
public static MethodHandle udev_device_get_sysattr_value$MH() {
return RuntimeHelper.requireNonNull(constants$1.udev_device_get_sysattr_value$MH,"udev_device_get_sysattr_value");
}
@@ -95,8 +117,63 @@ public static MemoryAddress udev_device_get_sysattr_value ( Addressable udev_dev
throw new AssertionError("should not reach here", ex$);
}
}
+ public static MethodHandle udev_monitor_new_from_netlink$MH() {
+ return RuntimeHelper.requireNonNull(constants$1.udev_monitor_new_from_netlink$MH,"udev_monitor_new_from_netlink");
+ }
+ public static MemoryAddress udev_monitor_new_from_netlink ( Addressable udev, Addressable name) {
+ var mh$ = udev_monitor_new_from_netlink$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact(udev, name);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle udev_monitor_enable_receiving$MH() {
+ return RuntimeHelper.requireNonNull(constants$1.udev_monitor_enable_receiving$MH,"udev_monitor_enable_receiving");
+ }
+ public static int udev_monitor_enable_receiving ( Addressable udev_monitor) {
+ var mh$ = udev_monitor_enable_receiving$MH();
+ try {
+ return (int)mh$.invokeExact(udev_monitor);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle udev_monitor_get_fd$MH() {
+ return RuntimeHelper.requireNonNull(constants$1.udev_monitor_get_fd$MH,"udev_monitor_get_fd");
+ }
+ public static int udev_monitor_get_fd ( Addressable udev_monitor) {
+ var mh$ = udev_monitor_get_fd$MH();
+ try {
+ return (int)mh$.invokeExact(udev_monitor);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle udev_monitor_receive_device$MH() {
+ return RuntimeHelper.requireNonNull(constants$2.udev_monitor_receive_device$MH,"udev_monitor_receive_device");
+ }
+ public static MemoryAddress udev_monitor_receive_device ( Addressable udev_monitor) {
+ var mh$ = udev_monitor_receive_device$MH();
+ try {
+ return (java.lang.foreign.MemoryAddress)mh$.invokeExact(udev_monitor);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
+ public static MethodHandle udev_monitor_filter_add_match_subsystem_devtype$MH() {
+ return RuntimeHelper.requireNonNull(constants$2.udev_monitor_filter_add_match_subsystem_devtype$MH,"udev_monitor_filter_add_match_subsystem_devtype");
+ }
+ public static int udev_monitor_filter_add_match_subsystem_devtype ( Addressable udev_monitor, Addressable subsystem, Addressable devtype) {
+ var mh$ = udev_monitor_filter_add_match_subsystem_devtype$MH();
+ try {
+ return (int)mh$.invokeExact(udev_monitor, subsystem, devtype);
+ } catch (Throwable ex$) {
+ throw new AssertionError("should not reach here", ex$);
+ }
+ }
public static MethodHandle udev_enumerate_unref$MH() {
- return RuntimeHelper.requireNonNull(constants$1.udev_enumerate_unref$MH,"udev_enumerate_unref");
+ return RuntimeHelper.requireNonNull(constants$2.udev_enumerate_unref$MH,"udev_enumerate_unref");
}
public static MemoryAddress udev_enumerate_unref ( Addressable udev_enumerate) {
var mh$ = udev_enumerate_unref$MH();
@@ -107,7 +184,7 @@ public static MemoryAddress udev_enumerate_unref ( Addressable udev_enumerate) {
}
}
public static MethodHandle udev_enumerate_new$MH() {
- return RuntimeHelper.requireNonNull(constants$1.udev_enumerate_new$MH,"udev_enumerate_new");
+ return RuntimeHelper.requireNonNull(constants$2.udev_enumerate_new$MH,"udev_enumerate_new");
}
public static MemoryAddress udev_enumerate_new ( Addressable udev) {
var mh$ = udev_enumerate_new$MH();
@@ -118,7 +195,7 @@ public static MemoryAddress udev_enumerate_new ( Addressable udev) {
}
}
public static MethodHandle udev_enumerate_add_match_subsystem$MH() {
- return RuntimeHelper.requireNonNull(constants$1.udev_enumerate_add_match_subsystem$MH,"udev_enumerate_add_match_subsystem");
+ return RuntimeHelper.requireNonNull(constants$2.udev_enumerate_add_match_subsystem$MH,"udev_enumerate_add_match_subsystem");
}
public static int udev_enumerate_add_match_subsystem ( Addressable udev_enumerate, Addressable subsystem) {
var mh$ = udev_enumerate_add_match_subsystem$MH();
@@ -129,7 +206,7 @@ public static int udev_enumerate_add_match_subsystem ( Addressable udev_enumerat
}
}
public static MethodHandle udev_enumerate_scan_devices$MH() {
- return RuntimeHelper.requireNonNull(constants$1.udev_enumerate_scan_devices$MH,"udev_enumerate_scan_devices");
+ return RuntimeHelper.requireNonNull(constants$2.udev_enumerate_scan_devices$MH,"udev_enumerate_scan_devices");
}
public static int udev_enumerate_scan_devices ( Addressable udev_enumerate) {
var mh$ = udev_enumerate_scan_devices$MH();
@@ -140,7 +217,7 @@ public static int udev_enumerate_scan_devices ( Addressable udev_enumerate) {
}
}
public static MethodHandle udev_enumerate_get_list_entry$MH() {
- return RuntimeHelper.requireNonNull(constants$1.udev_enumerate_get_list_entry$MH,"udev_enumerate_get_list_entry");
+ return RuntimeHelper.requireNonNull(constants$3.udev_enumerate_get_list_entry$MH,"udev_enumerate_get_list_entry");
}
public static MemoryAddress udev_enumerate_get_list_entry ( Addressable udev_enumerate) {
var mh$ = udev_enumerate_get_list_entry$MH();
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceInfo.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceInfo.java
index b93ca796..b13b4420 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceInfo.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceInfo.java
@@ -26,10 +26,6 @@ public class WindowsUSBDeviceInfo extends USBDeviceInfoImpl {
this.currentConfigurationValue = currentConfigurationValue;
}
- String devicePath() {
- return (String) id;
- }
-
@Override
public USBDevice open() {
return new WindowsUSBDevice(id, this, currentConfigurationValue);
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
index c7d39cc0..c2a3d8d6 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
@@ -10,6 +10,7 @@
import net.codecrete.usb.USBDeviceInfo;
import net.codecrete.usb.USBException;
import net.codecrete.usb.common.USBDescriptors;
+import net.codecrete.usb.common.USBDeviceInfoImpl;
import net.codecrete.usb.common.USBDeviceRegistry;
import net.codecrete.usb.common.USBStructs;
import net.codecrete.usb.windows.gen.kernel32.Kernel32;
@@ -311,50 +312,25 @@ private void onDeviceConnected(String devicePath) {
final var hubHandles = new HashMap();
session.addCloseAction(() -> hubHandles.forEach((path, handle) -> Kernel32.CloseHandle(handle)));
- // check for duplicates
- if (findDeviceIndex(devices, devicePath) >= 0)
- return;
-
// create device info instance
var deviceInfo = createDeviceInfo(devInfoSetHandle, devInfo, devicePath, hubHandles);
- // copy list
- var newDeviceList = new ArrayList<>(devices);
- newDeviceList.add(deviceInfo);
- devices = newDeviceList;
-
- // send notification
- emitOnDeviceConnected(deviceInfo);
+ // add it to device list
+ addDevice(deviceInfo);
}
}
private void onDeviceDisconnected(String devicePath) {
-
- // locate device to be removed
- int index = findDeviceIndex(devices, devicePath);
- if (index < 0)
- return; // strange
-
- // copy list and remove device
- var deviceInfo = devices.get(index);
- var newDeviceList = new ArrayList<>(devices);
- newDeviceList.remove(index);
- devices = newDeviceList;
-
- // send notification
- emitOnDeviceDisconnected(deviceInfo);
+ // remove from device list
+ removeDevice(devicePath);
}
- /**
- * Finds the index of the device with the given path in the device list
- * @param deviceList the device list
- * @param devicePath the device path
- * @return return the index, or -1 if the device is not found
- */
- private static int findDeviceIndex(List deviceList, String devicePath) {
+ @Override
+ protected int findDeviceIndex(List deviceList, Object deviceId) {
+ var id = deviceId.toString();
for (int i = 0; i < deviceList.size(); i++) {
- var winInfo = (WindowsUSBDeviceInfo) deviceList.get(i);
- if (winInfo.devicePath().equalsIgnoreCase(devicePath))
+ var dev = (USBDeviceInfoImpl) deviceList.get(i);
+ if (id.equalsIgnoreCase(dev.getUniqueId().toString()))
return i;
}
return -1;
From 2ff6f478c9fd0ebb4e835868cb6d7922e99718c2 Mon Sep 17 00:00:00 2001
From: Manuel Bleichenbacher
Date: Mon, 29 Aug 2022 23:41:10 +0200
Subject: [PATCH 023/433] macOS: complete refactoring of common registry code
---
.../usb/common/USBDeviceRegistry.java | 3 +-
.../usb/macos/MacosUSBDeviceRegistry.java | 79 ++++++-------------
2 files changed, 24 insertions(+), 58 deletions(-)
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceRegistry.java
index e7a113ee..f5529efa 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceRegistry.java
@@ -95,7 +95,7 @@ protected void addDevice(USBDeviceInfo device) {
emitOnDeviceConnected(device);
}
- protected void removeDevice(String deviceId) {
+ protected void removeDevice(Object deviceId) {
// locate device to be removed
int index = findDeviceIndex(devices, deviceId);
if (index < 0)
@@ -111,7 +111,6 @@ protected void removeDevice(String deviceId) {
emitOnDeviceDisconnected(deviceInfo);
}
-
/**
* Finds the index of the device with the given ID in the device list
* @param deviceList the device list
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceRegistry.java
index 31f027a7..194ae049 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceRegistry.java
@@ -16,6 +16,7 @@
import java.lang.invoke.MethodType;
import java.util.ArrayList;
import java.util.List;
+import java.util.function.BiConsumer;
import static java.lang.foreign.MemoryAddress.NULL;
import static java.lang.foreign.ValueLayout.*;
@@ -44,15 +45,13 @@ public List getAllDevices() {
}
/**
- * Process the device iterator and return a list of devices ({@link USBDeviceInfo}).
+ * Process the devices resulting from the iterator
*
- * @param iterator iterator
+ * @param iterator the iterator
* @param isDisconnected flag is the iterator is for disconnected devices
- * @return list of devices
+ * @param function a function that will be called for each device with the entry ID and the service
*/
- private List iterateDevices(int iterator, boolean isDisconnected) {
-
- List result = new ArrayList<>();
+ private void iterateDevices(int iterator, boolean isDisconnected, BiConsumer function) {
int svc;
while ((svc = IoKit.IOIteratorNext(iterator)) != 0) {
@@ -76,17 +75,13 @@ private List iterateDevices(int iterator, boolean isDisconnected)
throw new MacosUSBException("IORegistryEntryGetRegistryEntryID failed", ret);
var entryId = entryIdHolder.get(JAVA_LONG, 0);
- var deviceInfo = createDeviceInfo(entryId, service);
-
- if (deviceInfo != null)
- result.add(deviceInfo);
+ // call function to process device
+ function.accept(entryId, service);
}
}
-
- return result;
}
- private USBDeviceInfo createDeviceInfo(long entryID, int service) {
+ private USBDeviceInfo createDeviceInfo(Long entryID, int service) {
Integer vendorId = IoKitHelper.GetPropertyInt(service, "idVendor");
Integer productId = IoKitHelper.GetPropertyInt(service, "idProduct");
@@ -126,8 +121,13 @@ private void monitorDevices() {
MethodType.methodType(void.class, MemoryAddress.class, int.class));
int deviceConnectedIter = setupNotification(session, notifyPort, IoKit.kIOFirstMatchNotification, onDeviceConnectedMH);
- // iterate current devices in order to arm the notifications
- devices = iterateDevices(deviceConnectedIter, false);
+ // iterate current devices in order to arm the notifications (and build initial device list)
+ devices = new ArrayList<>();
+ iterateDevices(deviceConnectedIter, false, (entryId, service) -> {
+ var deviceInfo = createDeviceInfo(entryId, service);
+ if (deviceInfo != null)
+ devices.add(deviceInfo);
+ });
// signal completion of initial device enumeration
signalEnumerationComplete();
@@ -182,16 +182,13 @@ private int setupNotification(MemorySession session, MemoryAddress notifyPort, M
* @param iterator device iterator
*/
private void onDevicesConnected(MemoryAddress ignoredRefCon, int iterator) {
- // retrieve device info for connected devices
- var connectedDevices = iterateDevices(iterator, false);
-
- // create new device list with connected devices
- var newDeviceList = new ArrayList<>(devices);
- newDeviceList.addAll(connectedDevices);
- devices = newDeviceList;
- // emit events
- connectedDevices.forEach(this::emitOnDeviceConnected);
+ // process device info for connected devices
+ iterateDevices(iterator, false, (entryId, service) -> {
+ var deviceInfo = createDeviceInfo(entryId, service);
+ if (deviceInfo != null)
+ addDevice(deviceInfo);
+ });
}
/**
@@ -203,38 +200,8 @@ private void onDevicesConnected(MemoryAddress ignoredRefCon, int iterator) {
* @param iterator device iterator
*/
private void onDevicesDisconnected(MemoryAddress ignoredRefCon, int iterator) {
- // retrieve device info for disconnected devices
- var disconnectedDevices = iterateDevices(iterator, true);
-
- // create new device list without the disconnected devices
- var newDeviceList = new ArrayList<>(devices);
- for (var device : disconnectedDevices) {
- int index = findDeviceIndex(newDeviceList, device);
- if (index >= 0)
- newDeviceList.remove(index);
- }
- devices = newDeviceList;
-
- // emit events
- disconnectedDevices.forEach(this::emitOnDeviceDisconnected);
- }
- /**
- * Find the index of the device in the device list.
- *
- * Devices are compared by their IO registry entry ID.
- *
- * @param deviceList the device list
- * @param device the device
- * @return the index of the device, or -1 if it is not found
- */
- private static int findDeviceIndex(List deviceList, USBDeviceInfo device) {
- Object id = ((MacosUSBDeviceInfo)device).getId();
- for (int i = 0; i < deviceList.size(); i++) {
- var macDevice = (MacosUSBDeviceInfo) deviceList.get(i);
- if (id.equals(macDevice.getId()))
- return i;
- }
- return -1;
+ // process device info for disconnected devices
+ iterateDevices(iterator, true, (entryId, service) -> removeDevice(entryId));
}
}
From d0f6f24a565b673406eb1e00c62ad5089c9baca2 Mon Sep 17 00:00:00 2001
From: Manuel Bleichenbacher
Date: Mon, 29 Aug 2022 23:46:24 +0200
Subject: [PATCH 024/433] README reflects additions and changes
---
README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 20b6879f..d5ecf010 100644
--- a/README.md
+++ b/README.md
@@ -52,12 +52,12 @@ MAVEN_OPTS="--enable-preview --enable-native-access=ALL-UNNAMED" mvn install exe
- Enumeration of USB devices
- Control transfer
- Bulk transfer
+- Notification about connected/disconnected devices
### To do
- Interrupt transfer
- Isochronous transfer
-- Notification about connected/disconnected devices
- Descriptive information about interfaces, settings and endpoints
- Alternate interface settings
- Composite devices (on Windows)
@@ -81,7 +81,7 @@ No special considerations apply. Using this library, a Java application can conn
### Linux
-*libsystemd* is used to discover USB devices. So it only runs on Linux distributions with systemd and the related library. The majority of Linux distributions suitable for desktop computing (as opposed to distributions optimized for containers) fulfills this.
+*libudev* is used to discover and monitor USB devices. The library is closely tied to *systemd*. So it only runs on Linux distributions with systemd and the related libraries. The majority of Linux distributions suitable for desktop computing (as opposed to distributions optimized for containers) fulfills this requriement.
Similar to macOS, a Java application can connect to any USB device and claim any interfaces that aren't claimed by an operating system driver or another application.
From d0816f98784ef2169951e2b5e786dfdc5fdea29f Mon Sep 17 00:00:00 2001
From: Manuel Bl
Date: Tue, 30 Aug 2022 20:27:26 +0200
Subject: [PATCH 025/433] Linux: minor cleanup
---
java-does-usb/jextract/gen_linux.sh | 2 +-
.../java/net/codecrete/usb/linux/Linux.java | 36 +++++++++++++++++++
.../usb/linux/LinuxUSBDeviceRegistry.java | 30 +++++-----------
.../usb/linux/gen/select/fd_set.java | 25 +++++++++++++
.../usb/linux/gen/select/select.java | 3 --
5 files changed, 71 insertions(+), 25 deletions(-)
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/Linux.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/gen/select/fd_set.java
diff --git a/java-does-usb/jextract/gen_linux.sh b/java-does-usb/jextract/gen_linux.sh
index 55d983ba..1417a44e 100755
--- a/java-does-usb/jextract/gen_linux.sh
+++ b/java-does-usb/jextract/gen_linux.sh
@@ -84,5 +84,5 @@ $JEXTRACT --source --output ../src/main/java \
--header-class-name select \
--target-package net.codecrete.usb.linux.gen.select \
--include-function select \
- --include-macro FD_SETSIZE \
+ --include-typedef fd_set \
/usr/include/x86_64-linux-gnu/sys/select.h
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/Linux.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/Linux.java
new file mode 100644
index 00000000..8d759c0e
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/Linux.java
@@ -0,0 +1,36 @@
+//
+// Java Does USB
+// Copyright (c) 2022 Manuel Bleichenbacher
+// Licensed under MIT License
+// https://opensource.org/licenses/MIT
+//
+
+package net.codecrete.usb.linux;
+
+import java.lang.foreign.MemoryAddress;
+import java.lang.foreign.MemorySegment;
+import java.lang.foreign.MemorySession;
+
+import static java.lang.foreign.MemoryAddress.NULL;
+
+/**
+ * Helper functions for Linux
+ */
+public class Linux {
+
+ /**
+ * Creates a Java string as a copy of the null-terminated UTF-8 string.
+ *
+ * @param str the memory address pointing to string
+ * @return the Java string, or {@code null} if the memory address is 0
+ */
+ public static String createStringFromAddress(MemoryAddress str) {
+ try (var session = MemorySession.openConfined()) {
+ if (str == NULL)
+ return null;
+
+ var ret = MemorySegment.ofAddress(str, 2000, session);
+ return ret.getUtf8String(0);
+ }
+ }
+}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceRegistry.java
index ed739607..d2826d07 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceRegistry.java
@@ -10,6 +10,7 @@
import net.codecrete.usb.USBDeviceInfo;
import net.codecrete.usb.USBException;
import net.codecrete.usb.common.USBDeviceRegistry;
+import net.codecrete.usb.linux.gen.select.fd_set;
import net.codecrete.usb.linux.gen.select.select;
import net.codecrete.usb.linux.gen.udev.udev;
@@ -17,7 +18,6 @@
import java.lang.foreign.MemoryAddress;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.MemorySession;
-import java.lang.invoke.MethodHandle;
import java.util.ArrayList;
import java.util.List;
@@ -72,7 +72,7 @@ private void enumeratePresentDevices(Addressable udevInstance) {
throw new USBException("internal error (udev_enumerate_scan_devices)");
// enumerate devices
- for (var entry= udev.udev_enumerate_get_list_entry(enumerate);
+ for (var entry = udev.udev_enumerate_get_list_entry(enumerate);
entry != NULL;
entry = udev.udev_list_entry_get_next(entry)) {
@@ -178,6 +178,7 @@ private void onDeviceDisconnected(MemoryAddress device) {
* If the device is missing one of vendor ID, product ID or device path,
* {@code null} is returned.
*
+ *
* @param device the device
* @return the device info
*/
@@ -221,35 +222,22 @@ private static String getDeviceAttribute(Addressable device, String attribute) {
}
private static String getDeviceName(Addressable device) {
- return callStringFunction(device, udev.udev_device_get_devnode$MH());
+ return Linux.createStringFromAddress(udev.udev_device_get_devnode(device));
}
private static String getDeviceAction(Addressable device) {
- return callStringFunction(device, udev.udev_device_get_action$MH());
- }
-
- private static String callStringFunction(Addressable device, MethodHandle function) {
- try (var session = MemorySession.openConfined()) {
- var devNameAddr = (MemoryAddress) function.invokeExact(device);
- if (devNameAddr == NULL)
- return null;
-
- var ret = MemorySegment.ofAddress(devNameAddr, 2000, session);
- return ret.getUtf8String(0);
-
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
+ return Linux.createStringFromAddress(udev.udev_device_get_action(device));
}
/**
* Waits until the specified file descriptor becomes ready for reading.
- * @param fd the file descriptor
+ *
+ * @param fd the file descriptor
* @param session a memory session for allocating memory
*/
private static void waitForFileDescriptor(int fd, MemorySession session) {
- // fd_set is a bit array with a capacity of FD_SETSIZE bits
- var fds = session.allocate(JAVA_LONG, select.FD_SETSIZE() / JAVA_LONG.bitSize());
+ // fd_set is a bit array (constructed from 64-bit integers)
+ var fds = session.allocate(fd_set.$LAYOUT());
fds.set(JAVA_LONG, fd / JAVA_LONG.bitSize(), 1L << (fd % JAVA_LONG.bitSize()));
int res = select.select(fd + 1, fds, NULL, NULL, NULL);
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/select/fd_set.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/select/fd_set.java
new file mode 100644
index 00000000..2a321b89
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/select/fd_set.java
@@ -0,0 +1,25 @@
+// Generated by jextract
+
+package net.codecrete.usb.linux.gen.select;
+
+import java.lang.foreign.*;
+public class fd_set {
+
+ static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
+ MemoryLayout.sequenceLayout(16, Constants$root.C_LONG_LONG$LAYOUT).withName("__fds_bits")
+ );
+ public static MemoryLayout $LAYOUT() {
+ return fd_set.$struct$LAYOUT;
+ }
+ public static MemorySegment __fds_bits$slice(MemorySegment seg) {
+ return seg.asSlice(0, 128);
+ }
+ public static long sizeof() { return $LAYOUT().byteSize(); }
+ public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
+ public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
+ return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
+ }
+ public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/select/select.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/select/select.java
index 85d6f09d..85ed94b2 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/select/select.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/gen/select/select.java
@@ -28,9 +28,6 @@ public static int select ( int __nfds, Addressable __readfds, Addressable __wr
throw new AssertionError("should not reach here", ex$);
}
}
- public static int FD_SETSIZE() {
- return (int)1024L;
- }
}
From 0e4125193e2a86e58d9cfc67577f9dcdb32417b0 Mon Sep 17 00:00:00 2001
From: Manuel Bl
Date: Wed, 31 Aug 2022 18:53:37 +0200
Subject: [PATCH 026/433] Document code generation
---
java-does-usb/jextract/README.md | 67 ++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
create mode 100644 java-does-usb/jextract/README.md
diff --git a/java-does-usb/jextract/README.md b/java-does-usb/jextract/README.md
new file mode 100644
index 00000000..82a12f04
--- /dev/null
+++ b/java-does-usb/jextract/README.md
@@ -0,0 +1,67 @@
+# Code Generation with *jextract*
+
+Some of the binding code for accessing native functions and data structures is generated with [jextract](https://jdk.java.net/jextract/). The tool is still under construction and has its limitations.
+
+In order to generate the code, the scripts in this directory have to be run (`gen_linux.sh`, `gen_macos.sh` and `gen_win_xxx.cmd`). Each script has to be run on that particular operating system.
+
+The code is generated in directories below `gen`, i.e. `main/java/net/codecrete/usb/linux/gen` and similar for the other operating systems. For each library (`xxx.so` or `xxx.dll`) and each macOS framework, a separate package is created.
+
+The scripts explicitly specify the functions, structs etc. to include as generating code for entire operating system header files can result in an excessive amount of Java source files and classes.
+
+The resulting code is then committed to the source code repository. Before the commit, imports are cleaned up to get rid of superfluous imports. Most IDEs provide a convenient command to execute this on entire directories.
+
+
+## Linux
+
+To run the script, most likely the header files for *libudev* must be installed (the library itself is most likely already installed):
+
+```
+sudo apt-get install libudev-dev
+```
+
+On Linux, *jextract* is very successful. The only limitations are:
+
+- `usbdevice_fs.h`: The macro `USBDEVFS_CONTROL` (and all similar ones) are not generated. They are probably considered a function-like macro. *jextract* does not generate code for function-like macro. But `USBDEVFS_CONTROL` is actually a constant.
+
+- `sd-device.h` (header file for *libsystemd*): *jextract* fails with *"Error: /usr/include/inttypes.h:290:8: error: unknown type name 'intmax_t'"*. The reason is yet unknown. This code is currently not needed as it uses *libudev* instead of *libsystemd*. They are related, *libsystemd* is the future solution, but it is missing support for monitoring devices.
+
+- `libudev.h`: After code generation, the class `RuntimeHelper.java` in `.../linux/gen/udev` must be manually modified as the code to access the library does not work for the directory the library is located in. So replace:
+
+```
+ System.loadLibrary("udev");
+ SymbolLookup loaderLookup = SymbolLookup.loaderLookup();
+```
+
+with:
+
+```
+ SymbolLookup loaderLookup = SymbolLookup.libraryLookup("libudev.so", MemorySession.openImplicit());
+```
+
+
+## MacOS
+
+Most of the required native function on macOS are part of a framework. Framework internally have a more complex file organization of header and binary files than appears on the outside. Thus they require a special logic to locate framework header files. *clang* supports it with the `-F` and `-iframework`. *jextract* does not support it. The result is that only a single function is generated. The binding code for all other functions and data structures is written manually.
+
+Loading framework libraries at runtime also requires special support. That is already built in and working nicely, e.g. to load the *IOKit* framework, below code can be used.
+
+```
+SymbolLookup ioKitLookup SymbolLookup.libraryLookup("IOKit.framework/IOKit", MemorySession.openImplicit());
+```
+
+
+## Windows
+
+On Windows, several scripts must be run as *jextract* is a batch file that never returns. It's not possible to call it multiple times from a single script.
+
+Most Windows SDK header files are not independent. They require that `Windows.h` is included first. So instead of specifying the target header files directly, a helper header file (`windows_headers.h` in this directory) is specified.
+
+The known limitations are:
+
+- `typedef` to `struct`: If only the *typedef* is specified (`--include-typedef`), an empty Java class is generated. If both *typedef* and the *struct* it refers to are specified, the *typedef* class is still empty but inherits from the *struct* class, which contains all the *struct* members.
+
+- Variable size *struct*: Several Windows struct are of variable size. The last member is an array. The *struct* definition specifies array length 1. But you are expected to allocate more space depending on the actual array size you need. *jextract* generates code for array length 1 and when access array members, the length is checked. So the generated code isn't really usable.
+
+- `USB_NODE_CONNECTION_INFORMATION_EX`: This struct uses a packed layout without considering alignment. The last four members are on an offset even though they are multiple bytes long. *jextract* creates the correct offsets but defines strict alignment constraints for the members. So the memory layout cannot be instantiated as it throws an exception.
+
+- GUID constants like `GUID_DEVINTERFACE_USB_DEVICE` do not work. While code is generated, the code fails at run-time as it is unable to locate the symbol. This is most likely due to the fact that the constant isn't in any native library at all. Rather they are defined in file that uses them and then multiple copies are discarded at link time using [`__declspec(selectany)`](https://docs.microsoft.com/en-us/cpp/cpp/selectany?view=msvc-170).
From 5f9cb31127ef238d7b35a95c32122f83a9e966af Mon Sep 17 00:00:00 2001
From: Manuel Bl
Date: Wed, 31 Aug 2022 19:13:42 +0200
Subject: [PATCH 027/433] Windows: use cleaner typedef name
---
java-does-usb/jextract/gen_win_kernel32.cmd | 3 +-
java-does-usb/jextract/gen_win_setupapi.cmd | 5 +-
java-does-usb/jextract/gen_win_stdlib.cmd | 2 +-
java-does-usb/jextract/gen_win_usbioctl.cmd | 7 +-
java-does-usb/jextract/gen_win_user32.cmd | 6 +-
java-does-usb/jextract/gen_win_winusb.cmd | 2 +-
.../codecrete/usb/windows/DeviceProperty.java | 18 +-
.../java/net/codecrete/usb/windows/Win.java | 12 +-
.../usb/windows/WindowsUSBDeviceRegistry.java | 42 ++---
.../usb/windows/gen/kernel32/GUID.java | 9 +
.../setupapi/SP_DEVICE_INTERFACE_DATA.java | 9 +
.../SP_DEVICE_INTERFACE_DETAIL_DATA_W.java | 9 +
.../windows/gen/setupapi/SP_DEVINFO_DATA.java | 9 +
.../_USB_NODE_CONNECTION_INFORMATION_EX.java | 171 ------------------
.../DEV_BROADCAST_DEVICEINTERFACE_W.java | 9 +
.../windows/gen/user32/DEV_BROADCAST_HDR.java | 9 +
.../codecrete/usb/windows/gen/user32/MSG.java | 9 +
.../usb/windows/gen/user32/WNDCLASSEXW.java | 9 +
18 files changed, 122 insertions(+), 218 deletions(-)
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/GUID.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SP_DEVICE_INTERFACE_DATA.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SP_DEVICE_INTERFACE_DETAIL_DATA_W.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SP_DEVINFO_DATA.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/_USB_NODE_CONNECTION_INFORMATION_EX.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/DEV_BROADCAST_DEVICEINTERFACE_W.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/DEV_BROADCAST_HDR.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/MSG.java
create mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/WNDCLASSEXW.java
diff --git a/java-does-usb/jextract/gen_win_kernel32.cmd b/java-does-usb/jextract/gen_win_kernel32.cmd
index 08aa4d94..b591e50c 100644
--- a/java-does-usb/jextract/gen_win_kernel32.cmd
+++ b/java-does-usb/jextract/gen_win_kernel32.cmd
@@ -1,4 +1,4 @@
-set JEXTRACT=..\..\..\jextract\build\jextract\bin\jextract.bat
+set JEXTRACT=..\..\..\jextract-19\bin\jextract.bat
set SDK_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0
%JEXTRACT% --source --output ../src/main/java ^
-D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
@@ -23,4 +23,5 @@ set SDK_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0
--include-macro FILE_FLAG_OVERLAPPED ^
--include-macro OPEN_EXISTING ^
--include-struct _GUID ^
+ --include-typedef GUID ^
windows_headers.h
diff --git a/java-does-usb/jextract/gen_win_setupapi.cmd b/java-does-usb/jextract/gen_win_setupapi.cmd
index edaf3411..c027cc38 100644
--- a/java-does-usb/jextract/gen_win_setupapi.cmd
+++ b/java-does-usb/jextract/gen_win_setupapi.cmd
@@ -1,4 +1,4 @@
-set JEXTRACT=..\..\..\jextract\build\jextract\bin\jextract.bat
+set JEXTRACT=..\..\..\jextract-19\bin\jextract.bat
set SDK_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0
%JEXTRACT% --source --output ../src/main/java ^
-D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
@@ -16,8 +16,11 @@ set SDK_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0
--include-function SetupDiGetDevicePropertyW ^
--include-function SetupDiOpenDeviceInterfaceW ^
--include-struct _SP_DEVINFO_DATA ^
+ --include-typedef SP_DEVINFO_DATA ^
--include-struct _SP_DEVICE_INTERFACE_DATA ^
+ --include-typedef SP_DEVICE_INTERFACE_DATA ^
--include-struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W ^
+ --include-typedef SP_DEVICE_INTERFACE_DETAIL_DATA_W ^
--include-macro DIGCF_PRESENT ^
--include-macro DIGCF_DEVICEINTERFACE ^
--include-macro SPDRP_ADDRESS ^
diff --git a/java-does-usb/jextract/gen_win_stdlib.cmd b/java-does-usb/jextract/gen_win_stdlib.cmd
index 8a80e5e0..e56b841f 100644
--- a/java-does-usb/jextract/gen_win_stdlib.cmd
+++ b/java-does-usb/jextract/gen_win_stdlib.cmd
@@ -1,4 +1,4 @@
-set JEXTRACT=..\..\..\jextract\build\jextract\bin\jextract.bat
+set JEXTRACT=..\..\..\jextract-19\bin\jextract.bat
%JEXTRACT% --source --output ../src/main/java ^
-D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
--header-class-name StdLib ^
diff --git a/java-does-usb/jextract/gen_win_usbioctl.cmd b/java-does-usb/jextract/gen_win_usbioctl.cmd
index 76cb7589..6710f2ce 100644
--- a/java-does-usb/jextract/gen_win_usbioctl.cmd
+++ b/java-does-usb/jextract/gen_win_usbioctl.cmd
@@ -1,4 +1,4 @@
-set JEXTRACT=..\..\..\jextract\build\jextract\bin\jextract.bat
+set JEXTRACT=..\..\..\jextract-19\bin\jextract.bat
set SDK_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0
%JEXTRACT% --source --output ../src/main/java ^
-D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
@@ -6,11 +6,6 @@ set SDK_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0
-I "%SDK_DIR%\shared" ^
--header-class-name USBIoctl ^
--target-package net.codecrete.usb.windows.gen.usbioctl ^
- --include-struct _USB_NODE_CONNECTION_INFORMATION_EX ^
--include-macro IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX ^
--include-macro IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION ^
windows_headers.h
-
-:: Generated code is invalid: No instance of type _USB_NODE_CONNECTION_INFORMATION_EX can be created.0
-:: They crash with:
-:: java.lang.UnsupportedOperationException: Invalid alignment requirements for layout s16(DeviceAddress)
diff --git a/java-does-usb/jextract/gen_win_user32.cmd b/java-does-usb/jextract/gen_win_user32.cmd
index 14f5ad2a..5dd02fd5 100644
--- a/java-does-usb/jextract/gen_win_user32.cmd
+++ b/java-does-usb/jextract/gen_win_user32.cmd
@@ -1,4 +1,4 @@
-set JEXTRACT=..\..\..\jextract\build\jextract\bin\jextract.bat
+set JEXTRACT=..\..\..\jextract-19\bin\jextract.bat
set SDK_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0
%JEXTRACT% --source --output ../src/main/java ^
-D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
@@ -19,7 +19,11 @@ set SDK_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0
--include-macro DBT_DEVICEREMOVECOMPLETE ^
--include-macro DBT_DEVTYP_DEVICEINTERFACE ^
--include-struct tagMSG ^
+ --include-typedef MSG ^
--include-struct tagWNDCLASSEXW ^
+ --include-typedef WNDCLASSEXW ^
--include-struct _DEV_BROADCAST_HDR ^
+ --include-typedef DEV_BROADCAST_HDR ^
--include-struct _DEV_BROADCAST_DEVICEINTERFACE_W ^
+ --include-typedef DEV_BROADCAST_DEVICEINTERFACE_W ^
windows_headers.h
diff --git a/java-does-usb/jextract/gen_win_winusb.cmd b/java-does-usb/jextract/gen_win_winusb.cmd
index a8975263..e059905c 100644
--- a/java-does-usb/jextract/gen_win_winusb.cmd
+++ b/java-does-usb/jextract/gen_win_winusb.cmd
@@ -1,4 +1,4 @@
-set JEXTRACT=..\..\..\jextract\build\jextract\bin\jextract.bat
+set JEXTRACT=..\..\..\jextract-19\bin\jextract.bat
set SDK_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0
%JEXTRACT% --source --output ../src/main/java ^
-D _AMD64_ -D _M_AMD64=100 -D UNICODE -D _UNICODE ^
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/DeviceProperty.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/DeviceProperty.java
index ce0a54dc..825cac53 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/DeviceProperty.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/DeviceProperty.java
@@ -8,10 +8,10 @@
package net.codecrete.usb.windows;
import net.codecrete.usb.USBException;
+import net.codecrete.usb.windows.gen.kernel32.GUID;
import net.codecrete.usb.windows.gen.kernel32.Kernel32;
-import net.codecrete.usb.windows.gen.kernel32._GUID;
+import net.codecrete.usb.windows.gen.setupapi.SP_DEVICE_INTERFACE_DATA;
import net.codecrete.usb.windows.gen.setupapi.SetupAPI;
-import net.codecrete.usb.windows.gen.setupapi._SP_DEVICE_INTERFACE_DATA;
import java.lang.foreign.Addressable;
import java.lang.foreign.MemorySegment;
@@ -90,8 +90,8 @@ public static String getDevicePath(String instanceID, Addressable interfaceGuid)
session.addCloseAction(() -> SetupAPI.SetupDiDestroyDeviceInfoList(devInfoSetHandle));
// retrieve first element of enumeration
- var devIntfData = session.allocate(_SP_DEVICE_INTERFACE_DATA.$LAYOUT());
- _SP_DEVICE_INTERFACE_DATA.cbSize$set(devIntfData, (int) devIntfData.byteSize());
+ var devIntfData = session.allocate(SP_DEVICE_INTERFACE_DATA.$LAYOUT());
+ SP_DEVICE_INTERFACE_DATA.cbSize$set(devIntfData, (int) devIntfData.byteSize());
if (SetupAPI.SetupDiEnumDeviceInterfaces(devInfoSetHandle, NULL, interfaceGuid, 0, devIntfData) == 0)
throw new USBException("internal error (SetupDiEnumDeviceInterfaces)");
@@ -111,11 +111,11 @@ public static MemorySegment createDEVPROPKEY(int data1, short data2, short data3
byte data4_0, byte data4_1, byte data4_2, byte data4_3,
byte data4_4, byte data4_5, byte data4_6, byte data4_7,
int pid) {
- var propKey = MemorySession.global().allocate(_GUID.sizeof() + JAVA_INT.byteSize());
- _GUID.Data1$set(propKey, data1);
- _GUID.Data2$set(propKey, data2);
- _GUID.Data3$set(propKey, data3);
- var data4 = _GUID.Data4$slice(propKey);
+ var propKey = MemorySession.global().allocate(GUID.sizeof() + JAVA_INT.byteSize());
+ GUID.Data1$set(propKey, data1);
+ GUID.Data2$set(propKey, data2);
+ GUID.Data3$set(propKey, data3);
+ var data4 = GUID.Data4$slice(propKey);
data4.set(JAVA_BYTE, 0, data4_0);
data4.set(JAVA_BYTE, 1, data4_1);
data4.set(JAVA_BYTE, 2, data4_2);
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/Win.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/Win.java
index c850dc72..b0aabe7f 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/Win.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/Win.java
@@ -7,7 +7,7 @@
package net.codecrete.usb.windows;
-import net.codecrete.usb.windows.gen.kernel32._GUID;
+import net.codecrete.usb.windows.gen.kernel32.GUID;
import net.codecrete.usb.windows.gen.stdlib.StdLib;
import java.lang.foreign.MemoryAddress;
@@ -82,11 +82,11 @@ public static String createStringFromSegment(MemorySegment segment) {
public static MemorySegment CreateGUID(int data1, short data2, short data3,
byte data4_0, byte data4_1, byte data4_2, byte data4_3,
byte data4_4, byte data4_5, byte data4_6, byte data4_7) {
- var guid = MemorySegment.allocateNative(_GUID.$LAYOUT(), MemorySession.global());
- _GUID.Data1$set(guid, data1);
- _GUID.Data2$set(guid, data2);
- _GUID.Data3$set(guid, data3);
- var data4 = _GUID.Data4$slice(guid);
+ var guid = MemorySegment.allocateNative(GUID.$LAYOUT(), MemorySession.global());
+ GUID.Data1$set(guid, data1);
+ GUID.Data2$set(guid, data2);
+ GUID.Data3$set(guid, data3);
+ var data4 = GUID.Data4$slice(guid);
data4.set(JAVA_BYTE, 0, data4_0);
data4.set(JAVA_BYTE, 1, data4_1);
data4.set(JAVA_BYTE, 2, data4_2);
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
index c2a3d8d6..7fb8deab 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
@@ -14,9 +14,9 @@
import net.codecrete.usb.common.USBDeviceRegistry;
import net.codecrete.usb.common.USBStructs;
import net.codecrete.usb.windows.gen.kernel32.Kernel32;
+import net.codecrete.usb.windows.gen.setupapi.SP_DEVICE_INTERFACE_DATA;
+import net.codecrete.usb.windows.gen.setupapi.SP_DEVINFO_DATA;
import net.codecrete.usb.windows.gen.setupapi.SetupAPI;
-import net.codecrete.usb.windows.gen.setupapi._SP_DEVICE_INTERFACE_DATA;
-import net.codecrete.usb.windows.gen.setupapi._SP_DEVINFO_DATA;
import net.codecrete.usb.windows.gen.usbioctl.USBIoctl;
import net.codecrete.usb.windows.gen.user32.*;
@@ -73,8 +73,8 @@ private void enumeratePresentDevices() {
// ensure the result is destroyed when the scope is left
outerSession.addCloseAction(() -> SetupAPI.SetupDiDestroyDeviceInfoList(devInfoSetHandle));
- var devInfo = MemorySegment.allocateNative(_SP_DEVINFO_DATA.$LAYOUT(), outerSession);
- _SP_DEVINFO_DATA.cbSize$set(devInfo, (int) _SP_DEVINFO_DATA.$LAYOUT().byteSize());
+ var devInfo = MemorySegment.allocateNative(SP_DEVINFO_DATA.$LAYOUT(), outerSession);
+ SP_DEVINFO_DATA.cbSize$set(devInfo, (int) SP_DEVINFO_DATA.$LAYOUT().byteSize());
// ensure all hubs are closed later
final var hubHandles = new HashMap();
@@ -218,11 +218,11 @@ private void monitorDevices() {
);
// register window class
- var wx = session.allocate(tagWNDCLASSEXW.$LAYOUT());
- tagWNDCLASSEXW.cbSize$set(wx, (int) wx.byteSize());
- tagWNDCLASSEXW.lpfnWndProc$set(wx, handleWindowMessageStub.address());
- tagWNDCLASSEXW.hInstance$set(wx, instance);
- tagWNDCLASSEXW.lpszClassName$set(wx, className.address());
+ var wx = session.allocate(WNDCLASSEXW.$LAYOUT());
+ WNDCLASSEXW.cbSize$set(wx, (int) wx.byteSize());
+ WNDCLASSEXW.lpfnWndProc$set(wx, handleWindowMessageStub.address());
+ WNDCLASSEXW.hInstance$set(wx, instance);
+ WNDCLASSEXW.lpszClassName$set(wx, className.address());
User32.RegisterClassExW(wx);
// create message-only window
@@ -232,10 +232,10 @@ private void monitorDevices() {
throw new USBException("internal error (CreateWindowExW)", Kernel32.GetLastError());
// configure notifications
- var notificationFilter = session.allocate(_DEV_BROADCAST_DEVICEINTERFACE_W.$LAYOUT());
- _DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_size$set(notificationFilter, (int) notificationFilter.byteSize());
- _DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_devicetype$set(notificationFilter, User32.DBT_DEVTYP_DEVICEINTERFACE());
- _DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_classguid$slice(notificationFilter).copyFrom(USBHelper.GUID_DEVINTERFACE_USB_DEVICE);
+ var notificationFilter = session.allocate(DEV_BROADCAST_DEVICEINTERFACE_W.$LAYOUT());
+ DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_size$set(notificationFilter, (int) notificationFilter.byteSize());
+ DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_devicetype$set(notificationFilter, User32.DBT_DEVTYP_DEVICEINTERFACE());
+ DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_classguid$slice(notificationFilter).copyFrom(USBHelper.GUID_DEVINTERFACE_USB_DEVICE);
var notifyHandle = User32.RegisterDeviceNotificationW(hwnd, notificationFilter, User32.DEVICE_NOTIFY_WINDOW_HANDLE());
if (notifyHandle == NULL)
@@ -248,7 +248,7 @@ private void monitorDevices() {
signalEnumerationComplete();
// process messages
- var msg = session.allocate(tagMSG.$LAYOUT());
+ var msg = session.allocate(MSG.$LAYOUT());
while (User32.GetMessageW(msg, hwnd, 0, 0) > 0)
; // do nothing
@@ -262,11 +262,11 @@ private long handleWindowMessage(MemoryAddress hWnd, int uMsg, long wParam, l
// check for message related to connecting/disconnecting devices
if (uMsg == User32.WM_DEVICECHANGE() && (wParam == User32.DBT_DEVICEARRIVAL() || wParam == User32.DBT_DEVICEREMOVECOMPLETE())) {
try (var session = MemorySession.openConfined()) {
- var data = MemorySegment.ofAddress(MemoryAddress.ofLong(lParam), _DEV_BROADCAST_DEVICEINTERFACE_W.sizeof(), session);
- if (_DEV_BROADCAST_HDR.dbch_devicetype$get(data) == User32.DBT_DEVTYP_DEVICEINTERFACE()) {
+ var data = MemorySegment.ofAddress(MemoryAddress.ofLong(lParam), DEV_BROADCAST_DEVICEINTERFACE_W.sizeof(), session);
+ if (DEV_BROADCAST_HDR.dbch_devicetype$get(data) == User32.DBT_DEVTYP_DEVICEINTERFACE()) {
// get device path
- var nameSlice = MemorySegment.ofAddress(_DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_name$slice(data).address(), 500, session);
+ var nameSlice = MemorySegment.ofAddress(DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_name$slice(data).address(), 500, session);
var devicePath = Win.createStringFromSegment(nameSlice);
if (wParam == User32.DBT_DEVICEARRIVAL())
onDeviceConnected(devicePath);
@@ -294,14 +294,14 @@ private void onDeviceConnected(String devicePath) {
// ensure the result is destroyed when the scope is left
session.addCloseAction(() -> SetupAPI.SetupDiDestroyDeviceInfoList(devInfoSetHandle));
- var devIntfData = session.allocate(_SP_DEVICE_INTERFACE_DATA.$LAYOUT());
- _SP_DEVICE_INTERFACE_DATA.cbSize$set(devIntfData, (int) devIntfData.byteSize());
+ var devIntfData = session.allocate(SP_DEVICE_INTERFACE_DATA.$LAYOUT());
+ SP_DEVICE_INTERFACE_DATA.cbSize$set(devIntfData, (int) devIntfData.byteSize());
var devicePathSegment = Win.createSegmentFromString(devicePath, session);
if (SetupAPI.SetupDiOpenDeviceInterfaceW(devInfoSetHandle, devicePathSegment, 0, devIntfData) == 0)
throw new USBException("internal error (SetupDiOpenDeviceInterfaceW)", Kernel32.GetLastError());
- var devInfo = session.allocate(_SP_DEVINFO_DATA.$LAYOUT());
- _SP_DEVINFO_DATA.cbSize$set(devInfo, (int) devInfo.byteSize());
+ var devInfo = session.allocate(SP_DEVINFO_DATA.$LAYOUT());
+ SP_DEVINFO_DATA.cbSize$set(devInfo, (int) devInfo.byteSize());
if (SetupAPI.SetupDiGetDeviceInterfaceDetailW(devInfoSetHandle, devIntfData, NULL, 0, NULL, devInfo) == 0) {
int err = Kernel32.GetLastError();
if (err != Kernel32.ERROR_INSUFFICIENT_BUFFER())
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/GUID.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/GUID.java
new file mode 100644
index 00000000..ea550f1d
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/kernel32/GUID.java
@@ -0,0 +1,9 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.kernel32;
+
+public class GUID extends _GUID {
+
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SP_DEVICE_INTERFACE_DATA.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SP_DEVICE_INTERFACE_DATA.java
new file mode 100644
index 00000000..95322b6e
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SP_DEVICE_INTERFACE_DATA.java
@@ -0,0 +1,9 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.setupapi;
+
+public class SP_DEVICE_INTERFACE_DATA extends _SP_DEVICE_INTERFACE_DATA {
+
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SP_DEVICE_INTERFACE_DETAIL_DATA_W.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SP_DEVICE_INTERFACE_DETAIL_DATA_W.java
new file mode 100644
index 00000000..77a1e06d
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SP_DEVICE_INTERFACE_DETAIL_DATA_W.java
@@ -0,0 +1,9 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.setupapi;
+
+public class SP_DEVICE_INTERFACE_DETAIL_DATA_W extends _SP_DEVICE_INTERFACE_DETAIL_DATA_W {
+
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SP_DEVINFO_DATA.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SP_DEVINFO_DATA.java
new file mode 100644
index 00000000..89a49f0d
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/setupapi/SP_DEVINFO_DATA.java
@@ -0,0 +1,9 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.setupapi;
+
+public class SP_DEVINFO_DATA extends _SP_DEVINFO_DATA {
+
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/_USB_NODE_CONNECTION_INFORMATION_EX.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/_USB_NODE_CONNECTION_INFORMATION_EX.java
deleted file mode 100644
index 892dd93d..00000000
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/usbioctl/_USB_NODE_CONNECTION_INFORMATION_EX.java
+++ /dev/null
@@ -1,171 +0,0 @@
-// Generated by jextract
-
-package net.codecrete.usb.windows.gen.usbioctl;
-
-import java.lang.foreign.*;
-import java.lang.invoke.VarHandle;
-public class _USB_NODE_CONNECTION_INFORMATION_EX {
-
- static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout(
- Constants$root.C_LONG$LAYOUT.withName("ConnectionIndex"),
- MemoryLayout.structLayout(
- Constants$root.C_CHAR$LAYOUT.withName("bLength"),
- Constants$root.C_CHAR$LAYOUT.withName("bDescriptorType"),
- Constants$root.C_SHORT$LAYOUT.withName("bcdUSB"),
- Constants$root.C_CHAR$LAYOUT.withName("bDeviceClass"),
- Constants$root.C_CHAR$LAYOUT.withName("bDeviceSubClass"),
- Constants$root.C_CHAR$LAYOUT.withName("bDeviceProtocol"),
- Constants$root.C_CHAR$LAYOUT.withName("bMaxPacketSize0"),
- Constants$root.C_SHORT$LAYOUT.withName("idVendor"),
- Constants$root.C_SHORT$LAYOUT.withName("idProduct"),
- Constants$root.C_SHORT$LAYOUT.withName("bcdDevice"),
- Constants$root.C_CHAR$LAYOUT.withName("iManufacturer"),
- Constants$root.C_CHAR$LAYOUT.withName("iProduct"),
- Constants$root.C_CHAR$LAYOUT.withName("iSerialNumber"),
- Constants$root.C_CHAR$LAYOUT.withName("bNumConfigurations")
- ).withName("DeviceDescriptor"),
- Constants$root.C_CHAR$LAYOUT.withName("CurrentConfigurationValue"),
- Constants$root.C_CHAR$LAYOUT.withName("Speed"),
- Constants$root.C_CHAR$LAYOUT.withName("DeviceIsHub"),
- Constants$root.C_SHORT$LAYOUT.withName("DeviceAddress"),
- Constants$root.C_LONG$LAYOUT.withName("NumberOfOpenPipes"),
- Constants$root.C_LONG$LAYOUT.withName("ConnectionStatus"),
- MemoryLayout.sequenceLayout(0, MemoryLayout.structLayout(
- MemoryLayout.structLayout(
- Constants$root.C_CHAR$LAYOUT.withName("bLength"),
- Constants$root.C_CHAR$LAYOUT.withName("bDescriptorType"),
- Constants$root.C_CHAR$LAYOUT.withName("bEndpointAddress"),
- Constants$root.C_CHAR$LAYOUT.withName("bmAttributes"),
- Constants$root.C_SHORT$LAYOUT.withName("wMaxPacketSize"),
- Constants$root.C_CHAR$LAYOUT.withName("bInterval")
- ).withName("EndpointDescriptor"),
- Constants$root.C_LONG$LAYOUT.withName("ScheduleOffset")
- ).withName("_USB_PIPE_INFO")).withName("PipeList")
- ).withName("_USB_NODE_CONNECTION_INFORMATION_EX");
- public static MemoryLayout $LAYOUT() {
- return _USB_NODE_CONNECTION_INFORMATION_EX.$struct$LAYOUT;
- }
- static final VarHandle ConnectionIndex$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("ConnectionIndex"));
- public static VarHandle ConnectionIndex$VH() {
- return _USB_NODE_CONNECTION_INFORMATION_EX.ConnectionIndex$VH;
- }
- public static int ConnectionIndex$get(MemorySegment seg) {
- return (int)_USB_NODE_CONNECTION_INFORMATION_EX.ConnectionIndex$VH.get(seg);
- }
- public static void ConnectionIndex$set( MemorySegment seg, int x) {
- _USB_NODE_CONNECTION_INFORMATION_EX.ConnectionIndex$VH.set(seg, x);
- }
- public static int ConnectionIndex$get(MemorySegment seg, long index) {
- return (int)_USB_NODE_CONNECTION_INFORMATION_EX.ConnectionIndex$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void ConnectionIndex$set(MemorySegment seg, long index, int x) {
- _USB_NODE_CONNECTION_INFORMATION_EX.ConnectionIndex$VH.set(seg.asSlice(index*sizeof()), x);
- }
- public static MemorySegment DeviceDescriptor$slice(MemorySegment seg) {
- return seg.asSlice(4, 18);
- }
- static final VarHandle CurrentConfigurationValue$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("CurrentConfigurationValue"));
- public static VarHandle CurrentConfigurationValue$VH() {
- return _USB_NODE_CONNECTION_INFORMATION_EX.CurrentConfigurationValue$VH;
- }
- public static byte CurrentConfigurationValue$get(MemorySegment seg) {
- return (byte)_USB_NODE_CONNECTION_INFORMATION_EX.CurrentConfigurationValue$VH.get(seg);
- }
- public static void CurrentConfigurationValue$set( MemorySegment seg, byte x) {
- _USB_NODE_CONNECTION_INFORMATION_EX.CurrentConfigurationValue$VH.set(seg, x);
- }
- public static byte CurrentConfigurationValue$get(MemorySegment seg, long index) {
- return (byte)_USB_NODE_CONNECTION_INFORMATION_EX.CurrentConfigurationValue$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void CurrentConfigurationValue$set(MemorySegment seg, long index, byte x) {
- _USB_NODE_CONNECTION_INFORMATION_EX.CurrentConfigurationValue$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle Speed$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("Speed"));
- public static VarHandle Speed$VH() {
- return _USB_NODE_CONNECTION_INFORMATION_EX.Speed$VH;
- }
- public static byte Speed$get(MemorySegment seg) {
- return (byte)_USB_NODE_CONNECTION_INFORMATION_EX.Speed$VH.get(seg);
- }
- public static void Speed$set( MemorySegment seg, byte x) {
- _USB_NODE_CONNECTION_INFORMATION_EX.Speed$VH.set(seg, x);
- }
- public static byte Speed$get(MemorySegment seg, long index) {
- return (byte)_USB_NODE_CONNECTION_INFORMATION_EX.Speed$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void Speed$set(MemorySegment seg, long index, byte x) {
- _USB_NODE_CONNECTION_INFORMATION_EX.Speed$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle DeviceIsHub$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("DeviceIsHub"));
- public static VarHandle DeviceIsHub$VH() {
- return _USB_NODE_CONNECTION_INFORMATION_EX.DeviceIsHub$VH;
- }
- public static byte DeviceIsHub$get(MemorySegment seg) {
- return (byte)_USB_NODE_CONNECTION_INFORMATION_EX.DeviceIsHub$VH.get(seg);
- }
- public static void DeviceIsHub$set( MemorySegment seg, byte x) {
- _USB_NODE_CONNECTION_INFORMATION_EX.DeviceIsHub$VH.set(seg, x);
- }
- public static byte DeviceIsHub$get(MemorySegment seg, long index) {
- return (byte)_USB_NODE_CONNECTION_INFORMATION_EX.DeviceIsHub$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void DeviceIsHub$set(MemorySegment seg, long index, byte x) {
- _USB_NODE_CONNECTION_INFORMATION_EX.DeviceIsHub$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle DeviceAddress$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("DeviceAddress"));
- public static VarHandle DeviceAddress$VH() {
- return _USB_NODE_CONNECTION_INFORMATION_EX.DeviceAddress$VH;
- }
- public static short DeviceAddress$get(MemorySegment seg) {
- return (short)_USB_NODE_CONNECTION_INFORMATION_EX.DeviceAddress$VH.get(seg);
- }
- public static void DeviceAddress$set( MemorySegment seg, short x) {
- _USB_NODE_CONNECTION_INFORMATION_EX.DeviceAddress$VH.set(seg, x);
- }
- public static short DeviceAddress$get(MemorySegment seg, long index) {
- return (short)_USB_NODE_CONNECTION_INFORMATION_EX.DeviceAddress$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void DeviceAddress$set(MemorySegment seg, long index, short x) {
- _USB_NODE_CONNECTION_INFORMATION_EX.DeviceAddress$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle NumberOfOpenPipes$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("NumberOfOpenPipes"));
- public static VarHandle NumberOfOpenPipes$VH() {
- return _USB_NODE_CONNECTION_INFORMATION_EX.NumberOfOpenPipes$VH;
- }
- public static int NumberOfOpenPipes$get(MemorySegment seg) {
- return (int)_USB_NODE_CONNECTION_INFORMATION_EX.NumberOfOpenPipes$VH.get(seg);
- }
- public static void NumberOfOpenPipes$set( MemorySegment seg, int x) {
- _USB_NODE_CONNECTION_INFORMATION_EX.NumberOfOpenPipes$VH.set(seg, x);
- }
- public static int NumberOfOpenPipes$get(MemorySegment seg, long index) {
- return (int)_USB_NODE_CONNECTION_INFORMATION_EX.NumberOfOpenPipes$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void NumberOfOpenPipes$set(MemorySegment seg, long index, int x) {
- _USB_NODE_CONNECTION_INFORMATION_EX.NumberOfOpenPipes$VH.set(seg.asSlice(index*sizeof()), x);
- }
- static final VarHandle ConnectionStatus$VH = $struct$LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("ConnectionStatus"));
- public static VarHandle ConnectionStatus$VH() {
- return _USB_NODE_CONNECTION_INFORMATION_EX.ConnectionStatus$VH;
- }
- public static int ConnectionStatus$get(MemorySegment seg) {
- return (int)_USB_NODE_CONNECTION_INFORMATION_EX.ConnectionStatus$VH.get(seg);
- }
- public static void ConnectionStatus$set( MemorySegment seg, int x) {
- _USB_NODE_CONNECTION_INFORMATION_EX.ConnectionStatus$VH.set(seg, x);
- }
- public static int ConnectionStatus$get(MemorySegment seg, long index) {
- return (int)_USB_NODE_CONNECTION_INFORMATION_EX.ConnectionStatus$VH.get(seg.asSlice(index*sizeof()));
- }
- public static void ConnectionStatus$set(MemorySegment seg, long index, int x) {
- _USB_NODE_CONNECTION_INFORMATION_EX.ConnectionStatus$VH.set(seg.asSlice(index*sizeof()), x);
- }
- public static long sizeof() { return $LAYOUT().byteSize(); }
- public static MemorySegment allocate(SegmentAllocator allocator) { return allocator.allocate($LAYOUT()); }
- public static MemorySegment allocateArray(int len, SegmentAllocator allocator) {
- return allocator.allocate(MemoryLayout.sequenceLayout(len, $LAYOUT()));
- }
- public static MemorySegment ofAddress(MemoryAddress addr, MemorySession session) { return RuntimeHelper.asArray(addr, $LAYOUT(), 1, session); }
-}
-
-
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/DEV_BROADCAST_DEVICEINTERFACE_W.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/DEV_BROADCAST_DEVICEINTERFACE_W.java
new file mode 100644
index 00000000..42c68946
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/DEV_BROADCAST_DEVICEINTERFACE_W.java
@@ -0,0 +1,9 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.user32;
+
+public class DEV_BROADCAST_DEVICEINTERFACE_W extends _DEV_BROADCAST_DEVICEINTERFACE_W {
+
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/DEV_BROADCAST_HDR.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/DEV_BROADCAST_HDR.java
new file mode 100644
index 00000000..bc2a60af
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/DEV_BROADCAST_HDR.java
@@ -0,0 +1,9 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.user32;
+
+public class DEV_BROADCAST_HDR extends _DEV_BROADCAST_HDR {
+
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/MSG.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/MSG.java
new file mode 100644
index 00000000..2cff5412
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/MSG.java
@@ -0,0 +1,9 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.user32;
+
+public class MSG extends tagMSG {
+
+}
+
+
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/WNDCLASSEXW.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/WNDCLASSEXW.java
new file mode 100644
index 00000000..b09b0cfc
--- /dev/null
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/gen/user32/WNDCLASSEXW.java
@@ -0,0 +1,9 @@
+// Generated by jextract
+
+package net.codecrete.usb.windows.gen.user32;
+
+public class WNDCLASSEXW extends tagWNDCLASSEXW {
+
+}
+
+
From 5ca47136bc2a61288b196f125788f31130c79508 Mon Sep 17 00:00:00 2001
From: Manuel Bleichenbacher
Date: Wed, 31 Aug 2022 21:26:35 +0200
Subject: [PATCH 028/433] macOS: Use pre-built jextract binaries
---
java-does-usb/jextract/README.md | 7 ++++++-
java-does-usb/jextract/gen_macos.sh | 2 +-
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/java-does-usb/jextract/README.md b/java-does-usb/jextract/README.md
index 82a12f04..bd23301e 100644
--- a/java-does-usb/jextract/README.md
+++ b/java-does-usb/jextract/README.md
@@ -1,6 +1,6 @@
# Code Generation with *jextract*
-Some of the binding code for accessing native functions and data structures is generated with [jextract](https://jdk.java.net/jextract/). The tool is still under construction and has its limitations.
+Some of the binding code for accessing native functions and data structures is generated with [jextract](https://jdk.java.net/jextract/). The tool is still under construction and has its limitations.
In order to generate the code, the scripts in this directory have to be run (`gen_linux.sh`, `gen_macos.sh` and `gen_win_xxx.cmd`). Each script has to be run on that particular operating system.
@@ -11,6 +11,11 @@ The scripts explicitly specify the functions, structs etc. to include as generat
The resulting code is then committed to the source code repository. Before the commit, imports are cleaned up to get rid of superfluous imports. Most IDEs provide a convenient command to execute this on entire directories.
+## General limitations
+
+- Binaries of *jextract* can be downloaded from https://jdk.java.net/jextract/. Only x64 binaries are available. It is unclear if the x64 jextract run on macOS with Apple Silicon (ARM64) using the Rosetta emulator produces valid bindings. So far, not problems have been detected.
+
+
## Linux
To run the script, most likely the header files for *libudev* must be installed (the library itself is most likely already installed):
diff --git a/java-does-usb/jextract/gen_macos.sh b/java-does-usb/jextract/gen_macos.sh
index 31907319..bfdd2698 100755
--- a/java-does-usb/jextract/gen_macos.sh
+++ b/java-does-usb/jextract/gen_macos.sh
@@ -1,6 +1,6 @@
#!/bin/sh
-JEXTRACT=../../../jextract/build/jextract/bin/jextract
+JEXTRACT=../../../jextract-19/bin/jextract
SDK_DIR=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
# CoreFoundation
From 3659bf52b179ef0101fb05410da402b0135ba593 Mon Sep 17 00:00:00 2001
From: Manuel Bleichenbacher
Date: Wed, 31 Aug 2022 21:29:30 +0200
Subject: [PATCH 029/433] macOS: Remove unnecessary function
---
java-does-usb/jextract/gen_macos.sh | 1 -
.../codecrete/usb/macos/gen/mach/constants$0.java | 8 --------
.../java/net/codecrete/usb/macos/gen/mach/mach.java | 12 ------------
3 files changed, 21 deletions(-)
diff --git a/java-does-usb/jextract/gen_macos.sh b/java-does-usb/jextract/gen_macos.sh
index bfdd2698..ce77e369 100755
--- a/java-does-usb/jextract/gen_macos.sh
+++ b/java-does-usb/jextract/gen_macos.sh
@@ -15,6 +15,5 @@ $JEXTRACT --source --output ../src/main/java \
-I $SDK_DIR/usr/include \
--header-class-name mach \
--target-package net.codecrete.usb.macos.gen.mach \
- --include-function mach_error \
--include-function mach_error_string \
$SDK_DIR/usr/include/mach/mach.h
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/constants$0.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/constants$0.java
index 3d61da92..00707d13 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/constants$0.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/constants$0.java
@@ -13,14 +13,6 @@ class constants$0 {
"mach_error_string",
constants$0.mach_error_string$FUNC
);
- static final FunctionDescriptor mach_error$FUNC = FunctionDescriptor.ofVoid(
- Constants$root.C_POINTER$LAYOUT,
- Constants$root.C_INT$LAYOUT
- );
- static final MethodHandle mach_error$MH = RuntimeHelper.downcallHandle(
- "mach_error",
- constants$0.mach_error$FUNC
- );
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/mach.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/mach.java
index 8e162bc9..6b42d952 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/mach.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/gen/mach/mach.java
@@ -2,7 +2,6 @@
package net.codecrete.usb.macos.gen.mach;
-import java.lang.foreign.Addressable;
import java.lang.foreign.MemoryAddress;
import java.lang.invoke.MethodHandle;
@@ -29,17 +28,6 @@ public static MemoryAddress mach_error_string ( int error_value) {
throw new AssertionError("should not reach here", ex$);
}
}
- public static MethodHandle mach_error$MH() {
- return RuntimeHelper.requireNonNull(constants$0.mach_error$MH,"mach_error");
- }
- public static void mach_error ( Addressable str, int error_value) {
- var mh$ = mach_error$MH();
- try {
- mh$.invokeExact(str, error_value);
- } catch (Throwable ex$) {
- throw new AssertionError("should not reach here", ex$);
- }
- }
}
From 16fbdff59c92ee8add59c386f7993c574390164f Mon Sep 17 00:00:00 2001
From: Manuel Bleichenbacher
Date: Wed, 31 Aug 2022 21:57:14 +0200
Subject: [PATCH 030/433] Factor out common registry code
---
.../src/main/java/net/codecrete/usb/USB.java | 4 +-
.../usb/common/USBDeviceRegistry.java | 80 +++++++++-
.../usb/linux/LinuxUSBDeviceRegistry.java | 119 ++++++--------
.../usb/macos/MacosUSBDeviceRegistry.java | 124 +++++++--------
.../usb/windows/WindowsUSBDeviceRegistry.java | 148 ++++++++----------
5 files changed, 245 insertions(+), 230 deletions(-)
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/USB.java b/java-does-usb/src/main/java/net/codecrete/usb/USB.java
index 5f9b7d35..86cef6c9 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/USB.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/USB.java
@@ -41,8 +41,10 @@ private static USBDeviceRegistry createInstance() {
private static USBDeviceRegistry _instance = null;
private static synchronized USBDeviceRegistry instance() {
- if (_instance == null)
+ if (_instance == null) {
_instance = createInstance();
+ _instance.start();
+ }
return _instance;
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceRegistry.java
index f5529efa..c4ee6007 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceRegistry.java
@@ -10,6 +10,7 @@
import net.codecrete.usb.USBDeviceInfo;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
@@ -17,18 +18,55 @@
import java.util.function.Consumer;
/**
- * USB device registry.
+ * Base class for USB device registry.
+ *
+ * This singleton class maintains a list of connected USB devices.
+ * It starts a background thread monitoring the USB devices being
+ * connected and disconnected.
+ *
+ *
+ * The background thread enumerates the already present devices
+ * and builds the initial device list.
+ *
*/
public abstract class USBDeviceRegistry {
- protected volatile List devices;
+ private volatile List devices;
protected Consumer onDeviceConnectedHandler;
protected Consumer onDeviceDisconnectedHandler;
private final Lock lock = new ReentrantLock();
private final Condition enumerationComplete = lock.newCondition();
- public abstract List getAllDevices();
+ /**
+ * Start this device registry.
+ *
+ * This method blocks until the initial device enumeration has
+ * completed.
+ *
+ */
+ public void start() {
+ startDeviceMonitor(this::monitorDevices);
+ }
+
+ /**
+ * Enumerate the already present devices and then start monitoring
+ * devices being connected and disconnected.
+ *
+ * Implementors of this method are expected to call, {@link #setInitialDeviceList(List)}
+ * after the initial device implementation.
+ *
+ */
+ protected abstract void monitorDevices();
+
+ /**
+ * Gets the list of the currently connected USB devices.
+ *
+ * @return list of devices
+ */
+ public List getAllDevices() {
+ return Collections.unmodifiableList(devices);
+ }
public void setOnDeviceConnected(Consumer handler) {
onDeviceConnectedHandler = handler;
@@ -50,6 +88,12 @@ protected void emitOnDeviceDisconnected(USBDeviceInfo device) {
/**
* Starts the background thread and waits until the first device enumeration is complete.
+ *
+ * In order to signal that the initial enumeration is complete, the monitor task is expected
+ * to call {@link #setInitialDeviceList(List)}.
+ *
+ *
+ * @param monitorTask the task to start in the background
*/
protected void startDeviceMonitor(Runnable monitorTask) {
// start new thread
@@ -71,7 +115,7 @@ protected void startDeviceMonitor(Runnable monitorTask) {
/**
* Signals completion of initial device enumeration.
*/
- protected void signalEnumerationComplete() {
+ private void signalEnumerationComplete() {
lock.lock();
try {
enumerationComplete.signalAll();
@@ -80,9 +124,27 @@ protected void signalEnumerationComplete() {
}
}
+ /**
+ * Sets the device list of the initial device enumeration.
+ *
+ * This function singals to the spawning thread that the enumeration is complete.
+ *
+ *
+ * @param deviceList the device list
+ */
+ protected void setInitialDeviceList(List deviceList) {
+ devices = deviceList;
+ signalEnumerationComplete();
+ }
+
+ /**
+ * Adds a device to the list of connected USB devices.
+ *
+ * @param device device to add
+ */
protected void addDevice(USBDeviceInfo device) {
// check for duplicates
- if (findDeviceIndex(devices, ((USBDeviceInfoImpl)device).getUniqueId()) >= 0)
+ if (findDeviceIndex(devices, ((USBDeviceInfoImpl) device).getUniqueId()) >= 0)
return;
// copy list
@@ -95,6 +157,11 @@ protected void addDevice(USBDeviceInfo device) {
emitOnDeviceConnected(device);
}
+ /**
+ * Removes a device from the list of connected USB devices.
+ *
+ * @param deviceId the unique ID of the device to remove
+ */
protected void removeDevice(Object deviceId) {
// locate device to be removed
int index = findDeviceIndex(devices, deviceId);
@@ -113,8 +180,9 @@ protected void removeDevice(Object deviceId) {
/**
* Finds the index of the device with the given ID in the device list
+ *
* @param deviceList the device list
- * @param deviceId the unique device ID
+ * @param deviceId the unique device ID
* @return return the index, or -1 if the device is not found
*/
protected int findDeviceIndex(List deviceList, Object deviceId) {
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceRegistry.java
index d2826d07..de5eb7bf 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceRegistry.java
@@ -26,15 +26,6 @@
/**
* Linux implementation of USB device registry.
- *
- * This singleton class maintains a list of connected USB devices.
- * It starts a background thread monitoring the USB devices being
- * connected and disconnected.
- *
- *
- * The background thread also enumerates the already present devices
- * and builds the initial device list.
- *
*/
public class LinuxUSBDeviceRegistry extends USBDeviceRegistry {
@@ -42,66 +33,8 @@ public class LinuxUSBDeviceRegistry extends USBDeviceRegistry {
private static final MemorySegment MONITOR_NAME = MemorySession.global().allocateUtf8String("udev");
private static final MemorySegment DEVTYPE_USB_DEVICE = MemorySession.global().allocateUtf8String("usb_device");
- /**
- * Creates a new instance.
- */
- public LinuxUSBDeviceRegistry() {
- startDeviceMonitor(this::monitorDevices);
- }
-
@Override
- public List getAllDevices() {
- return devices;
- }
-
- private void enumeratePresentDevices(Addressable udevInstance) {
- List result = new ArrayList<>();
- try (var outerSession = MemorySession.openConfined()) {
-
- // create device enumerator
- var enumerate = udev.udev_enumerate_new(udevInstance);
- if (enumerate == NULL)
- throw new USBException("internal error (udev_enumerate_new)");
-
- outerSession.addCloseAction(() -> udev.udev_enumerate_unref(enumerate));
-
- if (udev.udev_enumerate_add_match_subsystem(enumerate, SUBSYSTEM_USB) < 0)
- throw new USBException("internal error (udev_enumerate_add_match_subsystem)");
-
- if (udev.udev_enumerate_scan_devices(enumerate) < 0)
- throw new USBException("internal error (udev_enumerate_scan_devices)");
-
- // enumerate devices
- for (var entry = udev.udev_enumerate_get_list_entry(enumerate);
- entry != NULL;
- entry = udev.udev_list_entry_get_next(entry)) {
-
- try (var session = MemorySession.openConfined()) {
-
- var path = udev.udev_list_entry_get_name(entry);
- if (path == NULL)
- continue;
-
- // get device handle
- var dev = udev.udev_device_new_from_syspath(udevInstance, path);
- if (dev == NULL)
- continue;
-
- // ensure the device is released
- session.addCloseAction(() -> udev.udev_device_unref(dev));
-
- // get device details
- var deviceInfo = getDeviceDetails(dev);
- if (deviceInfo != null)
- result.add(deviceInfo);
- }
- }
- }
-
- devices = result;
- }
-
- private void monitorDevices() {
+ protected void monitorDevices() {
// setup udev monitor
var udevInstance = udev.udev_new();
@@ -125,9 +58,6 @@ private void monitorDevices() {
// create initial list of devices
enumeratePresentDevices(udevInstance);
- // signal initial enumeration is complete
- signalEnumerationComplete();
-
// monitor device changes
while (true) {
try (var session = MemorySession.openConfined()) {
@@ -154,6 +84,53 @@ private void monitorDevices() {
}
}
+ private void enumeratePresentDevices(Addressable udevInstance) {
+ List result = new ArrayList<>();
+ try (var outerSession = MemorySession.openConfined()) {
+
+ // create device enumerator
+ var enumerate = udev.udev_enumerate_new(udevInstance);
+ if (enumerate == NULL)
+ throw new USBException("internal error (udev_enumerate_new)");
+
+ outerSession.addCloseAction(() -> udev.udev_enumerate_unref(enumerate));
+
+ if (udev.udev_enumerate_add_match_subsystem(enumerate, SUBSYSTEM_USB) < 0)
+ throw new USBException("internal error (udev_enumerate_add_match_subsystem)");
+
+ if (udev.udev_enumerate_scan_devices(enumerate) < 0)
+ throw new USBException("internal error (udev_enumerate_scan_devices)");
+
+ // enumerate devices
+ for (var entry = udev.udev_enumerate_get_list_entry(enumerate);
+ entry != NULL;
+ entry = udev.udev_list_entry_get_next(entry)) {
+
+ try (var session = MemorySession.openConfined()) {
+
+ var path = udev.udev_list_entry_get_name(entry);
+ if (path == NULL)
+ continue;
+
+ // get device handle
+ var dev = udev.udev_device_new_from_syspath(udevInstance, path);
+ if (dev == NULL)
+ continue;
+
+ // ensure the device is released
+ session.addCloseAction(() -> udev.udev_device_unref(dev));
+
+ // get device details
+ var deviceInfo = getDeviceDetails(dev);
+ if (deviceInfo != null)
+ result.add(deviceInfo);
+ }
+ }
+ }
+
+ setInitialDeviceList(result);
+ }
+
private void onDeviceConnected(MemoryAddress device) {
var deviceInfo = getDeviceDetails(device);
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceRegistry.java
index 194ae049..35e51254 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceRegistry.java
@@ -15,7 +15,6 @@
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.ArrayList;
-import java.util.List;
import java.util.function.BiConsumer;
import static java.lang.foreign.MemoryAddress.NULL;
@@ -23,33 +22,65 @@
/**
* MacOS implementation of USB device registry.
- *
- * This singleton class maintains a list of connected USB devices.
- * It starts a background thread monitoring the USB devices being
- * connected and disconnected.
- *
- *
- * The background thread also creates the initial devices list as
- * setting up the notifications will initially deliver the connected
- * devices anyway.
- *
*/
public class MacosUSBDeviceRegistry extends USBDeviceRegistry {
- public MacosUSBDeviceRegistry() {
- startDeviceMonitor(this::monitorDevices);
- }
+ /**
+ * Monitors the USB devices.
+ *
+ * This method is the core of the background thread. It runs forever and does not terminate.
+ *
+ */
+ @Override
+ protected void monitorDevices() {
+
+ // as the method runs forever, there is no need to clean up one-time allocations
+ try (var session = MemorySession.openConfined()) {
+
+ // setup run loop, run loop source and notification port
+ var notifyPort = IoKit.IONotificationPortCreate(IoKit.kIOMasterPortDefault);
+ var runLoopSource = IoKit.IONotificationPortGetRunLoopSource(notifyPort);
+ var runLoop = CoreFoundation.CFRunLoopGetCurrent();
+ CoreFoundation.CFRunLoopAddSource(runLoop, runLoopSource, IoKit.kCFRunLoopDefaultMode);
+
+ // setup notification for connected devices
+ var onDeviceConnectedMH = MethodHandles.lookup().findVirtual(
+ MacosUSBDeviceRegistry.class, "onDevicesConnected",
+ MethodType.methodType(void.class, MemoryAddress.class, int.class));
+ int deviceConnectedIter = setupNotification(session, notifyPort, IoKit.kIOFirstMatchNotification, onDeviceConnectedMH);
+
+ // iterate current devices in order to arm the notifications (and build initial device list)
+ var deviceList = new ArrayList();
+ iterateDevices(deviceConnectedIter, false, (entryId, service) -> {
+ var deviceInfo = createDeviceInfo(entryId, service);
+ if (deviceInfo != null)
+ deviceList.add(deviceInfo);
+ });
+ setInitialDeviceList(deviceList);
+
+ // setup notification for disconnected devices
+ var onDeviceDisconnectedMH = MethodHandles.lookup().findVirtual(
+ MacosUSBDeviceRegistry.class, "onDevicesDisconnected",
+ MethodType.methodType(void.class, MemoryAddress.class, int.class));
+ int deviceDisconnectedIter = setupNotification(session, notifyPort, IoKit.kIOTerminatedNotification, onDeviceDisconnectedMH);
- public List getAllDevices() {
- return devices;
+ // iterate current devices in order to arm the notifications
+ onDevicesDisconnected(NULL, deviceDisconnectedIter);
+
+ // loop forever
+ CoreFoundation.CFRunLoopRun();
+
+ } catch (NoSuchMethodException | IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
}
/**
* Process the devices resulting from the iterator
*
- * @param iterator the iterator
+ * @param iterator the iterator
* @param isDisconnected flag is the iterator is for disconnected devices
- * @param function a function that will be called for each device with the entry ID and the service
+ * @param function a function that will be called for each device with the entry ID and the service
*/
private void iterateDevices(int iterator, boolean isDisconnected, BiConsumer function) {
@@ -98,57 +129,6 @@ private USBDeviceInfo createDeviceInfo(Long entryID, int service) {
return new MacosUSBDeviceInfo(entryID, vendorId, productId, manufacturer, product, serial, classCode, subclassCode, protocolCode);
}
- /**
- * Monitors the USB devices.
- *
- * This method is the core of the background thread. It runs forever and does not terminate.
- *
- */
- private void monitorDevices() {
-
- // as the method runs forever, there is no need to clean up one-time allocations
- try (var session = MemorySession.openConfined()) {
-
- // setup run loop, run loop source and notification port
- var notifyPort = IoKit.IONotificationPortCreate(IoKit.kIOMasterPortDefault);
- var runLoopSource = IoKit.IONotificationPortGetRunLoopSource(notifyPort);
- var runLoop = CoreFoundation.CFRunLoopGetCurrent();
- CoreFoundation.CFRunLoopAddSource(runLoop, runLoopSource, IoKit.kCFRunLoopDefaultMode);
-
- // setup notification for connected devices
- var onDeviceConnectedMH = MethodHandles.lookup().findVirtual(
- MacosUSBDeviceRegistry.class, "onDevicesConnected",
- MethodType.methodType(void.class, MemoryAddress.class, int.class));
- int deviceConnectedIter = setupNotification(session, notifyPort, IoKit.kIOFirstMatchNotification, onDeviceConnectedMH);
-
- // iterate current devices in order to arm the notifications (and build initial device list)
- devices = new ArrayList<>();
- iterateDevices(deviceConnectedIter, false, (entryId, service) -> {
- var deviceInfo = createDeviceInfo(entryId, service);
- if (deviceInfo != null)
- devices.add(deviceInfo);
- });
-
- // signal completion of initial device enumeration
- signalEnumerationComplete();
-
- // setup notification for disconnected devices
- var onDeviceDisconnectedMH = MethodHandles.lookup().findVirtual(
- MacosUSBDeviceRegistry.class, "onDevicesDisconnected",
- MethodType.methodType(void.class, MemoryAddress.class, int.class));
- int deviceDisconnectedIter = setupNotification(session, notifyPort, IoKit.kIOTerminatedNotification, onDeviceDisconnectedMH);
-
- // iterate current devices in order to arm the notifications
- onDevicesDisconnected(NULL, deviceDisconnectedIter);
-
- // loop forever
- CoreFoundation.CFRunLoopRun();
-
- } catch (NoSuchMethodException | IllegalAccessException e) {
- throw new RuntimeException(e);
- }
- }
-
private int setupNotification(MemorySession session, MemoryAddress notifyPort, MemorySegment notificationType, MethodHandle callback)
throws NoSuchMethodException, IllegalAccessException {
@@ -178,8 +158,9 @@ private int setupNotification(MemorySession session, MemoryAddress notifyPort, M
*
* This method is used in an upcall from native code.
*
+ *
* @param ignoredRefCon ignored parameter
- * @param iterator device iterator
+ * @param iterator device iterator
*/
private void onDevicesConnected(MemoryAddress ignoredRefCon, int iterator) {
@@ -196,8 +177,9 @@ private void onDevicesConnected(MemoryAddress ignoredRefCon, int iterator) {
*
* This method is used in an upcall from native code.
*
+ *
* @param ignoredRefCon ignored parameter
- * @param iterator device iterator
+ * @param iterator device iterator
*/
private void onDevicesDisconnected(MemoryAddress ignoredRefCon, int iterator) {
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
index 7fb8deab..8b75b901 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceRegistry.java
@@ -32,30 +32,64 @@
/**
* Windows implementation of USB device registry.
- *
- * This singleton class maintains a list of connected USB devices.
- * It starts a background thread monitoring the USB devices being
- * connected and disconnected.
- *
- *
- * The background thread also enumerates the already present devices
- * and builds the initial device list.
- *
*/
public class WindowsUSBDeviceRegistry extends USBDeviceRegistry {
- /**
- * Create new instance
- *
- * Starts a second thread and immediately iterates all USB devices.
- *
- */
- public WindowsUSBDeviceRegistry() {
- startDeviceMonitor(this::monitorDevices);
- }
+ @Override
+ protected void monitorDevices() {
+ try (var session = MemorySession.openConfined()) {
+
+ final var className = Win.createSegmentFromString("USB_MONITOR", session);
+ final var windowName = Win.createSegmentFromString("USB device monitor", session);
+ final var instance = Kernel32.GetModuleHandleW(NULL);
+
+ // create upcall for handling window messages
+ var handleWindowMessageMH = MethodHandles.lookup().findVirtual(
+ WindowsUSBDeviceRegistry.class,
+ "handleWindowMessage",
+ MethodType.methodType(long.class, MemoryAddress.class, int.class, long.class, long.class)
+ ).bindTo(this);
+ var handleWindowMessageStub = Linker.nativeLinker().upcallStub(
+ handleWindowMessageMH,
+ FunctionDescriptor.of(JAVA_LONG, ADDRESS, JAVA_INT, JAVA_LONG, JAVA_LONG),
+ session
+ );
- public List getAllDevices() {
- return devices;
+ // register window class
+ var wx = session.allocate(WNDCLASSEXW.$LAYOUT());
+ WNDCLASSEXW.cbSize$set(wx, (int) wx.byteSize());
+ WNDCLASSEXW.lpfnWndProc$set(wx, handleWindowMessageStub.address());
+ WNDCLASSEXW.hInstance$set(wx, instance);
+ WNDCLASSEXW.lpszClassName$set(wx, className.address());
+ User32.RegisterClassExW(wx);
+
+ // create message-only window
+ Addressable hwnd = User32.CreateWindowExW(0, className, windowName, 0,
+ 0, 0, 0, 0, User32.HWND_MESSAGE(), NULL, instance, NULL);
+ if (hwnd == NULL)
+ throw new USBException("internal error (CreateWindowExW)", Kernel32.GetLastError());
+
+ // configure notifications
+ var notificationFilter = session.allocate(DEV_BROADCAST_DEVICEINTERFACE_W.$LAYOUT());
+ DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_size$set(notificationFilter, (int) notificationFilter.byteSize());
+ DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_devicetype$set(notificationFilter, User32.DBT_DEVTYP_DEVICEINTERFACE());
+ DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_classguid$slice(notificationFilter).copyFrom(USBHelper.GUID_DEVINTERFACE_USB_DEVICE);
+
+ var notifyHandle = User32.RegisterDeviceNotificationW(hwnd, notificationFilter, User32.DEVICE_NOTIFY_WINDOW_HANDLE());
+ if (notifyHandle == NULL)
+ throw new USBException("internal error (RegisterDeviceNotificationW)", Kernel32.GetLastError());
+
+ // initial device enumeration
+ enumeratePresentDevices();
+
+ // process messages
+ var msg = session.allocate(MSG.$LAYOUT());
+ while (User32.GetMessageW(msg, hwnd, 0, 0) > 0)
+ ; // do nothing
+
+ } catch (NoSuchMethodException | IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
}
private void enumeratePresentDevices() {
@@ -96,7 +130,7 @@ private void enumeratePresentDevices() {
deviceList.add(createDeviceInfo(devInfoSetHandle, devInfo, devicePath, hubHandles));
}
- devices = deviceList;
+ setInitialDeviceList(deviceList);
}
}
@@ -198,66 +232,7 @@ private String getStringDescriptor(Addressable hubHandle, int usbPortNumber, int
}
}
- private void monitorDevices() {
- try (var session = MemorySession.openConfined()) {
-
- final var className = Win.createSegmentFromString("USB_MONITOR", session);
- final var windowName = Win.createSegmentFromString("USB device monitor", session);
- final var instance = Kernel32.GetModuleHandleW(NULL);
-
- // create upcall for handling window messages
- var handleWindowMessageMH = MethodHandles.lookup().findVirtual(
- WindowsUSBDeviceRegistry.class,
- "handleWindowMessage",
- MethodType.methodType(long.class, MemoryAddress.class, int.class, long.class, long.class)
- ).bindTo(this);
- var handleWindowMessageStub = Linker.nativeLinker().upcallStub(
- handleWindowMessageMH,
- FunctionDescriptor.of(JAVA_LONG, ADDRESS, JAVA_INT, JAVA_LONG, JAVA_LONG),
- session
- );
-
- // register window class
- var wx = session.allocate(WNDCLASSEXW.$LAYOUT());
- WNDCLASSEXW.cbSize$set(wx, (int) wx.byteSize());
- WNDCLASSEXW.lpfnWndProc$set(wx, handleWindowMessageStub.address());
- WNDCLASSEXW.hInstance$set(wx, instance);
- WNDCLASSEXW.lpszClassName$set(wx, className.address());
- User32.RegisterClassExW(wx);
-
- // create message-only window
- Addressable hwnd = User32.CreateWindowExW(0, className, windowName, 0,
- 0, 0, 0, 0, User32.HWND_MESSAGE(), NULL, instance, NULL);
- if (hwnd == NULL)
- throw new USBException("internal error (CreateWindowExW)", Kernel32.GetLastError());
-
- // configure notifications
- var notificationFilter = session.allocate(DEV_BROADCAST_DEVICEINTERFACE_W.$LAYOUT());
- DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_size$set(notificationFilter, (int) notificationFilter.byteSize());
- DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_devicetype$set(notificationFilter, User32.DBT_DEVTYP_DEVICEINTERFACE());
- DEV_BROADCAST_DEVICEINTERFACE_W.dbcc_classguid$slice(notificationFilter).copyFrom(USBHelper.GUID_DEVINTERFACE_USB_DEVICE);
-
- var notifyHandle = User32.RegisterDeviceNotificationW(hwnd, notificationFilter, User32.DEVICE_NOTIFY_WINDOW_HANDLE());
- if (notifyHandle == NULL)
- throw new USBException("internal error (RegisterDeviceNotificationW)", Kernel32.GetLastError());
-
- // initial device enumeration
- enumeratePresentDevices();
-
- // signal that the enumeration is complete
- signalEnumerationComplete();
-
- // process messages
- var msg = session.allocate(MSG.$LAYOUT());
- while (User32.GetMessageW(msg, hwnd, 0, 0) > 0)
- ; // do nothing
-
- } catch (NoSuchMethodException | IllegalAccessException e) {
- throw new RuntimeException(e);
- }
- }
-
- private long handleWindowMessage(MemoryAddress hWnd, int uMsg, long wParam, long lParam) {
+ private long handleWindowMessage(MemoryAddress hWnd, int uMsg, long wParam, long lParam) {
// check for message related to connecting/disconnecting devices
if (uMsg == User32.WM_DEVICECHANGE() && (wParam == User32.DBT_DEVICEARRIVAL() || wParam == User32.DBT_DEVICEREMOVECOMPLETE())) {
@@ -325,6 +300,17 @@ private void onDeviceDisconnected(String devicePath) {
removeDevice(devicePath);
}
+ /**
+ * Finds the index of the device in the list.
+ *
+ * This override uses a case-insensitive string comparison as Windows uses different casing
+ * when initially enumerating devices and during later monitoring.
+ *
+ *
+ * @param deviceList the device list
+ * @param deviceId the unique device ID
+ * @return index, or -1 if not found
+ */
@Override
protected int findDeviceIndex(List deviceList, Object deviceId) {
var id = deviceId.toString();
From 317e4289a38b0437b3f81f764fb832cae5d70715 Mon Sep 17 00:00:00 2001
From: Manuel Bleichenbacher
Date: Thu, 1 Sep 2022 20:27:49 +0200
Subject: [PATCH 031/433] Prepare for merge of USBDeviceInfo and USBDevice
---
.../codecrete/usb/common/USBDeviceImpl.java | 2 +
.../codecrete/usb/linux/LinuxUSBDevice.java | 22 ++++++---
.../usb/linux/LinuxUSBDeviceInfo.java | 4 +-
.../codecrete/usb/macos/MacosUSBDevice.java | 46 ++++++++++++-------
.../usb/macos/MacosUSBDeviceInfo.java | 4 +-
.../usb/windows/WindowsUSBDevice.java | 35 ++++++++++----
.../usb/windows/WindowsUSBDeviceInfo.java | 4 +-
7 files changed, 82 insertions(+), 35 deletions(-)
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceImpl.java b/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceImpl.java
index 833ac2d5..6ce61be5 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceImpl.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceImpl.java
@@ -44,6 +44,8 @@ protected USBDeviceImpl(
this.protocolCode = info.getProtocolCode();
}
+ public abstract void open();
+
public int getProductId() {
return productId;
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDevice.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDevice.java
index 119bc478..5bec9e65 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDevice.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDevice.java
@@ -26,10 +26,16 @@
public class LinuxUSBDevice extends USBDeviceImpl {
- private final int fd;
+ private int fd = -1;
LinuxUSBDevice(Object id, USBDeviceInfo info) {
super(id, info);
+ }
+
+ @Override
+ public void open() {
+ if (fd != -1)
+ return;
try (var session = MemorySession.openConfined()) {
var pathUtf8 = session.allocateUtf8String(id.toString());
@@ -39,6 +45,15 @@ public class LinuxUSBDevice extends USBDeviceImpl {
}
}
+ @Override
+ public void close() throws Exception {
+ if (fd == -1)
+ return;
+
+ unistd.close(fd);
+ fd = -1;
+ }
+
public void claimInterface(int interfaceNumber) {
try (var session = MemorySession.openConfined()) {
var intfNumSegment = session.allocate(JAVA_INT, interfaceNumber);
@@ -133,9 +148,4 @@ public byte[] transferIn(int endpointNumber, int maxLength) {
return buffer.asSlice(0, res).toArray(JAVA_BYTE);
}
}
-
- @Override
- public void close() throws Exception {
- unistd.close(fd);
- }
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceInfo.java b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceInfo.java
index 45f9fd75..0116715d 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceInfo.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceInfo.java
@@ -24,7 +24,9 @@ public class LinuxUSBDeviceInfo extends USBDeviceInfoImpl {
@Override
public USBDevice open() {
- return new LinuxUSBDevice(id, this);
+ var device = new LinuxUSBDevice(id, this);
+ device.open();
+ return device;
}
Object devicePath() {
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDevice.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDevice.java
index 3153465e..4b0a6929 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDevice.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDevice.java
@@ -25,18 +25,23 @@
public class MacosUSBDevice extends USBDeviceImpl {
- private final MemoryAddress device;
- private final int configurationValue;
+ private MemoryAddress device;
+ private int configurationValue;
private List claimedInterfaces;
private List endpoints;
MacosUSBDevice(Object id, USBDeviceInfo info) {
super(id, info);
+ }
+
+ @Override
+ public void open() {
+ if (device != null)
+ return;
try (var session = MemorySession.openConfined()) {
-// // get service from IO registry
-// final int service = IoKit.IORegistryEntryFromPath(0, path);
+ // get service from IO registry
var matching = IoKit.IORegistryEntryIDMatching((Long) id);
if (matching == NULL)
throw new MacosUSBException("IORegistryEntryIDMatching failed");
@@ -56,6 +61,7 @@ public class MacosUSBDevice extends USBDeviceImpl {
int ret = IoKitUSB.USBDeviceOpen(device);
if (ret != 0) {
IoKit.Release(device);
+ device = null;
throw new MacosUSBException("unable to open USB device", ret);
}
@@ -78,11 +84,30 @@ public class MacosUSBDevice extends USBDeviceImpl {
} catch (Throwable e) {
IoKitUSB.USBDeviceClose(device);
IoKit.Release(device);
+ device = null;
+ configurationValue = 0;
throw e;
}
}
}
+ @Override
+ public void close() throws Exception {
+ if (device == null)
+ return;
+
+ if (claimedInterfaces != null) {
+ for (InterfaceInfo interfaceInfo : claimedInterfaces) {
+ IoKitUSB.USBInterfaceClose(interfaceInfo.asMemoryAddress());
+ IoKit.Release(interfaceInfo.asMemoryAddress());
+ }
+ }
+
+ IoKitUSB.USBDeviceClose(device);
+ IoKit.Release(device);
+ device = null;
+ }
+
private InterfaceInfo findInterface(int interfaceNumber) {
try (var outerSession = MemorySession.openConfined()) {
@@ -292,19 +317,6 @@ public byte[] transferIn(int endpointNumber, int maxLength) {
}
}
- @Override
- public void close() throws Exception {
- if (claimedInterfaces != null) {
- for (InterfaceInfo interfaceInfo : claimedInterfaces) {
- IoKitUSB.USBInterfaceClose(interfaceInfo.asMemoryAddress());
- IoKit.Release(interfaceInfo.asMemoryAddress());
- }
- }
-
- IoKitUSB.USBDeviceClose(device);
- IoKit.Release(device);
- }
-
static class InterfaceInfo {
long addr;
int interfaceNumber;
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceInfo.java b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceInfo.java
index f988475b..18ff4ffb 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceInfo.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceInfo.java
@@ -24,7 +24,9 @@ public class MacosUSBDeviceInfo extends USBDeviceInfoImpl {
@Override
public USBDevice open() {
- return new MacosUSBDevice(id, this);
+ var device = new MacosUSBDevice(id, this);
+ device.open();
+ return device;
}
Object getId() {
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDevice.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDevice.java
index eeee50b1..a7354bb0 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDevice.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDevice.java
@@ -34,10 +34,10 @@
*/
public class WindowsUSBDevice extends USBDeviceImpl {
- private final MemoryAddress device;
- private final MemoryAddress firstInterface;
+ private MemoryAddress device;
+ private MemoryAddress firstInterface;
private final byte currentConfigurationValue;
- private final Configuration configuration;
+ private Configuration configuration;
private List claimedInterfaces;
@@ -45,6 +45,13 @@ public class WindowsUSBDevice extends USBDeviceImpl {
WindowsUSBDevice(Object id, USBDeviceInfo info, byte currentConfigurationValue) {
super(id, info);
this.currentConfigurationValue = currentConfigurationValue;
+ }
+
+ @Override
+ public void open() {
+
+ if (device != null)
+ return;
try (var session = MemorySession.openConfined()) {
@@ -81,11 +88,27 @@ public class WindowsUSBDevice extends USBDeviceImpl {
} catch (Throwable e) {
Kernel32.CloseHandle(device);
+ configuration = null;
+ firstInterface = null;
+ device = null;
throw e;
}
}
}
+
+ @Override
+ public void close() throws Exception {
+ if (device == null)
+ return;
+
+ WinUSB.WinUsb_Free(firstInterface);
+ firstInterface = null;
+ Kernel32.CloseHandle(device);
+ device = null;
+ configuration = null;
+ }
+
public void claimInterface(int interfaceNumber) {
var intfOptional =
configuration.interfaces.stream().filter(intf -> intf.number == interfaceNumber).findFirst();
@@ -197,10 +220,4 @@ public byte[] transferIn(int endpointNumber, int maxLength) {
return buffer.asSlice(0, len).toArray(JAVA_BYTE);
}
}
-
- @Override
- public void close() throws Exception {
- WinUSB.WinUsb_Free(firstInterface);
- Kernel32.CloseHandle(device);
- }
}
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceInfo.java b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceInfo.java
index b13b4420..cada0e64 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceInfo.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceInfo.java
@@ -28,6 +28,8 @@ public class WindowsUSBDeviceInfo extends USBDeviceInfoImpl {
@Override
public USBDevice open() {
- return new WindowsUSBDevice(id, this, currentConfigurationValue);
+ var device = new WindowsUSBDevice(id, this, currentConfigurationValue);
+ device.open();
+ return device;
}
}
From b43b8a2463c3f2fe02ac843500b84cf5e64c5ee3 Mon Sep 17 00:00:00 2001
From: Manuel Bleichenbacher
Date: Thu, 1 Sep 2022 22:52:53 +0200
Subject: [PATCH 032/433] Merge USBDeviceInfo and USBDevice
---
.../src/main/java/net/codecrete/usb/USB.java | 17 +--
.../java/net/codecrete/usb/USBDevice.java | 48 ++++---
.../net/codecrete/usb/USBDeviceFilter.java | 4 +-
.../java/net/codecrete/usb/USBDeviceInfo.java | 116 ---------------
.../codecrete/usb/common/USBDeviceImpl.java | 90 ++++++------
.../usb/common/USBDeviceInfoImpl.java | 136 ------------------
.../usb/common/USBDeviceRegistry.java | 43 +++---
.../codecrete/usb/linux/LinuxUSBDevice.java | 43 +++---
.../usb/linux/LinuxUSBDeviceInfo.java | 35 -----
.../usb/linux/LinuxUSBDeviceRegistry.java | 63 +++-----
.../codecrete/usb/macos/MacosUSBDevice.java | 94 ++++++------
.../usb/macos/MacosUSBDeviceInfo.java | 35 -----
.../usb/macos/MacosUSBDeviceRegistry.java | 58 ++++----
.../usb/windows/WindowsUSBDevice.java | 56 ++++----
.../usb/windows/WindowsUSBDeviceInfo.java | 35 -----
.../usb/windows/WindowsUSBDeviceRegistry.java | 100 +++++++------
.../net/codecrete/usb/BulkTransferTest.java | 6 +-
.../codecrete/usb/ControlTransferTest.java | 6 +-
.../codecrete/usb/DeviceEnumerationTest.java | 4 +-
.../net/codecrete/usb/IsSameDeviceTest.java | 46 ------
20 files changed, 295 insertions(+), 740 deletions(-)
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/USBDeviceInfo.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/common/USBDeviceInfoImpl.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/linux/LinuxUSBDeviceInfo.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceInfo.java
delete mode 100644 java-does-usb/src/main/java/net/codecrete/usb/windows/WindowsUSBDeviceInfo.java
delete mode 100644 java-does-usb/src/test/java/net/codecrete/usb/IsSameDeviceTest.java
diff --git a/java-does-usb/src/main/java/net/codecrete/usb/USB.java b/java-does-usb/src/main/java/net/codecrete/usb/USB.java
index 86cef6c9..1e8e4e97 100644
--- a/java-does-usb/src/main/java/net/codecrete/usb/USB.java
+++ b/java-does-usb/src/main/java/net/codecrete/usb/USB.java
@@ -33,7 +33,8 @@ private static USBDeviceRegistry createInstance() {
} else if (osName.equals("Linux") && (osArch.equals("amd64") || osArch.equals("aarch64"))) {
impl = new LinuxUSBDeviceRegistry();
} else {
- throw new UnsupportedOperationException(String.format("JavaCanDoUsb is not implemented for architecture %s/%s", osName, osArch));
+ throw new UnsupportedOperationException(String.format("JavaCanDoUsb is not implemented for architecture " +
+ "%s/%s", osName, osArch));
}
return impl;
}
@@ -62,7 +63,7 @@ private USB() {
*
* @return list of USB devices
*/
- public static List getAllDevices() {
+ public static List getAllDevices() {
return instance().getAllDevices();
}
@@ -72,7 +73,7 @@ public static List getAllDevices() {
* @param filter device filter
* @return list of USB devices
*/
- public static List getDevices(USBDeviceFilter filter) {
+ public static List getDevices(USBDeviceFilter filter) {
return instance().getAllDevices().stream().filter(filter::matches).collect(Collectors.toList());
}
@@ -82,7 +83,7 @@ public static List getDevices(USBDeviceFilter filter) {
* @param filters list of device filters
* @return list of USB devices
*/
- public static List getDevices(List filters) {
+ public static List getDevices(List filters) {
return instance().getAllDevices().stream().filter(dev -> USBDeviceFilter.matchesAny(dev, filters))
.collect(Collectors.toList());
}
@@ -93,7 +94,7 @@ public static List getDevices(List filters) {
* @param filter device filter
* @return USB device, or {@code null} if no device matches
*/
- public static USBDeviceInfo getDevice(USBDeviceFilter filter) {
+ public static USBDevice getDevice(USBDeviceFilter filter) {
return instance().getAllDevices().stream().filter(filter::matches).findFirst().orElse(null);
}
@@ -103,7 +104,7 @@ public static USBDeviceInfo getDevice(USBDeviceFilter filter) {
* @param filters list of device filters
* @return USB device, or {@code null} if no device matches
*/
- public static USBDeviceInfo getDevice(List |