< prev index next >

src/java.base/unix/classes/sun/nio/fs/UnixNativeDispatcher.java

Print this page
*** 23,10 ***
--- 23,12 ---
   * questions.
   */
  
  package sun.nio.fs;
  
+ import jdk.internal.misc.Blocker;
+ 
  /**
   * Unix system and library calls.
   */
  
  class UnixNativeDispatcher {

*** 61,29 ***
  
      /**
       * int open(const char* path, int oflag, mode_t mode)
       */
      static int open(UnixPath path, int flags, int mode) throws UnixException {
!         NativeBuffer buffer = copyToNativeBuffer(path);
!         try {
!             return open0(buffer.address(), flags, mode);
!         } finally {
!             buffer.release();
          }
      }
      private static native int open0(long pathAddress, int flags, int mode)
          throws UnixException;
  
      /**
       * int openat(int dfd, const char* path, int oflag, mode_t mode)
       */
      static int openat(int dfd, byte[] path, int flags, int mode) throws UnixException {
!         NativeBuffer buffer = NativeBuffers.asNativeBuffer(path);
!         try {
!             return openat0(dfd, buffer.address(), flags, mode);
!         } finally {
!             buffer.release();
          }
      }
      private static native int openat0(int dfd, long pathAddress, int flags, int mode)
          throws UnixException;
  
--- 63,31 ---
  
      /**
       * int open(const char* path, int oflag, mode_t mode)
       */
      static int open(UnixPath path, int flags, int mode) throws UnixException {
!         try (NativeBuffer buffer = copyToNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 return Blocker.managedBlock(() -> open0(buffer.address(), flags, mode));
!             } else {
!                 return open0(buffer.address(), flags, mode);
+             }
          }
      }
      private static native int open0(long pathAddress, int flags, int mode)
          throws UnixException;
  
      /**
       * int openat(int dfd, const char* path, int oflag, mode_t mode)
       */
      static int openat(int dfd, byte[] path, int flags, int mode) throws UnixException {
!         try (NativeBuffer buffer = NativeBuffers.asNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 return Blocker.managedBlock(() -> openat0(dfd, buffer.address(), flags, mode));
!             } else {
!                 return openat0(dfd, buffer.address(), flags, mode);
+             }
          }
      }
      private static native int openat0(int dfd, long pathAddress, int flags, int mode)
          throws UnixException;
  

