diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixLogHandler.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixLogHandler.java index f66e2e9782db..f373ff45425c 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixLogHandler.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixLogHandler.java @@ -26,20 +26,17 @@ import java.io.FileDescriptor; -import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.LogHandler; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.type.CCharPointer; -import org.graalvm.nativeimage.impl.InternalPlatform; +import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.word.UnsignedWord; +import com.oracle.svm.core.CErrorNumber; import com.oracle.svm.core.annotate.AutomaticFeature; -import com.oracle.svm.core.headers.Errno; import com.oracle.svm.core.posix.headers.LibC; @AutomaticFeature -@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) class PosixLogHandlerFeature implements Feature { @Override public void beforeAnalysis(BeforeAnalysisAccess access) { @@ -60,7 +57,7 @@ public class PosixLogHandler implements LogHandler { @Override public void log(CCharPointer bytes, UnsignedWord length) { /* Save and restore errno around calls that would otherwise change errno. */ - final int savedErrno = Errno.errno(); + final int savedErrno = CErrorNumber.getCErrorNumber(); try { if (!PosixUtils.writeBytes(getOutputFile(), bytes, length)) { /* @@ -70,19 +67,19 @@ public void log(CCharPointer bytes, UnsignedWord length) { fatalError(); } } finally { - Errno.set_errno(savedErrno); + CErrorNumber.setCErrorNumber(savedErrno); } } @Override public void flush() { /* Save and restore errno around calls that would otherwise change errno. */ - final int savedErrno = Errno.errno(); + final int savedErrno = CErrorNumber.getCErrorNumber(); try { PosixUtils.flush(getOutputFile()); /* ignore error -- they're benign */ } finally { - Errno.set_errno(savedErrno); + CErrorNumber.setCErrorNumber(savedErrno); } } diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixNativeLibraryFeature.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixNativeLibraryFeature.java index f254ed141871..fd666df4ef0f 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixNativeLibraryFeature.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixNativeLibraryFeature.java @@ -37,10 +37,10 @@ import org.graalvm.word.UnsignedWord; import org.graalvm.word.WordFactory; +import com.oracle.svm.core.CErrorNumber; import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.AutomaticFeature; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.headers.Errno; import com.oracle.svm.core.jdk.JNIPlatformNativeLibrarySupport; import com.oracle.svm.core.jdk.Jvm; import com.oracle.svm.core.jdk.NativeLibrarySupport; @@ -51,7 +51,6 @@ import com.oracle.svm.core.posix.headers.darwin.DarwinSyslimits; @AutomaticFeature -@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) class PosixNativeLibraryFeature implements Feature { @Override public void afterRegistration(AfterRegistrationAccess access) { @@ -89,10 +88,10 @@ public boolean initializeBuiltinLibraries() { } rlp.set_rlim_cur(newValue); if (Resource.setrlimit(Resource.RLIMIT_NOFILE(), rlp) != 0) { - Log.log().string("setrlimit to increase file descriptor limit failed, errno ").signed(Errno.errno()).newline(); + Log.log().string("setrlimit to increase file descriptor limit failed, errno ").signed(CErrorNumber.getCErrorNumber()).newline(); } } else { - Log.log().string("getrlimit failed, errno ").signed(Errno.errno()).newline(); + Log.log().string("getrlimit failed, errno ").signed(CErrorNumber.getCErrorNumber()).newline(); } } @@ -203,14 +202,11 @@ public PointerBase findSymbol(String name) { return findBuiltinSymbol(name); } assert dlhandle.isNonNull(); - try (CCharPointerHolder symbol = CTypeConversion.toCString(name)) { - return Dlfcn.dlsym(dlhandle, symbol.get()); - } + return PosixUtils.dlsym(dlhandle, name); } } } -@Platforms({Platform.LINUX.class, Platform.DARWIN.class}) @TargetClass(className = "java.io.UnixFileSystem") final class Target_java_io_UnixFileSystem_JNI { @Alias diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixSubstrateOperatingSystemMXBean.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixSubstrateOperatingSystemMXBean.java index cc9a3d5ad6cd..8133cf398cf4 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixSubstrateOperatingSystemMXBean.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixSubstrateOperatingSystemMXBean.java @@ -24,29 +24,27 @@ */ package com.oracle.svm.core.posix; -import static com.oracle.svm.core.posix.headers.Resource.RLIMIT_NOFILE; -import static com.oracle.svm.core.posix.headers.Resource.getrlimit; - import java.lang.management.OperatingSystemMXBean; import java.util.concurrent.TimeUnit; import org.graalvm.nativeimage.ImageSingletons; -import org.graalvm.nativeimage.Platforms; +import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.StackValue; import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.impl.InternalPlatform; +import com.oracle.svm.core.CErrorNumber; import com.oracle.svm.core.annotate.AutomaticFeature; -import com.oracle.svm.core.headers.Errno; import com.oracle.svm.core.jdk.SubstrateOperatingSystemMXBean; -import com.oracle.svm.core.posix.headers.Resource.rlimit; -import com.oracle.svm.core.posix.headers.Stat; -import com.oracle.svm.core.posix.headers.Stat.stat; +import com.oracle.svm.core.posix.headers.Errno; +import com.oracle.svm.core.posix.headers.Resource; import com.oracle.svm.core.posix.headers.Times; import com.oracle.svm.core.posix.headers.Unistd; +import com.oracle.svm.core.posix.headers.darwin.DarwinStat; +import com.oracle.svm.core.posix.headers.linux.LinuxStat; +import com.oracle.svm.core.util.VMError; import com.sun.management.UnixOperatingSystemMXBean; -@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) class PosixSubstrateOperatingSystemMXBean extends SubstrateOperatingSystemMXBean implements UnixOperatingSystemMXBean { /** @@ -72,8 +70,8 @@ public long getProcessCpuTime() { @Override public long getMaxFileDescriptorCount() { - rlimit rlp = StackValue.get(rlimit.class); - if (getrlimit(RLIMIT_NOFILE(), rlp) < 0) { + Resource.rlimit rlp = StackValue.get(Resource.rlimit.class); + if (Resource.getrlimit(Resource.RLIMIT_NOFILE(), rlp) < 0) { throwUnchecked(PosixUtils.newIOExceptionWithLastError("getrlimit failed")); } return rlp.rlim_cur().rawValue(); @@ -84,21 +82,31 @@ public long getOpenFileDescriptorCount() { int maxFileDescriptor = Unistd.getdtablesize(); long count = 0; for (int i = 0; i <= maxFileDescriptor; i++) { - stat stat = StackValue.get(stat.class); - if (Stat.fstat(i, stat) == 0 || Errno.errno() != Errno.EBADF()) { + if (fstat(i) == 0 || CErrorNumber.getCErrorNumber() != Errno.EBADF()) { count++; } } return count; } + private static int fstat(int fd) { + if (Platform.includedIn(InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class)) { + LinuxStat.stat64 stat = StackValue.get(LinuxStat.stat64.class); + return LinuxStat.fstat64(fd, stat); + } else if (Platform.includedIn(InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class)) { + DarwinStat.stat stat = StackValue.get(DarwinStat.stat.class); + return DarwinStat.fstat(fd, stat); + } else { + throw VMError.shouldNotReachHere("Unsupported platform"); + } + } + @SuppressWarnings("unchecked") private static void throwUnchecked(Throwable exception) throws T { throw (T) exception; } } -@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) @AutomaticFeature class PosixSubstrateOperatingSystemMXBeanFeature implements Feature { @Override diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixSystemPropertiesSupport.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixSystemPropertiesSupport.java index 6d7720cad1a1..ff1cc83611ca 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixSystemPropertiesSupport.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixSystemPropertiesSupport.java @@ -24,21 +24,16 @@ */ package com.oracle.svm.core.posix; -import static com.oracle.svm.core.posix.headers.Limits.MAXPATHLEN; -import static com.oracle.svm.core.posix.headers.Pwd.getpwuid; - -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.StackValue; import org.graalvm.nativeimage.c.type.CCharPointer; import org.graalvm.nativeimage.c.type.CTypeConversion; -import org.graalvm.nativeimage.impl.InternalPlatform; import org.graalvm.word.WordFactory; import com.oracle.svm.core.jdk.SystemPropertiesSupport; -import com.oracle.svm.core.posix.headers.Pwd.passwd; +import com.oracle.svm.core.posix.headers.Limits; +import com.oracle.svm.core.posix.headers.Pwd; import com.oracle.svm.core.posix.headers.Unistd; -@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) public abstract class PosixSystemPropertiesSupport extends SystemPropertiesSupport { /* @@ -48,19 +43,19 @@ public abstract class PosixSystemPropertiesSupport extends SystemPropertiesSuppo @Override protected String userNameValue() { - passwd pwent = getpwuid(Unistd.getuid()); + Pwd.passwd pwent = Pwd.getpwuid(Unistd.getuid()); return pwent.isNull() ? "?" : CTypeConversion.toJavaString(pwent.pw_name()); } @Override protected String userHomeValue() { - passwd pwent = getpwuid(Unistd.getuid()); + Pwd.passwd pwent = Pwd.getpwuid(Unistd.getuid()); return pwent.isNull() ? "?" : CTypeConversion.toJavaString(pwent.pw_dir()); } @Override protected String userDirValue() { - int bufSize = MAXPATHLEN(); + int bufSize = Limits.MAXPATHLEN(); CCharPointer buf = StackValue.get(bufSize); if (Unistd.getcwd(buf, WordFactory.unsigned(bufSize)).isNonNull()) { return CTypeConversion.toJavaString(buf); diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixUtils.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixUtils.java index 1a95a4d00d85..46bad115d511 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixUtils.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixUtils.java @@ -24,25 +24,11 @@ */ package com.oracle.svm.core.posix; -import static com.oracle.svm.core.headers.Errno.errno; -import static com.oracle.svm.core.posix.headers.Fcntl.O_WRONLY; -import static com.oracle.svm.core.posix.headers.Fcntl.open; -import static com.oracle.svm.core.posix.headers.Unistd.close; -import static com.oracle.svm.core.posix.headers.Unistd.dup2; -import static com.oracle.svm.core.posix.headers.Unistd.read; -import static com.oracle.svm.core.posix.headers.Unistd.write; - import java.io.FileDescriptor; -import java.io.FileNotFoundException; import java.io.IOException; -import java.io.SyncFailedException; -import java.util.ArrayList; -import java.util.List; import java.util.function.Function; -import org.graalvm.compiler.core.common.SuppressFBWarnings; import org.graalvm.compiler.serviceprovider.JavaVersionUtil; -import org.graalvm.nativeimage.PinnedObject; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.StackValue; @@ -50,31 +36,24 @@ import org.graalvm.nativeimage.c.type.CIntPointer; import org.graalvm.nativeimage.c.type.CTypeConversion; import org.graalvm.nativeimage.c.type.CTypeConversion.CCharPointerHolder; -import org.graalvm.nativeimage.impl.DeprecatedPlatform; import org.graalvm.nativeimage.impl.InternalPlatform; import org.graalvm.word.PointerBase; import org.graalvm.word.SignedWord; import org.graalvm.word.UnsignedWord; import org.graalvm.word.WordFactory; +import com.oracle.svm.core.CErrorNumber; import com.oracle.svm.core.SubstrateUtil; import com.oracle.svm.core.annotate.Alias; -import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.annotate.TargetElement; import com.oracle.svm.core.annotate.Uninterruptible; -import com.oracle.svm.core.headers.Errno; -import com.oracle.svm.core.jdk.JDK11OrLater; import com.oracle.svm.core.posix.headers.Dlfcn; -import com.oracle.svm.core.posix.headers.Fcntl; -import com.oracle.svm.core.posix.headers.LibC; +import com.oracle.svm.core.posix.headers.Errno; import com.oracle.svm.core.posix.headers.Locale; import com.oracle.svm.core.posix.headers.Unistd; -import com.oracle.svm.core.posix.headers.UnistdNoTransitions; import com.oracle.svm.core.posix.headers.Wait; import com.oracle.svm.core.util.VMError; -@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) public class PosixUtils { static String setLocale(String category, String locale) { @@ -83,7 +62,7 @@ static String setLocale(String category, String locale) { return setLocale(intCategory, locale); } - public static String setLocale(int category, String locale) { + private static String setLocale(int category, String locale) { if (locale == null) { CCharPointer cstrResult = Locale.setlocale(category, WordFactory.nullPointer()); return CTypeConversion.toJavaString(cstrResult); @@ -112,7 +91,7 @@ private static int getCategory(String category) { case "LC_MESSAGES": return Locale.LC_MESSAGES(); } - if (Platform.includedIn(DeprecatedPlatform.LINUX_SUBSTITUTION.class)) { + if (Platform.includedIn(InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class)) { switch (category) { case "LC_PAPER": return Locale.LC_PAPER(); @@ -128,96 +107,31 @@ private static int getCategory(String category) { return Locale.LC_IDENTIFICATION(); } } - throw VMError.shouldNotReachHere("Unknown locale category: " + category); - } - - public static String removeTrailingSlashes(String path) { - int p = path.length() - 1; - while (p > 0 && path.charAt(p) == '/') { - --p; - } - return p > 0 ? path.substring(0, p + 1) : path; + throw new IllegalArgumentException("Unknown locale category: " + category); } @TargetClass(java.io.FileDescriptor.class) private static final class Target_java_io_FileDescriptor { @Alias int fd; - - /* jdk/src/solaris/native/java/io/FileDescriptor_md.c */ - // 53 JNIEXPORT void JNICALL - // 54 Java_java_io_FileDescriptor_sync(JNIEnv *env, jobject this) { - @Substitute - public /* native */ void sync() throws SyncFailedException { - // 55 FD fd = THIS_FD(this); - // 56 if (IO_Sync(fd) == -1) { - if (Unistd.fsync(fd) == -1) { - // 57 JNU_ThrowByName(env, "java/io/SyncFailedException", "sync failed"); - throw new SyncFailedException("sync failed"); - } - } - - @Substitute // - @TargetElement(onlyWith = JDK11OrLater.class) // - @SuppressWarnings({"unused"}) - /* { Do not re-format commented out C code. @formatter:off */ - /* open-jdk11/src/java.base/unix/native/libjava/FileDescriptor_md.c */ - // 72 JNIEXPORT jboolean JNICALL - // 73 Java_java_io_FileDescriptor_getAppend(JNIEnv *env, jclass fdClass, jint fd) { - private static /* native */ boolean getAppend(int fd) { - // 74 int flags = fcntl(fd, F_GETFL); - int flags = Fcntl.fcntl(fd, Fcntl.F_GETFL()); - // 75 return ((flags & O_APPEND) == 0) ? JNI_FALSE : JNI_TRUE; - return ((flags & Fcntl.O_APPEND()) == 0) ? false : true; - } - /* } Do not re-format commented out C code. @formatter:on */ - - @Substitute // - @TargetElement(onlyWith = JDK11OrLater.class) // - @SuppressWarnings({"unused", "static-method"}) - /* { Do not re-format commented out C code. @formatter:off */ - /* open-jdk11/src/java.base/unix/native/libjava/FileDescriptor_md.c */ - // 78 // instance method close0 for FileDescriptor - // 79 JNIEXPORT void JNICALL - // 80 Java_java_io_FileDescriptor_close0(JNIEnv *env, jobject this) { - private /* native */ void close0() throws IOException { - // 81 fileDescriptorClose(env, this); - PosixUtils.fileClose(Util_java_io_FileDescriptor.fromTarget(this)); - } - } - - static final class Util_java_io_FileDescriptor { - - /** Cast from Target class to Java class. */ - @SuppressFBWarnings(value = "BC", justification = "Cast from @TargetClass") - static java.io.FileDescriptor fromTarget(Target_java_io_FileDescriptor tjifd) { - return java.io.FileDescriptor.class.cast(tjifd); - } - - /** Cast from Java class to Target class. */ - @SuppressFBWarnings(value = "BC", justification = "Cast to @TargetClass") - static Target_java_io_FileDescriptor toTarget(java.io.FileDescriptor jifd) { - return Target_java_io_FileDescriptor.class.cast(jifd); - } - } public static int getFD(FileDescriptor descriptor) { - return Util_java_io_FileDescriptor.toTarget(descriptor).fd; + return SubstrateUtil.cast(descriptor, Target_java_io_FileDescriptor.class).fd; } public static void setFD(FileDescriptor descriptor, int fd) { - Util_java_io_FileDescriptor.toTarget(descriptor).fd = fd; + SubstrateUtil.cast(descriptor, Target_java_io_FileDescriptor.class).fd = fd; } /** Return the error string for the last error, or a default message. */ public static String lastErrorString(String defaultMsg) { - int errno = Errno.errno(); + int errno = CErrorNumber.getCErrorNumber(); return errorString(errno, defaultMsg); } public static IOException newIOExceptionWithLastError(String defaultMsg) { - return new IOException(PosixUtils.lastErrorString(defaultMsg)); + return new IOException(lastErrorString(defaultMsg)); } /** Return the error string for the given error number, or a default message. */ @@ -229,51 +143,12 @@ public static String errorString(int errno, String defaultMsg) { return result.length() != 0 ? result : defaultMsg; } - public static void fileOpen(String path, FileDescriptor fd, int flags) throws FileNotFoundException { - try (CCharPointerHolder pathPin = CTypeConversion.toCString(removeTrailingSlashes(path))) { - CCharPointer pathPtr = pathPin.get(); - int handle = open(pathPtr, flags, 0666); - if (handle >= 0) { - setFD(fd, handle); - } else { - throw new FileNotFoundException(path); - } - } - } - - public static void fileClose(FileDescriptor fd) throws IOException { - int handle = getFD(fd); - if (handle == -1) { - return; - } - setFD(fd, -1); - - // Do not close file descriptors 0, 1, 2. Instead, redirect to /dev/null. - if (handle >= 0 && handle <= 2) { - int devnull; - - try (CCharPointerHolder pathPin = CTypeConversion.toCString("/dev/null")) { - CCharPointer pathPtr = pathPin.get(); - devnull = open(pathPtr, O_WRONLY(), 0); - } - if (devnull < 0) { - setFD(fd, handle); - throw PosixUtils.newIOExceptionWithLastError("open /dev/null failed"); - } else { - dup2(devnull, handle); - close(devnull); - } - } else if (close(handle) == -1) { - throw PosixUtils.newIOExceptionWithLastError("close failed"); - } - } - public static int getpid() { return Unistd.getpid(); } @Platforms(Platform.HOSTED_ONLY.class) - static final class ProcessNameProvider implements Function { + private static final class ProcessNameProvider implements Function { @Override public String apply(TargetClass annotation) { if (JavaVersionUtil.JAVA_SPEC <= 8) { @@ -285,10 +160,10 @@ public String apply(TargetClass annotation) { } @TargetClass(classNameProvider = ProcessNameProvider.class) - @Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) - static final class Target_java_lang_UNIXProcess { + private static final class Target_java_lang_UNIXProcess { @Alias int pid; } + public static int getpid(Process process) { Target_java_lang_UNIXProcess instance = SubstrateUtil.cast(process, Target_java_lang_UNIXProcess.class); return instance.pid; @@ -297,9 +172,9 @@ public static int getpid(Process process) { public static int waitForProcessExit(int ppid) { CIntPointer statusptr = StackValue.get(CIntPointer.class); while (Wait.waitpid(ppid, statusptr, 0) < 0) { - if (Errno.errno() == Errno.ECHILD()) { + if (CErrorNumber.getCErrorNumber() == Errno.ECHILD()) { return 0; - } else if (Errno.errno() == Errno.EINTR()) { + } else if (CErrorNumber.getCErrorNumber() == Errno.EINTR()) { break; } else { return -1; @@ -316,108 +191,6 @@ public static int waitForProcessExit(int ppid) { return status; } - public static int readSingle(FileDescriptor fd) throws IOException { - CCharPointer retPtr = StackValue.get(CCharPointer.class); - int handle = PosixUtils.getFDHandle(fd); - SignedWord nread = read(handle, retPtr, WordFactory.unsigned(1)); - if (nread.equal(0)) { - // EOF - return -1; - } else if (nread.equal(-1)) { - throw PosixUtils.newIOExceptionWithLastError("Read error"); - } - return retPtr.read() & 0xFF; - } - - public static int readBytes(byte[] b, int off, int len, FileDescriptor fd) throws IOException { - if (b == null) { - throw new NullPointerException(); - } else if (PosixUtils.outOfBounds(off, len, b)) { - throw new IndexOutOfBoundsException(); - } - if (len == 0) { - return 0; - } - - SignedWord nread; - CCharPointer buf = LibC.malloc(WordFactory.unsigned(len)); - try { - if (buf.equal(WordFactory.zero())) { - throw new OutOfMemoryError(); - } - - int handle = getFDHandle(fd); - nread = read(handle, buf, WordFactory.unsigned(len)); - if (nread.greaterThan(0)) { - /* - * We do not read directly into the (pinned) result array because read can block, - * and that could lead to object pinned for an unexpectedly long time. - */ - try (PinnedObject pin = PinnedObject.create(b)) { - LibC.memcpy(pin.addressOfArrayElement(off), buf, (UnsignedWord) nread); - } - } else if (nread.equal(-1)) { - throw PosixUtils.newIOExceptionWithLastError("Read error"); - } else { - // EOF - nread = WordFactory.signed(-1); - } - } finally { - LibC.free(buf); - } - - return (int) nread.rawValue(); - } - - @SuppressWarnings("unused") - public static void writeSingle(FileDescriptor fd, int b, boolean append) throws IOException { - SignedWord n; - int handle = getFD(fd); - if (handle == -1) { - throw new IOException("Stream Closed"); - } - - CCharPointer bufPtr = StackValue.get(CCharPointer.class); - bufPtr.write((byte) b); - // the append parameter is disregarded - n = write(handle, bufPtr, WordFactory.unsigned(1)); - - if (n.equal(-1)) { - throw PosixUtils.newIOExceptionWithLastError("Write error"); - } - } - - @SuppressWarnings("unused") - public static void writeBytes(FileDescriptor descriptor, byte[] bytes, int off, int len, boolean append) throws IOException { - if (bytes == null) { - throw new NullPointerException(); - } else if (PosixUtils.outOfBounds(off, len, bytes)) { - throw new IndexOutOfBoundsException(); - } - if (len == 0) { - return; - } - - try (PinnedObject bytesPin = PinnedObject.create(bytes)) { - CCharPointer curBuf = bytesPin.addressOfArrayElement(off); - UnsignedWord curLen = WordFactory.unsigned(len); - while (curLen.notEqual(0)) { - int fd = getFD(descriptor); - if (fd == -1) { - throw new IOException("Stream Closed"); - } - - SignedWord n = write(fd, curBuf, curLen); - - if (n.equal(-1)) { - throw PosixUtils.newIOExceptionWithLastError("Write error"); - } - curBuf = curBuf.addressOf(n); - curLen = curLen.subtract((UnsignedWord) n); - } - } - } - /** * Low-level output of bytes already in native memory. This method is allocation free, so that * it can be used, e.g., in low-level logging routines. @@ -442,60 +215,11 @@ public static boolean writeBytes(FileDescriptor descriptor, CCharPointer bytes, return true; } - static boolean flush(FileDescriptor descriptor) { + public static boolean flush(FileDescriptor descriptor) { int fd = getFD(descriptor); return Unistd.fsync(fd) == 0; } - public static int getFDHandle(FileDescriptor fd) throws IOException { - int handle = getFD(fd); - if (handle == -1) { - throw new IOException("Stream Closed"); - } - return handle; - } - - static boolean outOfBounds(int off, int len, byte[] array) { - return off < 0 || len < 0 || array.length - off < len; - } - - /** - * From a given path, remove all {@code .} and {@code dir/..}. - */ - public static String collapse(String path) { - boolean absolute = path.charAt(0) == '/'; - String wpath = absolute ? path.substring(1) : path; - - // split the path and remove unnecessary elements - List parts = new ArrayList<>(); - int pos = 0; - int next; - do { - next = wpath.indexOf('/', pos); - String part = next != -1 ? wpath.substring(pos, next) : wpath.substring(pos); - if (part.length() > 0) { - if (part.equals(".")) { - // ignore - } else if (part.equals("..")) { - // omit this .. and the preceding part - parts.remove(parts.size() - 1); - } else { - parts.add(part); - } - } - pos = next + 1; - } while (next != -1); - - // reassemble the path - StringBuilder rpath = new StringBuilder(absolute ? "/" : ""); - for (String part : parts) { - rpath.append(part).append('/'); - } - rpath.deleteCharAt(rpath.length() - 1); - - return rpath.toString(); - } - public static PointerBase dlopen(String file, int mode) { try (CCharPointerHolder pathPin = CTypeConversion.toCString(file)) { CCharPointer pathPtr = pathPin.get(); @@ -540,8 +264,8 @@ public static int readBytes(int fd, CCharPointer buffer, int bufferLen, int read int readBytes = -1; if (readOffset < bufferLen) { do { - readBytes = (int) UnistdNoTransitions.read(fd, buffer.addressOf(readOffset), WordFactory.unsigned(bufferLen - readOffset)).rawValue(); - } while (readBytes == -1 && errno() == Errno.EINTR()); + readBytes = (int) Unistd.NoTransitions.read(fd, buffer.addressOf(readOffset), WordFactory.unsigned(bufferLen - readOffset)).rawValue(); + } while (readBytes == -1 && CErrorNumber.getCErrorNumber() == Errno.EINTR()); } return readBytes; } diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixVirtualMemoryProvider.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixVirtualMemoryProvider.java index 4db5b8832535..1b4a638a8834 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixVirtualMemoryProvider.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixVirtualMemoryProvider.java @@ -36,16 +36,12 @@ import static com.oracle.svm.core.posix.headers.Mman.NoTransitions.mmap; import static com.oracle.svm.core.posix.headers.Mman.NoTransitions.mprotect; import static com.oracle.svm.core.posix.headers.Mman.NoTransitions.munmap; -import static com.oracle.svm.core.posix.headers.Unistd._SC_PAGE_SIZE; -import static com.oracle.svm.core.posix.headers.UnistdNoTransitions.sysconf; import static org.graalvm.word.WordFactory.nullPointer; import org.graalvm.compiler.word.Word; -import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.ImageSingletons; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.type.WordPointer; -import org.graalvm.nativeimage.impl.InternalPlatform; +import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.word.Pointer; import org.graalvm.word.PointerBase; import org.graalvm.word.UnsignedWord; @@ -57,9 +53,9 @@ import com.oracle.svm.core.c.CGlobalData; import com.oracle.svm.core.c.CGlobalDataFactory; import com.oracle.svm.core.os.VirtualMemoryProvider; +import com.oracle.svm.core.posix.headers.Unistd; @AutomaticFeature -@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) class PosixVirtualMemoryProviderFeature implements Feature { @Override public void beforeAnalysis(BeforeAnalysisAccess access) { @@ -77,7 +73,7 @@ public class PosixVirtualMemoryProvider implements VirtualMemoryProvider { public static UnsignedWord getPageSize() { Word value = CACHED_PAGE_SIZE.get().read(); if (value.equal(WordFactory.zero())) { - long queried = sysconf(_SC_PAGE_SIZE()); + long queried = Unistd.NoTransitions.sysconf(Unistd._SC_PAGE_SIZE()); value = WordFactory.unsigned(queried); CACHED_PAGE_SIZE.get().write(value); } diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/SegfaultHandlerFeature.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/SegfaultHandlerFeature.java index 1ccd2073393e..59c08f8f4dcc 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/SegfaultHandlerFeature.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/SegfaultHandlerFeature.java @@ -30,13 +30,11 @@ import org.graalvm.nativeimage.Isolate; import org.graalvm.nativeimage.IsolateThread; import org.graalvm.nativeimage.LogHandler; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.StackValue; import org.graalvm.nativeimage.c.function.CEntryPoint; import org.graalvm.nativeimage.c.function.CEntryPointLiteral; import org.graalvm.nativeimage.c.struct.SizeOf; import org.graalvm.nativeimage.hosted.Feature; -import org.graalvm.nativeimage.impl.InternalPlatform; import org.graalvm.word.PointerBase; import org.graalvm.word.WordFactory; @@ -66,7 +64,6 @@ import com.oracle.svm.core.snippets.KnownIntrinsics; import com.oracle.svm.core.thread.VMThreads; -@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) @AutomaticFeature public class SegfaultHandlerFeature implements Feature { diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/SunMiscSubstitutions.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/SunMiscSubstitutions.java index d65a52d4f41a..b65e9cbcc1f7 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/SunMiscSubstitutions.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/SunMiscSubstitutions.java @@ -36,21 +36,21 @@ import org.graalvm.nativeimage.StackValue; import org.graalvm.nativeimage.c.type.CIntPointer; import org.graalvm.nativeimage.hosted.Feature; -import org.graalvm.nativeimage.impl.InternalPlatform; import org.graalvm.word.WordFactory; +import com.oracle.svm.core.CErrorNumber; import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.AutomaticFeature; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; import com.oracle.svm.core.annotate.TargetElement; -import com.oracle.svm.core.headers.Errno; import com.oracle.svm.core.jdk.JDK11OrLater; import com.oracle.svm.core.jdk.JDK8OrEarlier; import com.oracle.svm.core.jdk.RuntimeSupport; import com.oracle.svm.core.log.Log; import com.oracle.svm.core.os.IsDefined; import com.oracle.svm.core.posix.headers.CSunMiscSignal; +import com.oracle.svm.core.posix.headers.Errno; import com.oracle.svm.core.posix.headers.Signal; import com.oracle.svm.core.posix.headers.Signal.SignalDispatcher; import com.oracle.svm.core.posix.headers.Time; @@ -68,7 +68,6 @@ public String apply(TargetClass annotation) { } } -@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) @TargetClass(classNameProvider = Package_jdk_internal_misc.class, className = "Signal") final class Target_jdk_internal_misc_Signal { @@ -107,7 +106,6 @@ private static void raise0(int signalNumber) { } /** Support for Target_sun_misc_Signal. */ -@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) final class Util_jdk_internal_misc_Signal { /** A thread to dispatch signals as they are raised. */ @@ -168,7 +166,7 @@ private static void ensureInitialized() throws IllegalArgumentException { /* Open the C signal handling mechanism. */ final int openResult = CSunMiscSignal.open(); if (openResult != 0) { - final int openErrno = Errno.errno(); + final int openErrno = CErrorNumber.getCErrorNumber(); /* Check for the C signal handling mechanism already being open. */ if (openErrno == Errno.EBUSY()) { throw new IllegalArgumentException("C signal handling mechanism is in use."); @@ -388,7 +386,6 @@ protected long decrementCount() { } } -@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) @AutomaticFeature class IgnoreSIGPIPEFeature implements Feature { @@ -416,7 +413,6 @@ public void run() { } } -@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) @TargetClass(className = "jdk.internal.misc.VM", onlyWith = JDK11OrLater.class) final class Target_jdk_internal_misc_VM { diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/Target_java_lang_System.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/Target_java_lang_System_Posix.java similarity index 90% rename from substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/Target_java_lang_System.java rename to substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/Target_java_lang_System_Posix.java index a8056c33a347..da24d93f6936 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/Target_java_lang_System.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/Target_java_lang_System_Posix.java @@ -26,9 +26,7 @@ import java.io.Console; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.StackValue; -import org.graalvm.nativeimage.impl.InternalPlatform; import org.graalvm.word.WordFactory; import com.oracle.svm.core.annotate.Alias; @@ -41,8 +39,7 @@ import com.oracle.svm.core.posix.headers.Time.timezone; @TargetClass(java.lang.System.class) -@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) -final class Target_java_lang_System { +final class Target_java_lang_System_Posix { @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset)// static volatile Console cons; diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/UnmanagedMemorySupportImpl.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/UnmanagedMemorySupportImpl.java index 80299f313c7a..7b6daa79a0b5 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/UnmanagedMemorySupportImpl.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/UnmanagedMemorySupportImpl.java @@ -24,10 +24,8 @@ */ package com.oracle.svm.core.posix; -import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.ImageSingletons; -import org.graalvm.nativeimage.Platforms; -import org.graalvm.nativeimage.impl.InternalPlatform; +import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.impl.UnmanagedMemorySupport; import org.graalvm.word.PointerBase; import org.graalvm.word.UnsignedWord; @@ -64,7 +62,6 @@ public void free(PointerBase ptr) { } @AutomaticFeature -@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) class UnmanagedMemoryFeature implements Feature { @Override public void afterRegistration(AfterRegistrationAccess access) { diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/aarch64/package-info.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/aarch64/package-info.java new file mode 100644 index 000000000000..8825cb96e2ab --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/aarch64/package-info.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2019, 2019, 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. + */ + +@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) +package com.oracle.svm.core.posix.aarch64; + +import org.graalvm.nativeimage.Platforms; +import org.graalvm.nativeimage.impl.InternalPlatform; diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/amd64/package-info.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/amd64/package-info.java new file mode 100644 index 000000000000..3b6848cd0ffe --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/amd64/package-info.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2019, 2019, 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. + */ + +@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) +package com.oracle.svm.core.posix.amd64; + +import org.graalvm.nativeimage.Platforms; +import org.graalvm.nativeimage.impl.InternalPlatform; diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinCErrorNumberSupport.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinCErrorNumberSupport.java new file mode 100644 index 000000000000..60c37e2aaa5a --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinCErrorNumberSupport.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2019, 2019, 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. + */ +package com.oracle.svm.core.posix.darwin; + +import com.oracle.svm.core.CErrorNumber.CErrorNumberSupport; +import com.oracle.svm.core.annotate.Uninterruptible; +import com.oracle.svm.core.posix.headers.darwin.DarwinErrno; + +class DarwinCErrorNumberSupport implements CErrorNumberSupport { + + @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) + @Override + public int getCErrorNumber() { + return DarwinErrno.__error().read(); + } + + @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) + @Override + public void setCErrorNumber(int value) { + DarwinErrno.__error().write(value); + } +} diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinCoreFoundationUtils.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinCoreFoundationUtils.java index 505e73222c8f..c14916944195 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinCoreFoundationUtils.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinCoreFoundationUtils.java @@ -25,14 +25,11 @@ package com.oracle.svm.core.posix.darwin; import org.graalvm.nativeimage.PinnedObject; -import org.graalvm.nativeimage.Platforms; -import org.graalvm.nativeimage.impl.InternalPlatform; import org.graalvm.word.PointerBase; import org.graalvm.word.WordFactory; import com.oracle.svm.core.posix.headers.darwin.CoreFoundation; -@Platforms(InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class) public final class DarwinCoreFoundationUtils { private DarwinCoreFoundationUtils() { diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinImageHeapProvider.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinImageHeapProvider.java index 54face2c284d..5c8d3362174a 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinImageHeapProvider.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinImageHeapProvider.java @@ -32,11 +32,9 @@ import org.graalvm.compiler.word.Word; import org.graalvm.nativeimage.ImageSingletons; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.StackValue; import org.graalvm.nativeimage.c.type.WordPointer; import org.graalvm.nativeimage.hosted.Feature; -import org.graalvm.nativeimage.impl.InternalPlatform; import org.graalvm.word.Pointer; import org.graalvm.word.PointerBase; import org.graalvm.word.UnsignedWord; @@ -53,7 +51,6 @@ import com.oracle.svm.core.util.UnsignedUtils; @AutomaticFeature -@Platforms(InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class) class DarwinImageHeapProviderFeature implements Feature { @Override public void duringSetup(DuringSetupAccess access) { diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinImageSingletonsFeature.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinImageSingletonsFeature.java new file mode 100644 index 000000000000..c7ad95a40634 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinImageSingletonsFeature.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2019, 2019, 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. + */ +package com.oracle.svm.core.posix.darwin; + +import org.graalvm.nativeimage.ImageSingletons; +import org.graalvm.nativeimage.hosted.Feature; + +import com.oracle.svm.core.CErrorNumber.CErrorNumberSupport; +import com.oracle.svm.core.annotate.AutomaticFeature; + +@AutomaticFeature +class DarwinImageSingletonsFeature implements Feature { + + @Override + public void afterRegistration(AfterRegistrationAccess access) { + ImageSingletons.add(CErrorNumberSupport.class, new DarwinCErrorNumberSupport()); + } +} diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinPhysicalMemory.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinPhysicalMemory.java index c75267a95f0a..a59ac4d28217 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinPhysicalMemory.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinPhysicalMemory.java @@ -24,27 +24,24 @@ */ package com.oracle.svm.core.posix.darwin; -import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.ImageSingletons; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.StackValue; import org.graalvm.nativeimage.c.struct.SizeOf; import org.graalvm.nativeimage.c.type.CIntPointer; import org.graalvm.nativeimage.c.type.CLongPointer; import org.graalvm.nativeimage.c.type.WordPointer; -import org.graalvm.nativeimage.impl.InternalPlatform; +import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.word.UnsignedWord; import org.graalvm.word.WordFactory; +import com.oracle.svm.core.CErrorNumber; import com.oracle.svm.core.annotate.AutomaticFeature; import com.oracle.svm.core.heap.PhysicalMemory; import com.oracle.svm.core.log.Log; -import com.oracle.svm.core.headers.Errno; import com.oracle.svm.core.posix.headers.Sysctl; import com.oracle.svm.core.posix.headers.darwin.DarwinSysctl; import com.oracle.svm.core.util.VMError; -@Platforms(InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class) class DarwinPhysicalMemory extends PhysicalMemory { static class PhysicalMemorySupportImpl implements PhysicalMemorySupport { @@ -68,7 +65,7 @@ public UnsignedWord size() { physicalMemorySizePointer.write(SizeOf.get(CLongPointer.class)); final int sysctlResult = Sysctl.sysctl(namePointer, 2, physicalMemoryPointer, (WordPointer) physicalMemorySizePointer, WordFactory.nullPointer(), 0); if (sysctlResult != 0) { - Log.log().string("DarwinPhysicalMemory.PhysicalMemorySupportImpl.size(): sysctl() returns with errno: ").signed(Errno.errno()).newline(); + Log.log().string("DarwinPhysicalMemory.PhysicalMemorySupportImpl.size(): sysctl() returns with errno: ").signed(CErrorNumber.getCErrorNumber()).newline(); VMError.shouldNotReachHere("DarwinPhysicalMemory.PhysicalMemorySupportImpl.size() failed."); } /* Cache the value, races are idempotent. */ diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinProcessPropertiesSupport.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinProcessPropertiesSupport.java index 5cea23c17018..50f56eb081fd 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinProcessPropertiesSupport.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinProcessPropertiesSupport.java @@ -24,15 +24,13 @@ */ package com.oracle.svm.core.posix.darwin; -import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.PinnedObject; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.StackValue; import org.graalvm.nativeimage.c.type.CCharPointer; import org.graalvm.nativeimage.c.type.CIntPointer; import org.graalvm.nativeimage.c.type.CTypeConversion; -import org.graalvm.nativeimage.impl.InternalPlatform; +import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.impl.ProcessPropertiesSupport; import org.graalvm.word.WordFactory; @@ -41,7 +39,6 @@ import com.oracle.svm.core.posix.headers.darwin.DarwinDyld; import com.oracle.svm.core.util.VMError; -@Platforms(InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class) public class DarwinProcessPropertiesSupport extends PosixProcessPropertiesSupport { @Override diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinStackOverflowSupport.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinStackOverflowSupport.java index 0eebbbee35bb..92869f211b24 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinStackOverflowSupport.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinStackOverflowSupport.java @@ -24,10 +24,8 @@ */ package com.oracle.svm.core.posix.darwin; -import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.ImageSingletons; -import org.graalvm.nativeimage.Platforms; -import org.graalvm.nativeimage.impl.InternalPlatform; +import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.word.UnsignedWord; import com.oracle.svm.core.annotate.AutomaticFeature; @@ -36,7 +34,6 @@ import com.oracle.svm.core.posix.headers.darwin.DarwinPthread; import com.oracle.svm.core.stack.StackOverflowCheck; -@Platforms({InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) class DarwinStackOverflowSupport implements StackOverflowCheck.OSSupport { @Uninterruptible(reason = "Called while thread is being attached to the VM, i.e., when the thread state is not yet set up.") @@ -49,7 +46,6 @@ public UnsignedWord lookupStackEnd() { } } -@Platforms({InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) @AutomaticFeature class DarwinStackOverflowSupportFeature implements Feature { @Override diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinSubstitutions.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinSubstitutions.java index 1c6f9ade134c..ef3769a23356 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinSubstitutions.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinSubstitutions.java @@ -28,11 +28,9 @@ import static com.oracle.svm.core.posix.headers.darwin.DarwinTime.mach_absolute_time; import static com.oracle.svm.core.posix.headers.darwin.DarwinTime.mach_timebase_info; -import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.ImageSingletons; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.StackValue; -import org.graalvm.nativeimage.impl.InternalPlatform; +import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.word.WordFactory; import com.oracle.svm.core.annotate.AutomaticFeature; @@ -43,9 +41,8 @@ import com.oracle.svm.core.posix.headers.Time.timezone; import com.oracle.svm.core.posix.headers.darwin.DarwinTime.MachTimebaseInfo; -@Platforms(InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class) @TargetClass(java.lang.System.class) -final class Target_java_lang_System { +final class Target_java_lang_System_Darwin { @Substitute @Uninterruptible(reason = "Does basic math after a few simple system calls") @@ -85,8 +82,7 @@ public static String mapLibraryName(String libname) { } } -/** Additional static-like fields for {@link Target_java_lang_System}. */ -@Platforms(InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class) +/** Additional static-like fields for {@link Target_java_lang_System_Darwin}. */ final class Util_java_lang_System { boolean timeBaseValid = false; boolean fastTime = false; @@ -97,7 +93,6 @@ final class Util_java_lang_System { } } -@Platforms(InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class) @AutomaticFeature class DarwinSubsitutionsFeature implements Feature { diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinSystemPropertiesSupport.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinSystemPropertiesSupport.java index cba9f466dc82..77c0ec2bab83 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinSystemPropertiesSupport.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinSystemPropertiesSupport.java @@ -26,13 +26,11 @@ import static com.oracle.svm.core.posix.headers.darwin.CoreFoundation.CFRetain; -import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.ImageSingletons; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.StackValue; import org.graalvm.nativeimage.c.type.CCharPointer; import org.graalvm.nativeimage.c.type.CTypeConversion; -import org.graalvm.nativeimage.impl.InternalPlatform; +import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.word.UnsignedWord; import org.graalvm.word.WordFactory; @@ -44,7 +42,6 @@ import com.oracle.svm.core.posix.headers.darwin.CoreFoundation; import com.oracle.svm.core.posix.headers.darwin.CoreFoundation.CFStringRef; -@Platforms({InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) public class DarwinSystemPropertiesSupport extends PosixSystemPropertiesSupport { @Override @@ -99,7 +96,6 @@ protected String osVersionValue() { } } -@Platforms({InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) @AutomaticFeature class DarwinSystemPropertiesFeature implements Feature { @Override diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/package-info.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/package-info.java new file mode 100644 index 000000000000..cb3a12c43ea3 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/package-info.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2019, 2019, 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. + */ + +@Platforms({InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) +package com.oracle.svm.core.posix.darwin; + +import org.graalvm.nativeimage.Platforms; +import org.graalvm.nativeimage.impl.InternalPlatform; diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Dlfcn.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Dlfcn.java index 04a194fd9081..1f82cc6992c8 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Dlfcn.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Dlfcn.java @@ -24,7 +24,6 @@ */ package com.oracle.svm.core.posix.headers; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.constant.CConstant; import org.graalvm.nativeimage.c.function.CFunction; @@ -32,18 +31,15 @@ import org.graalvm.nativeimage.c.struct.CField; import org.graalvm.nativeimage.c.struct.CStruct; import org.graalvm.nativeimage.c.type.CCharPointer; -import org.graalvm.nativeimage.impl.InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS; -import org.graalvm.nativeimage.impl.InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS; import org.graalvm.word.Pointer; import org.graalvm.word.PointerBase; import org.graalvm.word.WordBase; -//Checkstyle: stop +// Checkstyle: stop /** * Definitions manually translated from the C header file dlfcn.h. */ -@Platforms({DARWIN_JNI_AND_SUBSTITUTIONS.class, LINUX_JNI_AND_SUBSTITUTIONS.class}) @CContext(PosixDirectives.class) @CLibrary("dl") public class Dlfcn { diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Errno.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Errno.java new file mode 100644 index 000000000000..54f847e46cb4 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Errno.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2013, 2019, 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. + */ +package com.oracle.svm.core.posix.headers; + +import org.graalvm.nativeimage.c.CContext; +import org.graalvm.nativeimage.c.constant.CConstant; +import org.graalvm.nativeimage.c.function.CFunction; +import org.graalvm.nativeimage.c.type.CCharPointer; + +// Checkstyle: stop + +/** + * Definitions manually translated from the C header file sys/errno.h. + */ +@CContext(PosixDirectives.class) +public class Errno { + + @CConstant + public static native int EPERM(); + + @CConstant + public static native int ESRCH(); + + @CConstant + public static native int EINTR(); + + @CConstant + public static native int EBADF(); + + @CConstant + public static native int ECHILD(); + + @CConstant + public static native int EBUSY(); + + @CConstant + public static native int ETIMEDOUT(); + + @CFunction + public static native CCharPointer strerror(int errnum); +} diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Fcntl.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Fcntl.java index 9e41d60775df..0b9c77ef59b9 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Fcntl.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Fcntl.java @@ -24,17 +24,11 @@ */ package com.oracle.svm.core.posix.headers; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.constant.CConstant; import org.graalvm.nativeimage.c.function.CFunction; import org.graalvm.nativeimage.c.function.CFunction.Transition; -import org.graalvm.nativeimage.c.struct.CField; -import org.graalvm.nativeimage.c.struct.CStruct; import org.graalvm.nativeimage.c.type.CCharPointer; -import org.graalvm.nativeimage.impl.DeprecatedPlatform; -import org.graalvm.word.PointerBase; -import org.graalvm.word.SignedWord; // Checkstyle: stop @@ -44,121 +38,9 @@ @CContext(PosixDirectives.class) public class Fcntl { - @CFunction - public static native int fcntl(int fd, int cmd); - - @CFunction - public static native int fcntl(int fd, int cmd, int arg); - - @CFunction(value = "fcntl", transition = CFunction.Transition.NO_TRANSITION) - public static native int fcntl_no_transition(int fd, int cmd, int arg); - - @CFunction - public static native int fcntl(int fd, int cmd, flock arg); - - @CFunction - public static native int open(CCharPointer pathname, int flags, int mode); - - public static native int openat(int fd, CCharPointer pathname, int flags, int mode); - - @CStruct(addStructKeyword = true) - public interface flock extends PointerBase { - @CField - short l_type(); - - @CField - void set_l_type(short value); - - @CField - short l_whence(); - - @CField - void set_l_whence(short value); - - @CField - SignedWord l_start(); - - @CField - void set_l_start(SignedWord value); - - @CField - SignedWord l_len(); - - @CField - void set_l_len(SignedWord value); - - @CField - int l_pid(); - - @CField - void set_l_pid(int value); - } - @CConstant public static native int O_RDONLY(); - @CConstant - public static native int O_WRONLY(); - - @CConstant - public static native int O_RDWR(); - - @CConstant - public static native int O_CREAT(); - - @CConstant - public static native int O_TRUNC(); - - @CConstant - public static native int O_APPEND(); - - @CConstant - public static native int O_NONBLOCK(); - - @CConstant - public static native int O_SYNC(); - - @CConstant - public static native int F_SETLK(); - - @CConstant - public static native int F_SETLKW(); - - @CConstant - @Platforms(DeprecatedPlatform.LINUX_SUBSTITUTION.class) - public static native int O_DIRECT(); - - @CConstant - public static native int O_DSYNC(); - - @CConstant - public static native int F_SETFD(); - - @CConstant - public static native int F_GETFL(); - - @CConstant - public static native int F_SETFL(); - - @CConstant - public static native int FD_CLOEXEC(); - - @CConstant - public static native short F_RDLCK(); - - @CConstant - public static native short F_WRLCK(); - - @CConstant - public static native short F_UNLCK(); - - @CConstant - @Platforms({DeprecatedPlatform.DARWIN_SUBSTITUTION.class}) - public static native int F_NOCACHE(); - - @CFunction - public static native int fallocate(int fd, int mode, SignedWord offset, SignedWord len); - public static class NoTransitions { @CFunction(transition = Transition.NO_TRANSITION) public static native int open(CCharPointer pathname, int flags, int mode); diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/LibC.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/LibC.java index cd5e5f13ef29..230e779f6837 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/LibC.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/LibC.java @@ -24,23 +24,20 @@ */ package com.oracle.svm.core.posix.headers; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.function.CFunction; import org.graalvm.nativeimage.c.type.CCharPointer; import org.graalvm.nativeimage.c.type.CCharPointerPointer; -import org.graalvm.nativeimage.impl.InternalPlatform; import org.graalvm.word.PointerBase; import org.graalvm.word.SignedWord; import org.graalvm.word.UnsignedWord; import com.oracle.svm.core.annotate.Uninterruptible; -//Checkstyle: stop +// Checkstyle: stop /** * Basic functions from the standard C library that we require to be present on all Posix platforms. */ -@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) public class LibC { /** diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Limits.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Limits.java index 9bc2f841df9b..e66c79310c91 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Limits.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Limits.java @@ -27,7 +27,7 @@ import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.constant.CConstant; -//Checkstyle: stop +// Checkstyle: stop /** * Definitions manually translated from the C header file linux/limits.h. diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Locale.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Locale.java index 3e79070e40d8..b5810d05bb4f 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Locale.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Locale.java @@ -29,11 +29,13 @@ import org.graalvm.nativeimage.c.constant.CConstant; import org.graalvm.nativeimage.c.function.CFunction; import org.graalvm.nativeimage.c.type.CCharPointer; -import org.graalvm.nativeimage.impl.DeprecatedPlatform; +import org.graalvm.nativeimage.impl.InternalPlatform; -//Checkstyle: stop +// Checkstyle: stop -/** Declarations of method from . */ +/** + * Declarations of method from the C header file locale.h. + */ @CContext(PosixDirectives.class) public class Locale { @CConstant @@ -57,27 +59,27 @@ public class Locale { @CConstant public static native int LC_MESSAGES(); - @Platforms(DeprecatedPlatform.LINUX_SUBSTITUTION.class) + @Platforms(InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class) @CConstant public static native int LC_PAPER(); - @Platforms(DeprecatedPlatform.LINUX_SUBSTITUTION.class) + @Platforms(InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class) @CConstant public static native int LC_NAME(); - @Platforms(DeprecatedPlatform.LINUX_SUBSTITUTION.class) + @Platforms(InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class) @CConstant public static native int LC_ADDRESS(); - @Platforms(DeprecatedPlatform.LINUX_SUBSTITUTION.class) + @Platforms(InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class) @CConstant public static native int LC_TELEPHONE(); - @Platforms(DeprecatedPlatform.LINUX_SUBSTITUTION.class) + @Platforms(InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class) @CConstant public static native int LC_MEASUREMENT(); - @Platforms(DeprecatedPlatform.LINUX_SUBSTITUTION.class) + @Platforms(InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class) @CConstant public static native int LC_IDENTIFICATION(); diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Mman.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Mman.java index 79245ba77d7e..ce5b3b9abb7f 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Mman.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Mman.java @@ -32,7 +32,7 @@ import org.graalvm.word.PointerBase; import org.graalvm.word.UnsignedWord; -//Checkstyle: stop +// Checkstyle: stop /** * Definitions manually translated from the C header file sys/mman.h. diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/PosixDirectives.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/PosixDirectives.java index a951b1d08b76..ecbdef7a3807 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/PosixDirectives.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/PosixDirectives.java @@ -36,70 +36,35 @@ public class PosixDirectives implements CContext.Directives { private static final String[] commonLibs = new String[]{ - "", - "", "", "", - "", - "", - "", "", "", - "", - "", - "", - "", - "", - "", "", "", - "", - "", "", - "", - "", "", - "", - "", "", - "", - "", "", - "", - "", "", - "", - "", "", "", - "", - "", "", - "", - "", "", "", - "" }; private static final String[] darwinLibs = new String[]{ "", - "", "", - "", "", "", - "", - "", + "", "", }; private static final String[] linuxLibs = new String[]{ - "", - "", - "", "", - "", }; @Override diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Pthread.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Pthread.java index 313f9e9ca88b..9641c7b7cad9 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Pthread.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Pthread.java @@ -24,7 +24,6 @@ */ package com.oracle.svm.core.posix.headers; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.constant.CConstant; import org.graalvm.nativeimage.c.function.CFunction; @@ -33,8 +32,6 @@ import org.graalvm.nativeimage.c.struct.CPointerTo; import org.graalvm.nativeimage.c.struct.CStruct; import org.graalvm.nativeimage.c.type.WordPointer; -import org.graalvm.nativeimage.impl.InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS; -import org.graalvm.nativeimage.impl.InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS; import org.graalvm.word.PointerBase; import org.graalvm.word.UnsignedWord; import org.graalvm.word.WordBase; @@ -44,28 +41,21 @@ import com.oracle.svm.core.thread.VMThreads.OSThreadHandle; import com.oracle.svm.core.thread.VMThreads.OSThreadId; -//Checkstyle: stop +// Checkstyle: stop /** * Definitions manually translated from the C header file pthread.h. */ @CContext(PosixDirectives.class) -@Platforms({DARWIN_JNI_AND_SUBSTITUTIONS.class, LINUX_JNI_AND_SUBSTITUTIONS.class}) @CLibrary("pthread") public class Pthread { - /* - * The fields of the following structures are not exposed on purpose. - */ - public interface pthread_t extends OSThreadHandle, OSThreadId { } @CPointerTo(nameOfCType = "pthread_t") public interface pthread_tPointer extends PointerBase { - pthread_t read(); - } @CStruct diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Pwd.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Pwd.java index 7180d770754a..5c629df96c52 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Pwd.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Pwd.java @@ -27,13 +27,11 @@ import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.function.CFunction; import org.graalvm.nativeimage.c.struct.CField; -import org.graalvm.nativeimage.c.struct.CPointerTo; import org.graalvm.nativeimage.c.struct.CStruct; import org.graalvm.nativeimage.c.type.CCharPointer; import org.graalvm.word.PointerBase; -import org.graalvm.word.UnsignedWord; -//Checkstyle: stop +// Checkstyle: stop /** * Definitions manually translated from the C header file pwd.h. @@ -46,47 +44,10 @@ public interface passwd extends PointerBase { @CField CCharPointer pw_name(); - @CField - CCharPointer pw_passwd(); - - @CField - int pw_uid(); - - @CField - int pw_gid(); - - @CField - CCharPointer pw_gecos(); - @CField CCharPointer pw_dir(); - - @CField - CCharPointer pw_shell(); } - @CPointerTo(passwd.class) - public interface passwdPointer extends PointerBase { - passwd read(); - - void write(PointerBase value); - } - - @CFunction - public static native void setpwent(); - - @CFunction - public static native passwd getpwent(); - @CFunction public static native passwd getpwuid(int __uid); - - @CFunction - public static native passwd getpwnam(CCharPointer __name); - - @CFunction - public static native int getpwuid_r(int __uid, passwd __resultbuf, CCharPointer __buffer, UnsignedWord __buflen, passwdPointer __result); - - @CFunction - public static native int getpwnam_r(CCharPointer __name, passwd __resultbuf, CCharPointer __buffer, UnsignedWord __buflen, passwdPointer __result); } diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Resource.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Resource.java index a11b5de83e0a..9a9de4c7f942 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Resource.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Resource.java @@ -45,14 +45,12 @@ public class Resource { @CStruct(addStructKeyword = true) public interface rlimit extends PointerBase { - /** The current (soft) limit. */ @CField UnsignedWord rlim_cur(); @CField void set_rlim_cur(UnsignedWord value); - /** The hard limit. */ @CField UnsignedWord rlim_max(); @@ -65,11 +63,4 @@ public interface rlimit extends PointerBase { @CFunction public static native int setrlimit(int resource, rlimit rlimits); - - @CFunction - public static native int getpriority(int which, /* unsigned */ int who); - - @CFunction - public static native int setpriority(int which, /* unsigned */ int who, int prio); - } diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Sched.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Sched.java index 2b67284769dd..20d98e2166dd 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Sched.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Sched.java @@ -24,26 +24,17 @@ */ package com.oracle.svm.core.posix.headers; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.function.CFunction; -import org.graalvm.nativeimage.impl.InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS; -import org.graalvm.nativeimage.impl.InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS; -//Allow methods with non-standard names: Checkstyle: stop +// Checkstyle: stop -/* - * The definitions I need, manually translated from the C header file . +/** + * Definitions manually translated from the C header file sched.h. */ - -@Platforms({DARWIN_JNI_AND_SUBSTITUTIONS.class, LINUX_JNI_AND_SUBSTITUTIONS.class}) @CContext(PosixDirectives.class) public class Sched { - /** - * sched_yield() causes the calling thread to relinquish the CPU. The thread is moved to the end - * of the queue for its static priority and a new thread gets to run. - */ @CFunction public static native int sched_yield(); } diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Signal.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Signal.java index a092d06b9bc0..45b11166d8e3 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Signal.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Signal.java @@ -43,12 +43,13 @@ import org.graalvm.nativeimage.impl.InternalPlatform; import org.graalvm.word.PointerBase; +// Checkstyle: stop + /** - * Contains definitions from signal.h that we actually need. + * Definitions manually translated from the C header file signal.h. */ @CContext(PosixDirectives.class) public class Signal { - /* Allow lower-case type names, underscores in names, etc.: Checkstyle: stop. */ @CFunction public static native int kill(int pid, int sig); @@ -65,14 +66,11 @@ public class Signal { @CFunction public static native int sigprocmask(int how, sigset_tPointer set, sigset_tPointer oldset); - /** A pointer to a signal set. The implementation of a signal set is platform-specific. */ @CPointerTo(nameOfCType = "sigset_t") public interface sigset_tPointer extends PointerBase { } public interface SignalDispatcher extends CFunctionPointer { - - /** From signal(2): typedef void (*sig_t) (int). */ @InvokeCFunctionPointer void dispatch(int sig); } @@ -94,7 +92,6 @@ public interface SignalDispatcher extends CFunctionPointer { @CStruct public interface siginfo_t extends PointerBase { - /* Fields unused */ } @Platforms(InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class) @@ -135,56 +132,12 @@ public enum GregEnum { public native int getCValue(); } - @Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) @CStruct public interface ucontext_t extends PointerBase { - /*- - // AMD64 userlevel context. - typedef struct ucontext - { - unsigned long int uc_flags; - struct ucontext *uc_link; - stack_t uc_stack; - mcontext_t uc_mcontext; - __sigset_t uc_sigmask; - struct _libc_fpstate __fpregs_mem; - } ucontext_t; - - // Context to describe whole processor state. - typedef struct - { - gregset_t gregs; - // Note that fpregs is a pointer. - fpregset_t fpregs; - __extension__ unsigned long long __reserved1 [8]; - } mcontext_t; - */ @CFieldAddress("uc_mcontext.gregs") @Platforms({DeprecatedPlatform.LINUX_SUBSTITUTION_AMD64.class, Platform.LINUX_AMD64.class}) GregsPointer uc_mcontext_gregs(); - /*- - // AArch64 userlevel context. - typedef struct ucontext - { - unsigned long uc_flags; - struct ucontext *uc_link; - stack_t uc_stack; - __sigset_t uc_sigmask; - mcontext_t uc_mcontext; - } ucontext_t; - typedef struct sigcontext mcontext_t; - struct sigcontext { - __u64 fault_address; - // AArch64 registers - __u64 regs[31]; - __u64 sp; - __u64 pc; - __u64 pstate; - // 4K reserved for FP/SIMD state and future expansion - __u8 __reserved[4096] __attribute__((__aligned__(16))); - }; - */ @CFieldAddress("uc_mcontext") @Platforms({DeprecatedPlatform.LINUX_SUBSTITUTION_AARCH64.class, Platform.LINUX_AARCH64.class}) mcontext_t uc_mcontext(); @@ -192,7 +145,6 @@ public interface ucontext_t extends PointerBase { @CField("uc_mcontext") @Platforms({DeprecatedPlatform.DARWIN_SUBSTITUTION_AMD64.class, Platform.DARWIN_AMD64.class}) MContext64 uc_mcontext64(); - } @Platforms({DeprecatedPlatform.DARWIN_SUBSTITUTION_AMD64.class, Platform.DARWIN_AMD64.class}) @@ -274,28 +226,15 @@ public interface mcontext_t extends PointerBase { } public interface AdvancedSignalDispatcher extends CFunctionPointer { - - /** From SIGACTION(2): void (*sa_sigaction)(int, siginfo_t *, void *). */ @InvokeCFunctionPointer void dispatch(int signum, siginfo_t siginfo, WordPointer opaque); } - @Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) @CConstant public static native int SA_SIGINFO(); @CStruct(addStructKeyword = true) public interface sigaction extends PointerBase { - /*- - struct sigaction { - void (*sa_handler)(int); - void (*sa_sigaction)(int, siginfo_t *, void *); - sigset_t sa_mask; - int sa_flags; - void (*sa_restorer)(void); - }; - */ - @CField SignalDispatcher sa_handler(); @@ -383,6 +322,4 @@ public enum DarwinSignalEnum { @CFunction public static native int sigemptyset(sigset_tPointer set); - - /* Allow lower-case type names, underscores in names, etc.: Checkstyle: resume. */ } diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Stdlib.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Stdlib.java index da32e08d81e9..17984e0a4de3 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Stdlib.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Stdlib.java @@ -28,26 +28,14 @@ import org.graalvm.nativeimage.c.function.CFunction; import org.graalvm.nativeimage.c.type.CCharPointer; -//Checkstyle: stop +// Checkstyle: stop /** - * Contains the definitions from stdlib.h that we actually needed. + * Definitions manually translated from the C header file stdlib.h. */ @CContext(PosixDirectives.class) public class Stdlib { @CFunction public static native CCharPointer realpath(CCharPointer name, CCharPointer resolved); - - @CFunction - public static native CCharPointer mkdtemp(CCharPointer template); - - @CFunction - public static native CCharPointer getenv(CCharPointer name); - - @CFunction - public static native int setenv(CCharPointer name, CCharPointer value, int overwrite); - - @CFunction - public static native int unsetenv(CCharPointer name); } diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Sysctl.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Sysctl.java index 4caf5b3192f3..56366ec36e0d 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Sysctl.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Sysctl.java @@ -30,13 +30,14 @@ import org.graalvm.nativeimage.c.type.WordPointer; import org.graalvm.word.PointerBase; -/** Declarations of method from . */ +// Checkstyle: stop + +/** + * Definitions manually translated from the C header file sys/sysctl.h. + */ @CContext(PosixDirectives.class) public class Sysctl { - // { Allow names with underscores: Checkstyle: stop @CFunction public static native int sysctl(CIntPointer name, long nlen, PointerBase oldval, WordPointer oldlenp, PointerBase newval, long newlen); - - // } Allow names with underscores: Checkstyle: resume } diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Time.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Time.java index 81463cb0dc32..f5fc7e985480 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Time.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Time.java @@ -30,7 +30,6 @@ import org.graalvm.nativeimage.c.struct.AllowWideningCast; import org.graalvm.nativeimage.c.struct.CField; import org.graalvm.nativeimage.c.struct.CStruct; -import org.graalvm.nativeimage.c.type.CCharPointer; import org.graalvm.word.PointerBase; // Checkstyle: stop @@ -66,18 +65,6 @@ public interface timezone extends PointerBase { @CFunction(transition = CFunction.Transition.NO_TRANSITION) public static native int gettimeofday(timeval tv, timezone tz); - @CFunction - public static native int utimes(CCharPointer file, timeval tvp); - - @CFunction - public static native int lutimes(CCharPointer file, timeval tvp); - - @CFunction - public static native int futimes(int fd, timeval tvp); - - @CFunction - public static native int futimesat(int fd, CCharPointer file, timeval tvp); - @CStruct(addStructKeyword = true) public interface timespec extends PointerBase { @CField @@ -92,11 +79,4 @@ public interface timespec extends PointerBase { @CField void set_tv_nsec(long value); } - - @CFunction - public static native long time(PointerBase timer); - - @CFunction - public static native int nanosleep(timespec requested_time, timespec remaining); - } diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Times.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Times.java index 59feacd56da9..e519d2631413 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Times.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Times.java @@ -30,12 +30,13 @@ import org.graalvm.nativeimage.c.struct.CStruct; import org.graalvm.word.PointerBase; +//Checkstyle: stop + /** * Definitions manually translated from the C header file sys/times.h. */ @CContext(PosixDirectives.class) public class Times { - /* Allow lower-case type names: Checkstyle: stop. */ @CStruct(addStructKeyword = true) public interface tms extends PointerBase { @@ -67,6 +68,4 @@ public interface tms extends PointerBase { @CFunction public static native long times(tms tp); - - /* Allow lower-case type names: Checkstyle: resume. */ } diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Unistd.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Unistd.java index 447e4b21fca2..26839526f04e 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Unistd.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Unistd.java @@ -28,9 +28,9 @@ import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.constant.CConstant; import org.graalvm.nativeimage.c.function.CFunction; +import org.graalvm.nativeimage.c.function.CFunction.Transition; import org.graalvm.nativeimage.c.type.CCharPointer; import org.graalvm.nativeimage.c.type.CCharPointerPointer; -import org.graalvm.nativeimage.c.type.CIntPointer; import org.graalvm.nativeimage.impl.InternalPlatform; import org.graalvm.word.PointerBase; import org.graalvm.word.SignedWord; @@ -44,111 +44,33 @@ @CContext(PosixDirectives.class) public class Unistd { - @CConstant - public static native int R_OK(); - - @CConstant - public static native int W_OK(); - - @CConstant - public static native int X_OK(); - - @CConstant - public static native int F_OK(); - - @CConstant - public static native int STDIN_FILENO(); - - @CFunction - public static native int access(CCharPointer name, int type); - @CConstant public static native short SEEK_SET(); @CConstant public static native short SEEK_CUR(); - @CConstant - public static native short SEEK_END(); - @CFunction public static native SignedWord lseek(int fd, SignedWord offset, int whence); - @CFunction - public static native int close(int fd); - - @CFunction - public static native SignedWord read(int fd, PointerBase buf, UnsignedWord nbytes); - @CFunction public static native SignedWord write(int fd, PointerBase buf, UnsignedWord n); - @CFunction - public static native SignedWord pread(int fd, PointerBase buf, UnsignedWord nbytes, long offset); - - @CFunction - public static native SignedWord pwrite(int fd, PointerBase buf, UnsignedWord n, long offset); - - @CFunction - public static native int pipe(CIntPointer pipedes); - - @CFunction - public static native /* unsigned */ int sleep(/* unsigned */ int seconds); - - @CFunction - public static native int chown(CCharPointer file, /* unsigned */ int owner, /* unsigned */ int group); - - @CFunction - public static native int fchown(int fd, /* unsigned */ int owner, /* unsigned */ int group); - - @CFunction - public static native int lchown(CCharPointer file, /* unsigned */ int owner, /* unsigned */ int group); - - @CFunction - public static native int chdir(CCharPointer path); - @CFunction public static native CCharPointer getcwd(CCharPointer buf, UnsignedWord size); - @CFunction - public static native int dup(int fd); - - @CFunction - public static native int dup2(int fd, int fd2); - - @CFunction - public static native int execve(CCharPointer path, CCharPointerPointer argv, CCharPointerPointer envp); - @CFunction public static native int execv(CCharPointer path, CCharPointerPointer argv); - @CConstant - public static native int _PC_NAME_MAX(); - @CConstant public static native int _SC_CLK_TCK(); - @CConstant - public static native int _SC_OPEN_MAX(); - @CConstant public static native int _SC_PAGESIZE(); @CConstant public static native int _SC_PAGE_SIZE(); - @CConstant - public static native int _SC_IOV_MAX(); - - @CConstant - public static native int _SC_GETGR_R_SIZE_MAX(); - - @CConstant - public static native int _SC_GETPW_R_SIZE_MAX(); - - @CConstant - public static native int _SC_NPROCESSORS_ONLN(); - @CConstant @Platforms(InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class) public static native int _SC_PHYS_PAGES(); @@ -157,9 +79,6 @@ public class Unistd { @Platforms(InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class) public static native int _CS_DARWIN_USER_TEMP_DIR(); - @CFunction - public static native long pathconf(CCharPointer path, int name); - @CFunction public static native long sysconf(int name); @@ -169,21 +88,6 @@ public class Unistd { @CFunction public static native int getpid(); - @CFunction - public static native int getppid(); - - @CFunction - public static native int getpgrp(); - - @CFunction - public static native int getpgid(int pid); - - @CFunction - public static native int setpgid(int pid, int pgid); - - @CFunction - public static native int setsid(); - @CFunction public static native int getuid(); @@ -196,54 +100,9 @@ public class Unistd { @CFunction public static native int getegid(); - @CFunction - public static native int getgroups(int size, CIntPointer list); - - @CFunction - public static native int setuid(int uid); - - @CFunction - public static native int seteuid(int uid); - - @CFunction - public static native int setgid(int gid); - - @CFunction - public static native int setegid(int gid); - @CFunction public static native int fork(); - @CFunction - public static native int isatty(int fd); - - @CFunction - public static native int link(CCharPointer from, CCharPointer to); - - @CFunction - public static native int symlink(CCharPointer from, CCharPointer to); - - @CFunction - public static native SignedWord readlink(CCharPointer path, CCharPointer buf, UnsignedWord len); - - @CFunction - public static native int unlink(CCharPointer name); - - @CFunction - public static native int unlinkat(int fd, CCharPointer name, int flag); - - @CFunction - public static native int rmdir(CCharPointer path); - - @CFunction - public static native CCharPointer getlogin(); - - @CFunction - public static native int gethostname(CCharPointer name, UnsignedWord len); - - @CFunction - public static native int daemon(int nochdir, int noclose); - @CFunction public static native int fsync(int fd); @@ -253,21 +112,14 @@ public class Unistd { @CFunction public static native int getdtablesize(); - @CFunction - public static native int truncate(CCharPointer file, SignedWord length); - - @CFunction - public static native int ftruncate(int fd, long length); - - @CFunction - public static native int fdatasync(int fildes); - - @CFunction - public static native CCharPointer crypt(CCharPointer key, CCharPointer salt); + public static class NoTransitions { + @CFunction(transition = Transition.NO_TRANSITION) + public static native int close(int fd); - @CFunction - public static native SignedWord recvmsg(int socket, Socket.msghdr message, int flags); + @CFunction(transition = Transition.NO_TRANSITION) + public static native SignedWord read(int fd, PointerBase buf, UnsignedWord nbytes); - @CFunction - public static native SignedWord sendmsg(int socket, Socket.msghdr message, int flags); + @CFunction(transition = Transition.NO_TRANSITION) + public static native long sysconf(int name); + } } diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Utsname.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Utsname.java index 6603e24fbeb7..f3c5a26d8a01 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Utsname.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Utsname.java @@ -33,9 +33,12 @@ // Checkstyle: stop -/** Declarations of method from . */ +/** + * Definitions manually translated from the C header file sys/utsname.h. + */ @CContext(PosixDirectives.class) public class Utsname { + @CStruct(addStructKeyword = true) public interface utsname extends PointerBase { @CFieldAddress diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Wait.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Wait.java index 69d8eedd2f99..09d365316768 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Wait.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Wait.java @@ -28,19 +28,13 @@ import org.graalvm.nativeimage.c.function.CFunction; import org.graalvm.nativeimage.c.type.CIntPointer; +// Checkstyle: stop + /** - * Contains definitions from sys/wait.h that we need. + * Definitions manually translated from the C header sys/wait.h. */ @CContext(PosixDirectives.class) public class Wait { - /* Allow lower-case type names: Checkstyle: stop. */ - - /* - * Operating system dependency: The C function returns a pid_t, which happens to be an int on - * both Darwin and Linux, but it does not have to be an int on all platforms. - */ - @CFunction - public static native int wait(CIntPointer stat_loc); @CFunction public static native int waitpid(int pid, CIntPointer stat_loc, int options); @@ -66,6 +60,4 @@ public static boolean WIFSIGNALED(int status) { public static int WTERMSIG(int status) { return ((status) & 0x7F); } - - /* Allow lower-case type names: Checkstyle: resume. */ } diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/CoreFoundation.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/CoreFoundation.java index 5566dcc5a7eb..1c0612ed62fd 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/CoreFoundation.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/CoreFoundation.java @@ -24,24 +24,21 @@ */ package com.oracle.svm.core.posix.headers.darwin; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.function.CFunction; import org.graalvm.nativeimage.c.function.CLibrary; -import org.graalvm.nativeimage.impl.InternalPlatform; import org.graalvm.word.PointerBase; import org.graalvm.word.SignedWord; import com.oracle.svm.core.posix.headers.PosixDirectives; -//Checkstyle: stop +// Checkstyle: stop /** - * Contains the definitions from CoreFoundation/CoreFoundation.h that we actually needed. + * Definitions manually translated from the C header file CoreFoundation/CoreFoundation.h. */ @CContext(PosixDirectives.class) @CLibrary("-framework CoreFoundation") -@Platforms(InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class) public class CoreFoundation { public interface CFStringRef extends PointerBase { @@ -51,28 +48,15 @@ public interface CFMutableStringRef extends CFStringRef { } - /** - * Functions to create mutable strings. "maxLength", if not 0, is a hard bound on the length of - * the string. If 0, there is no limit on the length. - */ @CFunction public static native CFMutableStringRef CFStringCreateMutable(PointerBase alloc, SignedWord maxLength); @CFunction public static native void CFStringAppendCharacters(CFMutableStringRef theString, PointerBase chars, SignedWord numChars); - /** - * Normalizes the string into the specified form as described in Unicode Technical Report #15. - * - * @param theString The string which is to be normalized. If this parameter is not a valid - * mutable CFString, the behavior is undefined. - * @param theForm The form into which the string is to be normalized. If this parameter is not a - * valid CFStringNormalizationForm value, the behavior is undefined. - */ @CFunction public static native void CFStringNormalize(CFMutableStringRef theString, SignedWord theForm); - /** Number of 16-bit Unicode characters in the string. */ @CFunction public static native long CFStringGetLength(CFStringRef theString); diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinDyld.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinDyld.java index b1313e4d1a3d..75779b1f68bb 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinDyld.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinDyld.java @@ -24,24 +24,21 @@ */ package com.oracle.svm.core.posix.headers.darwin; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.function.CFunction; import org.graalvm.nativeimage.c.type.CCharPointer; import org.graalvm.nativeimage.c.type.CIntPointer; import com.oracle.svm.core.posix.headers.PosixDirectives; -import org.graalvm.nativeimage.impl.InternalPlatform; -// { Allow names with underscores: Checkstyle: stop +// Checkstyle: stop -/** Declarations of method from . */ -@Platforms(InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class) +/** + * Definitions manually translated from the C header file mach-o/dyld.h. + */ @CContext(PosixDirectives.class) public class DarwinDyld { @CFunction public static native int _NSGetExecutablePath(CCharPointer buf, CIntPointer bufsize); - } -// } Allow names with underscores: Checkstyle: resume diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinErrno.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinErrno.java index 8701017df36b..18e18c9bf581 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinErrno.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinErrno.java @@ -24,38 +24,13 @@ */ package com.oracle.svm.core.posix.headers.darwin; -import com.oracle.svm.core.headers.Errno; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.function.CFunction; import org.graalvm.nativeimage.c.type.CIntPointer; -import com.oracle.svm.core.annotate.Substitute; -import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.annotate.Uninterruptible; -import org.graalvm.nativeimage.impl.InternalPlatform; +// Checkstyle: stop -//Checkstyle: stop +public class DarwinErrno { -@Platforms(InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class) -class DarwinErrno { - - @TargetClass(Errno.class) - static final class Target_com_oracle_svm_core_headers_Errno { - @Substitute - @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) - private static int errno() { - return Util_com_oracle_svm_core_headers_Errno.__error().read(); - } - - @Substitute - @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) - public static void set_errno(int value) { - Util_com_oracle_svm_core_headers_Errno.__error().write(value); - } - } - - static final class Util_com_oracle_svm_core_headers_Errno { - @CFunction(transition = CFunction.Transition.NO_TRANSITION) - static native CIntPointer __error(); - } + @CFunction(transition = CFunction.Transition.NO_TRANSITION) + public static native CIntPointer __error(); } diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinPthread.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinPthread.java index 97c0ea606de0..1109dfd322a4 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinPthread.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinPthread.java @@ -24,24 +24,22 @@ */ package com.oracle.svm.core.posix.headers.darwin; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.function.CFunction; import org.graalvm.nativeimage.c.function.CFunction.Transition; import org.graalvm.nativeimage.c.function.CLibrary; import org.graalvm.nativeimage.c.type.CCharPointer; -import org.graalvm.nativeimage.impl.InternalPlatform; import org.graalvm.word.Pointer; import org.graalvm.word.UnsignedWord; import com.oracle.svm.core.posix.headers.PosixDirectives; import com.oracle.svm.core.posix.headers.Pthread; +// Checkstyle: stop + @CContext(PosixDirectives.class) -@Platforms(InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class) @CLibrary("pthread") public class DarwinPthread { - /* { Allow names with underscores: Checkstyle: stop */ @CFunction public static native int pthread_setname_np(CCharPointer name); @@ -51,6 +49,4 @@ public class DarwinPthread { @CFunction(transition = Transition.NO_TRANSITION) public static native Pointer pthread_get_stackaddr_np(Pthread.pthread_t thread); - - /* } Allow names with underscores: Checkstyle: resume */ } diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinStat.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinStat.java new file mode 100644 index 000000000000..16d33d4bc7df --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinStat.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2013, 2017, 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. + */ +package com.oracle.svm.core.posix.headers.darwin; + +import org.graalvm.nativeimage.c.CContext; +import org.graalvm.nativeimage.c.function.CFunction; +import org.graalvm.nativeimage.c.struct.CStruct; +import org.graalvm.word.PointerBase; + +import com.oracle.svm.core.posix.headers.PosixDirectives; + +// Checkstyle: stop + +/** + * Definitions manually translated from the C header file sys/stat.h. + */ +@CContext(PosixDirectives.class) +public class DarwinStat { + + @CStruct(addStructKeyword = true) + public interface stat extends PointerBase { + } + + @CFunction("fstat$INODE64") + public static native int fstat(int fd, stat buf); +} diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinSysctl.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinSysctl.java index 5ae2b8adf155..a964788f25fd 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinSysctl.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinSysctl.java @@ -24,18 +24,18 @@ */ package com.oracle.svm.core.posix.headers.darwin; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.constant.CConstant; import com.oracle.svm.core.posix.headers.PosixDirectives; -import org.graalvm.nativeimage.impl.InternalPlatform; -/** Declarations of method from . */ -@Platforms(InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class) +// Checkstyle: stop + +/** + * Definitions manually translated from the C header file sys/sysctl.h. + */ @CContext(PosixDirectives.class) public class DarwinSysctl { - // { Allow names with underscores: Checkstyle: stop @CConstant public static native int CTL_KERN(); @@ -51,6 +51,4 @@ public class DarwinSysctl { @CConstant public static native int HW_MEMSIZE(); - - // } Allow names with underscores: Checkstyle: resume } diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinSyslimits.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinSyslimits.java index 3ba931507019..74abfe19488b 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinSyslimits.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinSyslimits.java @@ -24,21 +24,19 @@ */ package com.oracle.svm.core.posix.headers.darwin; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.constant.CConstant; -import org.graalvm.nativeimage.impl.InternalPlatform; import com.oracle.svm.core.posix.headers.PosixDirectives; -/** Declarations of method from . */ -@Platforms(InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class) +// Checkstyle: stop + +/** + * Definitions manually translated from the C header file sys/syslimits.h. + */ @CContext(PosixDirectives.class) public class DarwinSyslimits { - // { Allow names with underscores: Checkstyle: stop @CConstant public static native int OPEN_MAX(); - - // } Allow names with underscores: Checkstyle: resume } diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinTime.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinTime.java index e5ed49e50822..7d84ab4bac24 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinTime.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinTime.java @@ -24,20 +24,17 @@ */ package com.oracle.svm.core.posix.headers.darwin; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.function.CFunction; import org.graalvm.nativeimage.c.struct.CField; import org.graalvm.nativeimage.c.struct.CStruct; -import org.graalvm.nativeimage.impl.InternalPlatform; import org.graalvm.word.PointerBase; import com.oracle.svm.core.posix.headers.PosixDirectives; -//Checkstyle: stop +// Checkstyle: stop @CContext(PosixDirectives.class) -@Platforms(InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class) public class DarwinTime { @CStruct("struct mach_timebase_info") diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinVirtualMemory.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinVirtualMemory.java index f5423a0cf9ac..b3f310ea4ac6 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinVirtualMemory.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/DarwinVirtualMemory.java @@ -24,20 +24,17 @@ */ package com.oracle.svm.core.posix.headers.darwin; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.function.CFunction; import org.graalvm.nativeimage.c.type.WordPointer; -import org.graalvm.nativeimage.impl.InternalPlatform; import org.graalvm.word.UnsignedWord; import org.graalvm.word.WordBase; import com.oracle.svm.core.posix.headers.PosixDirectives; -//Checkstyle: stop +// Checkstyle: stop @CContext(PosixDirectives.class) -@Platforms(InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class) public class DarwinVirtualMemory { @CFunction(transition = CFunction.Transition.NO_TRANSITION) @@ -51,5 +48,4 @@ public class DarwinVirtualMemory { @CFunction(transition = CFunction.Transition.NO_TRANSITION) public static native int vm_deallocate(int targetTask, WordBase address, UnsignedWord size); - } diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/package-info.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/package-info.java new file mode 100644 index 000000000000..124ad17012f6 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/darwin/package-info.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2019, 2019, 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. + */ + +@Platforms({InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) +package com.oracle.svm.core.posix.headers.darwin; + +import org.graalvm.nativeimage.Platforms; +import org.graalvm.nativeimage.impl.InternalPlatform; diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/linux/LinuxErrno.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/linux/LinuxErrno.java index 70c3d8d76171..73c16b201116 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/linux/LinuxErrno.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/linux/LinuxErrno.java @@ -24,39 +24,13 @@ */ package com.oracle.svm.core.posix.headers.linux; -import com.oracle.svm.core.headers.Errno; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.function.CFunction; import org.graalvm.nativeimage.c.type.CIntPointer; -import com.oracle.svm.core.annotate.Substitute; -import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.annotate.Uninterruptible; -import org.graalvm.nativeimage.impl.InternalPlatform; +// Checkstyle: stop -//Checkstyle: stop +public class LinuxErrno { -@Platforms(InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class) -class LinuxErrno { - - @TargetClass(Errno.class) - static final class Target_com_oracle_svm_core_headers_Errno { - - @Substitute - @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) - private static int errno() { - return Util_com_oracle_svm_core_headers_Errno.__errno_location().read(); - } - - @Substitute - @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) - public static void set_errno(int value) { - Util_com_oracle_svm_core_headers_Errno.__errno_location().write(value); - } - } - - static final class Util_com_oracle_svm_core_headers_Errno { - @CFunction(transition = CFunction.Transition.NO_TRANSITION) - static native CIntPointer __errno_location(); - } + @CFunction(transition = CFunction.Transition.NO_TRANSITION) + public static native CIntPointer __errno_location(); } diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Paths.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/linux/LinuxPaths.java similarity index 83% rename from substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Paths.java rename to substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/linux/LinuxPaths.java index f325fbdd4994..b93bd5787f4f 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Paths.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/linux/LinuxPaths.java @@ -22,19 +22,18 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.posix.headers; +package com.oracle.svm.core.posix.headers.linux; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.constant.CConstant; -import org.graalvm.nativeimage.impl.InternalPlatform; -/* Allow underscores in names: Checkstyle: stop. */ +import com.oracle.svm.core.posix.headers.PosixDirectives; + +// Checkstyle: stop @CContext(PosixDirectives.class) -public class Paths { +public class LinuxPaths { - @Platforms(InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class) @CConstant public static native String _PATH_VARTMP(); } diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/linux/LinuxPthread.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/linux/LinuxPthread.java index ccb7477be803..1399f02fff4b 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/linux/LinuxPthread.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/linux/LinuxPthread.java @@ -24,24 +24,20 @@ */ package com.oracle.svm.core.posix.headers.linux; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.function.CFunction; import org.graalvm.nativeimage.c.function.CLibrary; import org.graalvm.nativeimage.c.type.CCharPointer; -import org.graalvm.nativeimage.impl.InternalPlatform; import com.oracle.svm.core.posix.headers.PosixDirectives; import com.oracle.svm.core.posix.headers.Pthread.pthread_t; +// Checkstyle: stop + @CContext(PosixDirectives.class) @CLibrary("pthread") -@Platforms(InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class) public class LinuxPthread { - /* { Allow names with underscores: Checkstyle: stop */ @CFunction public static native int pthread_setname_np(pthread_t target_thread, CCharPointer name); - - /* } Allow names with underscores: Checkstyle: resume */ } diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/linux/LinuxStat.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/linux/LinuxStat.java new file mode 100644 index 000000000000..b5508e26003f --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/linux/LinuxStat.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2013, 2017, 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. + */ +package com.oracle.svm.core.posix.headers.linux; + +import org.graalvm.nativeimage.c.CContext; +import org.graalvm.nativeimage.c.function.CFunction; +import org.graalvm.nativeimage.c.struct.CField; +import org.graalvm.nativeimage.c.struct.CStruct; +import org.graalvm.word.PointerBase; + +import com.oracle.svm.core.posix.headers.PosixDirectives; + +// Checkstyle: stop + +/** + * Definitions manually translated from the C header file sys/stat.h. + */ +@CContext(PosixDirectives.class) +public class LinuxStat { + + @CStruct(addStructKeyword = true) + public interface stat64 extends PointerBase { + @CField + long st_ino(); + } + + @CFunction + public static native int fstat64(int fd, stat64 buf); + + public static class NoTransitions { + @CFunction(transition = CFunction.Transition.NO_TRANSITION) + public static native int fstat64(int fd, stat64 buf); + } +} diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/linux/LinuxTime.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/linux/LinuxTime.java index 8a740b7eaa55..ba16edcd859e 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/linux/LinuxTime.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/linux/LinuxTime.java @@ -24,12 +24,10 @@ */ package com.oracle.svm.core.posix.headers.linux; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.constant.CConstant; import org.graalvm.nativeimage.c.function.CFunction; import org.graalvm.nativeimage.c.function.CLibrary; -import org.graalvm.nativeimage.impl.InternalPlatform; import com.oracle.svm.core.posix.headers.PosixDirectives; import com.oracle.svm.core.posix.headers.Time; @@ -40,10 +38,8 @@ * Definitions manually translated from the C header file sys/time.h. */ @CContext(PosixDirectives.class) -@Platforms(InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class) public class LinuxTime extends Time { - /** Monotonic system-wide clock. */ @CConstant public static native int CLOCK_MONOTONIC(); diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/linux/package-info.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/linux/package-info.java new file mode 100644 index 000000000000..3f9a514f1960 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/linux/package-info.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2019, 2019, 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. + */ + +@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class}) +package com.oracle.svm.core.posix.headers.linux; + +import org.graalvm.nativeimage.Platforms; +import org.graalvm.nativeimage.impl.InternalPlatform; diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/package-info.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/package-info.java new file mode 100644 index 000000000000..a3b0ea4de111 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/package-info.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2019, 2019, 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. + */ + +@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) +package com.oracle.svm.core.posix.headers; + +import org.graalvm.nativeimage.Platforms; +import org.graalvm.nativeimage.impl.InternalPlatform; diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxCErrorNumberSupport.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxCErrorNumberSupport.java new file mode 100644 index 000000000000..75b884656861 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxCErrorNumberSupport.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2019, 2019, 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. + */ +package com.oracle.svm.core.posix.linux; + +import com.oracle.svm.core.CErrorNumber.CErrorNumberSupport; +import com.oracle.svm.core.annotate.Uninterruptible; +import com.oracle.svm.core.posix.headers.linux.LinuxErrno; + +class LinuxCErrorNumberSupport implements CErrorNumberSupport { + + @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) + @Override + public int getCErrorNumber() { + return LinuxErrno.__errno_location().read(); + } + + @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) + @Override + public void setCErrorNumber(int value) { + LinuxErrno.__errno_location().write(value); + } +} diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxImageHeapProvider.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxImageHeapProvider.java index c6591709ef0e..6908e58e1bd4 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxImageHeapProvider.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxImageHeapProvider.java @@ -31,12 +31,9 @@ import static com.oracle.svm.core.Isolates.IMAGE_HEAP_RELOCATABLE_END; import static com.oracle.svm.core.Isolates.IMAGE_HEAP_WRITABLE_BEGIN; import static com.oracle.svm.core.Isolates.IMAGE_HEAP_WRITABLE_END; -import static com.oracle.svm.core.posix.headers.Fcntl.NoTransitions.open; import static com.oracle.svm.core.posix.headers.LibC.free; import static com.oracle.svm.core.posix.headers.LibC.malloc; import static com.oracle.svm.core.posix.headers.LibC.memcpy; -import static com.oracle.svm.core.posix.headers.Stat.fstat_no_transition; -import static com.oracle.svm.core.posix.headers.UnistdNoTransitions.close; import static com.oracle.svm.core.posix.linux.ProcFSSupport.findMapping; import static com.oracle.svm.core.util.PointerUtils.roundUp; import static com.oracle.svm.core.util.UnsignedUtils.isAMultiple; @@ -46,13 +43,11 @@ import org.graalvm.compiler.nodes.extended.MembarNode; import org.graalvm.compiler.word.Word; import org.graalvm.nativeimage.ImageSingletons; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.StackValue; import org.graalvm.nativeimage.c.type.CCharPointer; import org.graalvm.nativeimage.c.type.CLongPointer; import org.graalvm.nativeimage.c.type.WordPointer; import org.graalvm.nativeimage.hosted.Feature; -import org.graalvm.nativeimage.impl.InternalPlatform; import org.graalvm.word.ComparableWord; import org.graalvm.word.LocationIdentity; import org.graalvm.word.Pointer; @@ -73,13 +68,12 @@ import com.oracle.svm.core.posix.PosixUtils; import com.oracle.svm.core.posix.headers.Fcntl; import com.oracle.svm.core.posix.headers.LibC; -import com.oracle.svm.core.posix.headers.Stat; -import com.oracle.svm.core.posix.headers.UnistdNoTransitions; +import com.oracle.svm.core.posix.headers.Unistd; +import com.oracle.svm.core.posix.headers.linux.LinuxStat; import jdk.vm.ci.code.MemoryBarriers; @AutomaticFeature -@Platforms(InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class) class LinuxImageHeapProviderFeature implements Feature { @Override public void duringSetup(DuringSetupAccess access) { @@ -166,7 +160,7 @@ public int initialize(Pointer reservedAddressSpace, UnsignedWord reservedSize, W * * NOTE: we do not use /proc/self/exe because it breaks with some tools like Valgrind. */ - int mapfd = open(PROC_SELF_MAPS.get(), Fcntl.O_RDONLY(), 0); + int mapfd = Fcntl.NoTransitions.open(PROC_SELF_MAPS.get(), Fcntl.O_RDONLY(), 0); if (mapfd == -1) { return CEntryPointErrors.LOCATE_IMAGE_FAILED; } @@ -175,25 +169,25 @@ public int initialize(Pointer reservedAddressSpace, UnsignedWord reservedSize, W final CLongPointer offset = StackValue.get(CLongPointer.class); final CLongPointer inode = StackValue.get(CLongPointer.class); boolean found = findMapping(mapfd, buffer, MAX_PATHLEN, IMAGE_HEAP_RELOCATABLE_BEGIN.get(), IMAGE_HEAP_RELOCATABLE_END.get(), startAddr, offset, inode, true); - close(mapfd); + Unistd.NoTransitions.close(mapfd); if (!found) { free(buffer); return CEntryPointErrors.LOCATE_IMAGE_FAILED; } - Stat.stat stat = StackValue.get(Stat.stat.class); - int opened = open(buffer, Fcntl.O_RDONLY(), 0); + LinuxStat.stat64 stat = StackValue.get(LinuxStat.stat64.class); + int opened = Fcntl.NoTransitions.open(buffer, Fcntl.O_RDONLY(), 0); if (opened < 0) { free(buffer); return CEntryPointErrors.OPEN_IMAGE_FAILED; } - if (fstat_no_transition(opened, stat) != 0) { + if (LinuxStat.NoTransitions.fstat64(opened, stat) != 0) { free(buffer); - close(opened); + Unistd.NoTransitions.close(opened); return CEntryPointErrors.LOCATE_IMAGE_FAILED; } if (stat.st_ino() != inode.read()) { boolean ignore = false; - int versionfd = open(PROC_VERSION.get(), Fcntl.O_RDONLY(), 0); + int versionfd = Fcntl.NoTransitions.open(PROC_VERSION.get(), Fcntl.O_RDONLY(), 0); if (versionfd != -1) { if (PosixUtils.readEntirely(versionfd, buffer, MAX_PATHLEN)) { /* @@ -203,11 +197,11 @@ public int initialize(Pointer reservedAddressSpace, UnsignedWord reservedSize, W */ ignore = LibC.strstr(buffer, PROC_VERSION_WSL_SUBSTRING.get()).isNonNull(); } - close(versionfd); + Unistd.NoTransitions.close(versionfd); } if (!ignore) { free(buffer); - close(opened); + Unistd.NoTransitions.close(opened); return CEntryPointErrors.LOCATE_IMAGE_IDENTITY_MISMATCH; } } @@ -221,7 +215,7 @@ public int initialize(Pointer reservedAddressSpace, UnsignedWord reservedSize, W if (previous.equal(fd)) { fd = signed(opened); } else { - UnistdNoTransitions.close(opened); + Unistd.NoTransitions.close(opened); fd = previous; } } diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxImageSingletonsFeature.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxImageSingletonsFeature.java new file mode 100644 index 000000000000..513594f6d626 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxImageSingletonsFeature.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2019, 2019, 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. + */ +package com.oracle.svm.core.posix.linux; + +import org.graalvm.nativeimage.ImageSingletons; +import org.graalvm.nativeimage.hosted.Feature; + +import com.oracle.svm.core.CErrorNumber.CErrorNumberSupport; +import com.oracle.svm.core.annotate.AutomaticFeature; + +@AutomaticFeature +class LinuxImageSingletonsFeature implements Feature { + + @Override + public void afterRegistration(AfterRegistrationAccess access) { + ImageSingletons.add(CErrorNumberSupport.class, new LinuxCErrorNumberSupport()); + } +} diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxPhysicalMemory.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxPhysicalMemory.java index 2727eb8ca233..6e0be321787e 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxPhysicalMemory.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxPhysicalMemory.java @@ -28,9 +28,7 @@ import java.io.IOException; import org.graalvm.nativeimage.ImageSingletons; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.hosted.Feature; -import org.graalvm.nativeimage.impl.InternalPlatform; import org.graalvm.word.UnsignedWord; import org.graalvm.word.WordFactory; @@ -45,7 +43,6 @@ import com.oracle.svm.core.thread.VMOperation; import com.oracle.svm.core.util.UnsignedUtils; -@Platforms(InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class) class LinuxPhysicalMemory extends PhysicalMemory { static class PhysicalMemorySupportImpl implements PhysicalMemorySupport { diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxProcessPropertiesSupport.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxProcessPropertiesSupport.java index 4d80d70c44a8..9df09d99bbed 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxProcessPropertiesSupport.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxProcessPropertiesSupport.java @@ -24,16 +24,13 @@ */ package com.oracle.svm.core.posix.linux; -import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.ImageSingletons; -import org.graalvm.nativeimage.Platforms; -import org.graalvm.nativeimage.impl.InternalPlatform; +import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.impl.ProcessPropertiesSupport; import com.oracle.svm.core.annotate.AutomaticFeature; import com.oracle.svm.core.posix.PosixProcessPropertiesSupport; -@Platforms(InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class) public class LinuxProcessPropertiesSupport extends PosixProcessPropertiesSupport { @Override diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxStackOverflowSupport.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxStackOverflowSupport.java index 17b27c0a4001..d4b36f26f27e 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxStackOverflowSupport.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxStackOverflowSupport.java @@ -24,12 +24,10 @@ */ package com.oracle.svm.core.posix.linux; -import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.ImageSingletons; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.StackValue; import org.graalvm.nativeimage.c.type.WordPointer; -import org.graalvm.nativeimage.impl.InternalPlatform; +import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.word.UnsignedWord; import com.oracle.svm.core.annotate.AutomaticFeature; @@ -38,7 +36,6 @@ import com.oracle.svm.core.posix.headers.Pthread; import com.oracle.svm.core.stack.StackOverflowCheck; -@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class}) class LinuxStackOverflowSupport implements StackOverflowCheck.OSSupport { @Uninterruptible(reason = "Called while thread is being attached to the VM, i.e., when the thread state is not yet set up.") @@ -67,7 +64,6 @@ public UnsignedWord lookupStackEnd() { } } -@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class}) @AutomaticFeature class LinuxStackOverflowSupportFeature implements Feature { @Override diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxSubstitutions.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxSubstitutions.java index a858f36c4061..22532ca825e5 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxSubstitutions.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxSubstitutions.java @@ -28,9 +28,7 @@ import static com.oracle.svm.core.posix.headers.linux.LinuxTime.CLOCK_MONOTONIC; import static com.oracle.svm.core.posix.headers.linux.LinuxTime.clock_gettime; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.StackValue; -import org.graalvm.nativeimage.impl.InternalPlatform; import org.graalvm.word.WordFactory; import com.oracle.svm.core.annotate.Substitute; @@ -40,9 +38,8 @@ import com.oracle.svm.core.posix.headers.Time.timeval; import com.oracle.svm.core.posix.headers.Time.timezone; -@Platforms(InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class) @TargetClass(java.lang.System.class) -final class Target_java_lang_System { +final class Target_java_lang_System_Linux { @Substitute @Uninterruptible(reason = "Does basic math after a simple system call") diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxSystemPropertiesSupport.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxSystemPropertiesSupport.java index d11e5cee9cf0..973a9aa52667 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxSystemPropertiesSupport.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxSystemPropertiesSupport.java @@ -24,25 +24,22 @@ */ package com.oracle.svm.core.posix.linux; -import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.ImageSingletons; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.StackValue; import org.graalvm.nativeimage.c.type.CTypeConversion; +import org.graalvm.nativeimage.hosted.Feature; import com.oracle.svm.core.annotate.AutomaticFeature; import com.oracle.svm.core.jdk.SystemPropertiesSupport; import com.oracle.svm.core.posix.PosixSystemPropertiesSupport; -import com.oracle.svm.core.posix.headers.Paths; import com.oracle.svm.core.posix.headers.Utsname; -import org.graalvm.nativeimage.impl.InternalPlatform; +import com.oracle.svm.core.posix.headers.linux.LinuxPaths; -@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class}) public class LinuxSystemPropertiesSupport extends PosixSystemPropertiesSupport { @Override protected String tmpdirValue() { - return Paths._PATH_VARTMP(); + return LinuxPaths._PATH_VARTMP(); } @Override @@ -55,7 +52,6 @@ protected String osVersionValue() { } } -@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class}) @AutomaticFeature class LinuxSystemPropertiesFeature implements Feature { @Override diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/package-info.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/package-info.java new file mode 100644 index 000000000000..06186aaedea0 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/package-info.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2019, 2019, 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. + */ + +@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class}) +package com.oracle.svm.core.posix.linux; + +import org.graalvm.nativeimage.Platforms; +import org.graalvm.nativeimage.impl.InternalPlatform; diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/package-info.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/package-info.java new file mode 100644 index 000000000000..60e82670e695 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/package-info.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2019, 2019, 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. + */ + +@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) +package com.oracle.svm.core.posix; + +import org.graalvm.nativeimage.Platforms; +import org.graalvm.nativeimage.impl.InternalPlatform; diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/pthread/PthreadVMLockSupport.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/pthread/PthreadVMLockSupport.java index 9d9261b59eae..968c2b1da25c 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/pthread/PthreadVMLockSupport.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/pthread/PthreadVMLockSupport.java @@ -33,7 +33,6 @@ import org.graalvm.nativeimage.StackValue; import org.graalvm.nativeimage.c.struct.SizeOf; import org.graalvm.nativeimage.hosted.Feature; -import org.graalvm.nativeimage.impl.InternalPlatform; import org.graalvm.word.UnsignedWord; import org.graalvm.word.WordFactory; @@ -43,11 +42,11 @@ import com.oracle.svm.core.annotate.UnknownObjectField; import com.oracle.svm.core.config.ConfigurationValues; import com.oracle.svm.core.config.ObjectLayout; -import com.oracle.svm.core.headers.Errno; import com.oracle.svm.core.locks.ClassInstanceReplacer; import com.oracle.svm.core.locks.VMCondition; import com.oracle.svm.core.locks.VMMutex; import com.oracle.svm.core.log.Log; +import com.oracle.svm.core.posix.headers.Errno; import com.oracle.svm.core.posix.headers.Pthread; import com.oracle.svm.core.posix.headers.Time; import com.oracle.svm.core.thread.VMThreads; @@ -59,7 +58,6 @@ * implemented via pthreads. */ @AutomaticFeature -@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) final class PthreadVMLockFeature implements Feature { private final ClassInstanceReplacer mutexReplacer = new ClassInstanceReplacer(VMMutex.class) { diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/pthread/package-info.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/pthread/package-info.java new file mode 100644 index 000000000000..03449cf919b9 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/pthread/package-info.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2019, 2019, 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. + */ + +@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) +package com.oracle.svm.core.posix.pthread; + +import org.graalvm.nativeimage.Platforms; +import org.graalvm.nativeimage.impl.InternalPlatform; diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/thread/PosixJavaThreads.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/thread/PosixJavaThreads.java index bc7277da207f..488375bcaa5d 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/thread/PosixJavaThreads.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/thread/PosixJavaThreads.java @@ -39,7 +39,6 @@ import org.graalvm.nativeimage.c.type.CTypeConversion; import org.graalvm.nativeimage.c.type.CTypeConversion.CCharPointerHolder; import org.graalvm.nativeimage.hosted.Feature; -import org.graalvm.nativeimage.impl.InternalPlatform; import org.graalvm.word.UnsignedWord; import org.graalvm.word.WordBase; import org.graalvm.word.WordFactory; @@ -55,10 +54,10 @@ import com.oracle.svm.core.c.function.CEntryPointOptions; import com.oracle.svm.core.c.function.CEntryPointOptions.Publish; import com.oracle.svm.core.c.function.CEntryPointSetup.LeaveDetachThreadEpilogue; -import com.oracle.svm.core.headers.Errno; import com.oracle.svm.core.log.Log; import com.oracle.svm.core.os.IsDefined; import com.oracle.svm.core.posix.PosixUtils; +import com.oracle.svm.core.posix.headers.Errno; import com.oracle.svm.core.posix.headers.LibC; import com.oracle.svm.core.posix.headers.Pthread; import com.oracle.svm.core.posix.headers.Pthread.pthread_attr_t; @@ -205,7 +204,6 @@ protected void beforeThreadRun(Thread thread) { } @TargetClass(Thread.class) -@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) final class Target_java_lang_Thread { @Inject @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset)// boolean hasPthreadIdentifier; @@ -362,7 +360,6 @@ public ParkEvent create() { } @AutomaticFeature -@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) class PosixThreadsFeature implements Feature { @Override public void afterRegistration(AfterRegistrationAccess access) { diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/thread/PosixVMThreads.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/thread/PosixVMThreads.java index 5700198f1e50..b874a5dc72f3 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/thread/PosixVMThreads.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/thread/PosixVMThreads.java @@ -26,12 +26,11 @@ import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.IsolateThread; -import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.function.CFunction; import org.graalvm.nativeimage.c.function.CFunction.Transition; import org.graalvm.nativeimage.c.type.CCharPointer; import org.graalvm.nativeimage.hosted.Feature; -import org.graalvm.nativeimage.impl.InternalPlatform; +import org.graalvm.word.PointerBase; import org.graalvm.word.WordFactory; import com.oracle.svm.core.annotate.AutomaticFeature; @@ -41,7 +40,6 @@ import com.oracle.svm.core.posix.PosixUtils; import com.oracle.svm.core.posix.headers.LibC; import com.oracle.svm.core.posix.headers.Pthread; -import com.oracle.svm.core.posix.headers.Stdio.FILE; import com.oracle.svm.core.posix.pthread.PthreadVMLockSupport; import com.oracle.svm.core.thread.VMThreads; @@ -84,6 +82,9 @@ public void freeIsolateThread(IsolateThread thread) { LibC.free(thread); } + interface FILE extends PointerBase { + } + @CFunction(value = "fdopen", transition = Transition.NO_TRANSITION) private static native FILE fdopen(int fd, CCharPointer mode); @@ -103,7 +104,6 @@ public void failFatally(int code, CCharPointer message) { } @AutomaticFeature -@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) class PosixVMThreadsFeature implements Feature { @Override public void afterRegistration(AfterRegistrationAccess access) { diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/thread/package-info.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/thread/package-info.java new file mode 100644 index 000000000000..e08a2355f785 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/thread/package-info.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2019, 2019, 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. + */ + +@Platforms({InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class, InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class}) +package com.oracle.svm.core.posix.thread; + +import org.graalvm.nativeimage.Platforms; +import org.graalvm.nativeimage.impl.InternalPlatform; diff --git a/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/PosixJavaIOSubstitutions_JDK11OrLater.java b/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/PosixJavaIOSubstitutions_JDK11OrLater.java index 29472b0f36c9..856a187cb7b3 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/PosixJavaIOSubstitutions_JDK11OrLater.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/PosixJavaIOSubstitutions_JDK11OrLater.java @@ -32,7 +32,7 @@ import com.oracle.svm.core.annotate.TargetClass; import com.oracle.svm.core.jdk.JDK11OrLater; import com.oracle.svm.core.posix.headers.Limits; -import com.oracle.svm.core.posix.headers.Unistd; +import com.oracle.svm.core.posixsubst.headers.Unistd; /** Dummy class to have a class with the file's name. */ public final class PosixJavaIOSubstitutions_JDK11OrLater { diff --git a/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/Target_java_io_FileCleanable.java b/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/Target_java_io_FileCleanable.java index 0ef8a576d912..e92620c9c114 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/Target_java_io_FileCleanable.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/Target_java_io_FileCleanable.java @@ -33,7 +33,7 @@ import com.oracle.svm.core.annotate.TargetClass; import com.oracle.svm.core.jdk.JDK11OrLater; import com.oracle.svm.core.posix.PosixUtils; -import com.oracle.svm.core.posix.headers.Unistd; +import com.oracle.svm.core.posixsubst.headers.Unistd; @Platforms({DeprecatedPlatform.LINUX_SUBSTITUTION.class, DeprecatedPlatform.DARWIN_SUBSTITUTION.class}) @TargetClass(className = "java.io.FileCleanable", onlyWith = JDK11OrLater.class) diff --git a/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/jdk11/PosixJavaNIOSubstitutions.java b/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/jdk11/PosixJavaNIOSubstitutions.java index f3e999fad3e0..c3e9598928db 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/jdk11/PosixJavaNIOSubstitutions.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/jdk11/PosixJavaNIOSubstitutions.java @@ -24,8 +24,8 @@ */ package com.oracle.svm.core.posixsubst.jdk11; -import static com.oracle.svm.core.posix.headers.Unistd.write; import static com.oracle.svm.core.posixsubst.PosixJavaNIOSubstitutions.convertReturnVal; +import static com.oracle.svm.core.posixsubst.headers.Unistd.write; import java.io.FileDescriptor; import java.io.IOException; @@ -41,7 +41,7 @@ import com.oracle.svm.core.jdk.JDK11OrLater; import com.oracle.svm.core.os.IsDefined; import com.oracle.svm.core.posix.PosixUtils; -import com.oracle.svm.core.posix.headers.Fcntl; +import com.oracle.svm.core.posixsubst.headers.Fcntl; import com.oracle.svm.core.posixsubst.headers.Statvfs; @Platforms({DeprecatedPlatform.LINUX_SUBSTITUTION.class, DeprecatedPlatform.DARWIN_SUBSTITUTION.class}) diff --git a/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/jdk11/darwin/Target_jdk_net_MacOSXSocketOptions.java b/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/jdk11/darwin/Target_jdk_net_MacOSXSocketOptions.java index 7fc1cf4619dd..1120f2c692bd 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/jdk11/darwin/Target_jdk_net_MacOSXSocketOptions.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/jdk11/darwin/Target_jdk_net_MacOSXSocketOptions.java @@ -24,15 +24,14 @@ */ package com.oracle.svm.core.posixsubst.jdk11.darwin; -import java.net.SocketException; +import static com.oracle.svm.core.posixsubst.headers.NetinetIn.IPPROTO_TCP; +import static com.oracle.svm.core.posixsubst.headers.NetinetTcp.TCP_KEEPALIVE; +import static com.oracle.svm.core.posixsubst.headers.NetinetTcp.TCP_KEEPCNT; +import static com.oracle.svm.core.posixsubst.headers.NetinetTcp.TCP_KEEPINTVL; +import static com.oracle.svm.core.posixsubst.jdk11.darwin.Util_jdk_net_MacOSXSocketOptions.handleError; +import static com.oracle.svm.core.posixsubst.jdk11.darwin.Util_jdk_net_MacOSXSocketOptions.socketOptionSupported; -import com.oracle.svm.core.annotate.Substitute; -import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.headers.Errno; -import com.oracle.svm.core.jdk.JDK11OrLater; -import com.oracle.svm.core.posix.PosixUtils; -import com.oracle.svm.core.posix.headers.Socket; -import com.oracle.svm.core.posixsubst.PosixJavaNetClose; +import java.net.SocketException; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platforms; @@ -41,12 +40,13 @@ import org.graalvm.nativeimage.c.type.CIntPointer; import org.graalvm.nativeimage.impl.DeprecatedPlatform; -import static com.oracle.svm.core.posixsubst.headers.NetinetIn.IPPROTO_TCP; -import static com.oracle.svm.core.posixsubst.headers.NetinetTcp.TCP_KEEPALIVE; -import static com.oracle.svm.core.posixsubst.headers.NetinetTcp.TCP_KEEPCNT; -import static com.oracle.svm.core.posixsubst.headers.NetinetTcp.TCP_KEEPINTVL; -import static com.oracle.svm.core.posixsubst.jdk11.darwin.Util_jdk_net_MacOSXSocketOptions.handleError; -import static com.oracle.svm.core.posixsubst.jdk11.darwin.Util_jdk_net_MacOSXSocketOptions.socketOptionSupported; +import com.oracle.svm.core.annotate.Substitute; +import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.jdk.JDK11OrLater; +import com.oracle.svm.core.posix.PosixUtils; +import com.oracle.svm.core.posixsubst.PosixJavaNetClose; +import com.oracle.svm.core.posixsubst.headers.Errno; +import com.oracle.svm.core.posixsubst.headers.Socket; @TargetClass(className = "jdk.net.MacOSXSocketOptions", onlyWith = JDK11OrLater.class) @Platforms({DeprecatedPlatform.DARWIN_SUBSTITUTION_AMD64.class}) diff --git a/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/jdk11/darwin/package-info.java b/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/jdk11/darwin/package-info.java index 7bc462f96821..dd2df2949cfc 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/jdk11/darwin/package-info.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/jdk11/darwin/package-info.java @@ -23,7 +23,7 @@ * questions. */ -@Platforms({DeprecatedPlatform.LINUX_SUBSTITUTION.class, DeprecatedPlatform.DARWIN_SUBSTITUTION.class}) +@Platforms({DeprecatedPlatform.DARWIN_SUBSTITUTION.class}) package com.oracle.svm.core.posixsubst.jdk11.darwin; import org.graalvm.nativeimage.Platforms; diff --git a/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/jdk11/linux/Target_jdk_net_LinuxSocketOptions.java b/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/jdk11/linux/Target_jdk_net_LinuxSocketOptions.java index 29768c7af2a6..4a0025bcbff5 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/jdk11/linux/Target_jdk_net_LinuxSocketOptions.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/jdk11/linux/Target_jdk_net_LinuxSocketOptions.java @@ -24,17 +24,21 @@ */ package com.oracle.svm.core.posixsubst.jdk11.linux; -import java.net.SocketException; +import static com.oracle.svm.core.posixsubst.headers.NetinetTcp.SOL_TCP; +import static com.oracle.svm.core.posixsubst.headers.NetinetTcp.TCP_KEEPCNT; +import static com.oracle.svm.core.posixsubst.headers.NetinetTcp.TCP_KEEPIDLE; +import static com.oracle.svm.core.posixsubst.headers.NetinetTcp.TCP_KEEPINTVL; +import static com.oracle.svm.core.posixsubst.headers.NetinetTcp.TCP_QUICKACK; +import static com.oracle.svm.core.posixsubst.headers.Socket.PF_INET; +import static com.oracle.svm.core.posixsubst.headers.Socket.SOCK_STREAM; +import static com.oracle.svm.core.posixsubst.headers.Socket.SOL_SOCKET; +import static com.oracle.svm.core.posixsubst.headers.Socket.getsockopt; +import static com.oracle.svm.core.posixsubst.headers.Socket.setsockopt; +import static com.oracle.svm.core.posixsubst.headers.Socket.socket; +import static com.oracle.svm.core.posixsubst.jdk11.linux.Util_jdk_net_LinuxSocketOptions.handleError; +import static com.oracle.svm.core.posixsubst.jdk11.linux.Util_jdk_net_LinuxSocketOptions.socketOptionSupported; -import com.oracle.svm.core.annotate.Substitute; -import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.headers.Errno; -import com.oracle.svm.core.jdk.JDK11OrLater; -import com.oracle.svm.core.posix.PosixUtils; -import com.oracle.svm.core.posix.headers.Socket; -import com.oracle.svm.core.posixsubst.PosixJavaNetClose; -import com.oracle.svm.core.posixsubst.headers.NetinetIn; -import com.oracle.svm.core.posixsubst.headers.NetinetTcp; +import java.net.SocketException; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platforms; @@ -43,19 +47,15 @@ import org.graalvm.nativeimage.c.type.CIntPointer; import org.graalvm.nativeimage.impl.DeprecatedPlatform; -import static com.oracle.svm.core.posix.headers.Socket.PF_INET; -import static com.oracle.svm.core.posix.headers.Socket.SOCK_STREAM; -import static com.oracle.svm.core.posix.headers.Socket.SOL_SOCKET; -import static com.oracle.svm.core.posix.headers.Socket.getsockopt; -import static com.oracle.svm.core.posix.headers.Socket.setsockopt; -import static com.oracle.svm.core.posix.headers.Socket.socket; -import static com.oracle.svm.core.posixsubst.headers.NetinetTcp.SOL_TCP; -import static com.oracle.svm.core.posixsubst.headers.NetinetTcp.TCP_KEEPCNT; -import static com.oracle.svm.core.posixsubst.headers.NetinetTcp.TCP_KEEPIDLE; -import static com.oracle.svm.core.posixsubst.headers.NetinetTcp.TCP_KEEPINTVL; -import static com.oracle.svm.core.posixsubst.headers.NetinetTcp.TCP_QUICKACK; -import static com.oracle.svm.core.posixsubst.jdk11.linux.Util_jdk_net_LinuxSocketOptions.handleError; -import static com.oracle.svm.core.posixsubst.jdk11.linux.Util_jdk_net_LinuxSocketOptions.socketOptionSupported; +import com.oracle.svm.core.annotate.Substitute; +import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.jdk.JDK11OrLater; +import com.oracle.svm.core.posix.PosixUtils; +import com.oracle.svm.core.posixsubst.PosixJavaNetClose; +import com.oracle.svm.core.posixsubst.headers.Errno; +import com.oracle.svm.core.posixsubst.headers.NetinetIn; +import com.oracle.svm.core.posixsubst.headers.NetinetTcp; +import com.oracle.svm.core.posixsubst.headers.Socket; @TargetClass(className = "jdk.net.LinuxSocketOptions", onlyWith = JDK11OrLater.class) @Platforms({DeprecatedPlatform.LINUX_SUBSTITUTION.class}) diff --git a/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/jdk11/linux/package-info.java b/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/jdk11/linux/package-info.java index cb4fe7877261..e228c8fcd36a 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/jdk11/linux/package-info.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst.jdk11/src/com/oracle/svm/core/posixsubst/jdk11/linux/package-info.java @@ -23,7 +23,7 @@ * questions. */ -@Platforms({DeprecatedPlatform.LINUX_SUBSTITUTION.class, DeprecatedPlatform.DARWIN_SUBSTITUTION.class}) +@Platforms({DeprecatedPlatform.LINUX_SUBSTITUTION.class}) package com.oracle.svm.core.posixsubst.jdk11.linux; import org.graalvm.nativeimage.Platforms; diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/JavaNetNetUtil.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/JavaNetNetUtil.java index 6913add3d657..f5ec0fbaa17f 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/JavaNetNetUtil.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/JavaNetNetUtil.java @@ -52,20 +52,20 @@ import org.graalvm.word.WordFactory; import com.oracle.svm.core.SubstrateUtil; -import com.oracle.svm.core.headers.Errno; import com.oracle.svm.core.os.IsDefined; import com.oracle.svm.core.posix.PosixUtils; import com.oracle.svm.core.posix.headers.LibC; -import com.oracle.svm.core.posix.headers.Socket; import com.oracle.svm.core.posix.headers.Sysctl; import com.oracle.svm.core.posix.headers.Time; -import com.oracle.svm.core.posix.headers.Unistd; import com.oracle.svm.core.posix.headers.darwin.DarwinSysctl; +import com.oracle.svm.core.posixsubst.headers.Errno; import com.oracle.svm.core.posixsubst.headers.Ioctl; import com.oracle.svm.core.posixsubst.headers.NetinetIn; import com.oracle.svm.core.posixsubst.headers.NetinetTcp; import com.oracle.svm.core.posixsubst.headers.Poll; import com.oracle.svm.core.posixsubst.headers.Poll.pollfd; +import com.oracle.svm.core.posixsubst.headers.Socket; +import com.oracle.svm.core.posixsubst.headers.Unistd; import com.oracle.svm.core.util.VMError; //Allow methods with non-standard names: Checkstyle: stop diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/JavaNetNetworkInterface.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/JavaNetNetworkInterface.java index cd4c41d681e9..3765e85a3efe 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/JavaNetNetworkInterface.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/JavaNetNetworkInterface.java @@ -31,7 +31,6 @@ import java.net.NetworkInterface; import java.net.SocketException; -import com.oracle.svm.core.util.Utf8; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.PinnedObject; import org.graalvm.nativeimage.Platforms; @@ -45,16 +44,17 @@ import org.graalvm.word.WordFactory; import com.oracle.svm.core.SubstrateUtil; -import com.oracle.svm.core.headers.Errno; import com.oracle.svm.core.log.Log; import com.oracle.svm.core.os.IsDefined; import com.oracle.svm.core.posix.PosixUtils; import com.oracle.svm.core.posix.headers.LibC; -import com.oracle.svm.core.posix.headers.Socket; -import com.oracle.svm.core.posix.headers.Unistd; +import com.oracle.svm.core.posixsubst.headers.Errno; import com.oracle.svm.core.posixsubst.headers.NetIf; import com.oracle.svm.core.posixsubst.headers.NetinetIn; +import com.oracle.svm.core.posixsubst.headers.Socket; +import com.oracle.svm.core.posixsubst.headers.Unistd; import com.oracle.svm.core.util.PointerUtils; +import com.oracle.svm.core.util.Utf8; /* { Do not format quoted code: @formatter:off */ /* { Allow non-standard names: Checkstyle: stop */ diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/Java_lang_Process_Supplement.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/Java_lang_Process_Supplement.java index 50d565ec368a..bc2d0f19d9a7 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/Java_lang_Process_Supplement.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/Java_lang_Process_Supplement.java @@ -48,18 +48,18 @@ import com.oracle.svm.core.LibCHelper; import com.oracle.svm.core.SubstrateUtil; import com.oracle.svm.core.annotate.Uninterruptible; -import com.oracle.svm.core.headers.Errno; import com.oracle.svm.core.heap.NoAllocationVerifier; import com.oracle.svm.core.posix.PosixUtils; -import com.oracle.svm.core.posix.headers.Fcntl; import com.oracle.svm.core.posix.headers.LibC; import com.oracle.svm.core.posix.headers.Limits; -import com.oracle.svm.core.posix.headers.Unistd; -import com.oracle.svm.core.posix.headers.UnistdNoTransitions; import com.oracle.svm.core.posixsubst.headers.Dirent; +import com.oracle.svm.core.posixsubst.headers.Errno; import com.oracle.svm.core.posixsubst.headers.Dirent.DIR; import com.oracle.svm.core.posixsubst.headers.Dirent.dirent; import com.oracle.svm.core.posixsubst.headers.Dirent.direntPointer; +import com.oracle.svm.core.posixsubst.headers.Fcntl; +import com.oracle.svm.core.posixsubst.headers.Unistd; +import com.oracle.svm.core.posixsubst.headers.UnistdNoTransitions; import com.oracle.svm.core.util.VMError; @Platforms({DeprecatedPlatform.LINUX_SUBSTITUTION.class, DeprecatedPlatform.DARWIN_SUBSTITUTION.class}) diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixJaasSubstitutions.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixJaasSubstitutions.java index e8800e9bb01a..00b46f9ebcec 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixJaasSubstitutions.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixJaasSubstitutions.java @@ -36,12 +36,12 @@ import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.headers.Errno; import com.oracle.svm.core.posix.headers.LibC; -import com.oracle.svm.core.posix.headers.Pwd; -import com.oracle.svm.core.posix.headers.Pwd.passwd; -import com.oracle.svm.core.posix.headers.Pwd.passwdPointer; -import com.oracle.svm.core.posix.headers.Unistd; +import com.oracle.svm.core.posixsubst.headers.Errno; +import com.oracle.svm.core.posixsubst.headers.Pwd; +import com.oracle.svm.core.posixsubst.headers.Pwd.passwd; +import com.oracle.svm.core.posixsubst.headers.Pwd.passwdPointer; +import com.oracle.svm.core.posixsubst.headers.Unistd; /** * Substitutions for the Java Authentication and Authorization Service (JAAS, diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixJavaIOSubstitutions.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixJavaIOSubstitutions.java index 0fad923e4ab6..f09f4a0f96d0 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixJavaIOSubstitutions.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixJavaIOSubstitutions.java @@ -24,60 +24,59 @@ */ package com.oracle.svm.core.posixsubst; +import static com.oracle.svm.core.CErrorNumber.getCErrorNumber; import static com.oracle.svm.core.annotate.RecomputeFieldValue.Kind.NewInstance; -import static com.oracle.svm.core.headers.Errno.EACCES; -import static com.oracle.svm.core.headers.Errno.EEXIST; -import static com.oracle.svm.core.headers.Errno.ENOENT; -import static com.oracle.svm.core.headers.Errno.ENOTDIR; -import static com.oracle.svm.core.headers.Errno.errno; -import static com.oracle.svm.core.posix.headers.Fcntl.O_APPEND; -import static com.oracle.svm.core.posix.headers.Fcntl.O_CREAT; -import static com.oracle.svm.core.posix.headers.Fcntl.O_DSYNC; -import static com.oracle.svm.core.posix.headers.Fcntl.O_RDONLY; -import static com.oracle.svm.core.posix.headers.Fcntl.O_RDWR; -import static com.oracle.svm.core.posix.headers.Fcntl.O_SYNC; -import static com.oracle.svm.core.posix.headers.Fcntl.O_TRUNC; -import static com.oracle.svm.core.posix.headers.Fcntl.O_WRONLY; -import static com.oracle.svm.core.posix.headers.Fcntl.open; import static com.oracle.svm.core.posix.headers.Limits.MAXPATHLEN; import static com.oracle.svm.core.posix.headers.Limits.PATH_MAX; -import static com.oracle.svm.core.posix.headers.Stat.S_IFCHR; -import static com.oracle.svm.core.posix.headers.Stat.S_IFDIR; -import static com.oracle.svm.core.posix.headers.Stat.S_IFIFO; -import static com.oracle.svm.core.posix.headers.Stat.S_IFMT; -import static com.oracle.svm.core.posix.headers.Stat.S_IFREG; -import static com.oracle.svm.core.posix.headers.Stat.S_IFSOCK; -import static com.oracle.svm.core.posix.headers.Stat.S_IRGRP; -import static com.oracle.svm.core.posix.headers.Stat.S_IROTH; -import static com.oracle.svm.core.posix.headers.Stat.S_IRUSR; -import static com.oracle.svm.core.posix.headers.Stat.S_IWGRP; -import static com.oracle.svm.core.posix.headers.Stat.S_IWOTH; -import static com.oracle.svm.core.posix.headers.Stat.S_IWUSR; -import static com.oracle.svm.core.posix.headers.Stat.S_IXGRP; -import static com.oracle.svm.core.posix.headers.Stat.S_IXOTH; -import static com.oracle.svm.core.posix.headers.Stat.S_IXUSR; -import static com.oracle.svm.core.posix.headers.Stat.chmod; -import static com.oracle.svm.core.posix.headers.Stat.fstat; -import static com.oracle.svm.core.posix.headers.Stat.mkdir; -import static com.oracle.svm.core.posix.headers.Stdio.remove; -import static com.oracle.svm.core.posix.headers.Stdio.rename; import static com.oracle.svm.core.posix.headers.Stdlib.realpath; -import static com.oracle.svm.core.posix.headers.Time.utimes; -import static com.oracle.svm.core.posix.headers.Unistd.R_OK; -import static com.oracle.svm.core.posix.headers.Unistd.SEEK_CUR; -import static com.oracle.svm.core.posix.headers.Unistd.SEEK_END; -import static com.oracle.svm.core.posix.headers.Unistd.SEEK_SET; -import static com.oracle.svm.core.posix.headers.Unistd.W_OK; -import static com.oracle.svm.core.posix.headers.Unistd.X_OK; -import static com.oracle.svm.core.posix.headers.Unistd.access; -import static com.oracle.svm.core.posix.headers.Unistd.close; -import static com.oracle.svm.core.posix.headers.Unistd.ftruncate; -import static com.oracle.svm.core.posix.headers.Unistd.lseek; import static com.oracle.svm.core.posixsubst.headers.Dirent.closedir; import static com.oracle.svm.core.posixsubst.headers.Dirent.opendir; import static com.oracle.svm.core.posixsubst.headers.Dirent.readdir_r; +import static com.oracle.svm.core.posixsubst.headers.Errno.EACCES; +import static com.oracle.svm.core.posixsubst.headers.Errno.EEXIST; +import static com.oracle.svm.core.posixsubst.headers.Errno.ENOENT; +import static com.oracle.svm.core.posixsubst.headers.Errno.ENOTDIR; +import static com.oracle.svm.core.posixsubst.headers.Fcntl.O_APPEND; +import static com.oracle.svm.core.posixsubst.headers.Fcntl.O_CREAT; +import static com.oracle.svm.core.posixsubst.headers.Fcntl.O_DSYNC; +import static com.oracle.svm.core.posixsubst.headers.Fcntl.O_RDONLY; +import static com.oracle.svm.core.posixsubst.headers.Fcntl.O_RDWR; +import static com.oracle.svm.core.posixsubst.headers.Fcntl.O_SYNC; +import static com.oracle.svm.core.posixsubst.headers.Fcntl.O_TRUNC; +import static com.oracle.svm.core.posixsubst.headers.Fcntl.O_WRONLY; +import static com.oracle.svm.core.posixsubst.headers.Fcntl.open; import static com.oracle.svm.core.posixsubst.headers.Ioctl.FIONREAD; import static com.oracle.svm.core.posixsubst.headers.Ioctl.ioctl; +import static com.oracle.svm.core.posixsubst.headers.Stat.S_IFCHR; +import static com.oracle.svm.core.posixsubst.headers.Stat.S_IFDIR; +import static com.oracle.svm.core.posixsubst.headers.Stat.S_IFIFO; +import static com.oracle.svm.core.posixsubst.headers.Stat.S_IFMT; +import static com.oracle.svm.core.posixsubst.headers.Stat.S_IFREG; +import static com.oracle.svm.core.posixsubst.headers.Stat.S_IFSOCK; +import static com.oracle.svm.core.posixsubst.headers.Stat.S_IRGRP; +import static com.oracle.svm.core.posixsubst.headers.Stat.S_IROTH; +import static com.oracle.svm.core.posixsubst.headers.Stat.S_IRUSR; +import static com.oracle.svm.core.posixsubst.headers.Stat.S_IWGRP; +import static com.oracle.svm.core.posixsubst.headers.Stat.S_IWOTH; +import static com.oracle.svm.core.posixsubst.headers.Stat.S_IWUSR; +import static com.oracle.svm.core.posixsubst.headers.Stat.S_IXGRP; +import static com.oracle.svm.core.posixsubst.headers.Stat.S_IXOTH; +import static com.oracle.svm.core.posixsubst.headers.Stat.S_IXUSR; +import static com.oracle.svm.core.posixsubst.headers.Stat.chmod; +import static com.oracle.svm.core.posixsubst.headers.Stat.fstat; +import static com.oracle.svm.core.posixsubst.headers.Stat.mkdir; +import static com.oracle.svm.core.posixsubst.headers.Stdio.remove; +import static com.oracle.svm.core.posixsubst.headers.Stdio.rename; +import static com.oracle.svm.core.posixsubst.headers.Unistd.R_OK; +import static com.oracle.svm.core.posixsubst.headers.Unistd.SEEK_CUR; +import static com.oracle.svm.core.posixsubst.headers.Unistd.SEEK_END; +import static com.oracle.svm.core.posixsubst.headers.Unistd.SEEK_SET; +import static com.oracle.svm.core.posixsubst.headers.Unistd.W_OK; +import static com.oracle.svm.core.posixsubst.headers.Unistd.X_OK; +import static com.oracle.svm.core.posixsubst.headers.Unistd.access; +import static com.oracle.svm.core.posixsubst.headers.Unistd.close; +import static com.oracle.svm.core.posixsubst.headers.Unistd.ftruncate; +import static com.oracle.svm.core.posixsubst.headers.Unistd.lseek; import java.io.File; import java.io.FileDescriptor; @@ -110,16 +109,17 @@ import com.oracle.svm.core.jdk.JDK8OrEarlier; import com.oracle.svm.core.posix.PosixUtils; import com.oracle.svm.core.posix.headers.LibC; -import com.oracle.svm.core.posix.headers.Stat; -import com.oracle.svm.core.posix.headers.Stat.stat; import com.oracle.svm.core.posix.headers.Time.timeval; -import com.oracle.svm.core.posixsubst.headers.Statvfs; -import com.oracle.svm.core.posixsubst.headers.Termios; import com.oracle.svm.core.posixsubst.headers.Dirent.DIR; import com.oracle.svm.core.posixsubst.headers.Dirent.dirent; import com.oracle.svm.core.posixsubst.headers.Dirent.direntPointer; +import com.oracle.svm.core.posixsubst.headers.Stat; +import com.oracle.svm.core.posixsubst.headers.Stat.stat; +import com.oracle.svm.core.posixsubst.headers.Statvfs; import com.oracle.svm.core.posixsubst.headers.Statvfs.statvfs; -import com.oracle.svm.core.posix.headers.Unistd; +import com.oracle.svm.core.posixsubst.headers.Termios; +import com.oracle.svm.core.posixsubst.headers.Time; +import com.oracle.svm.core.posixsubst.headers.Unistd; import com.oracle.svm.core.util.VMError; @TargetClass(className = "java.io.ExpiringCache") @@ -240,7 +240,7 @@ private String canonicalize0(String path) throws IOException { CCharPointer pathPtr = pathPin.get(); if (realpath(pathPtr, resolved).notEqual(WordFactory.zero())) { // that worked, so return it - return PosixUtils.collapse(CTypeConversion.toJavaString(resolved)); + return PosixSubstUtils.collapse(CTypeConversion.toJavaString(resolved)); } } @@ -265,7 +265,7 @@ private String canonicalize0(String path) throws IOException { CCharPointer resolvedPartPtr = pathPin.get(); r = realpath(resolvedPartPtr, resolved); } - int errno = errno(); + int errno = getCErrorNumber(); if (r.notEqual(WordFactory.zero())) { // the subpath has a canonical path break; @@ -286,10 +286,10 @@ private String canonicalize0(String path) throws IOException { if (rs.length() + 1 + unresolvedPart.length() > maxPathLen) { throw PosixUtils.newIOExceptionWithLastError("Bad pathname"); } - return PosixUtils.collapse(rs + "/" + unresolvedPart); + return PosixSubstUtils.collapse(rs + "/" + unresolvedPart); } else { // nothing resolved, so just return the original path - return PosixUtils.collapse(path); + return PosixSubstUtils.collapse(path); } } @@ -392,7 +392,7 @@ public boolean createFileExclusively(String path) throws IOException { if (path.equals("/")) { return false; } else { - try (CCharPointerHolder pathPin = CTypeConversion.toCString(PosixUtils.removeTrailingSlashes(path))) { + try (CCharPointerHolder pathPin = CTypeConversion.toCString(PosixSubstUtils.removeTrailingSlashes(path))) { CCharPointer pathPtr = pathPin.get(); fd = open(pathPtr, O_RDWR() | O_CREAT(), 0666); } @@ -438,7 +438,7 @@ public boolean setLastModifiedTime(File f, long time) { last.set_tv_sec(time / 1000); last.set_tv_usec((time % 1000) * 1000); - if (utimes(pathPtr, timeval) == 0) { + if (Time.utimes(pathPtr, timeval) == 0) { return true; } } @@ -455,28 +455,28 @@ final class Target_java_io_FileInputStream { @Substitute private int readBytes(byte[] b, int off, int len) throws IOException { - return PosixUtils.readBytes(b, off, len, fd); + return PosixSubstUtils.readBytes(b, off, len, fd); } @Substitute private void open(String name) throws FileNotFoundException { - PosixUtils.fileOpen(name, fd, O_RDONLY()); + PosixSubstUtils.fileOpen(name, fd, O_RDONLY()); } @Substitute // @TargetElement(onlyWith = JDK8OrEarlier.class) private void close0() throws IOException { - PosixUtils.fileClose(fd); + PosixSubstUtils.fileClose(fd); } @Substitute public int read() throws IOException { - return PosixUtils.readSingle(fd); + return PosixSubstUtils.readSingle(fd); } @Substitute public int available() throws IOException { - int handle = PosixUtils.getFDHandle(fd); + int handle = PosixSubstUtils.getFDHandle(fd); SignedWord ret = WordFactory.zero(); boolean av = false; @@ -521,7 +521,7 @@ public int available() throws IOException { public long skip(long n) throws IOException { SignedWord cur = WordFactory.zero(); SignedWord end = WordFactory.zero(); - int handle = PosixUtils.getFDHandle(fd); + int handle = PosixSubstUtils.getFDHandle(fd); if ((cur = lseek(handle, WordFactory.zero(), SEEK_CUR())).equal(WordFactory.signed(-1))) { throw PosixUtils.newIOExceptionWithLastError("Seek error"); @@ -554,23 +554,23 @@ final class Target_java_io_FileOutputStream { @Substitute protected void writeBytes(byte[] bytes, int off, int len, boolean append) throws IOException { - PosixUtils.writeBytes(SubstrateUtil.getFileDescriptor(SubstrateUtil.cast(this, FileOutputStream.class)), bytes, off, len, append); + PosixSubstUtils.writeBytes(SubstrateUtil.getFileDescriptor(SubstrateUtil.cast(this, FileOutputStream.class)), bytes, off, len, append); } @Substitute private void open(String name, boolean append) throws FileNotFoundException { - PosixUtils.fileOpen(name, SubstrateUtil.getFileDescriptor(SubstrateUtil.cast(this, FileOutputStream.class)), O_WRONLY() | O_CREAT() | (append ? O_APPEND() : O_TRUNC())); + PosixSubstUtils.fileOpen(name, SubstrateUtil.getFileDescriptor(SubstrateUtil.cast(this, FileOutputStream.class)), O_WRONLY() | O_CREAT() | (append ? O_APPEND() : O_TRUNC())); } @Substitute // @TargetElement(onlyWith = JDK8OrEarlier.class) private void close0() throws IOException { - PosixUtils.fileClose(SubstrateUtil.getFileDescriptor(SubstrateUtil.cast(this, FileOutputStream.class))); + PosixSubstUtils.fileClose(SubstrateUtil.getFileDescriptor(SubstrateUtil.cast(this, FileOutputStream.class))); } @Substitute private void write(int b, boolean append) throws IOException { - PosixUtils.writeSingle(SubstrateUtil.getFileDescriptor(SubstrateUtil.cast(this, FileOutputStream.class)), b, append); + PosixSubstUtils.writeSingle(SubstrateUtil.getFileDescriptor(SubstrateUtil.cast(this, FileOutputStream.class)), b, append); } } @@ -589,27 +589,27 @@ final class Target_java_io_RandomAccessFile { @Substitute public int read() throws IOException { - return PosixUtils.readSingle(fd); + return PosixSubstUtils.readSingle(fd); } @Substitute private int readBytes(byte[] b, int off, int len) throws IOException { - return PosixUtils.readBytes(b, off, len, fd); + return PosixSubstUtils.readBytes(b, off, len, fd); } @Substitute public void write(int b) throws IOException { - PosixUtils.writeSingle(fd, b, false); + PosixSubstUtils.writeSingle(fd, b, false); } @Substitute private void writeBytes(byte[] b, int off, int len) throws IOException { - PosixUtils.writeBytes(fd, b, off, len, false); + PosixSubstUtils.writeBytes(fd, b, off, len, false); } @Substitute private void seek(long pos) throws IOException { - int handle = PosixUtils.getFDHandle(fd); + int handle = PosixSubstUtils.getFDHandle(fd); if (pos < 0L) { throw PosixUtils.newIOExceptionWithLastError("Negative seek offset"); } else if (lseek(handle, WordFactory.signed(pos), SEEK_SET()).equal(WordFactory.signed(-1))) { @@ -621,7 +621,7 @@ private void seek(long pos) throws IOException { @Substitute public long getFilePointer() throws IOException { SignedWord ret; - int handle = PosixUtils.getFDHandle(fd); + int handle = PosixSubstUtils.getFDHandle(fd); if ((ret = lseek(handle, WordFactory.zero(), SEEK_CUR())).equal(WordFactory.signed(-1))) { throw PosixUtils.newIOExceptionWithLastError("Seek failed"); } @@ -642,20 +642,20 @@ private void open(String name, int mode) throws FileNotFoundException { flags |= O_DSYNC(); } } - PosixUtils.fileOpen(name, fd, flags); + PosixSubstUtils.fileOpen(name, fd, flags); } @Substitute // @TargetElement(onlyWith = JDK8OrEarlier.class) private void close0() throws IOException { - PosixUtils.fileClose(fd); + PosixSubstUtils.fileClose(fd); } @Substitute public long length() throws IOException { SignedWord cur = WordFactory.zero(); SignedWord end = WordFactory.zero(); - int handle = PosixUtils.getFDHandle(fd); + int handle = PosixSubstUtils.getFDHandle(fd); if ((cur = lseek(handle, WordFactory.zero(), SEEK_CUR())).equal(WordFactory.signed(-1))) { throw PosixUtils.newIOExceptionWithLastError("Seek failed"); @@ -670,7 +670,7 @@ public long length() throws IOException { @Substitute public void setLength(long newLength) throws IOException { SignedWord cur; - int handle = PosixUtils.getFDHandle(fd); + int handle = PosixSubstUtils.getFDHandle(fd); if ((cur = lseek(handle, WordFactory.zero(), SEEK_CUR())).equal(WordFactory.signed(-1))) { throw PosixUtils.newIOExceptionWithLastError("setLength failed"); diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixJavaLangSubstitutions.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixJavaLangSubstitutions.java index f75d0bffc069..cf524cbba5e8 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixJavaLangSubstitutions.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixJavaLangSubstitutions.java @@ -54,7 +54,7 @@ import com.oracle.svm.core.posix.PosixUtils; import com.oracle.svm.core.posix.headers.LibC; import com.oracle.svm.core.posix.headers.Signal; -import com.oracle.svm.core.posix.headers.Unistd; +import com.oracle.svm.core.posixsubst.headers.Unistd; import com.oracle.svm.core.util.PointerUtils; @TargetClass(className = "java.lang.ProcessEnvironment") diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixJavaNIOSubstitutions.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixJavaNIOSubstitutions.java index 45735b5ec0d7..7abc81a2dc31 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixJavaNIOSubstitutions.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixJavaNIOSubstitutions.java @@ -24,33 +24,7 @@ */ package com.oracle.svm.core.posixsubst; -import static com.oracle.svm.core.headers.Errno.EACCES; -import static com.oracle.svm.core.headers.Errno.EAGAIN; -import static com.oracle.svm.core.headers.Errno.ECANCELED; -import static com.oracle.svm.core.headers.Errno.EINTR; -import static com.oracle.svm.core.headers.Errno.EINVAL; -import static com.oracle.svm.core.headers.Errno.ENOENT; -import static com.oracle.svm.core.headers.Errno.ENOMEM; -import static com.oracle.svm.core.headers.Errno.ENOTCONN; -import static com.oracle.svm.core.headers.Errno.ENOTSOCK; -import static com.oracle.svm.core.headers.Errno.ENOTSUP; -import static com.oracle.svm.core.headers.Errno.EOPNOTSUPP; -import static com.oracle.svm.core.headers.Errno.ERANGE; -import static com.oracle.svm.core.headers.Errno.ESRCH; -import static com.oracle.svm.core.headers.Errno.errno; import static com.oracle.svm.core.posix.headers.Dlfcn.RTLD_DEFAULT; -import static com.oracle.svm.core.posix.headers.Fcntl.F_GETFL; -import static com.oracle.svm.core.posix.headers.Fcntl.F_RDLCK; -import static com.oracle.svm.core.posix.headers.Fcntl.F_SETFL; -import static com.oracle.svm.core.posix.headers.Fcntl.F_SETLK; -import static com.oracle.svm.core.posix.headers.Fcntl.F_SETLKW; -import static com.oracle.svm.core.posix.headers.Fcntl.F_UNLCK; -import static com.oracle.svm.core.posix.headers.Fcntl.F_WRLCK; -import static com.oracle.svm.core.posix.headers.Fcntl.O_NONBLOCK; -import static com.oracle.svm.core.posix.headers.Fcntl.fcntl; -import static com.oracle.svm.core.posix.headers.Fcntl.open; -import static com.oracle.svm.core.posix.headers.Grp.getgrgid_r; -import static com.oracle.svm.core.posix.headers.Grp.getgrnam_r; import static com.oracle.svm.core.posix.headers.Limits.PATH_MAX; import static com.oracle.svm.core.posix.headers.Mman.MAP_FAILED; import static com.oracle.svm.core.posix.headers.Mman.MAP_PRIVATE; @@ -59,50 +33,76 @@ import static com.oracle.svm.core.posix.headers.Mman.PROT_WRITE; import static com.oracle.svm.core.posix.headers.Mman.mmap; import static com.oracle.svm.core.posix.headers.Mman.munmap; -import static com.oracle.svm.core.posix.headers.Pwd.getpwnam_r; -import static com.oracle.svm.core.posix.headers.Pwd.getpwuid_r; import static com.oracle.svm.core.posix.headers.Resource.RLIMIT_NOFILE; import static com.oracle.svm.core.posix.headers.Resource.getrlimit; -import static com.oracle.svm.core.posix.headers.Stat.chmod; -import static com.oracle.svm.core.posix.headers.Stat.fstat; -import static com.oracle.svm.core.posix.headers.Stat.lstat; -import static com.oracle.svm.core.posix.headers.Stat.mkdir; -import static com.oracle.svm.core.posix.headers.Stat.mknod; -import static com.oracle.svm.core.posix.headers.Stdio.EOF; -import static com.oracle.svm.core.posix.headers.Stdio.fopen; -import static com.oracle.svm.core.posix.headers.Uio.readv; -import static com.oracle.svm.core.posix.headers.Uio.writev; -import static com.oracle.svm.core.posix.headers.Unistd.SEEK_CUR; -import static com.oracle.svm.core.posix.headers.Unistd.SEEK_SET; -import static com.oracle.svm.core.posix.headers.Unistd._SC_GETGR_R_SIZE_MAX; -import static com.oracle.svm.core.posix.headers.Unistd._SC_GETPW_R_SIZE_MAX; -import static com.oracle.svm.core.posix.headers.Unistd._SC_IOV_MAX; -import static com.oracle.svm.core.posix.headers.Unistd.access; -import static com.oracle.svm.core.posix.headers.Unistd.chown; -import static com.oracle.svm.core.posix.headers.Unistd.close; -import static com.oracle.svm.core.posix.headers.Unistd.dup2; -import static com.oracle.svm.core.posix.headers.Unistd.fdatasync; -import static com.oracle.svm.core.posix.headers.Unistd.fsync; -import static com.oracle.svm.core.posix.headers.Unistd.ftruncate; -import static com.oracle.svm.core.posix.headers.Unistd.lchown; -import static com.oracle.svm.core.posix.headers.Unistd.link; -import static com.oracle.svm.core.posix.headers.Unistd.lseek; -import static com.oracle.svm.core.posix.headers.Unistd.pathconf; -import static com.oracle.svm.core.posix.headers.Unistd.pipe; -import static com.oracle.svm.core.posix.headers.Unistd.pread; -import static com.oracle.svm.core.posix.headers.Unistd.pwrite; -import static com.oracle.svm.core.posix.headers.Unistd.read; -import static com.oracle.svm.core.posix.headers.Unistd.readlink; -import static com.oracle.svm.core.posix.headers.Unistd.rmdir; -import static com.oracle.svm.core.posix.headers.Unistd.symlink; -import static com.oracle.svm.core.posix.headers.Unistd.sysconf; -import static com.oracle.svm.core.posix.headers.Unistd.unlink; -import static com.oracle.svm.core.posix.headers.Unistd.write; import static com.oracle.svm.core.posix.headers.darwin.CoreFoundation.CFRelease; -import static com.oracle.svm.core.posix.headers.linux.LinuxSendfile.sendfile; import static com.oracle.svm.core.posixsubst.headers.Dirent.opendir; import static com.oracle.svm.core.posixsubst.headers.Dirent.readdir_r; +import static com.oracle.svm.core.posixsubst.headers.Errno.EACCES; +import static com.oracle.svm.core.posixsubst.headers.Errno.EAGAIN; +import static com.oracle.svm.core.posixsubst.headers.Errno.ECANCELED; +import static com.oracle.svm.core.posixsubst.headers.Errno.EINTR; +import static com.oracle.svm.core.posixsubst.headers.Errno.EINVAL; +import static com.oracle.svm.core.posixsubst.headers.Errno.ENOENT; +import static com.oracle.svm.core.posixsubst.headers.Errno.ENOMEM; +import static com.oracle.svm.core.posixsubst.headers.Errno.ENOTCONN; +import static com.oracle.svm.core.posixsubst.headers.Errno.ENOTSOCK; +import static com.oracle.svm.core.posixsubst.headers.Errno.ENOTSUP; +import static com.oracle.svm.core.posixsubst.headers.Errno.EOPNOTSUPP; +import static com.oracle.svm.core.posixsubst.headers.Errno.ERANGE; +import static com.oracle.svm.core.posixsubst.headers.Errno.ESRCH; +import static com.oracle.svm.core.posixsubst.headers.Errno.errno; +import static com.oracle.svm.core.posixsubst.headers.Fcntl.F_GETFL; +import static com.oracle.svm.core.posixsubst.headers.Fcntl.F_RDLCK; +import static com.oracle.svm.core.posixsubst.headers.Fcntl.F_SETFL; +import static com.oracle.svm.core.posixsubst.headers.Fcntl.F_SETLK; +import static com.oracle.svm.core.posixsubst.headers.Fcntl.F_SETLKW; +import static com.oracle.svm.core.posixsubst.headers.Fcntl.F_UNLCK; +import static com.oracle.svm.core.posixsubst.headers.Fcntl.F_WRLCK; +import static com.oracle.svm.core.posixsubst.headers.Fcntl.O_NONBLOCK; +import static com.oracle.svm.core.posixsubst.headers.Fcntl.fcntl; +import static com.oracle.svm.core.posixsubst.headers.Fcntl.open; +import static com.oracle.svm.core.posixsubst.headers.Grp.getgrgid_r; +import static com.oracle.svm.core.posixsubst.headers.Grp.getgrnam_r; +import static com.oracle.svm.core.posixsubst.headers.Pwd.getpwnam_r; +import static com.oracle.svm.core.posixsubst.headers.Pwd.getpwuid_r; +import static com.oracle.svm.core.posixsubst.headers.Stat.chmod; +import static com.oracle.svm.core.posixsubst.headers.Stat.fstat; +import static com.oracle.svm.core.posixsubst.headers.Stat.lstat; +import static com.oracle.svm.core.posixsubst.headers.Stat.mkdir; +import static com.oracle.svm.core.posixsubst.headers.Stat.mknod; +import static com.oracle.svm.core.posixsubst.headers.Stdio.EOF; +import static com.oracle.svm.core.posixsubst.headers.Stdio.fopen; +import static com.oracle.svm.core.posixsubst.headers.Uio.readv; +import static com.oracle.svm.core.posixsubst.headers.Uio.writev; +import static com.oracle.svm.core.posixsubst.headers.Unistd.SEEK_CUR; +import static com.oracle.svm.core.posixsubst.headers.Unistd.SEEK_SET; +import static com.oracle.svm.core.posixsubst.headers.Unistd._SC_GETGR_R_SIZE_MAX; +import static com.oracle.svm.core.posixsubst.headers.Unistd._SC_GETPW_R_SIZE_MAX; +import static com.oracle.svm.core.posixsubst.headers.Unistd._SC_IOV_MAX; +import static com.oracle.svm.core.posixsubst.headers.Unistd.access; +import static com.oracle.svm.core.posixsubst.headers.Unistd.chown; +import static com.oracle.svm.core.posixsubst.headers.Unistd.close; +import static com.oracle.svm.core.posixsubst.headers.Unistd.dup2; +import static com.oracle.svm.core.posixsubst.headers.Unistd.fdatasync; +import static com.oracle.svm.core.posixsubst.headers.Unistd.fsync; +import static com.oracle.svm.core.posixsubst.headers.Unistd.ftruncate; +import static com.oracle.svm.core.posixsubst.headers.Unistd.lchown; +import static com.oracle.svm.core.posixsubst.headers.Unistd.link; +import static com.oracle.svm.core.posixsubst.headers.Unistd.lseek; +import static com.oracle.svm.core.posixsubst.headers.Unistd.pathconf; +import static com.oracle.svm.core.posixsubst.headers.Unistd.pipe; +import static com.oracle.svm.core.posixsubst.headers.Unistd.pread; +import static com.oracle.svm.core.posixsubst.headers.Unistd.pwrite; +import static com.oracle.svm.core.posixsubst.headers.Unistd.read; +import static com.oracle.svm.core.posixsubst.headers.Unistd.readlink; +import static com.oracle.svm.core.posixsubst.headers.Unistd.rmdir; +import static com.oracle.svm.core.posixsubst.headers.Unistd.symlink; +import static com.oracle.svm.core.posixsubst.headers.Unistd.sysconf; +import static com.oracle.svm.core.posixsubst.headers.Unistd.unlink; +import static com.oracle.svm.core.posixsubst.headers.Unistd.write; import static com.oracle.svm.core.posixsubst.headers.darwin.DarwinSendfile.sendfile; +import static com.oracle.svm.core.posixsubst.headers.linux.LinuxSendfile.sendfile; import static com.oracle.svm.core.posixsubst.headers.linux.Mntent.getmntent_r; import static com.oracle.svm.core.posixsubst.headers.linux.Mntent.setmntent; @@ -148,7 +148,6 @@ import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; import com.oracle.svm.core.annotate.TargetElement; -import com.oracle.svm.core.headers.Errno; import com.oracle.svm.core.jdk.JDK11OrEarlier; import com.oracle.svm.core.jdk.JDK11OrLater; import com.oracle.svm.core.jdk.JDK8OrEarlier; @@ -157,33 +156,34 @@ import com.oracle.svm.core.posix.PosixUtils; import com.oracle.svm.core.posix.darwin.DarwinCoreFoundationUtils; import com.oracle.svm.core.posix.headers.Dlfcn; -import com.oracle.svm.core.posix.headers.Fcntl; -import com.oracle.svm.core.posix.headers.Fcntl.flock; -import com.oracle.svm.core.posix.headers.Grp.group; -import com.oracle.svm.core.posix.headers.Grp.groupPointer; import com.oracle.svm.core.posix.headers.LibC; import com.oracle.svm.core.posix.headers.Pthread; -import com.oracle.svm.core.posix.headers.Pwd.passwd; -import com.oracle.svm.core.posix.headers.Pwd.passwdPointer; import com.oracle.svm.core.posix.headers.Resource.rlimit; -import com.oracle.svm.core.posix.headers.Socket; -import com.oracle.svm.core.posix.headers.Socket.sockaddr; -import com.oracle.svm.core.posix.headers.Stat; -import com.oracle.svm.core.posix.headers.Stdio; -import com.oracle.svm.core.posix.headers.Stdio.FILE; import com.oracle.svm.core.posix.headers.Stdlib; -import com.oracle.svm.core.posix.headers.Time; +import com.oracle.svm.core.posixsubst.headers.Time; import com.oracle.svm.core.posix.headers.Time.timeval; -import com.oracle.svm.core.posix.headers.Uio.iovec; -import com.oracle.svm.core.posix.headers.Unistd; import com.oracle.svm.core.posix.headers.darwin.CoreFoundation; import com.oracle.svm.core.posixsubst.headers.Dirent; +import com.oracle.svm.core.posixsubst.headers.Errno; +import com.oracle.svm.core.posixsubst.headers.Fcntl; import com.oracle.svm.core.posixsubst.headers.NetinetIn; import com.oracle.svm.core.posixsubst.headers.Poll; +import com.oracle.svm.core.posixsubst.headers.Socket; +import com.oracle.svm.core.posixsubst.headers.Stat; import com.oracle.svm.core.posixsubst.headers.Statvfs; +import com.oracle.svm.core.posixsubst.headers.Stdio; +import com.oracle.svm.core.posixsubst.headers.Unistd; import com.oracle.svm.core.posixsubst.headers.Dirent.DIR; import com.oracle.svm.core.posixsubst.headers.Dirent.dirent; import com.oracle.svm.core.posixsubst.headers.Dirent.direntPointer; +import com.oracle.svm.core.posixsubst.headers.Fcntl.flock; +import com.oracle.svm.core.posixsubst.headers.Grp.group; +import com.oracle.svm.core.posixsubst.headers.Grp.groupPointer; +import com.oracle.svm.core.posixsubst.headers.Pwd.passwd; +import com.oracle.svm.core.posixsubst.headers.Pwd.passwdPointer; +import com.oracle.svm.core.posixsubst.headers.Socket.sockaddr; +import com.oracle.svm.core.posixsubst.headers.Stdio.FILE; +import com.oracle.svm.core.posixsubst.headers.Uio.iovec; import com.oracle.svm.core.posixsubst.headers.linux.Mntent; import com.oracle.svm.core.posixsubst.headers.linux.Mntent.mntent; diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixJavaNetClose.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixJavaNetClose.java index 9f1f35f6fb21..0e2ba867e232 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixJavaNetClose.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixJavaNetClose.java @@ -37,11 +37,11 @@ import org.graalvm.word.PointerBase; import org.graalvm.word.WordFactory; -import com.oracle.svm.core.headers.Errno; import com.oracle.svm.core.posix.headers.Pthread; -import com.oracle.svm.core.posix.headers.Socket; -import com.oracle.svm.core.posix.headers.Uio; +import com.oracle.svm.core.posixsubst.headers.Errno; import com.oracle.svm.core.posixsubst.headers.Poll; +import com.oracle.svm.core.posixsubst.headers.Socket; +import com.oracle.svm.core.posixsubst.headers.Uio; /** * Interrupt blocking operations when a file descriptor is closed. diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixJavaNetSubstitutions.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixJavaNetSubstitutions.java index 4885e043a68b..d5bc0feba493 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixJavaNetSubstitutions.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixJavaNetSubstitutions.java @@ -75,23 +75,23 @@ import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; import com.oracle.svm.core.annotate.TargetElement; -import com.oracle.svm.core.headers.Errno; import com.oracle.svm.core.jdk.JDK11OrEarlier; import com.oracle.svm.core.jdk.JDK11OrLater; import com.oracle.svm.core.jdk.JDK8OrEarlier; import com.oracle.svm.core.os.IsDefined; import com.oracle.svm.core.posix.PosixUtils; -import com.oracle.svm.core.posix.headers.Fcntl; import com.oracle.svm.core.posix.headers.LibC; -import com.oracle.svm.core.posix.headers.Socket; -import com.oracle.svm.core.posix.headers.Unistd; import com.oracle.svm.core.posixsubst.JavaNetNetworkInterface.PlatformSupport; +import com.oracle.svm.core.posixsubst.headers.Errno; +import com.oracle.svm.core.posixsubst.headers.Fcntl; import com.oracle.svm.core.posixsubst.headers.Ifaddrs; import com.oracle.svm.core.posixsubst.headers.Ioctl; import com.oracle.svm.core.posixsubst.headers.NetIf; import com.oracle.svm.core.posixsubst.headers.Netdb; import com.oracle.svm.core.posixsubst.headers.NetinetIn; import com.oracle.svm.core.posixsubst.headers.Poll; +import com.oracle.svm.core.posixsubst.headers.Socket; +import com.oracle.svm.core.posixsubst.headers.Unistd; import com.oracle.svm.core.posixsubst.headers.linux.LinuxIn; import com.oracle.svm.core.util.Utf8; import com.oracle.svm.core.util.VMError; diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixSubstUtils.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixSubstUtils.java new file mode 100644 index 000000000000..68dc8f7f3563 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixSubstUtils.java @@ -0,0 +1,308 @@ +/* + * Copyright (c) 2014, 2019, 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. + */ +package com.oracle.svm.core.posixsubst; + +import static com.oracle.svm.core.posixsubst.headers.Fcntl.O_WRONLY; +import static com.oracle.svm.core.posixsubst.headers.Fcntl.open; +import static com.oracle.svm.core.posixsubst.headers.Unistd.close; +import static com.oracle.svm.core.posixsubst.headers.Unistd.dup2; +import static com.oracle.svm.core.posixsubst.headers.Unistd.read; +import static com.oracle.svm.core.posixsubst.headers.Unistd.write; + +import java.io.FileDescriptor; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.SyncFailedException; +import java.util.ArrayList; +import java.util.List; + +import org.graalvm.nativeimage.PinnedObject; +import org.graalvm.nativeimage.StackValue; +import org.graalvm.nativeimage.c.type.CCharPointer; +import org.graalvm.nativeimage.c.type.CTypeConversion; +import org.graalvm.nativeimage.c.type.CTypeConversion.CCharPointerHolder; +import org.graalvm.word.SignedWord; +import org.graalvm.word.UnsignedWord; +import org.graalvm.word.WordFactory; + +import com.oracle.svm.core.SubstrateUtil; +import com.oracle.svm.core.annotate.Alias; +import com.oracle.svm.core.annotate.Substitute; +import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.annotate.TargetElement; +import com.oracle.svm.core.jdk.JDK11OrLater; +import com.oracle.svm.core.posix.PosixUtils; +import com.oracle.svm.core.posix.headers.LibC; +import com.oracle.svm.core.posixsubst.headers.Fcntl; +import com.oracle.svm.core.posixsubst.headers.Unistd; + +public class PosixSubstUtils extends PosixUtils { + + public static String removeTrailingSlashes(String path) { + int p = path.length() - 1; + while (p > 0 && path.charAt(p) == '/') { + --p; + } + return p > 0 ? path.substring(0, p + 1) : path; + } + + @TargetClass(java.io.FileDescriptor.class) + private static final class Target_java_io_FileDescriptor { + + @Alias int fd; + + /* jdk/src/solaris/native/java/io/FileDescriptor_md.c */ + // 53 JNIEXPORT void JNICALL + // 54 Java_java_io_FileDescriptor_sync(JNIEnv *env, jobject this) { + @Substitute + public /* native */ void sync() throws SyncFailedException { + // 55 FD fd = THIS_FD(this); + // 56 if (IO_Sync(fd) == -1) { + if (Unistd.fsync(fd) == -1) { + // 57 JNU_ThrowByName(env, "java/io/SyncFailedException", "sync failed"); + throw new SyncFailedException("sync failed"); + } + } + + @Substitute // + @TargetElement(onlyWith = JDK11OrLater.class) // + @SuppressWarnings({"unused"}) + /* { Do not re-format commented out C code. @formatter:off */ + /* open-jdk11/src/java.base/unix/native/libjava/FileDescriptor_md.c */ + // 72 JNIEXPORT jboolean JNICALL + // 73 Java_java_io_FileDescriptor_getAppend(JNIEnv *env, jclass fdClass, jint fd) { + private static /* native */ boolean getAppend(int fd) { + // 74 int flags = fcntl(fd, F_GETFL); + int flags = Fcntl.fcntl(fd, Fcntl.F_GETFL()); + // 75 return ((flags & O_APPEND) == 0) ? JNI_FALSE : JNI_TRUE; + return ((flags & Fcntl.O_APPEND()) == 0) ? false : true; + } + /* } Do not re-format commented out C code. @formatter:on */ + + @Substitute // + @TargetElement(onlyWith = JDK11OrLater.class) // + @SuppressWarnings({"unused", "static-method"}) + /* { Do not re-format commented out C code. @formatter:off */ + /* open-jdk11/src/java.base/unix/native/libjava/FileDescriptor_md.c */ + // 78 // instance method close0 for FileDescriptor + // 79 JNIEXPORT void JNICALL + // 80 Java_java_io_FileDescriptor_close0(JNIEnv *env, jobject this) { + private /* native */ void close0() throws IOException { + // 81 fileDescriptorClose(env, this); + fileClose(SubstrateUtil.cast(this, FileDescriptor.class)); + } + /* } Do not re-format commented out C code. @formatter:on */ + } + + public static void fileOpen(String path, FileDescriptor fd, int flags) throws FileNotFoundException { + try (CCharPointerHolder pathPin = CTypeConversion.toCString(removeTrailingSlashes(path))) { + CCharPointer pathPtr = pathPin.get(); + int handle = open(pathPtr, flags, 0666); + if (handle >= 0) { + setFD(fd, handle); + } else { + throw new FileNotFoundException(path); + } + } + } + + public static void fileClose(FileDescriptor fd) throws IOException { + int handle = getFD(fd); + if (handle == -1) { + return; + } + setFD(fd, -1); + + // Do not close file descriptors 0, 1, 2. Instead, redirect to /dev/null. + if (handle >= 0 && handle <= 2) { + int devnull; + + try (CCharPointerHolder pathPin = CTypeConversion.toCString("/dev/null")) { + CCharPointer pathPtr = pathPin.get(); + devnull = open(pathPtr, O_WRONLY(), 0); + } + if (devnull < 0) { + setFD(fd, handle); + throw newIOExceptionWithLastError("open /dev/null failed"); + } else { + dup2(devnull, handle); + close(devnull); + } + } else if (close(handle) == -1) { + throw newIOExceptionWithLastError("close failed"); + } + } + + public static int readSingle(FileDescriptor fd) throws IOException { + CCharPointer retPtr = StackValue.get(CCharPointer.class); + int handle = getFDHandle(fd); + SignedWord nread = read(handle, retPtr, WordFactory.unsigned(1)); + if (nread.equal(0)) { + // EOF + return -1; + } else if (nread.equal(-1)) { + throw newIOExceptionWithLastError("Read error"); + } + return retPtr.read() & 0xFF; + } + + public static int readBytes(byte[] b, int off, int len, FileDescriptor fd) throws IOException { + if (b == null) { + throw new NullPointerException(); + } else if (outOfBounds(off, len, b)) { + throw new IndexOutOfBoundsException(); + } + if (len == 0) { + return 0; + } + + SignedWord nread; + CCharPointer buf = LibC.malloc(WordFactory.unsigned(len)); + try { + if (buf.equal(WordFactory.zero())) { + throw new OutOfMemoryError(); + } + + int handle = getFDHandle(fd); + nread = read(handle, buf, WordFactory.unsigned(len)); + if (nread.greaterThan(0)) { + /* + * We do not read directly into the (pinned) result array because read can block, + * and that could lead to object pinned for an unexpectedly long time. + */ + try (PinnedObject pin = PinnedObject.create(b)) { + LibC.memcpy(pin.addressOfArrayElement(off), buf, (UnsignedWord) nread); + } + } else if (nread.equal(-1)) { + throw newIOExceptionWithLastError("Read error"); + } else { + // EOF + nread = WordFactory.signed(-1); + } + } finally { + LibC.free(buf); + } + + return (int) nread.rawValue(); + } + + @SuppressWarnings("unused") + public static void writeSingle(FileDescriptor fd, int b, boolean append) throws IOException { + SignedWord n; + int handle = getFD(fd); + if (handle == -1) { + throw new IOException("Stream Closed"); + } + + CCharPointer bufPtr = StackValue.get(CCharPointer.class); + bufPtr.write((byte) b); + // the append parameter is disregarded + n = write(handle, bufPtr, WordFactory.unsigned(1)); + + if (n.equal(-1)) { + throw newIOExceptionWithLastError("Write error"); + } + } + + @SuppressWarnings("unused") + public static void writeBytes(FileDescriptor descriptor, byte[] bytes, int off, int len, boolean append) throws IOException { + if (bytes == null) { + throw new NullPointerException(); + } else if (outOfBounds(off, len, bytes)) { + throw new IndexOutOfBoundsException(); + } + if (len == 0) { + return; + } + + try (PinnedObject bytesPin = PinnedObject.create(bytes)) { + CCharPointer curBuf = bytesPin.addressOfArrayElement(off); + UnsignedWord curLen = WordFactory.unsigned(len); + while (curLen.notEqual(0)) { + int fd = getFD(descriptor); + if (fd == -1) { + throw new IOException("Stream Closed"); + } + + SignedWord n = write(fd, curBuf, curLen); + + if (n.equal(-1)) { + throw newIOExceptionWithLastError("Write error"); + } + curBuf = curBuf.addressOf(n); + curLen = curLen.subtract((UnsignedWord) n); + } + } + } + + public static int getFDHandle(FileDescriptor fd) throws IOException { + int handle = getFD(fd); + if (handle == -1) { + throw new IOException("Stream Closed"); + } + return handle; + } + + static boolean outOfBounds(int off, int len, byte[] array) { + return off < 0 || len < 0 || array.length - off < len; + } + + /** + * From a given path, remove all {@code .} and {@code dir/..}. + */ + public static String collapse(String path) { + boolean absolute = path.charAt(0) == '/'; + String wpath = absolute ? path.substring(1) : path; + + // split the path and remove unnecessary elements + List parts = new ArrayList<>(); + int pos = 0; + int next; + do { + next = wpath.indexOf('/', pos); + String part = next != -1 ? wpath.substring(pos, next) : wpath.substring(pos); + if (part.length() > 0) { + if (part.equals(".")) { + // ignore + } else if (part.equals("..")) { + // omit this .. and the preceding part + parts.remove(parts.size() - 1); + } else { + parts.add(part); + } + } + pos = next + 1; + } while (next != -1); + + // reassemble the path + StringBuilder rpath = new StringBuilder(absolute ? "/" : ""); + for (String part : parts) { + rpath.append(part).append('/'); + } + rpath.deleteCharAt(rpath.length() - 1); + + return rpath.toString(); + } +} diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixSunNioSubstitutions.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixSunNioSubstitutions.java index 906357eaf9ff..3455482e50f8 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixSunNioSubstitutions.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/PosixSunNioSubstitutions.java @@ -26,20 +26,20 @@ import java.io.IOException; +import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.StackValue; import org.graalvm.nativeimage.c.type.CIntPointer; import org.graalvm.nativeimage.impl.DeprecatedPlatform; -import org.graalvm.nativeimage.Platforms; import org.graalvm.word.WordFactory; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; import com.oracle.svm.core.jdk.JDK8OrEarlier; -import com.oracle.svm.core.headers.Errno; import com.oracle.svm.core.posix.PosixUtils; import com.oracle.svm.core.posix.headers.Time; -import com.oracle.svm.core.posix.headers.Unistd; +import com.oracle.svm.core.posixsubst.headers.Errno; import com.oracle.svm.core.posixsubst.headers.Poll; +import com.oracle.svm.core.posixsubst.headers.Unistd; /* Do not reformat commented-out code: @formatter:off */ diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/VmPrimsJVM.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/VmPrimsJVM.java index 85c5bd98085e..636fd6fba3bf 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/VmPrimsJVM.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/VmPrimsJVM.java @@ -30,7 +30,7 @@ import org.graalvm.nativeimage.c.type.CIntPointer; import org.graalvm.nativeimage.impl.DeprecatedPlatform; -import com.oracle.svm.core.posix.headers.Socket; +import com.oracle.svm.core.posixsubst.headers.Socket; /** Native methods (and macros) from src/share/vm/prims/jvm.cpp translated to Java. */ @Platforms({DeprecatedPlatform.LINUX_SUBSTITUTION.class, DeprecatedPlatform.DARWIN_SUBSTITUTION.class}) diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/darwin/DarwinJavaNetCloseImpl.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/darwin/DarwinJavaNetCloseImpl.java index e6567e8ca66b..398411ae3c22 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/darwin/DarwinJavaNetCloseImpl.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/darwin/DarwinJavaNetCloseImpl.java @@ -24,24 +24,24 @@ */ package com.oracle.svm.core.posixsubst.darwin; -import org.graalvm.nativeimage.hosted.Feature; -import org.graalvm.nativeimage.impl.DeprecatedPlatform; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.StackValue; import org.graalvm.nativeimage.c.struct.SizeOf; import org.graalvm.nativeimage.c.type.CIntPointer; +import org.graalvm.nativeimage.hosted.Feature; +import org.graalvm.nativeimage.impl.DeprecatedPlatform; import org.graalvm.word.WordFactory; import com.oracle.svm.core.annotate.AutomaticFeature; -import com.oracle.svm.core.headers.Errno; import com.oracle.svm.core.posix.headers.LibC; -import com.oracle.svm.core.posix.headers.Socket; import com.oracle.svm.core.posix.headers.Time; -import com.oracle.svm.core.posix.headers.Unistd; import com.oracle.svm.core.posixsubst.PosixJavaNetClose; +import com.oracle.svm.core.posixsubst.headers.Errno; +import com.oracle.svm.core.posixsubst.headers.Socket; import com.oracle.svm.core.posixsubst.headers.SysParam; import com.oracle.svm.core.posixsubst.headers.SysSelect; +import com.oracle.svm.core.posixsubst.headers.Unistd; /** * Translation of the mechanisms in /jdk8u-dev/jdk/src/solaris/native/java/net/bsd_close.c that diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/darwin/DarwinJavaNetNetworkInterface.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/darwin/DarwinJavaNetNetworkInterface.java index 55c4e51491a8..a55cea431ba1 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/darwin/DarwinJavaNetNetworkInterface.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/darwin/DarwinJavaNetNetworkInterface.java @@ -26,8 +26,6 @@ import java.net.SocketException; -import org.graalvm.nativeimage.hosted.Feature; -import org.graalvm.nativeimage.impl.DeprecatedPlatform; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.StackValue; @@ -35,22 +33,24 @@ import org.graalvm.nativeimage.c.type.CCharPointer; import org.graalvm.nativeimage.c.type.CIntPointer; import org.graalvm.nativeimage.c.type.CTypeConversion; +import org.graalvm.nativeimage.hosted.Feature; +import org.graalvm.nativeimage.impl.DeprecatedPlatform; import org.graalvm.word.PointerBase; import org.graalvm.word.WordFactory; import com.oracle.svm.core.annotate.AutomaticFeature; import com.oracle.svm.core.posix.PosixUtils; -import com.oracle.svm.core.headers.Errno; import com.oracle.svm.core.posix.headers.LibC; -import com.oracle.svm.core.posix.headers.Socket; import com.oracle.svm.core.posixsubst.JavaNetNetworkInterface; import com.oracle.svm.core.posixsubst.JavaNetNetworkInterface.netif; +import com.oracle.svm.core.posixsubst.headers.Errno; import com.oracle.svm.core.posixsubst.headers.Ifaddrs; import com.oracle.svm.core.posixsubst.headers.Ioctl; import com.oracle.svm.core.posixsubst.headers.NetEthernet; import com.oracle.svm.core.posixsubst.headers.NetIf; import com.oracle.svm.core.posixsubst.headers.NetIfDl; import com.oracle.svm.core.posixsubst.headers.NetinetIn; +import com.oracle.svm.core.posixsubst.headers.Socket; import com.oracle.svm.core.posixsubst.headers.darwin.DarwinNetinet6In6_var; /* { Do not format quoted code: @formatter:off */ diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/darwin/DarwinNIOSubstitutions.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/darwin/DarwinNIOSubstitutions.java index a51c28933a5a..f3ab56211742 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/darwin/DarwinNIOSubstitutions.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/darwin/DarwinNIOSubstitutions.java @@ -38,13 +38,13 @@ import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; import com.oracle.svm.core.annotate.TargetElement; -import com.oracle.svm.core.headers.Errno; import com.oracle.svm.core.jdk.JDK11OrLater; import com.oracle.svm.core.jdk.JDK8OrEarlier; import com.oracle.svm.core.posix.PosixUtils; -import com.oracle.svm.core.posix.headers.Socket; import com.oracle.svm.core.posix.headers.Time; -import com.oracle.svm.core.posix.headers.Unistd; +import com.oracle.svm.core.posixsubst.headers.Errno; +import com.oracle.svm.core.posixsubst.headers.Socket; +import com.oracle.svm.core.posixsubst.headers.Unistd; import com.oracle.svm.core.posixsubst.headers.darwin.DarwinEvent; @Platforms({DeprecatedPlatform.DARWIN_SUBSTITUTION.class}) diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/darwin/package-info.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/darwin/package-info.java index 091713b2e5c3..0a1744869fa6 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/darwin/package-info.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/darwin/package-info.java @@ -23,7 +23,7 @@ * questions. */ -@Platforms({DeprecatedPlatform.LINUX_SUBSTITUTION.class, DeprecatedPlatform.DARWIN_SUBSTITUTION.class}) +@Platforms({DeprecatedPlatform.DARWIN_SUBSTITUTION.class}) package com.oracle.svm.core.posixsubst.darwin; import org.graalvm.nativeimage.Platforms; diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/ArpaInet.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/ArpaInet.java index 32b5be1358de..582b8c7fa3ff 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/ArpaInet.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/ArpaInet.java @@ -29,14 +29,12 @@ import org.graalvm.nativeimage.c.type.CCharPointer; import org.graalvm.word.PointerBase; -import com.oracle.svm.core.posix.headers.PosixDirectives; - /* Checkstyle: stop */ /** * Contains the definitions from arpa/inet.h that we actually needed. */ -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public class ArpaInet { @CFunction diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Dirent.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Dirent.java index 0b85362f0cad..cc1ab547e532 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Dirent.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Dirent.java @@ -33,14 +33,12 @@ import org.graalvm.nativeimage.c.type.CCharPointer; import org.graalvm.word.PointerBase; -import com.oracle.svm.core.posix.headers.PosixDirectives; - //Checkstyle: stop /** * Definitions manually translated from the C header file dirent.h. */ -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public class Dirent { @CStruct(addStructKeyword = true) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/headers/Errno.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Errno.java similarity index 98% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/headers/Errno.java rename to substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Errno.java index 32fe408a3541..5a45ebf3fc31 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/headers/Errno.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Errno.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.headers; +package com.oracle.svm.core.posixsubst.headers; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; @@ -33,7 +33,7 @@ import org.graalvm.nativeimage.impl.DeprecatedPlatform; import org.graalvm.word.UnsignedWord; -import com.oracle.svm.core.ErrnoDirectives; +import com.oracle.svm.core.CErrorNumber; import com.oracle.svm.core.annotate.Uninterruptible; //Checkstyle: stop @@ -41,7 +41,7 @@ /** * Definitions manually translated from the C header file sys/errno.h. */ -@CContext(ErrnoDirectives.class) +@CContext(PosixSubstDirectives.class) public class Errno { /** Operation not permitted. */ @@ -425,10 +425,14 @@ public class Errno { * appropriate implementation. */ @Uninterruptible(reason = "Called from uninterruptible code.") - public static native int errno(); + public static int errno() { + return CErrorNumber.getCErrorNumber(); + } @Uninterruptible(reason = "Called from uninterruptible code.") - public static native void set_errno(int value); + public static void set_errno(int value) { + CErrorNumber.setCErrorNumber(value); + } /* * strerror() and strerror_r() are actually defined in string.h, but are probably always used diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Fcntl.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Fcntl.java new file mode 100644 index 000000000000..495f1578d35d --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Fcntl.java @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2013, 2017, 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. + */ +package com.oracle.svm.core.posixsubst.headers; + +import org.graalvm.nativeimage.Platforms; +import org.graalvm.nativeimage.c.CContext; +import org.graalvm.nativeimage.c.constant.CConstant; +import org.graalvm.nativeimage.c.function.CFunction; +import org.graalvm.nativeimage.c.function.CFunction.Transition; +import org.graalvm.nativeimage.c.struct.CField; +import org.graalvm.nativeimage.c.struct.CStruct; +import org.graalvm.nativeimage.c.type.CCharPointer; +import org.graalvm.nativeimage.impl.DeprecatedPlatform; +import org.graalvm.word.PointerBase; +import org.graalvm.word.SignedWord; + +// Checkstyle: stop + +/** + * Definitions manually translated from the C header file fcntl.h. + */ +@CContext(PosixSubstDirectives.class) +public class Fcntl { + + @CFunction + public static native int fcntl(int fd, int cmd); + + @CFunction + public static native int fcntl(int fd, int cmd, int arg); + + @CFunction(value = "fcntl", transition = CFunction.Transition.NO_TRANSITION) + public static native int fcntl_no_transition(int fd, int cmd, int arg); + + @CFunction + public static native int fcntl(int fd, int cmd, flock arg); + + @CFunction + public static native int open(CCharPointer pathname, int flags, int mode); + + public static native int openat(int fd, CCharPointer pathname, int flags, int mode); + + @CStruct(addStructKeyword = true) + public interface flock extends PointerBase { + @CField + short l_type(); + + @CField + void set_l_type(short value); + + @CField + short l_whence(); + + @CField + void set_l_whence(short value); + + @CField + SignedWord l_start(); + + @CField + void set_l_start(SignedWord value); + + @CField + SignedWord l_len(); + + @CField + void set_l_len(SignedWord value); + + @CField + int l_pid(); + + @CField + void set_l_pid(int value); + } + + @CConstant + public static native int O_RDONLY(); + + @CConstant + public static native int O_WRONLY(); + + @CConstant + public static native int O_RDWR(); + + @CConstant + public static native int O_CREAT(); + + @CConstant + public static native int O_TRUNC(); + + @CConstant + public static native int O_APPEND(); + + @CConstant + public static native int O_NONBLOCK(); + + @CConstant + public static native int O_SYNC(); + + @CConstant + public static native int F_SETLK(); + + @CConstant + public static native int F_SETLKW(); + + @CConstant + @Platforms(DeprecatedPlatform.LINUX_SUBSTITUTION.class) + public static native int O_DIRECT(); + + @CConstant + public static native int O_DSYNC(); + + @CConstant + public static native int F_SETFD(); + + @CConstant + public static native int F_GETFL(); + + @CConstant + public static native int F_SETFL(); + + @CConstant + public static native int FD_CLOEXEC(); + + @CConstant + public static native short F_RDLCK(); + + @CConstant + public static native short F_WRLCK(); + + @CConstant + public static native short F_UNLCK(); + + @CConstant + @Platforms({DeprecatedPlatform.DARWIN_SUBSTITUTION.class}) + public static native int F_NOCACHE(); + + @CFunction + public static native int fallocate(int fd, int mode, SignedWord offset, SignedWord len); + + public static class NoTransitions { + @CFunction(transition = Transition.NO_TRANSITION) + public static native int open(CCharPointer pathname, int flags, int mode); + } +} diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/File.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/File.java similarity index 94% rename from substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/File.java rename to substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/File.java index 935fa17c5b7f..5b4250dd5462 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/File.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/File.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.posix.headers; +package com.oracle.svm.core.posixsubst.headers; import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.function.CFunction; @@ -30,7 +30,7 @@ /** * Contains definitions from sys/file.h that we need. */ -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public class File { @CFunction diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Grp.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Grp.java similarity index 97% rename from substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Grp.java rename to substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Grp.java index 2ec07a811736..ffe3de347c37 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Grp.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Grp.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.posix.headers; +package com.oracle.svm.core.posixsubst.headers; import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.function.CFunction; @@ -39,7 +39,7 @@ /** * Definitions manually translated from the C header file grp.h. */ -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public class Grp { @CStruct(addStructKeyword = true) public interface group extends PointerBase { diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Ifaddrs.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Ifaddrs.java index 182724be9445..85b5326aa1b8 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Ifaddrs.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Ifaddrs.java @@ -34,16 +34,13 @@ import org.graalvm.nativeimage.impl.DeprecatedPlatform; import org.graalvm.word.PointerBase; -import com.oracle.svm.core.posix.headers.PosixDirectives; -import com.oracle.svm.core.posix.headers.Socket; - // Allow methods with non-standard names: Checkstyle: stop /* * The definitions I need, manually translated from the C header file. */ @Platforms({DeprecatedPlatform.DARWIN_SUBSTITUTION.class, DeprecatedPlatform.LINUX_SUBSTITUTION.class}) -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public class Ifaddrs { private Ifaddrs() { diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Ioctl.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Ioctl.java index 03371f80947d..2861f06d56d5 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Ioctl.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Ioctl.java @@ -29,14 +29,12 @@ import org.graalvm.nativeimage.c.function.CFunction; import org.graalvm.word.PointerBase; -import com.oracle.svm.core.posix.headers.PosixDirectives; - //Checkstyle: stop /** * Definitions manually translated from the C header file sys/ioctl.h. */ -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public class Ioctl { @CConstant diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Langinfo.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Langinfo.java similarity index 95% rename from substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Langinfo.java rename to substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Langinfo.java index 34d5f0bf291e..7a41a954edeb 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Langinfo.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Langinfo.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.posix.headers; +package com.oracle.svm.core.posixsubst.headers; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.CContext; @@ -33,7 +33,7 @@ /** Definitions hand-translated from . */ @Platforms({DARWIN_JNI_AND_SUBSTITUTIONS.class, LINUX_JNI_AND_SUBSTITUTIONS.class}) -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public class Langinfo { /* Allow non-standard names: Checkstyle: stop */ diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/NetEthernet.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/NetEthernet.java index a1e525c6deca..115c47ddc2af 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/NetEthernet.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/NetEthernet.java @@ -27,9 +27,7 @@ import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.constant.CConstant; -import com.oracle.svm.core.posix.headers.PosixDirectives; - -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public class NetEthernet { /* { Do not format quoted code: @formatter:off */ /* { Allow non-standard names: Checkstyle: stop */ diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/NetIf.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/NetIf.java index a06ba41ff329..760972f88b6c 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/NetIf.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/NetIf.java @@ -36,14 +36,11 @@ import org.graalvm.nativeimage.impl.DeprecatedPlatform; import org.graalvm.word.PointerBase; -import com.oracle.svm.core.posix.headers.PosixDirectives; -import com.oracle.svm.core.posix.headers.Socket; - // Allow methods with non-standard names: Checkstyle: stop /** The definitions I need, manually translated from the C header file. */ @Platforms({DeprecatedPlatform.DARWIN_SUBSTITUTION.class, DeprecatedPlatform.LINUX_SUBSTITUTION.class}) -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public class NetIf { @CConstant @@ -72,7 +69,7 @@ public class NetIf { public static native int IFF_BROADCAST(); /* { Do not reformat commented out C code: @formatter:off */ - @CContext(PosixDirectives.class) + @CContext(PosixSubstDirectives.class) @Platforms({DeprecatedPlatform.LINUX_SUBSTITUTION.class, DeprecatedPlatform.DARWIN_SUBSTITUTION.class}) @CStruct(addStructKeyword = true) public interface ifreq extends PointerBase { @@ -162,7 +159,7 @@ public interface ifreq extends PointerBase { /* } Do not reformat commented out C code: @formatter:on */ /* { Do not reformat commented out C code: @formatter:off */ - @CContext(PosixDirectives.class) + @CContext(PosixSubstDirectives.class) @Platforms({DeprecatedPlatform.LINUX_SUBSTITUTION.class, DeprecatedPlatform.DARWIN_SUBSTITUTION.class}) @CStruct(addStructKeyword = true) public interface ifconf extends PointerBase { diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/NetIfDl.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/NetIfDl.java index 7e3d2a4b834b..d4b393bf0baf 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/NetIfDl.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/NetIfDl.java @@ -34,10 +34,8 @@ import org.graalvm.nativeimage.impl.DeprecatedPlatform; import org.graalvm.word.PointerBase; -import com.oracle.svm.core.posix.headers.PosixDirectives; - @Platforms({DeprecatedPlatform.DARWIN_SUBSTITUTION.class}) -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public class NetIfDl { /* { Do not format quoted code: @formatter:off */ /* { Allow non-standard names: Checkstyle: stop */ diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Netdb.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Netdb.java index 905a05dfe9d8..731195f4ba9d 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Netdb.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Netdb.java @@ -35,9 +35,6 @@ import org.graalvm.nativeimage.impl.DeprecatedPlatform; import org.graalvm.word.PointerBase; -import com.oracle.svm.core.posix.headers.PosixDirectives; -import com.oracle.svm.core.posix.headers.Socket; - // Allow methods with non-standard names: Checkstyle: stop /* @@ -45,7 +42,7 @@ */ @Platforms({DeprecatedPlatform.DARWIN_SUBSTITUTION.class, DeprecatedPlatform.LINUX_SUBSTITUTION.class}) -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public final class Netdb { private Netdb() { diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/NetinetIn.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/NetinetIn.java index 5e063fa33aa8..c43e5bf00c53 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/NetinetIn.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/NetinetIn.java @@ -36,13 +36,11 @@ import org.graalvm.nativeimage.impl.DeprecatedPlatform; import org.graalvm.word.PointerBase; -import com.oracle.svm.core.posix.headers.PosixDirectives; - // Allow methods with non-standard names: Checkstyle: stop /** The definitions I need, manually translated from the C header file. */ @Platforms({DeprecatedPlatform.DARWIN_SUBSTITUTION.class, DeprecatedPlatform.LINUX_SUBSTITUTION.class}) -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public class NetinetIn { private NetinetIn() { diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/NetinetTcp.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/NetinetTcp.java index 9a07ef9619a5..237d1d2495eb 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/NetinetTcp.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/NetinetTcp.java @@ -29,13 +29,11 @@ import org.graalvm.nativeimage.c.constant.CConstant; import org.graalvm.nativeimage.impl.DeprecatedPlatform; -import com.oracle.svm.core.posix.headers.PosixDirectives; - //Allow methods with non-standard names: Checkstyle: stop /** The definitions I need, manually translated from the C header file. */ @Platforms({DeprecatedPlatform.DARWIN_SUBSTITUTION.class, DeprecatedPlatform.LINUX_SUBSTITUTION.class}) -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public class NetinetTcp { @CConstant diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Poll.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Poll.java index ef5948a6b260..2c0eee8436fd 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Poll.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Poll.java @@ -35,8 +35,6 @@ import org.graalvm.nativeimage.impl.DeprecatedPlatform; import org.graalvm.word.PointerBase; -import com.oracle.svm.core.posix.headers.PosixDirectives; - //Allow methods with non-standard names: Checkstyle: stop /* @@ -44,7 +42,7 @@ */ @Platforms({DeprecatedPlatform.DARWIN_SUBSTITUTION.class, DeprecatedPlatform.LINUX_SUBSTITUTION.class}) -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public class Poll { /* @formatter:off */ diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/PosixSubstDirectives.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/PosixSubstDirectives.java new file mode 100644 index 000000000000..a10d4f3b129a --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/PosixSubstDirectives.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2016, 2019, 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. + */ +package com.oracle.svm.core.posixsubst.headers; + +import java.util.Arrays; +import java.util.List; + +import org.graalvm.nativeimage.Platform; +import org.graalvm.nativeimage.impl.InternalPlatform; + +import com.oracle.svm.core.posix.headers.PosixDirectives; +import com.oracle.svm.core.util.VMError; + +public class PosixSubstDirectives extends PosixDirectives { + private static final String[] commonLibs = new String[]{ + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + }; + + private static final String[] darwinLibs = new String[]{ + "", + "", + "", + "", + }; + + private static final String[] linuxLibs = new String[]{ + "", + "", + "", + "", + }; + + @Override + public List getHeaderFiles() { + List result = super.getHeaderFiles(); + + result.addAll(Arrays.asList(commonLibs)); + if (Platform.includedIn(InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class)) { + result.addAll(Arrays.asList(linuxLibs)); + } else if (Platform.includedIn(InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class)) { + result.addAll(Arrays.asList(darwinLibs)); + } else { + throw VMError.shouldNotReachHere("Unsupported OS"); + } + return result; + } +} diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Pwd.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Pwd.java new file mode 100644 index 000000000000..538123f82f1d --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Pwd.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2013, 2017, 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. + */ +package com.oracle.svm.core.posixsubst.headers; + +import org.graalvm.nativeimage.c.CContext; +import org.graalvm.nativeimage.c.function.CFunction; +import org.graalvm.nativeimage.c.struct.CField; +import org.graalvm.nativeimage.c.struct.CPointerTo; +import org.graalvm.nativeimage.c.struct.CStruct; +import org.graalvm.nativeimage.c.type.CCharPointer; +import org.graalvm.word.PointerBase; +import org.graalvm.word.UnsignedWord; + +// Checkstyle: stop + +/*** Definitions manually translated from the C header file pwd.h. */ + +@CContext(PosixSubstDirectives.class) +public class Pwd { + + @CStruct(addStructKeyword = true) + public interface passwd extends PointerBase { + @CField + CCharPointer pw_name(); + + @CField + CCharPointer pw_passwd(); + + @CField + int pw_uid(); + + @CField + int pw_gid(); + + @CField + CCharPointer pw_gecos(); + + @CField + CCharPointer pw_dir(); + + @CField + CCharPointer pw_shell(); + } + + @CPointerTo(passwd.class) + public interface passwdPointer extends PointerBase { + passwd read(); + + void write(PointerBase value); + } + + @CFunction + public static native void setpwent(); + + @CFunction + public static native passwd getpwent(); + + @CFunction + public static native passwd getpwuid(int __uid); + + @CFunction + public static native passwd getpwnam(CCharPointer __name); + + @CFunction + public static native int getpwuid_r(int __uid, passwd __resultbuf, CCharPointer __buffer, UnsignedWord __buflen, passwdPointer __result); + + @CFunction + public static native int getpwnam_r(CCharPointer __name, passwd __resultbuf, CCharPointer __buffer, UnsignedWord __buflen, passwdPointer __result); +} diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Socket.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Socket.java similarity index 98% rename from substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Socket.java rename to substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Socket.java index d37a0c580a18..d85116c30966 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Socket.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Socket.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.posix.headers; +package com.oracle.svm.core.posixsubst.headers; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.CContext; @@ -41,14 +41,14 @@ import org.graalvm.word.SignedWord; import org.graalvm.word.UnsignedWord; -import com.oracle.svm.core.posix.headers.Uio.iovec; +import com.oracle.svm.core.posixsubst.headers.Uio.iovec; // Checkstyle: stop /** * Definitions manually translated from the C header file sys/socket.h. */ -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public class Socket { @CConstant diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Spawn.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Spawn.java similarity index 97% rename from substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Spawn.java rename to substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Spawn.java index 51ca54f73746..67cafea904c0 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Spawn.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Spawn.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.posix.headers; +package com.oracle.svm.core.posixsubst.headers; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.CContext; @@ -36,9 +36,11 @@ import org.graalvm.nativeimage.impl.InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS; import org.graalvm.word.PointerBase; +import com.oracle.svm.core.posix.headers.Signal; + /** Definitions hand-translated from . */ @Platforms({DARWIN_JNI_AND_SUBSTITUTIONS.class, LINUX_JNI_AND_SUBSTITUTIONS.class}) -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public class Spawn { /* Allow lower-case type names: Checkstyle: stop. */ diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Stat.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Stat.java similarity index 98% rename from substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Stat.java rename to substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Stat.java index 3249b667cb6c..a52b1e075e67 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Stat.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Stat.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.posix.headers; +package com.oracle.svm.core.posixsubst.headers; import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.constant.CConstant; @@ -38,7 +38,7 @@ /** * Definitions manually translated from the C header file sys/stat.h. */ -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public class Stat { @CConstant diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Statvfs.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Statvfs.java index 5c2ff4e19187..a6f711925ca0 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Statvfs.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Statvfs.java @@ -32,14 +32,12 @@ import org.graalvm.nativeimage.c.type.CCharPointer; import org.graalvm.word.PointerBase; -import com.oracle.svm.core.posix.headers.PosixDirectives; - // Checkstyle: stop /** * Definitions manually translated from the C header file sys/statvfs.h. */ -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public class Statvfs { @CStruct(addStructKeyword = true) diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Stdio.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Stdio.java similarity index 96% rename from substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Stdio.java rename to substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Stdio.java index 24e066b1882b..24a10593f27e 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Stdio.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Stdio.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.posix.headers; +package com.oracle.svm.core.posixsubst.headers; import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.constant.CConstant; @@ -35,7 +35,7 @@ /** * Contains the definitions from stdio.h that we actually needed. */ -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public class Stdio { public interface FILE extends PointerBase { diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/SysParam.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/SysParam.java index a9038e702655..18fdea42e017 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/SysParam.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/SysParam.java @@ -30,10 +30,8 @@ import org.graalvm.nativeimage.c.function.CFunction.Transition; import org.graalvm.nativeimage.impl.DeprecatedPlatform; -import com.oracle.svm.core.posix.headers.PosixDirectives; - @Platforms({DeprecatedPlatform.DARWIN_SUBSTITUTION.class, DeprecatedPlatform.LINUX_SUBSTITUTION.class}) -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public class SysParam { /* diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/SysSelect.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/SysSelect.java index 0b0a89ebe2e6..86d20ba798fc 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/SysSelect.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/SysSelect.java @@ -33,11 +33,10 @@ import org.graalvm.nativeimage.impl.DeprecatedPlatform; import org.graalvm.word.PointerBase; -import com.oracle.svm.core.posix.headers.PosixDirectives; import com.oracle.svm.core.posix.headers.Time; @Platforms({DeprecatedPlatform.DARWIN_SUBSTITUTION.class, DeprecatedPlatform.LINUX_SUBSTITUTION.class}) -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public class SysSelect { /* ( Allow names with underscores: Checkstyle: stop */ diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Syscall.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Syscall.java similarity index 95% rename from substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Syscall.java rename to substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Syscall.java index e2eefe28ccc3..a0ea09d2a895 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Syscall.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Syscall.java @@ -22,13 +22,13 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.posix.headers; +package com.oracle.svm.core.posixsubst.headers; import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.function.CFunction; /** Declarations of method from . */ -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public class Syscall { @CFunction diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Termios.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Termios.java index 749d7e9634b8..c9aa63c14503 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Termios.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Termios.java @@ -33,10 +33,8 @@ import org.graalvm.nativeimage.c.struct.CStruct; import org.graalvm.word.PointerBase; -import com.oracle.svm.core.posix.headers.PosixDirectives; - /** Definitions manually translated from the C header file termios.h. */ -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public class Termios { // { Allow names with all upper-case and underscores: Checkstyle: stop diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Time.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Time.java new file mode 100644 index 000000000000..fb4ceba84091 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Time.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2013, 2017, 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. + */ +package com.oracle.svm.core.posixsubst.headers; + +import org.graalvm.nativeimage.c.CContext; +import org.graalvm.nativeimage.c.function.CFunction; +import org.graalvm.nativeimage.c.type.CCharPointer; +import org.graalvm.word.PointerBase; + +// Checkstyle: stop + +/** + * Definitions manually translated from the C header file sys/time.h. + */ +@CContext(PosixSubstDirectives.class) +public class Time extends com.oracle.svm.core.posix.headers.Time { + + @CFunction + public static native int utimes(CCharPointer file, timeval tvp); + + @CFunction + public static native int lutimes(CCharPointer file, timeval tvp); + + @CFunction + public static native int futimes(int fd, timeval tvp); + + @CFunction + public static native int futimesat(int fd, CCharPointer file, timeval tvp); + + @CFunction + public static native long time(PointerBase timer); + + @CFunction + public static native int nanosleep(timespec requested_time, timespec remaining); +} diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Uio.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Uio.java similarity index 96% rename from substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Uio.java rename to substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Uio.java index 7272ab542b7a..0f982880f0c3 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/Uio.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Uio.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.posix.headers; +package com.oracle.svm.core.posixsubst.headers; import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.function.CFunction; @@ -37,7 +37,7 @@ /** * Definitions manually translated from the C header file sys/uio.h. */ -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public class Uio { /** Structure for scatter/gather I/O. */ diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Unistd.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Unistd.java new file mode 100644 index 000000000000..b41bc5b1a39f --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/Unistd.java @@ -0,0 +1,273 @@ +/* + * Copyright (c) 2013, 2019, 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. + */ +package com.oracle.svm.core.posixsubst.headers; + +import org.graalvm.nativeimage.Platforms; +import org.graalvm.nativeimage.c.CContext; +import org.graalvm.nativeimage.c.constant.CConstant; +import org.graalvm.nativeimage.c.function.CFunction; +import org.graalvm.nativeimage.c.type.CCharPointer; +import org.graalvm.nativeimage.c.type.CCharPointerPointer; +import org.graalvm.nativeimage.c.type.CIntPointer; +import org.graalvm.nativeimage.impl.InternalPlatform; +import org.graalvm.word.PointerBase; +import org.graalvm.word.SignedWord; +import org.graalvm.word.UnsignedWord; + +// Checkstyle: stop + +/** + * Definitions manually translated from the C header file unistd.h. + */ +@CContext(PosixSubstDirectives.class) +public class Unistd { + + @CConstant + public static native int R_OK(); + + @CConstant + public static native int W_OK(); + + @CConstant + public static native int X_OK(); + + @CConstant + public static native int F_OK(); + + @CConstant + public static native int STDIN_FILENO(); + + @CFunction + public static native int access(CCharPointer name, int type); + + @CConstant + public static native short SEEK_SET(); + + @CConstant + public static native short SEEK_CUR(); + + @CConstant + public static native short SEEK_END(); + + @CFunction + public static native SignedWord lseek(int fd, SignedWord offset, int whence); + + @CFunction + public static native int close(int fd); + + @CFunction + public static native SignedWord read(int fd, PointerBase buf, UnsignedWord nbytes); + + @CFunction + public static native SignedWord write(int fd, PointerBase buf, UnsignedWord n); + + @CFunction + public static native SignedWord pread(int fd, PointerBase buf, UnsignedWord nbytes, long offset); + + @CFunction + public static native SignedWord pwrite(int fd, PointerBase buf, UnsignedWord n, long offset); + + @CFunction + public static native int pipe(CIntPointer pipedes); + + @CFunction + public static native /* unsigned */ int sleep(/* unsigned */ int seconds); + + @CFunction + public static native int chown(CCharPointer file, /* unsigned */ int owner, /* unsigned */ int group); + + @CFunction + public static native int fchown(int fd, /* unsigned */ int owner, /* unsigned */ int group); + + @CFunction + public static native int lchown(CCharPointer file, /* unsigned */ int owner, /* unsigned */ int group); + + @CFunction + public static native int chdir(CCharPointer path); + + @CFunction + public static native CCharPointer getcwd(CCharPointer buf, UnsignedWord size); + + @CFunction + public static native int dup(int fd); + + @CFunction + public static native int dup2(int fd, int fd2); + + @CFunction + public static native int execve(CCharPointer path, CCharPointerPointer argv, CCharPointerPointer envp); + + @CFunction + public static native int execv(CCharPointer path, CCharPointerPointer argv); + + @CConstant + public static native int _PC_NAME_MAX(); + + @CConstant + public static native int _SC_CLK_TCK(); + + @CConstant + public static native int _SC_OPEN_MAX(); + + @CConstant + public static native int _SC_PAGESIZE(); + + @CConstant + public static native int _SC_PAGE_SIZE(); + + @CConstant + public static native int _SC_IOV_MAX(); + + @CConstant + public static native int _SC_GETGR_R_SIZE_MAX(); + + @CConstant + public static native int _SC_GETPW_R_SIZE_MAX(); + + @CConstant + public static native int _SC_NPROCESSORS_ONLN(); + + @CConstant + @Platforms(InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class) + public static native int _SC_PHYS_PAGES(); + + @CConstant + @Platforms(InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class) + public static native int _CS_DARWIN_USER_TEMP_DIR(); + + @CFunction + public static native long pathconf(CCharPointer path, int name); + + @CFunction + public static native long sysconf(int name); + + @CFunction + public static native UnsignedWord confstr(int name, CCharPointer buf, UnsignedWord len); + + @CFunction + public static native int getpid(); + + @CFunction + public static native int getppid(); + + @CFunction + public static native int getpgrp(); + + @CFunction + public static native int getpgid(int pid); + + @CFunction + public static native int setpgid(int pid, int pgid); + + @CFunction + public static native int setsid(); + + @CFunction + public static native int getuid(); + + @CFunction + public static native int geteuid(); + + @CFunction + public static native int getgid(); + + @CFunction + public static native int getegid(); + + @CFunction + public static native int getgroups(int size, CIntPointer list); + + @CFunction + public static native int setuid(int uid); + + @CFunction + public static native int seteuid(int uid); + + @CFunction + public static native int setgid(int gid); + + @CFunction + public static native int setegid(int gid); + + @CFunction + public static native int fork(); + + @CFunction + public static native int isatty(int fd); + + @CFunction + public static native int link(CCharPointer from, CCharPointer to); + + @CFunction + public static native int symlink(CCharPointer from, CCharPointer to); + + @CFunction + public static native SignedWord readlink(CCharPointer path, CCharPointer buf, UnsignedWord len); + + @CFunction + public static native int unlink(CCharPointer name); + + @CFunction + public static native int unlinkat(int fd, CCharPointer name, int flag); + + @CFunction + public static native int rmdir(CCharPointer path); + + @CFunction + public static native CCharPointer getlogin(); + + @CFunction + public static native int gethostname(CCharPointer name, UnsignedWord len); + + @CFunction + public static native int daemon(int nochdir, int noclose); + + @CFunction + public static native int fsync(int fd); + + @CFunction + public static native int getpagesize(); + + @CFunction + public static native int getdtablesize(); + + @CFunction + public static native int truncate(CCharPointer file, SignedWord length); + + @CFunction + public static native int ftruncate(int fd, long length); + + @CFunction + public static native int fdatasync(int fildes); + + @CFunction + public static native CCharPointer crypt(CCharPointer key, CCharPointer salt); + + @CFunction + public static native SignedWord recvmsg(int socket, Socket.msghdr message, int flags); + + @CFunction + public static native SignedWord sendmsg(int socket, Socket.msghdr message, int flags); +} diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/UnistdNoTransitions.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/UnistdNoTransitions.java similarity index 95% rename from substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/UnistdNoTransitions.java rename to substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/UnistdNoTransitions.java index 5dee1312c867..6f93d658ace9 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/UnistdNoTransitions.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/UnistdNoTransitions.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.posix.headers; +package com.oracle.svm.core.posixsubst.headers; import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.function.CFunction; @@ -34,6 +34,7 @@ import org.graalvm.word.UnsignedWord; import com.oracle.svm.core.annotate.Uninterruptible; +import com.oracle.svm.core.posix.headers.Unistd; // Checkstyle: stop @@ -41,7 +42,7 @@ * Variants of {@link Unistd} functions that can be used from {@link Uninterruptible} methods * because they have {@link Transition#NO_TRANSITION} set. */ -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public class UnistdNoTransitions { @CFunction(transition = Transition.NO_TRANSITION) diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/ZLib.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/ZLib.java index 27f4ecdedcb3..df75d70c97d3 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/ZLib.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/ZLib.java @@ -42,8 +42,6 @@ import org.graalvm.word.PointerBase; import org.graalvm.word.UnsignedWord; -import com.oracle.svm.core.posix.headers.PosixDirectives; - //Checkstyle: stop /** @@ -52,7 +50,7 @@ * We only include this class in the JNI implementation in order to add -lz to the link line. */ @Platforms({DeprecatedPlatform.DARWIN_SUBSTITUTION.class, DeprecatedPlatform.LINUX_SUBSTITUTION.class}) -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) @CLibrary("z") public class ZLib { // extern uLong adler32 (uLong adler, const Bytef *buf, uInt len); diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/darwin/DarwinEvent.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/darwin/DarwinEvent.java index ae81173af781..b82d1a4bb97f 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/darwin/DarwinEvent.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/darwin/DarwinEvent.java @@ -36,12 +36,12 @@ import org.graalvm.nativeimage.impl.DeprecatedPlatform; import org.graalvm.word.PointerBase; -import com.oracle.svm.core.posix.headers.PosixDirectives; import com.oracle.svm.core.posix.headers.Time; +import com.oracle.svm.core.posixsubst.headers.PosixSubstDirectives; /* Allow underscores in names: Checkstyle: stop. */ -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) @Platforms({DeprecatedPlatform.DARWIN_SUBSTITUTION.class}) public class DarwinEvent { diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/darwin/DarwinInode64Suffix.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/darwin/DarwinInode64Suffix.java index 0be9a247ee93..0d705c0f47e8 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/darwin/DarwinInode64Suffix.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/darwin/DarwinInode64Suffix.java @@ -31,10 +31,10 @@ import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.posix.headers.Stat.stat; import com.oracle.svm.core.posixsubst.headers.Dirent.DIR; import com.oracle.svm.core.posixsubst.headers.Dirent.dirent; import com.oracle.svm.core.posixsubst.headers.Dirent.direntPointer; +import com.oracle.svm.core.posixsubst.headers.Stat.stat; //Checkstyle: stop @@ -53,7 +53,7 @@ static final class Target_com_oracle_svm_core_posix_headers_Dirent { private static native int readdir_r(DIR dirp, dirent entry, direntPointer result); } - @TargetClass(com.oracle.svm.core.posix.headers.Stat.class) + @TargetClass(com.oracle.svm.core.posixsubst.headers.Stat.class) static final class Target_com_oracle_svm_core_posix_headers_Stat { @Substitute @CFunction("stat$INODE64") diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/darwin/DarwinNetinet6In6_var.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/darwin/DarwinNetinet6In6_var.java index 469b387036b3..cf6cd14f4111 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/darwin/DarwinNetinet6In6_var.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/darwin/DarwinNetinet6In6_var.java @@ -33,14 +33,14 @@ import org.graalvm.nativeimage.impl.DeprecatedPlatform; import org.graalvm.word.PointerBase; -import com.oracle.svm.core.posix.headers.PosixDirectives; import com.oracle.svm.core.posixsubst.headers.NetinetIn; +import com.oracle.svm.core.posixsubst.headers.PosixSubstDirectives; /* { Do not format quoted code: @formatter:off */ /* { Allow non-standard names: Checkstyle: stop */ @Platforms(DeprecatedPlatform.DARWIN_SUBSTITUTION.class) -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public class DarwinNetinet6In6_var { @CStruct(addStructKeyword = true) diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/darwin/DarwinSendfile.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/darwin/DarwinSendfile.java index 78932b9a8508..be4236aed011 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/darwin/DarwinSendfile.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/darwin/DarwinSendfile.java @@ -33,12 +33,12 @@ import org.graalvm.nativeimage.impl.DeprecatedPlatform; import org.graalvm.word.PointerBase; -import com.oracle.svm.core.posix.headers.PosixDirectives; -import com.oracle.svm.core.posix.headers.Uio.iovec; +import com.oracle.svm.core.posixsubst.headers.PosixSubstDirectives; +import com.oracle.svm.core.posixsubst.headers.Uio.iovec; //Checkstyle: stop -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) @Platforms(DeprecatedPlatform.DARWIN_SUBSTITUTION.class) public class DarwinSendfile { diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/darwin/package-info.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/darwin/package-info.java index 53e655e170de..a0cce0ce912c 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/darwin/package-info.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/darwin/package-info.java @@ -23,7 +23,7 @@ * questions. */ -@Platforms({DeprecatedPlatform.LINUX_SUBSTITUTION.class, DeprecatedPlatform.DARWIN_SUBSTITUTION.class}) +@Platforms({DeprecatedPlatform.DARWIN_SUBSTITUTION.class}) package com.oracle.svm.core.posixsubst.headers.darwin; import org.graalvm.nativeimage.Platforms; diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/linux/Linux64Suffix.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/linux/Linux64Suffix.java index 7c2df4ad520f..3c0b28d42c93 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/linux/Linux64Suffix.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/linux/Linux64Suffix.java @@ -40,13 +40,13 @@ import com.oracle.svm.core.annotate.KeepOriginal; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.posix.headers.PosixDirectives; -import com.oracle.svm.core.posix.headers.Stat.stat; -import com.oracle.svm.core.posix.headers.Stdio.FILE; import com.oracle.svm.core.posixsubst.headers.Dirent.DIR; import com.oracle.svm.core.posixsubst.headers.Dirent.dirent; import com.oracle.svm.core.posixsubst.headers.Dirent.direntPointer; +import com.oracle.svm.core.posixsubst.headers.PosixSubstDirectives; +import com.oracle.svm.core.posixsubst.headers.Stat.stat; import com.oracle.svm.core.posixsubst.headers.Statvfs.statvfs; +import com.oracle.svm.core.posixsubst.headers.Stdio.FILE; //Checkstyle: stop @@ -56,7 +56,7 @@ class Linux64Suffix { @TargetClass(com.oracle.svm.core.posixsubst.headers.Dirent.dirent.class) @Substitute @CStruct(addStructKeyword = true) - @CContext(PosixDirectives.class) + @CContext(PosixSubstDirectives.class) interface dirent64 extends PointerBase { @KeepOriginal long d_ino(); @@ -76,10 +76,10 @@ static final class Target_com_oracle_svm_core_posix_headers_Dirent { private static native int readdir_r_no_transition(DIR dirp, dirent entry, direntPointer result); } - @TargetClass(com.oracle.svm.core.posix.headers.Fcntl.flock.class) + @TargetClass(com.oracle.svm.core.posixsubst.headers.Fcntl.flock.class) @Substitute @CStruct(addStructKeyword = true) - @CContext(PosixDirectives.class) + @CContext(PosixSubstDirectives.class) interface flock64 extends PointerBase { @KeepOriginal short l_type(); @@ -112,8 +112,8 @@ interface flock64 extends PointerBase { void set_l_pid(int value); } - @TargetClass(com.oracle.svm.core.posix.headers.Fcntl.class) - @CContext(PosixDirectives.class) + @TargetClass(com.oracle.svm.core.posixsubst.headers.Fcntl.class) + @CContext(PosixSubstDirectives.class) static final class Target_com_oracle_svm_core_posix_headers_Fcntl { @Substitute @CConstant("F_SETLK64") @@ -135,7 +135,7 @@ static final class Target_com_oracle_svm_core_posix_headers_Mman { @TargetClass(com.oracle.svm.core.posix.headers.Resource.rlimit.class) @Substitute @CStruct(addStructKeyword = true) - @CContext(PosixDirectives.class) + @CContext(PosixSubstDirectives.class) interface rlimit64 extends PointerBase { @KeepOriginal UnsignedWord rlim_cur(); @@ -161,10 +161,10 @@ static final class Target_com_oracle_svm_core_posix_headers_Resource { private static native int setrlimit(int resource, rlimit64 rlimits); } - @TargetClass(com.oracle.svm.core.posix.headers.Stat.stat.class) + @TargetClass(com.oracle.svm.core.posixsubst.headers.Stat.stat.class) @Substitute @CStruct(addStructKeyword = true) - @CContext(PosixDirectives.class) + @CContext(PosixSubstDirectives.class) interface stat64 extends PointerBase { @KeepOriginal long st_dev(); @@ -206,7 +206,7 @@ interface stat64 extends PointerBase { long st_ctime(); } - @TargetClass(com.oracle.svm.core.posix.headers.Stat.class) + @TargetClass(com.oracle.svm.core.posixsubst.headers.Stat.class) static final class Target_com_oracle_svm_core_posix_headers_Stat { @Substitute @CFunction("stat64") @@ -228,7 +228,7 @@ static final class Target_com_oracle_svm_core_posix_headers_Stat { @TargetClass(statvfs.class) @Substitute @CStruct(addStructKeyword = true) - @CContext(PosixDirectives.class) + @CContext(PosixSubstDirectives.class) interface statvfs64 extends PointerBase { @KeepOriginal long f_bsize(); @@ -275,14 +275,14 @@ static final class Target_com_oracle_svm_core_posix_headers_Statvfs { private static native int fstatvfs(int fildes, statvfs buf); } - @TargetClass(com.oracle.svm.core.posix.headers.Stdio.class) + @TargetClass(com.oracle.svm.core.posixsubst.headers.Stdio.class) static final class Target_com_oracle_svm_core_posix_headers_Stdio { @Substitute @CFunction("fopen64") private static native FILE fopen(CCharPointer filename, CCharPointer modes); } - @TargetClass(com.oracle.svm.core.posix.headers.Unistd.class) + @TargetClass(com.oracle.svm.core.posixsubst.headers.Unistd.class) static final class Target_com_oracle_svm_core_posix_headers_Unistd { @Substitute @CFunction("pread64") @@ -297,7 +297,7 @@ static final class Target_com_oracle_svm_core_posix_headers_Unistd { private static native int ftruncate(int fd, long length); } - @TargetClass(com.oracle.svm.core.posix.headers.linux.LinuxSendfile.class) + @TargetClass(com.oracle.svm.core.posixsubst.headers.linux.LinuxSendfile.class) static final class Target_com_oracle_svm_core_posix_headers_linux_LinuxSendfile { @Substitute @CFunction("sendfile64") diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/linux/LinuxEPoll.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/linux/LinuxEPoll.java index 106f963d5859..10cf4df92859 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/linux/LinuxEPoll.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/linux/LinuxEPoll.java @@ -35,11 +35,11 @@ import org.graalvm.nativeimage.impl.DeprecatedPlatform; import org.graalvm.word.PointerBase; -import com.oracle.svm.core.posix.headers.PosixDirectives; +import com.oracle.svm.core.posixsubst.headers.PosixSubstDirectives; /* Allow underscores in names: Checkstyle: stop. */ -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) @Platforms({DeprecatedPlatform.LINUX_SUBSTITUTION.class}) public class LinuxEPoll { diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/linux/LinuxIn.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/linux/LinuxIn.java index b9f0c4dc574a..e44762b05b8a 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/linux/LinuxIn.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/linux/LinuxIn.java @@ -24,9 +24,6 @@ */ package com.oracle.svm.core.posixsubst.headers.linux; -import com.oracle.svm.core.posix.headers.PosixDirectives; -import com.oracle.svm.core.posixsubst.headers.NetinetIn; - import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.struct.CField; @@ -35,9 +32,12 @@ import org.graalvm.nativeimage.impl.DeprecatedPlatform; import org.graalvm.word.PointerBase; +import com.oracle.svm.core.posixsubst.headers.NetinetIn; +import com.oracle.svm.core.posixsubst.headers.PosixSubstDirectives; + /* Checkstyle: stop */ -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) @Platforms(DeprecatedPlatform.LINUX_SUBSTITUTION.class) public class LinuxIn { // @formatter:off diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/linux/LinuxSched.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/linux/LinuxSched.java index 2a6b7ee475b4..8add146775d8 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/linux/LinuxSched.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/linux/LinuxSched.java @@ -32,9 +32,9 @@ import org.graalvm.nativeimage.impl.DeprecatedPlatform; import org.graalvm.word.PointerBase; -import com.oracle.svm.core.posix.headers.PosixDirectives; +import com.oracle.svm.core.posixsubst.headers.PosixSubstDirectives; -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) @Platforms({DeprecatedPlatform.LINUX_SUBSTITUTION.class}) public class LinuxSched { // Checkstyle: stop diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/linux/LinuxSendfile.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/linux/LinuxSendfile.java similarity index 91% rename from substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/linux/LinuxSendfile.java rename to substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/linux/LinuxSendfile.java index 8dc3c8954719..dbcd6545c7d4 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/headers/linux/LinuxSendfile.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/linux/LinuxSendfile.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package com.oracle.svm.core.posix.headers.linux; +package com.oracle.svm.core.posixsubst.headers.linux; import org.graalvm.nativeimage.c.CContext; import org.graalvm.nativeimage.c.function.CFunction; @@ -30,14 +30,14 @@ import org.graalvm.word.SignedWord; import org.graalvm.word.UnsignedWord; -import com.oracle.svm.core.posix.headers.PosixDirectives; +import com.oracle.svm.core.posixsubst.headers.PosixSubstDirectives; //Checkstyle: stop /** * Definitions manually translated from the C header file sys/sendfile.h. */ -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public class LinuxSendfile { @CFunction diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/linux/Mntent.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/linux/Mntent.java index 6c69383116cc..5ef74abe2618 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/linux/Mntent.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/linux/Mntent.java @@ -33,15 +33,15 @@ import org.graalvm.nativeimage.impl.DeprecatedPlatform; import org.graalvm.word.PointerBase; -import com.oracle.svm.core.posix.headers.PosixDirectives; -import com.oracle.svm.core.posix.headers.Stdio.FILE; +import com.oracle.svm.core.posixsubst.headers.PosixSubstDirectives; +import com.oracle.svm.core.posixsubst.headers.Stdio.FILE; //Checkstyle: stop /** * Definitions manually translated from the C header file mntent.h. */ -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) @Platforms(DeprecatedPlatform.LINUX_SUBSTITUTION.class) public class Mntent { diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/linux/package-info.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/linux/package-info.java index 45ace17cfb7f..40b1868818e5 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/linux/package-info.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/headers/linux/package-info.java @@ -23,7 +23,7 @@ * questions. */ -@Platforms({DeprecatedPlatform.LINUX_SUBSTITUTION.class, DeprecatedPlatform.DARWIN_SUBSTITUTION.class}) +@Platforms({DeprecatedPlatform.LINUX_SUBSTITUTION.class}) package com.oracle.svm.core.posixsubst.headers.linux; import org.graalvm.nativeimage.Platforms; diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/linux/LinuxJavaNetCloseImpl.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/linux/LinuxJavaNetCloseImpl.java index 558da3ae4483..a7bb9b34a00f 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/linux/LinuxJavaNetCloseImpl.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/linux/LinuxJavaNetCloseImpl.java @@ -24,21 +24,21 @@ */ package com.oracle.svm.core.posixsubst.linux; -import org.graalvm.nativeimage.hosted.Feature; -import org.graalvm.nativeimage.impl.DeprecatedPlatform; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.StackValue; import org.graalvm.nativeimage.c.type.CIntPointer; +import org.graalvm.nativeimage.hosted.Feature; +import org.graalvm.nativeimage.impl.DeprecatedPlatform; import org.graalvm.word.WordFactory; import com.oracle.svm.core.annotate.AutomaticFeature; -import com.oracle.svm.core.headers.Errno; -import com.oracle.svm.core.posix.headers.Socket; import com.oracle.svm.core.posix.headers.Time; -import com.oracle.svm.core.posix.headers.Unistd; import com.oracle.svm.core.posixsubst.PosixJavaNetClose; +import com.oracle.svm.core.posixsubst.headers.Errno; import com.oracle.svm.core.posixsubst.headers.Poll; +import com.oracle.svm.core.posixsubst.headers.Socket; +import com.oracle.svm.core.posixsubst.headers.Unistd; /** * Translation of the mechanisms in /jdk8u-dev/jdk/src/solaris/native/java/net/linux_close.c that diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/linux/LinuxJavaNetNetworkInterface.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/linux/LinuxJavaNetNetworkInterface.java index d752546a2090..d0473770494e 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/linux/LinuxJavaNetNetworkInterface.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/linux/LinuxJavaNetNetworkInterface.java @@ -32,8 +32,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.graalvm.nativeimage.hosted.Feature; -import org.graalvm.nativeimage.impl.DeprecatedPlatform; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.StackValue; @@ -43,28 +41,30 @@ import org.graalvm.nativeimage.c.type.CIntPointer; import org.graalvm.nativeimage.c.type.CTypeConversion; import org.graalvm.nativeimage.c.type.CTypeConversion.CCharPointerHolder; +import org.graalvm.nativeimage.hosted.Feature; +import org.graalvm.nativeimage.impl.DeprecatedPlatform; import org.graalvm.word.WordFactory; import com.oracle.svm.core.annotate.AutomaticFeature; import com.oracle.svm.core.log.Log; import com.oracle.svm.core.os.IsDefined; import com.oracle.svm.core.posix.PosixUtils; -import com.oracle.svm.core.headers.Errno; import com.oracle.svm.core.posix.headers.LibC; -import com.oracle.svm.core.posix.headers.PosixDirectives; -import com.oracle.svm.core.posix.headers.Socket; -import com.oracle.svm.core.posix.headers.Unistd; import com.oracle.svm.core.posixsubst.JavaNetNetworkInterface; import com.oracle.svm.core.posixsubst.headers.ArpaInet; +import com.oracle.svm.core.posixsubst.headers.Errno; import com.oracle.svm.core.posixsubst.headers.Ioctl; import com.oracle.svm.core.posixsubst.headers.NetIf; import com.oracle.svm.core.posixsubst.headers.NetinetIn; +import com.oracle.svm.core.posixsubst.headers.PosixSubstDirectives; +import com.oracle.svm.core.posixsubst.headers.Socket; +import com.oracle.svm.core.posixsubst.headers.Unistd; /* { Do not format quoted code: @formatter:off */ /* { Allow non-standard names: Checkstyle: stop */ @Platforms(DeprecatedPlatform.LINUX_SUBSTITUTION.class) -@CContext(PosixDirectives.class) +@CContext(PosixSubstDirectives.class) public class LinuxJavaNetNetworkInterface { /** Register the implementation. */ diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/linux/LinuxNIOSubstitutions.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/linux/LinuxNIOSubstitutions.java index d342db09b6a7..2bd33af3a06d 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/linux/LinuxNIOSubstitutions.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/linux/LinuxNIOSubstitutions.java @@ -42,13 +42,13 @@ import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; import com.oracle.svm.core.annotate.TargetElement; -import com.oracle.svm.core.headers.Errno; import com.oracle.svm.core.jdk.JDK11OrLater; import com.oracle.svm.core.jdk.JDK8OrEarlier; -import com.oracle.svm.core.posix.headers.Socket; import com.oracle.svm.core.posix.headers.Time; -import com.oracle.svm.core.posix.headers.Unistd; import com.oracle.svm.core.posixsubst.PosixJavaNIOSubstitutions; +import com.oracle.svm.core.posixsubst.headers.Errno; +import com.oracle.svm.core.posixsubst.headers.Socket; +import com.oracle.svm.core.posixsubst.headers.Unistd; import com.oracle.svm.core.posixsubst.headers.linux.LinuxEPoll; @Platforms({DeprecatedPlatform.LINUX_SUBSTITUTION.class}) diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/linux/Target_java_lang_Runtime.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/linux/Target_java_lang_Runtime.java index bc4f356b7daa..2e31ab58ee5b 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/linux/Target_java_lang_Runtime.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/linux/Target_java_lang_Runtime.java @@ -35,7 +35,7 @@ import com.oracle.svm.core.SubstrateOptions; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.posix.headers.Unistd; +import com.oracle.svm.core.posixsubst.headers.Unistd; import com.oracle.svm.core.posixsubst.headers.linux.LinuxSched; @Platforms(DeprecatedPlatform.LINUX_SUBSTITUTION.class) diff --git a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/linux/package-info.java b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/linux/package-info.java index 1b49e1d3b594..0dd197d4f947 100644 --- a/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/linux/package-info.java +++ b/substratevm/src/com.oracle.svm.core.posixsubst/src/com/oracle/svm/core/posixsubst/linux/package-info.java @@ -23,7 +23,7 @@ * questions. */ -@Platforms({DeprecatedPlatform.LINUX_SUBSTITUTION.class, DeprecatedPlatform.DARWIN_SUBSTITUTION.class}) +@Platforms({DeprecatedPlatform.LINUX_SUBSTITUTION.class}) package com.oracle.svm.core.posixsubst.linux; import org.graalvm.nativeimage.Platforms; diff --git a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsCErrorNumberSupport.java b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsCErrorNumberSupport.java new file mode 100644 index 000000000000..517f3179d826 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsCErrorNumberSupport.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2019, 2019, 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. + */ +package com.oracle.svm.core.windows; + +import com.oracle.svm.core.CErrorNumber.CErrorNumberSupport; +import com.oracle.svm.core.annotate.Uninterruptible; +import com.oracle.svm.core.windows.headers.WindowsErrno; + +class WindowsCErrorNumberSupport implements CErrorNumberSupport { + + @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) + @Override + public int getCErrorNumber() { + return WindowsErrno._errno().read(); + } + + @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) + @Override + public void setCErrorNumber(int value) { + WindowsErrno._errno().write(value); + } +} diff --git a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsImageSingletonsFeature.java b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsImageSingletonsFeature.java new file mode 100644 index 000000000000..6763e5bcf5e1 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsImageSingletonsFeature.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2019, 2019, 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. + */ +package com.oracle.svm.core.windows; + +import org.graalvm.nativeimage.ImageSingletons; +import org.graalvm.nativeimage.hosted.Feature; + +import com.oracle.svm.core.CErrorNumber.CErrorNumberSupport; +import com.oracle.svm.core.annotate.AutomaticFeature; + +@AutomaticFeature +class WindowsImageSingletonsFeature implements Feature { + + @Override + public void afterRegistration(AfterRegistrationAccess access) { + ImageSingletons.add(CErrorNumberSupport.class, new WindowsCErrorNumberSupport()); + } +} diff --git a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/headers/WindowsErrno.java b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/headers/WindowsErrno.java index a0c5161fa01e..a9ccd82e30f6 100644 --- a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/headers/WindowsErrno.java +++ b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/headers/WindowsErrno.java @@ -29,34 +29,11 @@ import org.graalvm.nativeimage.c.function.CFunction; import org.graalvm.nativeimage.c.type.CIntPointer; -import com.oracle.svm.core.annotate.Substitute; -import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.annotate.Uninterruptible; -import com.oracle.svm.core.headers.Errno; - -//Checkstyle: stop +// Checkstyle: stop @Platforms(Platform.WINDOWS.class) -class WindowsErrno { - - @TargetClass(Errno.class) - static final class Target_com_oracle_svm_core_headers_Errno { - - @Substitute - @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) - private static int errno() { - return Util_com_oracle_svm_core_headers_Errno._errno().read(); - } - - @Substitute - @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) - public static void set_errno(int value) { - Util_com_oracle_svm_core_headers_Errno._errno().write(value); - } - } +public class WindowsErrno { - static final class Util_com_oracle_svm_core_headers_Errno { - @CFunction(transition = CFunction.Transition.NO_TRANSITION) - static native CIntPointer _errno(); - } + @CFunction(transition = CFunction.Transition.NO_TRANSITION) + public static native CIntPointer _errno(); } diff --git a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/headers/package-info.java b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/headers/package-info.java new file mode 100644 index 000000000000..4b55a11df10f --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/headers/package-info.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2019, 2019, 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. + */ + +@Platforms(Platform.WINDOWS.class) +package com.oracle.svm.core.windows.headers; + +import org.graalvm.nativeimage.Platform; +import org.graalvm.nativeimage.Platforms; diff --git a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/package-info.java b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/package-info.java new file mode 100644 index 000000000000..b5e15a974c7e --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/package-info.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2019, 2019, 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. + */ + +@Platforms(Platform.WINDOWS.class) +package com.oracle.svm.core.windows; + +import org.graalvm.nativeimage.Platform; +import org.graalvm.nativeimage.Platforms; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/CErrorNumber.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/CErrorNumber.java new file mode 100644 index 000000000000..890f646d387f --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/CErrorNumber.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2013, 2019, 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. + */ +package com.oracle.svm.core; + +import org.graalvm.nativeimage.ImageSingletons; + +import com.oracle.svm.core.annotate.Uninterruptible; + +public class CErrorNumber { + + public interface CErrorNumberSupport { + @Uninterruptible(reason = "Called from uninterruptible code.") + int getCErrorNumber(); + + @Uninterruptible(reason = "Called from uninterruptible code.") + void setCErrorNumber(int value); + } + + @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) + public static int getCErrorNumber() { + return ImageSingletons.lookup(CErrorNumberSupport.class).getCErrorNumber(); + } + + @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) + public static void setCErrorNumber(int value) { + ImageSingletons.lookup(CErrorNumberSupport.class).setCErrorNumber(value); + } +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/ErrnoDirectives.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/ErrnoDirectives.java deleted file mode 100644 index e72f4dcb1030..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/ErrnoDirectives.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2019, 2019, 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. - */ -package com.oracle.svm.core; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import org.graalvm.nativeimage.Platform; -import org.graalvm.nativeimage.c.CContext; - -import com.oracle.svm.core.util.VMError; -import org.graalvm.nativeimage.impl.InternalPlatform; - -public class ErrnoDirectives implements CContext.Directives { - - @Override - public boolean isInConfiguration() { - return Platform.includedIn(InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class) || Platform.includedIn(InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class) || - Platform.includedIn(Platform.WINDOWS.class); - } - - @Override - public List getHeaderFiles() { - List result = new ArrayList<>(); - if (Platform.includedIn(InternalPlatform.LINUX_JNI_AND_SUBSTITUTIONS.class) || Platform.includedIn(InternalPlatform.DARWIN_JNI_AND_SUBSTITUTIONS.class)) { - result.add(""); - } else if (Platform.includedIn(Platform.WINDOWS.class)) { - result.add(""); - } else { - throw VMError.shouldNotReachHere("Unsupported OS"); - } - return result; - } - - @Override - public List getMacroDefinitions() { - if (!Platform.includedIn(Platform.WINDOWS.class)) { - return Arrays.asList("_GNU_SOURCE", "_LARGEFILE64_SOURCE"); - } - return Collections.emptyList(); - } -} diff --git a/substratevm/src/com.oracle.svm.truffle.nfi/src/com/oracle/svm/truffle/nfi/TruffleNFISupport.java b/substratevm/src/com.oracle.svm.truffle.nfi/src/com/oracle/svm/truffle/nfi/TruffleNFISupport.java index 154c056e688b..4f8d50db2aed 100644 --- a/substratevm/src/com.oracle.svm.truffle.nfi/src/com/oracle/svm/truffle/nfi/TruffleNFISupport.java +++ b/substratevm/src/com.oracle.svm.truffle.nfi/src/com/oracle/svm/truffle/nfi/TruffleNFISupport.java @@ -28,7 +28,6 @@ import java.nio.CharBuffer; import java.nio.charset.Charset; -import com.oracle.svm.core.headers.Errno; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.ObjectHandle; import org.graalvm.nativeimage.ObjectHandles; @@ -39,6 +38,7 @@ import org.graalvm.word.UnsignedWord; import org.graalvm.word.WordFactory; +import com.oracle.svm.core.CErrorNumber; import com.oracle.svm.core.SubstrateUtil; import com.oracle.svm.core.threadlocal.FastThreadLocalFactory; import com.oracle.svm.core.threadlocal.FastThreadLocalObject; @@ -218,12 +218,12 @@ public static class ErrnoMirrorContext implements AutoCloseable { public ErrnoMirrorContext() { errnoMirror = ErrnoMirror.getErrnoMirrorLocation(); - errnoMirror.write(Errno.errno()); + errnoMirror.write(CErrorNumber.getCErrorNumber()); } @Override public void close() { - Errno.set_errno(errnoMirror.read()); + CErrorNumber.setCErrorNumber(errnoMirror.read()); } } @@ -238,12 +238,12 @@ public static class NativeErrnoContext implements AutoCloseable { public NativeErrnoContext() { errnoMirror = ErrnoMirror.getErrnoMirrorLocation(); - Errno.set_errno(errnoMirror.read()); + CErrorNumber.setCErrorNumber(errnoMirror.read()); } @Override public void close() { - errnoMirror.write(Errno.errno()); + errnoMirror.write(CErrorNumber.getCErrorNumber()); } } }