Search in sources :

Example 56 with Substitute

use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.

the class PosixJavaIOSubstitutions method setLastModifiedTime.

@Substitute
public boolean setLastModifiedTime(File f, long time) {
    stat stat = StackValue.get(SizeOf.get(stat.class));
    try (CCharPointerHolder pathPin = CTypeConversion.toCString(f.getPath())) {
        CCharPointer pathPtr = pathPin.get();
        if (stat(pathPtr, stat) == 0) {
            timeval timeval = StackValue.get(2, SizeOf.get(timeval.class));
            // preserve access time
            timeval access = timeval.addressOf(0);
            access.set_tv_sec(stat.st_atime());
            access.set_tv_usec(0L);
            // change last-modified time
            timeval last = timeval.addressOf(1);
            last.set_tv_sec(time / 1000);
            last.set_tv_usec((time % 1000) * 1000);
            if (utimes(pathPtr, timeval) == 0) {
                return true;
            }
        }
    }
    return false;
}
Also used : Stat.stat(com.oracle.svm.core.posix.headers.Stat.stat) Stat.fstat(com.oracle.svm.core.posix.headers.Stat.fstat) Time.timeval(com.oracle.svm.core.posix.headers.Time.timeval) CCharPointerHolder(org.graalvm.nativeimage.c.type.CTypeConversion.CCharPointerHolder) CCharPointer(org.graalvm.nativeimage.c.type.CCharPointer) Substitute(com.oracle.svm.core.annotate.Substitute)

Example 57 with Substitute

use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.

the class PosixJavaIOSubstitutions method getFilePointer.

@Substitute
public long getFilePointer() throws IOException {
    SignedWord ret;
    int handle = PosixUtils.getFDHandle(fd);
    if ((ret = lseek(handle, WordFactory.zero(), SEEK_CUR())).equal(WordFactory.signed(-1))) {
        throw new IOException(lastErrorString("Seek failed"));
    }
    return ret.rawValue();
}
Also used : IOException(java.io.IOException) SignedWord(org.graalvm.word.SignedWord) Substitute(com.oracle.svm.core.annotate.Substitute)

Example 58 with Substitute

use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.

the class PosixJavaLangSubstitutions method currentTimeMillis.

@Substitute
@Uninterruptible(reason = "Called from uninterruptible code.")
public static long currentTimeMillis() {
    timeval timeval = StackValue.get(SizeOf.get(timeval.class));
    timezone timezone = WordFactory.nullPointer();
    gettimeofday(timeval, timezone);
    return timeval.tv_sec() * 1_000L + timeval.tv_usec() / 1_000L;
}
Also used : Time.timezone(com.oracle.svm.core.posix.headers.Time.timezone) Time.timeval(com.oracle.svm.core.posix.headers.Time.timeval) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible) Substitute(com.oracle.svm.core.annotate.Substitute)

Example 59 with Substitute

use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.

the class PosixJavaLangSubstitutions method waitForProcessExit.

@Substitute
@SuppressWarnings({ "static-method" })
int waitForProcessExit(int ppid) {
    CIntPointer statusptr = StackValue.get(SizeOf.get(CIntPointer.class));
    while (Wait.waitpid(ppid, statusptr, 0) < 0) {
        if (Errno.errno() == Errno.ECHILD()) {
            return 0;
        } else if (Errno.errno() != Errno.EINTR()) {
            return -1;
        }
    }
    int status = statusptr.read();
    if (Wait.WIFEXITED(status)) {
        return Wait.WEXITSTATUS(status);
    } else if (Wait.WIFSIGNALED(status)) {
        // Exited because of signal: return 0x80 + signal number like shells do
        return 0x80 + Wait.WTERMSIG(status);
    }
    return status;
}
Also used : CIntPointer(org.graalvm.nativeimage.c.type.CIntPointer) Substitute(com.oracle.svm.core.annotate.Substitute)

Example 60 with Substitute

use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.

the class DarwinSubstitutions method nanoTime.

@Substitute
@Uninterruptible(reason = "Does basic math after a few simple system calls")
private static long nanoTime() {
    final Util_java_lang_System utilJavaLangSystem = ImageSingletons.lookup(Util_java_lang_System.class);
    if (utilJavaLangSystem.fastTime) {
        return mach_absolute_time();
    }
    if (!utilJavaLangSystem.timeBaseValid) {
        MachTimebaseInfo timeBaseInfo = StackValue.get(SizeOf.get(MachTimebaseInfo.class));
        if (mach_timebase_info(timeBaseInfo) == 0) {
            if (timeBaseInfo.getdenom() == 1 && timeBaseInfo.getnumer() == 1) {
                utilJavaLangSystem.fastTime = true;
                return mach_absolute_time();
            }
            utilJavaLangSystem.factor = (double) timeBaseInfo.getnumer() / (double) timeBaseInfo.getdenom();
        }
        utilJavaLangSystem.timeBaseValid = true;
    }
    if (utilJavaLangSystem.factor != 0) {
        return (long) (mach_absolute_time() * utilJavaLangSystem.factor);
    }
    /* High precision time is not available, fall back to low precision. */
    timeval timeval = StackValue.get(SizeOf.get(timeval.class));
    timezone timezone = WordFactory.nullPointer();
    gettimeofday(timeval, timezone);
    return timeval.tv_sec() * 1_000_000_000L + timeval.tv_usec() * 1_000L;
}
Also used : Time.timezone(com.oracle.svm.core.posix.headers.Time.timezone) MachTimebaseInfo(com.oracle.svm.core.posix.headers.darwin.DarwinTime.MachTimebaseInfo) Time.timeval(com.oracle.svm.core.posix.headers.Time.timeval) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible) Substitute(com.oracle.svm.core.annotate.Substitute)

Aggregations

Substitute (com.oracle.svm.core.annotate.Substitute)69 CCharPointer (org.graalvm.nativeimage.c.type.CCharPointer)18 SocketException (java.net.SocketException)11 IOException (java.io.IOException)10 CIntPointer (org.graalvm.nativeimage.c.type.CIntPointer)10 PinnedObject (org.graalvm.nativeimage.PinnedObject)9 Util_java_io_FileDescriptor (com.oracle.svm.core.posix.PosixOSInterface.Util_java_io_FileDescriptor)8 FileDescriptor (java.io.FileDescriptor)8 CCharPointerHolder (org.graalvm.nativeimage.c.type.CTypeConversion.CCharPointerHolder)8 ServerSocket (java.net.ServerSocket)7 Socket (com.oracle.svm.core.posix.headers.Socket)6 NativeTruffleContext (com.oracle.svm.truffle.nfi.NativeAPI.NativeTruffleContext)6 SignedWord (org.graalvm.word.SignedWord)6 InterruptedIOException (java.io.InterruptedIOException)5 Time.timeval (com.oracle.svm.core.posix.headers.Time.timeval)4 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)3 Stat.fstat (com.oracle.svm.core.posix.headers.Stat.fstat)3 Stat.stat (com.oracle.svm.core.posix.headers.Stat.stat)3 Time.timezone (com.oracle.svm.core.posix.headers.Time.timezone)3 LibFFI.ffi_cif (com.oracle.svm.truffle.nfi.libffi.LibFFI.ffi_cif)3