*** 109,176 ***
  
      /**
       * link(const char* existing, const char* new)
       */
      static void link(UnixPath existing, UnixPath newfile) throws UnixException {
!         NativeBuffer existingBuffer = copyToNativeBuffer(existing);
!         NativeBuffer newBuffer = copyToNativeBuffer(newfile);
!         try {
!             link0(existingBuffer.address(), newBuffer.address());
!         } finally {
!             newBuffer.release();
!             existingBuffer.release();
          }
      }
      private static native void link0(long existingAddress, long newAddress)
          throws UnixException;
  
      /**
       * unlink(const char* path)
       */
      static void unlink(UnixPath path) throws UnixException {
!         NativeBuffer buffer = copyToNativeBuffer(path);
!         try {
!             unlink0(buffer.address());
!         } finally {
!             buffer.release();
          }
      }
      private static native void unlink0(long pathAddress) throws UnixException;
  
      /**
       * unlinkat(int dfd, const char* path, int flag)
       */
      static void unlinkat(int dfd, byte[] path, int flag) throws UnixException {
!         NativeBuffer buffer = NativeBuffers.asNativeBuffer(path);
!         try {
!             unlinkat0(dfd, buffer.address(), flag);
!         } finally {
!             buffer.release();
          }
      }
      private static native void unlinkat0(int dfd, long pathAddress, int flag)
          throws UnixException;
  
      /**
       * mknod(const char* path, mode_t mode, dev_t dev)
       */
      static void mknod(UnixPath path, int mode, long dev) throws UnixException {
!         NativeBuffer buffer = copyToNativeBuffer(path);
!         try {
!             mknod0(buffer.address(), mode, dev);
!         } finally {
!             buffer.release();
          }
      }
      private static native void mknod0(long pathAddress, int mode, long dev)
          throws UnixException;
  
      /**
       *  rename(const char* old, const char* new)
       */
      static void rename(UnixPath from, UnixPath to) throws UnixException {
!         NativeBuffer fromBuffer = copyToNativeBuffer(from);
!         NativeBuffer toBuffer = copyToNativeBuffer(to);
!         try {
!             rename0(fromBuffer.address(), toBuffer.address());
!         } finally {
!             toBuffer.release();
!             fromBuffer.release();
          }
      }
      private static native void rename0(long fromAddress, long toAddress)
          throws UnixException;
  
      /**
       *  renameat(int fromfd, const char* old, int tofd, const char* new)
       */
      static void renameat(int fromfd, byte[] from, int tofd, byte[] to) throws UnixException {
!         NativeBuffer fromBuffer = NativeBuffers.asNativeBuffer(from);
!         NativeBuffer toBuffer = NativeBuffers.asNativeBuffer(to);
!         try {
!             renameat0(fromfd, fromBuffer.address(), tofd, toBuffer.address());
!         } finally {
!             toBuffer.release();
!             fromBuffer.release();
          }
      }
      private static native void renameat0(int fromfd, long fromAddress, int tofd, long toAddress)
          throws UnixException;
  
      /**
       * mkdir(const char* path, mode_t mode)
       */
      static void mkdir(UnixPath path, int mode) throws UnixException {
!         NativeBuffer buffer = copyToNativeBuffer(path);
!         try {
!             mkdir0(buffer.address(), mode);
!         } finally {
!             buffer.release();
          }
      }
      private static native void mkdir0(long pathAddress, int mode) throws UnixException;
  
      /**
       * rmdir(const char* path)
       */
      static void rmdir(UnixPath path) throws UnixException {
!         NativeBuffer buffer = copyToNativeBuffer(path);
!         try {
!             rmdir0(buffer.address());
!         } finally {
!             buffer.release();
          }
      }
      private static native void rmdir0(long pathAddress) throws UnixException;
  
      /**
       * readlink(const char* path, char* buf, size_t bufsize)
       *
       * @return  link target
       */
      static byte[] readlink(UnixPath path) throws UnixException {
!         NativeBuffer buffer = copyToNativeBuffer(path);
!         try {
!             return readlink0(buffer.address());
!         } finally {
!             buffer.release();
          }
      }
      private static native byte[] readlink0(long pathAddress) throws UnixException;
  
      /**
       * realpath(const char* path, char* resolved_name)
       *
       * @return  resolved path
       */
      static byte[] realpath(UnixPath path) throws UnixException {
!         NativeBuffer buffer = copyToNativeBuffer(path);
!         try {
!             return realpath0(buffer.address());
!         } finally {
!             buffer.release();
          }
      }
      private static native byte[] realpath0(long pathAddress) throws UnixException;
  
      /**
       * symlink(const char* name1, const char* name2)
       */
      static void symlink(byte[] name1, UnixPath name2) throws UnixException {
!         NativeBuffer targetBuffer = NativeBuffers.asNativeBuffer(name1);
!         NativeBuffer linkBuffer = copyToNativeBuffer(name2);
!         try {
!             symlink0(targetBuffer.address(), linkBuffer.address());
!         } finally {
!             linkBuffer.release();
!             targetBuffer.release();
          }
      }
      private static native void symlink0(long name1, long name2)
          throws UnixException;
  
      /**
       * stat(const char* path, struct stat* buf)
       */
      static void stat(UnixPath path, UnixFileAttributes attrs) throws UnixException {
!         NativeBuffer buffer = copyToNativeBuffer(path);
!         try {
!             stat0(buffer.address(), attrs);
!         } finally {
!             buffer.release();
          }
      }
      private static native void stat0(long pathAddress, UnixFileAttributes attrs)
          throws UnixException;
  
