< prev index next >

src/java.base/linux/classes/sun/nio/fs/LinuxNativeDispatcher.java

Print this page
rev 55657 : 8227587: Add internal privileged System.loadLibrary
Reviewed-by: rriggs
   1 /*
   2  * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   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  * Linux specific system calls.
  33  */
  34 
  35 class LinuxNativeDispatcher extends UnixNativeDispatcher {
  36     private LinuxNativeDispatcher() { }
  37 
  38    /**
  39     * FILE *setmntent(const char *filename, const char *type);
  40     */
  41     static long setmntent(byte[] filename, byte[] type) throws UnixException {
  42         NativeBuffer pathBuffer = NativeBuffers.asNativeBuffer(filename);
  43         NativeBuffer typeBuffer = NativeBuffers.asNativeBuffer(type);
  44         try {
  45             return setmntent0(pathBuffer.address(), typeBuffer.address());
  46         } finally {
  47             typeBuffer.release();
  48             pathBuffer.release();
  49         }
  50     }


 104         try {
 105             fremovexattr0(filedes, buffer.address());
 106         } finally {
 107             buffer.release();
 108         }
 109     }
 110 
 111     private static native void fremovexattr0(int filedes, long nameAddress)
 112         throws UnixException;
 113 
 114     /**
 115      * size_t flistxattr(int filedes, const char *list, size_t size)
 116      */
 117     static native int flistxattr(int filedes, long listAddress, int size)
 118         throws UnixException;
 119 
 120     // initialize
 121     private static native void init();
 122 
 123     static {
 124         AccessController.doPrivileged(new PrivilegedAction<>() {
 125             public Void run() {
 126                 System.loadLibrary("nio");
 127                 return null;
 128         }});
 129         init();
 130     }
 131 }
   1 /*
   2  * Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   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  * Linux specific system calls.
  30  */
  31 
  32 class LinuxNativeDispatcher extends UnixNativeDispatcher {
  33     private LinuxNativeDispatcher() { }
  34 
  35    /**
  36     * FILE *setmntent(const char *filename, const char *type);
  37     */
  38     static long setmntent(byte[] filename, byte[] type) throws UnixException {
  39         NativeBuffer pathBuffer = NativeBuffers.asNativeBuffer(filename);
  40         NativeBuffer typeBuffer = NativeBuffers.asNativeBuffer(type);
  41         try {
  42             return setmntent0(pathBuffer.address(), typeBuffer.address());
  43         } finally {
  44             typeBuffer.release();
  45             pathBuffer.release();
  46         }
  47     }


 101         try {
 102             fremovexattr0(filedes, buffer.address());
 103         } finally {
 104             buffer.release();
 105         }
 106     }
 107 
 108     private static native void fremovexattr0(int filedes, long nameAddress)
 109         throws UnixException;
 110 
 111     /**
 112      * size_t flistxattr(int filedes, const char *list, size_t size)
 113      */
 114     static native int flistxattr(int filedes, long listAddress, int size)
 115         throws UnixException;
 116 
 117     // initialize
 118     private static native void init();
 119 
 120     static {
 121         jdk.internal.access.SharedSecrets.getJavaLangAccess().loadLibrary("nio");




 122         init();
 123     }
 124 }
< prev index next >