Search in sources :

Example 11 with SignedWord

use of org.graalvm.word.SignedWord in project graal by oracle.

the class PosixUtils method readSingle.

static int readSingle(FileDescriptor fd) throws IOException {
    CCharPointer retPtr = StackValue.get(SizeOf.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 new IOException(lastErrorString("Read error"));
    }
    return retPtr.read() & 0xFF;
}
Also used : IOException(java.io.IOException) SignedWord(org.graalvm.word.SignedWord) CCharPointer(org.graalvm.nativeimage.c.type.CCharPointer)

Example 12 with SignedWord

use of org.graalvm.word.SignedWord in project graal by oracle.

the class PosixUtils method writeSingle.

@SuppressWarnings("unused")
static void writeSingle(FileDescriptor fd, int b, boolean append) throws IOException {
    SignedWord n;
    int handle = Util_java_io_FileDescriptor.getFD(fd);
    if (handle == -1) {
        throw new IOException("Stream Closed");
    }
    CCharPointer bufPtr = StackValue.get(SizeOf.get(CCharPointer.class));
    bufPtr.write((byte) b);
    // the append parameter is disregarded
    n = write(handle, bufPtr, WordFactory.unsigned(1));
    if (n.equal(-1)) {
        throw new IOException(lastErrorString("Write error"));
    }
}
Also used : IOException(java.io.IOException) SignedWord(org.graalvm.word.SignedWord) CCharPointer(org.graalvm.nativeimage.c.type.CCharPointer)

Example 13 with SignedWord

use of org.graalvm.word.SignedWord in project graal by oracle.

the class PosixJavaIOSubstitutions method skip.

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

Example 14 with SignedWord

use of org.graalvm.word.SignedWord 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 15 with SignedWord

use of org.graalvm.word.SignedWord in project graal by oracle.

the class PosixJavaLangSubstitutions method writeEntirely.

@Uninterruptible(reason = "Called from uninterruptible code.")
static SignedWord writeEntirely(int fd, PointerBase buf, UnsignedWord count) {
    Pointer ptr = WordFactory.pointer(buf.rawValue());
    final Pointer end = ptr.add(count);
    SignedWord written;
    do {
        Errno.set_errno(0);
        written = UnistdNoTransitions.write(fd, ptr, end.subtract(ptr));
        if (written.greaterThan(0)) {
            ptr = ptr.add((int) written.rawValue());
        }
    } while (ptr.notEqual(end) && (written.notEqual(-1) || Errno.errno() == Errno.EINTR()));
    if (ptr.notEqual(buf)) {
        return WordFactory.signed(ptr.rawValue() - buf.rawValue());
    }
    return written;
}
Also used : CIntPointer(org.graalvm.nativeimage.c.type.CIntPointer) CCharPointerPointer(org.graalvm.nativeimage.c.type.CCharPointerPointer) CCharPointer(org.graalvm.nativeimage.c.type.CCharPointer) Dirent.direntPointer(com.oracle.svm.core.posix.headers.Dirent.direntPointer) Pointer(org.graalvm.word.Pointer) SignedWord(org.graalvm.word.SignedWord) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Aggregations

SignedWord (org.graalvm.word.SignedWord)16 IOException (java.io.IOException)9 CCharPointer (org.graalvm.nativeimage.c.type.CCharPointer)7 Substitute (com.oracle.svm.core.annotate.Substitute)6 CIntPointer (org.graalvm.nativeimage.c.type.CIntPointer)4 CCharPointerPointer (org.graalvm.nativeimage.c.type.CCharPointerPointer)3 Pointer (org.graalvm.word.Pointer)3 UnsignedWord (org.graalvm.word.UnsignedWord)3 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)2 SubstrateObjectConstant (com.oracle.svm.core.meta.SubstrateObjectConstant)2 Dirent.direntPointer (com.oracle.svm.core.posix.headers.Dirent.direntPointer)2 PrimitiveConstant (jdk.vm.ci.meta.PrimitiveConstant)2 Word (org.graalvm.compiler.word.Word)2 PinnedObject (org.graalvm.nativeimage.PinnedObject)2 Stat.fstat (com.oracle.svm.core.posix.headers.Stat.fstat)1 Stat.stat (com.oracle.svm.core.posix.headers.Stat.stat)1 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)1