--- 113,192 ---
  
      /**
       * link(const char* existing, const char* new)
       */
      static void link(UnixPath existing, UnixPath newfile) throws UnixException {
!         try (NativeBuffer existingBuffer = copyToNativeBuffer(existing);
!              NativeBuffer newBuffer = copyToNativeBuffer(newfile)) {
!             long existingAddress = existingBuffer.address();
!             long newAddress = newBuffer.address();
!             if (Thread.currentThread().isVirtual()) {
!                 Blocker.managedBlock(() -> link0(existingAddress, newAddress));
!             } else {
+                 link0(existingAddress, newAddress);
+             }
          }
      }
      private static native void link0(long existingAddress, long newAddress)
          throws UnixException;
  
      /**
       * unlink(const char* path)
       */
      static void unlink(UnixPath path) throws UnixException {
!         try (NativeBuffer buffer = copyToNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 Blocker.managedBlock(() -> unlink0(buffer.address()));
!             } else {
!                 unlink0(buffer.address());
+             }
          }
      }
      private static native void unlink0(long pathAddress) throws UnixException;
  
      /**
       * unlinkat(int dfd, const char* path, int flag)
       */
      static void unlinkat(int dfd, byte[] path, int flag) throws UnixException {
!         try (NativeBuffer buffer = NativeBuffers.asNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 Blocker.managedBlock(() -> unlinkat0(dfd, buffer.address(), flag));
!             } else {
!                 unlinkat0(dfd, buffer.address(), flag);
+             }
          }
      }
      private static native void unlinkat0(int dfd, long pathAddress, int flag)
          throws UnixException;
  
      /**
       * mknod(const char* path, mode_t mode, dev_t dev)
       */
      static void mknod(UnixPath path, int mode, long dev) throws UnixException {
!         try (NativeBuffer buffer = copyToNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 Blocker.managedBlock(() -> mknod0(buffer.address(), mode, dev));
!             } else {
!                 mknod0(buffer.address(), mode, dev);
+             }
          }
      }
      private static native void mknod0(long pathAddress, int mode, long dev)
          throws UnixException;
  
      /**
       *  rename(const char* old, const char* new)
       */
      static void rename(UnixPath from, UnixPath to) throws UnixException {
!         try (NativeBuffer fromBuffer = copyToNativeBuffer(from);
!              NativeBuffer toBuffer = copyToNativeBuffer(to)) {
!             long fromAddress = fromBuffer.address();
!             long toAddress = toBuffer.address();
!             if (Thread.currentThread().isVirtual()) {
!                 Blocker.managedBlock(() -> rename0(fromAddress, toAddress));
!             } else {
+                 rename0(fromAddress, toAddress);
+             }
          }
      }
      private static native void rename0(long fromAddress, long toAddress)
          throws UnixException;
  
      /**
       *  renameat(int fromfd, const char* old, int tofd, const char* new)
       */
      static void renameat(int fromfd, byte[] from, int tofd, byte[] to) throws UnixException {
!         try (NativeBuffer fromBuffer = NativeBuffers.asNativeBuffer(from);
!              NativeBuffer toBuffer = NativeBuffers.asNativeBuffer(to)) {
!             long fromAddress = fromBuffer.address();
!             long toAddress = toBuffer.address();
!             if (Thread.currentThread().isVirtual()) {
!                 Blocker.managedBlock(() -> renameat0(fromfd, fromAddress, tofd, toAddress));
!             } else {
+                 renameat0(fromfd, fromAddress, tofd, toAddress);
+             }
          }
      }
      private static native void renameat0(int fromfd, long fromAddress, int tofd, long toAddress)
          throws UnixException;
  
      /**
       * mkdir(const char* path, mode_t mode)
       */
      static void mkdir(UnixPath path, int mode) throws UnixException {
!         try (NativeBuffer buffer = copyToNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 Blocker.managedBlock(() -> mkdir0(buffer.address(), mode));
!             } else {
!                 mkdir0(buffer.address(), mode);
+             }
          }
      }
      private static native void mkdir0(long pathAddress, int mode) throws UnixException;
  
      /**
       * rmdir(const char* path)
       */
      static void rmdir(UnixPath path) throws UnixException {
!         try (NativeBuffer buffer = copyToNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 Blocker.managedBlock(() -> rmdir0(buffer.address()));
!             } else {
!                 rmdir0(buffer.address());
+             }
          }
      }
      private static native void rmdir0(long pathAddress) throws UnixException;
  
      /**
       * readlink(const char* path, char* buf, size_t bufsize)
       *
       * @return  link target
       */
      static byte[] readlink(UnixPath path) throws UnixException {
!         try (NativeBuffer buffer = copyToNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 return Blocker.managedBlock(() -> readlink0(buffer.address()));
!             } else {
!                 return readlink0(buffer.address());
+             }
          }
      }
      private static native byte[] readlink0(long pathAddress) throws UnixException;
  
      /**
       * realpath(const char* path, char* resolved_name)
       *
       * @return  resolved path
       */
      static byte[] realpath(UnixPath path) throws UnixException {
!         try (NativeBuffer buffer = copyToNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 return Blocker.managedBlock(() -> realpath0(buffer.address()));
!             } else {
!                 return realpath0(buffer.address());
+             }
          }
      }
      private static native byte[] realpath0(long pathAddress) throws UnixException;
  
      /**
       * symlink(const char* name1, const char* name2)
       */
      static void symlink(byte[] name1, UnixPath name2) throws UnixException {
!         try (NativeBuffer targetBuffer = NativeBuffers.asNativeBuffer(name1);
!              NativeBuffer linkBuffer = copyToNativeBuffer(name2)) {
!             long targetAddress = targetBuffer.address();
!             long linkAddress = linkBuffer.address();
!             if (Thread.currentThread().isVirtual()) {
!                 Blocker.managedBlock(() -> symlink0(targetAddress, linkAddress));
!             } else {
+                 symlink0(targetAddress, linkAddress);
+             }
          }
      }
      private static native void symlink0(long name1, long name2)
          throws UnixException;
  
      /**
       * stat(const char* path, struct stat* buf)
       */
      static void stat(UnixPath path, UnixFileAttributes attrs) throws UnixException {
!         try (NativeBuffer buffer = copyToNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 Blocker.managedBlock(() -> stat0(buffer.address(), attrs));
!             } else {
!                 stat0(buffer.address(), attrs);
+             }
          }
      }
      private static native void stat0(long pathAddress, UnixFileAttributes attrs)
          throws UnixException;
  

