4 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
8 * Jaewon Lim <jaewon81.lim@samsung.com>
9 * Woojin Jung <woojin2.jung@samsung.com>
10 * Juyoung Kim <j0.kim@samsung.com>
12 * This library is free software; you can redistribute it and/or modify it under
13 * the terms of the GNU Lesser General Public License as published by the
14 * Free Software Foundation; either version 2.1 of the License, or (at your option)
17 * This library is distributed in the hope that it will be useful, but WITHOUT ANY
18 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
20 * License for more details.
22 * You should have received a copy of the GNU Lesser General Public License
23 * along with this library; if not, write to the Free Software Foundation, Inc., 51
24 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
31 #ifndef __COLLECTIONS_H__
32 #define __COLLECTIONS_H__
34 #include <pthread.h> // for pthread_mutex_t
42 #define SYMBOLHASH _hashinfo.symHash
43 #define SYMBOLHASH_LOCK pthread_mutex_lock(&(_hashinfo.symHashMutex))
44 #define SYMBOLHASH_UNLOCK pthread_mutex_unlock(&(_hashinfo.symHashMutex))
46 #define MEMORYHASH _hashinfo.memHash
47 #define MEMORYHASH_LOCK pthread_mutex_lock(&(_hashinfo.memHashMutex))
48 #define MEMORYHASH_UNLOCK pthread_mutex_unlock(&(_hashinfo.memHashMutex))
50 #define OBJECTHASH _hashinfo.objHash
51 #define OBJECTHASH_LOCK pthread_mutex_lock(&(_hashinfo.objHashMutex))
52 #define OBJECTHASH_UNLOCK pthread_mutex_unlock(&(_hashinfo.objHashMutex))
54 #define DETECTORHASH _hashinfo.dttHash
55 #define DETECTORHASH_LOCK pthread_mutex_lock(&(_hashinfo.dttHashMutex))
56 #define DETECTORHASH_UNLOCK pthread_mutex_unlock(&(_hashinfo.dttHashMutex))
58 #define MEMTYPE_ALLOC 0x01
59 #define MEMTYPE_FREE 0x01
60 #define MEMTYPE_NEW 0x03
61 #define MEMTYPE_DELETE 0x03
63 #define MEM_INTERNAL 0x01
64 #define MEM_EXTERNAL 0x02
66 #define MEMMASK_CALLER 0xFFFF000000000000L
67 #define MEMMASK_TYPE 0x0000FFFF00000000L
68 #define MEMMASK_SIZE 0x00000000FFFFFFFFL
70 #define GET_MEMSIZE(_info) ((size_t)(_info & MEMMASK_SIZE))
71 #define GET_MEMCALLER(_info) ((unsigned short)((_info & MEMMASK_CALLER) >> 48))
72 #define GET_MEMTYPE(_info) ((unsigned short)((_info & MEMMASK_TYPE) >> 32))
74 #define MAKE_MEMINFO(caller, type, size) \
75 (((uint64_t)caller << 48) | ((uint64_t)type << 32) | ((uint64_t)size))
83 // khash table function definition
84 KHASH_MAP_INIT_INT(symbol, char*)
86 KHASH_MAP_INIT_INT(allocmap, uint64_t)
88 KHASH_MAP_INIT_INT(object, _objectinfo*)
90 KHASH_MAP_INIT_INT(detector, void*)
94 khash_t(symbol)* symHash;
95 pthread_mutex_t symHashMutex;
96 khash_t(allocmap)* memHash;
97 pthread_mutex_t memHashMutex;
98 khash_t(object)* objHash;
99 pthread_mutex_t objHashMutex;
100 khash_t(detector)* dttHash;
101 pthread_mutex_t dttHashMutex;
104 extern __hashInfo _hashinfo;
106 // APIs for symdata linked list
107 int add_to_glist(char* key, void* data);
108 int remove_from_glist(char* key);
109 int remove_all_glist();
110 void* find_glist(char* key);
112 // APIs for hash table
113 int initialize_hash_table();
114 int finalize_hash_table();
116 int find_symbol_hash(void* ptr, char** psymbol);
117 int add_symbol_hash(void* ptr, const char* str, int strlen);
118 int add_memory_hash(void* ptr, size_t size, unsigned short type, unsigned short caller);
119 int del_memory_hash(void* ptr, unsigned short type, unsigned short* caller);
121 int find_object_hash(void* ptr, char** type, char** classname);
122 int add_object_hash_class(void* ptr, const char* classname);
123 int add_object_hash_type(void* ptr, const char* type);
124 int del_object_hash(void* ptr);
126 int add_detector_hash(void* ptr, void* listener);
127 int del_detector_hash(void* ptr);
133 #endif /* __COLLECTIONS_H_ */