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
50 changes: 50 additions & 0 deletions resources/bundles/org.eclipse.core.filesystem/generateLinuxH.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/sh
# Regenerates the glibc bindings in src-gen. Needs jextract on the PATH,
# https://jdk.java.net/jextract/, and has to run on Linux.
#
# No --library: that would emit libraryLookup("libc.so"), which cannot be opened
# on glibc, where the library is libc.so.6. Without it the generated lookup falls
# back to the linker's default lookup, which already sees libc.
set -eu
cd "$(dirname "$0")"

cat > /tmp/LibC.h <<'HEADER'
#define _GNU_SOURCE
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <linux/stat.h>
#include <sys/stat.h>
#include <unistd.h>
HEADER

jextract --output src-gen \
--include-function statx \
--include-function opendir \
--include-function readdir \
--include-function closedir \
--include-function dirfd \
--include-function readlinkat \
--include-function chmod \
--include-struct statx \
--include-struct statx_timestamp \
--include-struct dirent \
--include-constant AT_FDCWD \
--include-constant AT_SYMLINK_NOFOLLOW \
--include-constant AT_STATX_SYNC_AS_STAT \
--include-constant STATX_TYPE \
--include-constant STATX_MODE \
--include-constant STATX_SIZE \
--include-constant STATX_MTIME \
--include-constant ENOENT \
--include-constant PATH_MAX \
--include-constant S_IFMT \
--include-constant S_IFDIR \
--include-constant S_IFLNK \
--include-constant S_IRUSR --include-constant S_IWUSR --include-constant S_IXUSR \
--include-constant S_IRGRP --include-constant S_IWGRP --include-constant S_IXGRP \
--include-constant S_IROTH --include-constant S_IWOTH --include-constant S_IXOTH \
--target-package org.linux \
--header-class-name LibC \
/tmp/LibC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Generated by jextract

package org.linux;

import java.lang.invoke.*;
import java.lang.foreign.*;
import java.nio.ByteOrder;

Check warning on line 7 in resources/bundles/org.eclipse.core.filesystem/src-gen/org/linux/LibC$shared.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

Unnecessary Code

NORMAL: The import java.nio.ByteOrder is never used
import java.util.*;
import java.util.function.*;

Check warning on line 9 in resources/bundles/org.eclipse.core.filesystem/src-gen/org/linux/LibC$shared.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

Unnecessary Code

NORMAL: The import java.util.function is never used
import java.util.stream.*;

import static java.lang.foreign.ValueLayout.*;

Check warning on line 12 in resources/bundles/org.eclipse.core.filesystem/src-gen/org/linux/LibC$shared.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

Unnecessary Code

NORMAL: The import java.lang.foreign.ValueLayout is never used
import static java.lang.foreign.MemoryLayout.PathElement.*;

Check warning on line 13 in resources/bundles/org.eclipse.core.filesystem/src-gen/org/linux/LibC$shared.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

Unnecessary Code

NORMAL: The import java.lang.foreign.MemoryLayout.PathElement is never used

public class LibC$shared {

LibC$shared() {
// Should not be called directly
}

public static final ValueLayout.OfBoolean C_BOOL = (ValueLayout.OfBoolean) Linker.nativeLinker().canonicalLayouts().get("bool");

Check warning on line 21 in resources/bundles/org.eclipse.core.filesystem/src-gen/org/linux/LibC$shared.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

NLS

NORMAL: $ Non-externalized string literal; it should be followed by //$NON-NLS-
public static final ValueLayout.OfByte C_CHAR =(ValueLayout.OfByte)Linker.nativeLinker().canonicalLayouts().get("char");

Check warning on line 22 in resources/bundles/org.eclipse.core.filesystem/src-gen/org/linux/LibC$shared.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

NLS

NORMAL: $ Non-externalized string literal; it should be followed by //$NON-NLS-
public static final ValueLayout.OfShort C_SHORT = (ValueLayout.OfShort) Linker.nativeLinker().canonicalLayouts().get("short");

Check warning on line 23 in resources/bundles/org.eclipse.core.filesystem/src-gen/org/linux/LibC$shared.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

NLS

NORMAL: $ Non-externalized string literal; it should be followed by //$NON-NLS-
public static final ValueLayout.OfInt C_INT = (ValueLayout.OfInt) Linker.nativeLinker().canonicalLayouts().get("int");

Check warning on line 24 in resources/bundles/org.eclipse.core.filesystem/src-gen/org/linux/LibC$shared.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

NLS

NORMAL: $ Non-externalized string literal; it should be followed by //$NON-NLS-
public static final ValueLayout.OfLong C_LONG_LONG = (ValueLayout.OfLong) Linker.nativeLinker().canonicalLayouts().get("long long");

Check warning on line 25 in resources/bundles/org.eclipse.core.filesystem/src-gen/org/linux/LibC$shared.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

NLS

NORMAL: $ Non-externalized string literal; it should be followed by //$NON-NLS-
public static final ValueLayout.OfFloat C_FLOAT = (ValueLayout.OfFloat) Linker.nativeLinker().canonicalLayouts().get("float");

Check warning on line 26 in resources/bundles/org.eclipse.core.filesystem/src-gen/org/linux/LibC$shared.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

NLS

NORMAL: $ Non-externalized string literal; it should be followed by //$NON-NLS-
public static final ValueLayout.OfDouble C_DOUBLE = (ValueLayout.OfDouble) Linker.nativeLinker().canonicalLayouts().get("double");

Check warning on line 27 in resources/bundles/org.eclipse.core.filesystem/src-gen/org/linux/LibC$shared.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

NLS

NORMAL: $ Non-externalized string literal; it should be followed by //$NON-NLS-
public static final AddressLayout C_POINTER = ((AddressLayout) Linker.nativeLinker().canonicalLayouts().get("void*"))

Check warning on line 28 in resources/bundles/org.eclipse.core.filesystem/src-gen/org/linux/LibC$shared.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

NLS

NORMAL: $ Non-externalized string literal; it should be followed by //$NON-NLS-
.withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, C_CHAR));
public static final ValueLayout.OfLong C_LONG = (ValueLayout.OfLong) Linker.nativeLinker().canonicalLayouts().get("long");

Check warning on line 30 in resources/bundles/org.eclipse.core.filesystem/src-gen/org/linux/LibC$shared.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

NLS

NORMAL: $ Non-externalized string literal; it should be followed by //$NON-NLS-

static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls");

Check warning on line 32 in resources/bundles/org.eclipse.core.filesystem/src-gen/org/linux/LibC$shared.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

NLS

NORMAL: $ Non-externalized string literal; it should be followed by //$NON-NLS-

static void traceDowncall(String name, Object... args) {
String traceArgs = Arrays.stream(args)
.map(Object::toString)
.collect(Collectors.joining(", "));

Check warning on line 37 in resources/bundles/org.eclipse.core.filesystem/src-gen/org/linux/LibC$shared.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

NLS

NORMAL: $ Non-externalized string literal; it should be followed by //$NON-NLS-
System.out.printf("%s(%s)\n", name, traceArgs);

Check warning on line 38 in resources/bundles/org.eclipse.core.filesystem/src-gen/org/linux/LibC$shared.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

NLS

NORMAL: $ Non-externalized string literal; it should be followed by //$NON-NLS-
}

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));
};
}
}

Loading
Loading