*** 287,158 ***
       * stat(const char* path, struct stat* buf)
       *
       * @return st_mode (file type and mode) or 0 if an error occurs.
       */
      static int stat(UnixPath path) {
!         NativeBuffer buffer = copyToNativeBuffer(path);
!         try {
!             return stat1(buffer.address());
!         } finally {
!             buffer.release();
          }
      }
      private static native int stat1(long pathAddress);
  
  
      /**
       * lstat(const char* path, struct stat* buf)
       */
      static void lstat(UnixPath path, UnixFileAttributes attrs) throws UnixException {
!         NativeBuffer buffer = copyToNativeBuffer(path);
!         try {
!             lstat0(buffer.address(), attrs);
!         } finally {
!             buffer.release();
          }
      }
      private static native void lstat0(long pathAddress, UnixFileAttributes attrs)
          throws UnixException;
  
      /**
       * fstat(int filedes, struct stat* buf)
       */
!     static native void fstat(int fd, UnixFileAttributes attrs) throws UnixException;
  
      /**
       * fstatat(int filedes,const char* path,  struct stat* buf, int flag)
       */
      static void fstatat(int dfd, byte[] path, int flag, UnixFileAttributes attrs)
          throws UnixException
      {
!         NativeBuffer buffer = NativeBuffers.asNativeBuffer(path);
!         try {
!             fstatat0(dfd, buffer.address(), flag, attrs);
!         } finally {
!             buffer.release();
          }
      }
      private static native void fstatat0(int dfd, long pathAddress, int flag,
          UnixFileAttributes attrs) throws UnixException;
  
      /**
       * chown(const char* path, uid_t owner, gid_t group)
       */
      static void chown(UnixPath path, int uid, int gid) throws UnixException {
!         NativeBuffer buffer = copyToNativeBuffer(path);
!         try {
!             chown0(buffer.address(), uid, gid);
!         } finally {
!             buffer.release();
          }
      }
      private static native void chown0(long pathAddress, int uid, int gid)
          throws UnixException;
  
      /**
       * lchown(const char* path, uid_t owner, gid_t group)
       */
      static void lchown(UnixPath path, int uid, int gid) throws UnixException {
!         NativeBuffer buffer = copyToNativeBuffer(path);
!         try {
!             lchown0(buffer.address(), uid, gid);
!         } finally {
!             buffer.release();
          }
      }
      private static native void lchown0(long pathAddress, int uid, int gid)
          throws UnixException;
  
      /**
       * fchown(int filedes, uid_t owner, gid_t group)
       */
!     static native void fchown(int fd, int uid, int gid) throws UnixException;
  
      /**
       * chmod(const char* path, mode_t mode)
       */
      static void chmod(UnixPath path, int mode) throws UnixException {
!         NativeBuffer buffer = copyToNativeBuffer(path);
!         try {
!             chmod0(buffer.address(), mode);
!         } finally {
!             buffer.release();
          }
      }
      private static native void chmod0(long pathAddress, int mode)
          throws UnixException;
  
      /**
       * fchmod(int fildes, mode_t mode)
       */
!     static native void fchmod(int fd, int mode) throws UnixException;
  
      /**
       * utimes(const char* path, const struct timeval times[2])
       */
      static void utimes(UnixPath path, long times0, long times1)
          throws UnixException
      {
!         NativeBuffer buffer = copyToNativeBuffer(path);
!         try {
!             utimes0(buffer.address(), times0, times1);
!         } finally {
!             buffer.release();
          }
      }
      private static native void utimes0(long pathAddress, long times0, long times1)
          throws UnixException;
  
      /**
       * futimes(int fildes, const struct timeval times[2])
       */
