lib: trusty: add `handle_ref_is_attached` to use from rust am: 3ab7c616ac

Original change: https://android-review.googlesource.com/c/trusty/lk/trusty/+/3434479

Change-Id: Ia9cd324b729218bf37ac9ad5f8f70212db3ae8c5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/lib/trusty/handle.c b/lib/trusty/handle.c
index c63290e..9ce9ad6 100644
--- a/lib/trusty/handle.c
+++ b/lib/trusty/handle.c
@@ -185,6 +185,10 @@
     spin_unlock_restore(&handle->slock, state, SPIN_LOCK_FLAG_INTERRUPTS);
 }
 
+bool handle_ref_is_attached(const struct handle_ref* const ref) {
+    return list_in_list(&ref->set_node);
+}
+
 void handle_list_init(struct handle_list* hlist) {
     DEBUG_ASSERT(hlist);
 
diff --git a/lib/trusty/include/lib/trusty/handle.h b/lib/trusty/include/lib/trusty/handle.h
index 7bf61ff..5b48284 100644
--- a/lib/trusty/include/lib/trusty/handle.h
+++ b/lib/trusty/include/lib/trusty/handle.h
@@ -180,6 +180,11 @@
     return handle->cookie;
 }
 
+/**
+ * Safe to call no matter the state `ref` is in, as long as it was initialized.
+ */
+bool handle_ref_is_attached(const struct handle_ref* ref);
+
 void handle_list_init(struct handle_list* hlist);
 void handle_list_add(struct handle_list* hlist, struct handle* handle);
 void handle_list_del(struct handle_list* hlist, struct handle* handle);