2019-05-07 02:18:18 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
2019-11-11 23:45:21 +00:00
|
|
|
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2019-05-07 02:18:18 +00:00
|
|
|
*/
|
|
|
|
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
#include "bh_hashmap.h"
|
2019-05-07 02:18:18 +00:00
|
|
|
|
|
|
|
typedef struct HashMapElem {
|
|
|
|
void *key;
|
|
|
|
void *value;
|
|
|
|
struct HashMapElem *next;
|
|
|
|
} HashMapElem;
|
|
|
|
|
|
|
|
struct HashMap {
|
|
|
|
/* size of element array */
|
|
|
|
uint32 size;
|
|
|
|
/* lock for elements */
|
|
|
|
korp_mutex *lock;
|
|
|
|
/* hash function of key */
|
|
|
|
HashFunc hash_func;
|
|
|
|
/* key equal function */
|
|
|
|
KeyEqualFunc key_equal_func;
|
|
|
|
KeyDestroyFunc key_destroy_func;
|
|
|
|
ValueDestroyFunc value_destroy_func;
|
|
|
|
HashMapElem *elements[1];
|
|
|
|
};
|
|
|
|
|
2021-10-14 01:12:07 +00:00
|
|
|
HashMap *
|
|
|
|
bh_hash_map_create(uint32 size, bool use_lock, HashFunc hash_func,
|
|
|
|
KeyEqualFunc key_equal_func, KeyDestroyFunc key_destroy_func,
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
ValueDestroyFunc value_destroy_func)
|
2019-05-07 02:18:18 +00:00
|
|
|
{
|
|
|
|
HashMap *map;
|
2019-11-20 13:16:36 +00:00
|
|
|
uint64 total_size;
|
2019-05-07 02:18:18 +00:00
|
|
|
|
|
|
|
if (size > HASH_MAP_MAX_SIZE) {
|
|
|
|
LOG_ERROR("HashMap create failed: size is too large.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hash_func || !key_equal_func) {
|
|
|
|
LOG_ERROR("HashMap create failed: hash function or key equal function "
|
2021-10-14 01:12:07 +00:00
|
|
|
" is NULL.\n");
|
2019-05-07 02:18:18 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-10-14 01:12:07 +00:00
|
|
|
total_size = offsetof(HashMap, elements)
|
|
|
|
+ sizeof(HashMapElem *) * (uint64)size
|
|
|
|
+ (use_lock ? sizeof(korp_mutex) : 0);
|
2019-05-07 02:18:18 +00:00
|
|
|
|
2021-10-14 01:12:07 +00:00
|
|
|
if (total_size >= UINT32_MAX || !(map = BH_MALLOC((uint32)total_size))) {
|
2019-05-07 02:18:18 +00:00
|
|
|
LOG_ERROR("HashMap create failed: alloc memory failed.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-11-20 13:16:36 +00:00
|
|
|
memset(map, 0, (uint32)total_size);
|
2019-05-07 02:18:18 +00:00
|
|
|
|
|
|
|
if (use_lock) {
|
2021-10-14 01:12:07 +00:00
|
|
|
map->lock = (korp_mutex *)((uint8 *)map + offsetof(HashMap, elements)
|
|
|
|
+ sizeof(HashMapElem *) * size);
|
2020-03-16 08:43:57 +00:00
|
|
|
if (os_mutex_init(map->lock)) {
|
2019-05-07 02:18:18 +00:00
|
|
|
LOG_ERROR("HashMap create failed: init map lock failed.\n");
|
2020-03-10 11:54:44 +00:00
|
|
|
BH_FREE(map);
|
2019-05-07 02:18:18 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
map->size = size;
|
|
|
|
map->hash_func = hash_func;
|
|
|
|
map->key_equal_func = key_equal_func;
|
|
|
|
map->key_destroy_func = key_destroy_func;
|
|
|
|
map->value_destroy_func = value_destroy_func;
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
bh_hash_map_insert(HashMap *map, void *key, void *value)
|
2019-05-07 02:18:18 +00:00
|
|
|
{
|
|
|
|
uint32 index;
|
|
|
|
HashMapElem *elem;
|
|
|
|
|
|
|
|
if (!map || !key) {
|
|
|
|
LOG_ERROR("HashMap insert elem failed: map or key is NULL.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (map->lock) {
|
2020-03-16 08:43:57 +00:00
|
|
|
os_mutex_lock(map->lock);
|
2019-05-07 02:18:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index = map->hash_func(key) % map->size;
|
|
|
|
elem = map->elements[index];
|
|
|
|
while (elem) {
|
|
|
|
if (map->key_equal_func(elem->key, key)) {
|
|
|
|
LOG_ERROR("HashMap insert elem failed: duplicated key found.\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
elem = elem->next;
|
|
|
|
}
|
|
|
|
|
2020-03-10 11:54:44 +00:00
|
|
|
if (!(elem = BH_MALLOC(sizeof(HashMapElem)))) {
|
2019-05-07 02:18:18 +00:00
|
|
|
LOG_ERROR("HashMap insert elem failed: alloc memory failed.\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
elem->key = key;
|
|
|
|
elem->value = value;
|
|
|
|
elem->next = map->elements[index];
|
|
|
|
map->elements[index] = elem;
|
|
|
|
|
|
|
|
if (map->lock) {
|
2020-03-16 08:43:57 +00:00
|
|
|
os_mutex_unlock(map->lock);
|
2019-05-07 02:18:18 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
if (map->lock) {
|
2020-03-16 08:43:57 +00:00
|
|
|
os_mutex_unlock(map->lock);
|
2019-05-07 02:18:18 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-10-14 01:12:07 +00:00
|
|
|
void *
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
bh_hash_map_find(HashMap *map, void *key)
|
2019-05-07 02:18:18 +00:00
|
|
|
{
|
|
|
|
uint32 index;
|
|
|
|
HashMapElem *elem;
|
|
|
|
void *value;
|
|
|
|
|
|
|
|
if (!map || !key) {
|
|
|
|
LOG_ERROR("HashMap find elem failed: map or key is NULL.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (map->lock) {
|
2020-03-16 08:43:57 +00:00
|
|
|
os_mutex_lock(map->lock);
|
2019-05-07 02:18:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index = map->hash_func(key) % map->size;
|
|
|
|
elem = map->elements[index];
|
|
|
|
|
|
|
|
while (elem) {
|
|
|
|
if (map->key_equal_func(elem->key, key)) {
|
|
|
|
value = elem->value;
|
|
|
|
if (map->lock) {
|
2020-03-16 08:43:57 +00:00
|
|
|
os_mutex_unlock(map->lock);
|
2019-05-07 02:18:18 +00:00
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
elem = elem->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (map->lock) {
|
2020-03-16 08:43:57 +00:00
|
|
|
os_mutex_unlock(map->lock);
|
2019-05-07 02:18:18 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2021-10-14 01:12:07 +00:00
|
|
|
bh_hash_map_update(HashMap *map, void *key, void *value, void **p_old_value)
|
2019-05-07 02:18:18 +00:00
|
|
|
{
|
|
|
|
uint32 index;
|
|
|
|
HashMapElem *elem;
|
|
|
|
|
|
|
|
if (!map || !key) {
|
|
|
|
LOG_ERROR("HashMap update elem failed: map or key is NULL.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (map->lock) {
|
2020-03-16 08:43:57 +00:00
|
|
|
os_mutex_lock(map->lock);
|
2019-05-07 02:18:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index = map->hash_func(key) % map->size;
|
|
|
|
elem = map->elements[index];
|
|
|
|
|
|
|
|
while (elem) {
|
|
|
|
if (map->key_equal_func(elem->key, key)) {
|
|
|
|
if (p_old_value)
|
|
|
|
*p_old_value = elem->value;
|
|
|
|
elem->value = value;
|
|
|
|
if (map->lock) {
|
2020-03-16 08:43:57 +00:00
|
|
|
os_mutex_unlock(map->lock);
|
2019-05-07 02:18:18 +00:00
|
|
|
}
|
|
|
|
return true;
|
2020-09-18 10:04:56 +00:00
|
|
|
}
|
|
|
|
elem = elem->next;
|
2019-05-07 02:18:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (map->lock) {
|
2020-03-16 08:43:57 +00:00
|
|
|
os_mutex_unlock(map->lock);
|
2019-05-07 02:18:18 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2021-10-14 01:12:07 +00:00
|
|
|
bh_hash_map_remove(HashMap *map, void *key, void **p_old_key,
|
|
|
|
void **p_old_value)
|
2019-05-07 02:18:18 +00:00
|
|
|
{
|
|
|
|
uint32 index;
|
|
|
|
HashMapElem *elem, *prev;
|
|
|
|
|
|
|
|
if (!map || !key) {
|
|
|
|
LOG_ERROR("HashMap remove elem failed: map or key is NULL.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (map->lock) {
|
2020-03-16 08:43:57 +00:00
|
|
|
os_mutex_lock(map->lock);
|
2019-05-07 02:18:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index = map->hash_func(key) % map->size;
|
|
|
|
prev = elem = map->elements[index];
|
|
|
|
|
|
|
|
while (elem) {
|
|
|
|
if (map->key_equal_func(elem->key, key)) {
|
|
|
|
if (p_old_key)
|
|
|
|
*p_old_key = elem->key;
|
|
|
|
if (p_old_value)
|
|
|
|
*p_old_value = elem->value;
|
|
|
|
|
|
|
|
if (elem == map->elements[index])
|
|
|
|
map->elements[index] = elem->next;
|
|
|
|
else
|
|
|
|
prev->next = elem->next;
|
|
|
|
|
2020-03-10 11:54:44 +00:00
|
|
|
BH_FREE(elem);
|
2019-05-07 02:18:18 +00:00
|
|
|
|
|
|
|
if (map->lock) {
|
2020-03-16 08:43:57 +00:00
|
|
|
os_mutex_unlock(map->lock);
|
2019-05-07 02:18:18 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
prev = elem;
|
|
|
|
elem = elem->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (map->lock) {
|
2020-03-16 08:43:57 +00:00
|
|
|
os_mutex_unlock(map->lock);
|
2019-05-07 02:18:18 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
bh_hash_map_destroy(HashMap *map)
|
2019-05-07 02:18:18 +00:00
|
|
|
{
|
|
|
|
uint32 index;
|
|
|
|
HashMapElem *elem, *next;
|
|
|
|
|
|
|
|
if (!map) {
|
|
|
|
LOG_ERROR("HashMap destroy failed: map is NULL.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (map->lock) {
|
2020-03-16 08:43:57 +00:00
|
|
|
os_mutex_lock(map->lock);
|
2019-05-07 02:18:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (index = 0; index < map->size; index++) {
|
|
|
|
elem = map->elements[index];
|
|
|
|
while (elem) {
|
|
|
|
next = elem->next;
|
|
|
|
|
|
|
|
if (map->key_destroy_func) {
|
|
|
|
map->key_destroy_func(elem->key);
|
|
|
|
}
|
|
|
|
if (map->value_destroy_func) {
|
|
|
|
map->value_destroy_func(elem->value);
|
|
|
|
}
|
2020-03-10 11:54:44 +00:00
|
|
|
BH_FREE(elem);
|
2019-05-07 02:18:18 +00:00
|
|
|
|
|
|
|
elem = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (map->lock) {
|
2020-03-16 08:43:57 +00:00
|
|
|
os_mutex_unlock(map->lock);
|
|
|
|
os_mutex_destroy(map->lock);
|
2019-05-07 02:18:18 +00:00
|
|
|
}
|
2020-03-10 11:54:44 +00:00
|
|
|
BH_FREE(map);
|
2019-05-07 02:18:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
2020-09-18 10:04:56 +00:00
|
|
|
|
|
|
|
uint32
|
|
|
|
bh_hash_map_get_struct_size(HashMap *hashmap)
|
|
|
|
{
|
2020-11-24 06:00:09 +00:00
|
|
|
uint32 size = (uint32)(uintptr_t)offsetof(HashMap, elements)
|
|
|
|
+ (uint32)sizeof(HashMapElem *) * hashmap->size;
|
2020-09-18 10:04:56 +00:00
|
|
|
|
|
|
|
if (hashmap->lock) {
|
2020-11-24 06:00:09 +00:00
|
|
|
size += (uint32)sizeof(korp_mutex);
|
2020-09-18 10:04:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32
|
|
|
|
bh_hash_map_get_elem_struct_size()
|
|
|
|
{
|
2020-11-24 06:00:09 +00:00
|
|
|
return (uint32)sizeof(HashMapElem);
|
2020-09-18 10:04:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2021-04-15 03:29:20 +00:00
|
|
|
bh_hash_map_traverse(HashMap *map, TraverseCallbackFunc callback,
|
|
|
|
void *user_data)
|
2020-09-18 10:04:56 +00:00
|
|
|
{
|
|
|
|
uint32 index;
|
|
|
|
HashMapElem *elem, *next;
|
|
|
|
|
|
|
|
if (!map || !callback) {
|
|
|
|
LOG_ERROR("HashMap traverse failed: map or callback is NULL.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (map->lock) {
|
|
|
|
os_mutex_lock(map->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (index = 0; index < map->size; index++) {
|
|
|
|
elem = map->elements[index];
|
|
|
|
while (elem) {
|
|
|
|
next = elem->next;
|
2021-04-15 03:29:20 +00:00
|
|
|
callback(elem->key, elem->value, user_data);
|
2020-09-18 10:04:56 +00:00
|
|
|
elem = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (map->lock) {
|
|
|
|
os_mutex_unlock(map->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2020-11-24 06:00:09 +00:00
|
|
|
}
|