!     static native void futimes(int fd, long times0, long times1) throws UnixException;
  
      /**
       * futimens(int fildes, const struct timespec times[2])
       */
!     static native void futimens(int fd, long times0, long times1) throws UnixException;
  
      /**
       * lutimes(const char* path, const struct timeval times[2])
       */
      static void lutimes(UnixPath path, long times0, long times1)
          throws UnixException
      {
!         NativeBuffer buffer = copyToNativeBuffer(path);
!         try {
!             lutimes0(buffer.address(), times0, times1);
!         } finally {
!             buffer.release();
          }
      }
      private static native void lutimes0(long pathAddress, long times0, long times1)
          throws UnixException;
  
      /**
       * DIR *opendir(const char* dirname)
       */
      static long opendir(UnixPath path) throws UnixException {
!         NativeBuffer buffer = copyToNativeBuffer(path);
!         try {
!             return opendir0(buffer.address());
!         } finally {
!             buffer.release();
          }
      }
      private static native long opendir0(long pathAddress) throws UnixException;
  
      /**
--- 307,205 ---
       * stat(const char* path, struct stat* buf)
       *
       * @return st_mode (file type and mode) or 0 if an error occurs.
       */
      static int stat(UnixPath path) {
!         try (NativeBuffer buffer = copyToNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 return Blocker.managedBlock(() -> stat1(buffer.address()));
!             } else {
!                 return stat1(buffer.address());
+             }
          }
      }
      private static native int stat1(long pathAddress);
  
  
      /**
       * lstat(const char* path, struct stat* buf)
       */
      static void lstat(UnixPath path, UnixFileAttributes attrs) throws UnixException {
!         try (NativeBuffer buffer = copyToNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 Blocker.managedBlock(() -> lstat0(buffer.address(), attrs));
!             } else {
!                 lstat0(buffer.address(), attrs);
+             }
          }
      }
      private static native void lstat0(long pathAddress, UnixFileAttributes attrs)
          throws UnixException;
  
      /**
       * fstat(int filedes, struct stat* buf)
       */
!     static void fstat(int fd, UnixFileAttributes attrs) throws UnixException {
+         if (Thread.currentThread().isVirtual()) {
+             Blocker.managedBlock(() -> fstat0(fd, attrs));
+         } else {
+             fstat0(fd, attrs);
+         }
+     }
+     private static native void fstat0(int fd, UnixFileAttributes attrs)
+         throws UnixException;
  
      /**
       * fstatat(int filedes,const char* path,  struct stat* buf, int flag)
       */
      static void fstatat(int dfd, byte[] path, int flag, UnixFileAttributes attrs)
          throws UnixException
      {
!         try (NativeBuffer buffer = NativeBuffers.asNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 Blocker.managedBlock(() -> fstatat0(dfd, buffer.address(), flag, attrs));
!             } else {
!                 fstatat0(dfd, buffer.address(), flag, attrs);
+             }
          }
      }
      private static native void fstatat0(int dfd, long pathAddress, int flag,
          UnixFileAttributes attrs) throws UnixException;
  
      /**
       * chown(const char* path, uid_t owner, gid_t group)
       */
      static void chown(UnixPath path, int uid, int gid) throws UnixException {
!         try (NativeBuffer buffer = copyToNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 Blocker.managedBlock(() -> chown0(buffer.address(), uid, gid));
!             } else {
!                 chown0(buffer.address(), uid, gid);
+             }
          }
      }
      private static native void chown0(long pathAddress, int uid, int gid)
          throws UnixException;
  
      /**
       * lchown(const char* path, uid_t owner, gid_t group)
       */
      static void lchown(UnixPath path, int uid, int gid) throws UnixException {
!         try (NativeBuffer buffer = copyToNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 Blocker.managedBlock(() -> lchown0(buffer.address(), uid, gid));
!             } else {
!                 lchown0(buffer.address(), uid, gid);
+             }
          }
      }
      private static native void lchown0(long pathAddress, int uid, int gid)
          throws UnixException;
  
      /**
       * fchown(int filedes, uid_t owner, gid_t group)
       */
!     static void fchown(int fd, int uid, int gid) throws UnixException {
+         if (Thread.currentThread().isVirtual()) {
+             Blocker.managedBlock(() -> fchown0(fd, uid, gid));
+         } else {
+             fchown0(fd, uid, gid);
+         }
+     }
+     static native void fchown0(int fd, int uid, int gid) throws UnixException;
  
      /**
       * chmod(const char* path, mode_t mode)
       */
      static void chmod(UnixPath path, int mode) throws UnixException {
!         try (NativeBuffer buffer = copyToNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 Blocker.managedBlock(() -> chmod0(buffer.address(), mode));
!             } else {
!                 chmod0(buffer.address(), mode);
+             }
          }
      }
      private static native void chmod0(long pathAddress, int mode)
          throws UnixException;
  
      /**
       * fchmod(int fildes, mode_t mode)
       */
