3 * =============================================================================
5 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #include "HandleSys.h"
35 #include "common_logic.h"
37 #include "ExtensionSys.h"
39 HandleSystem g_HandleSys;
41 QHandle *ignore_handle;
43 inline HandleType_t TypeParent(HandleType_t type)
45 return (type & ~HANDLESYS_SUBTYPE_MASK);
48 inline HandleError IdentityHandle(IdentityToken_t *token, unsigned int *index)
50 return g_HandleSys.GetHandle(token->ident, g_ShareSys.GetIdentRoot(), &ignore_handle, index);
53 HandleSystem::HandleSystem()
55 m_Handles = new QHandle[HANDLESYS_MAX_HANDLES + 1];
56 memset(m_Handles, 0, sizeof(QHandle) * (HANDLESYS_MAX_HANDLES + 1));
58 m_Types = new QHandleType[HANDLESYS_TYPEARRAY_SIZE];
59 memset(m_Types, 0, sizeof(QHandleType) * HANDLESYS_TYPEARRAY_SIZE);
61 m_strtab = new BaseStringTable(512);
66 HandleSystem::~HandleSystem()
74 HandleType_t HandleSystem::CreateType(const char *name,
75 IHandleTypeDispatch *dispatch,
77 const TypeAccess *typeAccess,
78 const HandleAccess *hndlAccess,
79 IdentityToken_t *ident,
86 *err = HandleError_Parameter;
91 if (typeAccess && typeAccess->hsVersion > SMINTERFACE_HANDLESYSTEM_VERSION)
95 *err = HandleError_Version;
100 if (hndlAccess && hndlAccess->hsVersion > SMINTERFACE_HANDLESYSTEM_VERSION)
104 *err = HandleError_Version;
109 bool isChild = false;
114 if (parent & HANDLESYS_SUBTYPE_MASK)
118 *err = HandleError_NoInherit;
122 if (parent >= HANDLESYS_TYPEARRAY_SIZE
123 || m_Types[parent].dispatch == NULL)
127 *err = HandleError_Parameter;
131 if (m_Types[parent].typeSec.access[HTypeAccess_Inherit] == false
132 && (m_Types[parent].typeSec.ident != ident))
136 *err = HandleError_Access;
142 if (name && name[0] != '\0')
144 if (m_TypeLookup.retrieve(name))
148 *err = HandleError_Parameter;
158 QHandleType *pParent = &m_Types[parent];
159 if (pParent->children >= HANDLESYS_MAX_SUBTYPES)
163 *err = HandleError_Limit;
168 for (unsigned int i=1; i<=HANDLESYS_MAX_SUBTYPES; i++)
170 if (m_Types[parent + i].dispatch == NULL)
180 *err = HandleError_Limit;
186 if (m_FreeTypes == 0)
188 /* Reserve another index */
189 if (m_TypeTail >= HANDLESYS_TYPEARRAY_SIZE)
193 *err = HandleError_Limit;
197 m_TypeTail += (HANDLESYS_MAX_SUBTYPES + 1);
201 /* The "free array" is compacted into the normal array for easiness */
202 index = m_Types[m_FreeTypes--].freeID;
206 QHandleType *pType = &m_Types[index];
208 pType->dispatch = dispatch;
209 if (name && name[0] != '\0')
211 pType->nameIdx = m_strtab->AddString(name);
212 m_TypeLookup.insert(name, pType);
221 pType->typeSec = *typeAccess;
223 InitAccessDefaults(&pType->typeSec, NULL);
224 pType->typeSec.ident = ident;
229 pType->hndlSec = *hndlAccess;
231 InitAccessDefaults(NULL, &pType->hndlSec);
242 bool HandleSystem::FindHandleType(const char *name, HandleType_t *type)
244 QHandleType **typepp = m_TypeLookup.retrieve(name);
251 unsigned int offset = *typepp - m_Types;
261 HandleError HandleSystem::TryAllocHandle(unsigned int *handle)
263 if (m_FreeHandles == 0)
265 if (m_HandleTail >= HANDLESYS_MAX_HANDLES)
267 return HandleError_Limit;;
269 *handle = ++m_HandleTail;
273 *handle = m_Handles[m_FreeHandles--].freeID;
276 return HandleError_None;
279 HandleError HandleSystem::MakePrimHandle(HandleType_t type,
280 QHandle **in_pHandle,
281 unsigned int *in_index,
283 IdentityToken_t *owner,
287 unsigned int owner_index = 0;
289 if (owner && (IdentityHandle(owner, &owner_index) != HandleError_None))
291 return HandleError_Identity;
295 if ((err = TryAllocHandle(&handle)) != HandleError_None)
297 if (!TryAndFreeSomeHandles()
298 || (err = TryAllocHandle(&handle)) != HandleError_None)
304 QHandle *pHandle = &m_Handles[handle];
306 assert(pHandle->set == false);
308 if (++m_HSerial >= HANDLESYS_MAX_SERIALS)
313 /* Set essential information */
314 pHandle->set = identity ? HandleSet_Identity : HandleSet_Used;
315 pHandle->refcount = 1;
316 pHandle->type = type;
317 pHandle->serial = m_HSerial;
318 pHandle->owner = owner;
319 pHandle->ch_next = 0;
320 pHandle->access_special = false;
321 pHandle->is_destroying = false;
323 /* Create the hash value */
324 Handle_t hash = pHandle->serial;
328 /* Add a reference count to the type */
329 m_Types[type].opened++;
332 *in_pHandle = pHandle;
336 /* Decode the identity token
337 * For now, we don't allow nested ownership
339 if (owner && !identity)
341 QHandle *pIdentity = &m_Handles[owner_index];
342 if (pIdentity->ch_prev == 0)
344 pIdentity->ch_prev = handle;
345 pIdentity->ch_next = handle;
346 pHandle->ch_prev = 0;
350 /* Link previous node to us (forward) */
351 m_Handles[pIdentity->ch_next].ch_next = handle;
352 /* Link us to previous node (backwards) */
353 pHandle->ch_prev = pIdentity->ch_next;
355 pIdentity->ch_next = handle;
357 pIdentity->refcount++;
361 pHandle->ch_prev = 0;
364 return HandleError_None;
367 void HandleSystem::SetTypeSecurityOwner(HandleType_t type, IdentityToken_t *pToken)
370 || type >= HANDLESYS_TYPEARRAY_SIZE
371 || m_Types[type].dispatch == NULL)
376 m_Types[type].typeSec.ident = pToken;
379 Handle_t HandleSystem::CreateHandleInt(HandleType_t type,
381 const HandleSecurity *pSec,
383 const HandleAccess *pAccess,
386 IdentityToken_t *ident;
387 IdentityToken_t *owner;
391 ident = pSec->pIdentity;
392 owner = pSec->pOwner;
399 || type >= HANDLESYS_TYPEARRAY_SIZE
400 || m_Types[type].dispatch == NULL)
404 *err = HandleError_Parameter;
409 /* Check to see if we're allowed to create this handle type */
410 QHandleType *pType = &m_Types[type];
411 if (!pType->typeSec.access[HTypeAccess_Create]
412 && (!pType->typeSec.ident
413 || pType->typeSec.ident != ident))
417 *err = HandleError_Access;
427 if ((_err=MakePrimHandle(type, &pHandle, &index, &handle, owner, identity)) != HandleError_None)
438 pHandle->access_special = true;
439 pHandle->sec = *pAccess;
442 pHandle->object = object;
448 Handle_t HandleSystem::CreateHandleEx(HandleType_t type, void *object, const HandleSecurity *pSec, const HandleAccess *pAccess, HandleError *err)
450 return CreateHandleInt(type, object, pSec, err, pAccess, false);
453 Handle_t HandleSystem::CreateHandle(HandleType_t type, void *object, IdentityToken_t *owner, IdentityToken_t *ident, HandleError *err)
457 sec.pIdentity = ident;
460 return CreateHandleEx(type, object, &sec, NULL, err);
463 bool HandleSystem::TypeCheck(HandleType_t intype, HandleType_t outtype)
465 /* Check the type inheritance */
466 if (intype & HANDLESYS_SUBTYPE_MASK)
468 if (intype != outtype
469 && (TypeParent(intype) != TypeParent(outtype)))
474 if (intype != outtype)
483 HandleError HandleSystem::GetHandle(Handle_t handle,
484 IdentityToken_t *ident,
485 QHandle **in_pHandle,
486 unsigned int *in_index,
489 unsigned int serial = (handle >> 16);
490 unsigned int index = (handle & HANDLESYS_HANDLE_MASK);
492 if (index == 0 || index > m_HandleTail || index > HANDLESYS_MAX_HANDLES)
494 return HandleError_Index;
497 QHandle *pHandle = &m_Handles[index];
500 || (pHandle->set == HandleSet_Freed && !ignoreFree))
502 return HandleError_Freed;
503 } else if (pHandle->set == HandleSet_Identity
504 && ident != g_ShareSys.GetIdentRoot())
506 /* Only IdentityHandle() can read this! */
507 return HandleError_Identity;
509 if (pHandle->serial != serial)
511 return HandleError_Changed;
514 *in_pHandle = pHandle;
517 return HandleError_None;
520 bool HandleSystem::CheckAccess(QHandle *pHandle, HandleAccessRight right, const HandleSecurity *pSecurity)
522 QHandleType *pType = &m_Types[pHandle->type];
525 if (pHandle->access_special)
527 access = pHandle->sec.access[right];
529 access = pType->hndlSec.access[right];
532 /* Check if the type's identity matches */
533 if (access & HANDLE_RESTRICT_IDENTITY)
535 IdentityToken_t *owner = pType->typeSec.ident;
537 || (!pSecurity || pSecurity->pIdentity != owner))
543 /* Check if the owner is allowed */
544 if (access & HANDLE_RESTRICT_OWNER)
546 IdentityToken_t *owner = pHandle->owner;
548 && (!pSecurity || pSecurity->pOwner != owner))
557 HandleError HandleSystem::CloneHandle(QHandle *pHandle, unsigned int index, Handle_t *newhandle, IdentityToken_t *newOwner)
559 /* Get a new Handle ID */
560 unsigned int new_index;
565 if ((err=MakePrimHandle(pHandle->type, &pNewHandle, &new_index, &new_handle, newOwner)) != HandleError_None)
570 /* Assign permissions from parent */
571 if (pHandle->access_special)
573 pNewHandle->access_special = true;
574 pNewHandle->sec = pHandle->sec;
577 pNewHandle->clone = index;
578 pNewHandle->object = NULL;
581 *newhandle = new_handle;
583 return HandleError_None;
586 HandleError HandleSystem::CloneHandle(Handle_t handle, Handle_t *newhandle, IdentityToken_t *newOwner, const HandleSecurity *pSecurity)
591 IdentityToken_t *ident = pSecurity ? pSecurity->pIdentity : NULL;
593 if ((err=GetHandle(handle, ident, &pHandle, &index)) != HandleError_None)
598 /* Identities cannot be cloned */
599 if (pHandle->set == HandleSet_Identity)
601 return HandleError_Identity;
604 /* Check if the handle can be cloned */
605 if (!CheckAccess(pHandle, HandleAccess_Clone, pSecurity))
607 return HandleError_Access;
610 /* Make sure we're not cloning a clone */
613 QHandle *pParent = &m_Handles[pHandle->clone];
614 return CloneHandle(pParent, pHandle->clone, newhandle, newOwner);
617 return CloneHandle(pHandle, index, newhandle, newOwner);
620 Handle_t HandleSystem::FastCloneHandle(QHandle *pHandle, unsigned int index)
623 return FastCloneHandle(&m_Handles[pHandle->clone], pHandle->clone);
626 if (CloneHandle(pHandle, index, &hndl, g_pCoreIdent) != HandleError_None)
632 Handle_t HandleSystem::FastCloneHandle(Handle_t hndl)
637 GetHandleUnchecked(hndl, pHandle, index);
639 return FastCloneHandle(pHandle, index);
642 void HandleSystem::GetHandleUnchecked(Handle_t hndl, QHandle *& pHandle, unsigned int &index)
645 unsigned int serial = (hndl >> 16);
647 index = (hndl & HANDLESYS_HANDLE_MASK);
649 assert(index != 0 && index <= m_HandleTail && index < HANDLESYS_MAX_HANDLES);
651 pHandle = &m_Handles[index];
653 assert(pHandle->set && pHandle->set != HandleSet_Freed);
654 assert(pHandle->serial == serial);
657 HandleError HandleSystem::FreeHandle(QHandle *pHandle, unsigned int index)
659 if (pHandle->is_destroying)
661 /* Someone tried to free this recursively.
662 * We'll just ignore this safely.
664 return HandleError_None;
667 QHandleType *pType = &m_Types[pHandle->type];
671 /* If we're a clone, decrease the parent reference count */
675 /* Note that if we ever have per-handle security, we would need to re-check
676 * the access on this Handle. */
677 master = pHandle->clone;
678 pMaster = &m_Handles[master];
680 /* Release the clone now */
681 pHandle->is_destroying = true;
682 ReleasePrimHandle(index);
684 /* Decrement the master's reference count */
685 if (--pMaster->refcount == 0)
687 /* Type should be the same but do this anyway... */
688 pType = &m_Types[pMaster->type];
689 pMaster->is_destroying = true;
692 pType->dispatch->OnHandleDestroy(pMaster->type, pMaster->object);
694 ReleasePrimHandle(master);
696 } else if (pHandle->set == HandleSet_Identity) {
697 /* If we're an identity, skip all this stuff!
698 * NOTE: SHARESYS DOES NOT CARE ABOUT THE DESTRUCTOR
700 pHandle->is_destroying = true;
701 ReleasePrimHandle(index);
703 /* Decrement, free if necessary */
704 if (--pHandle->refcount == 0)
706 pHandle->is_destroying = true;
709 pType->dispatch->OnHandleDestroy(pHandle->type, pHandle->object);
711 ReleasePrimHandle(index);
713 /* We must be cloned, so mark ourselves as freed */
714 pHandle->set = HandleSet_Freed;
715 /* Now, unlink us, so we're not being tracked by the owner */
718 UnlinkHandleFromOwner(pHandle, index);
723 return HandleError_None;
726 HandleError HandleSystem::FreeHandle(Handle_t handle, const HandleSecurity *pSecurity)
731 IdentityToken_t *ident = pSecurity ? pSecurity->pIdentity : NULL;
733 if ((err=GetHandle(handle, ident, &pHandle, &index)) != HandleError_None)
738 if (!CheckAccess(pHandle, HandleAccess_Delete, pSecurity))
740 return HandleError_Access;
743 return FreeHandle(pHandle, index);
746 HandleError HandleSystem::ReadHandle(Handle_t handle, HandleType_t type, const HandleSecurity *pSecurity, void **object)
751 IdentityToken_t *ident = pSecurity ? pSecurity->pIdentity : NULL;
753 if ((err=GetHandle(handle, ident, &pHandle, &index)) != HandleError_None)
758 if (!CheckAccess(pHandle, HandleAccess_Read, pSecurity))
760 return HandleError_Access;
763 /* Check the type inheritance */
764 if (pHandle->type & HANDLESYS_SUBTYPE_MASK)
766 if (pHandle->type != type
767 && (TypeParent(pHandle->type) != TypeParent(type)))
769 return HandleError_Type;
772 if (pHandle->type != type)
774 return HandleError_Type;
780 /* if we're a clone, the rules change - object is ONLY in our reference */
783 pHandle = &m_Handles[pHandle->clone];
785 *object = pHandle->object;
788 return HandleError_None;
791 void HandleSystem::UnlinkHandleFromOwner(QHandle *pHandle, unsigned int index)
793 /* Unlink us if necessary */
794 unsigned int ident_index;
795 if (IdentityHandle(pHandle->owner, &ident_index) != HandleError_None)
798 assert(pHandle->owner == 0);
802 pHandle->owner = NULL;
804 /* Note that since 0 is an invalid handle, if any of these links are 0,
805 * the data can still be set.
807 QHandle *pIdentity = &m_Handles[ident_index];
809 /* Unlink case: We're the head AND tail node */
810 if (index == pIdentity->ch_prev && index == pIdentity->ch_next)
812 pIdentity->ch_prev = 0;
813 pIdentity->ch_next = 0;
815 /* Unlink case: We're the head node */
816 else if (index == pIdentity->ch_prev) {
817 /* Link us to the next in the chain */
818 pIdentity->ch_prev = pHandle->ch_next;
819 /* Patch up the previous link */
820 m_Handles[pHandle->ch_next].ch_prev = 0;
822 /* Unlink case: We're the tail node */
823 else if (index == pIdentity->ch_next) {
824 /* Link us to the previous in the chain */
825 pIdentity->ch_next = pHandle->ch_prev;
826 /* Patch up the next link */
827 m_Handles[pHandle->ch_prev].ch_next = 0;
829 /* Unlink case: We're in the middle! */
831 /* Patch the forward reference */
832 m_Handles[pHandle->ch_next].ch_prev = pHandle->ch_prev;
833 /* Patch the backward reference */
834 m_Handles[pHandle->ch_prev].ch_next = pHandle->ch_next;
837 /* Lastly, decrease the reference count */
838 pIdentity->refcount--;
841 void HandleSystem::ReleasePrimHandle(unsigned int index)
843 QHandle *pHandle = &m_Handles[index];
844 HandleSet set = pHandle->set;
846 if (pHandle->owner && (set != HandleSet_Identity))
848 UnlinkHandleFromOwner(pHandle, index);
851 /* Were we an identity ourself? */
853 if (set == HandleSet_Identity)
855 /* Extra work to do. We need to find everything connected to this identity and release it. */
856 unsigned int ch_index;
858 unsigned int old_index = 0;
860 while ((ch_index = pHandle->ch_next) != 0)
862 pLocal = &m_Handles[ch_index];
864 assert(old_index != ch_index);
865 assert(pLocal->set == HandleSet_Used);
866 old_index = ch_index;
868 FreeHandle(pLocal, ch_index);
872 pHandle->set = HandleSet_None;
873 m_Types[pHandle->type].opened--;
874 m_Handles[++m_FreeHandles].freeID = index;
877 bool HandleSystem::RemoveType(HandleType_t type, IdentityToken_t *ident)
879 if (type == 0 || type >= HANDLESYS_TYPEARRAY_SIZE)
884 QHandleType *pType = &m_Types[type];
886 if (pType->typeSec.ident
887 && pType->typeSec.ident != ident)
892 if (pType->dispatch == NULL)
897 /* Remove children if we have to */
898 if (!(type & HANDLESYS_SUBTYPE_MASK))
900 QHandleType *childType;
901 for (unsigned int i=1; i<=HANDLESYS_MAX_SUBTYPES; i++)
903 childType = &m_Types[type + i];
904 if (childType->dispatch)
906 RemoveType(type + i, childType->typeSec.ident);
909 /* Link us into the free chain */
910 m_Types[++m_FreeTypes].freeID = type;
913 /* Invalidate the type now */
914 IHandleTypeDispatch *dispatch = pType->dispatch;
915 pType->dispatch = NULL;
917 /* Make sure nothing is using this type. */
921 for (unsigned int i=1; i<=m_HandleTail; i++)
923 pHandle = &m_Handles[i];
924 if (!pHandle->set || pHandle->type != type)
929 FreeHandle(pHandle, i);
931 if (pType->opened == 0)
938 /* Remove it from the type cache. */
939 if (pType->nameIdx != -1)
941 const char *typeName;
943 typeName = m_strtab->GetString(pType->nameIdx);
944 m_TypeLookup.remove(typeName);
950 bool HandleSystem::InitAccessDefaults(TypeAccess *pTypeAccess, HandleAccess *pHandleAccess)
954 if (pTypeAccess->hsVersion > SMINTERFACE_HANDLESYSTEM_VERSION)
958 pTypeAccess->access[HTypeAccess_Create] = false;
959 pTypeAccess->access[HTypeAccess_Inherit] = false;
960 pTypeAccess->ident = NULL;
965 if (pHandleAccess->hsVersion > SMINTERFACE_HANDLESYSTEM_VERSION)
970 pHandleAccess->access[HandleAccess_Clone] = 0;
971 pHandleAccess->access[HandleAccess_Delete] = HANDLE_RESTRICT_OWNER;
972 pHandleAccess->access[HandleAccess_Read] = HANDLE_RESTRICT_IDENTITY;
978 #define HANDLE_LOG_VERY_BAD(message, ...) \
979 smcore.LogFatal(message, ##__VA_ARGS__); \
980 smcore.LogError(message, ##__VA_ARGS__);
982 bool HandleSystem::TryAndFreeSomeHandles()
984 IPluginIterator *pl_iter = scripts->GetPluginIterator();
985 IPlugin *highest_owner = NULL;
986 unsigned int highest_handle_count = 0;
988 /* Search all plugins */
989 while (pl_iter->MorePlugins())
991 IPlugin *plugin = pl_iter->GetPlugin();
992 IdentityToken_t *identity = plugin->GetIdentity();
993 unsigned int handle_count = 0;
995 if (identity == NULL)
1000 /* Search all handles */
1001 for (unsigned int i = 1; i <= m_HandleTail; i++)
1003 if (m_Handles[i].set != HandleSet_Used)
1007 if (m_Handles[i].owner == identity)
1013 if (handle_count > highest_handle_count)
1015 highest_owner = plugin;
1016 highest_handle_count = handle_count;
1019 pl_iter->NextPlugin();
1022 if (highest_owner == NULL || highest_handle_count == 0)
1027 HANDLE_LOG_VERY_BAD("[SM] MEMORY LEAK DETECTED IN PLUGIN (file \"%s\")", highest_owner->GetFilename());
1028 HANDLE_LOG_VERY_BAD("[SM] Unloading plugin to free %d handles.", highest_handle_count);
1029 HANDLE_LOG_VERY_BAD("[SM] Contact the author(s) of this plugin to correct this error.", highest_handle_count);
1031 highest_owner->GetBaseContext()->ThrowNativeErrorEx(SP_ERROR_MEMACCESS, "Memory leak");
1033 return scripts->UnloadPlugin(highest_owner);
1036 void HandleSystem::Dump(HANDLE_REPORTER rep)
1038 unsigned int total_size = 0;
1039 rep("%-10.10s\t%-20.20s\t%-20.20s\t%-10.10s", "Handle", "Owner", "Type", "Memory");
1040 rep("--------------------------------------------------------------------------");
1041 for (unsigned int i = 1; i <= m_HandleTail; i++)
1043 if (m_Handles[i].set != HandleSet_Used)
1048 unsigned int index = (m_Handles[i].serial << 16) | i;
1049 /* Determine the owner */
1050 const char *owner = "UNKNOWN";
1051 if (m_Handles[i].owner)
1053 IdentityToken_t *pOwner = m_Handles[i].owner;
1054 if (pOwner == g_pCoreIdent)
1058 else if (pOwner == scripts->GetIdentity())
1060 owner = "PLUGINSYS";
1064 IExtension *ext = g_Extensions.GetExtensionFromIdent(pOwner);
1067 owner = ext->GetFilename();
1071 SMPlugin *pPlugin = scripts->FindPluginByIdentity(pOwner);
1074 owner = pPlugin->GetFilename();
1083 const char *type = "ANON";
1084 QHandleType *pType = &m_Types[m_Handles[i].type];
1085 unsigned int size = 0;
1086 unsigned int parentIdx;
1088 if (pType->nameIdx != -1)
1090 type = m_strtab->GetString(pType->nameIdx);
1093 if ((parentIdx = m_Handles[i].clone) != 0)
1095 if (m_Handles[parentIdx].refcount > 0)
1102 bresult = pType->dispatch->GetHandleApproxSize(m_Handles[parentIdx].type, m_Handles[parentIdx].object, &size);
1107 bresult = pType->dispatch->GetHandleApproxSize(m_Handles[i].type, m_Handles[i].object, &size);
1110 if (pType->dispatch->GetDispatchVersion() < HANDLESYS_MEMUSAGE_MIN_VERSION
1113 rep("0x%08x\t%-20.20s\t%-20.20s\t%-10.10s", index, owner, type, "-1");
1118 smcore.Format(buffer, sizeof(buffer), "%d", size);
1119 rep("0x%08x\t%-20.20s\t%-20.20s\t%-10.10s", index, owner, type, buffer);
1123 rep("-- Approximately %d bytes of memory are in use by Handles.\n", total_size);