Path: blob/21.2-virgl/include/android_stub/cutils/native_handle.h
4547 views
/*1* Copyright (C) 2009 The Android Open Source Project2*3* Licensed under the Apache License, Version 2.0 (the "License");4* you may not use this file except in compliance with the License.5* You may obtain a copy of the License at6*7* http://www.apache.org/licenses/LICENSE-2.08*9* Unless required by applicable law or agreed to in writing, software10* distributed under the License is distributed on an "AS IS" BASIS,11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12* See the License for the specific language governing permissions and13* limitations under the License.14*/1516#ifndef NATIVE_HANDLE_H_17#define NATIVE_HANDLE_H_1819#include <stdalign.h>2021#ifdef __cplusplus22extern "C" {23#endif2425#define NATIVE_HANDLE_MAX_FDS 102426#define NATIVE_HANDLE_MAX_INTS 10242728/* Declare a char array for use with native_handle_init */29#define NATIVE_HANDLE_DECLARE_STORAGE(name, maxFds, maxInts) \30alignas(native_handle_t) char (name)[ \31sizeof(native_handle_t) + sizeof(int) * ((maxFds) + (maxInts))]3233typedef struct native_handle34{35int version; /* sizeof(native_handle_t) */36int numFds; /* number of file-descriptors at &data[0] */37int numInts; /* number of ints at &data[numFds] */38#if defined(__clang__)39#pragma clang diagnostic push40#pragma clang diagnostic ignored "-Wzero-length-array"41#endif42int data[0]; /* numFds + numInts ints */43#if defined(__clang__)44#pragma clang diagnostic pop45#endif46} native_handle_t;4748typedef const native_handle_t* buffer_handle_t;4950/*51* native_handle_close52*53* closes the file descriptors contained in this native_handle_t54*55* return 0 on success, or a negative error code on failure56*57*/58int native_handle_close(const native_handle_t* h);5960/*61* native_handle_init62*63* Initializes a native_handle_t from storage. storage must be declared with64* NATIVE_HANDLE_DECLARE_STORAGE. numFds and numInts must not respectively65* exceed maxFds and maxInts used to declare the storage.66*/67native_handle_t* native_handle_init(char* storage, int numFds, int numInts);6869/*70* native_handle_create71*72* creates a native_handle_t and initializes it. must be destroyed with73* native_handle_delete(). Note that numFds must be <= NATIVE_HANDLE_MAX_FDS,74* numInts must be <= NATIVE_HANDLE_MAX_INTS, and both must be >= 0.75*76*/77native_handle_t* native_handle_create(int numFds, int numInts);7879/*80* native_handle_clone81*82* creates a native_handle_t and initializes it from another native_handle_t.83* Must be destroyed with native_handle_delete().84*85*/86native_handle_t* native_handle_clone(const native_handle_t* handle);8788/*89* native_handle_delete90*91* frees a native_handle_t allocated with native_handle_create().92* This ONLY frees the memory allocated for the native_handle_t, but doesn't93* close the file descriptors; which can be achieved with native_handle_close().94*95* return 0 on success, or a negative error code on failure96*97*/98int native_handle_delete(native_handle_t* h);99100101#ifdef __cplusplus102}103#endif104105#endif /* NATIVE_HANDLE_H_ */106107108