blob: e3fad397ad9696d9ba065ebf208aca9f3882db27 [file] [log] [blame]
Jens Wiklander28dfdc42018-11-15 00:29:08 +01001/* 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
10struct 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 */
22void 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 */
31int 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 */
37void *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 */
44void *handle_lookup(struct handle_db *db, int handle);
45
46#endif /*__HANDLE_H*/