blob: e42f9a1c84f92389c86eab0f7b295cc59f8d400a [file] [log] [blame]
John Reck9f5599b2017-08-07 11:18:40 -07001/*
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>
Ryan Prichard92b1ebe2018-07-19 20:32:19 -070032#include <sys/cdefs.h>
John Reck9f5599b2017-08-07 11:18:40 -070033
34/******************************************************************
35 *
36 * IMPORTANT NOTICE:
37 *
38 * This file is part of Android's set of stable system headers
39 * exposed by the Android NDK (Native Development Kit).
40 *
41 * Third-party source AND binary code relies on the definitions
42 * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES.
43 *
44 * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES)
45 * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS
46 * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY
47 * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES
48 */
49
50/**
51 * Structures and functions for a shared memory buffer that can be shared across process.
52 */
53
54#ifdef __cplusplus
55extern "C" {
56#endif
57
Ryan Prichard92b1ebe2018-07-19 20:32:19 -070058#if __ANDROID_API__ >= 27
59
John Reck9f5599b2017-08-07 11:18:40 -070060/**
61 * Returns a dup'd FD from the given Java android.os.SharedMemory object. The returned file
62 * descriptor has all the same properties & capabilities as the FD returned from
63 * ASharedMemory_create(), however the protection flags will be the same as those of the
64 * android.os.SharedMemory object.
65 *
66 * Use close() to release the shared memory region.
67 *
68 * \param env The JNIEnv* pointer
69 * \param sharedMemory The Java android.os.SharedMemory object
70 * \return file descriptor that denotes the shared memory; -1 if the shared memory object is
John Reck4c055832017-08-18 09:44:38 -070071 * already closed, if the JNIEnv or jobject is NULL, or if there are too many open file
72 * descriptors (errno=EMFILE)
John Reck9f5599b2017-08-07 11:18:40 -070073 */
Elliott Hughes9db409b2018-06-18 12:28:46 -070074int ASharedMemory_dupFromJava(JNIEnv* env, jobject sharedMemory) __INTRODUCED_IN(27);
John Reck9f5599b2017-08-07 11:18:40 -070075
Ryan Prichard92b1ebe2018-07-19 20:32:19 -070076#endif // __ANDROID_API__ >= 27
77
John Reck9f5599b2017-08-07 11:18:40 -070078#ifdef __cplusplus
79};
80#endif
81
82#endif // ANDROID_SHARED_MEMORY_JNI_H
83
84/** @} */