!     static void fchmod(int fd, int mode) throws UnixException {
+         if (Thread.currentThread().isVirtual()) {
+             Blocker.managedBlock(() -> fchmod0(fd, mode));
+         } else {
+             fchmod0(fd, mode);
+         }
+     }
+     private static native void fchmod0(int fd, int mode) throws UnixException;
  
      /**
       * utimes(const char* path, const struct timeval times[2])
       */
      static void utimes(UnixPath path, long times0, long times1)
          throws UnixException
      {
!         try (NativeBuffer buffer = copyToNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 Blocker.managedBlock(() -> utimes0(buffer.address(), times0, times1));
!             } else {
!                 utimes0(buffer.address(), times0, times1);
+             }
          }
      }
      private static native void utimes0(long pathAddress, long times0, long times1)
          throws UnixException;
  
      /**
       * futimes(int fildes, const struct timeval times[2])
       */
!     static void futimes(int fd, long times0, long times1) throws UnixException {
+         if (Thread.currentThread().isVirtual()) {
+             Blocker.managedBlock(() -> futimes0(fd, times0, times1));
+         } else {
+             futimes0(fd, times0, times1);
+         }
+     }
+     private static native void futimes0(int fd, long times0, long times1)
+         throws UnixException;
  
      /**
       * futimens(int fildes, const struct timespec times[2])
       */
!     static void futimens(int fd, long times0, long times1) throws UnixException {
+         if (Thread.currentThread().isVirtual()) {
+             Blocker.managedBlock(() -> futimens0(fd, times0, times1));
+         } else {
+             futimens0(fd, times0, times1);
+         }
+     }
+     private static native void futimens0(int fd, long times0, long times1)
+         throws UnixException;
  
      /**
       * lutimes(const char* path, const struct timeval times[2])
       */
      static void lutimes(UnixPath path, long times0, long times1)
          throws UnixException
      {
!         try (NativeBuffer buffer = copyToNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 Blocker.managedBlock(() -> lutimes0(buffer.address(), times0, times1));
!             } else {
!                 lutimes0(buffer.address(), times0, times1);
+             }
          }
      }
      private static native void lutimes0(long pathAddress, long times0, long times1)
          throws UnixException;
  
      /**
       * DIR *opendir(const char* dirname)
       */
      static long opendir(UnixPath path) throws UnixException {
!         try (NativeBuffer buffer = copyToNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 return Blocker.managedBlock(() -> opendir0(buffer.address()));
!             } else {
!                 return opendir0(buffer.address());
+             }
          }
      }
      private static native long opendir0(long pathAddress) throws UnixException;
  
      /**

*** 455,51 ***
      /**
       * struct dirent* readdir(DIR *dirp)
       *
       * @return  dirent->d_name
       */
!     static native byte[] readdir(long dir) throws UnixException;
  
      /**
       * size_t read(int fildes, void* buf, size_t nbyte)
       */
!     static native int read(int fildes, long buf, int nbyte) throws UnixException;
  
      /**
       * size_t writeint fildes, void* buf, size_t nbyte)
       */
!     static native int write(int fildes, long buf, int nbyte) throws UnixException;
  
      /**
       * access(const char* path, int amode);
       */
      static void access(UnixPath path, int amode) throws UnixException {
!         NativeBuffer buffer = copyToNativeBuffer(path);
!         try {
!             access0(buffer.address(), amode);
!         } finally {
!             buffer.release();
          }
      }
      private static native void access0(long pathAddress, int amode) throws UnixException;
  
      /**
       * access(constant char* path, F_OK)
       *
       * @return true if the file exists, false otherwise
       */
      static boolean exists(UnixPath path) {
!         NativeBuffer buffer = copyToNativeBuffer(path);
!         try {
!             return exists0(buffer.address());
!         } finally {
!             buffer.release();
          }
      }
      private static native boolean exists0(long pathAddress);
  
- 
      /**
       * struct passwd *getpwuid(uid_t uid);
       *
       * @return  passwd->pw_name
       */
--- 522,73 ---
      /**
       * struct dirent* readdir(DIR *dirp)
       *
       * @return  dirent->d_name
       */
