Skip to content

Commit 2ea1552

Browse files
committed
Fix fstat call in darwin-aarch64.
1 parent 3eeeae8 commit 2ea1552

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixStat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static boolean isOpen(int fd) {
4545
result = LinuxStat.fstat64(fd, stat);
4646
} else if (Platform.includedIn(Platform.DARWIN.class)) {
4747
DarwinStat.stat stat = StackValue.get(DarwinStat.stat.class);
48-
result = DarwinStat.fstat(fd, stat);
48+
result = DarwinStat.fstat_aarch64(fd, stat);
4949
} else {
5050
throw VMError.shouldNotReachHere("Unsupported platform");
5151
}

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinStat.java

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
*/
2525
package com.oracle.svm.core.posix.headers.darwin;
2626

27+
import com.oracle.svm.core.util.VMError;
28+
import org.graalvm.nativeimage.Platform;
29+
import org.graalvm.nativeimage.Platforms;
2730
import org.graalvm.nativeimage.c.CContext;
2831
import org.graalvm.nativeimage.c.function.CFunction;
2932
import org.graalvm.nativeimage.c.struct.CField;
@@ -53,10 +56,42 @@ public interface stat extends PointerBase {
5356
}
5457

5558
@CFunction("fstat$INODE64")
56-
public static native int fstat(int fd, stat buf);
59+
@Platforms({Platform.DARWIN_AMD64.class})
60+
public static native int fstat_amd64(int fd, stat buf);
61+
62+
@CFunction("fstat")
63+
@Platforms({Platform.DARWIN_AARCH64.class})
64+
public static native int fstat_aarch64(int fd, stat buf);
65+
66+
@Platforms(Platform.DARWIN.class)
67+
public static int fstat(int fd, stat buf) {
68+
if (Platform.includedIn(Platform.AMD64.class)) {
69+
return fstat_amd64(fd, buf);
70+
} else if (Platform.includedIn(Platform.AARCH64.class)) {
71+
return fstat_aarch64(fd, buf);
72+
} else {
73+
throw VMError.shouldNotReachHere();
74+
}
75+
}
5776

5877
public static class NoTransitions {
5978
@CFunction(value = "fstat$INODE64", transition = CFunction.Transition.NO_TRANSITION)
60-
public static native int fstat(int fd, stat buf);
79+
@Platforms({Platform.DARWIN_AMD64.class})
80+
public static native int fstat_amd64(int fd, stat buf);
81+
82+
@CFunction(value = "fstat", transition = CFunction.Transition.NO_TRANSITION)
83+
@Platforms({Platform.DARWIN_AARCH64.class})
84+
public static native int fstat_aarch64(int fd, stat buf);
85+
86+
@Platforms(Platform.DARWIN.class)
87+
public static int fstat(int fd, stat buf) {
88+
if (Platform.includedIn(Platform.AMD64.class)) {
89+
return fstat_amd64(fd, buf);
90+
} else if (Platform.includedIn(Platform.AARCH64.class)) {
91+
return fstat_aarch64(fd, buf);
92+
} else {
93+
throw VMError.shouldNotReachHere();
94+
}
95+
}
6196
}
6297
}

0 commit comments

Comments
 (0)