1 /* 2 * Copyright (C) 2017 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 17 /** 18 * @addtogroup Memory 19 * @{ 20 */ 21 22 /** 23 * @file sharedmem_jni.h 24 */ 25 26 #ifndef ANDROID_SHARED_MEMORY_JNI_H 27 #define ANDROID_SHARED_MEMORY_JNI_H 28 29 #include <jni.h> 30 #include <android/sharedmem.h> 31 #include <stddef.h> 32 33 /****************************************************************** 34 * 35 * IMPORTANT NOTICE: 36 * 37 * This file is part of Android's set of stable system headers 38 * exposed by the Android NDK (Native Development Kit). 39 * 40 * Third-party source AND binary code relies on the definitions 41 * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES. 42 * 43 * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES) 44 * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS 45 * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY 46 * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES 47 */ 48 49 /** 50 * Structures and functions for a shared memory buffer that can be shared across process. 51 */ 52 53 #ifdef __cplusplus 54 extern "C" { 55 #endif 56 57 #if __ANDROID_API__ >= __ANDROID_API_O_MR1__ 58 59 /** 60 * Returns a dup'd FD from the given Java android.os.SharedMemory object. The returned file 61 * descriptor has all the same properties & capabilities as the FD returned from 62 * ASharedMemory_create(), however the protection flags will be the same as those of the 63 * android.os.SharedMemory object. 64 * 65 * Use close() to release the shared memory region. 66 * 67 * \param env The JNIEnv* pointer 68 * \param sharedMemory The Java android.os.SharedMemory object 69 * \return file descriptor that denotes the shared memory; -1 if the shared memory object is 70 * already closed, if the JNIEnv or jobject is NULL, or if there are too many open file 71 * descriptors (errno=EMFILE) 72 */ 73 int ASharedMemory_dupFromJava(JNIEnv* env, jobject sharedMemory); 74 75 #endif 76 77 #ifdef __cplusplus 78 }; 79 #endif 80 81 #endif // ANDROID_SHARED_MEMORY_JNI_H 82 83 /** @} */ 84