Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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));
};
}
}
Original file line number Diff line number Diff line change
@@ -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$);
}
}
}
Original file line number Diff line number Diff line change
@@ -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 <errno.h>" > $HEADER_NAME
* echo "#include <string.h>" >> $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;
Loading