diff --git a/src/java.base/macosx/classes/jdk/internal/ffi/generated/errno/errno_h$shared.java b/src/java.base/macosx/classes/jdk/internal/ffi/generated/errno/errno_h$shared.java new file mode 100644 index 0000000000000..dbb8f91ad920a --- /dev/null +++ b/src/java.base/macosx/classes/jdk/internal/ffi/generated/errno/errno_h$shared.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// Generated by jextract + +package jdk.internal.ffi.generated.errno; + +import java.lang.foreign.*; +import java.lang.invoke.*; +import java.util.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; + +@SuppressWarnings("restricted") +public class errno_h$shared { + + errno_h$shared() { + // Should not be called directly + } + + public static final OfBoolean C_BOOL = (OfBoolean) Linker.nativeLinker().canonicalLayouts().get("bool"); + public static final OfByte C_CHAR =(OfByte)Linker.nativeLinker().canonicalLayouts().get("char"); + public static final OfShort C_SHORT = (OfShort) Linker.nativeLinker().canonicalLayouts().get("short"); + public static final OfInt C_INT = (OfInt) Linker.nativeLinker().canonicalLayouts().get("int"); + public static final OfLong C_LONG_LONG = (OfLong) Linker.nativeLinker().canonicalLayouts().get("long long"); + public static final OfFloat C_FLOAT = (OfFloat) Linker.nativeLinker().canonicalLayouts().get("float"); + public static final OfDouble C_DOUBLE = (OfDouble) Linker.nativeLinker().canonicalLayouts().get("double"); + public static final AddressLayout C_POINTER = ((AddressLayout) Linker.nativeLinker().canonicalLayouts().get("void*")) + .withTargetLayout(MemoryLayout.sequenceLayout(Long.MAX_VALUE, C_CHAR)); + public static final OfLong C_LONG = (OfLong) Linker.nativeLinker().canonicalLayouts().get("long"); + + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); + + static void traceDowncall(String name, Object... args) { + String traceArgs = Arrays.stream(args) + .map(Object::toString) + .collect(Collectors.joining(", ")); + System.out.printf("%s(%s)\n", name, traceArgs); + } + + static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { + try { + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + + static MemoryLayout align(MemoryLayout layout, long align) { + return switch (layout) { + case PaddingLayout p -> p; + case ValueLayout v -> v.withByteAlignment(align); + case GroupLayout g -> { + MemoryLayout[] alignedMembers = g.memberLayouts().stream() + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); + yield g instanceof StructLayout ? + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); + } + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); + }; + } +} diff --git a/src/java.base/macosx/classes/jdk/internal/ffi/generated/errno/errno_h.java b/src/java.base/macosx/classes/jdk/internal/ffi/generated/errno/errno_h.java new file mode 100644 index 0000000000000..7fdc152e91338 --- /dev/null +++ b/src/java.base/macosx/classes/jdk/internal/ffi/generated/errno/errno_h.java @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// Generated by jextract + +package jdk.internal.ffi.generated.errno; + +import java.lang.foreign.*; +import java.lang.invoke.*; + +@SuppressWarnings("restricted") +public class errno_h extends errno_h$shared { + + errno_h() { + // Should not be called directly + } + + static final Arena LIBRARY_ARENA = Arena.ofAuto(); + + static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.loaderLookup() + .or(Linker.nativeLinker().defaultLookup()); + + private static final int EINTR = (int)4L; + /** + * {@snippet lang=c : + * #define EINTR 4 + * } + */ + public static int EINTR() { + return EINTR; + } + + private static class strerror_r { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + C_INT, + C_INT, + C_POINTER, + C_LONG + ); + + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("strerror_r"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int strerror_r(int __errnum, char *__strerrbuf, size_t __buflen) + * } + */ + public static FunctionDescriptor strerror_r$descriptor() { + return strerror_r.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int strerror_r(int __errnum, char *__strerrbuf, size_t __buflen) + * } + */ + public static MethodHandle strerror_r$handle() { + return strerror_r.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int strerror_r(int __errnum, char *__strerrbuf, size_t __buflen) + * } + */ + public static MemorySegment strerror_r$address() { + return strerror_r.ADDR; + } + + /** + * {@snippet lang=c : + * int strerror_r(int __errnum, char *__strerrbuf, size_t __buflen) + * } + */ + public static int strerror_r(int __errnum, MemorySegment __strerrbuf, long __buflen) { + var mh$ = strerror_r.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("strerror_r", __errnum, __strerrbuf, __buflen); + } + return (int)mh$.invokeExact(__errnum, __strerrbuf, __buflen); + } catch (Error | RuntimeException ex) { + throw ex; + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } +} diff --git a/src/java.base/macosx/classes/jdk/internal/ffi/generated/errno/package-info.java b/src/java.base/macosx/classes/jdk/internal/ffi/generated/errno/package-info.java new file mode 100644 index 0000000000000..2a29f198b2a78 --- /dev/null +++ b/src/java.base/macosx/classes/jdk/internal/ffi/generated/errno/package-info.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Defines native structures for errno APIs. + * Generated with the following jextract command: + * {@snippet lang = "Shell Script": + * + * HEADER_NAME=errno.h + * echo "#include " > $HEADER_NAME + * echo "#include " >> $HEADER_NAME + * + * jextract --target-package jdk.internal.ffi.generated.errno \ + * --include-constant EINTR \ + * --include-function strerror_r \ + * $HEADER_NAME + * } + * + */ + +package jdk.internal.ffi.generated.errno; diff --git a/src/java.base/macosx/classes/jdk/internal/ffi/generated/kqueue/kevent.java b/src/java.base/macosx/classes/jdk/internal/ffi/generated/kqueue/kevent.java new file mode 100644 index 0000000000000..22bbf57bcfa8e --- /dev/null +++ b/src/java.base/macosx/classes/jdk/internal/ffi/generated/kqueue/kevent.java @@ -0,0 +1,378 @@ +/* + * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// Generated by jextract + +package jdk.internal.ffi.generated.kqueue; + +import java.lang.foreign.*; +import java.util.function.*; + +import static java.lang.foreign.MemoryLayout.PathElement.*; +import static java.lang.foreign.ValueLayout.*; + +/** + * {@snippet lang=c : + * struct kevent { + * uintptr_t ident; + * int16_t filter; + * uint16_t flags; + * uint32_t fflags; + * intptr_t data; + * void *udata; + * } + * } + */ +@SuppressWarnings("restricted") +public class kevent { + + kevent() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + kqueue_h.align(kqueue_h.C_LONG, 4).withName("ident"), + kqueue_h.C_SHORT.withName("filter"), + kqueue_h.C_SHORT.withName("flags"), + kqueue_h.C_INT.withName("fflags"), + kqueue_h.align(kqueue_h.C_LONG, 4).withName("data"), + kqueue_h.align(kqueue_h.C_POINTER, 4).withName("udata") + ).withName("kevent"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfLong ident$LAYOUT = (OfLong)$LAYOUT.select(groupElement("ident")); + + /** + * Layout for field: + * {@snippet lang=c : + * uintptr_t ident + * } + */ + public static final OfLong ident$layout() { + return ident$LAYOUT; + } + + private static final long ident$OFFSET = $LAYOUT.byteOffset(groupElement("ident")); + + /** + * Offset for field: + * {@snippet lang=c : + * uintptr_t ident + * } + */ + public static final long ident$offset() { + return ident$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * uintptr_t ident + * } + */ + public static long ident(MemorySegment struct) { + return struct.get(ident$LAYOUT, ident$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * uintptr_t ident + * } + */ + public static void ident(MemorySegment struct, long fieldValue) { + struct.set(ident$LAYOUT, ident$OFFSET, fieldValue); + } + + private static final OfShort filter$LAYOUT = (OfShort)$LAYOUT.select(groupElement("filter")); + + /** + * Layout for field: + * {@snippet lang=c : + * int16_t filter + * } + */ + public static final OfShort filter$layout() { + return filter$LAYOUT; + } + + private static final long filter$OFFSET = $LAYOUT.byteOffset(groupElement("filter")); + + /** + * Offset for field: + * {@snippet lang=c : + * int16_t filter + * } + */ + public static final long filter$offset() { + return filter$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * int16_t filter + * } + */ + public static short filter(MemorySegment struct) { + return struct.get(filter$LAYOUT, filter$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * int16_t filter + * } + */ + public static void filter(MemorySegment struct, short fieldValue) { + struct.set(filter$LAYOUT, filter$OFFSET, fieldValue); + } + + private static final OfShort flags$LAYOUT = (OfShort)$LAYOUT.select(groupElement("flags")); + + /** + * Layout for field: + * {@snippet lang=c : + * uint16_t flags + * } + */ + public static final OfShort flags$layout() { + return flags$LAYOUT; + } + + private static final long flags$OFFSET = $LAYOUT.byteOffset(groupElement("flags")); + + /** + * Offset for field: + * {@snippet lang=c : + * uint16_t flags + * } + */ + public static final long flags$offset() { + return flags$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * uint16_t flags + * } + */ + public static short flags(MemorySegment struct) { + return struct.get(flags$LAYOUT, flags$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * uint16_t flags + * } + */ + public static void flags(MemorySegment struct, short fieldValue) { + struct.set(flags$LAYOUT, flags$OFFSET, fieldValue); + } + + private static final OfInt fflags$LAYOUT = (OfInt)$LAYOUT.select(groupElement("fflags")); + + /** + * Layout for field: + * {@snippet lang=c : + * uint32_t fflags + * } + */ + public static final OfInt fflags$layout() { + return fflags$LAYOUT; + } + + private static final long fflags$OFFSET = $LAYOUT.byteOffset(groupElement("fflags")); + + /** + * Offset for field: + * {@snippet lang=c : + * uint32_t fflags + * } + */ + public static final long fflags$offset() { + return fflags$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * uint32_t fflags + * } + */ + public static int fflags(MemorySegment struct) { + return struct.get(fflags$LAYOUT, fflags$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * uint32_t fflags + * } + */ + public static void fflags(MemorySegment struct, int fieldValue) { + struct.set(fflags$LAYOUT, fflags$OFFSET, fieldValue); + } + + private static final OfLong data$LAYOUT = (OfLong)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * intptr_t data + * } + */ + public static final OfLong data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = $LAYOUT.byteOffset(groupElement("data")); + + /** + * Offset for field: + * {@snippet lang=c : + * intptr_t data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * intptr_t data + * } + */ + public static long data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * intptr_t data + * } + */ + public static void data(MemorySegment struct, long fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final AddressLayout udata$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("udata")); + + /** + * Layout for field: + * {@snippet lang=c : + * void *udata + * } + */ + public static final AddressLayout udata$layout() { + return udata$LAYOUT; + } + + private static final long udata$OFFSET = $LAYOUT.byteOffset(groupElement("udata")); + + /** + * Offset for field: + * {@snippet lang=c : + * void *udata + * } + */ + public static final long udata$offset() { + return udata$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * void *udata + * } + */ + public static MemorySegment udata(MemorySegment struct) { + return struct.get(udata$LAYOUT, udata$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * void *udata + * } + */ + public static void udata(MemorySegment struct, MemorySegment fieldValue) { + struct.set(udata$LAYOUT, udata$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} diff --git a/src/java.base/macosx/classes/jdk/internal/ffi/generated/kqueue/kqueue_h$shared.java b/src/java.base/macosx/classes/jdk/internal/ffi/generated/kqueue/kqueue_h$shared.java new file mode 100644 index 0000000000000..662916d4e8d99 --- /dev/null +++ b/src/java.base/macosx/classes/jdk/internal/ffi/generated/kqueue/kqueue_h$shared.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// Generated by jextract + +package jdk.internal.ffi.generated.kqueue; + +import java.lang.foreign.*; +import java.lang.invoke.*; +import java.util.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; + +@SuppressWarnings("restricted") +public class kqueue_h$shared { + + kqueue_h$shared() { + // Should not be called directly + } + + public static final OfBoolean C_BOOL = (OfBoolean) Linker.nativeLinker().canonicalLayouts().get("bool"); + public static final OfByte C_CHAR =(OfByte)Linker.nativeLinker().canonicalLayouts().get("char"); + public static final OfShort C_SHORT = (OfShort) Linker.nativeLinker().canonicalLayouts().get("short"); + public static final OfInt C_INT = (OfInt) Linker.nativeLinker().canonicalLayouts().get("int"); + public static final OfLong C_LONG_LONG = (OfLong) Linker.nativeLinker().canonicalLayouts().get("long long"); + public static final OfFloat C_FLOAT = (OfFloat) Linker.nativeLinker().canonicalLayouts().get("float"); + public static final OfDouble C_DOUBLE = (OfDouble) Linker.nativeLinker().canonicalLayouts().get("double"); + public static final AddressLayout C_POINTER = ((AddressLayout) Linker.nativeLinker().canonicalLayouts().get("void*")) + .withTargetLayout(MemoryLayout.sequenceLayout(Long.MAX_VALUE, C_CHAR)); + public static final OfLong C_LONG = (OfLong) Linker.nativeLinker().canonicalLayouts().get("long"); + + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); + + static void traceDowncall(String name, Object... args) { + String traceArgs = Arrays.stream(args) + .map(Object::toString) + .collect(Collectors.joining(", ")); + System.out.printf("%s(%s)\n", name, traceArgs); + } + + static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { + try { + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + + static MemoryLayout align(MemoryLayout layout, long align) { + return switch (layout) { + case PaddingLayout p -> p; + case ValueLayout v -> v.withByteAlignment(align); + case GroupLayout g -> { + MemoryLayout[] alignedMembers = g.memberLayouts().stream() + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); + yield g instanceof StructLayout ? + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); + } + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); + }; + } +} diff --git a/src/java.base/macosx/classes/jdk/internal/ffi/generated/kqueue/kqueue_h.java b/src/java.base/macosx/classes/jdk/internal/ffi/generated/kqueue/kqueue_h.java new file mode 100644 index 0000000000000..2ba04f53ea86d --- /dev/null +++ b/src/java.base/macosx/classes/jdk/internal/ffi/generated/kqueue/kqueue_h.java @@ -0,0 +1,222 @@ +/* + * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// Generated by jextract + +package jdk.internal.ffi.generated.kqueue; + +import java.lang.foreign.*; +import java.lang.invoke.*; + +@SuppressWarnings("restricted") +public class kqueue_h extends kqueue_h$shared { + + kqueue_h() { + // Should not be called directly + } + + static final Arena LIBRARY_ARENA = Arena.ofAuto(); + + static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.loaderLookup() + .or(Linker.nativeLinker().defaultLookup()); + + private static final int EV_ADD = (int)1L; + /** + * {@snippet lang=c : + * #define EV_ADD 1 + * } + */ + public static int EV_ADD() { + return EV_ADD; + } + private static final int EV_DELETE = (int)2L; + /** + * {@snippet lang=c : + * #define EV_DELETE 2 + * } + */ + public static int EV_DELETE() { + return EV_DELETE; + } + private static final int EV_ONESHOT = (int)16L; + /** + * {@snippet lang=c : + * #define EV_ONESHOT 16 + * } + */ + public static int EV_ONESHOT() { + return EV_ONESHOT; + } + private static final int EV_CLEAR = (int)32L; + /** + * {@snippet lang=c : + * #define EV_CLEAR 32 + * } + */ + public static int EV_CLEAR() { + return EV_CLEAR; + } + + private static class kqueue { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + kqueue_h.C_INT ); + + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("kqueue"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int kqueue() + * } + */ + public static FunctionDescriptor kqueue$descriptor() { + return kqueue.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int kqueue() + * } + */ + public static MethodHandle kqueue$handle() { + return kqueue.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int kqueue() + * } + */ + public static MemorySegment kqueue$address() { + return kqueue.ADDR; + } + + /** + * {@snippet lang=c : + * int kqueue() + * } + */ + public static int kqueue() { + var mh$ = kqueue.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("kqueue"); + } + return (int)mh$.invokeExact(); + } catch (Error | RuntimeException ex) { + throw ex; + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class kevent { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + kqueue_h.C_INT, + kqueue_h.C_INT, + kqueue_h.C_POINTER, + kqueue_h.C_INT, + kqueue_h.C_POINTER, + kqueue_h.C_INT, + kqueue_h.C_POINTER + ); + + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("kevent"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int kevent(int kq, const struct kevent *changelist, int nchanges, struct kevent *eventlist, int nevents, const struct timespec *timeout) + * } + */ + public static FunctionDescriptor kevent$descriptor() { + return kevent.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int kevent(int kq, const struct kevent *changelist, int nchanges, struct kevent *eventlist, int nevents, const struct timespec *timeout) + * } + */ + public static MethodHandle kevent$handle() { + return kevent.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int kevent(int kq, const struct kevent *changelist, int nchanges, struct kevent *eventlist, int nevents, const struct timespec *timeout) + * } + */ + public static MemorySegment kevent$address() { + return kevent.ADDR; + } + + /** + * {@snippet lang=c : + * int kevent(int kq, const struct kevent *changelist, int nchanges, struct kevent *eventlist, int nevents, const struct timespec *timeout) + * } + */ + public static int kevent(int kq, MemorySegment changelist, int nchanges, MemorySegment eventlist, int nevents, MemorySegment timeout) { + var mh$ = kevent.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("kevent", kq, changelist, nchanges, eventlist, nevents, timeout); + } + return (int)mh$.invokeExact(kq, changelist, nchanges, eventlist, nevents, timeout); + } catch (Error | RuntimeException ex) { + throw ex; + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + private static final int EVFILT_READ = (int)-1L; + /** + * {@snippet lang=c : + * #define EVFILT_READ -1 + * } + */ + public static int EVFILT_READ() { + return EVFILT_READ; + } + private static final int EVFILT_WRITE = (int)-2L; + /** + * {@snippet lang=c : + * #define EVFILT_WRITE -2 + * } + */ + public static int EVFILT_WRITE() { + return EVFILT_WRITE; + } +} diff --git a/src/java.base/macosx/classes/jdk/internal/ffi/generated/kqueue/package-info.java b/src/java.base/macosx/classes/jdk/internal/ffi/generated/kqueue/package-info.java new file mode 100644 index 0000000000000..ce372c87b749e --- /dev/null +++ b/src/java.base/macosx/classes/jdk/internal/ffi/generated/kqueue/package-info.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Defines native structures for Kqueue socket APIs. + * Generated with the following jextract command: + * {@snippet lang = "Shell Script": + * + * HEADER_NAME=kqueue.h + * echo "#include " > $HEADER_NAME + * echo "#include " >> $HEADER_NAME + * + * + * jextract --target-package jdk.internal.ffi.generated.kqueue \ + * --include-constant EV_CLEAR \ + * --include-constant EV_ONESHOT \ + * --include-constant EV_DELETE \ + * --include-constant EV_ADD \ + * --include-constant EVFILT_WRITE \ + * --include-constant EVFILT_READ \ + * --include-function kevent \ + * --include-function kqueue \ + * --include-struct kevent \ + * $HEADER_NAME + * } + * + */ + +package jdk.internal.ffi.generated.kqueue; diff --git a/src/java.base/macosx/classes/jdk/internal/ffi/generated/timespec/package-info.java b/src/java.base/macosx/classes/jdk/internal/ffi/generated/timespec/package-info.java new file mode 100644 index 0000000000000..850991e61fc51 --- /dev/null +++ b/src/java.base/macosx/classes/jdk/internal/ffi/generated/timespec/package-info.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Defines native structures for timespec APIs. + * Generated with the following jextract command: + * {@snippet lang = "Shell Script": + * + * HEADER_NAME=timespec.h + * echo "#include " > $HEADER_NAME + * + * jextract --target-package jdk.internal.ffi.generated.timespec \ + * --include-struct timespec \ + * $HEADER_NAME + * } + * + */ + +package jdk.internal.ffi.generated.timespec; diff --git a/src/java.base/macosx/classes/jdk/internal/ffi/generated/timespec/timespec.java b/src/java.base/macosx/classes/jdk/internal/ffi/generated/timespec/timespec.java new file mode 100644 index 0000000000000..bee0caf26fc5c --- /dev/null +++ b/src/java.base/macosx/classes/jdk/internal/ffi/generated/timespec/timespec.java @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// Generated by jextract + +package jdk.internal.ffi.generated.timespec; + +import java.lang.foreign.*; +import java.util.function.*; + +import static java.lang.foreign.MemoryLayout.PathElement.*; +import static java.lang.foreign.ValueLayout.*; + +/** + * {@snippet lang=c : + * struct timespec { + * __darwin_time_t tv_sec; + * long tv_nsec; + * } + * } + */ +@SuppressWarnings("restricted") +public class timespec { + + timespec() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + timespec_h.C_LONG.withName("tv_sec"), + timespec_h.C_LONG.withName("tv_nsec") + ).withName("timespec"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfLong tv_sec$LAYOUT = (OfLong)$LAYOUT.select(groupElement("tv_sec")); + + /** + * Layout for field: + * {@snippet lang=c : + * __darwin_time_t tv_sec + * } + */ + public static final OfLong tv_sec$layout() { + return tv_sec$LAYOUT; + } + + private static final long tv_sec$OFFSET = $LAYOUT.byteOffset(groupElement("tv_sec")); + + /** + * Offset for field: + * {@snippet lang=c : + * __darwin_time_t tv_sec + * } + */ + public static final long tv_sec$offset() { + return tv_sec$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * __darwin_time_t tv_sec + * } + */ + public static long tv_sec(MemorySegment struct) { + return struct.get(tv_sec$LAYOUT, tv_sec$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * __darwin_time_t tv_sec + * } + */ + public static void tv_sec(MemorySegment struct, long fieldValue) { + struct.set(tv_sec$LAYOUT, tv_sec$OFFSET, fieldValue); + } + + private static final OfLong tv_nsec$LAYOUT = (OfLong)$LAYOUT.select(groupElement("tv_nsec")); + + /** + * Layout for field: + * {@snippet lang=c : + * long tv_nsec + * } + */ + public static final OfLong tv_nsec$layout() { + return tv_nsec$LAYOUT; + } + + private static final long tv_nsec$OFFSET = $LAYOUT.byteOffset(groupElement("tv_nsec")); + + /** + * Offset for field: + * {@snippet lang=c : + * long tv_nsec + * } + */ + public static final long tv_nsec$offset() { + return tv_nsec$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * long tv_nsec + * } + */ + public static long tv_nsec(MemorySegment struct) { + return struct.get(tv_nsec$LAYOUT, tv_nsec$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * long tv_nsec + * } + */ + public static void tv_nsec(MemorySegment struct, long fieldValue) { + struct.set(tv_nsec$LAYOUT, tv_nsec$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} diff --git a/src/java.base/macosx/classes/jdk/internal/ffi/generated/timespec/timespec_h$shared.java b/src/java.base/macosx/classes/jdk/internal/ffi/generated/timespec/timespec_h$shared.java new file mode 100644 index 0000000000000..6af5bb12e0c3a --- /dev/null +++ b/src/java.base/macosx/classes/jdk/internal/ffi/generated/timespec/timespec_h$shared.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// Generated by jextract + +package jdk.internal.ffi.generated.timespec; + +import java.lang.foreign.*; +import java.lang.invoke.*; +import java.util.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; + +@SuppressWarnings("restricted") +public class timespec_h$shared { + + timespec_h$shared() { + // Should not be called directly + } + + public static final OfBoolean C_BOOL = (OfBoolean) Linker.nativeLinker().canonicalLayouts().get("bool"); + public static final OfByte C_CHAR =(OfByte)Linker.nativeLinker().canonicalLayouts().get("char"); + public static final OfShort C_SHORT = (OfShort) Linker.nativeLinker().canonicalLayouts().get("short"); + public static final OfInt C_INT = (OfInt) Linker.nativeLinker().canonicalLayouts().get("int"); + public static final OfLong C_LONG_LONG = (OfLong) Linker.nativeLinker().canonicalLayouts().get("long long"); + public static final OfFloat C_FLOAT = (OfFloat) Linker.nativeLinker().canonicalLayouts().get("float"); + public static final OfDouble C_DOUBLE = (OfDouble) Linker.nativeLinker().canonicalLayouts().get("double"); + public static final AddressLayout C_POINTER = ((AddressLayout) Linker.nativeLinker().canonicalLayouts().get("void*")) + .withTargetLayout(MemoryLayout.sequenceLayout(Long.MAX_VALUE, C_CHAR)); + public static final OfLong C_LONG = (OfLong) Linker.nativeLinker().canonicalLayouts().get("long"); + + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); + + static void traceDowncall(String name, Object... args) { + String traceArgs = Arrays.stream(args) + .map(Object::toString) + .collect(Collectors.joining(", ")); + System.out.printf("%s(%s)\n", name, traceArgs); + } + + static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { + try { + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + + static MemoryLayout align(MemoryLayout layout, long align) { + return switch (layout) { + case PaddingLayout p -> p; + case ValueLayout v -> v.withByteAlignment(align); + case GroupLayout g -> { + MemoryLayout[] alignedMembers = g.memberLayouts().stream() + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); + yield g instanceof StructLayout ? + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); + } + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); + }; + } +} diff --git a/src/java.base/macosx/classes/jdk/internal/ffi/generated/timespec/timespec_h.java b/src/java.base/macosx/classes/jdk/internal/ffi/generated/timespec/timespec_h.java new file mode 100644 index 0000000000000..e1470fcf43f67 --- /dev/null +++ b/src/java.base/macosx/classes/jdk/internal/ffi/generated/timespec/timespec_h.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// Generated by jextract + +package jdk.internal.ffi.generated.timespec; + +import java.lang.foreign.*; + +public class timespec_h extends timespec_h$shared { + + timespec_h() { + // Should not be called directly + } + + static final Arena LIBRARY_ARENA = Arena.ofAuto(); + + static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.loaderLookup() + .or(Linker.nativeLinker().defaultLookup()); + +}