2 * Copyright (c) 2014, STMicroelectronics International N.V.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
28 #include <tee/tee_obj.h>
31 #include <tee_api_defines.h>
32 #include <mm/tee_mmu.h>
33 #include <tee/tee_fs.h>
34 #include <tee/tee_pobj.h>
36 #include <tee/tee_svc_storage.h>
37 #include <tee/tee_svc_cryp.h>
39 void tee_obj_add(struct user_ta_ctx *utc, struct tee_obj *o)
41 TAILQ_INSERT_TAIL(&utc->objects, o, link);
44 TEE_Result tee_obj_get(struct user_ta_ctx *utc, uint32_t obj_id,
49 TAILQ_FOREACH(o, &utc->objects, link) {
50 if (obj_id == (vaddr_t)o) {
55 return TEE_ERROR_BAD_PARAMETERS;
58 void tee_obj_close(struct user_ta_ctx *utc, struct tee_obj *o)
60 TAILQ_REMOVE(&utc->objects, o, link);
62 if ((o->info.handleFlags & TEE_HANDLE_FLAG_PERSISTENT)) {
63 o->pobj->fops->close(&o->fh);
64 tee_pobj_release(o->pobj);
70 void tee_obj_close_all(struct user_ta_ctx *utc)
72 struct tee_obj_head *objects = &utc->objects;
74 while (!TAILQ_EMPTY(objects))
75 tee_obj_close(utc, TAILQ_FIRST(objects));
78 TEE_Result tee_obj_verify(struct tee_ta_session *sess, struct tee_obj *o)
81 const struct tee_file_operations *fops = o->pobj->fops;
82 struct tee_file_handle *fh = NULL;
85 return TEE_ERROR_STORAGE_NOT_AVAILABLE;
87 res = fops->open(o->pobj, &fh);
88 if (res == TEE_ERROR_CORRUPT_OBJECT) {
89 EMSG("Object corrupt\n");
90 fops->remove(o->pobj);
91 tee_obj_close(to_user_ta_ctx(sess->ctx), o);
98 struct tee_obj *tee_obj_alloc(void)
100 return calloc(1, sizeof(struct tee_obj));
103 void tee_obj_free(struct tee_obj *o)
106 tee_obj_attr_free(o);