• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.ravenwood.common;
17 
18 import java.io.FileDescriptor;
19 
20 /**
21  * Class to host all the JNI methods used in ravenwood runtime.
22  */
23 public class RavenwoodRuntimeNative {
RavenwoodRuntimeNative()24     private RavenwoodRuntimeNative() {
25     }
26 
27     static {
RavenwoodCommonUtils.ensureOnRavenwood()28         RavenwoodCommonUtils.ensureOnRavenwood();
RavenwoodCommonUtils.loadRavenwoodNativeRuntime()29         RavenwoodCommonUtils.loadRavenwoodNativeRuntime();
30     }
31 
applyFreeFunction(long freeFunction, long nativePtr)32     public static native void applyFreeFunction(long freeFunction, long nativePtr);
33 
nLseek(int fd, long offset, int whence)34     public static native long nLseek(int fd, long offset, int whence);
35 
nPipe2(int flags)36     public static native int[] nPipe2(int flags);
37 
nDup(int oldfd)38     public static native int nDup(int oldfd);
39 
nFcntlInt(int fd, int cmd, int arg)40     public static native int nFcntlInt(int fd, int cmd, int arg);
41 
lseek(FileDescriptor fd, long offset, int whence)42     public static long lseek(FileDescriptor fd, long offset, int whence) {
43         return nLseek(JvmWorkaround.getInstance().getFdInt(fd), offset, whence);
44     }
45 
pipe2(int flags)46     public static FileDescriptor[] pipe2(int flags) {
47         var fds = nPipe2(flags);
48         var ret = new FileDescriptor[] {
49                 new FileDescriptor(),
50                 new FileDescriptor(),
51         };
52         JvmWorkaround.getInstance().setFdInt(ret[0], fds[0]);
53         JvmWorkaround.getInstance().setFdInt(ret[1], fds[1]);
54 
55         return ret;
56     }
57 
dup(FileDescriptor fd)58     public static FileDescriptor dup(FileDescriptor fd) {
59         var fdInt = nDup(JvmWorkaround.getInstance().getFdInt(fd));
60 
61         var retFd = new java.io.FileDescriptor();
62         JvmWorkaround.getInstance().setFdInt(retFd, fdInt);
63         return retFd;
64     }
65 
fcntlInt(FileDescriptor fd, int cmd, int arg)66     public static int fcntlInt(FileDescriptor fd, int cmd, int arg) {
67         var fdInt = JvmWorkaround.getInstance().getFdInt(fd);
68 
69         return nFcntlInt(fdInt, cmd, arg);
70     }
71 }
72