Skip to content

Commit

Permalink
another try
Browse files Browse the repository at this point in the history
  • Loading branch information
rjernst committed Jul 10, 2024
1 parent 9439fdd commit 080c02e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ private interface NativeFunctions extends Library {
}

private interface FStat64Function extends Library {
int fstat(int fd, Pointer stat);
int fstat64(int fd, Pointer stat);
}
private interface FXStatFunction extends Library {
int __fxstat(int version, int fd, Pointer stat);
}

private final NativeFunctions functions;
Expand All @@ -144,11 +147,9 @@ private interface FStat64Function extends Library {
fstat64 = Native.load("c", FStat64Function.class);
} catch (UnsatisfiedLinkError e) {
// TODO: explain
fstat64 = Native.load(
"c",
FStat64Function.class,
Map.of(Library.OPTION_FUNCTION_MAPPER, (FunctionMapper) (lib, method) -> "__fxsta4")
);
var fxstat = Native.load("c", FXStatFunction.class);
int fstat_version = System.getProperty("os.arch").equals("aarch64") ? 0 : 1;
fstat64 = (fd, stat) -> fxstat.__fxstat(fstat_version, fd, stat);
}
this.fstat64 = fstat64;
}
Expand Down Expand Up @@ -223,7 +224,7 @@ public int close(int fd) {
public int fstat64(int fd, Stat64 stats) {
assert stats instanceof JnaStat64;
var jnaStats = (JnaStat64) stats;
return fstat64.fstat(fd, jnaStats.memory);
return fstat64.fstat64(fd, jnaStats.memory);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.lang.foreign.MemorySegment;
import java.lang.foreign.StructLayout;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;

import static java.lang.foreign.MemoryLayout.PathElement.groupElement;
Expand Down Expand Up @@ -67,11 +68,12 @@ class JdkPosixCLibrary implements PosixCLibrary {
static {
MethodHandle fstat;
try {
fstat = downcallHandleWithErrno("fstat", FunctionDescriptor.of(JAVA_INT, JAVA_INT, ADDRESS));
fstat = downcallHandleWithErrno("fstat64", FunctionDescriptor.of(JAVA_INT, JAVA_INT, ADDRESS));
} catch (LinkageError e) {
// Due to different sizes of the stat structure for 32 vs 64 bit machines, on some systems fstat actually points to
// an internal symbol. So we fall back to looking for that symbol.
fstat = downcallHandleWithErrno("__fxstat", FunctionDescriptor.of(JAVA_INT, JAVA_INT, ADDRESS));
int fstat_version = System.getProperty("os.arch").equals("aarch64") ? 0 : 1;
fstat = MethodHandles.insertArguments(downcallHandleWithErrno("__fxstat", FunctionDescriptor.of(JAVA_INT, JAVA_INT, JAVA_INT, ADDRESS)), 1, fstat_version);
}
fstat$mh = fstat;
}
Expand Down

0 comments on commit 080c02e

Please sign in to comment.