@@ -102,6 +102,10 @@ CK_OBJECT_HANDLE HandleManager::addSessionObject(CK_SLOT_ID slotID, CK_SESSION_H
102102 h.object = object;
103103 handles[++handleCounter] = h;
104104 objects[object] = handleCounter;
105+
106+ DEBUG_MSG (" Added session object - handle: %lu, slot ID: %lu, session ID: %lu, private: %d, obj: %p" ,
107+ handleCounter, slotID, hSession, isPrivate, object);
108+
105109 sessionObjectHandles[hSession].insert (handleCounter);
106110 slotHandles[slotID].insert (handleCounter);
107111 return (CK_OBJECT_HANDLE)handleCounter;
@@ -128,6 +132,10 @@ CK_OBJECT_HANDLE HandleManager::addTokenObject(CK_SLOT_ID slotID, bool isPrivate
128132 h.object = object;
129133 handles[++handleCounter] = h;
130134 objects[object] = handleCounter;
135+
136+ DEBUG_MSG (" Added token object - handle: %lu, slot ID: %lu, private: %d, obj: %p" ,
137+ handleCounter, slotID, isPrivate, object);
138+
131139 slotHandles[slotID].insert (handleCounter);
132140 return (CK_OBJECT_HANDLE)handleCounter;
133141}
@@ -165,6 +173,9 @@ void HandleManager::destroyObject(const CK_OBJECT_HANDLE hObject)
165173
166174 objects.erase (it->second .object );
167175 handles.erase (it);
176+ DEBUG_MSG (" Destroyed object handle: %lu" , hObject);
177+ } else {
178+ DEBUG_MSG (" Cannot destroy handle %lu that is not found or not an object handle" , hObject);
168179 }
169180}
170181
@@ -174,14 +185,18 @@ void HandleManager::sessionClosed(const CK_SESSION_HANDLE hSession)
174185
175186 std::map< CK_ULONG, Handle>::iterator it = handles.find (hSession);
176187 if (it == handles.end () || CKH_SESSION != it->second .kind )
188+ {
189+ DEBUG_MSG (" Session %lu not found and cannot be closed" , hSession);
177190 return ; // Unable to find the specified session.
178-
191+ }
179192 CK_SLOT_ID slotID = it->second .slotID ;
180193
181194 // session closed, so we can erase information about it.
182195 slotHandles[slotID].erase (hSession);
183196 handles.erase (it);
184197
198+ DEBUG_MSG (" Session %lu (slot %lu) closed" , hSession, slotID);
199+
185200 // Erase all session object handles associated with the given session handle
186201 // using the secondary index instead of scanning the entire handles map.
187202 std::map< CK_SESSION_HANDLE, std::set<CK_ULONG> >::iterator soit = sessionObjectHandles.find (hSession);
@@ -191,6 +206,7 @@ void HandleManager::sessionClosed(const CK_SESSION_HANDLE hSession)
191206 std::map< CK_ULONG, Handle>::iterator hit = handles.find (*oit);
192207 if (hit != handles.end ()) {
193208 objects.erase (hit->second .object );
209+ DEBUG_MSG (" Erasing object %lu for closed session %lu" , hit->first , hSession);
194210 slotHandles[slotID].erase (*oit);
195211 handles.erase (hit);
196212 }
@@ -216,6 +232,9 @@ void HandleManager::allSessionsClosed(const CK_SLOT_ID slotID, bool isLocked)
216232{
217233 MutexLocker lock (isLocked ? NULL : handlesMutex);
218234
235+
236+ DEBUG_MSG (" Closing all sessions for slot %lu" , slotID);
237+
219238 // Erase all "session", "session object" and "token object" handles for a given slot id
220239 // using the per-slot index instead of scanning the entire handles map.
221240 std::map< CK_SLOT_ID, std::set<CK_ULONG> >::iterator sit = slotHandles.find (slotID);
@@ -224,8 +243,10 @@ void HandleManager::allSessionsClosed(const CK_SLOT_ID slotID, bool isLocked)
224243 for (std::set<CK_ULONG>::iterator it = handleSet.begin (); it != handleSet.end (); ++it) {
225244 std::map< CK_ULONG, Handle>::iterator hit = handles.find (*it);
226245 if (hit != handles.end ()) {
227- if (CKH_OBJECT == hit->second .kind )
246+ if (CKH_OBJECT == hit->second .kind ) {
247+ DEBUG_MSG (" Erasing object %lu for empty slot %lu" , hit->first , slotID);
228248 objects.erase (hit->second .object );
249+ }
229250 if (CKH_SESSION == hit->second .kind )
230251 sessionObjectHandles.erase (*it);
231252 handles.erase (hit);
@@ -253,6 +274,7 @@ void HandleManager::tokenLoggedOut(const CK_SLOT_ID slotID)
253274 if (hit != handles.end () && CKH_OBJECT == hit->second .kind && hit->second .isPrivate ) {
254275 // A private object is present for the given slotID so we need to remove it.
255276 objects.erase (hit->second .object );
277+ DEBUG_MSG (" Erasing private object %lu for logged out token slot %lu" , hit->first , slotID);
256278 if (hit->second .hSession != CK_INVALID_HANDLE)
257279 sessionObjectHandles[hit->second .hSession ].erase (*it);
258280 handles.erase (hit);
0 commit comments