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