!     static byte[] readdir(long dir) throws UnixException {
+         if (Thread.currentThread().isVirtual()) {
+             return Blocker.managedBlock(() -> readdir0(dir));
+         } else {
+             return readdir0(dir);
+         }
+     }
+     static native byte[] readdir0(long dir) throws UnixException;
  
      /**
       * size_t read(int fildes, void* buf, size_t nbyte)
       */
!     static int read(int fildes, long buf, int nbyte) throws UnixException {
+         if (Thread.currentThread().isVirtual()) {
+             return Blocker.managedBlock(() -> read0(fildes, buf, nbyte));
+         } else {
+             return read0(fildes, buf, nbyte);
+         }
+     }
+     private static native int read0(int fildes, long buf, int nbyte) throws UnixException;
  
      /**
       * size_t writeint fildes, void* buf, size_t nbyte)
       */
!     static int write(int fildes, long buf, int nbyte) throws UnixException {
+         if (Thread.currentThread().isVirtual()) {
+             return Blocker.managedBlock(() -> write0(fildes, buf, nbyte));
+         } else {
+             return write0(fildes, buf, nbyte);
+         }
+     }
+     private static native int write0(int fildes, long buf, int nbyte) throws UnixException;
  
      /**
       * access(const char* path, int amode);
       */
      static void access(UnixPath path, int amode) throws UnixException {
!         try (NativeBuffer buffer = copyToNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 Blocker.managedBlock(() -> access0(buffer.address(), amode));
!             } else {
!                 access0(buffer.address(), amode);
+             }
          }
      }
      private static native void access0(long pathAddress, int amode) throws UnixException;
  
      /**
       * access(constant char* path, F_OK)
       *
       * @return true if the file exists, false otherwise
       */
      static boolean exists(UnixPath path) {
!         try (NativeBuffer buffer = copyToNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 return Blocker.managedBlock(() -> exists0(buffer.address()));
!             } else {
!                 return exists0(buffer.address());
+             }
          }
      }
      private static native boolean exists0(long pathAddress);
  
      /**
       * struct passwd *getpwuid(uid_t uid);
       *
       * @return  passwd->pw_name
       */

*** 516,45 ***
       * struct passwd *getpwnam(const char *name);
       *
       * @return  passwd->pw_uid
       */
      static int getpwnam(String name) throws UnixException {
!         NativeBuffer buffer = NativeBuffers.asNativeBuffer(Util.toBytes(name));
!         try {
!             return getpwnam0(buffer.address());
!         } finally {
!             buffer.release();
          }
      }
      private static native int getpwnam0(long nameAddress) throws UnixException;
  
      /**
       * struct group *getgrnam(const char *name);
       *
       * @return  group->gr_name
       */
      static int getgrnam(String name) throws UnixException {
!         NativeBuffer buffer = NativeBuffers.asNativeBuffer(Util.toBytes(name));
!         try {
!             return getgrnam0(buffer.address());
!         } finally {
!             buffer.release();
          }
      }
      private static native int getgrnam0(long nameAddress) throws UnixException;
  
      /**
       * statvfs(const char* path, struct statvfs *buf)
       */
      static void statvfs(UnixPath path, UnixFileStoreAttributes attrs)
          throws UnixException
      {
!         NativeBuffer buffer = copyToNativeBuffer(path);
!         try {
!             statvfs0(buffer.address(), attrs);
!         } finally {
!             buffer.release();
          }
      }
      private static native void statvfs0(long pathAddress, UnixFileStoreAttributes attrs)
          throws UnixException;
  
--- 605,48 ---
       * struct passwd *getpwnam(const char *name);
       *
       * @return  passwd->pw_uid
       */
      static int getpwnam(String name) throws UnixException {
!         try (NativeBuffer buffer = NativeBuffers.asNativeBuffer(Util.toBytes(name))) {
!             if (Thread.currentThread().isVirtual()) {
!                 return Blocker.managedBlock(() -> getpwnam0(buffer.address()));
!             } else {
!                 return getpwnam0(buffer.address());
+             }
          }
      }
      private static native int getpwnam0(long nameAddress) throws UnixException;
  
      /**
       * struct group *getgrnam(const char *name);
       *
       * @return  group->gr_name
       */
      static int getgrnam(String name) throws UnixException {
!         try (NativeBuffer buffer = NativeBuffers.asNativeBuffer(Util.toBytes(name))) {
!             if (Thread.currentThread().isVirtual()) {
!                 return Blocker.managedBlock(() -> getgrnam0(buffer.address()));
!             } else {
!                 return getgrnam0(buffer.address());
+             }
          }
      }
      private static native int getgrnam0(long nameAddress) throws UnixException;
  
      /**
       * statvfs(const char* path, struct statvfs *buf)
       */
      static void statvfs(UnixPath path, UnixFileStoreAttributes attrs)
          throws UnixException
      {
!         try (NativeBuffer buffer = copyToNativeBuffer(path)) {
!             if (Thread.currentThread().isVirtual()) {
!                 Blocker.managedBlock(() -> statvfs0(buffer.address(), attrs));
!             } else {
!                 statvfs0(buffer.address(), attrs);
+             }
          }
      }
      private static native void statvfs0(long pathAddress, UnixFileStoreAttributes attrs)
          throws UnixException;
  

