< prev index next >

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

Print this page
rev 55686 : 8227587: Add internal privileged System.loadLibrary
Reviewed-by: rriggs, mchung


   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.nio.fs;
  27 
  28 import java.security.AccessController;
  29 import java.security.PrivilegedAction;
  30 
  31 /**
  32  * Unix system and library calls.
  33  */
  34 
  35 class UnixNativeDispatcher {
  36     protected UnixNativeDispatcher() { }
  37 
  38     // returns a NativeBuffer containing the given path
  39     private static NativeBuffer copyToNativeBuffer(UnixPath path) {
  40         byte[] cstr = path.getByteArrayForSysCalls();
  41         int size = cstr.length + 1;
  42         NativeBuffer buffer = NativeBuffers.getNativeBufferFromCache(size);
  43         if (buffer == null) {
  44             buffer = NativeBuffers.allocNativeBuffer(size);
  45         } else {
  46             // buffer already contains the path
  47             if (buffer.owner() == path)
  48                 return buffer;
  49         }
  50         NativeBuffers.copyCStringToNativeBuffer(cstr, buffer);


 613     static boolean futimesSupported() {
 614         return (capabilities & SUPPORTS_FUTIMES) != 0;
 615     }
 616 
 617     /**
 618      * Supports lutimes
 619      */
 620     static boolean lutimesSupported() {
 621         return (capabilities & SUPPORTS_LUTIMES) != 0;
 622     }
 623 
 624     /**
 625      * Supports file birth (creation) time attribute
 626      */
 627     static boolean birthtimeSupported() {
 628         return (capabilities & SUPPORTS_BIRTHTIME) != 0;
 629     }
 630 
 631     private static native int init();
 632     static {
 633         AccessController.doPrivileged(new PrivilegedAction<>() {
 634             public Void run() {
 635                 System.loadLibrary("nio");
 636                 return null;
 637         }});
 638         capabilities = init();
 639     }
 640 }


   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.nio.fs;
  27 



  28 /**
  29  * Unix system and library calls.
  30  */
  31 
  32 class UnixNativeDispatcher {
  33     protected UnixNativeDispatcher() { }
  34 
  35     // returns a NativeBuffer containing the given path
  36     private static NativeBuffer copyToNativeBuffer(UnixPath path) {
  37         byte[] cstr = path.getByteArrayForSysCalls();
  38         int size = cstr.length + 1;
  39         NativeBuffer buffer = NativeBuffers.getNativeBufferFromCache(size);
  40         if (buffer == null) {
  41             buffer = NativeBuffers.allocNativeBuffer(size);
  42         } else {
  43             // buffer already contains the path
  44             if (buffer.owner() == path)
  45                 return buffer;
  46         }
  47         NativeBuffers.copyCStringToNativeBuffer(cstr, buffer);


 610     static boolean futimesSupported() {
 611         return (capabilities & SUPPORTS_FUTIMES) != 0;
 612     }
 613 
 614     /**
 615      * Supports lutimes
 616      */
 617     static boolean lutimesSupported() {
 618         return (capabilities & SUPPORTS_LUTIMES) != 0;
 619     }
 620 
 621     /**
 622      * Supports file birth (creation) time attribute
 623      */
 624     static boolean birthtimeSupported() {
 625         return (capabilities & SUPPORTS_BIRTHTIME) != 0;
 626     }
 627 
 628     private static native int init();
 629     static {
 630         jdk.internal.loader.BootLoader.loadLibrary("nio");




 631         capabilities = init();
 632     }
 633 }
< prev index next >