1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2014, Linaro Limited
4  */
5 #ifndef __HANDLE_H
6 #define __HANDLE_H
7 
8 #include <tee_internal_api.h>
9 
10 struct handle_db {
11 	void **ptrs;
12 	size_t max_ptrs;
13 };
14 
15 #define HANDLE_DB_INITIALIZER	{ NULL, 0 }
16 
17 /*
18  * Frees all internal data structures of the database, but does not free
19  * the db pointer. The database is safe to reuse after it's destroyed, it
20  * will just be empty again.
21  */
22 void handle_db_destroy(struct handle_db *db);
23 
24 /*
25  * Allocates a new handle and assigns the supplied pointer to it,
26  * ptr must not be NULL.
27  * The function returns
28  * >= 0 on success and
29  * -1 on failure
30  */
31 int handle_get(struct handle_db *db, void *ptr);
32 
33 /*
34  * Deallocates a handle. Returns the assiciated pointer of the handle
35  * the the handle was valid or NULL if it's invalid.
36  */
37 void *handle_put(struct handle_db *db, int handle);
38 
39 /*
40  * Returns the assiciated pointer of the handle if the handle is a valid
41  * handle.
42  * Returns NULL on failure.
43  */
44 void *handle_lookup(struct handle_db *db, int handle);
45 
46 #endif /*__HANDLE_H*/
47