*** 564,29 ***
      static native byte[] strerror(int errnum);
  
      /**
       * ssize_t fgetxattr(int filedes, const char *name, void *value, size_t size);
       */
!     static int fgetxattr(int filedes, byte[] name, long valueAddress,
!                          int valueLen) throws UnixException
      {
          try (NativeBuffer buffer = NativeBuffers.asNativeBuffer(name)) {
!             return fgetxattr0(filedes, buffer.address(), valueAddress, valueLen);
          }
      }
  
      private static native int fgetxattr0(int filedes, long nameAddress,
          long valueAddress, int valueLen) throws UnixException;
  
      /**
       *  fsetxattr(int filedes, const char *name, const void *value, size_t size, int flags);
       */
!     static void fsetxattr(int filedes, byte[] name, long valueAddress,
!                           int valueLen) throws UnixException
      {
          try (NativeBuffer buffer = NativeBuffers.asNativeBuffer(name)) {
!             fsetxattr0(filedes, buffer.address(), valueAddress, valueLen);
          }
      }
  
      private static native void fsetxattr0(int filedes, long nameAddress,
          long valueAddress, int valueLen) throws UnixException;
--- 656,39 ---
      static native byte[] strerror(int errnum);
  
      /**
       * ssize_t fgetxattr(int filedes, const char *name, void *value, size_t size);
       */
!     static int fgetxattr(int filedes, byte[] name, long valueAddress, int valueLen)
!         throws UnixException
      {
          try (NativeBuffer buffer = NativeBuffers.asNativeBuffer(name)) {
!             if (Thread.currentThread().isVirtual()) {
+                 return Blocker.managedBlock(() ->
+                         fgetxattr0(filedes, buffer.address(), valueAddress, valueLen));
+             } else {
+                 return fgetxattr0(filedes, buffer.address(), valueAddress, valueLen);
+             }
          }
      }
  
      private static native int fgetxattr0(int filedes, long nameAddress,
          long valueAddress, int valueLen) throws UnixException;
  
      /**
       *  fsetxattr(int filedes, const char *name, const void *value, size_t size, int flags);
       */
!     static void fsetxattr(int filedes, byte[] name, long valueAddress, int valueLen)
!         throws UnixException
      {
          try (NativeBuffer buffer = NativeBuffers.asNativeBuffer(name)) {
!             if (Thread.currentThread().isVirtual()) {
+                 Blocker.managedBlock(() ->
+                         fsetxattr0(filedes, buffer.address(), valueAddress, valueLen));
+             } else {
+                 fsetxattr0(filedes, buffer.address(), valueAddress, valueLen);
+             }
          }
      }
  
      private static native void fsetxattr0(int filedes, long nameAddress,
          long valueAddress, int valueLen) throws UnixException;

*** 594,11 ***
      /**
       * fremovexattr(int filedes, const char *name);
       */
      static void fremovexattr(int filedes, byte[] name) throws UnixException {
          try (NativeBuffer buffer = NativeBuffers.asNativeBuffer(name)) {
!             fremovexattr0(filedes, buffer.address());
          }
      }
  
      private static native void fremovexattr0(int filedes, long nameAddress)
          throws UnixException;
--- 696,15 ---
      /**
       * fremovexattr(int filedes, const char *name);
       */
      static void fremovexattr(int filedes, byte[] name) throws UnixException {
          try (NativeBuffer buffer = NativeBuffers.asNativeBuffer(name)) {
!             if (Thread.currentThread().isVirtual()) {
+                 Blocker.managedBlock(() -> fremovexattr0(filedes, buffer.address()));
+             } else {
+                 fremovexattr0(filedes, buffer.address());
+             }
          }
      }
  
      private static native void fremovexattr0(int filedes, long nameAddress)
          throws UnixException;
< prev index next >