Lines Matching refs:s

178 static void dec_session_ref_count(struct tee_ta_session *s)  in dec_session_ref_count()  argument
180 assert(s->ref_count > 0); in dec_session_ref_count()
181 s->ref_count--; in dec_session_ref_count()
182 if (s->ref_count == 1) in dec_session_ref_count()
183 condvar_signal(&s->refc_cv); in dec_session_ref_count()
186 void tee_ta_put_session(struct tee_ta_session *s) in tee_ta_put_session() argument
190 if (s->lock_thread == thread_get_id()) { in tee_ta_put_session()
191 s->lock_thread = THREAD_ID_INVALID; in tee_ta_put_session()
192 condvar_signal(&s->lock_cv); in tee_ta_put_session()
194 dec_session_ref_count(s); in tee_ta_put_session()
202 struct tee_ta_session *s = NULL; in tee_ta_find_session_nolock() local
205 TAILQ_FOREACH(s, open_sessions, link) { in tee_ta_find_session_nolock()
206 if (s->id == id) { in tee_ta_find_session_nolock()
207 found = s; in tee_ta_find_session_nolock()
218 struct tee_ta_session *s = NULL; in tee_ta_find_session() local
222 s = tee_ta_find_session_nolock(id, open_sessions); in tee_ta_find_session()
226 return s; in tee_ta_find_session()
232 struct tee_ta_session *s; in tee_ta_get_session() local
237 s = tee_ta_find_session_nolock(id, open_sessions); in tee_ta_get_session()
238 if (!s) in tee_ta_get_session()
240 if (s->unlink) { in tee_ta_get_session()
241 s = NULL; in tee_ta_get_session()
244 s->ref_count++; in tee_ta_get_session()
248 assert(s->lock_thread != thread_get_id()); in tee_ta_get_session()
250 while (s->lock_thread != THREAD_ID_INVALID && !s->unlink) in tee_ta_get_session()
251 condvar_wait(&s->lock_cv, &tee_ta_mutex); in tee_ta_get_session()
253 if (s->unlink) { in tee_ta_get_session()
254 dec_session_ref_count(s); in tee_ta_get_session()
255 s = NULL; in tee_ta_get_session()
259 s->lock_thread = thread_get_id(); in tee_ta_get_session()
264 return s; in tee_ta_get_session()
267 static void tee_ta_unlink_session(struct tee_ta_session *s, in tee_ta_unlink_session() argument
272 assert(s->ref_count >= 1); in tee_ta_unlink_session()
273 assert(s->lock_thread == thread_get_id()); in tee_ta_unlink_session()
274 assert(!s->unlink); in tee_ta_unlink_session()
276 s->unlink = true; in tee_ta_unlink_session()
277 condvar_broadcast(&s->lock_cv); in tee_ta_unlink_session()
279 while (s->ref_count != 1) in tee_ta_unlink_session()
280 condvar_wait(&s->refc_cv, &tee_ta_mutex); in tee_ta_unlink_session()
282 TAILQ_REMOVE(open_sessions, s, link); in tee_ta_unlink_session()
287 static void destroy_session(struct tee_ta_session *s, in destroy_session() argument
291 if (s->ts_sess.ctx && s->ts_sess.ctx->ops->dump_ftrace) { in destroy_session()
292 ts_push_current_session(&s->ts_sess); in destroy_session()
293 s->ts_sess.fbuf = NULL; in destroy_session()
294 s->ts_sess.ctx->ops->dump_ftrace(s->ts_sess.ctx); in destroy_session()
299 tee_ta_unlink_session(s, open_sessions); in destroy_session()
301 free(s->ts_sess.sbuf); in destroy_session()
303 free(s); in destroy_session()
315 static void destroy_ta_ctx_from_session(struct tee_ta_session *s) in destroy_ta_ctx_from_session() argument
321 struct ts_ctx *ts_ctx = s->ts_sess.ctx; in destroy_ta_ctx_from_session()
341 if (sess->ts_sess.ctx == ts_ctx && sess != s) { in destroy_ta_ctx_from_session()
358 sess != s) { in destroy_ta_ctx_from_session()
373 s->ts_sess.ctx = NULL; in destroy_ta_ctx_from_session()
393 static TEE_Result check_client(struct tee_ta_session *s, const TEE_Identity *id) in check_client() argument
399 if (s->clnt_id.login == TEE_LOGIN_TRUSTED_APP) { in check_client()
406 if (memcmp(&s->clnt_id, id, sizeof(TEE_Identity)) != 0) { in check_client()
569 static TEE_Result tee_ta_init_session_with_context(struct tee_ta_session *s, in tee_ta_init_session_with_context() argument
610 s->ts_sess.ctx = &ctx->ts_ctx; in tee_ta_init_session_with_context()
611 s->ts_sess.handle_svc = s->ts_sess.ctx->ops->handle_svc; in tee_ta_init_session_with_context()
647 struct tee_ta_session *s = calloc(1, sizeof(struct tee_ta_session)); in tee_ta_init_session() local
650 if (!s) in tee_ta_init_session()
653 s->cancel_mask = true; in tee_ta_init_session()
654 condvar_init(&s->refc_cv); in tee_ta_init_session()
655 condvar_init(&s->lock_cv); in tee_ta_init_session()
656 s->lock_thread = THREAD_ID_INVALID; in tee_ta_init_session()
657 s->ref_count = 1; in tee_ta_init_session()
660 s->id = new_session_id(open_sessions); in tee_ta_init_session()
661 if (!s->id) { in tee_ta_init_session()
666 TAILQ_INSERT_TAIL(open_sessions, s, link); in tee_ta_init_session()
669 res = tee_ta_init_session_with_context(s, uuid); in tee_ta_init_session()
675 res = stmm_init_session(uuid, s); in tee_ta_init_session()
680 res = tee_ta_init_pseudo_ta_session(uuid, s); in tee_ta_init_session()
685 res = tee_ta_init_user_ta_session(uuid, s); in tee_ta_init_session()
689 *sess = s; in tee_ta_init_session()
694 TAILQ_REMOVE(open_sessions, s, link); in tee_ta_init_session()
697 free(s); in tee_ta_init_session()
710 struct tee_ta_session *s = NULL; in tee_ta_open_session() local
716 res = tee_ta_init_session(err, open_sessions, uuid, &s); in tee_ta_open_session()
722 if (!check_params(s, param)) in tee_ta_open_session()
725 ts_ctx = s->ts_sess.ctx; in tee_ta_open_session()
731 tee_ta_close_session(s, open_sessions, KERN_IDENTITY); in tee_ta_open_session()
736 *sess = s; in tee_ta_open_session()
738 s->clnt_id = *clnt_id; in tee_ta_open_session()
741 s->param = param; in tee_ta_open_session()
742 set_invoke_timeout(s, cancel_req_to); in tee_ta_open_session()
743 res = ts_ctx->ops->enter_open_session(&s->ts_sess); in tee_ta_open_session()
752 s->param = NULL; in tee_ta_open_session()
754 tee_ta_put_session(s); in tee_ta_open_session()
756 tee_ta_close_session(s, open_sessions, KERN_IDENTITY); in tee_ta_open_session()
765 *err = s->err_origin; in tee_ta_open_session()
841 bool tee_ta_session_is_cancelled(struct tee_ta_session *s, TEE_Time *curr_time) in tee_ta_session_is_cancelled() argument
845 if (s->cancel_mask) in tee_ta_session_is_cancelled()
848 if (s->cancel) in tee_ta_session_is_cancelled()
851 if (s->cancel_time.seconds == UINT32_MAX) in tee_ta_session_is_cancelled()
859 if (current_time.seconds > s->cancel_time.seconds || in tee_ta_session_is_cancelled()
860 (current_time.seconds == s->cancel_time.seconds && in tee_ta_session_is_cancelled()
861 current_time.millis >= s->cancel_time.millis)) { in tee_ta_session_is_cancelled()
871 struct ts_session *s = ts_get_current_session(); in tee_ta_gprof_sample_pc() local
877 sbuf = s->sbuf; in tee_ta_gprof_sample_pc()
883 utc = to_user_ta_ctx(s->ctx); in tee_ta_gprof_sample_pc()
897 static void gprof_update_session_utime(bool suspend, struct ts_session *s, in gprof_update_session_utime() argument
900 struct sample_buf *sbuf = s->sbuf; in gprof_update_session_utime()
924 struct ts_session *s = ts_get_current_session(); in tee_ta_update_session_utime() local
927 gprof_update_session_utime(suspend, s, now); in tee_ta_update_session_utime()
944 struct ts_session *s = ts_get_current_session_may_fail(); in ftrace_update_times() local
949 if (!s) in ftrace_update_times()
954 fbuf = s->fbuf; in ftrace_update_times()