summaryrefslogtreecommitdiff
path: root/include/android/system/core/include/cutils/native_handle.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/android/system/core/include/cutils/native_handle.h')
-rw-r--r--include/android/system/core/include/cutils/native_handle.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/include/android/system/core/include/cutils/native_handle.h b/include/android/system/core/include/cutils/native_handle.h
index edd7888f..dbd37672 100644
--- a/include/android/system/core/include/cutils/native_handle.h
+++ b/include/android/system/core/include/cutils/native_handle.h
@@ -18,18 +18,37 @@
#ifndef NATIVE_HANDLE_H_
#define NATIVE_HANDLE_H_
+#include <stdalign.h>
+
#ifdef __cplusplus
extern "C" {
#endif
+#define NATIVE_HANDLE_MAX_FDS 1024
+#define NATIVE_HANDLE_MAX_INTS 1024
+
+/* Declare a char array for use with native_handle_init */
+#define NATIVE_HANDLE_DECLARE_STORAGE(name, maxFds, maxInts) \
+ alignas(native_handle_t) char (name)[ \
+ sizeof(native_handle_t) + sizeof(int) * ((maxFds) + (maxInts))]
+
typedef struct native_handle
{
int version; /* sizeof(native_handle_t) */
int numFds; /* number of file-descriptors at &data[0] */
int numInts; /* number of ints at &data[numFds] */
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wzero-length-array"
+#endif
int data[0]; /* numFds + numInts ints */
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
} native_handle_t;
+typedef const native_handle_t* buffer_handle_t;
+
/*
* native_handle_close
*
@@ -40,6 +59,14 @@ typedef struct native_handle
*/
int native_handle_close(const native_handle_t* h);
+/*
+ * native_handle_init
+ *
+ * Initializes a native_handle_t from storage. storage must be declared with
+ * NATIVE_HANDLE_DECLARE_STORAGE. numFds and numInts must not respectively
+ * exceed maxFds and maxInts used to declare the storage.
+ */
+native_handle_t* native_handle_init(char* storage, int numFds, int numInts);
/*
* native_handle_create
@@ -51,6 +78,15 @@ int native_handle_close(const native_handle_t* h);
native_handle_t* native_handle_create(int numFds, int numInts);
/*
+ * native_handle_clone
+ *
+ * creates a native_handle_t and initializes it from another native_handle_t.
+ * Must be destroyed with native_handle_delete().
+ *
+ */
+native_handle_t* native_handle_clone(const native_handle_t* handle);
+
+/*
* native_handle_delete
*
* frees a native_handle_t allocated with native_handle_create().